59 lines
1.8 KiB
C
59 lines
1.8 KiB
C
#ifndef SUPERCAP_H
|
|
#define SUPERCAP_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#define SUPERCAP_TX_ID 0x001U//C板->超电控制帧标准ID
|
|
#define SUPERCAP_RX_ID 0x100U//超电->C板反馈帧标准ID
|
|
#define SUPERCAP_DLC 8U //CAN帧数据长度
|
|
#define SUPERCAP_TX_PERIOD_MS 10U //发送周期(10ms=100Hz)
|
|
#define SUPERCAP_OFFLINE_TIME_MS 200U //超电反馈超时掉线判定(ms)
|
|
|
|
/* 超级电容反馈状态结构体 */
|
|
typedef struct
|
|
{
|
|
uint8_t ready; //就绪标志(1=超电板就绪可放电)
|
|
uint8_t cap_state; //超电工作状态码
|
|
uint8_t energy; //电容剩余能量百分比(0~100)
|
|
uint32_t last_tick; //最近一次收到反馈的时间戳(ms)
|
|
uint32_t rx_cnt; //反馈接收计数
|
|
uint32_t tx_cnt; //控制帧发送成功计数
|
|
uint32_t tx_err; //控制帧发送失败计数
|
|
} supercap_fdb_t;
|
|
|
|
/*
|
|
*函数简介:初始化超级电容模块并注册CAN1 0x100接收回调
|
|
*参数说明:无
|
|
*返回类型:无
|
|
*备注:必须在can_start()之后由CAN_Task调用
|
|
*/
|
|
extern void supercap_init(void);
|
|
|
|
/*
|
|
*函数简介:按100Hz周期向超级电容发送使能与输入功率上限指令(0x001)
|
|
*参数说明:enable:1=使能超电,0=关闭超电
|
|
*参数说明:power_limit_w:当前裁判系统允许输入功率上限(W)
|
|
*返回类型:无
|
|
*备注:内部按SUPERCAP_TX_PERIOD_MS分频发送
|
|
*/
|
|
extern void supercap_update_tx(uint8_t enable, uint8_t power_limit_w);
|
|
|
|
/*
|
|
*函数简介:查询超级电容是否在线
|
|
*参数说明:无
|
|
*返回类型:uint8_t:1=在线,0=离线或超时
|
|
*备注:无
|
|
*/
|
|
extern uint8_t supercap_is_online(void);
|
|
|
|
/*
|
|
*函数简介:获取超级电容最新反馈状态只读指针
|
|
*参数说明:无
|
|
*返回类型:const supercap_fdb_t *:反馈结构体指针
|
|
*备注:无
|
|
*/
|
|
extern const supercap_fdb_t * supercap_get_fdb(void);
|
|
|
|
#endif
|
|
|