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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
| #include <stdio.h>
#include "includes.h"
#include <string.h>
#define DEBUG 1
/* Definition of Task Stacks */
/* Stack grows from HIGH to LOW memory */
#define TASK_STACKSIZE 2048
OS_STK task1_stk[TASK_STACKSIZE];
OS_STK task2_stk[TASK_STACKSIZE];
OS_STK task3_stk[TASK_STACKSIZE];
#define QUEUELENGTH 10
OS_EVENT *CommQ;
OS_MEM *CommMem;
void *CommMsg[QUEUELENGTH];
INT32U CommBuf[16][32];
//struct Message *Mess;
/* Definition of Task Priorities */
#define TASK1_PRIORITY 6 // highest priority
#define TASK2_PRIORITY 7
#define TASK3_PRIORITY 12
struct Message{
char prio;
char id;
};
int changeState(int state)
{
if (state==0)
{
return 1;
}
else
{
return 0;
}
}
void print(int state, int task)
{
printf("Task: %d State: %d\n", task, state);
}
/* Prints a message and sleeps for given time interval */
void task1(void* pdata)
{
struct Message *Mess;
INT8U *pmsg;
INT8U err;
while (1)
{
pmsg = OSMemGet(CommMem, &err);
if (pmsg != (INT8U *)0) { /* Memory block allocated, use it. */
Mess[0].prio='H';
Mess[0].id='1';
/* add pointer to the new message to the queue */
OSQPost (CommQ, (void *) Mess);
OSTimeDlyHMSM(0, 0, 0, 10);
}
}
}
/* Prints a message and sleeps for given time interval */
void task2(void* pdata)
{
struct Message *Mess;
INT8U *pmsg;
INT8U err;
struct Message test;
while(1)
{
pmsg = OSMemGet(CommMem, &err);
if (pmsg != (INT8U *)0) { /* Memory block allocated, use it. */
Mess[1].prio='L';
Mess[1].id='1';
/* add pointer to the new message to the queue */
OSQPost (CommQ, (void *) Mess);
OSTimeDlyHMSM(0, 0, 0, 10);
}
}
}
void task3(void* pdata)
{
struct Message *Mess;
INT8U err;
while(1)
{
Mess = (struct Message *) OSQPend(CommQ, 0, &err);
int i;
for(i=0; i<=1; i++)
{
printf("%c - %c\n",Mess[i].prio, Mess[i].id);
}
}
}
/* The main function creates three task and starts multi-tasking */
int main(void)
{
printf("Lab 3 - Step1\n");
INT8U err;
OSTaskCreateExt
(task1, // Pointer to task code
NULL, // Pointer to argument that is
// passed to task
&task1_stk[TASK_STACKSIZE-1], // Pointer to top of task stack
TASK1_PRIORITY, // Desired Task priority
TASK1_PRIORITY, // Task ID
&task1_stk[0], // Pointer to bottom of task stack
TASK_STACKSIZE, // Stacksize
NULL, // Pointer to user supplied memory
// (not needed here)
OS_TASK_OPT_STK_CHK | // Stack Checking enabled
OS_TASK_OPT_STK_CLR // Stack Cleared
);
OSTaskCreateExt
(task2, // Pointer to task code
NULL, // Pointer to argument that is
// passed to task
&task2_stk[TASK_STACKSIZE-1], // Pointer to top of task stack
TASK2_PRIORITY, // Desired Task priority
TASK2_PRIORITY, // Task ID
&task2_stk[0], // Pointer to bottom of task stack
TASK_STACKSIZE, // Stacksize
NULL, // Pointer to user supplied memory
// (not needed here)
OS_TASK_OPT_STK_CHK | // Stack Checking enabled
OS_TASK_OPT_STK_CLR // Stack Cleared
);
OSTaskCreateExt
(task3, // Pointer to task code
NULL, // Pointer to argument that is
// passed to task
&task3_stk[TASK_STACKSIZE-1], // Pointer to top of task stack
TASK3_PRIORITY, // Desired Task priority
TASK3_PRIORITY, // Task ID
&task3_stk[0], // Pointer to bottom of task stack
TASK_STACKSIZE, // Stacksize
NULL, // Pointer to user supplied memory
// (not needed here)
OS_TASK_OPT_STK_CHK | // Stack Checking enabled
OS_TASK_OPT_STK_CLR // Stack Cleared
);
CommQ=OSQCreate(&CommMsg[0],QUEUELENGTH);
CommMem = OSMemCreate(&CommBuf[0][0], 16, 32 * sizeof(INT32U), &err);
OSStart();
return 0;
} |