Implemention of Mailbox Function Using Lpc2148 AIM Algorithm
Implemention of Mailbox Function Using Lpc2148 AIM Algorithm
AIM
To create a mailbox in Micro C/OS-II using LPC2148
ALGORITHM
Initialize the header file
If OS_CRITICAL_METHOD==3 then it will allocate local storage for variable
typeOS_CPU_SR cpu_sr=0 and end if statement
Define SW1 and SW2 for Pin 0.10 and 0.11
OS_EVENT structure created for OSMboxPost() and OSMboxPend()
OS_STK is used to create own stack space for task1,and task2
Declare the task functions
Initialize variable i and call LPC2148BSPInit()
Set pins 0.12 and 0.13 of port0 as output and call OSInit()
OSTaskCreate() is used to create task1,and task2 with priority so it can be managed
byuc/os-II
OSMboxCreate() create and initializes mailbox.
OSMboxPost() sends message to a task through mailbox and call OSStart()
Task1
Initialize variable err, i, and pointer variable msg
Initialize LPC2148BSPInit()
Within infinite loop, OSMboxPend() used by the task to receive a message and assign itin
variable msg
Assign i=*msg
If SW1==0 then increment i and print the value of i
OS_ENTER_CRITICAL() used to disable processors interrupt and enters into
criticalsection of code where it waits until SW1==0
If SW1!=0 then it use OS_EXIT_CRITICAL to enable processors interrupt and
comesout of critical section of code
OSMboxPost() sends message to a task through mailbox and assign it in variable err
OSTimeDlyHMSM used to delay the task for user specified time of 100milliseconds
Task2
Within infinite loop, OSMboxPend() used by the task to receive a message and assign itin
variable msg
Assign j=*msg
OSMboxPost() sends message to a task through mailbox and assign it in variable err
OSTimeDlyHMSM used to delay the task for user specified time of 50milliseconds
CODING
#include
"includes.h"#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register*/OS
_CPU_SR cpu_sr = 0;#endif #define sw1 IO0PIN_bit.P0_10#define sw2
IO0PIN_bit.P0_11OS_EVENT *comm;OS_STK Task1stk[1000];OS_STK Task2stk[1000];