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.

  • Resolved

CC2650MODA: TI RTOS Timer Restart

Intellectual 335 points

Replies: 3

Views: 69

Part Number: CC2650MODA

TI RTOS has Timer APIs to open, close, start and stop timers. But there is no API to restart/reset a timer. I am starting a timer in oneshot-up mode on an falling edge interrupt on a GPIO and I need to restart timer on following falling edges on GPIO, allowing Timer to elapse only when there is no falling edge on GPIO for defined time. I tried stopping and starting Timer but I dont think that is restarting a Timer. Is there something I am missing? what is a way to restart a timer?

inline void timer_start(uint32_t time_us) {
    GPTimerCC26XX_setLoadValue(hTimer, (timerTick_us * time_us) - 1);
    GPTimerCC26XX_start(hTimer);
}

inline void timer_stop() {
    GPTimerCC26XX_stop(hTimer);
}

void timerCallback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) {
    timer_stop();
    DEBUG_TOGGLE;
}


void edgeTriggerCallback(PIN_Handle handle, PIN_Id pinId) {
    timer_stop();
    timer_start(480);
    edge_count++;
}

void timer_init() {
    // Timer config
    GPTimerCC26XX_Params params;
    GPTimerCC26XX_Params_init(&params);
    params.width          = GPT_CONFIG_16BIT;
    params.mode           = GPT_MODE_ONESHOT_UP;
    params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
    hTimer = GPTimerCC26XX_open(CONFIG_TIMER_0, &params);
    if(hTimer == NULL) {
      //Log_error0("Failed to open GPTimer");
    }

    Types_FreqHz  freq;
    BIOS_getCpuFreq(&freq);
    timerTick_us = (freq.lo/1000000);
    GPTimerCC26XX_Value loadVal = timerTick_us * TIME_RESET_MIN; //480us, 1-wire reset

    loadVal = timerTick_us * 480; //480us, 1-wire reset
    GPTimerCC26XX_setLoadValue(hTimer, loadVal);
    GPTimerCC26XX_registerInterrupt(hTimer, &timerCallback, GPT_INT_TIMEOUT);

}

void one_init(one_device * d, const uint8_t count) {
	if (count > 4) {
		return;
	}
	timer_init();
	state = state_idle;

    // Get handle to One Wire Pin
	hOwPin = PIN_open(&hOwPinState, aOwPin);
    if (!hOwPin) {
      // Handle allocation error
    }
    // Edge trigger
    PIN_registerIntCb(hOwPin,  edgeTriggerCallback);
    PIN_setInterrupt(hOwPin,  PIN_ID(ONE_PIN)| PIN_IRQ_NEGEDGE);
}

  • Hi Pritesh,

    What a reset "is" depends on the mode in question. In your case, you would need to reset the counter register manually to avoid it reaching up to the set limit.

    A convenient way to do what you want it so to use the TimerSynchronize() API from driverlib:

    http://dev.ti.com/tirex/explore/content/simplelink_cc13x0_sdk_3_20_00_23/docs/driverlib_cc13xx_cc26xx/cc13x0/driverlib/group__timer__api.html

    Calling this for the Timer in use should issue a reset if the timer.

    Best regards,

    M-W

    Notice: I'm no longer with TI, sorry for the inconvenience. 

  • In reply to IUsedToBeARealPerson (M-W):

    Hi M-W,

    I will try out TimeSynchronize() API from driverlib. Are there examples source code for driverlib APIs. There are generally example source code provided for driverlib for most of the MCUs but I am not finding example folder in driverlib package of CC2650. This will make it easy to understand and use driverlib APIs.

  • In reply to Pritesh Patel:

    Hi Pritesh,

    No there is no DriverLib examples in the SDK, the documentation that exist is what is found on the link I sent you out. It shows code snippet on what each API and if you study this you will find that it is basically just register abstraction. 

    In some cases, you can find simple examples in the technical reference manual that refers to the use of DriverLib. 

    Best regards,

    M-W

    Notice: I'm no longer with TI, sorry for the inconvenience. 

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.