1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| #include "thread_task.h" #include "main.h" #include <stdio.h> #include "rtthread.h"
#define THREAD_1_PRIORITY 5 #define THREAD_1_STACK_SIZE 512 #define THREAD_1_TIMESLICE 1 static char thread_1_stack[THREAD_1_STACK_SIZE]; static struct rt_thread thread_1_handle;
#define THREAD_2_PRIORITY 5 #define THREAD_2_STACK_SIZE 512 #define THREAD_2_TIMESLICE 1 static char thread_2_stack[THREAD_1_STACK_SIZE]; static struct rt_thread thread_2_handle;
uint8_t count_1 = 0; uint8_t count_2 = 0;
void thread_1_entry(void* param) { while(1) { rt_tick_t now_tick = rt_tick_get(); HAL_GPIO_TogglePin(GPIOC, LED1_Pin);
rt_thread_delay_until(&now_tick, 1000); } }
void thread_2_entry(void* param) { while(1) { rt_tick_t now_tick = rt_tick_get(); HAL_GPIO_TogglePin(GPIOC, LED2_Pin); rt_thread_delay_until(&now_tick, 1000); } }
void ThreadStart(void) { rt_thread_init( &thread_1_handle, "thread_1", thread_1_entry, RT_NULL, &thread_1_stack[0], THREAD_1_STACK_SIZE, THREAD_1_PRIORITY, THREAD_1_TIMESLICE); rt_thread_startup(&thread_1_handle);
rt_thread_init( &thread_2_handle, "thread_2", thread_2_entry, RT_NULL, &thread_2_stack[0], THREAD_2_STACK_SIZE, THREAD_2_PRIORITY, THREAD_2_TIMESLICE); rt_thread_startup(&thread_2_handle); }
|