|
Read-Only
Author Axel Busch
Posted 30-Apr-2012 08:31 GMT
Toolset ARM
|
 KEIL RTX Mailbox example
Axel Busch
Hi,
i'm currently experimenting with RTX Mailboxes and i tried one the
Keil example which is not working. I stripped some unimportant things
like serial initialization, etc
OS_TID tsk1; /* assigned identification for task 1 */
OS_TID tsk2; /* assigned identification for task 2 */
typedef struct { /* Message object structure */
float voltage; /* AD result of measured voltage */
float current; /* AD result of measured current */
U32 counter; /* A counter value */
} T_MEAS;
os_mbx_declare (MsgBox,16); /* Declare an RTX mailbox */
_declare_box (mpool,sizeof(T_MEAS),16);/* Dynamic memory pool */
__task void send_task (void);
__task void rec_task (void);
/*----------------------------------------------------------------------------
* Task 1: RTX Kernel starts this task with os_sys_init (send_task)
*---------------------------------------------------------------------------*/
__task void send_task (void) {
T_MEAS *mptr;
tsk1 = os_tsk_self (); /* get own task identification number */
tsk2 = os_tsk_create (rec_task, 0); /* start task 2 */
os_mbx_init (MsgBox, sizeof(MsgBox));/* initialize the mailbox */
os_dly_wait (5); /* Startup delay for MCB21xx */
mptr = _alloc_box (mpool); /* Allocate a memory for the message */
mptr->voltage = 223.72; /* Set the message content */
mptr->current = 17.54;
mptr->counter = 120786;
os_mbx_send (MsgBox, mptr, 0xffff); /* Send the message to the mailbox */
IOSET1 = 0x10000;
os_dly_wait (100);
mptr = _alloc_box (mpool);
mptr->voltage = 227.23; /* Prepare a 2nd message */
mptr->current = 12.41;
mptr->counter = 170823;
os_mbx_send (MsgBox, mptr, 0xffff); /* And send it. */
os_tsk_pass (); /* Cooperative multitasking */
IOSET1 = 0x20000;
os_dly_wait (100);
mptr = _alloc_box (mpool);
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);
os_tsk_delete_self (); /* We are done here, delete this task */
}
/*----------------------------------------------------------------------------
* Task 2: RTX Kernel starts this task with os_tsk_create (rec_task, 0)
*---------------------------------------------------------------------------*/
__task void rec_task (void) {
T_MEAS *rptr;
for (;;) {
os_mbx_wait (MsgBox, (void **)&rptr, 0xffff); /* wait for the message */
printf ("\nVoltage: %.2f V\n",rptr->voltage);
printf ("Current: %.2f A\n",rptr->current);
printf ("Number of cycles: %d\n",rptr->counter);
_free_box (mpool, rptr); /* free memory allocated for message */
}
}
/*----------------------------------------------------------------------------
* Main: Initialize and start RTX Kernel
*---------------------------------------------------------------------------*/
int main (void) { /* program execution starts here */
_init_box (mpool, sizeof(mpool), /* initialize the 'mpool' memory for */
sizeof(T_MEAS)); /* the membox dynamic allocation */
os_sys_init (send_task); /* initialize and start task 1 */
}
i get the error: main.cpp(131): error: #513: a value of type "void
*" cannot be assigned to an entity of type "T_MEAS *" at this
line:
mptr = _alloc_box (mpool); /* Allocate a memory for the message */
Does anyone have an idea how this should be used?
|
|
Read-Only
Author Hans-Bernhard Broeker
Posted 30-Apr-2012 22:01 GMT
Toolset ARM
|
 RE: KEIL RTX Mailbox example
Hans-Bernhard Broeker
That's because you're compiling idiomatic C code as C++. A good
deal of the time that works, but not for implicit conversions to and
from (void *). You'll need a cast, or go back to plain C instead of
C++.
|