mcu_def.h

  1. /******************************************************************************
  2. 文 件 名 : mcu_def.h
  3. 版 本 号 : 初稿
  4. 作 者 :
  5. 生成日期 :
  6. 最近修改 :
  7. 功能描述 : 此文件定义芯片类型文件
  8. 函数列表 :
  9. 修改历史 :
  10. 1.日 期 :
  11. 作 者 :
  12. 修改内容 : 创建文件
  13. ******************************************************************************/
  14. #ifndef __MCU_DEF_H__
  15. #define __MCU_DEF_H__
  16. // #define STM32F10X_MD
  17. #if defined (STM32F10X_MD) || defined(STM32F10X_HD)
  18. #ifndef STM32F10X_MCU
  19. #define STM32F10X_MCU
  20. #endif
  21. #endif
  22. #if defined (STM32F030)
  23. #ifndef STM32F0XX_MCU
  24. #define STM32F0XX_MCU
  25. #endif
  26. #endif
  27. #if defined (STM32F0XX_MCU)
  28. #include "stm32f0xx.h"
  29. #endif
  30. #if defined (STM32F10X_MCU)
  31. #include "stm32f10x.h"
  32. #endif
  33. #endif /* __MCU_DEF_H__ */

top_type.h

  1. /******************************************************************************
  2. 文 件 名 : top_type.h
  3. 版 本 号 : 初稿
  4. 作 者 :
  5. 生成日期 :
  6. 最近修改 :
  7. 功能描述 : 此文件定义数据类型文件
  8. 函数列表 :
  9. 修改历史 :
  10. 1.日 期 :
  11. 作 者 :
  12. 修改内容 : 创建文件
  13. ******************************************************************************/
  14. #ifndef __TOP_TYPE_H__
  15. #define __TOP_TYPE_H__
  16. #include <stdint.h>
  17. #include "mcu_def.h"
  18. #define __NULL__ ((void *) 0)
  19. typedef enum {__FALSE = 0, __TRUE = !__FALSE} __BOOL__;
  20. /* 双字节高低位数据交换*/
  21. #define __SWAP_U16(val) \
  22. ( (((val) & (0xffu << 8)) >> 8) \
  23. | (((val) & 0xffu) << 8) )
  24. /* 四字节高低位数据交换*/
  25. #define __SWAP_U32(val) \
  26. ( (((val) & (0xfful << 24)) >> 24) \
  27. | (((val) & (0xfful << 16)) >> 8) \
  28. | (((val) & (0xfful << 8)) << 8) \
  29. | (((val) & 0xfful) << 24) )
  30. /* 八字节高低位数据交换*/
  31. #define __SWAP_U64(val) \
  32. ( (((val) & (0xffull << 56)) >> 56) \
  33. | (((val) & (0xffull << 48)) >> 40) \
  34. | (((val) & (0xffull << 40)) >> 24) \
  35. | (((val) & (0xffull << 32)) >> 8) \
  36. | (((val) & (0xffull << 24)) << 8) \
  37. | (((val) & (0xffull << 16)) << 24) \
  38. | (((val) & (0xffull << 8)) << 40) \
  39. | (((val) & 0xffull) << 56) )
  40. typedef signed short s16;
  41. typedef signed char s8;
  42. typedef const int32_t sc32; /*!< Read Only */
  43. typedef const int16_t sc16; /*!< Read Only */
  44. typedef const int8_t sc8; /*!< Read Only */
  45. typedef __IO int32_t vs32;
  46. typedef __IO int16_t vs16;
  47. typedef __IO int8_t vs8;
  48. typedef __I int32_t vsc32; /*!< Read Only */
  49. typedef __I int16_t vsc16; /*!< Read Only */
  50. typedef __I int8_t vsc8; /*!< Read Only */
  51. typedef uint32_t u32;
  52. typedef unsigned short u16;
  53. typedef unsigned char u8;
  54. typedef unsigned short const uc16; /*!< Read Only */
  55. typedef unsigned char const uc8; /*!< Read Only */
  56. typedef __IO uint32_t vu32;
  57. typedef __IO uint16_t vu16;
  58. typedef __IO uint8_t vu8;
  59. typedef __I uint32_t vuc32; /*!< Read Only */
  60. typedef __I uint16_t vuc16; /*!< Read Only */
  61. typedef __I uint8_t vuc8; /*!< Read Only */
  62. typedef uint8_t bool;
  63. #endif /* __TOP_TYPE_H__ */

compile_time.h

  1. /******************************************************************************
  2. 文 件 名 : compile_time.h
  3. 版 本 号 : 初稿
  4. 作 者 :
  5. 生成日期 :
  6. 最近修改 :
  7. 功能描述 : 编译时间H文件,定义编译时间类型,并提供获取时间函数
  8. 函数列表 :
  9. 修改历史 :
  10. 1.日 期 :
  11. 作 者 :
  12. 修改内容 : 创建文件
  13. ******************************************************************************/
  14. #ifndef __COMPILE_TIME_H__
  15. #define __COMPILE_TIME_H__
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #include "top_type.h"
  20. /**
  21. * @ 编译时间: 例子(18-1-5-9-37-40)
  22. * @
  23. */
  24. typedef struct tag_compile_time
  25. {
  26. uint8_t year;
  27. uint8_t month;
  28. uint8_t day;
  29. uint8_t hour;
  30. uint8_t min;
  31. uint8_t sec;
  32. }__attribute__((packed))compile_time_t;
  33. void compile_time_get (compile_time_t * p_compile_time);
  34. #ifdef __cplusplus
  35. }
  36. #endif
  37. #endif // end __COMPILE_TIME_H__

