1 /*******************************************************************
6 *******************************************************************/
12 /** LOCAL DEFINITIONS **/
21 #define SSP_TX_IDLE 0 // not expecting a ACK packet (no current transmissions in progress)
22 #define SSP_TX_WAITING 1 // waiting for a valid ACK to arrive
23 #define SSP_TX_TIMEOUT 2 // failed to receive a valid ACK in the timeout period, after retrying.
24 #define SSP_TX_ACKED 3 // valid ACK received before timeout period.
25 #define SSP_TX_BUFOVERRUN 4 // amount of data to send execeds the transmission buffer sizeof
26 #define SSP_TX_BUSY 5 // Attempted to start a transmission while a transmission was already in progress.
27 // #define SSP_TX_FAIL - failure...
30 #define SSP_RX_RECEIVING 1
31 #define SSP_RX_COMPLETE 2
33 // types of packet that can be received
36 #define SSP_RX_SYNCH 7
38 typedef enum decodeState_
{
47 typedef enum ReceiveState
{
60 uint8_t *rxBuf
; // Buffer used to store rcv data
61 uint16_t rxBufSize
; // rcv buffer size.
62 uint8_t *txBuf
; // Length of data in buffer
63 uint16_t txBufSize
; // CRC for data in Packet buff
64 uint16_t max_retry
; // Maximum number of retrys for a single transmit.
65 int32_t timeoutLen
; // how long to wait for each retry to succeed
66 void (*pfCallBack
)(uint8_t *, uint16_t); // call back function that is called when a full packet has been received
67 int16_t (*pfSerialRead
)(void); // function to call to read a byte from serial hardware
68 void (*pfSerialWrite
)(uint8_t); // function used to write a byte to serial hardware for transmission
69 uint32_t (*pfGetTime
)(void); // function returns time in number of seconds that has elapsed from a given reference point
72 typedef struct Port_tag
{
73 void (*pfCallBack
)(uint8_t *, uint16_t); // call back function that is called when a full packet has been received
74 int16_t (*pfSerialRead
)(void); // function to read a character from the serial input stream
75 void (*pfSerialWrite
)(uint8_t); // function to write a byte to be sent out the serial port
76 uint32_t (*pfGetTime
)(void); // function returns time in number of seconds that has elapsed from a given reference point
77 uint8_t retryCount
; // how many times have we tried to transmit the 'send' packet
78 uint8_t maxRetryCount
; // max. times to try to transmit the 'send' packet
79 int32_t timeoutLen
; // how long to wait for each retry to succeed
80 int32_t timeout
; // current timeout. when 'time' reaches this point we have timed out
81 uint8_t txSeqNo
; // current 'send' packet sequence number
82 uint16_t rxBufPos
; // current buffer position in the receive packet
83 uint16_t rxBufLen
; // number of 'data' bytes in the buffer
84 uint8_t rxSeqNo
; // current 'receive' packet number
85 uint16_t rxBufSize
; // size of the receive buffer.
86 uint16_t txBufSize
; // size of the transmit buffer.
87 uint8_t *txBuf
; // transmit buffer. REquired to store a copy of packet data in case a retry is needed.
88 uint8_t *rxBuf
; // receive buffer. Used to store data as a packet is received.
89 uint16_t sendSynch
; // flag to indicate that we should send a synchronize packet to the host
90 // this is required when switching from the application to the bootloader
91 // and vice-versa. This fixes the firwmare download timeout.
92 // when this flag is set to true, the next time we send a packet we will first
93 // send a synchronize packet.
94 ReceiveState_t InputState
;
95 DecodeState_t DecodeState
;
106 /** PUBLIC FUNCTIONS **/
107 int16_t ssp_ReceiveProcess(Port_t
*thisport
);
108 int16_t ssp_SendProcess(Port_t
*thisport
);
109 uint16_t ssp_SendString(Port_t
*thisport
, char *str
);
110 int16_t ssp_SendData(Port_t
*thisport
, const uint8_t *data
, const uint16_t length
);
111 void ssp_Init(Port_t
*thisport
, const PortConfig_t
*const info
);
112 int16_t ssp_ReceiveByte(Port_t
*thisport
);
113 uint16_t ssp_Synchronise(Port_t
*thisport
);
116 /** EXTERNAL FUNCTIONS **/
118 #endif // ifndef SSP_H