Mbox

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include "includes.

h"

#pragma config OSC = HS


#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config STVR = ON

OS_STK pile_tache1[128]; // pile for task 1


OS_STK pile_tache2[128]; // pile for task 2

void tache1(void *pdata1); // prototype for task 1


void tache2(void *pdata2); // prototype for task 2

// Semaphore for protecting the LCD display


OS_EVENT *comp_semaphore;
OS_EVENT *Mbox;

void main(void) {
BSP_Init();
OSInit();

// Create the semaphore for protecting the LCD display


comp_semaphore = OSSemCreate(1);
OSMboxCreate((void*)0);

// Create and start the tasks


OSTaskCreate(tache1, (void *)0, &pile_tache1[0], 1);
OSTaskCreate(tache2, (void *)0, &pile_tache2[0], 3);

OSStart();
}
INT8U MboxBuf[20];
void tache1(void *pdata1) {
signed int compteur = -1;
char buf[20];
INT8U erreur ;

while (1) {

if (compteur <100)
compteur++;
OSMboxPost(Mbox, (void *)&MboxBuf[0]);
OSMboxPend(Mbox, 10, &erreur);
sprintf(buf, "compteur = %d", compteur);
WriteCmdXLCD(0x00);
SetDDRamAddr(0x0);
putsXLCD(buf);

OSSemPost(comp_semaphore);
OSTimeDlyHMSM(0, 0, 1, 0);

}
}

void tache2(void *pdata2) {


signed int compteur = -100 ;
char buf[20];
INT8U erreur ;
void *msg;

while (1) {

if (compteur <128)

compteur+=1;
sprintf(buf, "compteur pair = %2.2d", compteur);
OSSemPend(comp_semaphore, 0,&erreur);
WriteCmdXLCD(0x40);
SetDDRamAddr(0x40);
putsXLCD(buf);
OSSemPost(comp_semaphore);
OSTimeDlyHMSM(0, 0, 1, 0);

You might also like