I am trying to share data between 2 tasks in MQX 4.2 using pipes. I am seeing data go in the pipe (and finally the task blocks when its full) but when I try to pull data out the other end there is nothing there. I have written a simple MQX 4.2 app that does just this and even it fails. Is there anything obvious I'm doing wrong? I have the pipes named differently in the two tasks but my understanding is that does not matter if they both open with the same "pipe1:" string.
#include <mqx.h>
#include <bsp.h>
#include <fio.h>
#include <io_pipe.h>
/* Task IDs */
#define HELLO_TASK 5
#define HELLO_TASK2 6
extern void hello_task(uint32_t);
extern void hello_task2(uint32_t);
const TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */
{ HELLO_TASK, hello_task, 1500, 8, "hello", MQX_AUTO_START_TASK, 0, 0 },
{ HELLO_TASK2, hello_task2,1500, 8, "hello2", MQX_TIME_SLICE_TASK, 0, 0 },
{ 0 }
};
static MQX_FILE_PTR inPipe1 = NULL;
static MQX_FILE_PTR outPipe1 = NULL;
static MQX_FILE_PTR inPipe2 = NULL;
static MQX_FILE_PTR outPipe2 = NULL;
/*TASK*-----------------------------------------------------
*
* Task Name : hello_task
* Comments :
* This task prints " Hello World "
*
*END*-----------------------------------------------------*/
void hello_task
(
uint32_t initial_data
)
{
(void)initial_data; /* disable 'unused variable' warning */
uint32_t nRead = 0;
_io_pipe_install("pipe1:", 128, 0);
inPipe1 = fopen("pipe1:", "rw");
_task_create(0, HELLO_TASK2, initial_data);
while(1)
{
write(inPipe1, "FEEDBEEF", 8);
ioctl(inPipe1, PIPE_IOCTL_NUM_CHARS_FULL, &nRead);
_time_delay(1000);
}
_task_block();
}
void hello_task2
(
uint32_t initial_data
)
{
(void)initial_data; /* disable 'unused variable' warning */
uint32_t nRead = 0;
uint8_t buffer[128];
inPipe2 = fopen("pipe1:", "rw");
while(1)
{
ioctl(inPipe2, PIPE_IOCTL_NUM_CHARS_FULL, &nRead);
if (nRead > 0)
{
if (nRead > 128)
{
nRead = 128;
}
nRead = read(inPipe2, buffer, nRead);
}
_time_delay(50);
}
_task_block();
}
/* EOF */
Ryan
I would try in the MQX forums for such questions:
- https://community.nxp.com/community/mqx
- MQX RTOS Training
- MQX Downloads
Although I don't think that MQX is supported by NXP any more.
Regards
Mark