/* * Протокол периферийного контроллера ПМ35/TMS320F28335: регистры, команды и разбор ответов. * Этот профиль имеет собственную адресацию и не должен подменяться протоколом основного * TMS320F2812. */ /** * @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 #include #include "balsam167_eeprom_layout.h" #ifdef __cplusplus extern "C" { #endif #define PERIPH28335_REGISTER_COUNT 128U #define PERIPH28335_REQUEST_SIZE 8U #define PERIPH28335_COMMAND_COUNT 17U /* Balsam-167 fitted AT25256B (marking 5EBL): 256 Kbit, NOT 256 Kbyte. * All reader positions below count physical EEPROM octets, not C28x words. * Four uint32_t fields make the caller-owned state stable for ctypes/JNI. */ #define PERIPH28335_EEPROM_BYTES BALSAM167_EEPROM_BYTES typedef struct { uint32_t controller; uint32_t start; uint32_t length; uint32_t received; } periph28335_eeprom_reader; /* No writes or capacity probes. Odd starts/lengths are allowed: the core reads * the containing 16-bit word and returns only the requested physical octets. */ int periph28335_eeprom_begin(periph28335_eeprom_reader *reader, uint32_t controller, uint32_t start, uint32_t length); size_t periph28335_eeprom_request(const periph28335_eeprom_reader *reader, uint8_t *output, size_t capacity); /* Returns 1/2 decoded octets, or a negative status; errors do not advance state. * PEEK payload = little-endian data WORD + timer WORD, not four memory bytes. * SPI16 shifts the data word high-octet first, so physical EEPROM order is * response[3], response[2]. This differs from a C28x little-endian RAM dump. */ int periph28335_eeprom_accept(periph28335_eeprom_reader *reader, const uint8_t *reply, size_t size, uint8_t *output, size_t capacity); 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 */