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/CC2640R2F: cc2640R2F how to add a Task that interval every 100 ms operate 1'st??

Part Number: CC2640R2F
Other Parts Discussed in Thread: TEST2, SYSBIOS

Tool/software: TI-RTOS

Hi,

I want to add a Task that interval every 100 ms operate 1'st. My code are as follows:

#include <string.h>

#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/sysbios/knl/Queue.h>

#include "hci_tl.h"
#include "gatt.h"
#include "linkdb.h"
#include "gapgattserver.h"
#include "gattservapp.h"
#include "devinfoservice.h"

#if defined(FEATURE_OAD) || defined(IMAGE_INVALIDATE)
#include "oad_target.h"
#include "oad.h"
#endif //FEATURE_OAD || IMAGE_INVALIDATE

#include "peripheral.h"
#include "gapbondmgr.h"

#include "osal_snv.h"
#include "icall_apimsg.h"

#include "util.h"

#ifdef USE_RCOSC
#include "rcosc_calibration.h"
#endif //USE_RCOSC

#ifdef USE_CORE_SDK
#include <ti/display/Display.h>
#else // !USE_CORE_SDK
#include <ti/mw/display/Display.h>
#endif // USE_CORE_SDK
#include "board_key.h"

#include "board.h"

#include "serial_port_service.h"
#include "spp_ble_server.h"
#include "inc/sdi_task.h"
#include "inc/sdi_tl_uart.h"

#if defined( DEBUG_SW_TRACE )
#include <driverlib/ioc.h>
#endif // USE_FPGA | DEBUG_SW_TRACE

#include "icall_api.h"

#define CTT_ICALL_EVT ICALL_MSG_EVENT_ID // Event_Id_31
#define CTT_QUEUE_EVT UTIL_QUEUE_EVENT_ID // Event_Id_30
#define CTT_PERIODIC_EVT Event_Id_07

#define CTT_ALL_EVENTS (CTT_ICALL_EVT | \
CTT_QUEUE_EVT | \
CTT_PERIODIC_EVT)

#define CTTTASK_STACK_SIZE 800
#define CTTTASK_PRIORITY 2


// How often to perform periodic event (in msec)
#define CTT_PERIODIC_EVT_PERIOD 100

static void CTT_init(void);
static void CTTTask_Fxn(UArg a0, UArg a1);
static void CTTTask_clockHandler(UArg a11);

static ICall_EntityID selfEntity;
static ICall_SyncHandle syncEvent;

static Clock_Struct periodicClock;

Char cttTaskStack[CTTTASK_STACK_SIZE];

Task_Struct cttTaskStruct;

int Don_test1;
long Don_test2;
uint32_t Don_test3;

void CTTTask_createTask(void)
{
Task_Params ctttaskParams;

// Configure and create the SDI task.
Task_Params_init(&ctttaskParams);
ctttaskParams.stack = cttTaskStack;
ctttaskParams.stackSize = CTTTASK_STACK_SIZE;
ctttaskParams.priority = CTTTASK_PRIORITY;

Task_construct(&cttTaskStruct, CTTTask_Fxn, &ctttaskParams, NULL);
}

void CTTTask_Fxn(UArg a0, UArg a1)
{
Don_test1 = 0;
Don_test2 = 1;

CTT_init();

for(;;)
{
uint32_t events;

// Wait for an event to be posted
events = Event_pend(syncEvent, Event_Id_NONE, CTT_ALL_EVENTS,
ICALL_TIMEOUT_FOREVER);

Don_test3 = events;

if(events)
{
// ICall_EntityID dest;
// ICall_ServiceEnum src;
// ICall_HciExtEvt *pMsg = NULL;

Don_test1++;
Don_test2 = Don_test2 + Don_test1;
}
}
}

static void CTT_init(void)
{
ICall_registerApp(&selfEntity, &syncEvent);

Util_constructClock(&periodicClock, CTTTask_clockHandler,
CTT_PERIODIC_EVT_PERIOD, 0, false, CTT_PERIODIC_EVT);
}

static void CTTTask_clockHandler(UArg a11)
{
// Wake up the application.
Event_post(syncEvent, a11);
}

My questions are as follows:

1, My code jest run CTTTask_Fxn(UArg a0, UArg a1) program 1'st, not interval every 100 ms operate 1'st.

2, How to modify my program, let it interval every 100 ms operate 1'st.

Any idea how can I solve the problem? Every help would be really appreciated!

Thanks in advance.

