source: trunk/softs/tsar_boot/io_drivers/io.h @ 276

Last change on this file since 276 was 276, checked in by bouyer, 12 years ago

A boot loader to be stored in ROM of a TSAR platform.
Based on Cesar FUGUET's work.
Platform-specific files are in a subdirectory, e.g. platform_fpga_de2-115,
so the same code can be targetted to different platforms.
The platform is selected with the PLATFORM_DIR environnement variable.
The supported variant are soclib and fpga, the later being the default
and the former selected by defining the SOCLIB environnement variable.
The boot loader embeds a binary device tree describing the platform,
to be used by the loaded software.

File size: 1.3 KB
Line 
1/**
2 * \file        io.h
3 * \date        5 September 2012
4 * \author      Cesar Fuguet
5 *
6 * Utility functions to write or read memory mapped hardware registers
7 */
8#ifndef IO_H
9#define IO_H
10
11#define in_reset __attribute__((section (".reset")))
12
13/**
14 * Read an 32 bits memory mapped hardware register
15 */
16in_reset static inline unsigned int ioread32(void * addr)
17{
18        return *(volatile unsigned int *) addr;
19}
20
21/**
22 * Read an 16 bits memory mapped hardware register
23 */
24in_reset static inline unsigned short ioread16(void * addr)
25{
26        return *(volatile unsigned short *) addr;
27}
28
29/**
30 * Read an 8 bits memory mapped hardware register
31 */
32in_reset static inline unsigned char ioread8(void * addr)
33{
34        return *(volatile unsigned char *) addr;
35}
36
37/**
38 * Write an 32 bits memory mapped hardware register
39 */
40in_reset static inline void iowrite32(void * addr, unsigned int value)
41{
42        *(volatile unsigned int *) addr = value;
43        asm volatile("sync");
44}
45
46/**
47 * Write an 16 bits memory mapped hardware register
48 */
49in_reset static inline void iowrite16(void * addr, unsigned short value)
50{
51        *(volatile unsigned short *) addr = value;
52        asm volatile("sync");
53}
54
55/**
56 * Write an 8 bits memory mapped hardware register
57 */
58in_reset static inline void iowrite8(void * addr, unsigned char value)
59{
60        *(volatile unsigned char *) addr = value;
61        asm volatile("sync");
62}
63
64#undef in_reset
65
66#endif
Note: See TracBrowser for help on using the repository browser.