Pumpkin, Inc.

Pumpkin User Forums

Problem with Binary semaphore when signalled in ISR

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®).

Problem with Binary semaphore when signalled in ISR

Postby srihari » Tue Jul 10, 2007 11:41 am

Hello,
I'am new to salvo rtos,i have written a code for reading a pulse using harware interrupt(RB0 int PIC16F877a). as shown below
code:

#include"main.h"
#include"salvo.h"

#define TASK_COUNT_P OSTCBP(2)
#define TASK_SERIAL_P OSTCBP(1)

#define PRIO_COUNT 8
#define PRIO_SERIAL 8

#define TMR0_RELOAD 156
#define BINSEM_UPDATE_PORT_P OSECBP(1)

unsigned int counter=0;

_OSLabel(TaskCount1)
_OSLabel(TaskSerial1)
void TaskCount(void)
{

for(; ;)
{
OS_WaitBinSem(BINSEM_UPDATE_PORT_P,OSNO_TIMEOUT,TaskCount1);
lcd_putch((counter/10000)+48); //display counter to lcd
lcd_putch((counter/1000)%10+48);
lcd_putch((counter/100)+48);
lcd_putch((counter/10)%10+48);
lcd_putch((counter%10)+48);

}
}

void TaskSerial(void)
{

char test;
for(; ;)
{
if(RCIF==0) // check if any charcter received from serial port
{
clear_usart_errors_inline;
}
else
{
test=RCREG;
lcd_goto(0x18);
lcd_putch(test);
}
OS_Yield(TaskSerial1);
}
}

int main(void)
{

RBPU=1; //portb pull-ups disabled
ADCON1=0x06;// SELECT digital i/o pins
gie_on; // Global Interrupt enabled
PEIE=0; // Peripheral Interrupt disabled
T0CS=0;
T0IE=0; // TMR0 Overflow Interrupt disabled
RCIE=0; // USART Receive Interrupt enabled
TRISA=0x00; //0x02; //-- RA0 for AT45DB081B Chip Select,RA1 checking the Busy flag,RA2 for Battery Voltage,RA3 for LED
TRISB=0xFf; //-- Keypad
TRISC=0x92; //-- 0x82 dont change this if u change there will be a problem in serial communication
TRISD=0x20; //--
TRISE=0X00; //-- Enable RE1
INTF=0;
INTE=1;
//--- Initialize the LCD------------------------------------------------------------------
lcd_init();
lcd_clear();
serial_setup();
lcd_goto(0x00);
lcd_puts("Testing RTOS ");

Init();
OSInit();
OSCreateTask(TaskCount,TASK_COUNT_P,PRIO_COUNT);
OSCreateTask(TaskSerial,TASK_SERIAL_P,PRIO_SERIAL);
OSCreateBinSem(BINSEM_UPDATE_PORT_P,0);
for(; ;)
{
OSSched();
}

}

void interrupt IntVector(void)
{
if(T0IE && T0IF)
{
T0IF=0;
TMR0 -= TMR0_RELOAD;
OSTimer();
}
if(INTE && INTF)
{
INTF=0;
counter++;
OSSignalBinSem(BINSEM_UPDATE_PORT_P);
}

}


// salvocfg.h file

#define OSUSE_LIBRARY TRUE
#define OSLIBRARY_TYPE OSF
#define OSLIBRARY_CONFIG OSA
#define OSLIBRARY_VARIANT OSB
#define OSEVENTS 2
#define OSEVENT_FLAGS 1
#define OSMESSAGE_QUEUES 0
#define OSTASKS 3


#define OSCOMPILER OSHT_PICC
#define OSTARGET OSPIC16
#define OSENABLE_BINARY_SEMAPHORE TRUE


The problem is, counter value is getting changed and sometimes semaphore is notgetting signalled
I have changed OSEVENT_FLAGS to value 2,but still i'am getting the problem.

Gloabal variable counter is getting corrupted,please help.

[This message has been edited by aek (edited July 12, 2007).]

srihari
 
Posts: 2
Joined: Mon Jul 09, 2007 11:00 pm
Location: secunderabad,andhrapradesh,india

Re: Problem with Binary semaphore when signalled in ISR

Postby aek » Thu Jul 12, 2007 10:13 am

I think you have a runtime error -- you're running two tasks as the same priority, where one is always yielding (i.e. always running), and you're going putch()'s to an LCD which is probably pretty slow. My guess is that OSSignalBinSem() is in fact returning an error on many occasions because the binSem is full. Check the return codes for OSSignalBinSem().

Also, remove the last three lines from your salvocfg.h.

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

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

Re: Problem with Binary semaphore when signalled in ISR

Postby srihari » Thu Jul 19, 2007 4:19 am

quote:
Originally posted by aek:
I think you have a runtime error -- you're running two tasks as the same priority, where one is always yielding (i.e. always running), and you're going putch()'s to an LCD which is probably pretty slow. My guess is that OSSignalBinSem() is in fact returning an error on many occasions because the binSem is full. Check the return codes for OSSignalBinSem().

Also, remove the last three lines from your salvocfg.h.


Thanks.

srihari
 
Posts: 2
Joined: Mon Jul 09, 2007 11:00 pm
Location: secunderabad,andhrapradesh,india


Return to PICmicro MCUs

Who is online

Users browsing this forum: No registered users and 3 guests

cron