ycdef.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright 2016, yichip Semiconductor(shenzhen office)
  3. * All Rights Reserved.
  4. *
  5. * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Yichip Semiconductor;
  6. * the contents of this file may not be disclosed to third parties, copied
  7. * or duplicated in any form, in whole or in part, without the prior
  8. * written permission of Yichip Semiconductor.
  9. */
  10. #ifndef _DEF_H_
  11. #define _DEF_H_
  12. #include <stdint.h>
  13. #include "yc11xx.h"
  14. /* SDK version information */
  15. #define SDK_VERSION 0L /**< major version number */
  16. #define SDK_SUBVERSION 0L /**< minor version number */
  17. #define SDK_REVISION 1L /**< revise version number */
  18. struct list_node
  19. {
  20. struct list_node *next; /**< point to next node. */
  21. struct list_node *prev; /**< point to prev node. */
  22. };
  23. typedef struct list_node list_t; /**< Type for lists. */
  24. #define typeof(x) uint32_t;
  25. /**
  26. * Base structure of Memory pool object
  27. */
  28. struct mempool
  29. {
  30. void *start_address; /**< memory pool start */
  31. uint16_t size; /**< size of memory pool */
  32. uint16_t block_size; /**< size of memory blocks */
  33. uint8_t* block_list; /**< memory blocks list */
  34. uint8_t block_total_count; /**< numbers of memory block */
  35. uint8_t block_free_count; /**< numbers of free memory block */
  36. };
  37. typedef struct mempool *mp_t;
  38. typedef uint32_t return_code;
  39. /* Compiler Related Definitions */
  40. #ifdef __CC_ARM /* ARM Compiler */
  41. #include <stdarg.h>
  42. #define SECTION(x) __attribute__((section(x)))
  43. #define YC_UNUSED __attribute__((unused))
  44. #define YC_USED __attribute__((used))
  45. #define ALIGN(n) __attribute__((aligned(n)))
  46. #define WEAK __weak
  47. #elif defined (__IAR_SYSTEMS_ICC__) /* for IAR Compiler */
  48. #include <stdarg.h>
  49. #define SECTION(x) @ x
  50. #define YC_UNUSED
  51. #define YC_USED
  52. #define PRAGMA(x) _Pragma(#x)
  53. #define ALIGN(n) PRAGMA(data_alignment=n)
  54. #define WEAK __weak
  55. #elif defined (__GNUC__) /* GNU GCC Compiler */
  56. #define SECTION(x) __attribute__((section(x)))
  57. #define YC_UNUSED __attribute__((unused))
  58. #define YC_USED __attribute__((used))
  59. #define ALIGN(n) __attribute__((aligned(n)))
  60. #define WEAK __attribute__((weak))
  61. #else
  62. #error not supported tool chain
  63. #endif
  64. #define HW_REG_8BIT(reg, value) (*((volatile uint8_t *)((uint32_t)reg)) = value)
  65. #define HR_REG_8BIT(reg) (*(volatile uint8_t *)((uint32_t)reg))
  66. #define H_SETBIT(reg, value) HW_REG_8BIT(reg,( (HR_REG_8BIT(reg)) | (value)))
  67. #define H_CLRBIT(reg, value) HW_REG_8BIT(reg, (HR_REG_8BIT(reg) & (~(value))))
  68. #define H_READBIT(reg, value) ((HR_REG_8BIT(reg)) & (value))
  69. #define H_BIT(x) (1 << (x))
  70. typedef enum
  71. {
  72. ERROR=0,
  73. SUCCESS=1,
  74. ERR_DEVICE_CLOSED=2,
  75. ERR_ILLEGAL_PARAM=3,
  76. }error_t;
  77. void _delay_ms(uint16_t ms);
  78. void _assert_handler(const char* file, int line,const char* func);
  79. #define _ASSERT(x) \
  80. if (!(x)) \
  81. { \
  82. _assert_handler(__FILE__,__LINE__,__FUNCTION__);\
  83. }
  84. #define _ASSERT_FAULT() \
  85. { \
  86. OS_ENTER_CRITICAL();\
  87. _assert_handler(__FILE__,__LINE__,__FUNCTION__);\
  88. }
  89. /**
  90. * @ingroup BasicDef
  91. *
  92. * @def _ALIGN_DOWN(size, align)
  93. * Return the down number of aligned at specified width. _ALIGN_DOWN(13, 4)
  94. * would return 12.
  95. */
  96. #define _ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
  97. /**
  98. * @ingroup BasicDef
  99. *
  100. * @def _ALIGN_UP(size, align)
  101. * Return the down number of aligned at specified width. _ALIGN_DOWN(13, 4)
  102. * would return 16.
  103. */
  104. #define _ALIGN_UP(size, align) ((size + 4) & ~((align) - 1))
  105. /**
  106. * device (I/O) Ids type
  107. */
  108. enum device_id
  109. {
  110. Device_Id_UartA = 0, /**< character device */
  111. Device_Id_UartB,
  112. Device_Id_Spi,
  113. Device_Id_I2c,
  114. Device_Id_Pwm,
  115. Device_Id_Keyscan
  116. };
  117. typedef struct device *device_t;
  118. #define MAX_DEV_NAME_SIZE 20
  119. /**
  120. * Device structure
  121. */
  122. struct device
  123. {
  124. enum device_id id;
  125. list_t list; /**< device list */
  126. /* common device interface */
  127. error_t (*reinit)(void);
  128. error_t (*enterlpm)(void);
  129. };
  130. typedef error_t (*tReinit)(void);
  131. typedef error_t (*tEnterlpm)(void);
  132. #define RB_UPDATE_PTR(p,s,e) ((p) == (e))?((p)=(s)):((p)++)
  133. /********************************************************************************
  134. ** Macros to get and put bytes to and from a stream (small Endian format)
  135. */
  136. #define STREAM_TO_UINT8(u8, p) {u8 = (uint8_t)(*(p)); (p) += 1;}
  137. #define STREAM_TO_UINT16(u16, p) {u16 = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); (p) += 2;}
  138. #define STREAM_TO_UINT24(u32, p) {u32 = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + ((((uint32_t)(*((p) + 2)))) << 16) ); (p) += 3;}
  139. #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;}
  140. /********************************************************************************
  141. ** Macros to get and put bytes to and from a stream (Big Endian format)
  142. */
  143. #define BE_STREAM_TO_UINT8(u8, p) {u8 = (uint8_t)(*(p)); (p) += 1;}
  144. #define BE_STREAM_TO_UINT16(u16, p) {u16 = (uint16_t)(((uint16_t)(*(p)) << 8) + (uint16_t)(*((p) + 1))); (p) += 2;}
  145. #define BE_STREAM_TO_UINT24(u32, p) {u32 = (((uint32_t)(*((p) + 2))) + ((uint32_t)(*((p) + 1)) << 8) + ((uint32_t)(*(p)) << 16)); (p) += 3;}
  146. #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;}
  147. #endif