Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

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