Quality RTOS & Embedded Software

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




Loading

PIC32 PORTSetBits macro

Posted by Kristof Eykens on July 22, 2011
When using these peripheral macro's when initializing the board the instruction are executed. When I use theses macro's like PORTSetBits and PORTClearBits within a vTaskSupendAll code block. The motor are not started or stopped.
Am I missing some configuration?

RE: PIC32 PORTSetBits macro

Posted by Kristof Eykens on July 22, 2011
prototype of the task looks like this:

void vTaskCPanel(void *pvParameters)
{
char action;
portBASE_TYPE xStatus;
char isBusy = 0;
TaskType event;
unsigned int sensorValue;

datacontainer data;
pin_locationmotor;
pin_locationsensor;

motor.portId1 = IOPORT_F;
motor.bit1= BIT_0;
motor.portId2= IOPORT_F;
motor.bit2= BIT_1;

sensor.portId1 = IOPORT_B;
sensor.bit1= BIT_15;
sensor.portId2= IOPORT_D;
sensor.bit2= BIT_4;

data.motor = motor;
data.sensor = sensor;

for(;;)
{
// wait for action queue, to be filled by vTaskEthListener
if (isBusy == 0)
{
xStatus = xQueueReceive(xQueueCPanel, &action, portMAX_DELAY);
if ( xStatus == pdPASS)
{
isBusy = 1;
event = Start;
}
else
{
// TODO: send error
}
}

// handle action
switch (action)
{
case 0:
switch (event)
{
case Start:
vTaskSuspendAll();
{
PORTSetBits(IOPORT_F, BIT_0);
PORTClearBits(IOPORT_F, BIT_1);
}
xTaskResumeAll();

event = Running;
break;
case Running:
vTaskSuspendAll();
{
sensorValue = PORTReadBits(IOPORT_B, BIT_15);
if (sensorValue == 0)
{
InternalMotorStop(&motor);
event = Stopped;
}
}
xTaskResumeAll();

break;
case Stopped:
isBusy = 0;
break;
}
// TODO: read core timer to check for sensor errors

// Delay task
vTaskDelay(100/portTICK_RATE_MS);
break;
case 1:
switch (event)
{
case Start:
vTaskSuspendAll();
{
PORTSetBits(motor.portId2, motor.bit2);
PORTClearBits(motor.portId1, motor.bit1);
}
xTaskResumeAll();

event = Running;
break;
case Running:
vTaskSuspendAll();
{
sensorValue = PORTReadBits(sensor.portId2, sensor.bit2);
if (sensorValue == 0)
{
InternalMotorStop(&motor);
event = Stopped;
}
}
xTaskResumeAll();

break;
case Stopped:
isBusy = 0;
break;
}
// TODO: read core timer to check for sensor errors

// Delay task
vTaskDelay(100/portTICK_RATE_MS);
break;
}
}
}

RE: PIC32 PORTSetBits macro

Posted by Kristof Eykens on July 25, 2011
After rewriting the project with FreeRTOS, I forgot to enable the motor circuit...
Sorry for my stupidity!


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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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