Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


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 ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner