HRI board firmware v2.1 Microcontroller firmware of the board used during the HRI labs.

Macros | Functions | Variables
communication.c File Reference
`#include "communication.h"`
`#include "drivers/callback_timers.h"`
`#include "drivers/adc.h"`
`#include "drivers/dac.h"`
`#include "drivers/incr_encoder.h"`
`#include "drivers/hall.h"`
`#include "drivers/uart.h"`
`#include "lib/basic_filter.h"`
`#include "lib/pid.h"`
`#include "lib/utils.h"`
`#include <stdio.h>`
`#include "torque_regulator.h"`

## Macros
#define | STREAMING_PERIOD 1000
#define | COMM_BUFFER_SIZE 4096
#define | DEBUG_MESSAGE_BUFFER_SIZE 1024

## Functions
void | comm_SendPacket (uint8_t type, uint8_t *data, uint16_t dataLength)
| Sends a packet with a header and data bytes. More...
void | comm_SendPacketHeader (uint8_t type)
| Sends manually a packet header. This function should be used along with comm_SendPacketContent(), in order to send very large packets, with minimal memory consumption. Otherwise, comm_SendPacket() should be used instead. More...
void | comm_SendPacketContent (uint8_t *data, uint16_t dataLength)
| Sends manually a part of packet content data. In order to send a very large packet that do not fit in memory, the packet is sent incrementally by calling comm_SendPacketHeader() once, then this function several times. Otherwise, comm_SendPacket() should be used instead. More...
void | comm_HandleByte (uint8_t rxData)
| Processes the received byte to interpret the messages. More...
void | comm_Stream ()
| Generates and sends a data streaming packet. More...
void | comm_GetVar (comm_SyncVar const *syncVar, uint8_t *varValueData)
| Gets the value of a SyncVar. More...
void | comm_SetVar (comm_SyncVar *syncVar, uint8_t *varValueData)
| Sets the value of a SyncVar. More...
void | comm_Init (void)
| Init the communication manager. More...
void | comm_Step (void)
| Updates the communication manager. Send the bytes waiting in the TX buffer, and process the bytes received. More...
void | comm_NotifyReady (void)
| Sends a packet to notify the PC that the board just (re)started. This informs the PC software that the board is ready, and that the variables list can be retrieved. More...
void | comm_monitorVar (const char name[], void *address, comm_VarType type, uint8_t size, comm_VarAccess access)
| Adds a monitored variable to the list, with its address. More...
void | comm_monitorVarFunc (const char name[], comm_VarType type, uint8_t size, void(*getFunc)(void), void(*setFunc)(void))
| Adds a monitored variable to the list, with getter/setter functions. If the getter and setter are set to an actual function address (not NULL), the variable will be READWRITE. If the getter is NULL but setter is not NULL, the variable will be WRITEONLY. If the getter is not NULL the setter is NULL, the variable will be READONLY. If the getter and setter are both NULL, the variable will not be added to the variables list. More...
void | comm_monitorBool (const char name[], bool *address, comm_VarAccess access)
| Adds a monitored bool variable to the list, with its address. More...
void | comm_monitorUint8 (const char name[], uint8_t *address, comm_VarAccess access)
| Adds a monitored uint8_t variable to the list, with its address. More...
void | comm_monitorInt8 (const char name[], int8_t *address, comm_VarAccess access)
| Adds a monitored int8_t variable to the list, with its address. More...
void | comm_monitorUint16 (const char name[], uint16_t *address, comm_VarAccess access)
| Adds a monitored uint16_t variable to the list, with its address. More...
void | comm_monitorInt16 (const char name[], int16_t *address, comm_VarAccess access)
| Adds a monitored int16_t variable to the list, with its address. More...
void | comm_monitorUint32 (const char name[], uint32_t *address, comm_VarAccess access)
| Adds a monitored uint32_t variable to the list, with its address. More...
void | comm_monitorInt32 (const char name[], int32_t *address, comm_VarAccess access)
| Adds a monitored int32_t variable to the list, with its address. More...
void | comm_monitorUint64 (const char name[], uint64_t *address, comm_VarAccess access)
| Adds a monitored uint64_t variable to the list, with its address. More...
void | comm_monitorInt64 (const char name[], int64_t *address, comm_VarAccess access)
| Adds a monitored int64_t variable to the list, with its address. More...
void | comm_monitorFloat (const char name[], float *address, comm_VarAccess access)
| Adds a monitored float variable to the list, with its address. More...
void | comm_monitorDouble (const char name[], double *address, comm_VarAccess access)
| Adds a monitored double variable to the list, with its address. More...
void | comm_monitorBoolFunc (const char name[], bool(*getFunc)(void), void(*setFunc)(bool))
| Adds a monitored bool variable to the list, with getter/setter. More...
void | comm_monitorUint8Func (const char name[], uint8_t(*getFunc)(void), void(*setFunc)(uint8_t))
| Adds a monitored uint8_t variable to the list, with getter/setter. More...
void | comm_monitorInt8Func (const char name[], int8_t(*getFunc)(void), void(*setFunc)(int8_t))
| Adds a monitored int8_t variable to the list, with getter/setter. More...
void | comm_monitorUint16Func (const char name[], uint16_t(*getFunc)(void), void(*setFunc)(uint16_t))
| Adds a monitored uint16_t variable to the list, with getter/setter. More...
void | comm_monitorInt16Func (const char name[], int16_t(*getFunc)(void), void(*setFunc)(int16_t))
| Adds a monitored int16_t variable to the list, with getter/setter. More...
void | comm_monitorUint32Func (const char name[], uint32_t(*getFunc)(void), void(*setFunc)(uint32_t))
| Adds a monitored uint32_t variable to the list, with getter/setter. More...
void | comm_monitorInt32Func (const char name[], int32_t(*getFunc)(void), void(*setFunc)(int32_t))
| Adds a monitored int32_t variable to the list, with getter/setter. More...
void | comm_monitorUint64Func (const char name[], uint64_t(*getFunc)(void), void(*setFunc)(uint64_t))
| Adds a monitored uint64_t variable to the list, with getter/setter. More...
void | comm_monitorInt64Func (const char name[], int64_t(*getFunc)(void), void(*setFunc)(int64_t))
| Adds a monitored int64_t variable to the list, with getter/setter. More...
void | comm_monitorFloatFunc (const char name[], float(*getFunc)(void), void(*setFunc)(float))
| Adds a monitored float variable to the list, with getter/setter. More...
void | comm_monitorDoubleFunc (const char name[], double(*getFunc)(void), void(*setFunc)(double))
| Adds a monitored double variable to the list, with getter/setter. More...
void | comm_LockSyncVarsList (void)
| Locks the monitored variables, so it can be used. After the call to this function, adding variables will not be possible anymore. The PC will not be able to get the variables list until this function is called. More...
void | comm_SendDebugMessage (const char *format,...)
| Sends a debug message to the computer. More...

