發表文章

目前顯示的是 12月, 2014的文章

文章總列表

假日藍芽/嵌入式系統工程師: Nordic app_timer module

目的 Nordic提供心跳表的範例程式,不用多少功夫就能把它跑起來。範例用了app_timer module,因為某種潔癖使然,我花了一些時間追蹤運作機制。另外Nordic沒有太多文件描述他的運作,我也希望這篇文章能幫助社會大眾。 app_timer module使用一個RTC (Real Time Clock)模擬成多個軟體timer。這個技巧以前我在歐萊禮的書看過,當時沒花太多工夫研究,這次也想順便弄懂裡面是怎麼實作的。 架構 app_timer使用硬體RTC1 timer app_timer支援多個軟體timer,但是底層只用RTC1硬體timer。軟體用了queue,linked-list這些資料結構堆出需要的功能 程式庫支援在不同的IRQ level執行(ARM Cortex M0支援多種IRQ level)。這個比較是設計的考量,操作內部資料結構時可以不用關中斷製造critical section 使用者可以創造多個SW timer,可以設定{period, one-shot/periodic, callback function} 使用方式就不寫中文了 (懶惰) Initialization #define APP_TIMER_PRESCALER (0) #define APP_TIMER_MAX_TIMERS (5) // # of timers #define APP_TIMER_OP_QUEUE_SIZE (5) // timer operation queue APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false); In my board, a 32768hz oscillator is placed. I set the prescalar of RTC1 to 0, whose actual divider value is (PRESCALER + 1) RTC1's internal timer is 24-bit wide, and setting prescaler to 0 results timer overflow after 512...

Holiday Bluetooth Engineer: Nordic's app_timer module

Purpose I was tracking the heart rate sensor example, and try to figure out how to use the library. I found app_timer module's usage is a bit weird, so I tried to read source code, and find underlying mechanism. The note is intended to help people who want to understand app_timer library in Nordic's library, since Nordic doesn't have good document of this library. The module uses a single HW timer to implement several SW timers. I once read the trick from O'Reilly book, and I'm interested in how to implement it. Architecture The library uses RTC1 timer as underlying hardware timer. The library supports multiple SW timers through using single HW timer (RTC1). It mainly uses queue/ linked-list to achieve the target. The library also supports schedule timer at different IRQ level. This is implementation consideration, which allows multiple execution context running at the same time without creating critical section explicitly. Users can create several ...