acc_reg_protocol.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  acc_reg_protocol_t
 Register access mode and functions struct. More...
 

Macros

#define ACC_REG_PROTOCOL_ADDRESS_LENGTH   (2U)
 
#define ACC_REG_PROTOCOL_REGDATA_LENGTH   (4U)
 
#define ACC_REG_ERROR_FLAG_PROTOCOL_STATE_ERROR   (1U << 0U)
 
#define ACC_REG_ERROR_FLAG_PACKET_LENGTH_ERROR   (1U << 1U)
 
#define ACC_REG_ERROR_FLAG_ADDRESS_ERROR   (1U << 2U)
 
#define ACC_REG_ERROR_FLAG_WRITE_FAILED   (1U << 3U)
 
#define ACC_REG_ERROR_FLAG_WRITE_TO_READ_ONLY   (1U << 4U)
 

Typedefs

typedef void() acc_reg_read_func_t(uint32_t *data)
 Function to read a register. More...
 
typedef bool() acc_reg_write_func_t(const uint32_t data)
 Function to writes a register. More...
 

Functions

void acc_reg_protocol_setup (const acc_reg_protocol_t *protocol_struct, uint16_t register_count)
 Setup register protocol. More...
 
void acc_reg_protocol_reset (void)
 Reset register protocol. More...
 
bool acc_reg_protocol_data_nack (void)
 Should protocol NACK the next data. More...
 
void acc_reg_protocol_data_in (uint8_t *buffer, size_t data_in_length)
 Handle data input to the register protocol. More...
 
void acc_reg_protocol_data_out (uint8_t *buffer, size_t data_out_length)
 Handle data input from the register protocol. More...
 
uint32_t acc_reg_protocol_get_error_flags (void)
 Get the error flags for the register protocol. More...
 
int32_t acc_reg_protocol_float_to_int32_milli (float value)
 Convert 1000 * float to int32. More...
 
uint32_t acc_reg_protocol_float_to_uint32_milli (float value)
 Convert 1000 * float to uint32. More...
 
float acc_reg_protocol_int32_milli_to_float (int32_t value)
 Convert int32 / 1000 to float. More...
 
float acc_reg_protocol_uint32_milli_to_float (uint32_t value)
 Convert uint32 / 1000 to float. More...
 

Macro Definition Documentation

◆ ACC_REG_ERROR_FLAG_ADDRESS_ERROR

#define ACC_REG_ERROR_FLAG_ADDRESS_ERROR   (1U << 2U)

Definition at line 16 of file acc_reg_protocol.h.

◆ ACC_REG_ERROR_FLAG_PACKET_LENGTH_ERROR

#define ACC_REG_ERROR_FLAG_PACKET_LENGTH_ERROR   (1U << 1U)

Definition at line 15 of file acc_reg_protocol.h.

◆ ACC_REG_ERROR_FLAG_PROTOCOL_STATE_ERROR

#define ACC_REG_ERROR_FLAG_PROTOCOL_STATE_ERROR   (1U << 0U)

Definition at line 14 of file acc_reg_protocol.h.

◆ ACC_REG_ERROR_FLAG_WRITE_FAILED

#define ACC_REG_ERROR_FLAG_WRITE_FAILED   (1U << 3U)

Definition at line 17 of file acc_reg_protocol.h.

◆ ACC_REG_ERROR_FLAG_WRITE_TO_READ_ONLY

#define ACC_REG_ERROR_FLAG_WRITE_TO_READ_ONLY   (1U << 4U)

Definition at line 18 of file acc_reg_protocol.h.

◆ ACC_REG_PROTOCOL_ADDRESS_LENGTH

#define ACC_REG_PROTOCOL_ADDRESS_LENGTH   (2U)

Definition at line 11 of file acc_reg_protocol.h.

◆ ACC_REG_PROTOCOL_REGDATA_LENGTH

#define ACC_REG_PROTOCOL_REGDATA_LENGTH   (4U)

Definition at line 12 of file acc_reg_protocol.h.

Typedef Documentation

◆ acc_reg_read_func_t

typedef void() acc_reg_read_func_t(uint32_t *data)

Function to read a register.