## Variables
uint32_t | selectedVariablesToStream
uint8_t | txBuffer [1024]
uint8_t | comm_packetTxBuffer [COMM_BUFFER_SIZE]
char | comm_debugMessageBuffer [DEBUG_MESSAGE_BUFFER_SIZE]
cb_CircularBuffer * | comm_rxQueue
uint8_t | rxCurrentMessageType = PC_MESSAGE_DO_NOTHING
uint32_t | rxBytesCount
uint8_t | firstHalfByte
uint8_t | rxDataBytesBuffer [32]
comm_SyncVar | comm_syncVars [N_SYNCVARS_MAX]
uint8_t | comm_nSyncVars
volatile bool | comm_varListLocked
uint8_t | comm_streamId
uint8_t | comm_nVarsToStream
comm_SyncVar const * | comm_streamedVars [N_SYNCVARS_MAX]
volatile uint32_t | hapt_timestamp

## Macro Definition Documentation

## ◆ COMM_BUFFER_SIZE

#define COMM_BUFFER_SIZE 4096

## ◆ DEBUG_MESSAGE_BUFFER_SIZE

#define DEBUG_MESSAGE_BUFFER_SIZE 1024

## ◆ STREAMING_PERIOD

#define STREAMING_PERIOD 1000

## Function Documentation

