k1mgy wrote on Monday, November 06, 2017:
Thank you. I read the material on interrupts. I’m including the relevant code below.
My processor is the AT91SAMG55 (ARM Cortex-M4). The data sheet tells me that priority 0 is the highest (opposite of most other devices). What I can’t fathom is the maximum number of interrupt priorities available. It’s either a 4 or 8 bit register… but there are some complexities. Maybe this doesn’t matter. Uncertain how this plays into the FreeRTOS event priority scheme or even if these are related. For now I am going to assume that the priority scheme relies on the CPU and therefore that 0 has the highest priority.
Questions:
1.** configMAX_PRIORITIES** is set to 5 in FreeRTOSConfig.h. Is this the setting to establish the max number of priorities available on the device? It’s unclear from the description of this setting. For now, since priority 0 = max on the CPU, I have set #tskIDLE_PRIORITY to 5 (assuming for the moment that 5 is the lowest).
-
Are interrupts turned off at any time during running of the scheduler? It appears at first glance this is so, as my GPIO interrupt handler is not triggered during scheduler execution.
-
For now, I have set up a simple boolean token that will, I hope, prevent any conflict between two timer tasks from accessing the SPI buss at the same time. A task that needs access to the SPI must get the token. If it does not, then any SPI calls within the task are disallowed. I’m concerned however that two timer-based tasks might request the token simultaneously. Hopefully these will not clash. I’d rather use a FreeRTOS-based token that guarantees its integrity. Any suggestions?
Priority constants:
#define tskIDLE_PRIORITY ( ( UBaseType_t ) 5U )
#define TOUCHPARSE_TASK_PRIORITY ( 1 )
#define TOUCHPARSE_STACK_SIZE (1024/sizeof(portSTACK_TYPE))
#define ADC_CONVERT_TASK_PRIORITY ( 3 )
#define ADC_CONVERT_STACK_SIZE (1024/sizeof(portSTACK_TYPE))
#define SCREEN_UPDATE_TASK_PRIORITY ( 2 )
#define SCREEN_UPDATE_STACK_SIZE (1024/sizeof(portSTACK_TYPE))
// task definitions
#define TASK_MONITOR_STACK_SIZE (1024/sizeof(portSTACK_TYPE))
#define TASK_MONITOR_STACK_PRIORITY (tskIDLE_PRIORITY)
#define TASK_LED_STACK_SIZE (1024/sizeof(portSTACK_TYPE))
#define TASK_LED_STACK_PRIORITY (tskIDLE_PRIORITY)
// global
bool GpuReadToken;
bool GetGPUReadToken(void)
{
if (!GpuReadToken)
GpuReadToken=true;
return(GpuReadToken);
}
void ClearGPUReadToken(void)
{
GpuReadToken=false;
}
--
main.c:
/* Create task to monitor processor activity */
if (xTaskCreate(task_mon, "Monitor", TASK_MONITOR_STACK_SIZE, NULL,
TASK_MONITOR_STACK_PRIORITY, NULL) != pdPASS)
{
printf("Failed to create task_mon task\r\n");
}
// Create task to make led blink
if (xTaskCreate(task_led, "Led", TASK_LED_STACK_SIZE, NULL,
TASK_LED_STACK_PRIORITY, NULL) != pdPASS)
{
printf("Failed to create test led task\r\n");
}
if (xTaskCreate(TouchParse, "TouchParse", TOUCHPARSE_STACK_SIZE, NULL,
TOUCHPARSE_TASK_PRIORITY, NULL) != pdPASS)
{
printf("Failed to create adc_conv task\r\n");
}
if (xTaskCreate(adc_conv, "ADC Convert", ADC_CONVERT_STACK_SIZE, NULL,
ADC_CONVERT_TASK_PRIORITY, NULL) != pdPASS)
{
printf("Failed to create adc_conv task\r\n");
}
if (xTaskCreate(ScreenUpdate, "Screen Update", SCREEN_UPDATE_STACK_SIZE, NULL,
SCREEN_UPDATE_TASK_PRIORITY, NULL) != pdPASS)
{
printf("Failed to create ScreenUpdate task\r\n");
}
-- callbacks --
void TouchParse(void *pvParameters)
{
static portCHAR szList[256];
UNUSED(pvParameters);
for (;;)
{
if (GetGPUReadToken())
{
// SPI CALL
tag_touched = Ft_Gpu_Hal_Rd32(phost, REG_TOUCH_TAG) & 0xFF;
ClearGPUReadToken();
}
// valid press
if (tag_touched>0 && tag_touched<99)
{
printf("***TP: Valid tag_touched[%i]\n\r",tag_touched);
Play_Sound(0x23,255);
vTaskDelay(50);
Stop_Sound();
vTaskDelay(450);
sprintf(cUtilStr,"Touched [%i]\0",tag_touched);
}
vTaskDelay(250); // 250mS
}
}
void ScreenUpdate(void *pvParameters)
{
UNUSED(pvParameters);
for (;;)
{
if (GetGPUReadToken())
{
// SPI CALL
BaseScreen();
ClearGPUReadToken();
}
is_conversion_done = false;
adc_start_software_conversion(ADC);
vTaskDelay(1000);
}
}