Tool/software: TI-RTOS
Hi,
Having difficulty getting a global variable set in another task to be at the correct value when referenced in another task. This is similar to archived post at e2e.ti.com/.../367224.
I have tried using static and volatile keywords to no avail. I am trying to use UART to send a file to the board for processing and back to the originator when complete.
Code with problem is listed below. In the code below the global variables, g_uart_handle and buffPointer, retain their correct values across tasks but outputData does not. Any help would be greatly appreciated.
/*
* @file main.c
*
* Created on: Jan 3, 2019
* Author: Damian Oslebo
*
*/
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include "stdio.h"
#include "stdint.h"
#include "stdlib.h"
#include "string.h"
/* UART Header files */
#include <ti/drv/uart/UART.h>
#include <ti/drv/uart/UART_stdio.h>
#include <ti/drv/uart/test/src/UART_board.h>
/* My Headers */
#include "Constants.h"
#include "RedundantWaveletTransform.h"
/* Function Declarations */
typedef enum taskID{task_start,task_end,task_rwt} taskID;
void Board_initUART(void);
void uart_transfer_start(UArg arg0, UArg arg1);
void perform_rwt(UArg arg0, UArg arg1);
void uart_transfer_end(UArg arg0, UArg arg1);
void queue_task(taskID id);
/* Constants */
#define XMITTER_RDY 123
/* Global Variables */
UART_Handle g_uart_handle;
/*static volatile*/ char buffPointer[BUFFER_SIZE << 2];
static volatile float outputData[NUM_STAGES][BUFFER_SIZE];
int main(void)
{
/* Call board init functions */
Board_initUART();
queue_task(task_start);
/* Start BIOS */
BIOS_start();
return (0);
} /* main */
void queue_task(taskID id)
{
Task_Handle task;
Error_Block eb;
Task_Params tskParams;
tskParams.priority = 1;
Error_init(&eb);
Task_Params_init(&tskParams);
switch(id)
{
case task_start:
task = Task_create(uart_transfer_start, &tskParams, &eb);
break;
case task_end:
task = Task_create(uart_transfer_end, &tskParams, &eb);
break;
case task_rwt:
task = Task_create(uart_transfer_end, &tskParams, &eb);
break;
default:
break;
}
if (task == NULL) {
System_printf("Task_create() failed!\n");
BIOS_exit(0);
}
}
void Board_initUART(void)
{
Board_initCfg boardCfg;
UART_Params params;
boardCfg = BOARD_INIT_MODULE_CLOCK;
Board_init(boardCfg);
UART_init();
UART_Params_init(¶ms);
params.baudRate = 115200;
params.writeDataMode = UART_DATA_BINARY;
params.readDataMode = UART_DATA_BINARY;
params.readReturnMode = UART_RETURN_FULL;
params.readEcho = UART_ECHO_OFF;
g_uart_handle = UART_open(UART_INSTANCE, ¶ms);
if (!g_uart_handle) {
System_printf("UART did not open");
}
} /* Board_initUART */
void uart_transfer_start(UArg arg0, UArg arg1)
{
char start_token = XMITTER_RDY;
int32_t databufferSize = BUFFER_SIZE << 2;
memset(buffPointer,0,databufferSize);
UART_writePolling(g_uart_handle,&start_token,1);
databufferSize = UART_readPolling(g_uart_handle,buffPointer,databufferSize);
queue_task(task_rwt);
} /* uart_transfer_start */
void uart_transfer_end(UArg arg0, UArg arg1)
{
char start_token = XMITTER_RDY;
float value;
int32_t index, index2;
UART_writePolling(g_uart_handle,&start_token,1);
/* This assignment will work because in the same task?
for(index = 0; index < BUFFER_SIZE; index++)
{
outputData[0][index] = 3.2f;
}
*/
for(index = 0; index < NUM_STAGES; index++)
{
for(index2 = 0; index2 < BUFFER_SIZE; index2++)
{
value = outputData[index][index2];
UART_writePolling(g_uart_handle,&value, 4);
}
}
} /* uart_transfer_end */
void perform_rwt(UArg arg0, UArg arg1)
{
int32_t index;
for(index = 0; index < BUFFER_SIZE; index++)
{
outputData[0][index] = 3.2f;
}
queue_task(task_end);
} /* perform_rwt */
