71 lines
2.2 KiB
C
71 lines
2.2 KiB
C
/*
|
||
* Исторический регистровый CAN-протокол BALZAM/TMS2812. Формат идентификаторов и порядок слов
|
||
* относятся именно к этому профилю; общий физический CAN не делает его совместимым с SET v2
|
||
* или протоколом ПМ35.
|
||
*/
|
||
|
||
/**
|
||
* @file balsam_can.h
|
||
* @brief CAN_Bal_2812 extended-CAN register space.
|
||
*
|
||
* The wire layout is used by BALZAM Src/balzam_7/CanSetupBalzam7.c:
|
||
* eCAN MDL precedes MDH on the wire: value2, value3, address/mask, value1.
|
||
* Each word is big-endian; address/mask is at bytes 4..5, not 0..1.
|
||
* BA000x routes PM -> node; BA001x routes node -> PM.
|
||
* The MPU panel uses 745009 / 745019 with the same register layout.
|
||
*/
|
||
#ifndef BALSAM_CAN_H
|
||
#define BALSAM_CAN_H
|
||
|
||
#include <stddef.h>
|
||
#include <stdint.h>
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#define BALSAM_CAN_BASE_ID 0x00BA0000UL
|
||
#define BALSAM_CAN_NODE_COUNT 13U
|
||
#define BALSAM_CAN_DATA_OFFSET 0x10U
|
||
#define BALSAM_CAN_DLC 8U
|
||
#define BALSAM_CAN_REGISTER_COUNT 3U
|
||
|
||
typedef enum {
|
||
BALSAM_CAN_TO_NODE = 0,
|
||
BALSAM_CAN_FROM_NODE = 1
|
||
} balsam_can_direction_t;
|
||
|
||
typedef struct {
|
||
uint8_t device;
|
||
uint8_t direction;
|
||
uint8_t present_mask;
|
||
uint16_t start_address;
|
||
uint16_t values[BALSAM_CAN_REGISTER_COUNT];
|
||
} balsam_can_frame_t;
|
||
|
||
/** Return non-zero for the command/data/terminal IDs used by CAN_Bal_2812. */
|
||
int balsam_can_is_id(uint32_t can_id);
|
||
|
||
/**
|
||
* Decode an 8-byte Balsam frame. Returns 1 on success, 0 for another CAN ID,
|
||
* -1 for invalid arguments and -2 for a Balsam ID with a non-8-byte payload.
|
||
*/
|
||
int balsam_can_decode(uint32_t can_id, const uint8_t *data, size_t size,
|
||
balsam_can_frame_t *output);
|
||
|
||
/** Human-readable Russian name of a CAN_Bal_2812 device. */
|
||
const char *balsam_can_device_name(uint8_t device);
|
||
|
||
/**
|
||
* Format the register name from the CAN_Bal_2812 data table into output.
|
||
* Returns the required length (excluding NUL); an empty string means unknown.
|
||
*/
|
||
size_t balsam_can_register_name(uint8_t device, uint16_t address,
|
||
char *output, size_t output_size);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif /* BALSAM_CAN_H */
|