mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
targets/hal/TARGET_Atmel/TARGET_SAM_CortexM0P/drivers/services/delay/sam0/systick_counter.c@144:423e1876dc07, 2016-08-02 (annotated)
- Committer:
- screamer
- Date:
- Tue Aug 02 14:07:36 2016 +0000
- Revision:
- 144:423e1876dc07
- Parent:
- 15:a81a8d6c1dfe
Added targets.json file for the supported targets in the release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 15:a81a8d6c1dfe | 1 | #include "delay.h" |
mbed_official | 15:a81a8d6c1dfe | 2 | |
mbed_official | 15:a81a8d6c1dfe | 3 | /** |
mbed_official | 15:a81a8d6c1dfe | 4 | * Value used to calculate ms delay. Default to be used with a 8MHz clock; |
mbed_official | 15:a81a8d6c1dfe | 5 | */ |
mbed_official | 15:a81a8d6c1dfe | 6 | static uint32_t cycles_per_ms = 8000000UL / 1000; |
mbed_official | 15:a81a8d6c1dfe | 7 | static uint32_t cycles_per_us = 8000000UL / 1000000; |
mbed_official | 15:a81a8d6c1dfe | 8 | |
mbed_official | 15:a81a8d6c1dfe | 9 | /** |
mbed_official | 15:a81a8d6c1dfe | 10 | * \brief Initialize the delay driver. |
mbed_official | 15:a81a8d6c1dfe | 11 | * |
mbed_official | 15:a81a8d6c1dfe | 12 | * This must be called during start up to initialize the delay routine with |
mbed_official | 15:a81a8d6c1dfe | 13 | * the current used main clock. It must run any time the main CPU clock is changed. |
mbed_official | 15:a81a8d6c1dfe | 14 | */ |
mbed_official | 15:a81a8d6c1dfe | 15 | void delay_init(void) |
mbed_official | 15:a81a8d6c1dfe | 16 | { |
mbed_official | 15:a81a8d6c1dfe | 17 | cycles_per_ms = system_gclk_gen_get_hz(0); |
mbed_official | 15:a81a8d6c1dfe | 18 | cycles_per_ms /= 1000; |
mbed_official | 15:a81a8d6c1dfe | 19 | cycles_per_us = cycles_per_ms / 1000; |
mbed_official | 15:a81a8d6c1dfe | 20 | |
mbed_official | 15:a81a8d6c1dfe | 21 | SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk; |
mbed_official | 15:a81a8d6c1dfe | 22 | } |
mbed_official | 15:a81a8d6c1dfe | 23 | |
mbed_official | 15:a81a8d6c1dfe | 24 | /** |
mbed_official | 15:a81a8d6c1dfe | 25 | * \brief Delay loop to delay at least n number of microseconds |
mbed_official | 15:a81a8d6c1dfe | 26 | * |
mbed_official | 15:a81a8d6c1dfe | 27 | * \param n Number of microseconds to wait |
mbed_official | 15:a81a8d6c1dfe | 28 | */ |
mbed_official | 15:a81a8d6c1dfe | 29 | void delay_cycles_us( |
mbed_official | 15:a81a8d6c1dfe | 30 | uint32_t n) |
mbed_official | 15:a81a8d6c1dfe | 31 | { |
mbed_official | 15:a81a8d6c1dfe | 32 | while (n--) { |
mbed_official | 15:a81a8d6c1dfe | 33 | /* Devide up to blocks of 10u */ |
mbed_official | 15:a81a8d6c1dfe | 34 | delay_cycles(cycles_per_us); |
mbed_official | 15:a81a8d6c1dfe | 35 | } |
mbed_official | 15:a81a8d6c1dfe | 36 | } |
mbed_official | 15:a81a8d6c1dfe | 37 | |
mbed_official | 15:a81a8d6c1dfe | 38 | /** |
mbed_official | 15:a81a8d6c1dfe | 39 | * \brief Delay loop to delay at least n number of milliseconds |
mbed_official | 15:a81a8d6c1dfe | 40 | * |
mbed_official | 15:a81a8d6c1dfe | 41 | * \param n Number of milliseconds to wait |
mbed_official | 15:a81a8d6c1dfe | 42 | */ |
mbed_official | 15:a81a8d6c1dfe | 43 | void delay_cycles_ms( |
mbed_official | 15:a81a8d6c1dfe | 44 | uint32_t n) |
mbed_official | 15:a81a8d6c1dfe | 45 | { |
mbed_official | 15:a81a8d6c1dfe | 46 | while (n--) { |
mbed_official | 15:a81a8d6c1dfe | 47 | /* Devide up to blocks of 1ms */ |
mbed_official | 15:a81a8d6c1dfe | 48 | delay_cycles(cycles_per_ms); |
mbed_official | 15:a81a8d6c1dfe | 49 | } |
mbed_official | 15:a81a8d6c1dfe | 50 | } |