I’m working with the PIC32 USB Starter Kit II with a PIC32MX795F512L. The 18 sample software projects provided by FreeRTOS.org in the purchased manual used version 7.5.3.
I made a project that creates a CHANGE
NOTICEVECTOR interrupt that responds to an SW1 button press. In addition, I created another task that flashes an LED (25ms ON / 50ms OFF).
When I press SW1, I get a message from my task that responds to the interrupt, but I notice the LED flashing is interrupted. When I press and hold SW1, the LED does not flash at all, and I don’t get my message until I release SW1.
I tried increasing the priority of my LED flashing task. I also switched from using assembly code for the interrupt to straight C. I looked for other configuration settings for the change notice. Nothing seems to help.
I also have a UART2 interrupt and related task that seems to operate properly without affecting the LED flash rate.
Any help would be appreciated.
Code:
~~~~
include <p32xxxx.h>
include <plib.h>
include “FreeRTOS.h”
include “task.h”
include “semphr.h”
include “basic_io.h”
pragma config FPLLODIV = DIV1, FPLLMUL = MUL20, FPLLIDIV = DIV_2
pragma config FWDTEN = OFF, FPBDIV = DIV_2, POSCMOD = XT, FNOSC = PRIPLL, CP = OFF
pragma config FSRSSEL = PRIORITY_7
static void vHandlerTask( void *pvParameters );
static void vHandlerTask2( void *pvParameters );
void vSetupEnvironment( void );
static void vTimerFunction( void *pvParameters );
xSemaphoreHandle xBinarySemaphore, xBinarySemaphore2;
define DESIRED_BAUDRATE (9600)
define SYSCLK (80000000L)
define MAXCOMMANDSIZE 256
char CommandString[MAXCOMMANDSIZE];
int CommandLoc = 0;
int main( void ) {
vSetupEnvironment();
vSemaphoreCreateBinary( xBinarySemaphore );
vSemaphoreCreateBinary( xBinarySemaphore2 );
if( xBinarySemaphore != NULL && xBinarySemaphore2 != NULL) {
xTaskCreate( vHandlerTask, ( signed char * ) "Handler", 240, NULL, 2, NULL );
xTaskCreate( vHandlerTask2, ( signed char * ) "Handler 2", 240, NULL, 2, NULL );
xTaskCreate( vTimerFunction, ( signed char * ) "LED Task", 240, NULL, 3, NULL );
vTaskStartScheduler();
}
for( ;; );
return 0;
}
static void vHandlerTask( void *pvParameters ) {
xSemaphoreTake( xBinarySemaphore, 0 );
for( ;; ) {
xSemaphoreTake( xBinarySemaphore, portMAX_DELAY );
putsUART2("Command string: ");
putsUART2(CommandString);
putsUART2("n");
CommandLoc = 0;
}
}
static void vHandlerTask2( void *pvParameters ) {
xSemaphoreTake( xBinarySemaphore2, 0 );
for( ;; ) {
xSemaphoreTake( xBinarySemaphore2, portMAX_DELAY );
putsUART2("button eventn");
}
}
void __ISR(
CHANGENOTICE_VECTOR, ipl1) vButtonISRHandler(void) {
long sHigherPriorityTaskWoken = pdFALSE;
mCNClearIntFlag();
xSemaphoreGiveFromISR( xBinarySemaphore2, &sHigherPriorityTaskWoken );
portEND_SWITCHING_ISR( sHigherPriorityTaskWoken );
}
void __ISR(
UART2VECTOR, ipl2) IntUart2Handler(void) {
unsigned int ch;
long sHigherPriorityTaskWoken = pdFALSE;
if(INTGetFlag(INT_SOURCE_UART_RX(UART2))) {
INTClearFlag(INT_SOURCE_UART_RX(UART2));
while (DataRdyUART2()) {
ch = getcUART2();
putcUART2(ch);
if (ch == 10 || ch == 13) {
if (CommandLoc > 0)
xSemaphoreGiveFromISR( xBinarySemaphore, &sHigherPriorityTaskWoken );
}
else if (CommandLoc < MAXCOMMANDSIZE-1) {
CommandString[CommandLoc++] = ch;
CommandString[CommandLoc] = 0;
}
else {
xSemaphoreGiveFromISR( xBinarySemaphore, &sHigherPriorityTaskWoken );
}
}
}
if ( INTGetFlag(INT_SOURCE_UART_TX(UART2)) ) {
INTClearFlag(INT_SOURCE_UART_TX(UART2));
}
portEND_SWITCHING_ISR( sHigherPriorityTaskWoken );
}
void vSetupEnvironment( void ) {
unsigned int dummy;
int pbClk;
SYSTEMConfigPerformance( configCPU_CLOCK_HZ );
mOSCSetPBDIV( OSC_PB_DIV_2 );
mPORTDClearBits(BIT_0 | BIT_1 | BIT_2);
mPORTDSetPinsDigitalOut(BIT_0 | BIT_1 | BIT_2 );
PORTSetPinsDigitalIn(IOPORT_D, BIT_6 | BIT_7);
mCNOpen((CN_ON | CN_FRZ_OFF), (CN15_ENABLE), 0);
dummy = mPORTDRead();
ConfigIntCN((CHANGE_INT_ON | CHANGE_INT_PRI_1));
pbClk=SYSTEMConfig( SYSCLK, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
OpenUART2( UART_EN, UART_RX_ENABLE | UART_TX_ENABLE, pbClk/16/DESIRED_BAUDRATE-1);
INTEnable(INT_SOURCE_UART_RX(UART2), INT_ENABLED);
INTSetVectorPriority(INT_VECTOR_UART(UART2), INT_PRIORITY_LEVEL_2);
INTSetVectorSubPriority(INT_VECTOR_UART(UART2), INT_SUB_PRIORITY_LEVEL_0);
INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
INTEnableSystemMultiVectoredInt();
while( BusyUART2());
putsUART2( "Startuprn");
}
static void vTimerFunction( void *pvParameters ) {
const int DLY1 = 25;
const int DLY2 = 50;
portTickType xLastWakeTime;
mPORTDClearBits(BIT_2);
xLastWakeTime = xTaskGetTickCount();
for( ;; ) {
mPORTDSetBits(BIT_2);
vTaskDelayUntil( &xLastWakeTime, DLY1 / portTICK_RATE_MS );
mPORTDClearBits(BIT_2);
vTaskDelayUntil( &xLastWakeTime, DLY2 / portTICK_RATE_MS );
}
}
~~~~