Page 1 of 1

Message is not received after signaled

PostPosted: Sun May 20, 2007 9:53 am
by nealfoster
I have a problem using event messaging. The code is below.

At a high level, I am expecting to receive 5 characters and then send the string as a message to another task. The other task takes the message and displays it on the lcd. this is the start of a larger project, but at this stage i just want to make sure that the plumbing is working.

I receive the characters, and send them, but the receiving task never wakes up. The output is also below.

am i initializing the events correctly?

any idea why the "MSG_FROM_PC" message from Task_PC_Comm not being received by Task_Bot_Comm?

any pointers for debugging (i am using mplab and icd2)?

----------------------------------------
CODE
----------------------------------------

code:
/************************************************************
Runs on Microchip PICDEM-2 (PIC18C452)
************************************************************/

#include "main.h"
#include <salvo.h>
#include <xlcd.h>
#include <delays.h>
#include <usart.h>

/************************************************************
**** ****
** **
Local #defines and function prototypes.

** **
**** ****
************************************************************/
#define KEY_DELAY 5 /* number of system */
/* ticks between key */
/* reads. */

#define TASK_HIGH_DELAY 250 /* for 1Hz @ 4MHz */

#define NUM_CTXSWS 20000 /* number of ctxsws for */
/* TaskOverride(). */

#define LED_PORT_MASK 0x7F /* bits that medium- */
/* and low-priority */
/* tasks can change. */

/* global variable */
char delay;

#define TASK_PC_P OSTCBP(1) /* task #1 */
#define TASK_BOT_P OSTCBP(2) /* "" #2 */

/* pass key via a message. */
#define MSG_FROM_PC OSECBP(1)
#define MSG_TO_PC OSECBP(2)

/* function prototypes */
void Task_Bot_Comm(void);
void Task_PC_Comm(void);

/* context-switching labels */
_OSLabel(Task_Bot_Comm1)
_OSLabel(Task_PC_Comm1)

/************************************************************
**** ****
** **
main()

Initialize relevant hardware registers, initialize Salvo and
create tasks, enable interrupts and start multitasking.

** **
**** ****
************************************************************/
int main( void )
{
/* init h/w, etc. */
Init();

/* initialize Salvo. */
OSInit();

/* init comms */
// configure USART (2400 baud, 8n1, no flow)
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
103 );

OpenXLCD( FOUR_BIT & LINES_5X7 ); // Initialize LCD

DelayXLCD(); // BusyXLCD() not working
while( BusyXLCD() )
;
WriteCmdXLCD( DON & CURSOR_OFF & BLINK_OFF ); // Set parameters


/* create tasks. */
OSCreateTask(Task_PC_Comm, TASK_PC_P, 7);
OSCreateTask(Task_Bot_Comm, TASK_BOT_P, 5);

/* enable interrupts. */
OSEi();

/* go! */
for (; ;)
OSSched();

}

