1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * This file contains the code to do simple memory and io accesses. |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * COPYRIGHT (c) 1989-2012. |
---|
9 | * On-Line Applications Research Corporation (OAR). |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.org/license/LICENSE. |
---|
14 | */ |
---|
15 | |
---|
16 | #include <rtems.h> |
---|
17 | #include <bsp.h> |
---|
18 | |
---|
19 | #include <bsp/pci.h> |
---|
20 | #include <bsp/irq.h> |
---|
21 | #include <rtems/bspIo.h> |
---|
22 | #include <rtems/endian.h> |
---|
23 | // #define DEBUG_ACCESSES 1 |
---|
24 | |
---|
25 | #ifdef DEBUG_ACCESSES |
---|
26 | #define JPRINTK(fmt, ...) printk("%s: " fmt, __FUNCTION__, ##__VA_ARGS__) |
---|
27 | #else |
---|
28 | #define JPRINTK(fmt, ...) |
---|
29 | #endif |
---|
30 | |
---|
31 | /* |
---|
32 | * * Simple accesses |
---|
33 | * */ |
---|
34 | void simple_out_32(uint32_t base, uint32_t addr, uint32_t val) |
---|
35 | { |
---|
36 | volatile uint32_t *ptr; |
---|
37 | |
---|
38 | ptr = (volatile uint32_t *) (base + addr); |
---|
39 | *ptr = val; |
---|
40 | |
---|
41 | JPRINTK( "%p data: 0x%x\n", ptr, val); |
---|
42 | } |
---|
43 | |
---|
44 | void simple_out_le32(uint32_t base, uint32_t addr, uint32_t val) |
---|
45 | { |
---|
46 | volatile uint32_t *ptr; |
---|
47 | uint32_t data = 0; |
---|
48 | |
---|
49 | ptr = (volatile uint32_t *) (base + addr); |
---|
50 | rtems_uint32_to_little_endian( val, (uint8_t *) &data); |
---|
51 | *ptr = data; |
---|
52 | |
---|
53 | JPRINTK( "%p data: 0x%x\n", ptr, data); |
---|
54 | } |
---|
55 | |
---|
56 | uint8_t simple_in_8( uint32_t base, uint32_t addr ) { |
---|
57 | volatile uint8_t *ptr; |
---|
58 | uint8_t val; |
---|
59 | |
---|
60 | ptr = (volatile uint8_t *) (base + addr); |
---|
61 | val = *ptr; |
---|
62 | JPRINTK( "0x%x data: 0x%x\n", ptr, val); |
---|
63 | |
---|
64 | return val; |
---|
65 | } |
---|
66 | |
---|
67 | int16_t simple_in_le16( uint32_t base, uint32_t addr ) { |
---|
68 | volatile uint16_t *ptr; |
---|
69 | uint16_t val; |
---|
70 | uint16_t rval; |
---|
71 | |
---|
72 | ptr = (volatile uint16_t *) (base + addr); |
---|
73 | val = *ptr; |
---|
74 | rval = rtems_uint16_from_little_endian( (uint8_t *) &val); |
---|
75 | JPRINTK( "0x%x data: 0x%x raw: 0x%x\n", ptr, rval, val); |
---|
76 | return rval; |
---|
77 | } |
---|
78 | |
---|
79 | int16_t simple_in_16( uint32_t base, uint32_t addr ) { |
---|
80 | volatile uint16_t *ptr; |
---|
81 | uint16_t val; |
---|
82 | |
---|
83 | ptr = (volatile uint16_t *) (base + addr); |
---|
84 | val = *ptr; |
---|
85 | JPRINTK( "0x%x data: 0x%x raw: 0x%x\n", ptr, val, val); |
---|
86 | return val; |
---|
87 | } |
---|
88 | |
---|
89 | uint32_t simple_in_le32( uint32_t base, uint32_t addr ) { |
---|
90 | volatile uint32_t *ptr; |
---|
91 | uint32_t val; |
---|
92 | uint32_t rval; |
---|
93 | |
---|
94 | ptr = (volatile uint32_t *) (base + addr); |
---|
95 | val = *ptr; |
---|
96 | rval = rtems_uint32_from_little_endian( (uint8_t *) &val); |
---|
97 | JPRINTK( "0x%x data: 0x%x raw: 0x%x\n", ptr, rval, val); |
---|
98 | return rval; |
---|
99 | } |
---|
100 | |
---|
101 | uint32_t simple_in_32( uint32_t base, uint32_t addr ) { |
---|
102 | volatile uint32_t *ptr; |
---|
103 | uint32_t val; |
---|
104 | |
---|
105 | ptr = (volatile uint32_t *) (base + addr); |
---|
106 | val = *ptr; |
---|
107 | JPRINTK( "0x%x data: 0x%x raw: 0x%x\n", ptr, val, val); |
---|
108 | return val; |
---|
109 | } |
---|
110 | |
---|
111 | void simple_out_8( uint32_t base, uint32_t addr, uint8_t val ) { |
---|
112 | volatile uint8_t *ptr; |
---|
113 | |
---|
114 | ptr = (volatile uint8_t *) (base | addr); |
---|
115 | JPRINTK( "0x%x data: 0x%x\n", ptr, val); |
---|
116 | *ptr = val; |
---|
117 | } |
---|
118 | |
---|
119 | void simple_out_le16( uint32_t base, uint32_t addr, uint16_t val ) { |
---|
120 | volatile uint16_t *ptr; |
---|
121 | uint16_t data; |
---|
122 | ptr = (volatile uint16_t *) (base + addr); |
---|
123 | rtems_uint16_to_little_endian( val, (uint8_t *) &data); |
---|
124 | *ptr = data; |
---|
125 | JPRINTK( "0x%x data: 0x%x\n", ptr, data); |
---|
126 | } |
---|
127 | |
---|
128 | void simple_out_16( uint32_t base, uint32_t addr, uint16_t val ) { |
---|
129 | volatile uint16_t *ptr; |
---|
130 | ptr = (volatile uint16_t *) (base + addr); |
---|
131 | *ptr = val; |
---|
132 | JPRINTK( "0x%x data: 0x%x\n", ptr, val); |
---|
133 | } |
---|