1
0

current_time.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* current-time.c
  2. *
  3. * Copyright (C) 2006-2022 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #include <wolfssl/wolfcrypt/settings.h>
  25. #ifdef WOLFSSL_TI_CURRTIME
  26. #include <stdio.h>
  27. #include <stdbool.h>
  28. #include <stdint.h>
  29. #include "inc/hw_ints.h"
  30. #include "inc/hw_memmap.h"
  31. #include "inc/hw_timer.h"
  32. #include "driverlib/rom.h"
  33. #include "driverlib/sysctl.h"
  34. #include "driverlib/timer.h"
  35. void InitTimer(void) {
  36. uint32_t ui32SysClock = ROM_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
  37. SYSCTL_OSC_MAIN |
  38. SYSCTL_USE_PLL |
  39. SYSCTL_CFG_VCO_480), 120000000);
  40. printf("Clock=%dMHz\n", (int)(ui32SysClock/1000000));
  41. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
  42. ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
  43. ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, -1);
  44. ROM_TimerEnable(TIMER0_BASE, TIMER_A);
  45. }
  46. static int initFlag = false ;
  47. double current_time(int reset)
  48. {
  49. if(!initFlag)InitTimer() ;
  50. initFlag = true ;
  51. if(reset)ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, -1);
  52. return (double)(-(int)ROM_TimerValueGet(TIMER0_BASE, TIMER_A ))/120000000.0 ;
  53. }
  54. #else
  55. /* dummy */
  56. double current_time(int reset) {
  57. static double t;
  58. t += 1.0; /* for avoid infinite loop of waiting time */
  59. if(reset)t = 0.0;
  60. return t ;
  61. }
  62. #endif