agileRTOS (zrtos)  Version 0.8.0 (ghostbuster)
types.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <limits.h>
#include <stdalign.h>
#include <zrtos/cast.h>
Include dependency graph for types.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ZRTOS_TYPES__BYTE_ALIGNMENT   (__alignof__(max_align_t))
 
#define ZRTOS_TYPES__BYTE_ALIGNMENT_MASK   (__alignof__(max_align_t)-1)
 
#define zrtos_types__get_offset_of(type, member)   __builtin_offsetof(type,member)
 
#define zrtos_types__get_container_of(ptr, type, member)
 
#define zrtos_types__get_container_of_ex(ptr, type, member)   ((ptr) ? zrtos_types__get_container_of(ptr, type, member) : 0) \
 
#define ZRTOS_TYPES__MIN(a, b)   ((a)<(b)?(a):(b))
 
#define ZRTOS_TYPES__MAX(a, b)   ((a)>(b)?(a):(b))
 
#define ZRTOS_TYPES__CMP(type, a_len, b_len)   ((a_len) < (b_len) ? - 1 : ((a_len) > (b_len) ? 1 : 0))
 
#define ZRTOS_TYPES__TYPEOF(a)   typeof(a)
 
#define ZRTOS_TYPES__SWAP(a, b)
 
#define ZRTOS_TYPES__SWAP_PTR_CONTENTS(a, b)
 
#define ZRTOS_TYPES__IS_ADD_OVERFLOW(a, b)   (((a + b ) < a))
 
#define ZRTOS_TYPES__GET_STATIC_ARRAY_LENGTH(arr)   (sizeof(arr)/sizeof((arr)[0]))
 
#define ZRTOS_TYPES__SIZE_MIN   (0)
 
#define ZRTOS_TYPES__SIZE_MAX   SIZE_MAX
 
#define ZRTOS_TYPES__INT8_MIN   INT8_MIN
 
#define ZRTOS_TYPES__INT8_MAX   INT8_MAX
 
#define ZRTOS_TYPES__INT16_MIN   INT16_MIN
 
#define ZRTOS_TYPES__INT16_MAX   INT16_MAX
 
#define ZRTOS_TYPES__INT32_MIN   INT32_MIN
 
#define ZRTOS_TYPES__INT32_MAX   INT32_MAX
 
#define ZRTOS_TYPES__INT64_MIN   INT64_MIN
 
#define ZRTOS_TYPES__INT64_MAX   INT64_MAX
 
#define ZRTOS_TYPES__UINT8_MIN   (0)
 
#define ZRTOS_TYPES__UINT8_MAX   UINT8_MAX
 
#define ZRTOS_TYPES__UINT16_MIN   (0)
 
#define ZRTOS_TYPES__UINT16_MAX   UINT16_MAX
 
#define ZRTOS_TYPES__UINT32_MIN   (0)
 
#define ZRTOS_TYPES__UINT32_MAX   UINT32_MAX
 
#define ZRTOS_TYPES__UINT64_MIN   (0)
 
#define ZRTOS_TYPES__UINT64_MAX   UINT64_MAX
 
#define ZRTOS_TYPES__MAP(value, in_min, in_max, out_min, out_max)   (((value)-(in_min))*((out_max)-(out_min))/((in_max)-(in_min))+(out_min))
 
#define zrtos_types__htobe16(x)   zrtos_types__uint16_bswap(x)
 
#define zrtos_types__htole16(x)   (x)
 
#define zrtos_types__be16toh(x)   zrtos_types__uint16_bswap(x)
 
#define zrtos_types__le16toh(x)   (x)
 
#define zrtos_types__htobe32(x)   zrtos_types__uint32_bswap(x)
 
#define zrtos_types__htole32(x)   (x)
 
#define zrtos_types__be32toh(x)   zrtos_types__uint32_bswap(x)
 
#define zrtos_types__le32toh(x)   (x)
 
#define zrtos_types__htobe64(x)   zrtos_types__uint64_bswap(x)
 
#define zrtos_types__htole64(x)   (x)
 
#define zrtos_types__be64toh(x)   zrtos_types__uint64_bswap(x)
 
#define zrtos_types__le64toh(x)   (x)
 

Typedefs

typedef uint16_t size_t
 
