]> rtime.felk.cvut.cz Git - arc.git/blob - include/io.h
f0b13e5b6b0bf0b6e611128fc8d22e30ba452b64
[arc.git] / include / io.h
1 /* -------------------------------- Arctic Core ------------------------------\r
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
3  *\r
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
5  *\r
6  * This source code is free software; you can redistribute it and/or modify it\r
7  * under the terms of the GNU General Public License version 2 as published by the\r
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
9  *\r
10  * This program is distributed in the hope that it will be useful, but\r
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
13  * for more details.\r
14  * -------------------------------- Arctic Core ------------------------------*/\r
15 \r
16 #ifndef IO_H_\r
17 #define IO_H_\r
18 \r
19 #define WRITE8(address, value)      (*(uint8_t*)(address) = (value))\r
20 #define READ8(address)              ((uint8_t)(*(uint8_t*)(address)))\r
21 \r
22 #define WRITE16(address, value)     (*(vuint16_t*)(address) = (value))\r
23 #define READ16(address)             ((uint16_t)(*(vuint16_t*)(address)))\r
24 \r
25 #define WRITE32(address, value)     (*(vuint32_t*)(address) = (value))\r
26 #define READ32(address)             ((uint32_t)(*(vuint32_t*)(address)))\r
27 \r
28 #define WRITE64(address, value)     (*(vuint64_t*)(address) = (value))\r
29 #define READ64(address)             ((uint64_t)(*(vuint64_t*)(address)))\r
30 \r
31 /* Not aligned reads */\r
32 #define READ32_NA(address )                     ( (((uint32_t)(((uint8_t *)address)[0]))<<24) + \\r
33                                                                           (((uint32_t)(((uint8_t *)address)[1]))<<16) + \\r
34                                                                           (((uint32_t)(((uint8_t *)address)[2]))<<8) +  \\r
35                                                                           ((uint32_t)(((uint8_t *)address)[3])) )\r
36 \r
37 #define READ16_NA(address )                     ( (((uint16_t)(((uint8_t *)address)[0]))<<8) +  \\r
38                                                                           (((uint16_t)(((uint8_t *)address)[1]))) )\r
39 \r
40 #define WRITE32_NA(address, value ) \\r
41         do { \\r
42         ((uint8_t *)address)[0] = ((value>>24)&0xff); \\r
43         ((uint8_t *)address)[1] = ((value>>16)&0xff); \\r
44         ((uint8_t *)address)[2] = ((value>>8)&0xff);  \\r
45         ((uint8_t *)address)[3] = ((value&0xff)); \\r
46         } while(0)\r
47 \r
48 #define WRITE16_NA(address, value ) \\r
49         do { \\r
50         ((uint8_t *)address)[0] = ((value>>8)&0xff); \\r
51         ((uint8_t *)address)[1] = ((value&0xff)); \\r
52         } while(0)\r
53 \r
54 \r
55 \r
56 #endif /* IO_H_ */\r