Vous êtes sur la page 1sur 5

Ex No: Date: IMPLEMENTION OF MAILBOX FUNCTION USING LPC2378 AIM:

To create a mailbox application using LPC2378.

ALGORITHM:
1. 2. 3. 4. 5. 6. Stack size is initialized. The send and receive function declared as App_send&App_recv. Multitasking started using OS_Start(). In sending function buffer array declared and datas are added into buffer array. Mailbox function created using OS Mbox Create(). If there is no error, data posted into mailbox using OSMboxPost() inorder to start data transfer. 7. After delay, mailbox deleted. 8. In the receiver function, retrieves data from the mailbox using OSMboxPend()

DESCRIPTION:
In general, mailboxes are much like queues. The typical RTOS has functions to create, to write to, and to read from mailboxes, and perhaps functions to check whether the mailbox contains any messages and to destroy the mailbox if it is no longer needed. The details of mailboxes, however, are different in different RTOSs.Here are some of the variations are: Although some RTOSs allow a certain number of messages in each mailbox, a number that you can usually choose when you create the mailbox, others allow only one message in a mailbox at a time. Once one message is written to a mailbox under these systems, the mailbox is full; no other message can be written to the mailbox until the first one is read. In some RTOSs, the number of messages in each mailbox is unlimited. There is a limit to the total number of messages that can be in all of the mailboxes in the system, but these messages will be distributed into the individual mailboxes as they are needed.

In some RTOSs, you can prioritize mailbox messages. Higher-priority messages will be read before lower-priority messages, regardless of the order in which they are written into the mailbox.

PROGRAM:
#include <includes.h> #define TASK_STK_SIZE OS_STK OS_STK 128 // initialize the stack size //initializing stack for sending function //initializing stack for receiving function

AppStk_send[TASK_STK_SIZE]; AppStk_recv[TASK_STK_SIZE];

static void App_send(void *p_arg); static void App_recv(void *p_arg); OS_EVENT *pmailbox; void main(intargc, char *argv[]) { BSP_IntDisAll(); BSP_Init(); OSInit();

// Declare send function // Declare receive function

OSTaskCreate(App_send,NULL,(OS_STK*)&AppStk_send[TASK_STK_SIZE-1],(INT8U)10); OSTaskCreate(App_recv,NULL,(OS_STK *)&AppStk_recv[TASK_STK_SIZE-1],(INT8U)30); OSStart(); } /* sending task*/ voidApp_send(void *p_arg) { INT8U i,err, *buffer[3]; buffer[0] = "test01"; buffer[1] = "test02"; buffer[2] = "test03"; p_arg = p_arg; pmailbox=OSMboxCreate(NULL); // create the mailbox function //assign buffer array //add data into the buffer //add data into the buffer //add data into the buffer // Start multitasking

for (i=0;i<=2;) { if((err=OSMboxPost(pmailbox,buffer[i]))==OS_NO_ERR) { printf("\n\r This is sender \n\t post data to Mailbox,data is: %s",buffer[i]); i++; } else if(err==OS_MBOX_FULL) printf("\n\r This is sender \n\t the Mailbox has data,data is: %s",pmailbox->OSEventPtr); else printf("\n\r Other err"); OSTimeDlyHMSM(0, 0, 5, 0); } //assigning delay

OSTimeDlyHMSM(0, 0, 5, 0);

//assigning delay

OSMboxDel (pmailbox, OS_DEL_NO_PEND, &err);

if(err==OS_ERR_TASK_WAITING) printf("\n\r Some task wait for this Mailbox"); } /* Receiving task*/ voidApp_recv(void *p_arg) { INT8U err; INT16U timeout=100; INT8U *buffer; p_arg = p_arg;

for (;;) {

buffer=OSMboxPend(pmailbox,timeout,&err); OSTimeDly(200); if(err==OS_NO_ERR) printf("\n\r This is receiver \n\t get data from Mailbox data is: %s",buffer); //assigning delay

else if(err==OS_TIMEOUT) printf("\n\r Timeout"); else if(err==OS_ERR_EVENT_TYPE) { printf("\n\r This is receiver \n\t err is OS_ERR_EVENT_TYPE"); break; } else break; OSTimeDlyHMSM(0, 0, 6, 0); } }

SNAPSHOTS:

Fig 1: Snapshot for mailbox function

RESULT:
The mailbox application is created using LPC2378.

Vous aimerez peut-être aussi