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.

RTOS/AM5728: Periodic task not working

Part Number: AM5728
Other Parts Discussed in Thread: BEAGLEBOARD-X15, , SYSBIOS

Tool/software: TI-RTOS

Hi, 

I'm using Beagleboard-X15 (AM5728). I'm trying to send dummy values on default UART (UART3) to bluetooth module. I've created a task which I want to repeat every 250 ms. The attached code just send the information on UART just once and doesn't send it again. 

Please help. 

Thanks. 

/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/Diags.h>
#include <xdc/runtime/Log.h>
#include <xdc/runtime/Assert.h>
#include <xdc/runtime/Registry.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/ipc/Ipc.h>
#include <ti/ipc/MessageQ.h>
#include <ti/ipc/MultiProc.h>

/*In case I need to print something and miscellaneous files*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* CSL Header files */
#ifdef _TMS320C6X
#include <ti/csl/csl_chip.h>
#endif

/* TI-RTOS Header files */
#include <ti/drv/gpio/GPIO.h>
#include <ti/drv/gpio/soc/GPIO_soc.h>
#include <ti/drv/gpio/test/led_blink/src/GPIO_log.h>
#include <ti/drv/gpio/test/led_blink/src/GPIO_board.h>
#include <ti/board/board.h>

/* UART Header files */
#include <ti/drv/uart/UART.h>
#include <ti/drv/uart/src/UART_osal.h>
#include <ti/csl/hw_types.h>
#include <ti/csl/soc.h>
#include <ti/drv/uart/UART_stdio.h>
#include <ti/drv/uart/test/src/UART_board.h>


/*Following has function calls used to communicate with ARM processor*/
#include "Server.h"


/**********************************************************************
 ************************** Internal functions ************************
 **********************************************************************/

/* uart clock callback function */
void clock_fxn_uart(UArg arg);

/* Create a uart task*/
void uart_task_creation();

void UART_CrossbarConfigure(void);
void Board_initUART(void);
Void uart_test(UArg arg0, UArg arg1);


/**********************************************************************
 ************************** Global Variables **************************
 **********************************************************************/

Clock_Handle hClockUart = NULL;     // used for system clock for Uart


/*Function definitions*/

void Board_initUART(void)
{
    Board_initCfg boardCfg;


    boardCfg = BOARD_INIT_PINMUX_CONFIG |
               BOARD_INIT_MODULE_CLOCK  |
               BOARD_INIT_UART_STDIO;


    Board_init(boardCfg);
}

Void uart_test(UArg arg0, UArg arg1)
{

    Board_initUART();   //Configure GPIO pins and UART
    UART_CrossbarConfigure();
    static int i=0;
    char input = '\n';
    char *buffPointer;

    buffPointer = (char*)malloc(INPUT_LENGTH);
    memset(buffPointer,0,INPUT_LENGTH);

    //UART_puts("\nuart driver and utils example test cases :\nEnter 16 characters or press Esc \n",sizeof("uart driver and utils example test cases : please enter 16 characters or press Esc or carriage return\n"));
    int w, y;
        UART_puts("Value to TC1:",sizeof("Value to TC1:"));
        UART_putc(i);

        for (w=0; w<10000000; w++ )
        {
            for (y=0; y<10; y++ )
            {

            }
        }
        i++;
} /* uart_test */


/*
 *  Uart task created to output data to bluetooth
 */
void uart_task_creation()
{
    /* Call board init functions */
    Task_Handle taskUart;
    Clock_Params clockParamsUart;           // clock parameters created
    Error_Block ebUart;

    Board_initUART();   //Configure GPIO pins and UART

    UART_CrossbarConfigure();

    Error_init(&ebUart);
    taskUart = Task_create(uart_test, NULL, &ebUart);
    if (taskUart == NULL) {
        System_printf("Task_create() failed!\n");
        BIOS_exit(0);
    }

    /* setting up clock */
    Clock_Params_init(&clockParamsUart);
    clockParamsUart.period = 250;                                   // set period
    clockParamsUart.startFlag = FALSE;                              // don't know why it's false
    hClockUart = Clock_create(clock_fxn_uart, TIMER_DELAY_UART, &clockParamsUart, &ebUart);      // After every 5 ms call the function clockFxn
    if (hClockUart == NULL) {                                       // If clock  creation is failed, throw an error and
        System_printf("Clock_create() failed!\n");              // shutdown the processor
        BIOS_exit(0);
    }

}

/*
 * clock_fxn_uart function: This is time triggered function. This is called every TIMER_DELAY_UART ms.
 */
void clock_fxn_uart(UArg arg) {
    uart_test(NULL, NULL);           // Start UART communication with bluetooth

}

/*
 *  ======== main ========
 */
