/** **************************************************************************************************** * @file bsp_delay.c * @author * @version V1.0 * @date 2024-02-10 * @brief main **************************************************************************************************** */ /*app*********************************************************************************************/ //#include "app_demo.h" /*kit*********************************************************************************************/ #include "kit_debug.h" /*bsp*********************************************************************************************/ #include "bsp_delay.h" #include "bsp_led.h" #include "bsp_task.h" #include "bsp_iic.h" #include "bsp_can.h" #include "bsp_spi.h" #include "bsp_flash.h" /*drv*********************************************************************************************/ #include "drv_sys.h" #include "drv_usart.h" #include "drv_gpio.h" /*uC/OS-III*********************************************************************************************/ #include "os.h" OS_TCB StartTask1_TCB; /* 任务控制块 */ void poll_start_task1_init(void) { HAL_Init(); /* 初始化HAL库 */ sys_stm32_clock_init(336, 8, 2, 7); /* 设置时钟,168Mhz */ delay_init(168); /* 延时初始化 */ //led_init(); /* 初始化LED */ InitGPIOs(); /* 初始化GPIO */ uint32_t userBaudRate = 115200; // 这里可以设置用户需要的波特率 InitUARTs(userBaudRate); // 使用用户指定的波特率初始化UART can_init(CAN_SJW_1TQ, CAN_BS2_6TQ, CAN_BS1_7TQ, 6, CAN_MODE_LOOPBACK); /* CAN初始化, 正常模式, 波特率500Kbps */ iic_init(); } void poll_start_task1_handler(uint32_t baseTime) { uint8_t canbuf[8]; uint8_t rxlen = 0; uint8_t res; //task1(baseTime); while(1) { //CAN1 test: for (uint8_t i = 0; i < 8; i++) { canbuf[i] = 1 + i; /* 填充发送缓冲区 */ } res = can_send_msg(0X66, canbuf, 8); /* ID = 0X66, 发送8个字节 */ if(res) { //发送成功 } rxlen = can_receive_msg(0X66, canbuf); /* CAN ID = 0X66, 接收数据查询 */ if(rxlen) { //接收成功 } } } void poll_start_task2_handler(uint32_t baseTime) { //task2(baseTime); while(1) { } } // name,id,_prio,_period,_,_timeout,init_call,_ask_call,stack_size TASK_STATIC_INIT_CCM(poll_start_task1, 1, 2, 500, 2000, poll_start_task1_init, poll_start_task1_handler, 400); TASK_STATIC_INIT_CCM(poll_start_task2, 2, 5, 1000, 2000, NULL, poll_start_task2_handler, 400); int main(void) { OS_ERR err; // KIT_DEBUG_PRINTF("12323 \r\n"); /* 关闭所有中断 */ CPU_IntDis(); KIT_DEBUG_PRINTF("BMS start \r\n"); /* 初始化uC/OS-III */ OSInit(&err); bsp_task_creat(&poll_start_task1,(uint8_t *)"poll_start_task1"); bsp_task_creat(&poll_start_task2,(uint8_t *)"poll_start_task2"); /* 开始任务调度 */ OSStart(&err); }