Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

ISR/semaphore help on PIC18F

Posted by Robert Clarke on May 7, 2010
Hi all,

I am new to FreeRTOS but I really need to get to grips with it so any help anyone can give me will be much appreciated.

I am using the PIC18 port on a PIC18F4680 and I am having trouble with the UART interrupt and a semaphore.
Esentially, I have 2 tasks a LED flashing task that is run every 250 ticks, and a Uart character recevied task which is blocked until a binary semaphore is taken. I am using xSemaphoreGiveFromISR inside the vSerialRxISR() to signal the uart task to wake up and process the char recieved but it does not work.
upon sending a char from hyperterm, the code on the pic handle the one char and then locks up and neither task ether led flashing or subsequent chars are handled. I can only assume I am missing something. I have posted my code snippetes below

void main(void) {
heapinit(); //Start optimized "Heap Management For Small Microcontrollers"

InitPic();
InitRS232();


//create LED flash task
xTaskCreate(Task1, (const portCHAR * const) "Ts1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
//create RX processing task
xTaskCreate(Task2, (const portCHAR * const) "Ts2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL);

//start scheduler
vTaskStartScheduler();

while(1) {
}
}

//RX ISR
void vSerialRxISR() {
static signed portBASE_TYPE xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE;

/* Unblock the task by releasing the semaphore. */
if(xSemaphoreGiveFromISR( xUartSem, &xHigherPriorityTaskWoken ) == pdTRUE){
//force a context switch
portYIELD();
}

//led flash task
void Task1(void *params) {

while(1){

LATBbits.LATB4 ^= 1;
LATBbits.LATB5 ^= 1;
vTaskDelay(250); //block task for 1S (250 ticks)
}
}

//RX recieved task
void Task2(void *params) {
__reclaim_stack();
vSemaphoreCreateBinary(xUartSem); //create the binary semaphore

while(1) {
/*Block waiting for the semaphore to become available. */
if( xSemaphoreTake( xUartSem, 100 ) == pdTRUE )
{
/* It is time to execute. */
serial_register = RCREG; // get the next byte



Process_RX(); //process the command




/* We have finished our task. Return to the top of the loop where
we will block on the semaphore until it is time to execute
again. Note when using the semaphore for synchronisation with an
ISR in this manner there is no need to 'give' the semaphore back. */
}


}
}

RE: ISR/semaphore help on PIC18F

Posted by Richard on May 7, 2010
The code you have posted is not particularly easy to read (formatting has been lost) but I cannot see anything that looks wrong.

The PIC18 is not an ideal target for running a real time kernel, and it might just be that it is running too slowly, resulting in overrun errors in the UART. You could try adding the following to the ISR:

/* Clear any overrun errors. */
if( RCSTAbits.OERR )
{
RCSTAbits.CREN = serCLEAR_OVERRUN;
RCSTAbits.CREN = serCONTINUOUS_RX;
}


Also you could try looking at the usual suspects of stack overflow, etc.

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists