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.

TI-RTOS tasks will not run when MAP_Interrupt_enableInterrupt() is called.

Hello all,

I am trying to write an TI-RTOS app for the MSP432p401R launchpad and It seems whenever I enable the ADC14 interupts my tasks stop being called at all.  I am wondering what I am doing wrong.

int main(void)
{
    /* Call board init functions. */
    Board_initGeneral();
    Board_initGPIO();
    // Board_initI2C();
    // Board_initSDSPI();
    // Board_initSPI();
    // Board_initUART();
    // Board_initWatchdog();
    // Board_initWiFi();

    /* Turn on user LED  */
    GPIO_write(Board_LED0, Board_LED_ON);
    /* Halting the Watchdog  */
        MAP_WDT_A_holdTimer();

        /* Initializing Variables */
        curADCResult = 0;

        /* Setting DCO to 48MHz  */
        MAP_PCM_setPowerState(PCM_AM_LDO_VCORE1);
        MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);

        /* Enabling the FPU for floating point operation */
        MAP_FPU_enableModule();
        MAP_FPU_enableLazyStacking();

        /* Initializing ADC (MCLK/1/4) */
        MAP_ADC14_enableModule();
        MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_4,
                0);

        /* Configuring GPIOs (5.5 A0) */
        MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5,
        GPIO_TERTIARY_MODULE_FUNCTION);

        /* Configuring ADC Memory */
        MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true);
        MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS,
        ADC_INPUT_A0, false);

        /* Configuring Sample Timer */
        MAP_ADC14_enableSampleTimer(ADC_MANUAL_ITERATION);

        /* Enabling/Toggling Conversion */
        MAP_ADC14_enableConversion();
        MAP_ADC14_toggleConversionTrigger();

        /* Enabling interrupts*/
        MAP_ADC14_enableInterrupt(ADC_INT0);
        MAP_Interrupt_enableInterrupt(INT_ADC14);
        MAP_Interrupt_enableMaster();

   /* while (1){
    *
           MAP_PCM_gotoLPM0();
        };*/
    /* Start BIOS */
    BIOS_start();

    return (0);
}

void ADCClockFXN(){};

void adc_isr(void)
{
    uint64_t status = MAP_ADC14_getEnabledInterruptStatus();
    MAP_ADC14_clearInterruptFlag(status);
    Semaphore_post(sem);
    if (ADC_INT0 & status)
    {
        curADCResult = MAP_ADC14_getResult(ADC_MEM0);
        normalizedADCRes = (curADCResult * 3.3) / 16384;

        MAP_ADC14_toggleConversionTrigger();

    }
}



void ADCTaskFxn(){
uint8_t i;
fcomplex b,c;
float auc=0.0;



while(1){
	               uint16_t currentSample = 0;
	               Semaphore_pend(sem,BIOS_WAIT_FOREVER);

	               while(currentSample < SAMPLECOUNT) {

	                 //Sleep  IDLE mode
	                Task_sleep(1);

	                 // Trigger ADC sampl

and so on.

I have created all of the tasks and interrupts with the Gui.

Most of the above code was from a non-RTOS example that I am trying to port into an RTOS program.  So I might be trying do do the impossible.

What I did was import the ADC14_single_sample_repeat example.  I then created an empty RTOS project. I then copied the code from the ADC14 sample into the RTOS project.  I created the tasks for my code and got all of it to compile. The ADC ISR works greate. But the tasks never get called.

These lines:

/* Enabling interrupts*/
        MAP_ADC14_enableInterrupt(ADC_INT0);
        MAP_Interrupt_enableInterrupt(INT_ADC14);
        MAP_Interrupt_enableMaster();

seem to be the culprit, particularly MAP_Interrupt_enableInterrupt(INT_ADC14);
If I comment that line the tasks run but the adc isr doesn't. If I put that line in, the adc isr runs but the tasks don't.

Thanks for any help.

JP

  • Moving to TI-RTOS forum to better answer your question.

    Regards,
    JH
  • Thanks and Sorry for posting in the wrong place.
  • When you say you created all the tasks and the interrupts with the GUI, does that include the ADC interrupt? What priority and configuration parameters did you use to define the ADC interrupt?

    Can you share the .cfg file that was generated by the GUI?

    In general, you should never use any of the driverlib interrupt management APIs. Instead you should use the corresponding APIs provide by the TI-RTOS kernel.

    This call:
    MAP_Interrupt_enableInterrupt(X);

    Should be replaced with
    Hwi_enableInterrupt(X);

    These calls:
    MAP_Interrupt_disableMaster();
    MAP_Interrupt_enableMaster();

    Shoud be replaced with
    Hwi_disable();
    Hwi_enable();

    And you SHOULD NOT call Hwi_enable() within main().

    Global interrupts are enabled within BIOS_start() when it is safe to do so.

    It appears that your ADC ISR is always retriggering the ADC to perform another conversion. If the conversion completes before the processor finishes returning from the interrupt, the interrupt will be re-entered immediately, not giving any time for the background thread to run. Perhaps the call to MAP_ADC14_toggleConversionTrigger() should be moved into the task function after returning from the Semaphore_pend() call.

    Alan
  • Thanks for your response.  I am still having trouble I tried to replace the driverlib functions with the Hwi versions but still no good. I also put the trigger statement in the task fxn and that didn't  help. 

    Can you tell me exactly how I should replace these lines of code with their RTOS Hwi versions?

     Here is the config file.

    And thanks again.

    /*
     
     */
    
    /*
     *  ======== empty_min.cfg ========
     */
    
    /* ================ General configuration ================ */
    var Defaults = xdc.useModule('xdc.runtime.Defaults');
    var Error = xdc.useModule('xdc.runtime.Error');
    var Main = xdc.useModule('xdc.runtime.Main');
    var System = xdc.useModule('xdc.runtime.System');
    var Text = xdc.useModule('xdc.runtime.Text');
    
    var BIOS = xdc.useModule('ti.sysbios.BIOS');
    var Clock = xdc.useModule('ti.sysbios.knl.Clock');
    var Task = xdc.useModule('ti.sysbios.knl.Task');
    var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
    var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
    var m3Hwi = xdc.useModule('ti.sysbios.family.arm.m3.Hwi');
    
    /* ================ System configuration ================ */
    var SysCallback = xdc.useModule('xdc.runtime.SysCallback');
    var Timer = xdc.useModule('ti.sysbios.hal.Timer');
    var Idle = xdc.useModule('ti.sysbios.knl.Idle');
    System.SupportProxy = SysCallback;
    System.maxAtexitHandlers = 0;
    
    /* Remove debug strings from the application */
    Text.isLoaded = false;
    
    /* Remove the raise hook from the application */
    Error.raiseHook = null;
    
    /*
     *  Program.stack is ignored with IAR. Use the project options in
     *  IAR Embedded Workbench to alter the system stack size.
     */
    if (!Program.build.target.$name.match(/iar/)) {
        /*
         *  Reducing the system stack size (used by ISRs and Swis) to reduce
         *  RAM usage.
         */
        Program.stack = 512;
    }
    
    /* ================ Kernel configuration ================ */
    /* Use Custom library with no logging or asserts */
    BIOS.libType = BIOS.LibType_Custom;
    BIOS.logsEnabled = false;
    BIOS.assertsEnabled = false;
    
    BIOS.heapSize = 1024;
    
    /* Do not use Hwi_excHandlerMin */
    m3Hwi.excHandlerFunc = null;
    
    /* Do not check Task or System stacks  */
    Task.checkStackFlag = false;
    Hwi.checkStackFlag = false;
    
    /* Reduce the number of Task priorities */
    Task.numPriorities = 8;
    
    /* Reduce the default stack size */
    Task.defaultStackSize = 512;
    
    var task0Params = new Task.Params();
    task0Params.instance.name = "heartBeat";
    task0Params.arg0 = 1000;
    task0Params.stackSize = 512;
    task0Params.priority = 3;
    Program.global.heartBeatTask = Task.create("&heartBeatFxn", task0Params);
    
    /* ================ Driver configuration ================ */
    var TIRTOS = xdc.useModule('ti.tirtos.TIRTOS');
    TIRTOS.useGPIO = true;
    var task1Params = new Task.Params();
    task1Params.instance.name = "ADCGet";
    task1Params.priority = 7;
    task1Params.arg0 = null;
    task1Params.arg1 = null;
    Program.global.ADCGet = Task.create("&ADCTaskFxn", task1Params);
    Clock.tickPeriod = 5;
    var clock0Params = new Clock.Params();
    clock0Params.instance.name = "ADCClock";
    clock0Params.period = 1;
    clock0Params.startFlag = true;
    Program.global.ADCClock = Clock.create("&ADCClockFXN", 1, clock0Params);
    Task.enableIdleTask = true;
    var hwi0Params = new Hwi.Params();
    hwi0Params.instance.name = "hwi";
    hwi0Params.enableInt = false;
    hwi0Params.maskSetting = xdc.module("ti.sysbios.interfaces.IHwi").MaskingOption_LOWER;
    Program.global.hwi = Hwi.create(40, "&adc_isr", hwi0Params);
    Task.deleteTerminatedTasks = false;
    Clock.tickMode = Clock.TickMode_PERIODIC;
    var semaphore0Params = new Semaphore.Params();
    semaphore0Params.instance.name = "sem";
    Program.global.sem = Semaphore.create(null, semaphore0Params);
    Clock.tickSource = Clock.TickSource_TIMER;
    Idle.idleFxns[0] = null;
    

  • I believe your application is being totally bogged down processing 5us clock tick interrupts, leaving no time for background threads to run.

    You've set the Clock.tickPeriod to 5us, and you've configured a Clock object to be invoked periodically on every 5us tick.

    Try using the default Clock.tickPeriod of 1000 (ie 1ms).

    Alan