NIL tick-less problem

Discussions and support about ChibiOS/NIL, the almost nil RTOS.
benitangela
Posts: 3
Joined: Thu Jul 23, 2020 3:29 am
Has thanked: 1 time

NIL tick-less problem

Postby benitangela » Tue Aug 04, 2020 10:26 am

Hi,

I am using LPC812 and want to implement CHIBIOS/NIL (tick-less mode).
I have define CH_CFG_ST_TIMEDELTA to 2 (chconf.h), use MRT as timer, and enable CORTEX_ENABLE_WFI_IDLE (chcore_v6m.h).
Besides, I have one thread to be run and while(true) in main is empty.

Code: Select all

#include "ch.h"
#include "hal.h"
#include "SEGGER_RTT.h"

static void gptcb(GPTDriver *gptp){
  (void) gptp;
  palTogglePad(LPC_GPIO_PORT, LED_GREEN);
}

/**
 * GPT configuration structure
*/
static const GPTConfig gptcfg = {
  1000, /* Timer clock in Hz */
  gptcb /* Timer callback */
};

/**
 * Blinker thread #1.
*/
static THD_WORKING_AREA(waThread1, 128);
static THD_FUNCTION(Thread1, arg) {

  (void)arg;

  while (true) {
    /* Perform processing here.*/
    SEGGER_RTT_printf(0, "11\n");
    chThdSleepSeconds(6);
  }
}

/**
 * Threads creation table, one entry per thread.
*/
THD_TABLE_BEGIN
  THD_TABLE_THREAD(0, "blinker", waThread1, Thread1, NULL)
THD_TABLE_END

/**
 * Application entry point.
*/
int main(void) {
  /*
   * System initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  SEGGER_RTT_printf(0, "main\n");
  halInit();
  chSysInit();

  /*
   * Initialize the GPT driver1
   */
  gptStart(&GPTD1, &gptcfg);

  /*
   * Start a continuous timer
   */
  gptStartContinuous(&GPTD1, 2000);
 
  /* This is now the idle thread loop, you may perform here a low priority
     task but you must never try to sleep or wait in this loop. Note that
     this tasks runs at the lowest priority level so any instruction added
     here will be executed after all other tasks have been started.*/
  while (true) {
  }
}


The problem is I can see my thread just running once, right after flash. After sleep, the thread will not be executed again.
Is there any configuration that I missed out on? Where can I get the full reference to implement tick-less mode in CHIBIOS/NIL?


Thank you very much.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: NIL tick-less problem

Postby Giovanni » Tue Aug 04, 2020 10:33 am

Hi,

In order to use tick-less mode you need to provide to the kernel port a specific timer interface, I don't know LPC812 but I would verify this timer implementation.

This function on STM32 is performed by the HAL "ST" (SysTick) driver, is there an equivalent on LPC? does it actually support tick-less mode?

Giovanni

benitangela
Posts: 3
Joined: Thu Jul 23, 2020 3:29 am
Has thanked: 1 time

Re: NIL tick-less problem

Postby benitangela » Tue Aug 11, 2020 3:30 am

Sorry for the late response,

I think there is no specific timer in LPC812, like what STM32 has.
The only timer that uses low power oscillator is WKT (WakeUp Timer), but it is a 32-bit down counter timer.

From the previous discussion http://www.chibios.com/forum/viewtopic.php?f=20&t=985&start=10,
I found this
In tick-less mode the system time is no more a variable incremented by the system tick, it is an hardware register incremented at a fixed rate.


So, my question is can I use two timers as the substitute? WKT for waking up from sleep mode and SCT/PWM timer (16-bit/32-bit timer, supports up-counting) to increment system time.


--
Benita

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: NIL tick-less problem

Postby Giovanni » Tue Aug 11, 2020 6:24 am

Hi,

The two timers need to be perfectly synchronized, system time and time event work together. Note that you can turn a down counter timer into an up counter, just invert the value before returning it, same thing when setting the comparator.

Giovanni

benitangela
Posts: 3
Joined: Thu Jul 23, 2020 3:29 am
Has thanked: 1 time

Re: NIL tick-less problem

Postby benitangela » Wed Aug 12, 2020 4:43 am

Hi,


If MCU is wake up from sleep mode, is the thread wake up directly too?
Or is there any additional setting should be done?
For example in tick mode, I implement this in the handler.

Code: Select all

chSysLockFromISR();
chSysTimerHandlerI();
chSysUnlockFromISR();



Thank you

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: NIL tick-less problem

Postby Giovanni » Wed Aug 12, 2020 5:19 am

The OS just executes a WFI instruction when there is nothing to do and expects to exit from it on next interrupt.

It depends on what this sleep mode does, on some MCUs is could require a re-initialization of clocks, you need to look at the manual for details.

Giovanni


Return to “ChibiOS/NIL”

Who is online

Users browsing this forum: No registered users and 1 guest