ethan
2023-04-08 f5e277c240b9211a1f047b88788f34f3dd5a97c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
 * @file Ems_def.h
 * @author your name (you@domain.com)
 * @brief 
 * @version 0.1
 * @date 2023-04-05
 * 
 * @copyright Copyright (c) 2023
 * 
 */
 
#ifndef EMS_DEF_H
#define EMS_DEF_H
 
/* includes ----------------------------------------------------------------- */
#include <stdint.h>
#include "EMS_config.h"
 
#if (EMS_QPC_EN != 0)
#include "qpc.h"
#endif
 
#ifdef __cplusplus
extern "C" {
#endif
 
/* public typedef ----------------------------------------------------------- */
typedef enum EMS_err
{
    EMS_OK                             = 0,
    EMS_ERROR                          = -1,
    EMS_ERR_EMPTY                      = -2,
    EMS_ERR_FULL                       = -3,
    EMS_ERR_TIMEOUT                    = -4,
    EMS_ERR_BUSY                       = -5,
    EMS_ERR_NO_MEMORY                  = -6,
    EMS_ERR_IO                         = -7,
    EMS_ERR_INVALID                    = -8,
    EMS_ERR_MEM_OVERLAY                = -9,
    EMS_ERR_MALLOC                     = -10,
    EMS_ERR_NOT_ENOUGH                 = -11,
} ems_err_t;
 
#if (EMS_QPC_EN != 0)
 
typedef struct EMS_event
{
    QEvt super;
    uint8_t data[EMS_EVENT_DATA_SIZE];
} EMS_event_t;
 
#endif
 
/**
 * Cast a member of a structure out to the containing structure.
 * @ptr:    the pointer to the member.
 * @type:   the type of the container struct this is embedded in.
 * @member: the name of the member within the struct.
 */
#ifndef container_of
#define container_of(pointer, type, member)                                    \
    ({                                                                         \
        void *__pointer = (void *)(pointer);                                   \
        ((type *)(__pointer - offsetof(type, member)));                        \
    })
#endif
 
#ifndef offsetof
#define offsetof(type, member)          ((uint32_t)&((type *)0)->member)
#endif
 
/* Compiler Related Definitions */
#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM Compiler */
    #include <stdarg.h>
    #define EMS_SECTION(x)             __attribute__((section(x)))
    #define EMS_USED                   __attribute__((used))
    #define EMS_ALIGN(n)               __attribute__((aligned(n)))
    #define EMS_WEAK                   __attribute__((weak))
    #define EMS_INLINE                 static __inline
 
#elif defined (__IAR_SYSTEMS_ICC__)           /* for IAR Compiler */
    #include <stdarg.h>
    #define EMS_SECTION(x)             @ x
    #define EMS_USED                   __root
    #define EMS_PRAGMA(x)              _Pragma(#x)
    #define EMS_ALIGN(n)               EMS_PRAGMA(data_alignment=n)
    #define EMS_WEAK                   __weak
    #define EMS_INLINE                 static inline
 
#elif defined (__GNUC__)                      /* GNU GCC Compiler */
    #include <stdarg.h>
    #define EMS_SECTION(x)             __attribute__((section(x)))
    #define EMS_USED                   __attribute__((used))
    #define EMS_ALIGN(n)               __attribute__((aligned(n)))
    #define EMS_WEAK                   __attribute__((weak))
    #define EMS_INLINE                 static __inline
#else
    #error The compiler is not supported!
#endif
 
#ifdef __cplusplus
}
#endif
 
#endif
 
/* ----------------------------- end of file -------------------------------- */