typedef int16_t ssize_t
 

Functions

int zrtos_types__ptr_cmp (void *a, void *b)
 
void * zrtos_types__ptr_add (void *ptr, size_t byte_len)
 
void * zrtos_types__ptr_subtract (void *ptr, size_t byte_len)
 
size_t zrtos_types__ptr_get_byte_distance (void *bigger, void *smaller)
 
void * zrtos_types__ptr_to_alignment (void *ptr)
 
size_t zrtos_types__ceil_size_to_alignment (size_t len)
 
bool zrtos_types__uint32_is_valid_address_range (uint32_t first_address, uint32_t last_address, uint32_t offset, size_t *length)
 
bool zrtos_types__ptr_is_valid_address_range (void *first_address, void *last_address, size_t offset, size_t *length)
 
bool zrtos_types__uint64_is_valid_address_range (uint64_t first_address, uint64_t last_address, uint64_t offset, size_t *length)
 
size_t zrtos_types__uint8_to_hex (uint8_t *dest, uint8_t src)
 
uint16_t zrtos_types__uint16_bswap (uint16_t x)
 
uint32_t zrtos_types__uint32_bswap (uint32_t x)
 
uint64_t zrtos_types__uint64_bswap (uint64_t x)
 
bool zrtos_types__is_digit (char c)
 
bool zrtos_types__is_whitespace (char c)
 
bool zrtos_types__is_newline (char c)
 

Macro Definition Documentation

◆ zrtos_types__be16toh

#define zrtos_types__be16toh (   x)    zrtos_types__uint16_bswap(x)

Definition at line 235 of file types.h.

◆ zrtos_types__be32toh

#define zrtos_types__be32toh (   x)    zrtos_types__uint32_bswap(x)

Definition at line 240 of file types.h.

◆ zrtos_types__be64toh

#define zrtos_types__be64toh (   x)    zrtos_types__uint64_bswap(x)

Definition at line 245 of file types.h.

◆ ZRTOS_TYPES__BYTE_ALIGNMENT

#define ZRTOS_TYPES__BYTE_ALIGNMENT   (__alignof__(max_align_t))

Definition at line 47 of file types.h.

◆ ZRTOS_TYPES__BYTE_ALIGNMENT_MASK

#define ZRTOS_TYPES__BYTE_ALIGNMENT_MASK   (__alignof__(max_align_t)-1)

Definition at line 48 of file types.h.

◆ ZRTOS_TYPES__CMP

#define ZRTOS_TYPES__CMP (   type,
  a_len,
  b_len 
)    ((a_len) < (b_len) ? - 1 : ((a_len) > (b_len) ? 1 : 0))

Definition at line 80 of file types.h.

◆ zrtos_types__get_container_of

#define zrtos_types__get_container_of (   ptr,
  type,
  member 
)
Value:
({ \
typeof( ((type *)0)->member ) *mptr__ = (typeof( ((type *)0)->member ) *)(ptr); \
(type *)((char *)mptr__ - zrtos_types__get_offset_of(type,member)); \
})
#define zrtos_types__get_offset_of(type, member)
Definition: types.h:66

Definition at line 69 of file types.h.

◆ zrtos_types__get_container_of_ex

#define zrtos_types__get_container_of_ex (   ptr,
  type,
  member 
)    ((ptr) ? zrtos_types__get_container_of(ptr, type, member) : 0) \

Definition at line 75 of file types.h.

◆ zrtos_types__get_offset_of

#define zrtos_types__get_offset_of (   type,
  member 
)    __builtin_offsetof(type,member)

Definition at line 66 of file types.h.

◆ ZRTOS_TYPES__GET_STATIC_ARRAY_LENGTH

#define ZRTOS_TYPES__GET_STATIC_ARRAY_LENGTH (   arr)    (sizeof(arr)/sizeof((arr)[0]))

Definition at line 166 of file types.h.

◆ zrtos_types__htobe16

#define zrtos_types__htobe16 (   x)    zrtos_types__uint16_bswap(x)

Definition at line 233 of file types.h.

◆ zrtos_types__htobe32

#define zrtos_types__htobe32 (   x)    zrtos_types__uint32_bswap(x)

Definition at line 238 of file types.h.

