Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.cpp 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "mbed.h"
  2. extern "C" {
  3. volatile uint32_t msTicks;
  4. void SysTick_Handler(void) {
  5. msTicks++;
  6. }
  7. void Delay(uint32_t dlyTicks) {
  8. uint32_t curTicks;
  9. curTicks = msTicks;
  10. while ((msTicks - curTicks) < dlyTicks);
  11. }
  12. }
  13. int main() {
  14. SysTick_Config(SystemCoreClock / 1000);
  15. SIM->SCGC6 |= SIM_SCGC6_PIT_MASK; // Clock PIT
  16. PIT->MCR = 0; // Enable PIT
  17. // Timer 1
  18. PIT->CHANNEL[1].LDVAL = 0xFFFFFFFF;
  19. PIT->CHANNEL[1].TCTRL = 0x0; // Disable Interrupts
  20. PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_CHN_MASK; // Chain to timer 0
  21. PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_TEN_MASK; // Start timer 1
  22. // Timer 2
  23. PIT->CHANNEL[0].LDVAL = 0xFFFFFFFF;
  24. PIT->CHANNEL[0].TCTRL = PIT_TCTRL_TEN_MASK; // Start timer 0, disable interrupts
  25. DigitalOut led(LED_BLUE);
  26. while (true) {
  27. Delay(1000);
  28. led = !led;
  29. uint64_t ticks = (uint64_t)PIT->LTMR64H << 32;
  30. ticks |= (uint64_t)PIT->LTMR64L;
  31. printf("ticks: 0x%x%x\n", (uint32_t)(ticks>>32), (uint32_t)(ticks & 0xFFFFFFFF));
  32. ticks = (~ticks) / 24;
  33. uint32_t us = (uint32_t)(0xFFFFFFFF & ticks);
  34. printf("us : 0x%x\n", us);
  35. }
  36. }