C MIP-SDK
Data Structures | Defines | Typedefs | Functions
mip_sdk_interface.h File Reference
#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)

Detailed Description

Author:
Nathan Miller
Version:
1.1

Function Documentation

void __mip_interface_command_response_handler ( void *  user_ptr,
u8 *  packet,
u16  packet_size,
u8  callback_type 
)

DESCRIPTION

Command-Response Handler.

DETAILS

Parameters:
[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]u16packet_size - Size of the MIP packet.
[in]u8callback_type - Type of callback.

NOTES

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 
)

DESCRIPTION

Find the callback info for the provided dataset.

DETAILS

Parameters:
[in]mip_interface*device_interface - pointer to the mip interface structure.
[in]u8data_set - dataset to search for.
[out]void*callback_user_ptr - pointer to the user data for the callback.
[out]parser_callback_ptrcallback_function - pointer to callback function.
Return values:
MIP_INTERFACE_ERRORThe callback could not be located or there was an error.
MIP_INTERFACE_OKThe callback was located.

NOTES

This is an internal function.

u16 __mip_interface_parse_input_buffer ( mip_interface device_interface)

DESCRIPTION

Processes the bytes in the input buffer and triggers the callback function.

DETAILS

Parameters:
[in]mip_interface*device_interface - pointer to the mip interface structure.
Return values:
MIP_INTERFACE_ERRORInterface not initialized.
MIP_INTERFACE_OKParser ran.

NOTES

This is an internal function.

u16 __mip_interface_time_timeout ( u32  initial_time,
u32  timeout_ms 
)

DESCRIPTION

Check for a timeout condition.

DETAILS

Parameters:
[in]u32initial_time - the start time to check against in milliseconds.
[in]u32timeout_ms - the timeout period in milliseconds.
Return values:
MIP_INTERFACE_TIMEOUTThe timeout has occured.
MIP_INTERFACE_NO_TIMEOUTNo timeout.

NOTES

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 
)

DESCRIPTION

Wait for a Command-Response.

DETAILS

Parameters:
[in]mip_interface*device_interface - a pointer to the mip_interface structure.
[in]u8command_set - the command set we are waiting for.
[in]u8command_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]u32timeout_ms - the timeout in milliseconds.
Return values:
MIP_INTERFACE_OKIf a response was received.
MIP_INTERFACE_ERRORIf the response was not received in the timeout period.

NOTES

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 
)

DESCRIPTION

Add a callback for the provided descriptor set.

DETAILS

Parameters:
[in]mip_interface*device_interface - pointer to the mip interface structure.
[in]u8data_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.
Return values:
MIP_INTERFACE_ERRORThe callback could not be added.
MIP_INTERFACE_OKThe callback was added successfully.

NOTES

None.

u16 mip_interface_close ( mip_interface device_interface)

DESCRIPTION

MIP Interface Close function.

DETAILS

Parameters:
[in]mip_interface*device_interface - The device interface.
Return values:
MIP_INTERFACE_ERRORThe interface was not closed.
MIP_INTERFACE_OKThe interface was successfully closed.

NOTES

None

u16 mip_interface_delete_descriptor_set_callback ( mip_interface device_interface,
u8  data_set 
)

DESCRIPTION

Delete the callback for the provided descriptor set if it exists.

DETAILS

Parameters:
[in]mip_interface*device_interface - pointer to the mip interface structure.
[in]u8data_set - data set to remove callbacks.
Return values:
MIP_INTERFACE_ERRORThe callback could not be removed.
MIP_INTERFACE_OKThe callback was removed successfully.

NOTES

None.

u16 mip_interface_init ( u32  com_port,
u32  baudrate,
mip_interface device_interface,
u32  packet_timeout_val 
)

DESCRIPTION

MIP Interface Initialization function.

DETAILS

