Pumpkin, Inc.

Pumpkin User Forums

PIC18C452 / OS_WaitSem()

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

PIC18C452 / OS_WaitSem()

Postby Benoit Braud » Wed Jul 10, 2002 5:40 am

My configuration is
* MPLAB-C18 in the MPLAB IDE.
* PIC18C452
* Simulation test.
* library use : slc18sft.lib
* My 'salvocfg.h' is :
code:

#define OSUSE_LIBRARY TRUE
#define OSLIBRARY_TYPE OSL
#define OSLIBRARY_GLOBALS OSF
#define OSLIBRARY_CONFIG OST
#define OSLIBRARY_VARIANT OSA

#define OSTASKS 3
#define OSEVENTS 4



* I want to use semaphore, binary semaphore, timeout

The macro OS_WaitSem() and the function 'OSReadSem()' do not work properly :
For 'OSReadSem()' the result is always 2.
For 'OS_WaitSem()', my task is always waiting. I try to call 'OSWaitEvent()' directly from my code : this function return 2 or 9.

If i watch the 'OSecbArea' memory in 32 bits, I see that the value is like this (i use the second semaphore) : '0000XXYY', where XX is incremented each time i call 'OSSignalSem()'. But the XX value is not decremented by call to 'OS_WaitSem()' and the value return by 'OSReadSem()' is not the XX value.

My code is like this :

code:

#define SEM_TURB_PULSES OSECBP(2)
#define BSEM_TURB_DELTAT OSECBP(1)


void task2 ( void )
{
static UINT16 count = 0;
for (;;) {
err = OSSignalSem( SEM_TURB_PULSES );
count++;
OS_Yield(Task2);
}
}


void task3 ( void )
{
UINT16 count3 = 0;
for (;;) {
OS_WaitSem( SEM_TURB_PULSES, OSNO_TIMEOUT, Task3 );
count3++;
OS_Yield(Task3);
}
}


void main( void )
{
OSInit();

err = OSCreateBinSem( BSEM_TURB_DELTAT, 0);
err = OSCreateSem( SEM_TURB_PULSES, 2);

err = OSCreateTask(task2, OSTCBP(2), 10);
err = OSCreateTask(task3, OSTCBP(3), 9);

while( 1 )
OSSched();
}


Regards.

------------------
Benoit B.

[This message has been edited by aek (edited July 10, 2002).]

Benoit B.
Benoit Braud
 
Posts: 10
Joined: Wed Jul 03, 2002 11:00 pm
Location: Avrillé, France

Re: PIC18C452 / OS_WaitSem()

Postby aek » Wed Jul 10, 2002 7:22 am

Hi Benoit.

1) Set OSLIBRARY_VARIANT to OSNONE (won't affect your compile).

2) Do not call OSWaitEvent() directly -- it's an internal function. Its return codes of 2 and 9 are correct for normal operation.

I wonder if there is a pointer error in this case ...

Can you do a quick test and try it with the slc18snt.lib library (and change salvocfg.h)? This will place all of Salvo's global variables in the access bank.

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

[This message has been edited by aek (edited July 10, 2002).]

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

Re: PIC18C452 / OS_WaitSem()

Postby aek » Wed Jul 10, 2002 9:48 am

Hi Benoit.

I created my own application using your code (no important changes, just complete and with declared labels, using slc18sft.lib) and it works fine (both tasks running, etc.) in MPLAB-SIM. Here's my code:

code:
   #define OSUSE_LIBRARY                TRUE   
#define OSLIBRARY_TYPE OSL
#define OSLIBRARY_GLOBALS OSF
#define OSLIBRARY_CONFIG OST
#define OSLIBRARY_VARIANT OSNONE
#define OSTASKS 3
#define OSEVENTS 4

and
code:
#include "salvo.h"


#define UINT16 unsigned int


#define SEM_TURB_PULSES OSECBP(2)
#define BSEM_TURB_DELTAT OSECBP(1)


_OSLabel(Task2a)
_OSLabel(Task3a)
_OSLabel(Task3b)


unsigned char err;


void Task2 ( void )
{
static UINT16 count = 0;

for (;;)
{
err = OSSignalSem( SEM_TURB_PULSES );
count++;
OS_Yield(Task2a);
}
}