◆ zrtos_types__htobe64

#define zrtos_types__htobe64 (   x)    zrtos_types__uint64_bswap(x)

Definition at line 243 of file types.h.

◆ zrtos_types__htole16

#define zrtos_types__htole16 (   x)    (x)

Definition at line 234 of file types.h.

◆ zrtos_types__htole32

#define zrtos_types__htole32 (   x)    (x)

Definition at line 239 of file types.h.

◆ zrtos_types__htole64

#define zrtos_types__htole64 (   x)    (x)

Definition at line 244 of file types.h.

◆ ZRTOS_TYPES__INT16_MAX

#define ZRTOS_TYPES__INT16_MAX   INT16_MAX

Definition at line 175 of file types.h.

◆ ZRTOS_TYPES__INT16_MIN

#define ZRTOS_TYPES__INT16_MIN   INT16_MIN

Definition at line 174 of file types.h.

◆ ZRTOS_TYPES__INT32_MAX

#define ZRTOS_TYPES__INT32_MAX   INT32_MAX

Definition at line 177 of file types.h.

◆ ZRTOS_TYPES__INT32_MIN

#define ZRTOS_TYPES__INT32_MIN   INT32_MIN

Definition at line 176 of file types.h.

◆ ZRTOS_TYPES__INT64_MAX

#define ZRTOS_TYPES__INT64_MAX   INT64_MAX

Definition at line 179 of file types.h.

◆ ZRTOS_TYPES__INT64_MIN

#define ZRTOS_TYPES__INT64_MIN   INT64_MIN

Definition at line 178 of file types.h.

◆ ZRTOS_TYPES__INT8_MAX

#define ZRTOS_TYPES__INT8_MAX   INT8_MAX

Definition at line 173 of file types.h.

◆ ZRTOS_TYPES__INT8_MIN

#define ZRTOS_TYPES__INT8_MIN   INT8_MIN

Definition at line 172 of file types.h.

◆ ZRTOS_TYPES__IS_ADD_OVERFLOW

#define ZRTOS_TYPES__IS_ADD_OVERFLOW (   a,
 
)    (((a + b ) < a))

Definition at line 163 of file types.h.

◆ zrtos_types__le16toh

#define zrtos_types__le16toh (   x)    (x)

Definition at line 236 of file types.h.

◆ zrtos_types__le32toh

#define zrtos_types__le32toh (   x)    (x)

Definition at line 241 of file types.h.

◆ zrtos_types__le64toh

#define zrtos_types__le64toh (   x)    (x)

Definition at line 246 of file types.h.

◆ ZRTOS_TYPES__MAP

#define ZRTOS_TYPES__MAP (   value,
  in_min,
  in_max,
  out_min,
  out_max 
)    (((value)-(in_min))*((out_max)-(out_min))/((in_max)-(in_min))+(out_min))

Definition at line 207 of file types.h.

◆ ZRTOS_TYPES__MAX

#define ZRTOS_TYPES__MAX (   a,
 
)    ((a)>(b)?(a):(b))

Definition at line 79 of file types.h.

◆ ZRTOS_TYPES__MIN

#define ZRTOS_TYPES__MIN (   a,
 
)    ((a)<(b)?(a):(b))

Definition at line 78 of file types.h.

◆ ZRTOS_TYPES__SIZE_MAX

#define ZRTOS_TYPES__SIZE_MAX   SIZE_MAX

Definition at line 170 of file types.h.

◆ ZRTOS_TYPES__SIZE_MIN

#define ZRTOS_TYPES__SIZE_MIN   (0)

Definition at line 169 of file types.h.

◆ ZRTOS_TYPES__SWAP

#define ZRTOS_TYPES__SWAP (   a,
 
)
Value:
do{ \
ZRTOS_TYPES__TYPEOF(a) a____ = (a); \
(a) = (b); \
(b) = a____; \
}while(0);

Definition at line 149 of file types.h.

◆ ZRTOS_TYPES__SWAP_PTR_CONTENTS

#define ZRTOS_TYPES__SWAP_PTR_CONTENTS (   a,
 
)
Value:
do{ \
ZRTOS_TYPES__TYPEOF(*a) a____ = *(a); \
*(a) = *(b); \
*(b) = a____; \
}while(0);

