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.
 
 
 
 
 
 

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