Documente Academic
Documente Profesional
Documente Cultură
h>
#include <stdio.h>
#include<lpc214x.h>
OS_TID tsk1;
OS_TID tsk2;
typedef struct {
float voltage;
float current;
long counter;
} T_MEAS;
/*
/*
/*
/*
*/
os_mbx_declare (MsgBox,16);
/* Declare an ARTX mailbox
unsigned int mpool[16*sizeof(T_MEAS)/4 + 3]; /* Dynamic memory pool
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
mptr->voltage = 229.44;
/* Prepare a 3rd message
mptr->current = 11.89;
mptr->counter = 237178;
os_mbx_send (MsgBox, mptr, 0xffff); /* And send it.
IOSET1 = 0x40000;
os_dly_wait (100);
mptr = _alloc_box (mpool);
mptr->voltage = 224.44;
/* Prepare a 4th message
mptr->current = 10.89;
mptr->counter = 207178;
os_mbx_send (MsgBox, mptr, 0xffff); /* And send it.
IOSET1 = 0x80000;
os_dly_wait (100);
mptr = _alloc_box (mpool);
mptr->voltage = 219.44;
/* Prepare a 5th message
mptr->current = 9.89;
mptr->counter = 177178;
os_mbx_send (MsgBox, mptr, 0xffff); /* And send it.
IOSET1 = 0x100000;
os_dly_wait (100);
*/
*/
*/
*/
*/
*/
os_tsk_delete_self ();
/* We are done here, delete this task */
}
/*---------------------------------------------------------------------------* Task 2: ARTX Kernel starts this task with os_tsk_create (rec_task, 0)
*---------------------------------------------------------------------------*/
void rec_task (void) __task {
T_MEAS *rptr;
int i=1;
printf("\n Five Messages Send and Received");
for (;;) {
os_mbx_wait (MsgBox, &rptr, 0xffff); /* wait for the message
*/
printf("\nMessage %d\n",i);i++;
printf ("\nVoltage: %.2f V\n",rptr->voltage);
printf ("Current: %.2f A\n",rptr->current);
printf ("Number of cycles: %ld\n",rptr->counter);
_free_box (mpool, rptr);
/* free memory allocated for message */
}
}
/*---------------------------------------------------------------------------*
Main: Initialize and start ARTX Kernel
*---------------------------------------------------------------------------*/
void main (void) {
/* program execution starts here
*/
U32 volatile start;
/* Wait for debugger connection (0.3s) */
for (start = 0; start < 1000000; start++) { ; }
IODIR1 = 0xFF0000;
init_serial ();
_init_box (mpool, sizeof(mpool),
sizeof(T_MEAS));
os_sys_init (send_task);
/*
/*
/*
/*
/*
*/
*/
*/
*/
*/
}
/*---------------------------------------------------------------------------* end of file
*---------------------------------------------------------------------------*/