SysCallBareUno.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * Copyright (c) 2011-2020 Bill Greiman
  3. * This file is part of the SdFat library for SD memory cards.
  4. *
  5. * MIT License
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #include "SysCall.h"
  26. #if 0 // defined(__AVR_ATmega328P__) && !ENABLE_ARDUINO_FEATURES
  27. #include <avr/interrupt.h>
  28. // ISR for timer 2 Compare A interrupt
  29. volatile uint16_t timer2 = 0;
  30. ISR(TIMER2_COMPA_vect) {
  31. timer2++;
  32. }
  33. SdMillis_t SysCall::curTimeMS() {
  34. if (TIMSK2 != (1 << OCIE2A)) {
  35. // use system clock (clkI/O).
  36. ASSR &= ~(1 << AS2);
  37. // Clear Timer on Compare Match (CTC) mode
  38. TCCR2A = (1 << WGM21);
  39. // Only need 64x prescale bits in TCCR2B
  40. TCCR2B = (1 << CS22);
  41. // set TOP so timer period is 1 ms.
  42. #if F_CPU/64000 > 250
  43. #error F_CPU too large.
  44. #endif // F_CPU/64000 > 250
  45. OCR2A = F_CPU/64000UL - 1;
  46. // Enable interrupt.
  47. TIMSK2 = (1 << OCIE2A);
  48. }
  49. cli();
  50. uint16_t rtn = timer2;
  51. sei();
  52. return rtn;
  53. }
  54. #endif // defined(__AVR_ATmega328P__) && !ENABLE_ARDUINO_FEATURES