cancel
Showing results for 
Search instead for 
Did you mean: 

osal sleep

zhu.chang-qing
Associate II
Posted on June 17, 2015 at 08:40

Hello,

I am a newer of SPC studio, while I am learning SPCstudio,

I read help docs such as ''SPC560Pxx OS-less OSAL Component User Manual.chm''

I don't understand how this function ''osalThreadSleepMilliseconds(1000);'' implement ,even though I go into it for details.

Does anyone know how this function works? It sleeps for a while ,then wake up,or it use a system timer (STM)  to delay some time.

Thanks!

#spcstudio
2 REPLIES 2
Erwan YVIN
ST Employee
Posted on June 17, 2015 at 10:26 Hello Zhu ,

osalThreadSleepMilliseconds(1000); is based system tick calculated from the PIT Channel 0

(Periodic Interrupt Timer) (cf below)

/**
* @brief PIT channel 0 interrupt handler.
*
* @isr
*/
OSAL_IRQ_HANDLER(vector59) {
OSAL_IRQ_PROLOGUE();
osalSysLockFromISR();
osalOsTimerHandlerI();
osalSysUnlockFromISR();
/* Resets the PIT channel 0 IRQ flag.*/
PIT.CH[0].TFLG.R = 1;
OSAL_IRQ_EPILOGUE();
}

Initilialization is done in hal_lld_init()

/* PIT channel 0 initialization for Kernel ticks, the PIT is configured
to run in DRUN,RUN0...RUN3 and HALT0 modes, the clock is gated in other
modes.*/
INTC.PSR[59].R = SPC5_PIT0_IRQ_PRIORITY;
halSPCSetPeripheralClockMode(92,
SPC5_ME_PCTL_RUN(2) | SPC5_ME_PCTL_LP(2));
reg = halSPCGetSystemClock() / OSAL_ST_FREQUENCY - 1;
PIT.PITMCR.R = 1;

/* PIT clock enabled, stop while debugging. */

PIT.CH[0].LDVAL.R = reg;
PIT.CH[0].CVAL.R = reg;
PIT.CH[0].TFLG.R = 1;

/* Interrupt flag cleared. */

PIT.CH[0].TCTRL.R = 3;

/* Timer active, interrupt enabled. */
Best Regards Erwan
zhu.chang-qing
Associate II
Posted on June 18, 2015 at 05:53

hi, erwan!

Thank you so much!

I will go trough it.