123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- #ifndef _DEF_H_
- #define _DEF_H_
- #include <stdint.h>
- #include "yc11xx.h"
- #define SDK_VERSION 0L
- #define SDK_SUBVERSION 0L
- #define SDK_REVISION 1L
- struct list_node
- {
- struct list_node *next;
- struct list_node *prev;
- };
- typedef struct list_node list_t;
- #define typeof(x) uint32_t;
- struct mempool
- {
- void *start_address;
- uint16_t size;
- uint16_t block_size;
- uint8_t* block_list;
- uint8_t block_total_count;
- uint8_t block_free_count;
-
- };
- typedef struct mempool *mp_t;
- typedef uint32_t return_code;
- #ifdef __CC_ARM
- #include <stdarg.h>
- #define SECTION(x) __attribute__((section(x)))
- #define YC_UNUSED __attribute__((unused))
- #define YC_USED __attribute__((used))
- #define ALIGN(n) __attribute__((aligned(n)))
- #define WEAK __weak
- #elif defined (__IAR_SYSTEMS_ICC__)
- #include <stdarg.h>
- #define SECTION(x) @ x
- #define YC_UNUSED
- #define YC_USED
- #define PRAGMA(x) _Pragma(#x)
- #define ALIGN(n) PRAGMA(data_alignment=n)
- #define WEAK __weak
- #elif defined (__GNUC__)
- #define SECTION(x) __attribute__((section(x)))
- #define YC_UNUSED __attribute__((unused))
- #define YC_USED __attribute__((used))
- #define ALIGN(n) __attribute__((aligned(n)))
- #define WEAK __attribute__((weak))
- #else
- #error not supported tool chain
- #endif
- #define HW_REG_8BIT(reg, value) (*((volatile uint8_t *)((uint32_t)reg)) = value)
- #define HR_REG_8BIT(reg) (*(volatile uint8_t *)((uint32_t)reg))
- #define H_SETBIT(reg, value) HW_REG_8BIT(reg,( (HR_REG_8BIT(reg)) | (value)))
- #define H_CLRBIT(reg, value) HW_REG_8BIT(reg, (HR_REG_8BIT(reg) & (~(value))))
- #define H_READBIT(reg, value) ((HR_REG_8BIT(reg)) & (value))
- #define H_BIT(x) (1 << (x))
- typedef enum
- {
- ERROR=0,
- SUCCESS=1,
- ERR_DEVICE_CLOSED=2,
- ERR_ILLEGAL_PARAM=3,
- }error_t;
- void _delay_ms(uint16_t ms);
- void _assert_handler(const char* file, int line,const char* func);
- #define _ASSERT(x) \
- if (!(x)) \
- { \
- _assert_handler(__FILE__,__LINE__,__FUNCTION__);\
- }
- #define _ASSERT_FAULT() \
- { \
- OS_ENTER_CRITICAL();\
- _assert_handler(__FILE__,__LINE__,__FUNCTION__);\
- }
- #define _ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
- #define _ALIGN_UP(size, align) ((size + 4) & ~((align) - 1))
- enum device_id
- {
- Device_Id_UartA = 0,
- Device_Id_UartB,
- Device_Id_Spi,
- Device_Id_I2c,
- Device_Id_Pwm,
- Device_Id_Keyscan
- };
- typedef struct device *device_t;
- #define MAX_DEV_NAME_SIZE 20
- struct device
- {
- enum device_id id;
-
- list_t list;
-
- error_t (*reinit)(void);
- error_t (*enterlpm)(void);
- };
- typedef error_t (*tReinit)(void);
- typedef error_t (*tEnterlpm)(void);
- #define RB_UPDATE_PTR(p,s,e) ((p) == (e))?((p)=(s)):((p)++)
- #define STREAM_TO_UINT8(u8, p) {u8 = (uint8_t)(*(p)); (p) += 1;}
- #define STREAM_TO_UINT16(u16, p) {u16 = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); (p) += 2;}
- #define STREAM_TO_UINT24(u32, p) {u32 = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + ((((uint32_t)(*((p) + 2)))) << 16) ); (p) += 3;}
- #define STREAM_TO_UINT32(u32, p) {u32 = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + ((((uint32_t)(*((p) + 2)))) << 16) + ((((uint32_t)(*((p) + 3)))) << 24)); (p) += 4;}
- #define BE_STREAM_TO_UINT8(u8, p) {u8 = (uint8_t)(*(p)); (p) += 1;}
- #define BE_STREAM_TO_UINT16(u16, p) {u16 = (uint16_t)(((uint16_t)(*(p)) << 8) + (uint16_t)(*((p) + 1))); (p) += 2;}
- #define BE_STREAM_TO_UINT24(u32, p) {u32 = (((uint32_t)(*((p) + 2))) + ((uint32_t)(*((p) + 1)) << 8) + ((uint32_t)(*(p)) << 16)); (p) += 3;}
- #define BE_STREAM_TO_UINT32(u32, p) {u32 = ((uint32_t)(*((p) + 3)) + ((uint32_t)(*((p) + 2)) << 8) + ((uint32_t)(*((p) + 1)) << 16) + ((uint32_t)(*(p)) << 24)); (p) += 4;}
- #endif
-
|