brazos-trapezoidal
Classes | Macros | Enumerations | Functions
Tsp.c File Reference

Theta Serial Protocol (TSP) More...

#include "Tsp.h"
#include "Version.h"
#include <string.h>
#include "Tsp_prv.h"
#include "Crc16.h"
Include dependency graph for Tsp.c:

Go to the source code of this file.

Classes

struct  ACK_STRUCT_TYPE
 

Macros

#define TSP_NUM_PARSERS   (sizeof(TSP_PARSER)/sizeof(TSP_PARSER_TYPE))
 defines how many parsers were defined in the prv list More...
 
#define CHARTOLONG(x, y)   (int16_t)((x << 8) + y)
 

Enumerations

enum  ACK_TYPE { ACK_IDLE , ACK_WAITTING , ACK_RETRY , ACK_ERROR }
 
enum  RXTX_DATA_TYPE { RX_DATA , TX_DATA }
 

Functions

void checkreceivedack (void)
 
_Bool TspCheckCRC (RXTX_DATA_TYPE txrx)
 
unsigned short int CRCMessageCalc (RXTX_DATA_TYPE txrx)
 
void Tsp__Initialize (void)
 It Initializes the module Tsp and its variables. More...
 
void Tsp__FastHandler (void)
 
void Tsp__SlowHandler (void)
 
BOOL_TYPE Tsp__Send (BOOL_TYPE wait_ack)
 Method to send Tsp message. More...
 
void Tsp__LoadData (unsigned char adress, unsigned char num_of_bytes, unsigned char api, unsigned char *data)
 

Detailed Description

Theta Serial Protocol (TSP)

SB - Start Byte (AA), From Address (0-255),To Address (0-255), NB - Number of Bytes (only data) API (0-255), Data (0-248 bytes) , CRC16 (2 bytes)

Version
S00_00_01 Aug 20, 2020

Definition in file Tsp.c.

Macro Definition Documentation

◆ CHARTOLONG

#define CHARTOLONG (   x,
  y 
)    (int16_t)((x << 8) + y)

Definition at line 57 of file Tsp.c.

◆ TSP_NUM_PARSERS

#define TSP_NUM_PARSERS   (sizeof(TSP_PARSER)/sizeof(TSP_PARSER_TYPE))

defines how many parsers were defined in the prv list

Definition at line 54 of file Tsp.c.

Enumeration Type Documentation

◆ ACK_TYPE

enum ACK_TYPE

-----------------------------— Theta Power Systems - CONFIDENTIAL --------------------------------------------—

Definition at line 25 of file Tsp.c.

◆ RXTX_DATA_TYPE

enum RXTX_DATA_TYPE

Definition at line 33 of file Tsp.c.

Function Documentation

◆ checkreceivedack()

void checkreceivedack ( void  )

Definition at line 472 of file Tsp.c.

◆ CRCMessageCalc()

unsigned short int CRCMessageCalc ( RXTX_DATA_TYPE  txrx)

Definition at line 433 of file Tsp.c.

◆ Tsp__FastHandler()

void Tsp__FastHandler ( void  )
@brief      Fast Handler for the module
@details    Must be called at a fast rate (1ms)

Checks if there is a new message in the Serial buffer.

Check pass_phrase in the package (last 2 bytes before the CRC)

Checks if the message is for this node or if it is a broadcast

If message was not for this node ignore it

Check CRC, if bad crc cleans the message

If is a discovery package

If the control pass phrase is wrong, send a bad ACK

If the version pass phrase is wrong, send a bad ACK

If the message was for this node and the crc is ok, Send AcK Also runs the APIs parsed functions

Runs the APIs receive functions defined in the prv file

Load ACK data to RX

If the message is an ack

Definition at line 132 of file Tsp.c.

◆ Tsp__Initialize()

void Tsp__Initialize ( void  )

It Initializes the module Tsp and its variables.

Definition at line 73 of file Tsp.c.

◆ Tsp__LoadData()

void Tsp__LoadData ( unsigned char  adress,
unsigned char  num_of_bytes,
unsigned char  api,
unsigned char *  data 
)

Definition at line 370 of file Tsp.c.

◆ Tsp__Send()

BOOL_TYPE Tsp__Send ( BOOL_TYPE  wait_ack)

Method to send Tsp message.

This method will send the data previously loaded to TX_Tsp_Data, it will check first if there is free space in the Ack Buffer before sending the message. Also it is necessary to define if this is a retry message, so it will not create another Ack.

Parameters
_Boolwait_ack: TRUE_T for wait to receiving an Ack, FALSE_T if this is not to wait for an ack retry message.
Returns
BOOL_TYPE ack_buffer_free: TRUE_T is message was accepted, FALSE_T if Ack buffer is full.

Find free buffer space

If there Ack Buffer is Full the new message will not be loaded.

If not sending Ack and there is space in the Ack Buffer, wait for Ack

Definition at line 294 of file Tsp.c.

◆ Tsp__SlowHandler()

void Tsp__SlowHandler ( void  )
@brief      Slow Handler for the module
@details    Can be called at a slower rate (around 5ms or 25ms)

Verify if there is any waiting Ack message

Definition at line 250 of file Tsp.c.

◆ TspCheckCRC()

_Bool TspCheckCRC ( RXTX_DATA_TYPE  txrx)

Definition at line 397 of file Tsp.c.