int main(void)
{
    uart_task_creation();

    /* Start BIOS */

    BIOS_start();
    return (0);
}


/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/Diags.h>
#include <xdc/runtime/Log.h>
#include <xdc/runtime/Assert.h>
#include <xdc/runtime/Registry.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/ipc/Ipc.h>
#include <ti/ipc/MessageQ.h>
#include <ti/ipc/MultiProc.h>

/*In case I need to print something and miscellaneous files*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* CSL Header files */
#ifdef _TMS320C6X
#include <ti/csl/csl_chip.h>
#endif

/* TI-RTOS Header files */
#include <ti/drv/gpio/GPIO.h>
#include <ti/drv/gpio/soc/GPIO_soc.h>
#include <ti/drv/gpio/test/led_blink/src/GPIO_log.h>
#include <ti/drv/gpio/test/led_blink/src/GPIO_board.h>
#include <ti/board/board.h>

/* UART Header files */
#include <ti/drv/uart/UART.h>
#include <ti/drv/uart/src/UART_osal.h>
#include <ti/csl/hw_types.h>
#include <ti/csl/soc.h>
#include <ti/drv/uart/UART_stdio.h>
#include <ti/drv/uart/test/src/UART_board.h>


/*Following has function calls used to communicate with ARM processor*/
#include "Server.h"


/**********************************************************************
 ************************** Internal functions ************************
 **********************************************************************/

/* uart clock callback function */
void clock_fxn_uart(UArg arg);

/* Create a uart task*/
void uart_task_creation();

void UART_CrossbarConfigure(void);
void Board_initUART(void);
Void uart_test(UArg arg0, UArg arg1);


/**********************************************************************
 ************************** Global Variables **************************
 **********************************************************************/

Clock_Handle hClockUart = NULL;     // used for system clock for Uart


/*Function definitions*/

void Board_initUART(void)
{
    Board_initCfg boardCfg;


    boardCfg = BOARD_INIT_PINMUX_CONFIG |
               BOARD_INIT_MODULE_CLOCK  |
               BOARD_INIT_UART_STDIO;


    Board_init(boardCfg);
}

Void uart_test(UArg arg0, UArg arg1)
{

    Board_initUART();   //Configure GPIO pins and UART
    UART_CrossbarConfigure();
    static int i=0;
    char input = '\n';
    char *buffPointer;

    buffPointer = (char*)malloc(INPUT_LENGTH);
    memset(buffPointer,0,INPUT_LENGTH);

    //UART_puts("\nuart driver and utils example test cases :\nEnter 16 characters or press Esc \n",sizeof("uart driver and utils example test cases : please enter 16 characters or press Esc or carriage return\n"));
    int w, y;
        UART_puts("Value to TC1:",sizeof("Value to TC1:"));
        UART_putc(i);

        for (w=0; w<10000000; w++ )
        {
            for (y=0; y<10; y++ )
            {

            }
        }
        i++;
} /* uart_test */


/*
 *  Uart task created to output data to bluetooth
 */
void uart_task_creation()
{
    /* Call board init functions */
    Task_Handle taskUart;
    Clock_Params clockParamsUart;           // clock parameters created
    Error_Block ebUart;

    Board_initUART();   //Configure GPIO pins and UART

    UART_CrossbarConfigure();

    Error_init(&ebUart);
    taskUart = Task_create(uart_test, NULL, &ebUart);
    if (taskUart == NULL) {
        System_printf("Task_create() failed!\n");
        BIOS_exit(0);
    }

    /* setting up clock */
    Clock_Params_init(&clockParamsUart);
    clockParamsUart.period = 250;                                   // set period
    clockParamsUart.startFlag = FALSE;                              // don't know why it's false
    hClockUart = Clock_create(clock_fxn_uart, TIMER_DELAY_UART, &clockParamsUart, &ebUart);      // After every 5 ms call the function clockFxn
    if (hClockUart == NULL) {                                       // If clock  creation is failed, throw an error and
        System_printf("Clock_create() failed!\n");              // shutdown the processor
        BIOS_exit(0);
    }

}

/*
 * clock_fxn_uart function: This is time triggered function. This is called every TIMER_DELAY_UART ms.
 */
void clock_fxn_uart(UArg arg) {
    uart_test(NULL, NULL);           // Start UART communication with bluetooth

}

/*
 *  ======== main ========
 */
