This an example of how to use PLC Universal SerialInterface service" to communicate with the target through a user-defined protocol.
In this file, a template for the serialization of a user-defined protocol is provided. It can be used as a basis to further implement a given desired functionality.
SAM4CP and SAM4S devices can be used.
This template can be used as basis to implement USI support for any user-defined protocol. This is done through the function:
uint8_t serial_if_user_def_api_parser(uint8_t *puc_rx_msg, uint16_t us_len);
This function is used as a callback by USI whenever a message with: TYPE_PROTOCOL = PROTOCOL_USER_DEFINED is received, in order to process it. By extending the capabilities of that function to the user-defined protocol, the USI is provided with the intelligence to support it.
This function receives two parameters:
uint8_t *puc_rx_msg Pointer to the message payload. uint16_t us_len Length of the payload.
As a basis of the user-defined protocol, two primitives have been defined:
SERIAL_IF_USER_DEF_GET_CMD: this primitive gets the value in a given memory address of the target. SERIAL_IF_USER_DEF_SET_CMD: this primitive stores a value in a given memory address of the target.
Respectively, the target will respond to them with:
SERIAL_IF_USER_DEF_GET_CMD_RSP: this primitive contains the value stored in the requested memory address of the target. SERIAL_IF_USER_DEF_SET_CMD_RSP: this primitive simply acknowledges the execution of the set command.
The message format of this protocol template is defined as:
Read command:
[ COMMAND ][ ADDRESS ]
<–1Byte–><–4 Bytes–>
Write command:
[ COMMAND ][ ADDRESS ][ VALUE ]
<–1Byte–><–4 Bytes–><–4 Bytes–>
The list of supported primitives can be extended in the function serial_if_user_def_api_parser() and in the typedef serial_if_user_def_cmd_t as needed by the user-defined protocol.
This template depends on the following modules:
This software was written for the IAR for ARM. Other compilers may or may not work.
For further information, visit Microchip.
Support and FAQ: https://www.microchip.com/support/