Parameters:
[in]u32com_port - The port to interface to.
[in]u32baudrate - The baudrate of the port.
[in]mip_interface*device_interface - The device interface.
[in]u32packet_timeout_val - Timeout for the incoming packet in milliseconds.
Return values:
MIP_INTERFACE_ERRORThe interface was not initialized.
MIP_INTERFACE_OKThe interface was successfully initialized.

NOTES

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 
)

DESCRIPTION

Send a MIP command and optionally wait for the response data.

DETAILS

Parameters:
[in]mip_interface*device_interface - a pointer to the mip_interface structure.
[in]u8command_set - command set.
[in]u8command_descriptor - command descriptor.
[in]u8*command_data - preformatted command data.
[in]u16command_data_size - size of command data.
[in]u8wait_for_response - 1: The function will wait for the response, 0: it will not wait.
[in]u32timeout_ms - the timeout in milliseconds.
Return values:
MIP_INTERFACE_OKIf a response was received and ACK'd or no resonse requested.
MIP_INTERFACE_ERRORIf the response was not received in the timeout period or NACK'd.

NOTES

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 
)

DESCRIPTION

Send a MIP command and wait for the response data.

DETAILS

Parameters:
[in]mip_interface*device_interface - a pointer to the mip_interface structure.
[in]u8command_set - command set.
[in]u8command_descriptor - command descriptor.
[in]u8*command_data - preformatted command data.
[in]u16command_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]u32timeout_ms - the timeout in milliseconds.
Return values:
MIP_INTERFACE_OKIf a response was received and ACK'd.
MIP_INTERFACE_ERRORIf the response was not received in the timeout period or NACK'd.

NOTES

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 
)

DESCRIPTION

Send a pre-formatted command and wait for the response data.

DETAILS

Parameters:
[in]mip_interface*device_interface - a pointer to the mip_interface structure.
[in]u8*command - preformatted MIP command.
[in]u16command_size - size of MIP command.
[in]u8wait_for_response - 1: The function will wait for the response, 0: it will not wait.
[in]u32timeout_ms - the timeout in milliseconds.
Return values:
MIP_INTERFACE_OKIf a response was received and ACK'd or no resonse requested.
MIP_INTERFACE_ERRORIf the response was not received in the timeout period or NACK'd.

NOTES

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 
)

DESCRIPTION

Send a pre-formatted command and wait for the response data.

DETAILS

Parameters:
[in]mip_interface*device_interface - a pointer to the mip_interface structure.
[in]u8*command - preformatted MIP command.
[in]u16command_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]u32timeout_ms - the timeout in milliseconds.
Return values:
MIP_INTERFACE_OKIf a response was received and ACK'd.
MIP_INTERFACE_ERRORIf the response was not received in the timeout period or NACK'd.

NOTES

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)

DESCRIPTION

MIP Interface Update function.

DETAILS

Parameters:
[in]mip_interface*device_interface - The device interface.
Return values:
MIP_INTERFACE_ERRORThe interface was not initialized.
MIP_INTERFACE_OKThe update step completed.

NOTES

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 
)

DESCRIPTION

Writes num_bytes of data to the device interface.

DETAILS

Parameters:
[in]mip_interface*device_interface - pointer to the mip interface structure.
[in]u8*data - pointer to data buffer to be written.
[in]u32num_bytes - the number of bytes to be written.
Return values:
MIP_INTERFACE_ERRORData not written or less than num_bytes written.
MIP_INTERFACE_OKData written.

NOTES

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 
)

DESCRIPTION

Writes num_bytes of data to the device interface, blocks until the space is available.

DETAILS

Parameters:
[in]mip_interface*device_interface - pointer to the mip interface structure.
[in]u8*data - pointer to data buffer to be written.
[in]u32num_bytes - the number of bytes to be written.
[in]u32timeout_ms - the timeout for the write in milliseconds.
Return values:
MIP_INTERFACE_ERRORData not written or less than num_bytes written.
MIP_INTERFACE_OKData written.

NOTES

This function is used to write bytes from a source into the interface,
which will then be parsed.

 All Data Structures Files Functions Defines