Pumpkin, Inc.

Pumpkin User Forums

OSSignalBinSem from ISR never gets there

For issues specific to Microchip's PICmicro® MCUs, including compilers (e.g. HI-TECH PICC & PICC-18, Microchip MPLAB®-C18) and IDEs (e.g. Microchip MPLAB®).

OSSignalBinSem from ISR never gets there

Postby calluml » Tue May 04, 2004 3:37 am

Before I start, I know that this will turn out to be something stupid I am doing, but here goes.

I am working on an app for the PIC18F8680 (Source code Salvo build using mcc18 and MPLAB 6.4+ICD) which is calling OSSignalBinSem from within an ISR on receipt of a CAN message. This should cause the CAN processing task to run.

I can set a breakpoint on the signal call and see it fire when I send a message to the device, but after that the rest of the code fails to run. The OS_WaitBinSem never returns and halting execution shows we at a point somewhere in the Salvo code.

This sounds like stack corruption but there is no reason (that I can see) to suspect that.

Any advice welcome, thanks.

CODE (stripped down but with problem):

code:
#include "main.h"
#include <salvo.h>
#include "can18xx8.h"

/********************* Function prototypes ***********************************/

void TaskLED(void);
void TaskCANRcvd(void);
void TaskCANSend(void);


/********************* Define global variables ********************************/

WORD msgCount = 0;

unsigned long CANid;
BYTE CANdata[10];
BYTE CANdatalen;
enum CAN_RX_MSG_FLAGS CANflags;

char canMessage[10] = "hello";


/********************* Code **************************************************/

void CANInit( void )
{
CANInitialize(1, 5, 8, 8, 3, CAN_CONFIG_ALL_VALID_MSG);

CANSetOperationMode(CAN_OP_MODE_CONFIG);

PIE3bits.RXB0IE = 1;
IPR3bits.RXB0IP = 1;

CANSetOperationMode(CAN_OP_MODE_NORMAL);
}


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

void Init( void )
{
/* set TMR2 postcalar to be 1:10, with */
/* reload value to give 500Hz for 4MHz */
/* xtal, and turn TMR2 on. TMR2 is used to */
/* call the Salvo system timer. */

PR2 = TMR2_RELOAD;

T2CON = 0x4C; //01001100

/* enable TMR2 interrupts, enable */
/* peripheral interrupts, enable (global) */
/* interrupts. */

PIE1bits.TMR2IE = 1;
INTCONbits.PEIE = 1;

/* init h/w, etc. */

TRISD = 0x00; // ChipSelect, PIZO, LED 5-6
TRISJ = 0x00; // LED 1-4

TRISH = 0xff; // BOLT position 1-4
TRISE = 0xff; // BOLT position 5-6
TRISB = 0xff; // Door switches

ADCON1 = 0x03; // dont want AD Converter

PORTJ = 0x00; // kill LEDs
PORTD = 0xE0; // top 3 bits to 1 to de-select controller chips, rest to kill PIZO & LEDs

}


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

int main( void )
{
// init H/W

Init();

/* initialize Salvo. */
OSInit();

OSCreateBinSem(BINSEM_UPDATE_LED, 0);
OSCreateBinSem(BINSEM_CAN_MSG_RCVD, 0);

/* create tasks. */
OSCreateTask(TaskLED, OSTCBP(1), 8);
OSCreateTask(TaskCANRcvd, OSTCBP(2), 8);
OSCreateTask(TaskCANSend, OSTCBP(3), 8);

CANInit();

// enable interrupts

OSEi();

// go!

for (;;)
OSSched();

}

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

void TaskCANRcvd( void )
{
for (;;) {

OS_WaitBinSem(BINSEM_CAN_MSG_RCVD, OSNO_TIMEOUT, 0);

++msgCount;

if (CANIsRxReady())
CANReceiveMessage(&CANid, CANdata, &CANdatalen, &CANflags);

OSSignalBinSem(BINSEM_UPDATE_LED);
}
}


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

void TaskCANSend( void )
{
static int x;

for (;;) {
OS_Delay(25000, 0);

CANSendMessage(0x00, (BYTE *) canMessage, 5, CAN_TX_PRIORITY_0 & CAN_TX_STD_FRAME & CAN_TX_NO_RTR_FRAME);

x++;
}
}

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

void TaskLED( void )
{
static BYTE bitOn = 0;

for (;;) {
OS_WaitBinSem(BINSEM_UPDATE_LED, OSNO_TIMEOUT, 0);

bitOn = 1;
}
}


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

#pragma interrupt ISRHigh save=PROD,section(".tmpdata")

void ISRHigh( void )
{
if ( PIE1bits.TMR2IE && PIR1bits.TMR2IF ) {
PIR1bits.TMR2IF = 0;

OSTimer();
}

if ( PIE3bits.RXB0IE && PIR3bits.RXB0IF ) {
PIR3bits.RXB0IF = 0;

OSSignalBinSem(BINSEM_CAN_MSG_RCVD);
}

}

#pragma code IntVectorHigh = 0x08

void IntVectorHigh( void )
{
_asm
goto ISRHigh
_endasm
}


salvocfg.h------------------------------------
#define OSBYTES_OF_DELAYS 2
#define OSEVENTS TRUE
#define OSEVENT_FLAGS 5
#define OSMESSAGE_QUEUES 2
#define OSTASKS 10

#define OSENABLE_TCBEXT0 TRUE
#define OSTYPE_TCBEXT0 void *

#define OSENABLE_BINARY_SEMAPHORES TRUE
#define OSENABLE_EVENT_FLAGS TRUE
#define OSENABLE_SEMAPHORES TRUE
#define OSENABLE_TIMEOUTS TRUE
#define OSENABLE_MESSAGES TRUE
#define OSENABLE_MESSAGE_QUEUES TRUE



[This message has been edited by aek (edited May 04, 2004).]

calluml
 
Posts: 10
Joined: Fri Mar 05, 2004 12:00 am
Location: united kingdom

Re: OSSignalBinSem from ISR never gets there

Postby calluml » Tue May 04, 2004 3:39 am

Oops, sorry, probably should have mailed that code seperately!
calluml
 
Posts: 10
Joined: Fri Mar 05, 2004 12:00 am
Location: united kingdom

Re: OSSignalBinSem from ISR never gets there

Postby aek » Tue May 04, 2004 3:44 am

Easy ...
code:
#define OSEVENTS TRUE

comes out of the preprocessor as
code:
#define OSEVENTS 1

when in fact you need at least
code:
#define OSEVENTS 2

(Previous stuff about PICC-18 deleted, since they don't apply when you're using MPLAB-C18 ... my bad.)

[This message has been edited by aek (edited May 04, 2004).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: OSSignalBinSem from ISR never gets there

Postby aek » Tue May 04, 2004 3:47 am

BTW, the reason why it compiles but doesn't run properly is that with OSEVENTS set (inadvertantly) to 1, yet you're creating and using two events (binSems, in this case), any operation on the second binSem is on memory that is allocated for (and potentially used by) something else. And that, of course, causes problems.

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

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: OSSignalBinSem from ISR never gets there

Postby calluml » Wed May 05, 2004 11:11 am

As suspected, my own stupid fault.

Many thanks for the help.

calluml
 
Posts: 10
Joined: Fri Mar 05, 2004 12:00 am
Location: united kingdom


Return to PICmicro MCUs

Who is online

Users browsing this forum: No registered users and 2 guests

cron