Make reading the global ms tick atomic in order to prevent glitches
This commit is contained in:
		| @@ -45,7 +45,7 @@ extern volatile uint32_t wait_tick_ms; | ||||
|  * @brief Systemclock in milliseconds. | ||||
|  * | ||||
|  * This value must not be reset during the whole runtime. | ||||
|  * | ||||
|  * @warning In order to use this, you must assure that the read access is atomic. | ||||
|  */ | ||||
| extern volatile uint64_t global_tick_ms; | ||||
|  | ||||
|   | ||||
| @@ -43,7 +43,13 @@ void systick_wait_ms(uint32_t ms) | ||||
|  | ||||
| uint64_t systick_get_global_tick() | ||||
| { | ||||
| 	return global_tick_ms; | ||||
| 	uint64_t temp; | ||||
|  | ||||
| 	__disable_irq(); | ||||
| 	temp = global_tick_ms; | ||||
| 	__enable_irq(); | ||||
|  | ||||
| 	return temp; | ||||
| } | ||||
|  | ||||
| bool __attribute__((optimize("O3"))) systick_ticks_have_passed(uint64_t start_timestamp, uint64_t ticks) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user