MYDEFS.H


1
#ifndef _mydefs_h_
2
#define _mydefs_h_
3
4
5
//      Easier type writing:
6
7
typedef unsigned char  u8;
8
typedef   signed char  s8;
9
typedef unsigned short u16;
10
typedef   signed short s16;
11
typedef unsigned long  u32;
12
typedef   signed long  s32;
13
14
15
//       Bit access of IO bits:
16
17
struct bits {
18
  u8 b0:1;
19
  u8 b1:1;
20
  u8 b2:1;
21
  u8 b3:1;
22
  u8 b4:1;
23
  u8 b5:1;
24
  u8 b6:1;
25
  u8 b7:1;
26
} __attribute__((__packed__));
27
28
29
#define SBIT_(port,pin) ((*(volatile struct bits*)&port).b##pin)
30
#define  SBIT(x,y)  SBIT_(x,y)
31
32
33
#define AIL(x)   static x __attribute__ ((always_inline)); static x
34
35
#define NIL(x)   x __attribute__ ((noinline)); x
36
37
38
// volatile access (reject unwanted removing repeated access):
39
40
#define vu8(x)  (*(volatile u8*)&(x))
41
#define vs8(x)  (*(volatile s8*)&(x))
42
#define vu16(x) (*(volatile u16*)&(x))
43
#define vs16(x) (*(volatile s16*)&(x))
44
#define vu32(x) (*(volatile u32*)&(x))
45
#define vs32(x) (*(volatile s32*)&(x))
46
47
48
#endif