diff options
| author | Damien George | 2014-08-25 13:24:33 +0100 |
|---|---|---|
| committer | Damien George | 2014-08-25 13:24:33 +0100 |
| commit | e5cbb70328239e58c820938eccd51f3c735fc312 (patch) | |
| tree | c6f1f9d9f83327ab595e14276d4f4ab9f9a56c5d /teensy | |
| parent | 9480138f0c917b2400991066e94636f7d8076a4c (diff) | |
stmhal: Make enable_irq and disable_irq inline functions.
These functions are generally 1 machine instruction, and are used in
critical code, so makes sense to have them inline.
Also leave these functions uninverted (ie 0 means enable, 1 means
disable) and provide macro constants if you really need to distinguish
the states. This makes for smaller code as well (combined with
inlining).
Applied to teensy port as well.
Diffstat (limited to 'teensy')
| -rw-r--r-- | teensy/mpconfigport.h | 37 | ||||
| -rw-r--r-- | teensy/teensy_hal.h | 13 |
2 files changed, 33 insertions, 17 deletions
diff --git a/teensy/mpconfigport.h b/teensy/mpconfigport.h index ec68c9b5b..5e4b5129b 100644 --- a/teensy/mpconfigport.h +++ b/teensy/mpconfigport.h @@ -51,11 +51,40 @@ typedef unsigned int mp_uint_t; // must be pointer size typedef void *machine_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size -mp_int_t disable_irq(void); -void enable_irq(mp_int_t enable); +// We have inlined IRQ functions for efficiency (they are generally +// 1 machine instruction). +// +// Note on IRQ state: you should not need to know the specific +// value of the state variable, but rather just pass the return +// value from disable_irq back to enable_irq. If you really need +// to know the machine-specific values, see irq.h. + +#ifndef __disable_irq +#define __disable_irq() __asm__ volatile("CPSID i"); +#endif + +__attribute__(( always_inline )) static inline uint32_t __get_PRIMASK(void) { + uint32_t result; + __asm volatile ("MRS %0, primask" : "=r" (result)); + return(result); +} + +__attribute__(( always_inline )) static inline void __set_PRIMASK(uint32_t priMask) { + __asm volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); +} + +__attribute__(( always_inline )) static inline void enable_irq(mp_uint_t state) { + __set_PRIMASK(state); +} + +__attribute__(( always_inline )) static inline mp_uint_t disable_irq(void) { + mp_uint_t state = __get_PRIMASK(); + __disable_irq(); + return state; +} -#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq() -#define MICROPY_END_ATOMIC_SECTION(enable) enable_irq(enable) +#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq() +#define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state) // There is no classical C heap in bare-metal ports, only Python // garbage-collected heap. For completeness, emulate C heap via diff --git a/teensy/teensy_hal.h b/teensy/teensy_hal.h index ffbb70bcc..d7589975c 100644 --- a/teensy/teensy_hal.h +++ b/teensy/teensy_hal.h @@ -119,19 +119,6 @@ __attribute__(( always_inline )) static inline void __WFI(void) __asm volatile ("wfi"); } -__attribute__(( always_inline )) static inline uint32_t __get_PRIMASK(void) -{ - uint32_t result; - __asm volatile ("MRS %0, primask" : "=r" (result)); - return(result); -} - -__attribute__(( always_inline )) static inline void __set_PRIMASK(uint32_t priMask) -{ - __asm volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); -} - - uint32_t HAL_GetTick(void); void HAL_Delay(uint32_t Delay); |