/************************************************************
**** ****
** **
Task_Bot_Comm()

** **
**** ****
************************************************************/
void Task_Bot_Comm( void )
{

static OStypeMsgP msgP;

putrsUSART ((const far rom char *)"
TaskBotComm: in task create for lcd
");

DelayXLCD(); // BusyXLCD() not working
while( BusyXLCD() )
;
putrsXLCD("BEGINTASK123456789012345678901234567890"); //write to LCD

while(1)
{
putrsUSART ((const far rom char *)"
TASKBotComm: waiting for message
");

OS_WaitMsg(MSG_FROM_PC, &msgP, OSNO_TIMEOUT, Task_Bot_Comm1);

putrsUSART ((const far rom char *)"
TASKBotComm: message received
");

WriteDataXLCD((char *) msgP); //write to LCD
}
}


/************************************************************
**** ****
** **
Task_PC_Comm()

this will handle messages... also used for debugging which should beput in debug ifdefs later on
right now interaction with pc is using rs232 on board the picdem2+

** **
**** ****
************************************************************/
void Task_PC_Comm( void )
{
char _data[41];
int index;
char data;

OSCreateMsg(MSG_FROM_PC, (OStypeMsgP) 0);

/* Display a prompt to the USART */
putrsUSART ((const far rom char *)"
PC Comm Running
");
index = 0;

_data[5] = '';

for (; ;) {
while(!DataRdyUSART()); //wait for data
data = ReadUSART(); //read data

putrsUSART ((const far rom char *)"
PCCOMMTask: character received by PC: ");
WriteUSART (data);
putrsUSART ((const far rom char *)"
");

_data[index] = data;
index++;

if(index == 5)
{

putrsUSART ((const far rom char *)"
PCCOMMTask: cmd received by PC");
//putrsUSART ((char *)_data);
putrsUSART ((const far rom char *)"
");

//send message
OSSignalMsg(MSG_FROM_PC, (OStypeMsgP) 0); //&_data);

putrsUSART ((const far rom char *)"
PCCOMMTASK sent message
");

index = 0;

}
}
}



----------------------------------------
OUTPUT from hyperterminal is below
----------------------------------------

TaskBotComm: in task create for lcd

TASKBotComm: waiting for message

Webport 1.0 - PC Comm Running

PCCOMMTask: character received by PC: t

PCCOMMTask: character received by PC: e

PCCOMMTask: character received by PC: s

PCCOMMTask: character received by PC: t

PCCOMMTask: character received by PC: 1

PCCOMMTask: cmd received by PC

PCCOMMTASK sent message

------------------------------------

Thanks.

[This message has been edited by aek (edited May 21, 2007).]


Re: Message is not received after signaled

PostPosted: Mon May 21, 2007 8:06 am
by nealfoster
I tried as you suggested, but now are receiveing a Bad pointer error

code:

code:
void Task_PC_Comm( void )
{
char _data[41];
int index;
char data;
OStypeErr err;

OSCreateMsg(MSG_FROM_PC, (OStypeMsgP) 1);

/* Display a prompt to the USART */
putrsUSART ((const far rom char *)"
Webport 1.0 - PC Comm Running
");
index = 0;

_data[5] = '';

for (;;) {
while(!DataRdyUSART()); //wait for data
data = ReadUSART(); //read data

putrsUSART ((const far rom char *)"
PCCOMMTask: character received by PC: ");
WriteUSART (data);
putrsUSART ((const far rom char *)"
");

_data[index] = data;
index++;

if(index == 5)
{
putrsUSART ((const far rom char *)"
PCCOMMTask: cmd received by PC");
//putrsUSART ((char *)_data);
putrsUSART ((const far rom char *)"
");

//send message
err = OSSignalMsg(MSG_FROM_PC, (OStypeMsgP) 1);

if(err==OSNOERR)
{
putrsUSART ((const far rom char *)"
PCCOMMTASK: sent message
");
OS_Delay(10000, Task_PC_Comm1);
}
else if(err = OSERR_BAD_P)
{
putrsUSART ((const far rom char *)"
PCCOMMTASK: message could not be sent: bad pointer
");
}
else if(err = OSERR_EVENT_BAD_TYPE)
{
putrsUSART ((const far rom char *)"
PCCOMMTASK: message could not be sent: bad event type
");
}
else if(err = OSERR_EVENT_FULL)
{
putrsUSART ((const far rom char *)"
PCCOMMTASK: message could not be sent: message is already defined
");
}
else
{
putrsUSART ((const far rom char *)"
PCCOMMTASK: message could not be sent: unknown reason
");
}

index = 0;

}
}
}



but receive the following output:

Webport 1.0 - PC Comm Running

PCCOMMTask: character received by PC: m

PCCOMMTask: character received by PC: j

PCCOMMTask: character received by PC: k

PCCOMMTask: character received by PC: l

PCCOMMTask: character received by PC: ;

PCCOMMTask: cmd received by PC

PCCOMMTASK: message could not be sent: bad pointer

[This message has been edited by aek (edited May 22, 2007).]


Re: Message is not received after signaled

PostPosted: Mon May 21, 2007 8:49 am
by aek
The problem is that you're signaling with 0, which is the same as not signaling at all.

Note that this is not true of message queues -- with a message queue, a message can contain a value of 0. But with messages, you need to give it a non-zero value.

So just change it to be

code:
OSSignalMsg(MSG_FROM_PC, (OStypeMsgP) 1);

------------------

[This message has been edited by aek (edited May 21, 2007).]


Re: Message is not received after signaled

PostPosted: Tue May 22, 2007 8:26 am
by aek
That error happens if the handle to the message is clearly out of bounds ... what does your salvocfg.h look like?

------------------


Re: Message is not received after signaled

PostPosted: Tue May 22, 2007 8:48 am
by nealfoster
here is my salvocfg.h

/************************************************************
Copyright (C) 1995-2002 Pumpkin, Inc. and its
Licensor(s). Freely distributable.

$Source: C:\RCS\d\salvo\demo\d4\syse\salvocfg.h,v $
$Author: aek $
$Revision: 3.5 $
$Date: 2003-07-20 13:06:52-07 $

Configuration options for demo program.

************************************************************/

#if defined(MAKE_WITH_FREE_LIB)
/* */
/* Salvo Lite build */
/* */
#define OSUSE_LIBRARY TRUE
#define OSLIBRARY_TYPE OSF
#define OSLIBRARY_GLOBALS OSF
#define OSLIBRARY_CONFIG OSA
#define OSLIBRARY_VARIANT OSNONE
//#define OSLIBRARY_CONFIG OSD
//#define OSLIBRARY_VARIANT ONONE
#define OSEVENTS 2
#define OSEVENT_FLAGS 0
#define OSMESSAGE_QUEUES 0
#define OSTASKS 3


#else

#error No MAKE_WITH_??? symbol defined. See salvocfg.h.

#endif

#if !defined(SYSE)

#error SYSE must be defined for this MPLAB-C18 demo project ...

#endif


Re: Message is not received after signaled

PostPosted: Tue May 22, 2007 9:08 am
by aek
Well, I dunno ... but I do see that you are creating it with a value of 1, and then signaling it ... but it's already 1.

Note also that Task_PC_Comm() is not a task (it never context-switches).

You appear to be doing everything right, Salvo-wise. I would make sure that there are no errant pointer writes to the OSecbArea[] memory -- you can watch OSecbArea[] in MPLAB, expand the individual ebs, and see what is happening to it after you signal it, etc.

------------------