C MIP-SDK
|
00001 00002 // 00006 // 00009 // 00010 // External dependencies: 00011 // 00012 // 00013 // 00015 // 00018 // 00028 // 00030 00031 #ifndef _MIP_SDK_INTERFACE_H 00032 #define _MIP_SDK_INTERFACE_H 00033 00034 00036 // 00037 //Include Files 00038 // 00040 00041 #include "mip.h" 00042 #include "mip_sdk_config.h" 00043 #include "mip_sdk_user_functions.h" 00044 #include "ring_buffer.h" 00045 #include "byteswap_utilities.h" 00046 00048 // 00049 // Defines 00050 // 00052 00054 00055 #define MIP_INTERFACE_INPUT_RING_BUFFER_SIZE MIP_MAX_PACKET_SIZE 00056 00057 00058 #define MIP_INTERFACE_CALLBACK_VALID_PACKET 0 00059 #define MIP_INTERFACE_CALLBACK_CHECKSUM_ERROR 1 00060 #define MIP_INTERFACE_CALLBACK_TIMEOUT 2 00061 00062 #define MIP_INTERFACE_OK 0 00063 #define MIP_INTERFACE_ERROR 1 00064 00065 #define MIP_INTERFACE_TIMEOUT 0 00066 #define MIP_INTERFACE_NO_TIMEOUT 1 00067 00068 #define MIP_INTERFACE_INITIALIZED 1 00069 #define MIP_INTERFACE_UNINITIALIZED 0 00070 00071 typedef void (*parser_callback_ptr)(void*, u8*, u16, u8); 00072 00073 00075 // 00076 // Structures 00077 // 00079 00080 typedef struct _mip_interface 00081 { 00082 //State 00083 u8 state; 00084 00085 //Port Handle 00086 void *port_handle; 00087 00088 //Input Ring Buffer 00089 ring_buffer input_buffer; 00090 u8 input_buffer_bytes[MIP_INTERFACE_INPUT_RING_BUFFER_SIZE]; 00091 00092 //MIP Packet Parser variables 00093 u8 mip_packet[MIP_MAX_PACKET_SIZE]; 00094 u16 mip_packet_byte_count; 00095 u32 parser_start_time; 00096 u32 parser_num_bad_checksums; 00097 u32 parser_timeouts; 00098 u8 parser_in_sync; 00099 u32 parser_headers_skipped; 00100 00101 u32 packet_timeout; 00102 00103 //Command/Response Variables 00104 u8 command_response_received; 00105 u8 command_id; 00106 u8 command_acknack_response; 00107 u8 *command_response_data; 00108 u8 command_response_data_size; 00109 00110 //Callback variables 00111 u8 callback_data_set_list[MIP_INTERFACE_MAX_CALLBACKS + 1]; 00112 parser_callback_ptr callback_function_list[MIP_INTERFACE_MAX_CALLBACKS + 1]; 00113 void *callback_user_ptr_list[MIP_INTERFACE_MAX_CALLBACKS + 1]; 00114 00115 }mip_interface; 00116 00117 00119 // 00120 // Function Prototypes 00121 // 00123 00124 u16 mip_interface_init(u32 com_port, u32 baudrate, mip_interface *device_interface, u32 packet_timeout_val); 00125 u16 mip_interface_close(mip_interface *device_interface); 00126 00127 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)); 00128 u16 mip_interface_delete_descriptor_set_callback(mip_interface *device_interface, u8 data_set); 00129 00130 u16 mip_interface_update(mip_interface *device_interface); 00131 00132 u16 mip_interface_send_command(mip_interface *device_interface, u8 command_set, u8 command_descriptor, u8 *command_data, 00133 u16 command_data_size, u8 wait_for_response, u32 timeout_ms); 00134 00135 u16 mip_interface_send_preformatted_command(mip_interface *device_interface, u8 *command, u16 command_size, u8 wait_for_response, u32 timeout_ms); 00136 00137 u16 mip_interface_send_command_with_response(mip_interface *device_interface, u8 command_set, u8 command_descriptor, u8 *command_data, 00138 u16 command_data_size, u8 **response_data, u16 *response_data_size, u32 timeout_ms); 00139 00140 u16 mip_interface_send_preformatted_command_with_response(mip_interface *device_interface, u8 *command, u16 command_size, 00141 u8 **response_data, u16 *response_data_size, u32 timeout_ms); 00142 00143 00144 u16 mip_interface_write(mip_interface *device_interface, u8 *data, u32 num_bytes, u32 *bytes_written); 00145 u16 mip_interface_write_blocking(mip_interface *device_interface, u8 *data, u32 num_bytes, u32 *bytes_written, u32 timeout_ms); 00146 00147 u16 __mip_interface_parse_input_buffer(mip_interface *device_interface); 00148 u16 __mip_interface_find_callback(mip_interface *device_interface, u8 data_set, void **callback_user_ptr, parser_callback_ptr *callback_function); 00149 u16 __mip_interface_time_timeout(u32 initial_time, u32 timeout_ms); 00150 00151 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); 00152 void __mip_interface_command_response_handler(void *user_ptr, u8 *packet, u16 packet_size, u8 callback_type); 00153 00154 00155 #endif