Pumpkin, Inc.

Pumpkin User Forums

Semaphores

If you can't make Salvo do what you want it to do, post it here.

Semaphores

Postby aek » Thu Dec 16, 2004 2:04 am

Use
code:
#define BINSEM_CLEARLCD_P OSECBP(5)

instead.

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

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

Re: Semaphores

Postby simon11 » Thu Dec 16, 2004 10:06 am

I am currently attempting to run a binary semaphore in my code using the C 18 compiler. My code is below. I am receiving a syntax error on the line OSSignalBinSem(BINSEM_CLEARLCD_P); and I am confused as to why.


#include "Superbrick.inc"
#include "salvo.h"
#include "SB.h"

_OSLabel(TaskDisplay1)
_OSLabel(TaskCAN1)
_OSLabel(TaskClear1)
#define BINSEM_CLEARLCD_P OSECBP(5);
void low_isr (void);
void ClearLCD (void);

/* VARIABLES */
char icheck;
char c;
unsigned int ButtonPress;
unsigned int Disp;

//CAN Setup Variables
unsigned int BufferConfig;
unsigned int BitTimeConfig;
unsigned int InterruptEnables;
unsigned int SPI_SyncMode;
unsigned int SPI_BusMode;
unsigned int SPI_SmpPhase;

//Send Variables
unsigned int SmsgId;
unsigned char SmsgPriority;
unsigned char SnumBytes;
unsigned char Sdata [8];
//Receive Variables
unsigned long RmsgId[1];
unsigned char RnumBytes[1];
unsigned char Rdata [8];


/* ISRS */
#pragma code low_vector = 0x18
void interrupt_at_low_vector (void){
_asm GOTO low_isr _endasm
}

#pragma code // Return to the default code section
#pragma interruptlow low_isr save=PROD

void low_isr (void){
if ((INTCON3 & 0x02) != 0){ //Button Press
Disp = 1; //Signals to Display
ButtonPress = PORTB / 32; //Stores Button Press
}
if ((INTCON3 & 0x01) != 0){ //CAN Interrupt
/*unsigned char CAN2510DataRead(
unsigned char bufferNum,
unsigned long *msgId,
unsigned char *numBytes,
unsigned char *data );
*/
}
INTCON3 &= 0xFC; //Set Flags to 0
}

/* FUNCTIONS */
void DelayFor18TCY (void){
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
}
void DelayPORXLCD (void){
Delay10KTCYx(60); //Delay of 15ms
return;
}
void DelayXLCD (void){
Delay10KTCYx(20); //Delay of 5ms
return;
}

/* TASKS */
void TaskDisplay (void) {
for(;;){
if (Disp == 1){
Disp = 0;
ButtonPress = 'ButtonPress';
WriteDataXLCD(ButtonPress); //write to LCD
icheck += icheck;
if (icheck == 16){
OSSignalBinSem(BINSEM_CLEARLCD_P);
}
}
OS_Yield(TaskDisplay1); //Yield to Scheduler
}
}

void TaskCAN (void) {
for(;;){
if (Disp == 1){
Sdata [0] = ButtonPress;
SmsgId = 0xFF;
SmsgPriority = CAN2510_PRI_HIGHEST;
SnumBytes = 0x02;
CAN2510WriteStd(SmsgId, SmsgPriority, SnumBytes, Sdata );
}
OS_Yield(TaskCAN1); //Yield to Scheduler
}
}

void TaskClear(void){
for(;;){
OS_WaitBinSem(BINSEM_CLEARLCD_P, OSNO_TIMEOUT, TaskClear1);

TRIS_DATA_PORT = 0x00; // Make port output
DATA_PORT = 0x01; // Write 1 to port
RS_PIN = 0; // Set control bits
RW_PIN = 0;
DelayFor18TCY();
E_PIN = 1; // Clock data into LCD
DelayFor18TCY();
E_PIN = 0;
RS_PIN = 0; // Reset control bits
TRIS_DATA_PORT = 0xff;
icheck = 0; // Reset Clear Check
}
}

/* MAIN */
void main (void) {

BufferConfig = CAN2510_RESET & CAN2510_RXB0_NOFILT & CAN2510_RXB1_NOFILT & CAN2510_RXB0_ROLL & CAN2510_RX1BF_OFF & CAN2510_RX0BF_OFF & CAN2510_TX2_GPIN & CAN2510_TX1_GPIN & CAN2510_TX0_GPIN & CAN2510_REQ_CONFIG & CAN2510_CLKOUT_8;
BitTimeConfig = CAN2510_BRG_1x & CAN2510_SJW_1TQ & CAN2510_PH2SEG_2TQ & CAN2510_PH1SEG_1TQ & CAN2510_PROPSEG_1TQ & CAN2510_PH2SOURCE_PH2 & CAN2510_SAMPLE_1x & CAN2510_RX_FILTER;
InterruptEnables = CAN2510_NONE_EN;
SPI_SyncMode = CAN2510_SPI_FOSC4;
SPI_SyncMode = CAN2510_SPI_MODE00;
SPI_SmpPhase = CAN2510_SPI_SMPMID;

c = CAN2510Init(BufferConfig, BitTimeConfig, InterruptEnables, SPI_SyncMode, SPI_BusMode, SPI_SmpPhase);

//Set up CAN for Normal Operation Mode
CAN2510SetMode(CAN2510_MODE_NORMAL);

//Setup Port B for Inputs
TRISB = 0xFF;
TRISA = 0x00;
TRISD = 0x00;
TRISC &= 0xFC;
TRISE &= 0xFB;

//Initialize INT2 & Set Priority of INT2 to low
INTCON3 = 0x10;
INTCON |= 0xC0;
ADCON0 &= 0xFE; //Turn A/D Converter off
ADCON1 |= 0x0F; //Set Inputs to digital inputs

OpenXLCD( EIGHT_BIT & LINES_5X7 );

//SBInit();
//Initialize OS
OSInit();

//Creating Tasks ID Priority
OSCreateTask(TaskDisplay, OSTCBP(1), 5);
OSCreateTask(TaskCAN, OSTCBP(2), 5);
OSCreateTask(TaskClear, OSTCBP(3), 2);

OSCreateBinSem(BINSEM_CLEARLCD, 0);
icheck = 0;

for (;;)
OSSched();
}

simon11
 
Posts: 20
Joined: Mon Nov 08, 2004 12:00 am
Location: Worcester,MA,usa


Return to Coding

Who is online

Users browsing this forum: No registered users and 4 guests

cron