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