Microprocessor and peripheral 2 assignments for AUTH
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.
 
 
 
 
 
 

109 lines
3.4 KiB

  1. /*
  2. * \file jiffies.h
  3. * \brief
  4. * A target independent jiffy functionality
  5. *
  6. * Copyright (C) 2014 Houtouridis Christos (http://www.houtouridis.net)
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as
  10. * published by the Free Software Foundation, either version 3
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifndef __jiffies_h__
  23. #define __jiffies_h__
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include <stdint.h>
  28. #include <string.h>
  29. #include "driver_types.h"
  30. typedef uint16_t jiffy_t; //!< Jiffy type 2 byte unsigned integer
  31. typedef int32_t jtime_t; //!< Jiffy time type for delay functionalities usec/msec
  32. typedef int (*jf_setfreq_pt) (uint32_t, uint32_t); //!< Pointer to setfreq function \sa setfreq
  33. /*!
  34. * Jiffy inner structure,
  35. * \info
  36. * We use jiffies to count small time intervals and usually this is
  37. * below SysTick Interrupt. So we use an indepentend counter for that.
  38. * Linux names jiffies the Tick per sec. This is toooo big for us.
  39. * We name jiffy each tick of the extra timer.
  40. * The equalivent of linux jiffies is the return value of clock ().
  41. */
  42. typedef volatile struct {
  43. jf_setfreq_pt setfreq; /*!< Pointer to driver's timer set freq function */
  44. /*
  45. * \note
  46. * This function must get an integer value for timer's desired
  47. * frequency and returns the maximum jiffy value. This usual
  48. * refers to timer's auto reload value.
  49. */
  50. jiffy_t *value; /*!< Pointer to timers current value */
  51. uint32_t freq; /*!< timer's frequency */
  52. jiffy_t jiffies; /*!< jiffies max value (timer's max value) */
  53. jiffy_t jp1ms; /*!< Jiffies per 1 msec to use in delay function */
  54. jiffy_t jp1us; /*!< Jiffies per 1 usec to use in delay function */
  55. jiffy_t jp100ns; /*!< Jiffies per 100 nsec to use in delay function */
  56. drv_status_en status;
  57. }jf_t;
  58. /*
  59. * ============= PUBLIC jiffy API =============
  60. */
  61. /*
  62. * Link and Glue functions
  63. */
  64. void jf_link_setfreq (jf_setfreq_pt pfun);
  65. void jf_link_value (jiffy_t* v);
  66. /*
  67. * Set functions
  68. */
  69. /*
  70. * User Functions
  71. */
  72. drv_status_en jf_probe (void);
  73. void jf_deinit (void);
  74. drv_status_en jf_init (uint32_t jf_freq, jiffy_t jiffies);
  75. jiffy_t jf_get_jiffies (void);
  76. jiffy_t jf_get_jiffy (void);
  77. jiffy_t jf_per_msec (void);
  78. jiffy_t jf_per_usec (void);
  79. jiffy_t jf_per_100nsec (void);
  80. void jf_delay_ms (jtime_t msec);
  81. void jf_delay_us (jtime_t usec);
  82. void jf_delay_100ns (jtime_t _100nsec);
  83. int jf_check_msec (jtime_t msec);
  84. int jf_check_usec (jtime_t usec);
  85. int jf_check_100nsec (jtime_t _100nsec);
  86. /*!
  87. * \note
  88. * The Jiffy lib has no jiffy_t target pointer in the API. This means
  89. * that IT CAN BE ONLY ONE jiffy timer per application.
  90. */
  91. #ifdef __cplusplus
  92. }
  93. #endif
  94. #endif //#ifndef __jiffies_h__