C MIP-SDK
Data Structures | Defines | Typedefs | Functions
mip.h File Reference
#include "mip_types.h"

Go to the source code of this file.

Data Structures

struct  _mip_header
struct  _mip_field_header
struct  _global_ack_nack_field

Defines

#define MIP_SYNC_BYTE1   0x75
#define MIP_SYNC_BYTE2   0x65
#define MIP_HEADER_SIZE   sizeof(mip_header)
#define MIP_CHECKSUM_SIZE   2
#define MIP_MAX_PAYLOAD_SIZE   255
#define MIP_MAX_PAYLOAD_DATA_SIZE   253
#define MIP_FIELD_HEADER_SIZE   sizeof(mip_field_header)
#define MIP_MAX_PACKET_SIZE   (MIP_HEADER_SIZE + MIP_MAX_PAYLOAD_SIZE + MIP_CHECKSUM_SIZE)
#define MIP_REPLY_DESC_GLOBAL_ACK_NACK   0xF1
#define MIP_DESC_GLOBAL_PRODUCTION_TEST   0xFE
#define MIP_ACK_NACK_ERROR_NONE   0x00
#define MIP_ACK_NACK_ERROR_UNKNOWN_COMMAND   0x01
#define MIP_ACK_NACK_ERROR_CHECKSUM_INVALID   0x02
#define MIP_ACK_NACK_ERROR_PARAMETER_INVALID   0x03
#define MIP_ACK_NACK_ERROR_COMMAND_FAILED   0x04
#define MIP_ACK_NACK_ERROR_COMMAND_TIMEOUT   0x05
#define MIP_ACK_NACK_ERROR_UNKNOWN_DESCRIPTOR_SET   0x06
#define MIP_OK   0
#define MIP_ERROR   1
#define MIP_MEMORY_ERROR   2
#define MIP_FIELD_NOT_AVAILABLE   3
#define MIP_INVALID_PACKET   4
#define MIP_CHECKSUM_ERROR   5
#define MIP_FUNCTION_SELECTOR_WRITE   0x01
#define MIP_FUNCTION_SELECTOR_READ   0x02
#define MIP_FUNCTION_SELECTOR_STORE_EEPROM   0x03
#define MIP_FUNCTION_SELECTOR_LOAD_EEPROM   0x04
#define MIP_FUNCTION_SELECTOR_LOAD_DEFAULT   0x05
#define IS_MIP_FUNCTION_SELECTOR(SELECTOR)

Typedefs

typedef struct _mip_header mip_header
typedef struct _mip_field_header mip_field_header
typedef struct
_global_ack_nack_field 
global_ack_nack_field

Functions

u16 mip_init (u8 *mip_buffer, u16 buffer_size, u8 descriptor_set)
u16 mip_add_field (u8 *mip_buffer, u16 buffer_size, void *field_data, u16 data_size, u16 data_descriptor)
u16 mip_add_formatted_field (u8 *mip_buffer, u16 buffer_size, void *field)
u16 mip_finalize (u8 *mip_buffer)
u16 mip_is_initialized (u8 *mip_buffer, u8 descriptor_set)
u16 mip_is_mip_packet (u8 *mip_buffer)
u8 mip_get_packet_descriptor_set (u8 *mip_buffer)
u8 mip_get_payload_size (u8 *mip_buffer)
u8 * mip_get_payload_ptr (u8 *mip_buffer)
u16 mip_get_packet_size (u8 *mip_buffer)
u16 mip_get_first_field (u8 *mip_buffer, mip_field_header **field_header, u8 **field_data, u16 *field_offset)
u16 mip_get_next_field (u8 *mip_buffer, mip_field_header **field_header, u8 **field_data, u16 *field_offset)
u16 mip_calculate_checksum (u8 *mip_buffer)
u16 mip_is_checksum_valid (u8 *mip_buffer)

Detailed Description

Author:
Nathan Miller
Version:
1.1

Define Documentation

#define IS_MIP_FUNCTION_SELECTOR (   SELECTOR)
Value:
(((SELECTOR) == MIP_FUNCTION_SELECTOR_WRITE)        || \
                                            ((SELECTOR) == MIP_FUNCTION_SELECTOR_READ)         || \
                                            ((SELECTOR) == MIP_FUNCTION_SELECTOR_STORE_EEPROM) || \
                                            ((SELECTOR) == MIP_FUNCTION_SELECTOR_LOAD_EEPROM)  || \
                                            ((SELECTOR) == MIP_FUNCTION_SELECTOR_LOAD_DEFAULT))

Function Documentation

u16 mip_add_field ( u8 *  mip_buffer,
u16  buffer_size,
void *  field_data,
u16  data_size,
u16  data_descriptor 
)

DESCRIPTION

Adds a field to an initialized MIP packet buffer.

DETAILS

Parameters:
[in,out]u8*mip_buffer - pointer to memory used to construct the mip packet.
[in]u16buffer_size - size of the mip mempory buffer.
[in]void*field_data - buffer containing the field data.
[in]u8u16 data_size - size of the field data (exlcuding the field header).
[in]u8u16 data_descriptor - the data descriptor for the field.
Return values:
MIP_OK- field added to MIP packet.
MIP_ERROR- A pointer is NULL.
MIP_MEMORY_ERROR- Not enough room in the mip buffer to add the field or
the packet will be too large for a MIP.

NOTES

None

u16 mip_add_formatted_field ( u8 *  mip_buffer,
u16  buffer_size,
void *  field 
)

DESCRIPTION

Adds a pre-formatted field (header and data already assembled) to an initialized MIP packet buffer.

DETAILS

