diff --git a/.cproject b/.cproject index dc60787..d713cf4 100644 --- a/.cproject +++ b/.cproject @@ -23,7 +23,7 @@ - + @@ -46,7 +46,7 @@ - + @@ -72,7 +72,7 @@ - + @@ -152,7 +152,7 @@ - + @@ -166,7 +166,7 @@ - + @@ -187,7 +187,7 @@ - + diff --git a/.settings/stm32cubeide.project.prefs b/.settings/stm32cubeide.project.prefs index e17c40e..184ab7f 100644 --- a/.settings/stm32cubeide.project.prefs +++ b/.settings/stm32cubeide.project.prefs @@ -1,5 +1,6 @@ +2F62501ED4689FB349E356AB974DBE57=1A37C75E31949FC1CF47D46CC4BFA318 635E684B79701B039C64EA45C3F84D30=C8B026EBE17C208F17FB66CE4235156C 66BE74F758C12D739921AEA421D593D3=1 8DF89ED150041C4CBC7CB9A9CAA90856=1A37C75E31949FC1CF47D46CC4BFA318 -DC22A860405A8BF2F2C095E5B6529F12=1A37C75E31949FC1CF47D46CC4BFA318 +DC22A860405A8BF2F2C095E5B6529F12=EC6C4D369FD4F7EABFE17B3222B5F3A0 eclipse.preferences.version=1 diff --git a/Core/Inc/FreeRTOSConfig.h b/Core/Inc/FreeRTOSConfig.h index 4980171..4e6a824 100644 --- a/Core/Inc/FreeRTOSConfig.h +++ b/Core/Inc/FreeRTOSConfig.h @@ -51,6 +51,10 @@ #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) #include extern uint32_t SystemCoreClock; +/* USER CODE BEGIN 0 */ + extern void configureTimerForRunTimeStats(void); + extern unsigned long getRunTimeCounterValue(void); +/* USER CODE END 0 */ #endif #define configENABLE_FPU 1 #define configENABLE_MPU 0 @@ -58,14 +62,17 @@ #define configUSE_PREEMPTION 1 #define configSUPPORT_STATIC_ALLOCATION 1 #define configSUPPORT_DYNAMIC_ALLOCATION 1 -#define configUSE_IDLE_HOOK 0 -#define configUSE_TICK_HOOK 0 +#define configUSE_IDLE_HOOK 1 +#define configUSE_TICK_HOOK 1 #define configCPU_CLOCK_HZ ( SystemCoreClock ) #define configTICK_RATE_HZ ((TickType_t)1000) #define configMAX_PRIORITIES ( 7 ) #define configMINIMAL_STACK_SIZE ((uint16_t)512) -#define configTOTAL_HEAP_SIZE ((size_t)30000) +#define configTOTAL_HEAP_SIZE ((size_t)50000) #define configMAX_TASK_NAME_LEN ( 16 ) +#define configGENERATE_RUN_TIME_STATS 1 +#define configUSE_TRACE_FACILITY 1 +#define configUSE_STATS_FORMATTING_FUNCTIONS 1 #define configUSE_16_BIT_TICKS 0 #define configUSE_MUTEXES 1 #define configQUEUE_REGISTRY_SIZE 8 @@ -147,6 +154,12 @@ standard names. */ #define xPortSysTickHandler SysTick_Handler +/* USER CODE BEGIN 2 */ +/* Definitions needed when configGENERATE_RUN_TIME_STATS is on */ +#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS configureTimerForRunTimeStats +#define portGET_RUN_TIME_COUNTER_VALUE getRunTimeCounterValue +/* USER CODE END 2 */ + /* USER CODE BEGIN Defines */ /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */ /* USER CODE END Defines */ diff --git a/Core/Inc/stm32f4xx_it.h b/Core/Inc/stm32f4xx_it.h index 55d8bf9..d362002 100644 --- a/Core/Inc/stm32f4xx_it.h +++ b/Core/Inc/stm32f4xx_it.h @@ -54,6 +54,10 @@ void UsageFault_Handler(void); void DebugMon_Handler(void); void DMA1_Stream1_IRQHandler(void); void DMA1_Stream3_IRQHandler(void); +void CAN1_TX_IRQHandler(void); +void CAN1_RX0_IRQHandler(void); +void CAN1_RX1_IRQHandler(void); +void CAN1_SCE_IRQHandler(void); void TIM1_TRG_COM_TIM11_IRQHandler(void); void USART3_IRQHandler(void); void TIM6_DAC_IRQHandler(void); diff --git a/Core/Src/can.c b/Core/Src/can.c index a3b7ee4..2885758 100644 --- a/Core/Src/can.c +++ b/Core/Src/can.c @@ -83,6 +83,15 @@ void HAL_CAN_MspInit(CAN_HandleTypeDef* canHandle) GPIO_InitStruct.Alternate = GPIO_AF9_CAN1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /* CAN1 interrupt Init */ + HAL_NVIC_SetPriority(CAN1_TX_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(CAN1_TX_IRQn); + HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn); + HAL_NVIC_SetPriority(CAN1_RX1_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(CAN1_RX1_IRQn); + HAL_NVIC_SetPriority(CAN1_SCE_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(CAN1_SCE_IRQn); /* USER CODE BEGIN CAN1_MspInit 1 */ /* USER CODE END CAN1_MspInit 1 */ @@ -106,6 +115,11 @@ void HAL_CAN_MspDeInit(CAN_HandleTypeDef* canHandle) */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12); + /* CAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(CAN1_TX_IRQn); + HAL_NVIC_DisableIRQ(CAN1_RX0_IRQn); + HAL_NVIC_DisableIRQ(CAN1_RX1_IRQn); + HAL_NVIC_DisableIRQ(CAN1_SCE_IRQn); /* USER CODE BEGIN CAN1_MspDeInit 1 */ /* USER CODE END CAN1_MspDeInit 1 */ diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index afdb21d..3ad94ad 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -65,9 +65,52 @@ void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackTy void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ); /* Hook prototypes */ +void configureTimerForRunTimeStats(void); +unsigned long getRunTimeCounterValue(void); +void vApplicationIdleHook(void); +void vApplicationTickHook(void); void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName); void vApplicationMallocFailedHook(void); +/* USER CODE BEGIN 1 */ +/* Functions needed when configGENERATE_RUN_TIME_STATS is on */ +__weak void configureTimerForRunTimeStats(void) +{ + +} + +__weak unsigned long getRunTimeCounterValue(void) +{ +return 0; +} +/* USER CODE END 1 */ + +/* USER CODE BEGIN 2 */ +__weak void vApplicationIdleHook( void ) +{ + /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set + to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle + task. It is essential that code added to this hook function never attempts + to block in any way (for example, call xQueueReceive() with a block time + specified, or call vTaskDelay()). If the application makes use of the + vTaskDelete() API function (as this demo application does) then it is also + important that vApplicationIdleHook() is permitted to return to its calling + function, because it is the responsibility of the idle task to clean up + memory allocated by the kernel to any task that has since been deleted. */ +} +/* USER CODE END 2 */ + +/* USER CODE BEGIN 3 */ +__weak void vApplicationTickHook( void ) +{ + /* This function will be called by each tick interrupt if + configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be + added here, but the tick hook is called from an interrupt context, so + code must not attempt to block, and only the interrupt safe FreeRTOS API + functions can be used (those that end in FromISR()). */ +} +/* USER CODE END 3 */ + /* USER CODE BEGIN 4 */ __weak void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName) { diff --git a/Core/Src/stm32f4xx_it.c b/Core/Src/stm32f4xx_it.c index 83dd03d..1d0a3db 100644 --- a/Core/Src/stm32f4xx_it.c +++ b/Core/Src/stm32f4xx_it.c @@ -55,6 +55,7 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern CAN_HandleTypeDef hcan1; extern TIM_HandleTypeDef htim1; extern TIM_HandleTypeDef htim6; extern TIM_HandleTypeDef htim7; @@ -198,6 +199,62 @@ void DMA1_Stream3_IRQHandler(void) } /** + * @brief This function handles CAN1 TX interrupts. + */ +void CAN1_TX_IRQHandler(void) +{ + /* USER CODE BEGIN CAN1_TX_IRQn 0 */ + + /* USER CODE END CAN1_TX_IRQn 0 */ + HAL_CAN_IRQHandler(&hcan1); + /* USER CODE BEGIN CAN1_TX_IRQn 1 */ + + /* USER CODE END CAN1_TX_IRQn 1 */ +} + +/** + * @brief This function handles CAN1 RX0 interrupts. + */ +void CAN1_RX0_IRQHandler(void) +{ + /* USER CODE BEGIN CAN1_RX0_IRQn 0 */ + + /* USER CODE END CAN1_RX0_IRQn 0 */ + HAL_CAN_IRQHandler(&hcan1); + /* USER CODE BEGIN CAN1_RX0_IRQn 1 */ + + /* USER CODE END CAN1_RX0_IRQn 1 */ +} + +/** + * @brief This function handles CAN1 RX1 interrupt. + */ +void CAN1_RX1_IRQHandler(void) +{ + /* USER CODE BEGIN CAN1_RX1_IRQn 0 */ + + /* USER CODE END CAN1_RX1_IRQn 0 */ + HAL_CAN_IRQHandler(&hcan1); + /* USER CODE BEGIN CAN1_RX1_IRQn 1 */ + + /* USER CODE END CAN1_RX1_IRQn 1 */ +} + +/** + * @brief This function handles CAN1 SCE interrupt. + */ +void CAN1_SCE_IRQHandler(void) +{ + /* USER CODE BEGIN CAN1_SCE_IRQn 0 */ + + /* USER CODE END CAN1_SCE_IRQn 0 */ + HAL_CAN_IRQHandler(&hcan1); + /* USER CODE BEGIN CAN1_SCE_IRQn 1 */ + + /* USER CODE END CAN1_SCE_IRQn 1 */ +} + +/** * @brief This function handles TIM1 trigger and commutation interrupts and TIM11 global interrupt. */ void TIM1_TRG_COM_TIM11_IRQHandler(void) diff --git a/Core/Src/usart.c b/Core/Src/usart.c index f661275..e694a67 100644 --- a/Core/Src/usart.c +++ b/Core/Src/usart.c @@ -43,7 +43,7 @@ void MX_USART1_UART_Init(void) /* USER CODE END USART1_Init 1 */ huart1.Instance = USART1; - huart1.Init.BaudRate = 115200; + huart1.Init.BaudRate = 961200; huart1.Init.WordLength = UART_WORDLENGTH_8B; huart1.Init.StopBits = UART_STOPBITS_1; huart1.Init.Parity = UART_PARITY_NONE; diff --git a/dbdb_liquid_path_control_v2.ioc b/dbdb_liquid_path_control_v2.ioc index bfbe262..4b60906 100644 --- a/dbdb_liquid_path_control_v2.ioc +++ b/dbdb_liquid_path_control_v2.ioc @@ -39,19 +39,24 @@ Dma.USART3_TX.1.Priority=DMA_PRIORITY_LOW Dma.USART3_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode FREERTOS.FootprintOK=true FREERTOS.INCLUDE_uxTaskGetStackHighWaterMark=1 -FREERTOS.IPParameters=Tasks01,FootprintOK,configUSE_NEWLIB_REENTRANT,configUSE_RECURSIVE_MUTEXES,configUSE_COUNTING_SEMAPHORES,configRECORD_STACK_HIGH_ADDRESS,configENABLE_FPU,configTOTAL_HEAP_SIZE,configMINIMAL_STACK_SIZE,INCLUDE_uxTaskGetStackHighWaterMark,configUSE_MALLOC_FAILED_HOOK,configCHECK_FOR_STACK_OVERFLOW,configUSE_TIMERS,configTIMER_TASK_PRIORITY +FREERTOS.IPParameters=Tasks01,FootprintOK,configUSE_NEWLIB_REENTRANT,configUSE_RECURSIVE_MUTEXES,configUSE_COUNTING_SEMAPHORES,configRECORD_STACK_HIGH_ADDRESS,configENABLE_FPU,configTOTAL_HEAP_SIZE,configMINIMAL_STACK_SIZE,INCLUDE_uxTaskGetStackHighWaterMark,configUSE_MALLOC_FAILED_HOOK,configCHECK_FOR_STACK_OVERFLOW,configUSE_TIMERS,configTIMER_TASK_PRIORITY,configUSE_TRACE_FACILITY,configGENERATE_RUN_TIME_STATS,configUSE_STATS_FORMATTING_FUNCTIONS,configUSE_IDLE_HOOK,configUSE_TICK_HOOK FREERTOS.Tasks01=defaultTask,-3,1024,StartDefaultTask,As weak,NULL,Dynamic,NULL,NULL FREERTOS.configCHECK_FOR_STACK_OVERFLOW=1 FREERTOS.configENABLE_FPU=1 +FREERTOS.configGENERATE_RUN_TIME_STATS=1 FREERTOS.configMINIMAL_STACK_SIZE=512 FREERTOS.configRECORD_STACK_HIGH_ADDRESS=1 FREERTOS.configTIMER_TASK_PRIORITY=3 -FREERTOS.configTOTAL_HEAP_SIZE=30000 +FREERTOS.configTOTAL_HEAP_SIZE=50000 FREERTOS.configUSE_COUNTING_SEMAPHORES=1 +FREERTOS.configUSE_IDLE_HOOK=1 FREERTOS.configUSE_MALLOC_FAILED_HOOK=1 FREERTOS.configUSE_NEWLIB_REENTRANT=1 FREERTOS.configUSE_RECURSIVE_MUTEXES=1 +FREERTOS.configUSE_STATS_FORMATTING_FUNCTIONS=1 +FREERTOS.configUSE_TICK_HOOK=1 FREERTOS.configUSE_TIMERS=1 +FREERTOS.configUSE_TRACE_FACILITY=1 File.Version=6 GPIO.groupedBy=Group By Peripherals KeepUserPlacement=false @@ -110,6 +115,10 @@ Mcu.UserName=STM32F407VETx MxCube.Version=6.11.0 MxDb.Version=DB.6.0.110 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false +NVIC.CAN1_RX0_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true +NVIC.CAN1_RX1_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true +NVIC.CAN1_SCE_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true +NVIC.CAN1_TX_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true NVIC.DMA1_Stream1_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true NVIC.DMA1_Stream3_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false @@ -205,7 +214,7 @@ ProjectManager.ProjectStructure= ProjectManager.RegisterCallBack= ProjectManager.StackSize=0x2000 ProjectManager.TargetToolchain=STM32CubeIDE -ProjectManager.ThreadSafeStrategy=Cortex-M4NS\:FreeRtosStrategy5, +ProjectManager.ThreadSafeStrategy=Cortex-M4NS\:FreeRtosStrategy4, ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= @@ -271,7 +280,8 @@ TIM6.IPParameters=Prescaler TIM6.Prescaler=71 TIM7.IPParameters=Prescaler TIM7.Prescaler=81 -USART1.IPParameters=VirtualMode +USART1.BaudRate=961200 +USART1.IPParameters=VirtualMode,BaudRate USART1.VirtualMode=VM_ASYNC USART2.IPParameters=VirtualMode USART2.VirtualMode=VM_ASYNC diff --git a/iflytop_canbus_protocol b/iflytop_canbus_protocol index fd05c9d..b6e54e5 160000 --- a/iflytop_canbus_protocol +++ b/iflytop_canbus_protocol @@ -1 +1 @@ -Subproject commit fd05c9d4f6c74f29f550399ec3c238eab0295d37 +Subproject commit b6e54e5016640a5410921706e3c35f8f1f817fbf diff --git a/usrc/main.cpp b/usrc/main.cpp index 8973378..ee8b278 100644 --- a/usrc/main.cpp +++ b/usrc/main.cpp @@ -49,7 +49,8 @@ void umain() { protocol_impl_service_init(); ZLOGI(TAG, "system init done"); - SysMgr::ins()->regTaskId(osThreadGetId()); + SysMgr::ins()->initedFinished(); + SysMgr::ins()->dumpSysInfo(); while (true) { osDelay(1); debug_light_ctrl(); diff --git a/usrc/project_configs.h b/usrc/project_configs.h index f223f5c..49462ae 100644 --- a/usrc/project_configs.h +++ b/usrc/project_configs.h @@ -33,3 +33,4 @@ #define SDK_IRQ_PREEMPTPRIORITY_DEFAULT 5 // IO中断默认中断等级 #define SDK_CFG__CFG_FLASH_ADDR 0x080C0000 // #define SDK_CFG__SN_FLASH_ADDR 0x080E0000 // +#define SDK_MAX_TASK 10 \ No newline at end of file diff --git a/usrc/protocol_impl/protocol_impl_service.cpp b/usrc/protocol_impl/protocol_impl_service.cpp index eca2ca6..bcbff57 100644 --- a/usrc/protocol_impl/protocol_impl_service.cpp +++ b/usrc/protocol_impl/protocol_impl_service.cpp @@ -3,7 +3,7 @@ #include "base/device_info.hpp" #include "zsdk/zcanreceiver/zcanreceiver.hpp" #define TAG "PROTO" - +using namespace iflytop; /*********************************************************************************************************************** * FUNCTION_LIST * ***********************************************************************************************************************/ @@ -18,13 +18,19 @@ static osThreadId PacketRxThreadId; /*********************************************************************************************************************** * FUNCTION_IMPL * ***********************************************************************************************************************/ + +#define GET_PARAM(buff, off) ((((int32_t*)(buff))[off])) + static void zcanbus_on_rx(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { // zcanbus_packet_t* packet = (zcanbus_packet_t*)rawpacket; - + ZLOGI(TAG, "rx packet from %d to %d, function_id %d, len %d", from, to, packet->function_id, len); + /*********************************************************************************************************************** + * 系统方法 * + ***********************************************************************************************************************/ + // 读板子信息 if (packet->function_id == kcmd_read_board_info) { static ack_read_board_info_data_t ack; - ack.boardType = deviceInfo_getBoardType(); - + ack.boardType = deviceInfo_getBoardType(); ack.projectId = deviceInfo_getProjectId(); ack.protcol_version = deviceInfo_getProtocolVersion(); ack.software_version = deviceInfo_getSoftwareVersion(); @@ -32,6 +38,42 @@ static void zcanbus_on_rx(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t l zcanbus_send_ack(packet, (uint8_t*)&ack, sizeof(ack)); } + + // 读系统信息 + else if (packet->function_id == kcmd_read_sysinfo) { + static ack_sysinfo_t ack; + ack.free_heap_size = SysMgr::ins()->osGetMinimumEverFreeHeapSize(); + ack.total_heap_size = SysMgr::ins()->osGetTotalHeapSize(); + ack.taskNum = SysMgr::ins()->getTaskNum(); + ack.sysHasRun = SysMgr::ins()->osGetSysRunTime() / 1000; + zcanbus_send_ack(packet, (uint8_t*)&ack, sizeof(ack)); + } + + // 读任务信息 + else if (packet->function_id == kcmd_read_taskinfo) { + static ask_taskinfo_t ack; + int32_t taskoff = GET_PARAM(packet->params, 0); + osThreadId taskId = SysMgr::ins()->osGetId(taskoff); + SysMgr::ins()->osTaskName(taskId, (char*)ack.taskName, sizeof(ack.taskName)); + SysMgr::ins()->osTaskStackRemainingSize(taskId, &ack.stackRemindSize); + SysMgr::ins()->osTaskPriority(taskId, &ack.priority); + SysMgr::ins()->osTaskGetState(taskId, (char*)&ack.state); + + zcanbus_send_ack(packet, (uint8_t*)&ack, sizeof(ack)); + } + + else if (packet->function_id == kcmd_heart_ping) { + static report_heatpacket_data_t heatpacket; + heatpacket.boardType = deviceInfo_getBoardType(); + heatpacket.heartIndex = GET_PARAM(packet->params, 0); + zcanbus_send_report(kreport_heatpacket, (uint8_t*)&heatpacket, sizeof(heatpacket)); + } + /*********************************************************************************************************************** + * 应用实现 * + ***********************************************************************************************************************/ + // 触发一次强制上报事件 + else if (packet->function_id == kcmd_force_report) { + } } static void zcanbus_on_connected(bool connected) { @@ -48,7 +90,7 @@ static void zcanbus_on_connected(bool connected) { static void onHeartReportTimer(void const* argument) { static report_heatpacket_data_t heatpacket; heatpacket.boardType = deviceInfo_getBoardType(); - zcanbus_send_report(kreport_heatpacket, (uint8_t*)&heatpacket, sizeof(heatpacket)); + // zcanbus_send_report(kreport_heatpacket, (uint8_t*)&heatpacket, sizeof(heatpacket)); } static void onPacketRxThreadStart(void const* argument) { while (true) { @@ -69,6 +111,6 @@ void protocol_impl_service_init() { // HeartReportTimerId = osTimerCreate(osTimer(HeartReportTimer), osTimerPeriodic, NULL); osTimerStart(HeartReportTimerId, HEART_PACKET_PERIOD_MS); - osThreadDef(PacketRxThread, onPacketRxThreadStart, osPriorityNormal, 1024, NULL); + osThreadDef(PacketRxThread, onPacketRxThreadStart, osPriorityNormal, 0, 1024); PacketRxThreadId = osThreadCreate(osThread(PacketRxThread), NULL); } diff --git a/zsdk b/zsdk index 87de1df..04ed10a 160000 --- a/zsdk +++ b/zsdk @@ -1 +1 @@ -Subproject commit 87de1df69a31ca63c98db607ba3851f3e201c857 +Subproject commit 04ed10ad7e7aeba9a47d660573db5bb095f222e6