Definition at line 156 of file types.h.

◆ ZRTOS_TYPES__TYPEOF

#define ZRTOS_TYPES__TYPEOF (   a)    typeof(a)

Definition at line 146 of file types.h.

◆ ZRTOS_TYPES__UINT16_MAX

#define ZRTOS_TYPES__UINT16_MAX   UINT16_MAX

Definition at line 184 of file types.h.

◆ ZRTOS_TYPES__UINT16_MIN

#define ZRTOS_TYPES__UINT16_MIN   (0)

Definition at line 183 of file types.h.

◆ ZRTOS_TYPES__UINT32_MAX

#define ZRTOS_TYPES__UINT32_MAX   UINT32_MAX

Definition at line 186 of file types.h.

◆ ZRTOS_TYPES__UINT32_MIN

#define ZRTOS_TYPES__UINT32_MIN   (0)

Definition at line 185 of file types.h.

◆ ZRTOS_TYPES__UINT64_MAX

#define ZRTOS_TYPES__UINT64_MAX   UINT64_MAX

Definition at line 188 of file types.h.

◆ ZRTOS_TYPES__UINT64_MIN

#define ZRTOS_TYPES__UINT64_MIN   (0)

Definition at line 187 of file types.h.

◆ ZRTOS_TYPES__UINT8_MAX

#define ZRTOS_TYPES__UINT8_MAX   UINT8_MAX

Definition at line 182 of file types.h.

◆ ZRTOS_TYPES__UINT8_MIN

#define ZRTOS_TYPES__UINT8_MIN   (0)

Definition at line 181 of file types.h.

Typedef Documentation

◆ size_t

typedef uint16_t size_t

Definition at line 22 of file types.h.

◆ ssize_t

typedef int16_t ssize_t

Definition at line 23 of file types.h.

Function Documentation

◆ zrtos_types__ceil_size_to_alignment()

size_t zrtos_types__ceil_size_to_alignment ( size_t  len)

Definition at line 59 of file types.h.

59  {
60  return len
63  ;
64 }
#define ZRTOS_TYPES__BYTE_ALIGNMENT
Definition: types.h:47
#define ZRTOS_TYPES__BYTE_ALIGNMENT_MASK
Definition: types.h:48
Here is the caller graph for this function:

◆ zrtos_types__is_digit()

bool zrtos_types__is_digit ( char  c)

Definition at line 264 of file types.h.

264  {
265  return c >= '0' && c <= '9';
266 }
Here is the caller graph for this function:

◆ zrtos_types__is_newline()

bool zrtos_types__is_newline ( char  c)

Definition at line 272 of file types.h.

272  {
273  return c == '\r' || c == '\n';
274 }

◆ zrtos_types__is_whitespace()

bool zrtos_types__is_whitespace ( char  c)

Definition at line 268 of file types.h.

268  {
269  return c == ' ' || c == '\t';
270 }

◆ zrtos_types__ptr_add()

void* zrtos_types__ptr_add ( void *  ptr,
size_t  byte_len 
)

Definition at line 35 of file types.h.

35  {
36  return ((uint8_t*)ptr)+byte_len;
37 }
static uint8_t
Definition: mcp2515.h:159
Here is the caller graph for this function:

◆ zrtos_types__ptr_cmp()

int zrtos_types__ptr_cmp ( void *  a,
void *  b 
)

Definition at line 31 of file types.h.

31  {
32  return ((ptrdiff_t)a)-((ptrdiff_t)b);
33 }
Here is the caller graph for this function:

◆ zrtos_types__ptr_get_byte_distance()

size_t zrtos_types__ptr_get_byte_distance ( void *  bigger,
void *  smaller 
)

Definition at line 43 of file types.h.

43  {
44  return ((uint8_t*)bigger)-((uint8_t*)smaller);
45 }
static uint8_t
Definition: mcp2515.h:159
Here is the caller graph for this function:

◆ zrtos_types__ptr_is_valid_address_range()

bool zrtos_types__ptr_is_valid_address_range ( void *  first_address,
void *  last_address,
size_t  offset,
size_t length 
)

Definition at line 100 of file types.h.