Parameters:
[in,out]u8*mip_buffer - pointer to memory used to construct the mip packet.
[in]u16buffer_size - size of the mip mempory buffer.
[in]void*field - buffer containing the field (must have header and data already assembled).
Return values:
MIP_OK- field added to MIP packet.
MIP_ERROR- A pointer is NULL.
MIP_MEMORY_ERROR- Not enough room in the mip buffer to add the field or
the packet will be too large for a MIP.

NOTES

None

u16 mip_calculate_checksum ( u8 *  mip_buffer)

DESCRIPTION

Calculates the 16-bit Fletcher checksum for the MIP packet.

DETAILS

Parameters:
[in]u8*mip_buffer - pointer to memory containing the mip packet.
Returns:
The MIP packet checksum, if mip_buffer contains a valid MIP packet.
0x00 otherwise.

NOTES

None

u16 mip_finalize ( u8 *  mip_buffer)

DESCRIPTION

Calculates the MIP checksum and updates the checksum field in the buffer.

DETAILS

Parameters:
[in,out]u8*mip_buffer - pointer to memory used to construct the mip packet.
Returns:
Size of the MIP Packet in bytes.

NOTES

None

u16 mip_get_first_field ( u8 *  mip_buffer,
mip_field_header **  field_header,
u8 **  field_data,
u16 *  field_offset 
)

DESCRIPTION

Gets the first MIP field (a wrapper for mip_get_next_field that makes it easier to use).

DETAILS

Parameters:
[in]u8*mip_buffer - pointer to memory containing the mip packet.
[out]mip_field_header**field_header - pointer to the first field header.
[out]u8**field_data - pointer to the first field data.
[out]u16*field_offset - integer offset from start of packet payload of first field.
Returns:
See mip_get_next_field definition.

NOTES

None

u16 mip_get_next_field ( u8 *  mip_buffer,
mip_field_header **  field_header,
u8 **  field_data,
u16 *  field_offset 
)

DESCRIPTION

Gets the next data field at field_offset.

DETAILS

Parameters:
[in]u8*mip_buffer - pointer to memory containing the mip packet.
[out]mip_field_header**field_header - pointer to the current field header.
[out]u8**field_data - pointer to the current field data.
[in,out]u16*field_offset - integer offset from start of packet payload of next field.
Return values:
MIP_OK- c\ field_header and field_data contain the parsed information.
MIP_ERROR- A pointer is NULL.
MIP_INVALID_PACKET- The buffer does not contain a valid MIP packet.
MIP_FIELD_NOT_AVAILABLE- The requested field does not exist.

NOTES

None

u8 mip_get_packet_descriptor_set ( u8 *  mip_buffer)

DESCRIPTION

Returns the MIP packet descriptor set.

DETAILS

Parameters:
[in]u8*mip_buffer - pointer to memory containing the mip packet.
Returns:
The MIP descriptor set byte if the buffer points to a valid packet.
0x00 otherwise.

NOTES

None

u16 mip_get_packet_size ( u8 *  mip_buffer)

DESCRIPTION

Gets the size of the MIP packet.

DETAILS

Parameters:
[in]u8*mip_buffer - pointer to memory containing the mip packet.
Returns:
0 - An error occurred
Size of the MIP packet, otherwise

NOTES

None

u8* mip_get_payload_ptr ( u8 *  mip_buffer)

DESCRIPTION

Returns a pointer to the start of the MIP payload data.

DETAILS

Parameters:
[in]u8*mip_buffer - pointer to memory containing the mip packet.
Returns:
A pointer to the MIP payload data.
NULL otherwise.

NOTES

None

u8 mip_get_payload_size ( u8 *  mip_buffer)

DESCRIPTION

Returns the MIP payload size.

DETAILS

Parameters:
[in]u8*mip_buffer - pointer to memory containing the mip packet.
Returns:
The MIP payload size if the buffer points to a valid packet.
0x00 otherwise.

NOTES

None

u16 mip_init ( u8 *  mip_buffer,
u16  buffer_size,
u8  descriptor_set 
)

DESCRIPTION

Initialize a MIP packet header.

DETAILS

Parameters:
[out]u8*mip_buffer - pointer to memory used to construct the mip packet.
[in]u16buffer_size - size of the mip memory buffer.
[in]u8descriptor_set - descriptor set field value.
Return values:
MIP_OK- MIP packet initialized.
MIP_ERROR- The pointer is NULL.
MIP_MEMORY_ERROR- Not enough room in the mip buffer.

NOTES

None

u16 mip_is_checksum_valid ( u8 *  mip_buffer)

DESCRIPTION

Returns the state of the MIP packet checksum.

DETAILS

Parameters:
[in]u8*mip_buffer - pointer to memory containing the mip packet.
Return values:
MIP_OK- The checksum is valid.
MIP_ERROR- The pointer is NULL.
MIP_INVALID_PACKET- The buffer does not contain a valid MIP packet.

NOTES

None

u16 mip_is_initialized ( u8 *  mip_buffer,
u8  descriptor_set 
)

DESCRIPTION

Check if a MIP packet is initialized.

DETAILS

Parameters:
[in]u8*mip_buffer - pointer to memory used to construct the mip packet.
[in]u8descriptor_set - expected descriptor set field value.
Return values:
MIP_OK- MIP packet initialized.
MIP_ERROR- The pointer is NULL or the MIP packet is not intialized.

NOTES

None

u16 mip_is_mip_packet ( u8 *  mip_buffer)

DESCRIPTION

Checks if the buffer contains a valid MIP header.

DETAILS

Parameters:
[in,out]u8*mip_buffer - pointer to memory containing the mip packet.
Return values:
MIP_OK- Header is valid.
MIP_ERROR- The pointer is NULL.
MIP_MEMORY_ERROR- The buffer does not contain a valid MIP packet header.

NOTES

None

 All Data Structures Files Functions Defines