Microchip® Advanced Software Framework

usi.c File Reference

PLC Service Universal Serial Interface.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include <stdio.h>
#include <string.h>
#include "conf_usi.h"
#include "asf.h"

Data Structures

struct  cmd_params_t
 
struct  map_buffers_t
 
struct  map_ports_t
 
struct  map_protocols_t
 
struct  USI_param_t
 

Macros

#define MIN_OVERHEAD   5
 
#define UART_TYPE   0
 
#define USART_TYPE   1
 
#define MSGMARK   0x7e
 
#define ESC_MSGMARK   0x5e
 
#define ESCMARK   0x7d
 
#define ESC_ESCMARK   0x5d
 
#define MSG_START   1
 
#define MSG_END   0
 
#define HEADER_LEN   2
 
#define CRC8_LEN   1
 
#define CRC16_LEN   2
 
#define CRC32_LEN   4
 
USI flow control internal protocol
#define PROTOCOL_INTERNAL   0x3F
 
#define CMD_LOCK_PORT   0
 
#define CMD_UNLOCK_PORT   1
 
#define INTERNAL_MSG_LEN   1
 
#define MAX_ESCAPED_INTERNAL_MSG_LEN   10
 
#define TX_BLOCK_TIMEOUT   50
 
#define RX_BLOCK_TIMEOUT   50
 
#define TXRX_BLOCK_UPDATE   1
 
#define TYPE_PROTOCOL_OFFSET   1
 
#define TYPE_PROTOCOL_MSK   0x3F
 
#define LEN_PROTOCOL_HI_OFFSET   0
 
#define LEN_PROTOCOL_HI_MSK   0xFF
 
#define LEN_PROTOCOL_HI_SHIFT   2
 
#define LEN_PROTOCOL_LO_OFFSET   1
 
#define LEN_PROTOCOL_LO_MSK   0xC0
 
#define LEN_PROTOCOL_LO_SHIFT   6
 
#define XLEN_PROTOCOL_OFFSET   2
 
#define XLEN_PROTOCOL_MSK   0xC0
 
#define XLEN_PROTOCOL_SHIFT_L   4
 
#define XLEN_PROTOCOL_SHIFT_R   10
 
#define PAYLOAD_OFFSET   2
 
#define CMD_PROTOCOL_OFFSET   2
 
#define CMD_PROTOCOL_MSK   0x3F
 

Enumerations

enum  {
  RX_IDLE,
  RX_MSG,
  RX_ESC,
  RX_EORX
}
 
enum  {
  TX_IDLE,
  TX_MSG
}
 

Functions

static void _cbInternalProtocol (uint8_t uc_port_idx, uint8_t uc_cmd)
 This function decodes internal protocol messages. More...
 
static uint16_t _decode_copy (uint8_t *puc_dest, uint8_t *puc_orig, uint16_t us_size)
 Decodes the escape sequences and copies the result into the destination buffer. More...
 
static uint8_t _doEoMsg (uint8_t uc_port)
 This function processes received message. More...
 
static uint8_t _getPortFromProtocol (uint8_t uc_p_type)
 This function extracts the port where the protocol is mapped to. More...
 
static uint8_t _process_msg (uint8_t uc_port)
 This function processes the complete received message. More...
 
static usi_status_t _usi_encode_and_send (uint8_t uc_port_idx, cmd_params_t *msg)
 Encodes the escape characters and transmits the message. More...
 
uint8_t baseMng_receivedCmd (uint8_t *puc_rx_msg, uint16_t us_len)))
 
uint8_t Dummy_serial_parser (uint8_t *puc_rx_msg, uint16_t us_len)
 Dummy serialization function. More...
 
uint8_t mngl_rcv_cmd (uint8_t *puc_rx_msg, uint16_t us_len)))
 
uint8_t phySerial_receivedCmd (uint8_t *puc_rx_msg, uint16_t us_len)))
 
uint8_t serial_432_if_api_parser (uint8_t *puc_rx_msg, uint16_t us_len)))
 Received message. More...
 
uint8_t serial_if_api_parser (uint8_t *puc_rx_msg, uint16_t us_len)))
 Received message. More...
 
uint8_t serial_if_mac_api_parser (uint8_t *puc_rx_msg, uint16_t us_len)))
 Received message. More...
 
uint8_t serial_if_mlme_api_parser (uint8_t *puc_rx_msg, uint16_t us_len)))
 Received message. More...
 
