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

FreeRTOS on SAM7x: Task only run once

Posted by Nobody/Anonymous on December 20, 2006
Hi all,

i am currently working on a project, where i have one task and one ISR.

without the ISR, the task is run continously. But if the interrupt is enabled the task is only run once.

here is my ISR:

void vCANISR( void ) __attribute__((naked));

void vCANISR( void )
{
portENTER_SWITCHING_ISR();
static volatile unsigned long ulIntStatus, ulIntMask, msgstatus;
static volatile unsigned char TEC, REC;
//portBASE_TYPE xSwitchRequired = pdFALSE;


ulIntStatus = AT91C_BASE_CAN->CAN_SR;
ulIntMask= AT91C_BASE_CAN->CAN_IMR;
ulIntStatus &= ulIntMask;

// For debug only:
TEC = (unsigned char)((AT91C_BASE_CAN->CAN_ECR & 0x00FF0000) >> 16);
REC = (unsigned char)(AT91C_BASE_CAN->CAN_ECR & 0x000000FF);


// BUS_OFF
if (ulIntStatus & AT91C_CAN_BOFF)
{
SAM7_CAN_SetCommStatus(AT91C_CAN_BOFF);
}

// ERROR_PASSIVE
if (ulIntStatus & AT91C_CAN_ERRP)
{
SAM7_CAN_SetCommStatus(AT91C_CAN_ERRP);
}

// ERROR_ACTIVE
if (ulIntStatus & AT91C_CAN_ERRA)
{
SAM7_CAN_SetCommStatus(AT91C_CAN_ERRA);
}

if (ulIntStatus & AT91C_CAN_MB0)//TX mailbox
{
msgstatus= AT91C_BASE_CAN->CAN_MB0.CAN_MB_MSR;
if (msgstatus & AT91C_CAN_MRDY)
{
if (SAM7_CAN_IsrTxMsg(&AT91C_BASE_CAN->CAN_MB0))
{
//queue empty
AT91C_BASE_CAN->CAN_IDR = AT91C_CAN_MB0; //Disable Mailbox 0 IRQ
}
else
{
//send next msg
//AT91C_BASE_CAN->CAN_TCR= AT91C_CAN_MB0; // Transfer request
AT91C_BASE_CAN->CAN_MB0.CAN_MB_MCR = AT91C_CAN_MTCR;// Transfer request
}
}

//xSwitchRequired = xSemaphoreGiveFromISR( xSemaphore, pdFALSE );
}

if (ulIntStatus & AT91C_CAN_MB1)//RX mailbox
{
msgstatus= AT91C_BASE_CAN->CAN_MB1.CAN_MB_MSR;
if (msgstatus & AT91C_CAN_MRDY)
{
SAM7_CAN_IsrRxMsg(&AT91C_BASE_CAN->CAN_MB1);
AT91C_BASE_CAN->CAN_MB1.CAN_MB_MCR = AT91C_CAN_MTCR;// Transfer request
}
//xSwitchRequired = xSemaphoreGiveFromISR( xSemaphore, pdFALSE );
}

if (ulIntStatus & AT91C_CAN_MB2)//RX mailbox
{
msgstatus= AT91C_BASE_CAN->CAN_MB2.CAN_MB_MSR;
if (msgstatus & AT91C_CAN_MRDY)
{
SAM7_CAN_IsrRxMsg(&AT91C_BASE_CAN->CAN_MB2);
AT91C_BASE_CAN->CAN_MB2.CAN_MB_MCR = AT91C_CAN_MTCR;// Transfer request
}
//xSwitchRequired = xSemaphoreGiveFromISR( xSemaphore, pdFALSE );
}

// Clear the interrupt.
AT91C_BASE_AIC->AIC_EOICR = 0;

portEXIT_SWITCHING_ISR( 0 );
//portEXIT_SWITCHING_ISR( xSwitchRequired );
}

NOTE: It is not necessary for the ISR to switch context. This is only done because of earlier experience with the lwip demo for the sam7x where i had a timerISR which would halt program execution if the above syntax weren't implemented (portEXIT_SWITCHING_ISR() and portEXIT_SWITCHING_ISR( 0 )).

is there another way to do this differently ?

RE: FreeRTOS on SAM7x: Task only run once

Posted by Nobody/Anonymous on December 20, 2006
If you do not need a context switch then you can defined the ISR just as a normal ISR - without the naked attribute, and without the ENTER_SWITCHING_ISR() EXIT_SWITCHING_ISR() macros. You use a different attribute which I think is just "IRQ". From memory the documentation page on the FreeRTOS site shows you the syntax. Look at one of the other ARM7 GCC ports documentation to see this.

RE: FreeRTOS on SAM7x: Task only run once

Posted by Nobody/Anonymous on December 21, 2006
Hi,

i have tried that, but it didn't work.
I found that i had to disable the AT91C_CAN_ERRP interrupt. Because it kept the interrupt firing.
But the interrupt is still continually run, eventhough CAN Status register is 0.

And that i cant understand. Because no interrupts on the CAN bus is pending, and still the interrupt handler is executed.

any help would be greatfully apprieciated.

thx

RE: FreeRTOS on SAM7x: Task only run once

Posted by Nobody/Anonymous on December 21, 2006
Presumably you have to clear the interrupt in the CAN peripheral and in the interrupt controller. I suspect one of these is not being done.

I would suggest writing program of hello world simplicity without FreeRTOS to get the CAN interrupt working as you want. Then once its working incorporate your ISR code into your FreeRTOS project.

RE: FreeRTOS on SAM7x: Task only run once

Posted by Nobody/Anonymous on December 21, 2006
>Presumably you have to clear the interrupt in the CAN peripheral and in the interrupt controller. I suspect one of >these is not being done.

You were right about that. Because of my init of the CAN mail boxes an interrupt was triggered because of MRDY was set.

here is the corrected code for the receive mailbox which shutsoff the mailbox0 interrupt if we are done sending
messages:

if (ulIntStatus & AT91C_CAN_MB0) //TX mailbox
{
msgstatus= AT91C_BASE_CAN->CAN_MB0.CAN_MB_MSR;
if (msgstatus & AT91C_CAN_MRDY)
{
if (SAM7_CAN_IsrTxMsg(&AT91C_BASE_CAN->CAN_MB0))
{
//queue empty
AT91C_BASE_CAN->CAN_MB0.CAN_MB_MCR = 0;// Clears MRDY flag
AT91C_BASE_CAN->CAN_IDR = AT91C_CAN_MB0; //Disable Mailbox 0 IRQ
}
else
{
//send next msg
//AT91C_BASE_CAN->CAN_TCR= AT91C_CAN_MB0; // Transfer request
AT91C_BASE_CAN->CAN_MB0.CAN_MB_MCR = AT91C_CAN_MTCR; // Transfer request
}
}



[ 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