Don

  • Your periodicClock object is only constructed, not started. You have to call Util_startClock.
  • Hi Edvard

    I add "Util_startClock(&periodicClock)" in "void CTTTask_Fxn(UArg a0, UArg a1)" function, but not effect.

    My code are as follows:

    // Clock instances for internal periodic events.
    static Clock_Struct periodicClock;

    void CTTTask_Fxn(UArg a0, UArg a1)
    {
    Don_test1 = 0;
    Don_test2 = 1;

    CTT_init();

    for(;;)
    {
    uint32_t events;

    // Wait for an event to be posted
    events = Event_pend(syncEvent, Event_Id_NONE, CTT_ALL_EVENTS,
    ICALL_TIMEOUT_FOREVER);

    Don_test3 = events;

    Util_startClock(&periodicClock);

    if(events)
    {
    // ICall_EntityID dest;
    // ICall_ServiceEnum src;
    // ICall_HciExtEvt *pMsg = NULL;

    Don_test1++;
    Don_test2 = Don_test2 + Don_test1;
    }

    }
    }

    Thanks for your reply,

    Regards,

    Don
  • Judging by your code, it seems the main task waits for an event which is posted from CTTTask_clockHandler. Only after the event is posted will the clock be started, however, the clock needs to start before CTTTask_clockHandler is called.

    Also, you only need to call startClock once as you are configuring it to be periodic.

    What you probably want is therefore to call startClock in the CTT_init function after you have constructed the clock object, or in main function before entering the for(;;) { ... } loop.
  • In reply to Edvard,

    I move my "Util_startClock(&periodicClock)" function to "CTT_init(void)" function, but not effect.

    Program just execute "CTTTask_Fxn(UArg a0, UArg a1)" once too. Could I have other problem not

    consider??

    My code are as follows:

    #include <string.h>

    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/knl/Event.h>
    #include <ti/sysbios/knl/Queue.h>

    #include "hci_tl.h"
    #include "gatt.h"
    #include "linkdb.h"
    #include "gapgattserver.h"
    #include "gattservapp.h"
    #include "devinfoservice.h"

    #if defined(FEATURE_OAD) || defined(IMAGE_INVALIDATE)
    #include "oad_target.h"
    #include "oad.h"
    #endif //FEATURE_OAD || IMAGE_INVALIDATE

    #include "peripheral.h"
    #include "gapbondmgr.h"

    #include "osal_snv.h"
    #include "icall_apimsg.h"

    #include "util.h"

    #ifdef USE_RCOSC
    #include "rcosc_calibration.h"
    #endif //USE_RCOSC

    #ifdef USE_CORE_SDK
    #include <ti/display/Display.h>
    #else // !USE_CORE_SDK
    #include <ti/mw/display/Display.h>
    #endif // USE_CORE_SDK
    #include "board_key.h"

    #include "board.h"

    #include "serial_port_service.h"
    #include "spp_ble_server.h"
    #include "inc/sdi_task.h"
    #include "inc/sdi_tl_uart.h"

    #if defined( DEBUG_SW_TRACE )
    #include <driverlib/ioc.h>
    #endif // USE_FPGA | DEBUG_SW_TRACE

    #include "icall_api.h"

    #define CTT_ICALL_EVT ICALL_MSG_EVENT_ID // Event_Id_31
    #define CTT_QUEUE_EVT UTIL_QUEUE_EVENT_ID // Event_Id_30
    #define CTT_PERIODIC_EVT Event_Id_07

    #define CTT_ALL_EVENTS (CTT_ICALL_EVT | \
    CTT_QUEUE_EVT | \
    CTT_PERIODIC_EVT)

    #define CTTTASK_STACK_SIZE 800
    #define CTTTASK_PRIORITY 2


    // How often to perform periodic event (in msec)
    #define CTT_PERIODIC_EVT_PERIOD 100

    static void CTT_init(void);
    static void CTTTask_Fxn(UArg a0, UArg a1);
    static void CTTTask_clockHandler(UArg a11);

    static ICall_EntityID selfEntity;
    static ICall_SyncHandle syncEvent;

    static Clock_Struct periodicClock;

    Char cttTaskStack[CTTTASK_STACK_SIZE];

    Task_Struct cttTaskStruct;

    int Don_test1;
    long Don_test2;
    uint32_t Don_test3;

    void CTTTask_createTask(void)
    {
    Task_Params ctttaskParams;

    // Configure and create the SDI task.
    Task_Params_init(&ctttaskParams);
    ctttaskParams.stack = cttTaskStack;
    ctttaskParams.stackSize = CTTTASK_STACK_SIZE;
    ctttaskParams.priority = CTTTASK_PRIORITY;

    Task_construct(&cttTaskStruct, CTTTask_Fxn, &ctttaskParams, NULL);
    }

    void CTTTask_Fxn(UArg a0, UArg a1)
    {
    Don_test1 = 0;
    Don_test2 = 1;

    CTT_init();

    for(;;)
    {
    uint32_t events;

    // Wait for an event to be posted
    events = Event_pend(syncEvent, Event_Id_NONE, CTT_ALL_EVENTS,
    ICALL_TIMEOUT_FOREVER);

    Don_test3 = events;

    if(events)
    {
    // ICall_EntityID dest;
    // ICall_ServiceEnum src;
    // ICall_HciExtEvt *pMsg = NULL;

    Don_test1++;
    Don_test2 = Don_test2 + Don_test1;
    }

    }
    }

    static void CTT_init(void)
    {
    ICall_registerApp(&selfEntity, &syncEvent);

    Util_startClock(&periodicClock);

    Util_constructClock(&periodicClock, CTTTask_clockHandler,
    CTT_PERIODIC_EVT_PERIOD, 0, false, CTT_PERIODIC_EVT);
    }

    static void CTTTask_clockHandler(UArg a11)
    {
    // Wake up the application.
    Event_post(syncEvent, a11);
    }

    Thanks for your reply,

    Regards,

    Don
  • In CTT_init, you need to call Util_startClock after Util_constructClock. You always have to construct the object before using it, e.g. startClock.

  • very thanks for your reply,

    When I let Util_startClock after Util_constructClock, and than modify
    "Util_constructClock(&periodicClock, CTTTask_clockHandler, CTT_PERIODIC_EVT_PERIOD, 0, false, CTT_PERIODIC_EVT)"
    become
    "Util_constructClock(&periodicClock, CTTTask_clockHandler, 0, CTT_PERIODIC_EVT_PERIOD, false, CTT_PERIODIC_EVT)".
    Now, my program can work 100 ms / 1'st.

    Regards,

    Don