diff --git a/src/APP/Aufgabe2/ps7/core0/main.c b/src/APP/Aufgabe2/ps7/core0/main.c index 4baad12..d0fbf5b 100644 --- a/src/APP/Aufgabe2/ps7/core0/main.c +++ b/src/APP/Aufgabe2/ps7/core0/main.c @@ -18,13 +18,34 @@ #define HELLO_WORLD_TASK_PRIO 30 #define CALC_TASK_PRIO 31 +#define TASK1_PRIO 32 +#define TASK2_PRIO 33 #define HELLO_WORLD_TASK_STK_SIZE 16000 #define CALC_TASK_STK_SIZE 32000 +#define TASK1_STK_SIZE 32000 +#define TASK2_STK_SIZE 32000 static OS_STK HelloWorldTaskStk[HELLO_WORLD_TASK_STK_SIZE]; static OS_STK CalcTaskStk[HELLO_WORLD_TASK_STK_SIZE]; +static OS_STK Task1Stk[TASK1_STK_SIZE]; +static OS_STK Task2Stk[TASK2_STK_SIZE]; +// Define the message queue buffer +#define QUEUE_SIZE 5 +void *MsgQueueTbl[QUEUE_SIZE]; + +// Declare the queue's Event Control Block +OS_EVENT *MsgQueue; + +// Define a simple message structure +typedef struct { + INT32U MessageID; + INT32U Data; +} MyMessage; + +// Declare message pointers +MyMessage MyMessages[QUEUE_SIZE]; int f(uint8_t n) { @@ -54,6 +75,40 @@ void CalcTask (void *pdata) } } +void Task1(void *pdata){ + INT8U err; + MyMessage *received_msg; + + while (1) { + // // Wait for a message from the queue. Wait indefinitely (0). + received_msg = OSQPend(MsgQueue, 0, &err); + + if (err == 0) { + UCOS_Print("test"); + } + } +} + +void Task2(void *pdata){ + INT8U i = 0; + INT8U err; + MyMessage *msg; + + while (1) { + // Prepare a new message + msg = &MyMessages[i % QUEUE_SIZE]; // Reuse message memory + msg->MessageID = i; + msg->Data = i * 10; + + // Post the message to the queue + OSQPost(MsgQueue, msg); + + // Pause the task for a period + OSTimeDlyHMSM(0, 0, 1, 0); + i++; + } +} + void InitDoneCallback(void * p_arg){ (void) p_arg; UCOS_Print("OS started!\r\n"); @@ -79,6 +134,29 @@ void InitDoneCallback(void * p_arg){ 0 ); + MsgQueue = OSQCreate((void **)&MsgQueueTbl[0], QUEUE_SIZE); + + OSTaskCreateExt(Task1, + 0, + &Task1Stk[TASK1_STK_SIZE-1], + TASK1_PRIO, + TASK1_PRIO, + &Task1Stk[0], + TASK1_STK_SIZE, + 0, + 0 + ); + + OSTaskCreateExt(Task2, + 0, + &Task2Stk[TASK2_STK_SIZE-1], + TASK2_PRIO, + TASK2_PRIO, + &Task2Stk[0], + TASK2_STK_SIZE, + 0, + 0 + ); while(1){ OSTimeDly(1);