Code:
#include<rtl.h>
#include<lpc214x.h>
os_mbx_declare(MsgBox, 10); //create object msgbox with size 10msgs
_declare_box(mpool, 04, 10); //memory pool with 10 blocks and eack block having 4 bytes
#define SELDISP1 0x10000000;
unsigned int cnt1,cnt2;
unsigned int array_dec[11] = {0x003F0000, 0X00060000, 0X005B0000, 0X004F0000, 0X00660000, 0X006D0000, 0X007D0000, 0X00070000, 0X007F0000, 0X006F0000, 0X00770000};
void delay(void)
{
unsigned int i;
for(i=0;i<=5000000;i++);
}
__task void task2(void)
{
//this task will recieve a count
U32*rptr;
//declare recieve pointer rptr
while(1)
{
os_mbx_wait (MsgBox, (void**)&rptr, 0xffff); //gets nxt msg from mailbox or waits for a new one
cnt2 = rptr[0]; //copy count value from task1 to cnt2
IO0DIR = 0X10FF0000;
IO0CLR = 0X10FF0000;
IO0SET = array_dec[cnt2]|SELDISP1;
}
}
__task void task1(void)
{
U32*mptr; //mailbox pointer
os_tsk_create (task2, 0);
cnt1 = 0;
os_mbx_init (MsgBox, sizeof(MsgBox)); //initialize mailbox
mptr = _alloc_box (mpool);
while(cnt1<11)
{
mptr[0] = cnt1;
delay();
os_mbx_send (MsgBox, mptr, 0xffff);
cnt1++;
}
if(cnt1==11)
for(;;);
}
int main(void)
{
_init_box (mpool, sizeof(mpool), sizeof(U32));
//initializes mem pool of 4 bytes in alignment
os_sys_init(task1);
}