uint8_t serial_if_plme_api_parser (uint8_t *puc_rx_msg, uint16_t us_len)))
 Received message. More...
 
uint8_t serial_if_sniffer_api_parser (uint8_t *puc_rx_msg, uint16_t us_len)))
 Received message. More...
 
uint8_t serial_if_user_def_api_parser (uint8_t *puc_rx_msg, uint16_t us_len)))
 Task to manage the serialization of the user defined protocol. More...
 
usi_status_t usi_send_cmd (void *msg)
 Function to transmit data through USI. More...
 
Universal Serial Interface API functions
void usi_txrx_block_timer (void)
 Function that updates the USI flow control timers. More...
 
void usi_process (void)
 Function to perform the USI RX process. More...
 
void usi_init (void)
 Create RX and TX USI tasks, and timer to update internal counters. More...
 

Variables

pf_usi_decode_cmd cbFnPhySerial = NULL
 
static uint8_t puc_rx_aux_buf [TXAUX_SIZE+2]
 
static uint8_t puc_tx_aux_buf [TXAUX_SIZE+2]
 
static const map_buffers_t usi_aux_rx_buf = {2 * TXAUX_SIZE + 2, &puc_rx_aux_buf[0]}
 
static const map_buffers_t usi_aux_tx_buf = {TXAUX_SIZE + 2, &puc_tx_aux_buf[0]}
 
const map_buffers_t *const usi_cfg_aux_rx_buf = &usi_aux_rx_buf
 
const map_buffers_t *const usi_cfg_aux_tx_buf = &usi_aux_tx_buf
 
const map_ports_t *const usi_cfg_map_ports = &usiMapPorts[0]
 
const map_protocols_t *const usi_cfg_map_protocols = &usi_map_protocols[0]
 
static USI_param_t usi_cfg_param [NUM_PORTS]
 
map_buffers_t *const usi_cfg_rx_buf = &usi_rx_buf[0]
 
const map_buffers_t *const usi_cfg_tx_buf = &usi_tx_buf[0]
 
Port Mapping. Configured with the values provided in conf_usi.h:

MapPorts[PORT TYPE, PORT CHANNEL, PORT SPEED, TX BUFFER SIZE, RX BUFFER SIZE]

static const map_ports_t usiMapPorts [NUM_PORTS+1]
 

Macro operators

#define TYPE_PROTOCOL(A)   ((A)&TYPE_PROTOCOL_MSK)
 
#define LEN_PROTOCOL(A, B)   ((((uint16_t)(A)) << LEN_PROTOCOL_HI_SHIFT) + ((B) >> LEN_PROTOCOL_LO_SHIFT))
 
#define XLEN_PROTOCOL(A, B, C)   ((((uint16_t)(A)) << LEN_PROTOCOL_HI_SHIFT) + ((B) >> LEN_PROTOCOL_LO_SHIFT) + (((uint16_t)(C)&XLEN_PROTOCOL_MSK) << XLEN_PROTOCOL_SHIFT_L))
 
#define LEN_HI_PROTOCOL(A)   (((uint16_t)(A) >> LEN_PROTOCOL_HI_SHIFT) & LEN_PROTOCOL_HI_MSK)
 
#define LEN_LO_PROTOCOL(A)   (((uint16_t)(A) << LEN_PROTOCOL_LO_SHIFT) & LEN_PROTOCOL_LO_MSK)
 
#define LEN_EX_PROTOCOL(A)   (((uint16_t)(A & 0x0c00)) >> 4)
 
#define CMD_PROTOCOL(A)   ((A)&CMD_PROTOCOL_MSK)
 
static uint8_t uc_message_status
 
cmd_params_t internal_command
 
uint8_t uc_int_cmd_lock = CMD_LOCK_PORT
 
uint8_t uc_int_cmd_unlock = CMD_UNLOCK_PORT
 

Protocol Mapping. Configured with the values provided in conf_usi.h:

#define CONF_PORT(type, channel, speed, tx_size, rx_size)   {type, channel, speed, tx_size, rx_size}
 
#define CONF_PORT(type, channel, speed, tx_size, rx_size)   rx_size
 
#define CONF_PORT(type, channel, speed, tx_size, rx_size)   tx_size
 
#define TXAUX_SIZE   0
 
static const map_protocols_t usi_map_protocols [NUM_PROTOCOLS+1]
 
static map_buffers_t usi_rx_buf [NUM_PORTS+1]
 
static const map_buffers_t usi_tx_buf [NUM_PORTS+1]