C MIP-SDK
|
#include "mip.h"
#include "mip_sdk_config.h"
#include "mip_sdk_user_functions.h"
#include "ring_buffer.h"
#include "byteswap_utilities.h"
Go to the source code of this file.
Data Structures | |
struct | _mip_interface |
Defines | |
#define | MIP_INTERFACE_INPUT_RING_BUFFER_SIZE MIP_MAX_PACKET_SIZE |
#define | MIP_INTERFACE_CALLBACK_VALID_PACKET 0 |
#define | MIP_INTERFACE_CALLBACK_CHECKSUM_ERROR 1 |
#define | MIP_INTERFACE_CALLBACK_TIMEOUT 2 |
#define | MIP_INTERFACE_OK 0 |
#define | MIP_INTERFACE_ERROR 1 |
#define | MIP_INTERFACE_TIMEOUT 0 |
#define | MIP_INTERFACE_NO_TIMEOUT 1 |
#define | MIP_INTERFACE_INITIALIZED 1 |
#define | MIP_INTERFACE_UNINITIALIZED 0 |
Typedefs | |
typedef void(* | parser_callback_ptr )(void *, u8 *, u16, u8) |
typedef struct _mip_interface | mip_interface |
Functions | |
u16 | mip_interface_init (u32 com_port, u32 baudrate, mip_interface *device_interface, u32 packet_timeout_val) |
u16 | mip_interface_close (mip_interface *device_interface) |
u16 | mip_interface_add_descriptor_set_callback (mip_interface *device_interface, u8 data_set, void *user_ptr, void(*packet_callback)(void *user_ptr, u8 *packet, u16 packet_size, u8 callback_type)) |
u16 | mip_interface_delete_descriptor_set_callback (mip_interface *device_interface, u8 data_set) |
u16 | mip_interface_update (mip_interface *device_interface) |
u16 | mip_interface_send_command (mip_interface *device_interface, u8 command_set, u8 command_descriptor, u8 *command_data, u16 command_data_size, u8 wait_for_response, u32 timeout_ms) |
u16 | mip_interface_send_preformatted_command (mip_interface *device_interface, u8 *command, u16 command_size, u8 wait_for_response, u32 timeout_ms) |
u16 | mip_interface_send_command_with_response (mip_interface *device_interface, u8 command_set, u8 command_descriptor, u8 *command_data, u16 command_data_size, u8 **response_data, u16 *response_data_size, u32 timeout_ms) |
u16 | mip_interface_send_preformatted_command_with_response (mip_interface *device_interface, u8 *command, u16 command_size, u8 **response_data, u16 *response_data_size, u32 timeout_ms) |
u16 | mip_interface_write (mip_interface *device_interface, u8 *data, u32 num_bytes, u32 *bytes_written) |
u16 | mip_interface_write_blocking (mip_interface *device_interface, u8 *data, u32 num_bytes, u32 *bytes_written, u32 timeout_ms) |
u16 | __mip_interface_parse_input_buffer (mip_interface *device_interface) |
u16 | __mip_interface_find_callback (mip_interface *device_interface, u8 data_set, void **callback_user_ptr, parser_callback_ptr *callback_function) |
u16 | __mip_interface_time_timeout (u32 initial_time, u32 timeout_ms) |
u16 | __mip_interface_wait_for_response (mip_interface *device_interface, u8 command_set, u8 command_descriptor, u8 *acknack_response, u8 **response_data, u16 *response_data_size, u32 timeout_ms) |
void | __mip_interface_command_response_handler (void *user_ptr, u8 *packet, u16 packet_size, u8 callback_type) |
void __mip_interface_command_response_handler | ( | void * | user_ptr, |
u8 * | packet, | ||
u16 | packet_size, | ||
u8 | callback_type | ||
) |
Command-Response Handler.
[in] | void | *user_ptr - Pointer to the user data for this callback. |
[in] | u8 | *packet - The MIP packet that matches the waiting command set. |
[in] | u16 | packet_size - Size of the MIP packet. |
[in] | u8 | callback_type - Type of callback. |
This is an internal function.
u16 __mip_interface_find_callback | ( | mip_interface * | device_interface, |
u8 | data_set, | ||
void ** | callback_user_ptr, | ||
parser_callback_ptr * | callback_function | ||
) |
Find the callback info for the provided dataset.
[in] | mip_interface | *device_interface - pointer to the mip interface structure. |
[in] | u8 | data_set - dataset to search for. |
[out] | void | *callback_user_ptr - pointer to the user data for the callback. |
[out] | parser_callback_ptr | callback_function - pointer to callback function. |
MIP_INTERFACE_ERROR | The callback could not be located or there was an error. |
MIP_INTERFACE_OK | The callback was located. |
This is an internal function.
u16 __mip_interface_parse_input_buffer | ( | mip_interface * | device_interface | ) |
Processes the bytes in the input buffer and triggers the callback function.
[in] | mip_interface | *device_interface - pointer to the mip interface structure. |
MIP_INTERFACE_ERROR | Interface not initialized. |
MIP_INTERFACE_OK | Parser ran. |
This is an internal function.
u16 __mip_interface_time_timeout | ( | u32 | initial_time, |
u32 | timeout_ms | ||
) |
Check for a timeout condition.
[in] | u32 | initial_time - the start time to check against in milliseconds. |
[in] | u32 | timeout_ms - the timeout period in milliseconds. |
MIP_INTERFACE_TIMEOUT | The timeout has occured. |
MIP_INTERFACE_NO_TIMEOUT | No timeout. |
This is an internal function.
u16 __mip_interface_wait_for_response | ( | mip_interface * | device_interface, |
u8 | command_set, | ||
u8 | command_descriptor, | ||
u8 * | acknack_response, | ||
u8 ** | response_data, | ||
u16 * | response_data_size, | ||
u32 | timeout_ms | ||
) |
Wait for a Command-Response.
[in] | mip_interface | *device_interface - a pointer to the mip_interface structure. |
[in] | u8 | command_set - the command set we are waiting for. |
[in] | u8 | command_descriptor - the command descriptor we are waiting for. |
[out] | u8 | *acknack_response - the resulting ack/nack response from the device. |
[out] | u8 | **response_data - a pointer to a pointer to the response data, NULL if no data field exists. |
[out] | u16 | *response_data_size - size of the response data, 0 if no data field exists. |
[in] | u32 | timeout_ms - the timeout in milliseconds. |
MIP_INTERFACE_OK | If a response was received. |
MIP_INTERFACE_ERROR | If the response was not received in the timeout period. |
This is an internal function.
u16 mip_interface_add_descriptor_set_callback | ( | mip_interface * | device_interface, |
u8 | data_set, | ||
void * | user_ptr, | ||
void(*)(void *user_ptr, u8 *packet, u16 packet_size, u8 callback_type) | packet_callback | ||
) |
Add a callback for the provided descriptor set.
[in] | mip_interface | *device_interface - pointer to the mip interface structure. |
[in] | u8 | data_set - data set used to trigger the callback. |
[in] | void | *user_ptr - pointer to the user data, which is passed to the callback. |
[in] | void | (*packet_callback) - function pointer for packet callback function. |
MIP_INTERFACE_ERROR | The callback could not be added. |
MIP_INTERFACE_OK | The callback was added successfully. |
None.
u16 mip_interface_close | ( | mip_interface * | device_interface | ) |
u16 mip_interface_delete_descriptor_set_callback | ( | mip_interface * | device_interface, |
u8 | data_set | ||
) |
Delete the callback for the provided descriptor set if it exists.
[in] | mip_interface | *device_interface - pointer to the mip interface structure. |
[in] | u8 | data_set - data set to remove callbacks. |
MIP_INTERFACE_ERROR | The callback could not be removed. |
MIP_INTERFACE_OK | The callback was removed successfully. |
None.
u16 mip_interface_init | ( | u32 | com_port, |
u32 | baudrate, | ||
mip_interface * | device_interface, | ||
u32 | packet_timeout_val | ||
) |
MIP Interface Initialization function.
[in] | u32 | com_port - The port to interface to. |
[in] | u32 | baudrate - The baudrate of the port. |
[in] | mip_interface | *device_interface - The device interface. |
[in] | u32 | packet_timeout_val - Timeout for the incoming packet in milliseconds. |
MIP_INTERFACE_ERROR | The interface was not initialized. |
MIP_INTERFACE_OK | The interface was successfully initialized. |
None
u16 mip_interface_send_command | ( | mip_interface * | device_interface, |
u8 | command_set, | ||
u8 | command_descriptor, | ||
u8 * | command_data, | ||
u16 | command_data_size, | ||
u8 | wait_for_response, | ||
u32 | timeout_ms | ||
) |
Send a MIP command and optionally wait for the response data.
[in] | mip_interface | *device_interface - a pointer to the mip_interface structure. |
[in] | u8 | command_set - command set. |
[in] | u8 | command_descriptor - command descriptor. |
[in] | u8 | *command_data - preformatted command data. |
[in] | u16 | command_data_size - size of command data. |
[in] | u8 | wait_for_response - 1: The function will wait for the response, 0: it will not wait. |
[in] | u32 | timeout_ms - the timeout in milliseconds. |
MIP_INTERFACE_OK | If a response was received and ACK'd or no resonse requested. |
MIP_INTERFACE_ERROR | If the response was not received in the timeout period or NACK'd. |
None.
u16 mip_interface_send_command_with_response | ( | mip_interface * | device_interface, |
u8 | command_set, | ||
u8 | command_descriptor, | ||
u8 * | command_data, | ||
u16 | command_data_size, | ||
u8 ** | response_data, | ||
u16 * | response_data_size, | ||
u32 | timeout_ms | ||
) |
Send a MIP command and wait for the response data.
[in] | mip_interface | *device_interface - a pointer to the mip_interface structure. |
[in] | u8 | command_set - command set. |
[in] | u8 | command_descriptor - command descriptor. |
[in] | u8 | *command_data - preformatted command data. |
[in] | u16 | command_data_size - size of command data. |
[out] | u8 | **response_data - pointer to a pointer that will point to the beginning of the response. |
[out] | u16 | *response_data_size - size of the response data. |
[in] | u32 | timeout_ms - the timeout in milliseconds. |
MIP_INTERFACE_OK | If a response was received and ACK'd. |
MIP_INTERFACE_ERROR | If the response was not received in the timeout period or NACK'd. |
response_data
will point to an internal buffer within the MIP interface.
The user should copy the information to their own buffer before manipulation.
u16 mip_interface_send_preformatted_command | ( | mip_interface * | device_interface, |
u8 * | command, | ||
u16 | command_size, | ||
u8 | wait_for_response, | ||
u32 | timeout_ms | ||
) |
Send a pre-formatted command and wait for the response data.
[in] | mip_interface | *device_interface - a pointer to the mip_interface structure. |
[in] | u8 | *command - preformatted MIP command. |
[in] | u16 | command_size - size of MIP command. |
[in] | u8 | wait_for_response - 1: The function will wait for the response, 0: it will not wait. |
[in] | u32 | timeout_ms - the timeout in milliseconds. |
MIP_INTERFACE_OK | If a response was received and ACK'd or no resonse requested. |
MIP_INTERFACE_ERROR | If the response was not received in the timeout period or NACK'd. |
None.
u16 mip_interface_send_preformatted_command_with_response | ( | mip_interface * | device_interface, |
u8 * | command, | ||
u16 | command_size, | ||
u8 ** | response_data, | ||
u16 * | response_data_size, | ||
u32 | timeout_ms | ||
) |
Send a pre-formatted command and wait for the response data.
[in] | mip_interface | *device_interface - a pointer to the mip_interface structure. |
[in] | u8 | *command - preformatted MIP command. |
[in] | u16 | command_size - size of MIP command. |
[out] | u8 | **response_data - pointer to a pointer that will point to the beginning of the response. |
[out] | u16 | *response_data_size - size of the response data. |
[in] | u32 | timeout_ms - the timeout in milliseconds. |
MIP_INTERFACE_OK | If a response was received and ACK'd. |
MIP_INTERFACE_ERROR | If the response was not received in the timeout period or NACK'd. |
response_data
will point to an internal buffer within the MIP interface.
The user should copy the information to their own buffer before manipulation.
u16 mip_interface_update | ( | mip_interface * | device_interface | ) |
MIP Interface Update function.
[in] | mip_interface | *device_interface - The device interface. |
MIP_INTERFACE_ERROR | The interface was not initialized. |
MIP_INTERFACE_OK | The update step completed. |
This function should be called regularly (e.g. every step of a minor cycle.)
This is the main loop of the interface.
u16 mip_interface_write | ( | mip_interface * | device_interface, |
u8 * | data, | ||
u32 | num_bytes, | ||
u32 * | bytes_written | ||
) |
Writes num_bytes
of data
to the device interface.
[in] | mip_interface | *device_interface - pointer to the mip interface structure. |
[in] | u8 | *data - pointer to data buffer to be written. |
[in] | u32 | num_bytes - the number of bytes to be written. |
MIP_INTERFACE_ERROR | Data not written or less than num_bytes written. |
MIP_INTERFACE_OK | Data written. |
This function is used to write bytes from a device to the interface,
which will then be parsed.
u16 mip_interface_write_blocking | ( | mip_interface * | device_interface, |
u8 * | data, | ||
u32 | num_bytes, | ||
u32 * | bytes_written, | ||
u32 | timeout_ms | ||
) |
Writes num_bytes
of data
to the device interface, blocks until the space is available.
[in] | mip_interface | *device_interface - pointer to the mip interface structure. |
[in] | u8 | *data - pointer to data buffer to be written. |
[in] | u32 | num_bytes - the number of bytes to be written. |
[in] | u32 | timeout_ms - the timeout for the write in milliseconds. |
MIP_INTERFACE_ERROR | Data not written or less than num_bytes written. |
MIP_INTERFACE_OK | Data written. |
This function is used to write bytes from a source into the interface,
which will then be parsed.