| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666 |
- /**
- * @file INCLUDE_ATY.h
- *
- * @param Project DEVICE_GENERAL_ATY_LIB
- *
- * @author ATY
- *
- * @copyright
- * - Copyright 2017 - 2026 MZ-ATY
- * - This code follows:
- * - MZ-ATY Various Contents Joint Statement -
- * <a href="https://mengze.top/MZ-ATY_VCJS">
- * https://mengze.top/MZ-ATY_VCJS</a>
- * - CC 4.0 BY-NC-SA -
- * <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
- * https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
- * - Your use will be deemed to have accepted the terms of this statement.
- *
- * @brief Headers include or defines for C platform
- *
- * @version
- * - D+: Design, T+: Test, A+: Archive
- * - 1_01_220605 > ATY
- * -# Preliminary version, first Release
- * - 1_02_251114 > ATY
- * -# refact and reorganize
- * @todo Not support 64 platfrom, do or never(and double)
- ********************************************************************************
- */
- // fromelf.exe --bin -o ./Pro/Pro.bin ./Pro/Pro.axf
- /* Keyword *********************************************************************
- | ANSI C (A) | ANSI C (B) | C99 | C11 | C51(C89) |
- |------------|------------|------------|-----------------|------------|
- | auto | break | inline | _Alignas | _at_ |
- | case | char | restrict | _Alignof | bdata |
- | const | continue | _Bool | _Atomic | bit |
- | default | do | _Complex | _Static_assert | code |
- | double | else | _Imaginary | _Noreturn | data |
- | enum | extern | | _Thread_local | idata |
- | float | for | | _Generic | xdata |
- | goto | if | | | pdata |
- | int | long | | | sbit |
- | register | return | | | sfr |
- | short | signed | | | sfr16 |
- | sizeof | static | | | interrupt |
- | struct | switch | | | using |
- | typedef | union | | | reentrant |
- | unsigned | void | | | |
- | volatile | while | | | |
- ********************************************************************************
- Removed keywords (C51 or compiler-model terms):
- - alien, compact, large, small, _priority_, _task_
- */
- #ifndef __INCLUDE_ATY_H
- #define __INCLUDE_ATY_H
- /******************************* Platform *************************************/
- /********************************* Words **************************************/
- #if defined (__SDCC_SYNTAX_FIX)
- # warning SDCC unrecognized compiler
- #define __BIT
- #define __DATA
- #define __IDATA
- #define __PDATA
- #define __XDATA
- #define __CODE
- #define __REENTRANT
- #define __ATY_NOP
- #define __ATY_WEAK
- #elif defined(SDCC) || defined(__SDCC)
- #define __BIT __bit
- #define __DATA __data
- #define __IDATA __idata
- #define __PDATA __pdata
- #define __XDATA __xdata
- #define __CODE __code
- #define __REENTRANT __reentrant
- #define __ATY_NOP __asm NOP __endasm
- #define __ATY_WEAK
- #elif defined(__CX51__) || defined(__C51__)
- #define __BIT bit
- #define __DATA data
- #define __IDATA idata
- #define __PDATA pdata
- #define __XDATA xdata
- #define __CODE code
- #define __REENTRANT reentrant
- #include <intrins.h> // _nop_()
- extern void _nop_(void);
- #define __ATY_NOP _nop_()
- #define __ATY_WEAK
- #elif defined(__ICCARM__)
- #define __BIT bit
- #define __DATA
- #define __IDATA
- #define __PDATA
- #define __XDATA
- #define __REENTRANT
- #define __CODE
- #define __ATY_NOP __nop()
- #define __ATY_WEAK __WEAK __ATTRIBUTES
- #elif defined(__CC_ARM) || defined(__ARMCC_VERSION) || defined(__ARMCOMPILER_VERSION)
- #define __BIT bit
- #define __DATA
- #define __IDATA
- #define __PDATA
- #define __XDATA
- #define __REENTRANT
- #define __CODE
- #define __ATY_NOP __nop()
- #define __ATY_WEAK __weak
- #else
- #warning Unsupported compiler!
- #endif /* Words */
- /******************************* Compiler *************************************/
- #if defined(_MSC_VER)
- #warning __ATY_COMPILER_MSVC 1
- #define __ATY_COMPILER_MSVC 1
- #else
- #define __ATY_COMPILER_MSVC 0
- #endif
- #if defined(__clang__)
- #warning __ATY_COMPILER_CLANG 1
- #define __ATY_COMPILER_CLANG 1
- #else
- #define __ATY_COMPILER_CLANG 0
- #endif
- #if defined(__GNUC__) && !defined(__clang__)
- // ESP-IDF,
- #warning __ATY_COMPILER_GCC 1
- #define __ATY_COMPILER_GCC 1
- #else
- #define __ATY_COMPILER_GCC 0
- #endif
- #if defined(__ICCARM__)
- // IAR, STM8,
- #warning __ATY_COMPILER_IAR 1
- #define __ATY_COMPILER_IAR 1
- #else
- #define __ATY_COMPILER_IAR 0
- #endif
- #if defined(__CC_ARM) || defined(__ARMCC_VERSION) || defined(__ARMCOMPILER_VERSION)
- // Keil MDK ARM, like STM32\GD32\ HX32...,
- #pragma diag_suppress 1215 // user #warning
- #warning __ATY_COMPILER_ARMCC 1
- #define __ATY_COMPILER_ARMCC 1
- #else
- #define __ATY_COMPILER_ARMCC 0
- #endif
- #if defined(SDCC) || defined(__SDCC)
- // 51,
- #warning __ATY_COMPILER_SDCC 1
- #define __ATY_COMPILER_SDCC 1
- #else
- #define __ATY_COMPILER_SDCC 0
- #endif
- #if defined(__C51__) || defined(__CX51__)
- // 51,
- #warning __ATY_COMPILER_KEIL_C51 1
- #define __ATY_COMPILER_KEIL_C51 1
- #else
- #define __ATY_COMPILER_KEIL_C51 0
- #endif
- #if __ATY_COMPILER_SDCC || __ATY_COMPILER_KEIL_C51
- #warning __ATY_IS_8051_COMPILER 1
- #define __ATY_IS_8051_COMPILER 1
- #else
- #define __ATY_IS_8051_COMPILER 0
- #endif
- #if __ATY_IS_8051_COMPILER
- #define __ATY_HAS_64BIT 0
- #else
- #define __ATY_HAS_64BIT 1
- #endif
- // USE_HAL_DRIVER
- // USE_FULL_LL_DRIVER
- // USE_STDPERIPH_DRIVER
- /******************************** Endian **************************************/
- #if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
- #if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
- #define __ATY_ENDIAN_LE 1
- #define __ATY_ENDIAN_BE 0
- #elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
- #define __ATY_ENDIAN_LE 0
- #define __ATY_ENDIAN_BE 1
- #else
- #define __ATY_ENDIAN_LE 1
- #define __ATY_ENDIAN_BE 0
- #endif
- #elif defined(__ARMEL__)
- #define __ATY_ENDIAN_LE 1
- #define __ATY_ENDIAN_BE 0
- #elif defined(__ARMEB__)
- #define __ATY_ENDIAN_LE 0
- #define __ATY_ENDIAN_BE 1
- #elif __ATY_IS_8051_COMPILER
- #define __ATY_ENDIAN_LE 0
- #define __ATY_ENDIAN_BE 1
- #elif defined(_WIN32) || defined(_WIN64)
- #define __ATY_ENDIAN_LE 1
- #define __ATY_ENDIAN_BE 0
- #else
- #define __ATY_ENDIAN_LE 1
- #define __ATY_ENDIAN_BE 0
- #endif
- #define __ATY_BSWAP16(x) (uint16_t)( \
- (((uint16_t)(x) & 0x00FFu) << 8) | \
- (((uint16_t)(x) & 0xFF00u) >> 8))
- #define __ATY_BSWAP32(x) (uint32_t)(( \
- ((uint32_t)(x) & 0x000000FFu) << 24) | \
- (((uint32_t)(x) & 0x0000FF00u) << 8) | \
- (((uint32_t)(x) & 0x00FF0000u) >> 8) | \
- (((uint32_t)(x) & 0xFF000000u) >> 24))
- #if __ATY_HAS_64BIT
- #define __ATY_BSWAP64(x) (uint64_t)( \
- ((((uint64_t)(x)) & 0x00000000000000FFULL) << 56) | \
- ((((uint64_t)(x)) & 0x000000000000FF00ULL) << 40) | \
- ((((uint64_t)(x)) & 0x0000000000FF0000ULL) << 24) | \
- ((((uint64_t)(x)) & 0x00000000FF000000ULL) << 8 ) | \
- ((((uint64_t)(x)) & 0x000000FF00000000ULL) >> 8 ) | \
- ((((uint64_t)(x)) & 0x0000FF0000000000ULL) >> 24) | \
- ((((uint64_t)(x)) & 0x00FF000000000000ULL) >> 40) | \
- ((((uint64_t)(x)) & 0xFF00000000000000ULL) >> 56))
- #endif
- #if __ATY_ENDIAN_LE
- #define __ATY_HTOLE16(x) (uint16_t)(x)
- #define __ATY_LETOH16(x) (uint16_t)(x)
- #define __ATY_HTOBE16(x) __ATY_BSWAP16(x)
- #define __ATY_BETOH16(x) __ATY_BSWAP16(x)
- #define __ATY_HTOLE32(x) (uint32_t)(x)
- #define __ATY_LETOH32(x) (uint32_t)(x)
- #define __ATY_HTOBE32(x) __ATY_BSWAP32(x)
- #define __ATY_BETOH32(x) __ATY_BSWAP32(x)
- #if __ATY_HAS_64BIT
- #define __ATY_HTOLE64(x) (uint64_t)(x)
- #define __ATY_LETOH64(x) (uint64_t)(x)
- #define __ATY_HTOBE64(x) __ATY_BSWAP64(x)
- #define __ATY_BETOH64(x) __ATY_BSWAP64(x)
- #endif
- #else
- #define __ATY_HTOLE16(x) __ATY_BSWAP16(x)
- #define __ATY_LETOH16(x) __ATY_BSWAP16(x)
- #define __ATY_HTOBE16(x) (uint16_t)(x)
- #define __ATY_BETOH16(x) (uint16_t)(x)
- #define __ATY_HTOLE32(x) __ATY_BSWAP32(x)
- #define __ATY_LETOH32(x) __ATY_BSWAP32(x)
- #define __ATY_HTOBE32(x) (uint32_t)(x)
- #define __ATY_BETOH32(x) (uint32_t)(x)
- #if __ATY_HAS_64BIT
- #define __ATY_HTOLE64(x) __ATY_BSWAP64(x)
- #define __ATY_LETOH64(x) __ATY_BSWAP64(x)
- #define __ATY_HTOBE64(x) (uint64_t)(x)
- #define __ATY_BETOH64(x) (uint64_t)(x)
- #endif
- #endif
- /******************************* Data Type ************************************/
- // #define __UNUSED(x) ((void)(x))
- #define __UNUSED(x) (x = x) // not suit for const, used for function formal parameter uaually
- #ifndef __stdint_h
- #define __stdint_h
- #ifndef bool
- #define bool uint8_t
- #endif /* bool */
- #ifndef true
- #define true 1
- #endif /* true */
- #ifndef false
- #define false 0
- #endif /* false */
- #ifndef bit
- #define bit uint8_t
- #endif /* bit */
- #ifndef _UINT8_T
- #define _UINT8_T
- typedef unsigned char uint8_t;
- #endif /* _UINT8_T */
- #ifndef _UINT16_T
- #define _UINT16_T
- typedef unsigned short int uint16_t;
- #endif /* _UINT16_T */
- #ifndef _UINT32_T
- #define _UINT32_T
- typedef unsigned long uint32_t;
- #endif /* _UINT32_T */
- #ifndef _UINT64_T
- #define _UINT64_T
- #if __ATY_HAS_64BIT
- typedef unsigned long long int uint64_t;
- #else
- typedef unsigned long int uint64_t; // 64 = 32, not 64 bit platform
- #endif /* uint64_t */
- #endif /* _UINT64_T */
- #ifndef _INT8_T
- #define _INT8_T
- typedef signed char int8_t;
- #endif /* _INT8_T */
- #ifndef _INT16_T
- #define _INT16_T
- typedef signed short int int16_t;
- #endif /* _INT16_T */
- #ifndef _INT32_T
- #define _INT32_T
- typedef signed int int32_t;
- #endif /* _INT32_T */
- #ifndef _INT64_T
- #define _INT64_T
- #if __ATY_HAS_64BIT
- typedef signed long long int int64_t;
- #else
- typedef signed long int int64_t; // 64 = 32, not 64 bit platform
- #endif /* int64_t */
- #endif /* _INT64_T */
- #endif /* __stdint_h */
- /********************************** ATY ***************************************/
- #define __ATY_IO_I 0
- #define __ATY_IO_O 1
- #define __ATY_HL_L 0
- #define __ATY_HL_H 1
- #define __ATY_RW_W 0
- #define __ATY_RW_R 1
- #define __ATY_RW_RW 2
- #define __ATY_BUSY 99
- #define __ATY_LOCKED 101
- #define __ATY_UNLOCKED 102
- #if (USE_RTOS == 1U)
- #define __ATY_LOCK(__HANDLE__)
- #define __ATY_UNLOCK(__HANDLE__)
- #else
- #define __ATY_LOCK(__HANDLE__) \
- do{ \
- if((__HANDLE__)->lock == __ATY_LOCKED) { \
- return __ATY_BUSY; \
- } \
- else { \
- (__HANDLE__)->lock = __ATY_LOCKED; \
- } \
- }while (0U)
- #define __ATY_UNLOCK(__HANDLE__) \
- do{ \
- (__HANDLE__)->lock = __ATY_UNLOCKED; \
- }while (0U)
- #endif /* USE_RTOS */
- /******************************* For user *************************************/
- #include "main.h"
- /* Diagnostic Suppress (hide warnings) *****************************************
- | Platform | Assigned but not used |
- |-----------------|------------------------------------------------------------|
- | ArmCC5(KeilARM) | #pragma diag_suppress 550 |
- | IAR (ICCARM) | #pragma diag_suppress=Pe550 |
- | GCC | #pragma GCC diagnostic ignored "-Wunused-but-set-variable" |
- | Clang/ArmClang | #pragma clang diagnostic ignored "-Wunused..." |
- | MSVC | #pragma warning(disable: 4189) |
- | Keil C51 | Not supported unified pragma diag |
- | SDCC (8051) | Not supported unified pragma diag |
- *******************************************************************************/
- #if defined (__ATY_COMPILER_ARMCC)
- #pragma diag_suppress 1215 // user #warning (before #warning)
- #pragma diag_suppress 550 // variable "" was set but never used
- #pragma diag_suppress 177 // function "" was declared but never referenced
- #pragma diag_suppress 186 // pointless comparison of unsigned integer with zero
- #pragma diag_suppress 1035 // single-precision operand implicitly converted to double-precision
- // #pragma diag_suppress 223 // function "xxx" declared implicitly
- #endif
- // stdarg ----------------------------------------------------------------------
- #define __ATY_USE_STDARG_LIB
- #ifdef __ATY_USE_STDARG_LIB
- #include <stdarg.h>
- #else
- #ifndef __stdarg_h
- #define __stdarg_h
- #if __ATY_COMPILER_CLANG || __ATY_COMPILER_GCC
- typedef __builtin_va_list va_list;
- #define va_start(ap, param) __builtin_va_start(ap, param)
- #define va_end(ap) __builtin_va_end(ap)
- #define va_arg(ap, type) __builtin_va_arg(ap, type)
- #define va_copy(dest, src) __builtin_va_copy(dest, src)
- #elif __ATY_COMPILER_ARMCC
- typedef struct __va_list{ void* __ap; } va_list;
- #define va_start(ap, parmN) __va_start(ap, parmN)
- #define va_arg(ap, type) __va_arg(ap, type)
- #define va_end(ap) __va_end(ap)
- #define va_copy(dest, src) ((void)((dest) = (src)))
- #elif __ATY_COMPILER_IAR
- typedef char* va_list;
- #define __ATY_VA_ALIGN (sizeof(int))
- #define va_start(ap, last) ((ap) = (char*)&(last) + ((sizeof(last)+__ATY_VA_ALIGN-1)&~(__ATY_VA_ALIGN-1)))
- #define va_arg(ap, type) (*(type*)((ap += ((sizeof(type)+__ATY_VA_ALIGN-1)&~(__ATY_VA_ALIGN-1))) - ((sizeof(type)+__ATY_VA_ALIGN-1)&~(__ATY_VA_ALIGN-1))))
- #define va_end(ap) ((ap) = (va_list)0)
- #define va_copy(dest, src) ((dest) = (src))
- #elif __ATY_IS_8051_COMPILER
- typedef unsigned char* va_list;
- #define va_start(ap, last) ((ap) = (unsigned char*)&(last) + sizeof(last))
- #define va_arg(ap, type) (*(type*)((ap += sizeof(type)) - sizeof(type)))
- #define va_end(ap) ((ap) = (va_list)0)
- #define va_copy(dest, src) ((dest) = (src))
- #elif __ATY_COMPILER_MSVC
- typedef char* va_list;
- #define __ATY_VA_ALIGN (sizeof(int))
- #define va_start(ap, last) ((ap) = (char*)&(last) + ((sizeof(last)+__ATY_VA_ALIGN-1)&~(__ATY_VA_ALIGN-1)))
- #define va_arg(ap, type) (*(type*)((ap += ((sizeof(type)+__ATY_VA_ALIGN-1)&~(__ATY_VA_ALIGN-1))) - ((sizeof(type)+__ATY_VA_ALIGN-1)&~(__ATY_VA_ALIGN-1))))
- #define va_end(ap) ((ap) = (va_list)0)
- #define va_copy(dest, src) ((dest) = (src))
- #else
- typedef char* va_list;
- #define __ATY_VA_ALIGN (sizeof(int))
- #define va_start(ap, last) ((ap) = (char*)&(last) + ((sizeof(last)+__ATY_VA_ALIGN-1)&~(__ATY_VA_ALIGN-1)))
- #define va_arg(ap, type) (*(type*)((ap += ((sizeof(type)+__ATY_VA_ALIGN-1)&~(__ATY_VA_ALIGN-1))) - ((sizeof(type)+__ATY_VA_ALIGN-1)&~(__ATY_VA_ALIGN-1))))
- #define va_end(ap) ((ap) = (va_list)0)
- #define va_copy(dest, src) ((dest) = (src))
- #endif
- #endif /* __stdarg_h */
- #endif /* __ATY_USE_STDARG_LIB */
- #define __ATY_PRINT_ENABLE 1
- #define __ATY_DEBUG_ENABLE 1
- #if __ATY_PRINT_ENABLE
- #include "HW_UART_ATY.h"
- extern struct HW_UART_ATY_Dev HW_UART_ATY_Dev_1;
- #define printf_ATY(...) UartPrintf(&HW_UART_ATY_Dev_1, __VA_ARGS__)
- #if __ATY_DEBUG_ENABLE
- #define printf_ATY_D(...) UartPrintf(&HW_UART_ATY_Dev_1, __VA_ARGS__)
- #else
- #define printf_ATY_D(...)
- #endif
- #else
- #define printf_ATY(...)
- #define printf_ATY_D(...)
- #endif
- // Soft Reset ------------------------------------------------------------------
- #ifndef __ATY_SOFT_RESET
- #if __ATY_IS_8051_COMPILER
- #if __ATY_COMPILER_SDCC
- #define __ATY_SOFT_RESET() \
- do { \
- IAP_CONTR |= 0x60; \
- void (* __code __aty_reset)(void) = (void (__code *)(void))0x0000; \
- __aty_reset(); \
- } while (0U)
- #elif __ATY_COMPILER_KEIL_C51
- #define __ATY_SOFT_RESET() \
- do { \
- IAP_CONTR |= 0x60; \
- void (* __aty_reset)(void) = (void (*)(void))0x0000; \
- __aty_reset(); \
- } while (0U)
- #else
- #define __ATY_SOFT_RESET() do { } while (0U)
- #endif
- #elif __ATY_COMPILER_ARMCC || __ATY_COMPILER_IAR || __ATY_COMPILER_GCC || __ATY_COMPILER_CLANG
- #define __ATY_SOFT_RESET() \
- do { \
- __disable_irq(); \
- __NVIC_SystemReset(); \
- } while (0U)
- #elif __ATY_COMPILER_MSVC
- #include <stdlib.h>
- #define __ATY_SOFT_RESET() \
- do { \
- abort(); \
- } while (0U)
- #else
- #define __ATY_SOFT_RESET() do { } while (0U)
- #endif
- #endif
- // DBG IO ----------------------------------------------------------------------
- // todo: move to HW_GPIO
- #define __ATY_DBG_DH 64u
- #define __ATY_DBG_DL 64u
- // #if defined(USE_HAL_DRIVER) && defined(ATY_DBG_GPIO_Port) && defined(ATY_DBG_GPIO_Pin)
- // #define __ATY_DEBUG_GPIO_WRITE(v) HAL_GPIO_WritePin(ATY_DBG_GPIO_Port, ATY_DBG_GPIO_Pin, ((v)?GPIO_PIN_SET:GPIO_PIN_RESET))
- // #define __ATY_DEBUG_GPIO_READ() (HAL_GPIO_ReadPin(ATY_DBG_GPIO_Port, ATY_DBG_GPIO_Pin)?1:0)
- // #elif __ATY_IS_8051_COMPILER && defined(ATY_DBG_BIT)
- // #define __ATY_DEBUG_GPIO_WRITE(v) do{ ATY_DBG_BIT = ((v)?1:0); }while(0)
- // #define __ATY_DEBUG_GPIO_READ() ((ATY_DBG_BIT)?1:0)
- // #elif defined(__ESP32_IDF_ATY) && defined(ATY_DBG_GPIO_NUM)
- // #define __ATY_DEBUG_GPIO_WRITE(v) gpio_set_level((gpio_num_t)(ATY_DBG_GPIO_NUM), ((v)?1:0))
- // #define __ATY_DEBUG_GPIO_READ() ((int)gpio_get_level((gpio_num_t)(ATY_DBG_GPIO_NUM)))
- // #endif
- #ifndef __ATY_DEBUG_GPIO_WRITE
- #define __ATY_DEBUG_GPIO_WRITE(v) do{ (void)(v); }while(0)
- #endif
- #ifndef __ATY_DEBUG_GPIO_READ
- #define __ATY_DEBUG_GPIO_READ() (0)
- #endif
- #define __ATY_DELAY_LOOP(n) \
- do { \
- volatile uint32_t __aty_d = (uint32_t)(n); \
- while (__aty_d--) { \
- __NOP_ATY; \
- } \
- } while (0U)
- #define __ATY_DBG_WAIT_RISING(timeout, okflag) \
- do { \
- uint32_t __aty_to = (uint32_t)(timeout); \
- (okflag) = 0; \
- while ((__ATY_DEBUG_GPIO_READ() == 0) && (__aty_to--)) { \
- __NOP_ATY; \
- } \
- if (__ATY_DEBUG_GPIO_READ() != 0) { \
- (okflag) = 1; \
- } \
- } while (0U)
- #define __ATY_DBG_WAIT_FALLING(timeout, okflag) \
- do { \
- uint32_t __aty_to = (uint32_t)(timeout); \
- (okflag) = 0; \
- while ((__ATY_DEBUG_GPIO_READ() != 0) && (__aty_to--)) { \
- __NOP_ATY; \
- } \
- if (__ATY_DEBUG_GPIO_READ() == 0) { \
- (okflag) = 1; \
- } \
- } while (0U)
- #define __ATY_DBG_MEASURE_HIGH(maxcount, count_out) \
- do { \
- uint32_t __aty_cnt = 0u; \
- while ((__ATY_DEBUG_GPIO_READ() != 0) && (__aty_cnt < (uint32_t)(maxcount))) { \
- __aty_cnt++; \
- __NOP_ATY; \
- } \
- (count_out) = __aty_cnt; \
- } while (0U)
- #define __ATY_DBG_RECV8(dst) \
- do { \
- uint8_t __aty_v = 0u; \
- for (uint8_t __aty_i = 0u; __aty_i < 8u; ++__aty_i) { \
- uint8_t __aty_ok = 0u; \
- __ATY_DBG_WAIT_RISING((__ATY_DBG_DH * 8u + __ATY_DBG_DL * 8u), __aty_ok); \
- if (!__aty_ok) { \
- break; \
- } \
- uint32_t __aty_len = 0u; \
- __ATY_DBG_MEASURE_HIGH((__ATY_DBG_DH * 3u), __aty_len); \
- if (__aty_len <= (__ATY_DBG_DH + (__ATY_DBG_DH / 2u))) { \
- __aty_v |= (uint8_t)(1u << __aty_i); \
- } \
- __ATY_DBG_WAIT_FALLING((__ATY_DBG_DL * 8u), __aty_ok); \
- __ATY_DELAY_LOOP(__ATY_DBG_DL); \
- } \
- (dst) = __aty_v; \
- __ATY_DELAY_LOOP(__ATY_DBG_DH * 4u); \
- } while (0U)
- #define __ATY_DBG_PULSE(hi, lo) \
- do { \
- __ATY_DEBUG_GPIO_WRITE(1); \
- __ATY_DELAY_LOOP((hi)); \
- __ATY_DEBUG_GPIO_WRITE(0); \
- __ATY_DELAY_LOOP((lo)); \
- } while (0U)
- #define __ATY_DBG_MARK(cnt, hi, lo) \
- do { \
- uint32_t __aty_c = (uint32_t)(cnt); \
- while (__aty_c--) { \
- __ATY_DBG_PULSE((hi), (lo)); \
- } \
- __ATY_DELAY_LOOP((hi) * 4u); \
- } while (0U)
- #define __ATY_DBG_SEND8(v) \
- do { \
- uint8_t __aty_b = (uint8_t)(v); \
- for (uint8_t __aty_i = 0u; __aty_i < 8u; ++__aty_i) { \
- if (((__aty_b & 0x01u) != 0u)) { \
- __ATY_DEBUG_GPIO_WRITE(1); \
- __ATY_DELAY_LOOP(__ATY_DBG_DH); \
- __ATY_DEBUG_GPIO_WRITE(0); \
- __ATY_DELAY_LOOP(__ATY_DBG_DL); \
- } else { \
- __ATY_DEBUG_GPIO_WRITE(1); \
- __ATY_DELAY_LOOP(__ATY_DBG_DH * 2u); \
- __ATY_DEBUG_GPIO_WRITE(0); \
- __ATY_DELAY_LOOP(__ATY_DBG_DL); \
- } \
- __aty_b >>= 1; \
- } \
- __ATY_DELAY_LOOP(__ATY_DBG_DH * 4u); \
- } while (0U)
- #define __ATY_DBG_R(v) __ATY_DBG_RECV8(v)
- #define __ATY_DBG_W(v) __ATY_DBG_SEND8(v)
- // remember to define __ATY_DEBUG_GPIO_WRITE(v) and __ATY_DEBUG_GPIO_READ()
- // for example:
- // #define __ATY_DEBUG_GPIO_WRITE(v) HAL_GPIO_WritePin(ATY_DBG_GPIO_Port, ATY_DBG_GPIO_Pin, ((v)?GPIO_PIN_SET:GPIO_PIN_RESET))
- // #define __ATY_DEBUG_GPIO_READ() (HAL_GPIO_ReadPin(ATY_DBG_GPIO_Port, ATY_DBG_GPIO_Pin)?1:0)
- /******************************************************************************/
- #endif /* __INCLUDE_ATY_H */
- /************************************ etc *************************************/
- /* init */
- /* use */
- /******************************************************************************/
- /******************************** End Of File *********************************/
|