[Shanghai Hangxin ACM32F070 development board review] 7. Give the watchdog a thread
[Copy link]
In my mind, threads are tasks and tasks are threads.
Last time I ran the RTX operating system in the watchdog routine, so this time I will create another task to bring the dog with me. After all, it was modified from the watchdog program, and it would be bad to change it away.
The first step is to change the parameters of the watchdog function
The previous program is void WDT_Reset_Test(void) and is changed to void WDT_Reset_Test(void const *argument)
If you don't change RTX in this way, it seems that it will not pass.
Step 2: Add an ID
osThreadId Dog;
Step 3: Create a task
Dog = osThreadCreate(osThread(WDT_Reset_Test), NULL);
The running results are as follows;
Full Program:
/*
******************************************************************************
* [url=home.php?mod=space&uid=1307177]@File[/url] main.c
* [url=home.php?mod=space&uid=159083]@brief[/url] main source File.
******************************************************************************
*/
#include "APP.h"
#include "cmsis_os.h"
#define UART_BAUD_RATE 115200
UART_HandleTypeDef UART2_Handle;
void led_Thread1 (void const *argument);
osThreadDef(led_Thread1, osPriorityNormal, 1, 0);
osThreadDef(WDT_Reset_Test,osPriorityNormal,1,0);
osThreadId T_led_ID1;
osThreadId Dog;
/************************************************************************
* function : Uart_Init
* Description: Uart Initiation.
************************************************************************/
void Uart_Init(void)
{
UART2_Handle.Instance = UART2;
UART2_Handle.Init.BaudRate = UART_BAUD_RATE;
UART2_Handle.Init.WordLength = UART_WORDLENGTH_8B;
UART2_Handle.Init.StopBits = UART_STOPBITS_1;
UART2_Handle.Init.Parity = UART_PARITY_NONE;
UART2_Handle.Init.Mode = UART_MODE_TX_RX_DEBUG;
UART2_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
HAL_UART_Init(&UART2_Handle);
/* UART_DEBUG_ENABLE control printfS */
printfS("MCU is running, HCLK=%dHz, PCLK=%dHz\n", System_Get_SystemClock(), System_Get_APBClock());
}
/*********************************************************************************
* Function : main
* Description :
* Input :
* Outpu :
* Author : CWT Data : 2020年
**********************************************************************************/
int main(void)
{
osKernelInitialize (); // initialize CMSIS-RTOS
System_Init();
Uart_Init();
//WDT_Reset_Test();
T_led_ID1 = osThreadCreate(osThread(led_Thread1), NULL);
Dog = osThreadCreate(osThread(WDT_Reset_Test), NULL);
osKernelStart (); // start thread execution
}
void led_Thread1 (void const *argument)
{
while(1)
{
printfS("HELLO EEWORLD !!!");
osDelay(500);
}
}
|