## ◆ comm_GetVar()

void comm_GetVar | ( | comm_SyncVar const * | syncVar,
|  | uint8_t * | varValueData
| ) |  |

Gets the value of a SyncVar.

Parameters

  syncVar | address of the SyncVar to get the value from.
  varValueData | start address of an array to copy the raw bytes of the value of the SyncVar.

## ◆ comm_HandleByte()

void comm_HandleByte | ( | uint8_t | rxData | ) |

Processes the received byte to interpret the messages.

Parameters

  rxData | the byte to be processed and interpreted.

## ◆ comm_SendPacket()

void comm_SendPacket | ( | uint8_t | type,
|  | uint8_t * | data,
|  | uint16_t | dataLength
| ) |  |

Sends a packet with a header and data bytes.

Parameters

  type | message type ("header" of the message).
  data | array of data bytes to be sent ("content" of the message).
  dataLength | number of data bytes to be sent.

Warning
  If sending a large amount of data, this function will block until all the data could be written to the write buffer, which can be very long.

## ◆ comm_SendPacketContent()

void comm_SendPacketContent | ( | uint8_t * | data,
|  | uint16_t | dataLength
| ) |  |

Sends manually a part of packet content data. In order to send a very large packet that do not fit in memory, the packet is sent incrementally by calling comm_SendPacketHeader() once, then this function several times. Otherwise, comm_SendPacket() should be used instead.

Parameters

  data | array of data bytes to be sent ("content" of the message).
  dataLength | number of data bytes to be sent.

Warning
  If the write buffers are full, this function will block until all the data could be written to the write buffer, which can be very long.

## ◆ comm_SendPacketHeader()

void comm_SendPacketHeader | ( | uint8_t | type | ) |

Sends manually a packet header. This function should be used along with comm_SendPacketContent(), in order to send very large packets, with minimal memory consumption. Otherwise, comm_SendPacket() should be used instead.

Parameters

  type | message type ("header" of the message).

Warning
  If the write buffers are full, this function will block until all the data could be written to the write buffer, which can be very long.

## ◆ comm_SetVar()

void comm_SetVar | ( | comm_SyncVar * | syncVar,
|  | uint8_t * | varValueData
| ) |  |

Sets the value of a SyncVar.

Parameters

  syncVar | address of the SyncVar to set the value.
  varValueData | start address of an array to copy the raw bytes to the SyncVar value.

## ◆ comm_Stream()

void comm_Stream | ( | void |  | ) |

Generates and sends a data streaming packet.

## Variable Documentation

## ◆ comm_debugMessageBuffer

char comm_debugMessageBuffer[DEBUG_MESSAGE_BUFFER_SIZE]

## ◆ comm_nSyncVars

uint8_t comm_nSyncVars

## ◆ comm_nVarsToStream

uint8_t comm_nVarsToStream

## ◆ comm_packetTxBuffer

uint8_t comm_packetTxBuffer[COMM_BUFFER_SIZE]

## ◆ comm_rxQueue

cb_CircularBuffer* comm_rxQueue

## ◆ comm_streamedVars

comm_SyncVar const* comm_streamedVars[N_SYNCVARS_MAX]

## ◆ comm_streamId

uint8_t comm_streamId

## ◆ comm_syncVars

comm_SyncVar comm_syncVars[N_SYNCVARS_MAX]

## ◆ comm_varListLocked

volatile bool comm_varListLocked

## ◆ firstHalfByte

uint8_t firstHalfByte

## ◆ hapt_timestamp

volatile uint32_t hapt_timestamp

## ◆ rxBytesCount

uint32_t rxBytesCount

## ◆ rxCurrentMessageType

uint8_t rxCurrentMessageType = PC_MESSAGE_DO_NOTHING

## ◆ rxDataBytesBuffer

uint8_t rxDataBytesBuffer[32]

## ◆ selectedVariablesToStream

uint32_t selectedVariablesToStream

## ◆ txBuffer

uint8_t txBuffer[1024]