compile_time.c

  1. /******************************************************************************
  2. 文 件 名 : compile_time.c
  3. 版 本 号 : 初稿
  4. 作 者 :
  5. 生成日期 :
  6. 最近修改 :
  7. 功能描述 : 编译时间C文件:通过预编译__DATE__和__TIME__实现获取编译时间函
  8. 数
  9. 函数列表 :
  10. compile_time_get
  11. 修改历史 :
  12. 1.日 期 :
  13. 作 者 :
  14. 修改内容 : 创建文件
  15. ******************************************************************************/
  16. #ifndef __COMPILE_TIME_C__
  17. #define __COMPILE_TIME_C__
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /******************************************************************************/
  22. /* */
  23. /* 头文件包含 */
  24. /* */
  25. /******************************************************************************/
  26. #include "compile_time.h"
  27. #include <stdio.h>
  28. #include <string.h>
  29. /******************************************************************************/
  30. /* */
  31. /* 宏定义 */
  32. /* */
  33. /******************************************************************************/
  34. /******************************************************************************/
  35. /* */
  36. /* 静态变量定义 */
  37. /* */
  38. /*******************************************************************************/
  39. /******************************************************************************/
  40. /* */
  41. /* 全局变量定义 */
  42. /* */
  43. /******************************************************************************/
  44. /******************************************************************************/
  45. /* */
  46. /* 静态函数定义 */
  47. /* */
  48. /*******************************************************************************/
  49. /******************************************************************************/
  50. /* */
  51. /* 全局函数定义 */
  52. /* */
  53. /******************************************************************************/
  54. /*****************************************************************************
  55. 函 数 名 : compile_time_get
  56. 功能描述 : 编译时间:获取编译时间
  57. 输入参数 : compile_time_t * p_compile_time
  58. 输出参数 : 无
  59. 返 回 值 :
  60. 调用函数 :
  61. 被调函数 :
  62. 修改历史 :
  63. 1.日 期 : 2018年1月5日
  64. 作 者 :
  65. 修改内容 : 新生成函数
  66. *****************************************************************************/
  67. void compile_time_get (compile_time_t * p_compile_time)
  68. {
  69. uint8_t time_buf[20];
  70. /* 将time_buf缓存区数据全部设置成0*/
  71. memset(time_buf, 0, sizeof(time_buf));
  72. /* 将p_compile_time缓存区数据全部设置成0*/
  73. memset(p_compile_time, 0, sizeof(compile_time_t));
  74. /* 中断输出编译时间*/
  75. sprintf((char *)time_buf,"%s",__DATE__);
  76. /* 取 2018 中18 */
  77. p_compile_time->year = time_buf[10] - '0';
  78. p_compile_time->year += (time_buf[9] - '0')*10;
  79. /* 月份*/
  80. switch ( time_buf[0] )
  81. {
  82. case 'A' :
  83. {
  84. if ( time_buf[1] == 'p' )
  85. {
  86. p_compile_time->month = 4;
  87. }
  88. else
  89. {
  90. p_compile_time->month = 8;
  91. }
  92. }break;
  93. case 'D' :
  94. {
  95. p_compile_time->month = 12;
  96. }break;
  97. case 'F' :
  98. {
  99. p_compile_time->month = 2;
  100. }break;
  101. case 'J' :
  102. {
  103. if ( time_buf[1] == 'a' )
  104. {
  105. p_compile_time->month = 1;
  106. }
  107. else
  108. {
  109. if ( time_buf[2] == 'n' )
  110. {
  111. p_compile_time->month = 6;
  112. }
  113. else
  114. {
  115. p_compile_time->month = 7;
  116. }
  117. }
  118. }break;
  119. case 'M' :
  120. {
  121. if ( time_buf[2] == 'r' )
  122. {
  123. p_compile_time->month = 3;
  124. }
  125. else
  126. {
  127. p_compile_time->month = 5;
  128. }
  129. }break;
  130. case 'N' :
  131. {
  132. p_compile_time->month = 11;
  133. }break;
  134. case 'O' :
  135. {
  136. p_compile_time->month = 10;
  137. }break;
  138. case 'S' :
  139. {
  140. p_compile_time->month = 9;
  141. }break;
  142. default:
  143. break;
  144. }
  145. /* 日*/
  146. p_compile_time->day = time_buf[5] - '0';
  147. if ( time_buf[4] != ' ' )
  148. {
  149. p_compile_time->day += (time_buf[4] - '0')*10;
  150. }
  151. memset(time_buf, 0, sizeof(time_buf));
  152. sprintf((char *)time_buf,"%s",__TIME__);
  153. /* 时 */
  154. p_compile_time->hour = (time_buf[0] - '0')*10 + (time_buf[1] - '0');
  155. /* 分 */
  156. p_compile_time->min = (time_buf[3] - '0')*10 + (time_buf[4] - '0');
  157. /* 秒 */
  158. p_compile_time->sec = (time_buf[6] - '0')*10 + (time_buf[7] - '0');
  159. }
  160. #ifdef __cplusplus
  161. }
  162. #endif
  163. #endif // end __COMPILE_TIME_C__

main.c

  1. #include "compile_time.h"
  2. /*
  3. * @ 编译时间: 例子(18-1-5-9-37-40)
  4. * @
  5. typedef struct tag_compile_time
  6. {
  7. uint8_t year;
  8. uint8_t month;
  9. uint8_t day;
  10. uint8_t hour;
  11. uint8_t min;
  12. uint8_t sec;
  13. }__attribute__((packed))compile_time_t;
  14. */
  15. void main(void)
  16. {
  17. compile_time_t compile_time;
  18. /* 获取编译时间 */
  19. compile_time_get (&compile_time);
  20. while(1)
  21. {
  22. }
  23. }