This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

safeRTOS + UART + ADC

Hi all, I´m trying to use safertos_demo to create an application that allows to run two task, the first one has to toggle a LED (when some condition active it, aperiodic task), the second one is a periodic task that read analog value and write the UART port, when it reads (analog data from ADC), it writes the data in UART port (periodic task), I´m trying to execute two task like periodic (LED and UART), and then, change (is as should be) LED periodic task into aperiodic task. I can do the analog reading using ADC and write it in UART port without safeRTOS, when I add the safeRTO the software donesn´t do anything. My code is attached.

//*****************************************************************************
//
// led_task.c - A simple flashing LED task.
//
// Copyright (c) 2009-2011 Texas Instruments Incorporated.  All rights reserved.
// Software License Agreement
// 
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
// 
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
// 
// This is part of revision 8049 of the DK-LM3S9D96 Firmware Package.
//
//*****************************************************************************

#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/rom.h"
#include "SafeRTOS/SafeRTOS_API.h"
#include "idle_task.h"
#include "led_task.h"
#include "priorities.h"

//*****************************************************************************
//
// The stack for the LED toggle task.
//
//*****************************************************************************
static unsigned long g_pulLEDTaskStack[128];

//*****************************************************************************
//
// The amount of time to delay between toggles of the LED.
//
//*****************************************************************************
unsigned long g_ulLEDDelay = 500;

//*****************************************************************************
//
// This task simply toggles the user LED at a 1 Hz rate.
//
//*****************************************************************************
static void
LEDTask(void *pvParameters)
{
    portTickType ulLastTime;

    //
    // Get the current tick count.
    //
    ulLastTime = xTaskGetTickCount();

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Turn on the user LED.
        //
        ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3);

        //
        // Wait for the required amount of time.
        //
        xTaskDelayUntil(&ulLastTime, g_ulLEDDelay);

        //
        // Turn off the user LED.
        //
        ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0);

        //
        // Wait for the required amount of time.
        //
        xTaskDelayUntil(&ulLastTime, g_ulLEDDelay);
    }
}

//*****************************************************************************
//
// Initializes the LED task.
//
//*****************************************************************************
unsigned long
LEDTaskInit(void)
{
    //
    // Initialize the GPIO used to drive the user LED.
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);

    //
    // Create the LED task.
    //
    if(xTaskCreate(LEDTask, (signed portCHAR *)"LED",
                   (signed portCHAR *)g_pulLEDTaskStack,
                   sizeof(g_pulLEDTaskStack), NULL, PRIORITY_LED_TASK,
                   NULL) != pdPASS)
    {
        return(1);
    }
    TaskCreated();

    //
    // Success.
    //
    return(0);
}
8463.priorities.h
//*****************************************************************************
//
// uart_task.c - Task to output text on the UART.
//
// Copyright (c) 2009 Texas Instruments Incorporated.  All rights reserved.
// TI Information - Selective Disclosure
//
//*****************************************************************************

#include "utils/uartstdio.h"
#include "SafeRTOS/SafeRTOS_API.h"
#include "uart_task.h"
#include "priorities.h"
#include "idle_task.h"
#include "inc/hw_nvic.h"
#include "inc/hw_ints.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "grlib/grlib.h"
#include "drivers/kitronix320x240x16_ssd2119_8bit.h"
#include "drivers/set_pinout.h"
#include "driverlib/gpio.h"
#include "driverlib/uart.h"
#include "driverlib/adc.h"
#include "driverlib/interrupt.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/debug.h"
#include "display_task.h"
#include "idle_task.h"
#include "led_task.h"
#include "stdio.h"
#include "utils/uartstdio.h"



//*****************************************************************************
//
// This task receives messages from the other tasks and outputs strings to the
// UART.
//
//*****************************************************************************

//*****************************************************************************
//
// Variables globales para la aplicaci�n.
//
//*****************************************************************************
float humedad, temperatura, datoSensor, Humedad1;
char humidity[30];
char temperature[30];
char datoS[30];
unsigned long ulValue=0;
unsigned char prueba;

static void
UARTTask(void *pvParameters)
{

    //
    // Set the clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Set the device pinout appropriately for this board.
    //
    PinoutSet();

		//configure PB4 for analog measurement

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_4);
    SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS);
		ADCSequenceConfigure(ADC0_BASE,0, ADC_TRIGGER_PROCESSOR,0);
		ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_CH10 | ADC_CTL_IE | ADC_CTL_END);	
		ADCIntClear(ADC0_BASE, 0);//borro la interrupci�n de secuencia
    ADCSequenceEnable(ADC0_BASE, 0);


    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

    //
    // Set GPIO A0 and A1 as UART pins.
    //
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
    ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

    //
    // Enable the UART interrupt.
    //
    ROM_IntEnable(INT_UART0);
    ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);


    while(1){

		ADCProcessorTrigger(ADC0_BASE, 0);	
		while(!ADCIntStatus(ADC0_BASE, 0,false)){
		//Espero a que la conversi�n est� lista
		};
		ADCSequenceDataGet(ADC0_BASE, 0, &ulValue);//Guardo los datos en el buffer &ulValue
			
		datoSensor   = (float)ulValue;
		ulValue=ulValue*255/1023;

		prueba=ulValue; 
		//prueba = 0x11;
		ROM_UARTCharPutNonBlocking(UART0_BASE, prueba);
		
	}
}


//*****************************************************************************
//
// Initializes the UART task.
//
//*****************************************************************************
unsigned long
UARTTaskInit(void)
{

    //
    // Create the UART task.
    //
    if(xTaskCreate(UARTTask, (signed portCHAR *)"UART",
                   (signed portCHAR *)UART0_BASE,
                   sizeof(UART0_BASE), NULL, PRIORITY_UART_TASK,// LA PRIORIDAD DE LA UART ES 0
                   NULL) != pdPASS)
    {
        return(1);
    }
			TaskCreated();
    //
    // Success.
    //
    return(0);
}

  • Hello Leonardo,

    Need clarity on the following

    1. Which DK/EK of TM4C123/TM4C129 is being used?

    2. Does the code compile or not?

    3. Does it execute to some point and then "not do anything"

    4. Can you check the NVIC_FAULTSTAT and NVIC_FAULTADDR to see if a Fault has occurred?

    Regards

    Amit

  • Hi Amit:

    1. Dk -LM3S9D96

    2. Yes, it compiles

    3. When I execute debug mode, it run step by step and finally arrives to final while in code.

    4. Where I can find NVIC_FAULTADDR  and NVIC_FAULTSTAT , in Manuals and datasheet I can´t find it

     

    Thanks..

  • Hello Leonardo,

    It would be address 0xE000ED28 and 0xE000ED38 for STAT and ADDR.

    Also which while loop in the files that you had attached in the original code post?

    Regards

    Amit

  • Hi Amit, 0xE000ED28  and 0xE000ED38 show no faults.

    The while loop is the last one after start scheduler

  • Hi,

    Leonardo, I have looked a little bit your code - and I have some observations:

    a) you must split the initialization from tasks - there is no reason to call system clock setting at the task level; should be done first, before anything else. This is requested also by the fact the system tick shoud be in place before starting the scheduler.

    b) in such systems, you need to set up a system tick in a separate task. All the activities are based on such system tick. Recommend to start with some demo programs to learn how to build your own.

    c) you may download this tool: http://www.highintegritysystems.com/down-loads/stateviewer-plug-in/

    This is an addtional tool for Eclipse based IDEs - if you use such (if I remember well it is on CCS6 resources page) - and works together with the debugger, showing you status of different tasks and other useful info.

    Petrei