PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

delay.c 1.0KB

3 år sedan
12345678910111213141516171819202122232425262728293031323334
  1. #include "Arduino.h"
  2. #define TWO_MHZ 2000000
  3. // delay and micros for 2 MHz cpu speed
  4. /***************************************************************************************************/
  5. uint32_t micros_lp(void) {
  6. uint32_t count, current, istatus;
  7. __disable_irq();
  8. current = SYST_CVR;
  9. count = systick_millis_count;
  10. istatus = SCB_ICSR; // bit 26 indicates if systick exception pending
  11. __enable_irq();
  12. //systick_current = current;
  13. //systick_count = count;
  14. //systick_istatus = istatus & SCB_ICSR_PENDSTSET ? 1 : 0;
  15. if ((istatus & SCB_ICSR_PENDSTSET) && current > 50) count++;
  16. current = ((2000000 / 1000) - 1) - current;
  17. return count * 1000 + current / (TWO_MHZ / 1000000);
  18. }
  19. /***************************************************************************************************/
  20. void delay_lp(uint32_t ms) {
  21. uint32_t start = micros();
  22. if (ms > 0) {
  23. while (1) {
  24. while ((micros() - start) >= 1000) {
  25. ms--;
  26. if (ms == 0) return;
  27. start += 1000;
  28. }
  29. yield();
  30. }
  31. }
  32. }