The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_SAMD21J18A/TARGET_Atmel/TARGET_SAM_CortexM0P/drivers/services/delay/sam0/systick_counter.h@111:4336505e4b1c
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 111:4336505e4b1c 1 #ifndef CYCLE_COUNTER_H_INCLUDED
Kojto 111:4336505e4b1c 2 #define CYCLE_COUNTER_H_INCLUDED
Kojto 111:4336505e4b1c 3
Kojto 111:4336505e4b1c 4 #include <compiler.h>
Kojto 111:4336505e4b1c 5 #include <clock.h>
Kojto 111:4336505e4b1c 6
Kojto 111:4336505e4b1c 7 #ifdef __cplusplus
Kojto 111:4336505e4b1c 8 extern "C" {
Kojto 111:4336505e4b1c 9 #endif
Kojto 111:4336505e4b1c 10
Kojto 111:4336505e4b1c 11 /**
Kojto 111:4336505e4b1c 12 * \name Convenience functions for busy-wait delay loops
Kojto 111:4336505e4b1c 13 *
Kojto 111:4336505e4b1c 14 * @{
Kojto 111:4336505e4b1c 15 */
Kojto 111:4336505e4b1c 16
Kojto 111:4336505e4b1c 17 /**
Kojto 111:4336505e4b1c 18 * \brief Delay loop to delay n number of cycles
Kojto 111:4336505e4b1c 19 * Delay program execution for at least the specified number of CPU cycles.
Kojto 111:4336505e4b1c 20 *
Kojto 111:4336505e4b1c 21 * \param n Number of cycles to delay
Kojto 111:4336505e4b1c 22 */
Kojto 111:4336505e4b1c 23 static inline void delay_cycles(
Kojto 111:4336505e4b1c 24 const uint32_t n)
Kojto 111:4336505e4b1c 25 {
Kojto 111:4336505e4b1c 26 if (n > 0) {
Kojto 111:4336505e4b1c 27 SysTick->LOAD = n;
Kojto 111:4336505e4b1c 28 SysTick->VAL = 0;
Kojto 111:4336505e4b1c 29
Kojto 111:4336505e4b1c 30 while (!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk)) {
Kojto 111:4336505e4b1c 31 };
Kojto 111:4336505e4b1c 32 }
Kojto 111:4336505e4b1c 33 }
Kojto 111:4336505e4b1c 34
Kojto 111:4336505e4b1c 35 void delay_cycles_us(uint32_t n);
Kojto 111:4336505e4b1c 36
Kojto 111:4336505e4b1c 37 void delay_cycles_ms(uint32_t n);
Kojto 111:4336505e4b1c 38
Kojto 111:4336505e4b1c 39 /**
Kojto 111:4336505e4b1c 40 * \brief Delay program execution for at least the specified number of microseconds.
Kojto 111:4336505e4b1c 41 *
Kojto 111:4336505e4b1c 42 * \param delay number of microseconds to wait
Kojto 111:4336505e4b1c 43 */
Kojto 111:4336505e4b1c 44 #define cpu_delay_us(delay) delay_cycles_us(delay)
Kojto 111:4336505e4b1c 45
Kojto 111:4336505e4b1c 46 /**
Kojto 111:4336505e4b1c 47 * \brief Delay program execution for at least the specified number of milliseconds.
Kojto 111:4336505e4b1c 48 *
Kojto 111:4336505e4b1c 49 * \param delay number of milliseconds to wait
Kojto 111:4336505e4b1c 50 */
Kojto 111:4336505e4b1c 51 #define cpu_delay_ms(delay) delay_cycles_ms(delay)
Kojto 111:4336505e4b1c 52
Kojto 111:4336505e4b1c 53 /**
Kojto 111:4336505e4b1c 54 * \brief Delay program execution for at least the specified number of seconds.
Kojto 111:4336505e4b1c 55 *
Kojto 111:4336505e4b1c 56 * \param delay number of seconds to wait
Kojto 111:4336505e4b1c 57 */
Kojto 111:4336505e4b1c 58 #define cpu_delay_s(delay) delay_cycles_ms(1000 * delay)
Kojto 111:4336505e4b1c 59
Kojto 111:4336505e4b1c 60 /**
Kojto 111:4336505e4b1c 61 * @}
Kojto 111:4336505e4b1c 62 */
Kojto 111:4336505e4b1c 63
Kojto 111:4336505e4b1c 64 #ifdef __cplusplus
Kojto 111:4336505e4b1c 65 }
Kojto 111:4336505e4b1c 66 #endif
Kojto 111:4336505e4b1c 67
Kojto 111:4336505e4b1c 68 #endif /* CYCLE_COUNTER_H_INCLUDED */