Parameters
[out]dataThe data to be read

Definition at line 25 of file acc_reg_protocol.h.

◆ acc_reg_write_func_t

typedef bool() acc_reg_write_func_t(const uint32_t data)

Function to writes a register.

Parameters
[in]dataThe data to be written
Returns
The access result OK/ERROR

Definition at line 33 of file acc_reg_protocol.h.

Function Documentation

◆ acc_reg_protocol_data_in()

void acc_reg_protocol_data_in ( uint8_t *  buffer,
size_t  data_in_length 
)

Handle data input to the register protocol.

Parameters
[in]bufferThe data to be processed by the protocol
[in]data_in_lengthThe byte length of the data to be processed
  • Read only register
  • No valid address, read is still possoble
  • Write register failed
  • Next register is read only

Definition at line 230 of file acc_reg_protocol.c.

◆ acc_reg_protocol_data_nack()

bool acc_reg_protocol_data_nack ( void  )

Should protocol NACK the next data.

Return true if protocol should nack the next data write

Definition at line 218 of file acc_reg_protocol.c.

◆ acc_reg_protocol_data_out()

void acc_reg_protocol_data_out ( uint8_t *  buffer,
size_t  data_out_length 
)

Handle data input from the register protocol.

Parameters
[in]bufferThe data buffer to be filled with data
[in]data_out_lengthThe byte length of the data to be read

Definition at line 294 of file acc_reg_protocol.c.

◆ acc_reg_protocol_float_to_int32_milli()

int32_t acc_reg_protocol_float_to_int32_milli ( float  value)

Convert 1000 * float to int32.

Parameters
[in]valueA float value
Returns
The float value * 1000 as an int32

Definition at line 330 of file acc_reg_protocol.c.

◆ acc_reg_protocol_float_to_uint32_milli()

uint32_t acc_reg_protocol_float_to_uint32_milli ( float  value)

Convert 1000 * float to uint32.

Parameters
[in]valueA float value
Returns
The float value * 1000 as an uint32

Definition at line 336 of file acc_reg_protocol.c.

◆ acc_reg_protocol_get_error_flags()

uint32_t acc_reg_protocol_get_error_flags ( void  )

Get the error flags for the register protocol.

The error flags will be cleared by this call

ACC_REG_ERROR_FLAG_PROTOCOL_STATE_ERROR The flag will be set if for example the protocol got unexpected data

ACC_REG_ERROR_FLAG_PACKET_LENGTH_ERROR The flag will be set if for example the protocol got data with unexpected length

ACC_REG_ERROR_FLAG_ADDRESS_ERROR The flag will be set if a register address outside the address space is used

ACC_REG_ERROR_FLAG_WRITE_FAILED The flag will be set if a register write failed

ACC_REG_ERROR_FLAG_WRITE_TO_READ_ONLY The flag will be set if a read only register is written

Return The protocol error flags

Definition at line 319 of file acc_reg_protocol.c.

◆ acc_reg_protocol_int32_milli_to_float()

float acc_reg_protocol_int32_milli_to_float ( int32_t  value)

Convert int32 / 1000 to float.

Parameters
[in]valueAn int32 value
Returns
The int32 value / 1000 as a float

Definition at line 342 of file acc_reg_protocol.c.

◆ acc_reg_protocol_reset()

void acc_reg_protocol_reset ( void  )

Reset register protocol.

This function should be called when a new transaction start.

Definition at line 211 of file acc_reg_protocol.c.

◆ acc_reg_protocol_setup()

void acc_reg_protocol_setup ( const acc_reg_protocol_t protocol_struct,
uint16_t  register_count 
)

Setup register protocol.

Parameters
[in]protocol_structThe protocol struct with read/write functions
[in]register_countThe number of registers in the struct

Definition at line 202 of file acc_reg_protocol.c.

◆ acc_reg_protocol_uint32_milli_to_float()

float acc_reg_protocol_uint32_milli_to_float ( uint32_t  value)

Convert uint32 / 1000 to float.

Parameters
[in]valueAn uint32 value
Returns
The uint32 value / 1000 as a float

Definition at line 351 of file acc_reg_protocol.c.