]> rtime.felk.cvut.cz Git - arc.git/blob - include/io.h
Added example of CAN communication for the TMS570LS31x HDK
[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 READWRITE32(address,mask,val)  WRITE32(address,(READ32(address)&~(mask))|val)\r
41 \r
42 \r
43 \r
44 /* NA - Not Aligned */\r
45 #define WRITE32_NA(address, value ) \\r
46         do { \\r
47         ((uint8_t *)address)[0] = ((value>>24)&0xff); \\r
48         ((uint8_t *)address)[1] = ((value>>16)&0xff); \\r
49         ((uint8_t *)address)[2] = ((value>>8)&0xff);  \\r
50         ((uint8_t *)address)[3] = ((value&0xff)); \\r
51         } while(0)\r
52 \r
53 #define WRITE16_NA(address, value ) \\r
54         do { \\r
55         ((uint8_t *)address)[0] = ((value>>8)&0xff); \\r
56         ((uint8_t *)address)[1] = ((value&0xff)); \\r
57         } while(0)\r
58 \r
59 \r
60 \r
61 #endif /* IO_H_ */\r