105  {
107  last_address
108  ,first_address
109  )){
110  *length = ZRTOS_TYPES__MIN(
111  *length
113  last_address
115  last_address
116  ,offset
117  )
118  )
119  );
120  return true;
121  }
122  return false;
123 }
void * zrtos_types__ptr_subtract(void *ptr, size_t byte_len)
Definition: types.h:39
#define ZRTOS_TYPES__MIN(a, b)
Definition: types.h:78
size_t zrtos_types__ptr_get_byte_distance(void *bigger, void *smaller)
Definition: types.h:43
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_types__ptr_subtract()

void* zrtos_types__ptr_subtract ( void *  ptr,
size_t  byte_len 
)

Definition at line 39 of file types.h.

39  {
40  return ((uint8_t*)ptr)-byte_len;
41 }
static uint8_t
Definition: mcp2515.h:159
Here is the caller graph for this function:

◆ zrtos_types__ptr_to_alignment()

void* zrtos_types__ptr_to_alignment ( void *  ptr)

Definition at line 50 of file types.h.

50  {
51  uintptr_t ret = (uintptr_t)ptr;
52  ret = ret
55  ;
56  return (void*)ret;
57 }
#define ZRTOS_TYPES__BYTE_ALIGNMENT
Definition: types.h:47
#define ZRTOS_TYPES__BYTE_ALIGNMENT_MASK
Definition: types.h:48

◆ zrtos_types__uint16_bswap()

uint16_t zrtos_types__uint16_bswap ( uint16_t  x)

Definition at line 210 of file types.h.

210  {
211  return ((__uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)));
212 }

◆ zrtos_types__uint32_bswap()

uint32_t zrtos_types__uint32_bswap ( uint32_t  x)

Definition at line 214 of file types.h.

214  {
215  return ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8)
216  | (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24));
217 }

◆ zrtos_types__uint32_is_valid_address_range()

bool zrtos_types__uint32_is_valid_address_range ( uint32_t  first_address,
uint32_t  last_address,
uint32_t  offset,
size_t length 
)

Definition at line 83 of file types.h.

88  {
89  if(offset >= first_address
90  && offset <= last_address){
91  *length = ZRTOS_TYPES__MIN(
92  *length
93  ,last_address - offset
94  );
95  return true;
96  }
97  return false;
98 }
#define ZRTOS_TYPES__MIN(a, b)
Definition: types.h:78
Here is the caller graph for this function:

◆ zrtos_types__uint64_bswap()

uint64_t zrtos_types__uint64_bswap ( uint64_t  x)

Definition at line 219 of file types.h.

219  {
220  return
221  ((((x) & 0xff00000000000000ull) >> 56)
222  | (((x) & 0x00ff000000000000ull) >> 40)
223  | (((x) & 0x0000ff0000000000ull) >> 24)
224  | (((x) & 0x000000ff00000000ull) >> 8)
225  | (((x) & 0x00000000ff000000ull) << 8)
226  | (((x) & 0x0000000000ff0000ull) << 24)
227  | (((x) & 0x000000000000ff00ull) << 40)
228  | (((x) & 0x00000000000000ffull) << 56))
229  ;
230 }

◆ zrtos_types__uint64_is_valid_address_range()

bool zrtos_types__uint64_is_valid_address_range ( uint64_t  first_address,
uint64_t  last_address,
uint64_t  offset,
size_t length 
)

Definition at line 125 of file types.h.

130  {
131  if(offset >= first_address
132  && offset <= last_address){
133  *length = ZRTOS_TYPES__MIN(
134  *length
135  ,last_address - offset
136  );
137  return true;
138  }
139  return false;
140 }
#define ZRTOS_TYPES__MIN(a, b)
Definition: types.h:78

◆ zrtos_types__uint8_to_hex()

size_t zrtos_types__uint8_to_hex ( uint8_t dest,
uint8_t  src 
)

Definition at line 190 of file types.h.

190  {
191  uint8_t h = (src & 0xF) + '0';
192  uint8_t l = (src >> 4) + '0';
193 
194  if(h > '9'){
195  h += 'A' - '9';
196  }
197  if(l > '9'){
198  l += 'A' - '9';
199  }
200 
201  dest[0] = h;
202  dest[1] = l;
203 
204  return 2;
205 }
static uint8_t
Definition: mcp2515.h:159