bool core_util_atomic_cas_u8(uint8_t *ptr, uint8_t *expectedCurrentValue, uint8_t desiredValue) { uint8_t currentValue = __LDREXB((volatile uint8_t*)ptr); if (currentValue != *expectedCurrentValue) { *expectedCurrentValue = currentValue; __CLREX(); return false; } return !__STREXB(desiredValue, (volatile uint8_t*)ptr); }
bool atomic_cas<uint32_t>(uint32_t *ptr, uint32_t *expectedCurrentValue, uint32_t desiredValue) { uint32_t currentValue = __LDREXW(ptr); if (currentValue != *expectedCurrentValue) { *expectedCurrentValue = currentValue; __CLREX(); return false; } return !__STREXW(desiredValue, ptr); }
bool core_util_atomic_cas_u32(volatile uint32_t *ptr, uint32_t *expectedCurrentValue, uint32_t desiredValue) { do { uint32_t currentValue = __LDREXW(ptr); if (currentValue != *expectedCurrentValue) { *expectedCurrentValue = currentValue; __CLREX(); return false; } } while (__STREXW(desiredValue, ptr)); return true; }
/** \fn int32_t Set_Channel_active_flag (uint8_t ch) \brief Protected set of channel active flag \param[in] ch Channel number (0..7) \returns - \b 0: function succeeded - \b -1: function failed */ static int32_t Set_Channel_active_flag (uint8_t ch) { uint32_t val; do { val = __LDREXW (&Channel_active); if (val & (1 << ch)) { __CLREX (); return -1; } } while (__STREXW (val | (1 << ch), &Channel_active)); return 0; }
int atomic_cas(atomic_int_t *var, int old, int now) { int tmp; int status; /* Load exclusive */ tmp = __LDREXW((volatile uint32_t *)(&ATOMIC_VALUE(*var))); if (tmp != old) { /* Clear memory exclusivity */ __CLREX(); return 0; } /* Try to write the new value */ status = __STREXW(now, (volatile uint32_t *)(&ATOMIC_VALUE(*var))); return (status == 0); }
/** * @brief Triggered by systen timer interrupt every millisecond. * @param None * @retval None */ void timer_interrupt_fn(void) { boot_time_ms++; /* we do it like this to have correct roll-over behaviour */ boot_time_us_base += 1000u; /* each timer decrements every millisecond if > 0 */ for (unsigned i = 0; i < NTIMERS; i++) { /* dont need exclusive access for reading the enabled flag because it will not be changed very often */ if (timer[i].flags & TIMER_FLAG_ENABLED) { if (timer[i].countdown > 0) { timer[i].countdown--; } else { timer[i].countdown = timer[i].period - 1; /* set the flag: */ timer[i].flags |= TIMER_FLAG_TRIGGERED; /* force a fail of the flags access instructions: */ __CLREX(); } } } }