timing_alt.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * @Author: jiejie
  3. * @Github: https://github.com/jiejieTop
  4. * @Date: 2020-01-08 19:41:14
  5. * @LastEditTime: 2020-01-08 19:44:11
  6. * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  7. */
  8. /**
  9. * \file timing_alt.h
  10. *
  11. * \brief Portable interface to the CPU cycle counter
  12. *
  13. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * http://www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. *
  28. * This file is part of mbed TLS (https://tls.mbed.org)
  29. */
  30. #ifndef _TIMING_ALT_H_
  31. #define _TIMING_ALT_H_
  32. #if !defined(MBEDTLS_CONFIG_FILE)
  33. #include "config.h"
  34. #else
  35. #include MBEDTLS_CONFIG_FILE
  36. #endif
  37. #include "stdint.h"
  38. /**
  39. * @brief timer structure
  40. */
  41. struct mbedtls_timing_hr_time {
  42. uint64_t timer_ms;
  43. };
  44. /**
  45. * @brief Context for mbedtls_timing_set/get_delay()
  46. */
  47. typedef struct {
  48. struct mbedtls_timing_hr_time timer;
  49. uint32_t int_ms;
  50. uint32_t fin_ms;
  51. } mbedtls_timing_delay_context;
  52. /**
  53. * @brief Return the elapsed time in milliseconds
  54. *
  55. * @param val points to a timer structure
  56. * @param reset if set to 1, the timer is restarted
  57. */
  58. unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int reset);
  59. /**
  60. * @brief Set a pair of delays to watch
  61. * Must point to a valid mbedtls_timing_delay_context struct.
  62. *
  63. * @param data Pointer to timing data
  64. * @param int_ms First (intermediate) delay in milliseconds.
  65. * @param fin_ms Second (final) delay in milliseconds.
  66. * Pass 0 to cancel the current delay.
  67. */
  68. void mbedtls_timing_set_delay(void *data, uint32_t int_ms, uint32_t fin_ms);
  69. /**
  70. * @brief Get the status of delays
  71. * (Memory helper: number of delays passed.)
  72. *
  73. * @param data Pointer to timing data
  74. * Must point to a valid mbedtls_timing_delay_context struct.
  75. *
  76. * @return -1 if cancelled (fin_ms = 0)
  77. * 0 if none of the delays are passed,
  78. * 1 if only the intermediate delay is passed,
  79. * 2 if the final delay is passed.
  80. */
  81. int mbedtls_timing_get_delay(void *data);
  82. #endif