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 94 95 96 97 98 99 100 101 102 103
| #include "thread_task.h" #include "main.h" #include <stdio.h> #include "rtthread.h" #include <rthw.h>
#define THREAD_1_PRIORITY 4 #define THREAD_1_STACK_SIZE 512 #define THREAD_1_TIMESLICE 10 static struct rt_thread *thread_1_handle;
#define THREAD_2_PRIORITY 5 #define THREAD_2_STACK_SIZE 512 #define THREAD_2_TIMESLICE 10 static struct rt_thread *thread_2_handle;
rt_mq_t mq_test;
void thread_1_entry(void* param) { uint8_t buffer[2]; while(1) {
rt_mq_recv(mq_test, buffer, 2, 0xffffffff);
HAL_GPIO_TogglePin(GPIOC, LED1_Pin);
rt_thread_delay(4000); } }
void thread_2_entry(void* param) { uint8_t text[2] = {0,1}; while(1) { text[0] ++; rt_mq_send_wait(mq_test, text, 2, 0xffff);
HAL_GPIO_TogglePin(GPIOC, LED2_Pin); rt_thread_delay(200); } }
void ThreadStart(void) { rt_base_t level = rt_hw_interrupt_disable(); thread_1_handle = rt_thread_create( "thread_1", thread_1_entry, RT_NULL, THREAD_1_STACK_SIZE, THREAD_1_PRIORITY, THREAD_1_TIMESLICE );
rt_thread_startup(thread_1_handle);
thread_2_handle = rt_thread_create( "thread_2", thread_2_entry, RT_NULL, THREAD_2_STACK_SIZE, THREAD_2_PRIORITY, THREAD_2_TIMESLICE ); rt_thread_startup(thread_2_handle);
mq_test = rt_mq_create( "mq_test", 2, 12, RT_IPC_FLAG_FIFO ); rt_hw_interrupt_enable(level); }
|