int main(void)
{
    uart_task_creation();

    /* Start BIOS */

    BIOS_start();
    return (0);
}


  • The RTOS team have been notified. They will respond here.
  • Hi,

    Your clock function clock_fxn_uart() calls the uart_test(). Can you add a counter inside this clock_fxn_uart() to check if the problem is the clock function is only entered once? If this is the problem, you can refer to how to set up a periodic clock like below:

    var timer0Params = new Timer.Params();
    timer0Params.instance.name = "mytimer";
    timer0Params.period = 1000;
    timer0Params.periodType = xdc.module("ti.sysbios.interfaces.ITimer").PeriodType_MICROSECS;
    Program.global.mytimer = Timer.create(5, "&timerIsr", timer0Params); // ok

    This was tested and timeIsr can be entered multiple times.

    Regards, Eric
  • Hi Eric,

    You're right. clock_fxn_uart is called only once. But I can't use your code snippet because I think I've only one timer and as I'm also doing IPC so that timer is not available. I get "timer device unavailable error" when I used your code. Is there a way I can use any other timer or clock and do you have an example code for that.

    Thanks.
    -Ahmed.
  • Please check: software-dl.ti.com/.../Timer.html

    If the timer is already used or you are not sure which is available: Create could fail if timer peripheral is unavailable. To request any available timer use ANY as the id. TimerId's are logical ids. The family-specific implementations map the ids to physical peripherals.

    Regards, Eric
  • I get error ""ANY" is not defined", when I add following lines in cfg file. (I've included #include <ti/sysbios/hal/Timer.h> line in my Main.c file)

    var timer0Params = new Timer.Params();
    timer0Params.instance.name = "mytimer";
    timer0Params.period = 1000;
    timer0Params.periodType = xdc.module("ti.sysbios.interfaces.ITimer").PeriodType_MICROSECS;
    Program.global.mytimer = Timer.create(ANY, "&timerIsr", timer0Params); // ok
  • I changed last line to following and able to compile.
    Program.global.mytimer = Timer.create(timer)Params.ANY, "&clock_fxn_uart", timer0Params); // ok

    Still this is not calling the function clock_fxn_uart repetitively.
  • After more debugging I think both timer and clock code snippets run the routine/function repetitively. It's function call UART_puts or UART_putc or UART_write which sends information to bluetooth module only the first time and second time it aborts the thread.
  • Hi Eric,

    What I ended up doing is that I put UART_printf command in while (1) loop and TI-RTOS is automatically switching between tasks, which will do what I'm trying to achieve. I've one more question. Right now I'm using UART3. I want to use UART1 instead of 3. Can you please point out how should I do pin muxing/any other changes to achieve that.

    Thanks a lot for your help.
    -Ahmed.
  • Please refer to www.ti.com/.../sprac32.pdf. This steps also apply to AM437x.

    Regards, Eric
  • I'm using AM5728, not 335 or 437. I used pinmux tool and enabled few uarts including UART1. The tool generated "boardPadDelay.h", "boardPadDelayDevice.c", "boardPadDelayInit.c" and "boardPadDelayTune.h" and some other text and csv files. I replaced all original four files from following directory with the above downloaded files. 

    ti-processor-sdk-rtos-am57xx-evm-04.00.00.04/pdk_am57xx_1_0_7/packages/ti/board/src/evmAM572x/

    Then I recompile the directory using following commands and everything pass. 

    source pdksetupenv.sh

    make clean

    make LIMIT_BOARDS="evmAM572x" LIMIT_SOCS="am572x"

    I'm trying to run uart_polling_test example from rtos sdk. The project compiles fine but doesn't send anything on UART 1. Attached is the main.c

    Thanks. 

    -Ahmed. 

    /*
     * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * Redistributions of source code must retain the above copyright
     * notice, this list of conditions and the following disclaimer.
     *
     * Redistributions in binary form must reproduce the above copyright
     * notice, this list of conditions and the following disclaimer in the
     * documentation and/or other materials provided with the
     * distribution.
     *
     * Neither the name of Texas Instruments Incorporated nor the names of
     * its contributors may be used to endorse or promote products derived
     * from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    
    /**
     *  \file  uart_test.c
     *
     *  \brief  Example application main file. This application will demonstrate
     *          UART RTOS driver for polling mode.
     *   This file performs as mentioned below:
     *
     *      1. Configure UART using structure UART_Params where user can configure
     *         readmode writemode etc. different parameters.
     *      2. First call UART_init()
     *      3. Call UART_open with UART_Params structure to get UART instance handle.
     *      4. Then user is expected to input some data(can be upto max 1000 chars)
     *         and it is printed back on console using UART RTOS API's
     *         UART_readPolling() and UART_write() respectively.
     *   Note
     *      1. The sample application is written for TDAXX EVM, DRA75X EVM and AM57XX.
     *      2. The UART instance used is UART1 for TDA2XX,AM57XX,DRA75X and
     *         UART3 for TDA3XX,DRA78X.
     *
    **/
    
    /* ========================================================================== */
    /*                             Include Files                                  */
    /* ========================================================================== */
    /* XDCtools Header files */
    #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/src/UART_osal.h>
    #include <ti/csl/hw_types.h>
    #include <ti/csl/soc.h>
    
    /* ========================================================================== */
    /*                           Macros & Typedefs                                */
    /* ========================================================================== */
    #if defined (SOC_TDA2XX) || defined (SOC_DRA75x) || defined (SOC_AM572x) || defined (SOC_TDA2EX) || defined (SOC_AM571x)
    #define UART_INSTANCE 0
    #endif
    #if defined (SOC_TDA3XX) || defined (SOC_DRA78x)
    #define UART_INSTANCE 2
    #endif
    
    /* ========================================================================== */
    /*                          Internal Function Declarations                    */
    /* ========================================================================== */
    /* None */
    
    /* ========================================================================== */
    /*                            Global Variables                                */
    /* ========================================================================== */
    UART_Handle uart_handle;
    
    /* UART parameters structure polled mode*/
    const UART_Params user_params = {
        UART_MODE_BLOCKING,     /* readMode */
        UART_MODE_BLOCKING,     /* writeMode */
        0U,                     /* readTimeout */
        0U,                     /* writeTimeout */
        NULL,                  /* readCallback */
        NULL,                 /* writeCallback */
        UART_RETURN_NEWLINE,  /* readReturnMode */
        UART_DATA_TEXT,       /* readDataMode */
        UART_DATA_TEXT,       /* writeDataMode */
        UART_ECHO_ON,         /* readEcho */
        115200,               /* baudRate */
        UART_LEN_8,           /* dataLength */
        UART_STOP_ONE,        /* stopBits */
        UART_PAR_NONE         /* parityType */
    };
    
    /* ========================================================================== */
    /*                          Function Definitions                              */
    /* ========================================================================== */
    void padConfig_prcmEnable()
    {
    #if defined (SOC_AM572x) || defined (SOC_AM571x)
        /*Pad configurations */
        HW_WR_REG32(CSL_MPU_CORE_PAD_IO_REGISTERS_REGS+CSL_CONTROL_CORE_PAD_IO_PAD_UART1_RXD,0x00040000);
        HW_WR_REG32(CSL_MPU_CORE_PAD_IO_REGISTERS_REGS+CSL_CONTROL_CORE_PAD_IO_PAD_UART1_TXD,0x00000000);
    #endif
    #if defined (SOC_TDA2XX) || defined (SOC_TDA2EX) || defined (SOC_DRA75x)
        /*Pad configurations */
        HW_WR_REG32(SOC_CORE_PAD_IO_REGISTERS_BASE+CTRL_CORE_PAD_UART1_RXD,0x00040000);
        HW_WR_REG32(SOC_CORE_PAD_IO_REGISTERS_BASE+CTRL_CORE_PAD_UART1_TXD,0x00000000);
    #endif
    #if defined (SOC_TDA3XX) || defined (SOC_DRA78x)
        /*Pad configurations */
        HW_WR_REG32(SOC_CORE_PAD_IO_REGISTERS_BASE+CTRL_CORE_PAD_IO_SPI1_SCLK,0x00040001);
        HW_WR_REG32(SOC_CORE_PAD_IO_REGISTERS_BASE+CTRL_CORE_PAD_IO_SPI1_CS0,0x00000001);
    #endif
    }
    
    void uart_test(UArg arg0, UArg arg1)
    {
        UART_Params      params;
        int32_t count;
        char input = '\n';
        char buffPointer[1000];
        char echoPrompt[] = "\nuart driver example test:\nEnter some data or press Esc \n";
        char echoPrompt1[] = "Data received is\n";
    
        padConfig_prcmEnable();
    
        UART_init();
        params = user_params;
        uart_handle = UART_open(UART_INSTANCE, &params);
    
        UART_write(uart_handle,echoPrompt,sizeof(echoPrompt));
    
        while(1)
           {
            count=UART_readPolling(uart_handle,buffPointer,1000);
            UART_write(uart_handle,&input,1U);
            UART_write(uart_handle,echoPrompt1,sizeof(echoPrompt1));
            UART_write(uart_handle,buffPointer,count);
            UART_write(uart_handle,echoPrompt,sizeof(echoPrompt));
           }
    }
    
    int main(void)
    {
        Task_Handle task;
        Error_Block eb;
    
        Error_init(&eb);
    
        task = Task_create(uart_test, NULL, &eb);
        if (task == NULL) {
            System_printf("Task_create() failed!\n");
            BIOS_exit(0);
        }
    
        /* Start BIOS */
        BIOS_start();
        return (0);
    }
    /********************************* End of file ******************************/
    

  • Hi,

    The thread topic is timer. Can you open a new one for PINMUX as the timer issue was already resolved. Thanks!

    Regards, Eric
  • Thank you.
    Will do.