use RTOS get tick() API for millis() and micros() function.

This commit is contained in:
hathach committed 2017-01-10 16:13:38 +07:00
1 parent eeaf56b083
commit 26a58c25f9
4 files changed
+10 -60

No files matched your search

+2 -39
View File
@@ -25,39 +25,16 @@
extern "C" {
#endif
static volatile uint32_t overflows = 0;
uint32_t millis( void )
{
uint64_t ticks = (uint64_t)((uint64_t)overflows << (uint64_t)32) | (uint64_t)(NRF_RTC1->COUNTER);
return (ticks * 1000) / 32768;
return tick2ms(xTaskGetTickCount());
}
uint32_t micros( void )
{
uint64_t ticks = (uint64_t)((uint64_t)overflows << (uint64_t)32) | (uint64_t)(NRF_RTC1->COUNTER);
return (ticks * 1000000) / 32768;
return tick2us(xTaskGetTickCount());
}
#if 0
void delay( uint32_t ms )
{
if ( ms == 0 )
{
return ;
}
uint32_t start = millis() ;
do
{
yield() ;
} while ( millis() - start < ms ) ;
}
#else
void delay_blocking(uint32_t ms)
{
if ( ms == 0 )
@@ -78,20 +55,6 @@ void delay( uint32_t ms )
vTaskDelay(ms2tick(ms));
}
#endif
void RTC1_IRQHandler(void)
{
NRF_RTC1->EVENTS_OVRFLW = 0;
#if __CORTEX_M == 0x04
volatile uint32_t dummy = NRF_RTC1->EVENTS_OVRFLW;
(void)dummy;
#endif
overflows = (overflows + 1) & 0xff;
}
#ifdef __cplusplus
}
#endif
@@ -78,11 +78,13 @@ typedef void (*TaskFunction_t)( void * );
/* Converts a time in milliseconds to a time in ticks. */
#if configTICK_RATE_HZ == 1000
#define ms2tick(ms) ms
#define tick2ms(tck) tck
#define ms2tick(ms) (ms)
#define tick2ms(tck) (tck)
#define tick2us(tck) (1000*(tck))
#else
#define ms2tick( xTimeInMs ) ( ( TickType_t ) ( ( ( TickType_t ) ( xTimeInMs ) * ( TickType_t ) configTICK_RATE_HZ ) / ( TickType_t ) 1000 ) )
#define tick2ms(tck) ( ((tck) * 1000) / configTICK_RATE_HZ )
#define tick2ms(tck) ( ( ((uint64_t)(tck)) * 1000) / configTICK_RATE_HZ )
#define tick2us(tck) ( ( ((uint64_t)(tck)) * 1000000) / configTICK_RATE_HZ )
#endif
+2 -8
View File
@@ -35,6 +35,8 @@ static void loop_task(void* arg)
{
loop();
// if (serialEventRun) serialEventRun();
// To compatible with most code where loop is not rtos-aware
vTaskDelay(1); //taskYIELD();
}
@@ -49,8 +51,6 @@ int main( void )
initVariant();
delay_blocking(1);
if (setLoopStacksize)
{
_loopStacksize = setLoopStacksize();
@@ -65,11 +65,5 @@ int main( void )
NVIC_SystemReset();
// for (;;)
// {
// loop();
// if (serialEventRun) serialEventRun();
// }
return 0;
}
+1 -10
View File
@@ -27,19 +27,10 @@ extern "C" {
void init( void )
{
NVIC_SetPriority(RTC1_IRQn, 15);
NVIC_ClearPendingIRQ(RTC1_IRQn);
NVIC_EnableIRQ(RTC1_IRQn);
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
NRF_RTC1->PRESCALER = 0;
NRF_RTC1->EVTENSET = offsetof(NRF_RTC_Type, EVENTS_OVRFLW);
NRF_RTC1->INTENSET = offsetof(NRF_RTC_Type, EVENTS_OVRFLW);
NRF_RTC1->TASKS_START = 1;
}
#ifdef __cplusplus
}
#endif
#endif