Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
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.
 
 
 
 
 
 

39 lines
858 B

  1. /* From: https://stackoverflow.com/questions/32610019/arm-m4-instructions-per-cycle-ipc-counters */
  2. /* minor formating + type fixes */
  3. volatile unsigned int *DWT_CYCCNT ;
  4. volatile unsigned int *DWT_CONTROL ;
  5. volatile unsigned int *SCB_DEMCR ;
  6. static void
  7. reset_timer()
  8. {
  9. DWT_CYCCNT = (unsigned int *)0xE0001004; //address of the register
  10. DWT_CONTROL = (unsigned int *)0xE0001000; //address of the register
  11. SCB_DEMCR = (unsigned int *)0xE000EDFC; //address of the register
  12. *SCB_DEMCR = *SCB_DEMCR | 0x01000000;
  13. *DWT_CYCCNT = 0; // reset the counter
  14. *DWT_CONTROL = 0;
  15. }
  16. static void start_timer()
  17. {
  18. *DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter
  19. }
  20. static void
  21. stop_timer()
  22. {
  23. *DWT_CONTROL = *DWT_CONTROL | 0 ; // disable the counter
  24. }
  25. static unsigned int
  26. getCycles()
  27. {
  28. return *DWT_CYCCNT;
  29. }