提交 e4823f32 编写于 作者: B Bernard Xiong 提交者: GitHub

Merge pull request #743 from geniusgogo/NRF52832

[BSP] update NRF52832 bsp
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
void rt_init_thread_entry(void* parameter) void rt_init_thread_entry(void* parameter)
{ {
rt_os_ready(); extern rt_err_t ble_init(void);
ble_init(); ble_init();
} }
...@@ -39,7 +40,7 @@ int rt_application_init(void) ...@@ -39,7 +40,7 @@ int rt_application_init(void)
RT_THREAD_PRIORITY_MAX / 3, 20); RT_THREAD_PRIORITY_MAX / 3, 20);
if (tid != RT_NULL) if (tid != RT_NULL)
rt_thread_startup(tid); rt_thread_startup(tid);
return 0; return 0;
} }
......
...@@ -592,7 +592,7 @@ static rt_bool_t _stack_init(void) ...@@ -592,7 +592,7 @@ static rt_bool_t _stack_init(void)
static void _stack_thread(void *parameter) static void _stack_thread(void *parameter)
{ {
rt_tick_t next_timeout = (rt_tick_t)RT_WAITING_FOREVER; rt_tick_t next_timeout = (rt_tick_t)RT_WAITING_FOREVER;
FAST_ADV(); FAST_ADV();
// Enter main loop. // Enter main loop.
for (;;) for (;;)
......
...@@ -10,8 +10,7 @@ ...@@ -10,8 +10,7 @@
#include "nrf_gpio.h" #include "nrf_gpio.h"
#include <rtthread.h> #include <rtthread.h>
#include <rthw.h>
static rt_bool_t osready = RT_FALSE;
#if 0 #if 0
...@@ -39,7 +38,7 @@ void SysTick_Configuration(void) ...@@ -39,7 +38,7 @@ void SysTick_Configuration(void)
void SysTick_Handler(void) void SysTick_Handler(void)
{ {
if (osready) if (rt_thread_self() != RT_NULL)
{ {
/* enter interrupt */ /* enter interrupt */
rt_interrupt_enter(); rt_interrupt_enter();
...@@ -84,7 +83,7 @@ void SysTick_Configuration(void) ...@@ -84,7 +83,7 @@ void SysTick_Configuration(void)
NVIC_EnableIRQ(NRF_RTC_IRQn); NVIC_EnableIRQ(NRF_RTC_IRQn);
} }
void OSTick_Handler( void ) static rt_tick_t _tick_distance(void)
{ {
nrf_rtc_event_clear(NRF_RTC_REG, NRF_RTC_EVENT_COMPARE_0); nrf_rtc_event_clear(NRF_RTC_REG, NRF_RTC_EVENT_COMPARE_0);
...@@ -98,40 +97,71 @@ void OSTick_Handler( void ) ...@@ -98,40 +97,71 @@ void OSTick_Handler( void )
m_tick_overflow_count++; m_tick_overflow_count++;
} }
{ return ((m_tick_overflow_count << NRF_RTC_BITWIDTH) + systick_counter) - rt_tick_get();
uint32_t diff; }
diff = ((m_tick_overflow_count << NRF_RTC_BITWIDTH) + systick_counter) - rt_tick_get();
while((diff--) > 0) void OSTick_Handler( void )
{
uint32_t diff;
diff = _tick_distance();
while((diff--) > 0)
{
if (rt_thread_self() != RT_NULL)
{ {
if (osready) /* enter interrupt */
{ rt_interrupt_enter();
/* enter interrupt */
rt_interrupt_enter();
rt_tick_increase(); rt_tick_increase();
/* leave interrupt */ /* leave interrupt */
rt_interrupt_leave(); rt_interrupt_leave();
} }
}
}
static void _wakeup_tick_adjust(void)
{
uint32_t diff;
uint32_t level;
level = rt_hw_interrupt_disable();
diff = _tick_distance();
rt_tick_set(rt_tick_get() + diff);
if (rt_thread_self() != RT_NULL)
{
struct rt_thread *thread;
/* check time slice */
thread = rt_thread_self();
if (thread->remaining_tick <= diff)
{
/* change to initialized tick */
thread->remaining_tick = thread->init_tick;
/* yield */
rt_thread_yield();
} }
else
{
thread->remaining_tick -= diff;
}
/* check timer */
rt_timer_check();
} }
rt_hw_interrupt_enable(level);
} }
static void _sleep_ongo( uint32_t sleep_tick ) static void _sleep_ongo( uint32_t sleep_tick )
{ {
/*
* Implementation note:
*
* To help debugging the option configUSE_TICKLESS_IDLE_SIMPLE_DEBUG was presented.
* This option would make sure that even if program execution was stopped inside
* this function no more than expected number of ticks would be skipped.
*
* Normally RTC works all the time even if firmware execution was stopped
* and that may lead to skipping too much of ticks.
*/
uint32_t enterTime; uint32_t enterTime;
uint32_t entry_tick; uint32_t entry_tick;
/* Make sure the SysTick reload value does not overflow the counter. */ /* Make sure the SysTick reload value does not overflow the counter. */
...@@ -144,7 +174,6 @@ static void _sleep_ongo( uint32_t sleep_tick ) ...@@ -144,7 +174,6 @@ static void _sleep_ongo( uint32_t sleep_tick )
enterTime = nrf_rtc_counter_get(NRF_RTC_REG); enterTime = nrf_rtc_counter_get(NRF_RTC_REG);
// if ( eTaskConfirmSleepModeStatus() != eAbortSleep )
{ {
uint32_t wakeupTime = (enterTime + sleep_tick) & NRF_RTC_MAXTICKS; uint32_t wakeupTime = (enterTime + sleep_tick) & NRF_RTC_MAXTICKS;
...@@ -183,6 +212,8 @@ static void _sleep_ongo( uint32_t sleep_tick ) ...@@ -183,6 +212,8 @@ static void _sleep_ongo( uint32_t sleep_tick )
nrf_rtc_int_disable(NRF_RTC_REG, NRF_RTC_INT_COMPARE0_MASK); nrf_rtc_int_disable(NRF_RTC_REG, NRF_RTC_INT_COMPARE0_MASK);
nrf_rtc_event_clear(NRF_RTC_REG, NRF_RTC_EVENT_COMPARE_0); nrf_rtc_event_clear(NRF_RTC_REG, NRF_RTC_EVENT_COMPARE_0);
_wakeup_tick_adjust();
/* Correct the system ticks */ /* Correct the system ticks */
{ {
...@@ -200,11 +231,6 @@ static void _sleep_ongo( uint32_t sleep_tick ) ...@@ -200,11 +231,6 @@ static void _sleep_ongo( uint32_t sleep_tick )
#endif #endif
void rt_os_ready(void)
{
osready = 1;
}
void rt_hw_system_powersave(void) void rt_hw_system_powersave(void)
{ {
uint32_t sleep_tick; uint32_t sleep_tick;
......
...@@ -9,7 +9,5 @@ ...@@ -9,7 +9,5 @@
void rt_hw_board_init(void); void rt_hw_board_init(void);
void rt_os_ready(void);
#endif #endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册