INCLUDE_ATY.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. /**
  2. * @file INCLUDE_ATY.h
  3. *
  4. * @param Project DEVICE_GENERAL_ATY_LIB
  5. *
  6. * @author ATY
  7. *
  8. * @copyright
  9. * - Copyright 2017 - 2025 MZ-ATY
  10. * - This code follows:
  11. * - MZ-ATY Various Contents Joint Statement -
  12. * <a href="https://mengze.top/MZ-ATY_VCJS">
  13. * https://mengze.top/MZ-ATY_VCJS</a>
  14. * - CC 4.0 BY-NC-SA -
  15. * <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  16. * https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
  17. * - Your use will be deemed to have accepted the terms of this statement.
  18. *
  19. * @brief Headers include or defines for all embedded code
  20. * - MCU main changes at GPIO/TIMER/PWM
  21. *
  22. * @version
  23. * - 1_01_220605 > ATY
  24. * -# Preliminary version, first Release
  25. * @todo
  26. * - HW port file set independent
  27. * - Not support 64 platfrom, todo or never(and double)
  28. ********************************************************************************
  29. */
  30. // fromelf.exe --bin -o ./DIPM_ATY_ST_V3/DIPM_ATY_ST_V3.bin ./DIPM_ATY_ST_V3/DIPM_ATY_ST_V3.axf
  31. /* Keyword ********************************************************************
  32. ANSI C:
  33. auto
  34. break
  35. case
  36. char
  37. const
  38. continue
  39. default
  40. do
  41. double
  42. else
  43. enum
  44. extern
  45. float
  46. for
  47. goto
  48. if
  49. int
  50. long
  51. register
  52. return
  53. short
  54. signed
  55. sizeof
  56. static
  57. struct
  58. switch
  59. typedef
  60. union
  61. unsigned
  62. void
  63. volatile
  64. while
  65. C99:
  66. inline
  67. restrict
  68. _Bool
  69. _Complex
  70. _Imaginary
  71. C11:
  72. _Alignas
  73. _Alignof
  74. _Atomic
  75. _Static_assert
  76. _Noreturn
  77. _Thread_local
  78. _Generic
  79. C51:
  80. _at_
  81. _priority_
  82. _task_
  83. alien
  84. bdata
  85. bit
  86. code
  87. compact
  88. data
  89. idata
  90. interrupt
  91. large
  92. pdata
  93. reentrant
  94. sbit
  95. sfr
  96. sfr16
  97. small
  98. using
  99. xdata
  100. ********************************************************************************
  101. */
  102. #ifndef __INCLUDE_ATY_H
  103. #define __INCLUDE_ATY_H
  104. /******************************* Data Type ************************************/
  105. // #define __UNUSED(x) ((void)(x))
  106. #define __UNUSED(x) (x = x) // not suit for const, used for function formal parameter uaually
  107. #ifndef __stdint_h
  108. #define __stdint_h
  109. #ifndef bit
  110. #define bit uint8_t
  111. #endif /* bit */
  112. #ifndef _UINT8_T
  113. #define _UINT8_T
  114. typedef unsigned char uint8_t;
  115. #endif /* _UINT8_T */
  116. #ifndef _UINT16_T
  117. #define _UINT16_T
  118. typedef unsigned short int uint16_t;
  119. #endif /* _UINT16_T */
  120. #ifndef _UINT32_T
  121. #define _UINT32_T
  122. typedef unsigned long uint32_t;
  123. #endif /* _UINT32_T */
  124. #ifndef _UINT64_T
  125. #define _UINT64_T
  126. #if defined (SDCC) || defined(__SDCC) || defined(__CX51__) || defined(__C51__)
  127. typedef unsigned long int uint64_t; // uint64_t at 64 bit platform with ulong
  128. #else
  129. typedef unsigned long long int uint64_t;
  130. #endif /* uint64_t */
  131. #endif /* _UINT64_T */
  132. typedef signed char int8_t;
  133. typedef signed short int int16_t;
  134. typedef signed int int32_t;
  135. #if defined (SDCC) || defined(__SDCC) || defined(__CX51__) || defined(__C51__)
  136. typedef signed long int int64_t;
  137. #else
  138. typedef signed long long int int64_t;
  139. #endif /* int64_t */
  140. #endif /* __stdint_h */
  141. /******************************* Platform *************************************/
  142. #if defined (__SDCC_SYNTAX_FIX)
  143. #include <stdbool.h>
  144. #include <lint.h>
  145. # warning unrecognized compiler
  146. #define __BIT bool
  147. #define __DATA
  148. #define __IDATA
  149. #define __PDATA
  150. #define __XDATA
  151. #define __CODE
  152. #define __REENTRANT
  153. #define SBIT(name, addr, bit) volatile bool name
  154. #define SFR(name, addr) volatile unsigned char name
  155. #define SFRX(addr) (*(unsigned char volatile *)(addr))
  156. #define SFR16X(addr) (*(unsigned char volatile *)(addr))
  157. #define INTERRUPT(name, vector) void name (void)
  158. #define INTERRUPT_USING(name, vector, regnum) void name (void)
  159. #define __NOP_ATY
  160. #define __WEAK_ATY
  161. #elif defined(SDCC) || defined(__SDCC)
  162. #define __BIT __bit
  163. #define __DATA __data
  164. #define __IDATA __idata
  165. #define __PDATA __pdata
  166. #define __XDATA __xdata
  167. #define __CODE __code
  168. #define __REENTRANT __reentrant
  169. #define SBIT(name, addr, bit) __sbit __at(addr+bit) name
  170. #define SFR(name, addr) __sfr __at(addr) name
  171. #define SFRX(addr) (*(unsigned char volatile __xdata *)(addr))
  172. #define SFR16X(addr) (*(unsigned int volatile __xdata *)(addr))
  173. // #define INTERRUPT(name, vector) void name (void) __interrupt (vector)
  174. // #define INTERRUPT_USING(name, vector, regnum) void name (void) __interrupt (vector) __using (regnum)
  175. #define INTERRUPT(vector) __interrupt (vector)
  176. #define INTERRUPT_USING(vector, regnum) __interrupt (vector) __using (regnum)
  177. #define __NOP_ATY __asm NOP __endasm
  178. #define __WEAK_ATY
  179. #elif defined(__CX51__) || defined(__C51__)
  180. // #warning Use C51
  181. #define __BIT bit
  182. #define __DATA data
  183. #define __IDATA idata
  184. #define __PDATA pdata
  185. #define __XDATA xdata
  186. #define __CODE code
  187. #define __REENTRANT reentrant
  188. #define SBIT(name, addr, bit) sbit name = addr^bit
  189. #define SFR(name, addr) sfr name = addr
  190. #define SFRX(addr) (*(unsigned char volatile xdata *)(addr))
  191. #define SFR16X(addr) (*(unsigned int volatile xdata *)(addr))
  192. // #define INTERRUPT(name, vector) void name (void) interrupt vector
  193. // #define INTERRUPT_USING(name, vector, regnum) void name (void) interrupt vector using regnum
  194. #define INTERRUPT(vector) interrupt vector
  195. #define INTERRUPT_USING(vector, regnum) interrupt vector using regnum
  196. #include <intrins.h> // _nop_()
  197. extern void _nop_(void);
  198. #define __NOP_ATY _nop_()
  199. #define __WEAK_ATY
  200. #elif defined(__ICCARM__) || defined(__CC_ARM)
  201. // #include <stdint.h>
  202. #define __BIT bit
  203. #define __DATA
  204. #define __IDATA
  205. #define __PDATA
  206. #define __XDATA
  207. #define __CODE
  208. #define __NOP_ATY __nop()
  209. #if defined (__ICCARM__)
  210. #define __WEAK_ATY __WEAK __ATTRIBUTES
  211. #elif defined(__CC_ARM)
  212. #define __WEAK_ATY __weak
  213. #endif
  214. #else
  215. #warning Unsupported compiler!
  216. #endif /* PLATFORM */
  217. /******************************* For user *************************************/
  218. // #define DBG_ATY(DBG_CODE, code)
  219. // do{
  220. // #ifdef DBG_CODE
  221. // code
  222. // #endif
  223. // }while(0)
  224. #include "main.h"
  225. // #if defined (__HC32_ATY) || \
  226. // defined(__STM32_SPL_ATY) || \
  227. // defined(__STM32_HAL_ATY) || \
  228. // defined(__STM32_LL_ATY)
  229. // // shield warnings
  230. // #pragma diag_suppress 550 // variable "" was set but never used
  231. // #pragma diag_suppress 177 // function "" was declared but never referenced
  232. // #pragma diag_suppress 186 // pointless comparison of unsigned integer with zero
  233. // #pragma diag_suppress 1035 // single-precision operand implicitly converted to double-precision
  234. // // #pragma diag_suppress 223
  235. // #endif
  236. // #ifdef __STC51_ATY
  237. // #define BIG_ENDIAN // chip in big endian mode, like 51
  238. // #endif
  239. // #if defined (__STC51_ATY)
  240. // #define LOG_ATY(__STRING) UartSendStr(__STRING)
  241. // #elif defined(__HC32_ATY) || \
  242. // defined(__STM32_SPL_ATY) || \
  243. // defined(__STM32_HAL_ATY) || \
  244. // defined(__STM32_LL_ATY)
  245. // #include "HW_UART_ATY.h"
  246. // #include "stdarg.h"
  247. // #define LOG_ATY(__STRING) printf(__STRING) // C99
  248. // #define LOG_ATY__(__STRING, ...) printf(__STRING,##__VA_ARGS__) // C99
  249. // #else
  250. // #define LOG_ATY(__STRING)
  251. // #endif
  252. // #if !defined(__PRINTF_ATY) && !defined(__stdio_h) && !defined(__STM32_HAL_ATY)
  253. // #include "stdarg.h"
  254. // __WEAK_ATY void printf(uint8_t*, ...);
  255. // #endif /* __PRINTF_ATY */
  256. /*
  257. // todo, not tested and need to be adjust
  258. // #include <stdio.h> // printf(only for debug)
  259. #if defined (__HC32_ATY) || \
  260. defined(__STM32_SPL_ATY) || \
  261. defined(__STM32_HAL_ATY) || \
  262. defined(__STM32_LL_ATY)
  263. #include "STM32_HAL_PRINTF_ATY.h"
  264. #include "stdarg.h"
  265. #define LOG_ATY(__STRING, ...) printf(__STRING,##__VA_ARGS__) // C99
  266. #else
  267. #include "HW_UART_ATY.h"
  268. #include "stdarg.h"
  269. #define LOG_ATY(...) UartSendStr(__VA_ARGS__)
  270. #endif
  271. */
  272. // Define device symbol to main header
  273. // #define __STC51_ATY
  274. // #define __STC8G_ATY
  275. // #define __STC8H_ATY
  276. // #define __HC32_ATY
  277. // #define __STM32_SPL_ATY
  278. // #define __STM32_LL_ATY
  279. // #define __STM32_HAL_ATY
  280. // #define __ESP8266_RTOS_ATY
  281. // #define __ESP32_IDF_ATY
  282. // #define __TIMER_CYCLE_ATY
  283. // #define TIMERC_N htim4
  284. // #define TIMERC_N 0
  285. // #define __I2C_HARDWARE_ATY
  286. // #define I2CH_N hi2c1
  287. // #define I2CH_N 0
  288. // #define I2CH_N I2C_NUM_0
  289. // #define __SPI_HARDWARE_ATY
  290. // #define SPIH_N hspi2
  291. // #define SPIH_N 0
  292. // #define __PWM_HARDWARE_ATY
  293. // #define PWMH_N htim1
  294. // #define PWMH_N TIM1
  295. // #define PWMH_N 1
  296. // #define DEBUG_PRINTF_RECEIVE
  297. // #define PRINTF_UART huart3
  298. // #define PRINTF_DMA hdma_usart3_rx
  299. // extern DMA_HandleTypeDef PRINTF_DMA;
  300. /******************************************************************************/
  301. #define _ATY_IO_O 0
  302. #define _ATY_IO_I 1
  303. #define _ATY_HL_L 0
  304. #define _ATY_HL_H 1
  305. #define _ATY_RW_W 0
  306. #define _ATY_RW_R 1
  307. #define _ATY_RW_RW 2
  308. #define _ATY_BUSY 99
  309. #define _ATY_LOCKED 101
  310. #define _ATY_UNLOCKED 102
  311. #if (USE_RTOS == 1U)
  312. #define __ATY_LOCK(__HANDLE__)
  313. #define __ATY_UNLOCK(__HANDLE__)
  314. #else
  315. #define __ATY_LOCK(__HANDLE__) \
  316. do{ \
  317. if((__HANDLE__)->lock == _ATY_LOCKED) { \
  318. return _ATY_BUSY; \
  319. } \
  320. else { \
  321. (__HANDLE__)->lock = _ATY_LOCKED; \
  322. } \
  323. }while (0U)
  324. #define __ATY_UNLOCK(__HANDLE__) \
  325. do{ \
  326. (__HANDLE__)->lock = _ATY_UNLOCKED; \
  327. }while (0U)
  328. #endif /* USE_RTOS */
  329. #endif /* __INCLUDE_ATY_H */
  330. /************************************ etc *************************************/
  331. /* init */
  332. /* use */
  333. /******************************************************************************/
  334. /******************************** End Of File *********************************/