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.

Sys/Bios task class

Other Parts Discussed in Thread: SYSBIOS

I have a class defined that encapsulates a task.  I can successfully create and start the task but then it all falls apart.  I've got a 28335 peripheral explorer kit and I'm trying to toggle one of the leds in my task object but the Task_sleep function just ends up going off into the either.

Here is my code


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>

#include <ti/sysbios/knl/Task.h>
#include "DSP2833x_Device.h"

#include <xdc/std.h>
#include <xdc/runtime/Log.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <xdc/std.h>
#include <xdc/runtime/Log.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>
#include "DSP2833x_Device.h"

void InitSystem(void);
void Gpio_select(void);
extern "C" { Void minTaskWrapper(UArg a0, UArg a1);}

// class definition

class MinAppTask {
private:
    Task_Handle _taskHandle;
    Error_Block _eb;
public:
    MinAppTask(void);
    ~MinAppTask();
    virtual Void taskFxn(UArg a0, UArg a1);
    bool initialize();
};

MinAppTask::MinAppTask(void) {
}

bool MinAppTask::initialize()
{
    bool result;
    Task_Params taskParams;

    Task_Params_init(&taskParams);
    taskParams.priority = 1;
    taskParams.arg0 = (UArg)this;
    _taskHandle = Task_create((Task_FuncPtr)minTaskWrapper, &taskParams, &_eb);
    if (_taskHandle == NULL) {
        result = false;
    }
    else
    {
        result = true;
    }
    return (result);
}

MinAppTask::~MinAppTask()
{
    // TODO Auto-generated destructor stub
    Task_delete(&_taskHandle);
}

void MinAppTask::taskFxn (UArg a0, UArg a1)
{
    //char holdBuf[128];
    while(1)
    {
        GpioDataRegs.GPADAT.bit.GPIO9 = 1;
        Task_sleep(500);
        GpioDataRegs.GPADAT.bit.GPIO9 = 0;
        Task_sleep(500);

    }
}

extern "C" {
Void minTaskWrapper(UArg a0, UArg a1)
{
    MinAppTask * aTask;
    aTask = (MinAppTask *)a0;
    aTask->taskFxn(a0,a1);
}
}

void InitSystem(void);
void Gpio_select(void);
/*
 *  ======== main ========
 */
int  main()
{
    InitSystem();
    Gpio_select();
    MinAppTask task1;

    if (!task1.initialize())
    {
        System_printf("Could not create tasks, terminating\n");
        BIOS_exit(0);
    }else
        BIOS_start();
}


void InitSystem(void)
{
    EALLOW;
    SysCtrlRegs.WDCR = 0x0028;            // Watchdog enabled, 4.3 milliseconds
    SysCtrlRegs.PLLSTS.bit.DIVSEL = 2;
    SysCtrlRegs.PLLCR.bit.DIV = 10;        // 30MHz * 10 / 2 = 150 MHz
    SysCtrlRegs.HISPCP.all = 0x0001;
       SysCtrlRegs.LOSPCP.all = 0x0002;
    SysCtrlRegs.PCLKCR0.all = 0x0000;
    SysCtrlRegs.PCLKCR1.all = 0x0000;
    SysCtrlRegs.PCLKCR3.all = 0x0000;
    SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1;
    EDIS;
}

void Gpio_select(void)
{
    EALLOW;
    GpioCtrlRegs.GPAMUX1.all = 0;        // GPIO15 ... GPIO0 = General Puropse I/O
    GpioCtrlRegs.GPAMUX2.all = 0;        // GPIO31 ... GPIO16 = General Purpose I/O
    GpioCtrlRegs.GPBMUX1.all = 0;        // GPIO47 ... GPIO32 = General Purpose I/O
    GpioCtrlRegs.GPBMUX2.all = 0;        // GPIO63 ... GPIO48 = General Purpose I/O
    GpioCtrlRegs.GPCMUX1.all = 0;        // GPIO79 ... GPIO64 = General Purpose I/O
    GpioCtrlRegs.GPCMUX2.all = 0;        // GPIO87 ... GPIO80 = General Purpose I/O

    GpioCtrlRegs.GPADIR.all = 0;
    GpioCtrlRegs.GPADIR.bit.GPIO9 = 1;    // peripheral explorer: LED LD1 at GPIO9
    GpioCtrlRegs.GPADIR.bit.GPIO11 = 1;    // peripheral explorer: LED LD2 at GPIO11

    GpioCtrlRegs.GPBDIR.all = 0;        // GPIO63-32 as inputs
    GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;    // peripheral explorer: LED LD3 at GPIO34
    GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49
    GpioCtrlRegs.GPCDIR.all = 0;        // GPIO87-64 as inputs
    EDIS;
}

I could use a little help in getting this example to flash LD1.

  • Hi Andrew --

    Are you able to put a breakpoint on your Task_sleep() call and see that the code reaches that b/p?   When you say "goes off into ether", can you elaborate?  Can you look in disassembly window and see where the PC is when you halt the targett?

    I think you need to initialize that 'eb' structure before you call Task_create().  See below.

    bool MinAppTask::initialize()
    {
        bool result;
        Task_Params taskParams;

        Error_init(&_eb);

        Task_Params_init(&taskParams);
        taskParams.priority = 1;
        taskParams.arg0 = (UArg)this;
        _taskHandle = Task_create((Task_FuncPtr)minTaskWrapper, &taskParams, &_eb);
        if (_taskHandle == NULL) {
            result = false;
        }
        else
        {
            result = true;
        }
        return (result);
    }

  • I can put a break point on the call to Task_sleep(500); but only after the program has started.  If I put it in before the debugger starts it complains saying

    "C28xx: Trouble Setting Breakpoint with the Action "Finish Auto Run" at 0x3010b3: (Error -1066 @ 0x3010B3) Unable to set requested breakpoint in memory. Verify that the breakpoint address is in writable memory. (Emulation package 5.1.8.0) ".

    It does enter the function but then it acts finda funny.  Here is what I see as I step through.

    On Entry, the variable timeout of Task_sleep has a value of 500. 

    After stepping once the timeout variable changes to 0 and turns yellow in the variable window.  The debugger is now pointing to line 483

     if (timeout == BIOS_NO_WAIT) {
            return;

    }

    Well, timeout is zero ( but it should be 500) and stepping jumps me back to the function entry point with time timeout variable now set to 0. Stepping again moved the debugger to line 483 again but this time the timeout variable is 500 (after just turning yellow).

    The Task_sleep now moves into the body of the function and checks for a timeout of BIOS_WAIT_FOREVER which it is not.  Stepping should move to line 489 but it jumps to ti_sysbios_knl_Clock_Params_init in Clock.h at which point it throws an exception in the console saying

    "C28xx: Trouble Setting Breakpoint with the Action "Continue or Finish Stepping" at 0x302ee4: (Error -1066 @ 0x302EE4) Unable to set requested breakpoint in memory. Verify that the breakpoint address is in writable memory. (Emulation package 5.1.8.0) ".

    Simply letting the program run then pausing shows we are at memory location 3ff9fa.

    Still lost, looking for answers.