god-yuan-hero/User/task/supercap.c
2025-12-07 14:35:28 +08:00

51 lines
2.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
supercap Task
*/
/* Includes ----------------------------------------------------------------- */
#include "task/user_task.h"
/* USER INCLUDE BEGIN */
#include "device/supercap.h"
/* USER INCLUDE END */
/* Private typedef ---------------------------------------------------------- */
/* Private define ----------------------------------------------------------- */
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* USER STRUCT BEGIN */
CAN_SuperCapTXDataTypeDef SuperCap_CanTX;
/* USER STRUCT END */
/* Private function --------------------------------------------------------- */
/* Exported functions ------------------------------------------------------- */
void Task_supercap(void *argument) {
(void)argument; /* 未使用argument消除警告 */
/* 计算任务运行到指定频率需要等待的tick数 */
const uint32_t delay_tick = osKernelGetTickFreq() / SUPERCAP_FREQ;
osDelay(SUPERCAP_INIT_DELAY); /* 延时一段时间再开启任务 */
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
/* USER CODE INIT BEGIN */
SuperCap_Init();
SuperCap_CanTX.Enable = 1 ; //超级电容使能。1使能0失能
SuperCap_CanTX.Charge = 1 ; //V1.1超级电容充电。1充电0放电在PLUS版本中此标志位无效超电的充放电是自动的
SuperCap_CanTX.Powerlimit = 120 ; //裁判系统功率限制
SuperCap_CanTX.ChargePower = 1 ; //V1.1超级电容充电功率在PLUS版本中此参数超电的充电功率随着底盘功率变化
/* USER CODE INIT END */
while (1) {
tick += delay_tick; /* 计算下一个唤醒时刻 */
/* USER CODE BEGIN */
SuperCap_Update();
CAN_TX_SuperCapData(&SuperCap_CanTX);
/* USER CODE END */
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
}
}