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.
 
 
 
 
 
 

138 lines
3.1 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. #define _CLOCK_T_ unsigned long /* clock() */
  47. typedef _CLOCK_T_ clock_t; /*!< CPU time type */
  48. #endif
  49. #ifndef _TIME_T_
  50. #define _TIME_T_ long /* time() */
  51. typedef _TIME_T_ time_t; /*!< date/time in unix secs past 1-Jan-70 type for 68 years*/
  52. #endif
  53. /*
  54. * Helper macros
  55. */
  56. #define _CLOCK_T_MAX_VALUE_ (ULONG_MAX) //!< Helper macro for maximum signed CPU time calculations
  57. /*!
  58. * Calculate the positive time difference of _t2_ and _t1_, where
  59. * _t1_, _t2_ are clock_t values
  60. * \note
  61. * _t2_ event comes is AFTER _t1_
  62. *
  63. * ex:
  64. * 0 1 2 3 4 5 6 7 8 9
  65. * ^ ^
  66. * | |
  67. * a b
  68. *
  69. * if : t1=a, t2=b then dt = b-a = t2 - t1
  70. * if : t1=b, t2=a then dt = 9 - (b-a) + 1 = UMAX - (t1-t2) + 1
  71. *
  72. */
  73. #define _CLOCK_DIFF(_t2_, _t1_) ( ((_t2_)>(_t1_)) ? ((_t2_)-(_t1_)) : (_CLOCK_T_MAX_VALUE_ - ((_t1_) - (_t2_)) + 1) )
  74. /*
  75. * CPU time macros
  76. */
  77. #define msec2CPUtime(_ms_) (((_ms_) * get_freq()) / 1000)
  78. #define sec2CPUtime(_s_) ((_s_) * get_freq())
  79. #define CPUtime2msec(_t_) (((_t_) * 1000) / get_freq())
  80. #define CPUtime2sec(_t_) ((_t_) / get_freq())
  81. HAL_StatusTypeDef HAL_SysTick_Init(clock_t sf);
  82. clock_t HAL_SelectSysTickFreq (clock_t sf);
  83. clock_t HAL_GetSysTickFreq (void);
  84. int HAL_SetSysTickFreq (clock_t sf);
  85. /*
  86. * OS like Functionalities
  87. */
  88. clock_t get_freq (void);
  89. int set_freq (clock_t sf);
  90. clock_t clock (void);
  91. clock_t setclock (clock_t c);
  92. time_t time (time_t *timer);
  93. int settime (const time_t *t);
  94. /*
  95. * ============== Cycle count ==============
  96. */
  97. LLD_Status_en CYCLE_Init (void);
  98. clock_t CYCLE_Get (void);
  99. /*
  100. * =============== Digital I/O ===============
  101. * BTN -- PC13
  102. * LED -- PA5 (SB42 is in place) [SB29: PB13]
  103. */
  104. LLD_Status_en Port_Init (void);
  105. uint8_t BTN (void);
  106. void LED (uint8_t on);
  107. /*
  108. * ============= Board Init ==============
  109. */
  110. LLD_Status_en LLD_Init (clock_t sys_freq);
  111. #endif /* NUCLEO_F401RE_H_ */