void Task3 ( void )
{
static UINT16 count3 = 0;

for (;;)
{
OS_WaitSem( SEM_TURB_PULSES, OSNO_TIMEOUT, Task3a );
count3++;
OS_Yield(Task3b);
}
}


void OSIdlingHook( void ) { ; }


void main( void )
{
OSInit();

err = OSCreateBinSem( BSEM_TURB_DELTAT, 0);
err = OSCreateSem( SEM_TURB_PULSES, 2);
err = OSCreateTask(Task2, OSTCBP(2), 10);
err = OSCreateTask(Task3, OSTCBP(3), 9);

while( 1 )
OSSched();
}


Both count and count3 are incrementing as I would expect. For example, set a breakpoint on OSSched(). On the 10th breakpoint, count=2 and count3=3. On the 15th, count=3 and count3=5.

Note that because you initialize SEM_TURB_PULSES to 2, Task3() will run twice (count3 = 1, count3 = 2) before Task2() runs (count = 1). Thereafter they will "ping-pong" as Task2() sets the semaphore and Task3() waits it successfully.

Regards,

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

[This message has been edited by aek (edited July 10, 2002).]

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

Re: PIC18C452 / OS_WaitSem()

Postby aek » Wed Jul 10, 2002 9:56 am

Hi Benoit.

One more thing ... I know what you've written is test code. Ultimately you'll want Task3() to look like

code:
void Task3 ( void ) 
{
static UINT16 count3 = 0;

for (;;)
{
OS_WaitSem( SEM_TURB_PULSES, OSNO_TIMEOUT, Task3a );
count3++;
}
}

i.e. the OS_Yield() is not necessary in conjunction with OS_WaitSem(). As written, the OS_Yield() just forces extra trips through the scheduler.

Regards,

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

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

Re: PIC18C452 / OS_WaitSem()

Postby Benoit Braud » Thu Jul 11, 2002 12:04 am

I try your example and i have always the same problem : the task 'Task3' stay lock in the OS_WaitSem(). I think that something is wrong in my configuration. Can you send me all the file of the project you built for testing ? With this, i will try with the same configuration as you.

Do you test with MPLAB-C18 ? Version ?

------------------
Benoit B.

[This message has been edited by aek (edited July 11, 2002).]

Benoit B.
Benoit Braud
 
Posts: 10
Joined: Wed Jul 03, 2002 11:00 pm
Location: Avrillé, France

Re: PIC18C452 / OS_WaitSem()

Postby aek » Thu Jul 11, 2002 7:30 am

Hi Benoit.

1) Did you notice that in your example, count3 is not static? You need to make count3 static ...

2) We tested with C18 v1.10 -- here are the build results:

code:
Building 1.HEX...

Compiling MAIN.C:
Command line: "C:mccinmcc18.exe -w2 -ms -o -isalvoinc -p=18C452 -iD:PUMPKI~1BENOIT~11 D:PUMPKI~1BENOIT~11MAIN.C"
MPLAB C18 v1.10 Copyright 2001 Microchip Technology Inc.
Errors: 0
Warnings: 0

Linking:
Command line: "C:PROGRA~1MPLABMPLINK.EXE /m 1.map /o 1.HEX /l C:MCCLIB /k C:MCCLKR MAIN.O
C:MCCLKR18C452.LKR D:SALVOLIBSLC18SFT.LIB "
MPLINK 2.50, Linker
Copyright (c) 2001 Microchip Technology Inc.
Errors : 0

MP2COD 2.50, COFF to COD File Converter
Copyright (c) 2001 Microchip Technology Inc.
Errors : 0

MP2HEX 2.50, COFF to HEX File Converter
Copyright (c) 2001 Microchip Technology Inc.
Errors : 0


Build completed successfully.


I'll email you the project, *.c and *.h files now. You may have to edit the project to set the paths correctly ...

There is a possibility that the current release (v2) of C18 is either faulty, or perhaps it won't work with libraries compiled with C18 v1.10 ...

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

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


Return to PICmicro MCUs

Who is online

Users browsing this forum: No registered users and 4 guests

cron