|
#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "acc_reg_protocol.h"
Go to the source code of this file.
Macros | |
#define | REG_INVALID_ADDRESS 0xffffU |
#define | REG_ERROR_READ_ADDRESS 0xeeeeee00U |
#define | REG_ERROR_READ_OF_WO_REG 0xeeeeee01U |
Enumerations | |
enum | acc_reg_mode_t { REG_MODE_READ_WRITE, REG_MODE_READ, REG_MODE_WRITE, REG_MODE_ERROR } |
Register access mode. More... | |
enum | acc_reg_protocol_state_t { REG_STATE_WAIT_FOR_ADDRESS, REG_STATE_WAIT_FOR_READ_OR_WRITE, REG_STATE_WAIT_FOR_WRITE, REG_STATE_WAIT_FOR_READ, REG_STATE_NACK_NEXT_WRITE } |
Register protocol state. More... | |
Functions | |
static const acc_reg_protocol_t * | get_register_struct (uint16_t register_address) |
Get register struct from protocol struct. More... | |
static void | set_address (uint8_t *buffer) |
Set current register address. More... | |
static bool | register_is_writable (void) |
Return true if register is writable. More... | |
static void | read_register (uint8_t *buffer) |
Read register at current register address and increase address. More... | |
static bool | write_register (uint8_t *buffer) |
Write register at current register address and increase address. More... | |
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... | |
Variables | |
static const acc_reg_protocol_t * | reg_protocol_struct = NULL |
static uint16_t | reg_register_count = 0 |
static acc_reg_protocol_state_t | reg_state = REG_STATE_WAIT_FOR_ADDRESS |
static uint16_t | reg_address = 0xffffU |
static uint32_t | reg_error_flags = 0 |
#define REG_ERROR_READ_ADDRESS 0xeeeeee00U |
Definition at line 39 of file acc_reg_protocol.c.
#define REG_ERROR_READ_OF_WO_REG 0xeeeeee01U |
Definition at line 40 of file acc_reg_protocol.c.
#define REG_INVALID_ADDRESS 0xffffU |
Definition at line 38 of file acc_reg_protocol.c.
enum acc_reg_mode_t |
Register access mode.
Enumerator | |
---|---|
REG_MODE_READ_WRITE | |
REG_MODE_READ | |
REG_MODE_WRITE | |
REG_MODE_ERROR |
Definition at line 17 of file acc_reg_protocol.c.
Register protocol state.
Enumerator | |
---|---|
REG_STATE_WAIT_FOR_ADDRESS | |
REG_STATE_WAIT_FOR_READ_OR_WRITE | |
REG_STATE_WAIT_FOR_WRITE | |
REG_STATE_WAIT_FOR_READ | |
REG_STATE_NACK_NEXT_WRITE |
Definition at line 29 of file acc_reg_protocol.c.
void acc_reg_protocol_data_in | ( | uint8_t * | buffer, |
size_t | data_in_length | ||
) |
Handle data input to the register protocol.
[in] | buffer | The data to be processed by the protocol |
[in] | data_in_length | The byte length of the data to be processed |
Definition at line 230 of file acc_reg_protocol.c.
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.
void acc_reg_protocol_data_out | ( | uint8_t * | buffer, |
size_t | data_out_length | ||
) |
Handle data input from the register protocol.
[in] | buffer | The data buffer to be filled with data |
[in] | data_out_length | The byte length of the data to be read |
Definition at line 294 of file acc_reg_protocol.c.
int32_t acc_reg_protocol_float_to_int32_milli | ( | float | value | ) |
Convert 1000 * float to int32.
[in] | value | A float value |
Definition at line 330 of file acc_reg_protocol.c.
uint32_t acc_reg_protocol_float_to_uint32_milli | ( | float | value | ) |
Convert 1000 * float to uint32.
[in] | value | A float value |
Definition at line 336 of file acc_reg_protocol.c.
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.
float acc_reg_protocol_int32_milli_to_float | ( | int32_t | value | ) |
Convert int32 / 1000 to float.
[in] | value | An int32 value |
Definition at line 342 of file acc_reg_protocol.c.
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.
void acc_reg_protocol_setup | ( | const acc_reg_protocol_t * | protocol_struct, |
uint16_t | register_count | ||
) |
Setup register protocol.
[in] | protocol_struct | The protocol struct with read/write functions |
[in] | register_count | The number of registers in the struct |
Definition at line 202 of file acc_reg_protocol.c.
float acc_reg_protocol_uint32_milli_to_float | ( | uint32_t | value | ) |
Convert uint32 / 1000 to float.
[in] | value | An uint32 value |
Definition at line 351 of file acc_reg_protocol.c.
|
static |
Get register struct from protocol struct.
[in] | register_address | The address of the register |
Definition at line 55 of file acc_reg_protocol.c.
|
static |
Read register at current register address and increase address.
[out] | buffer | The output data buffer |
Definition at line 114 of file acc_reg_protocol.c.
|
static |
Return true if register is writable.
Definition at line 101 of file acc_reg_protocol.c.
|
static |
Set current register address.
[in] | buffer | The input data buffer |
Definition at line 80 of file acc_reg_protocol.c.
|
static |
Write register at current register address and increase address.
[in] | buffer | The input data buffer |
Definition at line 156 of file acc_reg_protocol.c.
|
static |
Definition at line 45 of file acc_reg_protocol.c.
|
static |
Definition at line 46 of file acc_reg_protocol.c.
|
static |
Definition at line 42 of file acc_reg_protocol.c.
|
static |
Definition at line 43 of file acc_reg_protocol.c.
|
static |
Definition at line 44 of file acc_reg_protocol.c.