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.
 
 
 
 
 
 

157 lines
3.5 KiB

  1. /*!
  2. * \file
  3. * NUCLEO_F401RE.h
  4. * \brief
  5. * Nucleo F401RE port file. This file contain the implementation of driver
  6. * calls for F401RE board.
  7. *
  8. * Author: Christos Choutouridis AEM: 8997
  9. * email : <cchoutou@ece.auth.gr>
  10. */
  11. #ifndef NUCLEO_F401RE_H_
  12. #define NUCLEO_F401RE_H_
  13. #include <stm32f4xx.h>
  14. #include <stm32f4xx_hal.h>
  15. #include <core_cm4.h>
  16. /*
  17. * ========= Data types ========
  18. */
  19. //! Driver status return type
  20. typedef enum {
  21. LLD_OK = 0, //!< Indicate successful operation
  22. LLD_ERROR //!< Indicate Error
  23. }LLD_Status_en;
  24. typedef uint8_t din_t;
  25. #define OFF (0)
  26. #define ON (!OFF)
  27. #ifndef FALSE
  28. #define FALSE (0)
  29. #endif
  30. #ifndef TRUE
  31. #define TRUE (!FALSE)
  32. #endif
  33. /*
  34. * =============== System ===============
  35. */
  36. #if defined ( __GNUC__ ) && !defined (__CC_ARM)
  37. #include <sys/types.h>
  38. #endif
  39. #include <limits.h>
  40. /*
  41. * Also defined in types.h
  42. */
  43. #ifndef _CLOCK_T_
  44. #if defined (__CC_ARM)
  45. #define _CLOCK_T_ unsigned int
  46. #else
  47. #define _CLOCK_T_ unsigned long
  48. #endif
  49. typedef _CLOCK_T_ clock_t; /*!< CPU time type */
  50. #endif
  51. #ifndef _TIME_T_
  52. #if defined (__CC_ARM)
  53. #define _TIME_T_ unsigned int
  54. #else
  55. #define _TIME_T_ unsigned long
  56. #endif
  57. typedef _TIME_T_ time_t; /*!< date/time in unix secs past 1-Jan-70 type for 68 years*/
  58. #endif
  59. /*
  60. * Helper macros
  61. */
  62. #define _CLOCK_T_MAX_VALUE_ (ULONG_MAX) //!< Helper macro for maximum signed CPU time calculations
  63. /*!
  64. * Calculate the positive time difference of _t2_ and _t1_, where
  65. * _t1_, _t2_ are clock_t values
  66. * \note
  67. * _t2_ event comes is AFTER _t1_
  68. *
  69. * ex:
  70. * 0 1 2 3 4 5 6 7 8 9
  71. * ^ ^
  72. * | |
  73. * a b
  74. *
  75. * if : t1=a, t2=b then dt = b-a = t2 - t1
  76. * if : t1=b, t2=a then dt = 9 - (b-a) + 1 = UMAX - (t1-t2) + 1
  77. *
  78. */
  79. #define _CLOCK_DIFF(_t2_, _t1_) ( ((_t2_)>(_t1_)) ? ((_t2_)-(_t1_)) : (_CLOCK_T_MAX_VALUE_ - ((_t1_) - (_t2_)) + 1) )
  80. /*
  81. * CPU time macros
  82. */
  83. #define msec2CPUtime(_ms_) (((_ms_) * get_freq()) / 1000)
  84. #define sec2CPUtime(_s_) ((_s_) * get_freq())
  85. #define CPUtime2msec(_t_) (((_t_) * 1000) / get_freq())
  86. #define CPUtime2sec(_t_) ((_t_) / get_freq())
  87. HAL_StatusTypeDef HAL_SysTick_Init(clock_t sf);
  88. clock_t HAL_SelectSysTickFreq (clock_t sf);
  89. clock_t HAL_GetSysTickFreq (void);
  90. int HAL_SetSysTickFreq (clock_t sf);
  91. /*
  92. * ================ Jiffies =====================
  93. */
  94. #define JF_TIMER TIM5
  95. #define JF_TIM_CLOCK_FREQ (1000000) //1MHz it's OK
  96. #define JF_TIM_VALUE (JF_TIMER->CNT)
  97. #define JF_TIMER_CLK_ENABLE __HAL_RCC_TIM5_CLK_ENABLE
  98. int JF_setfreq (uint32_t jf_freq, uint32_t jiffies);
  99. /*
  100. * OS like Functionalities
  101. */
  102. clock_t get_freq (void);
  103. int set_freq (clock_t sf);
  104. clock_t clock (void);
  105. clock_t setclock (clock_t c);
  106. time_t time (time_t *timer);
  107. int settime (const time_t *t);
  108. /*
  109. * ============== Cycle count ==============
  110. */
  111. LLD_Status_en CYCLE_Init (void);
  112. clock_t CYCLE_Get (void);
  113. uint8_t _DINx (GPIO_TypeDef *port, uint32_t pin);
  114. uint8_t _DOUTx (GPIO_TypeDef *port, uint32_t pin, uint8_t st);
  115. /*
  116. * =============== Digital I/O ===============
  117. * BTN -- PC13
  118. * LED -- PA5 (SB42 is in place) [SB29: PB13]
  119. */
  120. LLD_Status_en NUCLEO_Port_Init (void);
  121. uint8_t NUCLEO_BTN (void);
  122. void NUCLEO_LED (uint8_t on);
  123. /*
  124. * ============= Board Init ==============
  125. */
  126. LLD_Status_en NUCLEO_Init (clock_t sys_freq);
  127. #endif /* NUCLEO_F401RE_H_ */