69 lines
2.0 KiB
C
69 lines
2.0 KiB
C
/**
|
|
* @file periph28335.h
|
|
* @brief Shared PM35/TMS320F28335 register protocol.
|
|
*
|
|
* The protocol is independent from PM67/TMS320F2812 CAN and RS channels.
|
|
* It implements the direct RS232/485 register terminal used by PM35.
|
|
*/
|
|
#ifndef PERIPH28335_H
|
|
#define PERIPH28335_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define PERIPH28335_REGISTER_COUNT 128U
|
|
#define PERIPH28335_REQUEST_SIZE 8U
|
|
#define PERIPH28335_COMMAND_COUNT 17U
|
|
|
|
typedef enum {
|
|
PERIPH28335_OK = 0,
|
|
PERIPH28335_ERROR_ARGUMENT = -1,
|
|
PERIPH28335_ERROR_RANGE = -2,
|
|
PERIPH28335_ERROR_LENGTH = -3,
|
|
PERIPH28335_ERROR_CRC = -4,
|
|
PERIPH28335_ERROR_HEADER = -5,
|
|
PERIPH28335_ERROR_CAPACITY = -6
|
|
} periph28335_status_t;
|
|
|
|
uint16_t periph28335_crc16_modbus(const uint8_t *data, size_t size);
|
|
|
|
size_t periph28335_append_crc(const uint8_t *payload, size_t payload_size,
|
|
uint8_t *output, size_t output_size);
|
|
|
|
size_t periph28335_build_read_registers(
|
|
uint8_t controller, uint16_t start, uint16_t count,
|
|
uint8_t *output, size_t output_size);
|
|
|
|
size_t periph28335_build_write_register(
|
|
uint8_t controller, uint16_t address, uint16_t value,
|
|
uint8_t *output, size_t output_size);
|
|
|
|
size_t periph28335_build_command(
|
|
uint8_t controller, uint8_t command_index,
|
|
uint8_t *output, size_t output_size);
|
|
|
|
size_t periph28335_expected_read_response_size(uint16_t count);
|
|
|
|
int periph28335_decode_read_response(
|
|
const uint8_t *data, size_t size, uint8_t controller, uint16_t count,
|
|
uint16_t *output, size_t output_count);
|
|
|
|
int periph28335_validate_write_response(
|
|
const uint8_t *response, size_t response_size,
|
|
const uint8_t *request, size_t request_size);
|
|
|
|
size_t periph28335_project_count(void);
|
|
const char *periph28335_project_name(size_t project_index);
|
|
const char *periph28335_command_name(size_t project_index,
|
|
size_t command_index);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* PERIPH28335_H */
|