source: trunk/softs/tsar_boot/include/io.h @ 704

Last change on this file since 704 was 704, checked in by alain, 10 years ago

tsar_boot:

  • Erasing unused constant in defs.h
  • Modofication in IO access functions to allow addressing in clusters using physical address extension
File size: 2.9 KB
Line 
1/**********************************************************************
2 * \file        io.h
3 * \date        5 September 2012
4 * \author      Cesar Fuguet / Alain Greiner
5 *
6 * Utility functions to write or read memory mapped hardware registers
7 *********************************************************************/
8
9#ifndef IO_H
10#define IO_H
11
12#include <defs.h>
13
14/**********************************************************************
15 * Read an 32 bits memory mapped hardware register
16 * with physical address extension to access cluster_io
17 *********************************************************************/
18static inline unsigned int ioread32(void * addr)
19{
20    unsigned int value;
21    unsigned int ext = CLUSTER_IO;
22
23    asm volatile(
24        "mtc2  %2,    $24            \n"  /* PADDR_EXT <= cluster_io */
25        "lw    %0,    0(%1)          \n"  /* value <= *(ext\addr)    */
26        "mtc2  $0,    $24            \n"  /* PADDR_EXT <= 0          */
27        : "=r" (value)
28        : "r" (addr), "r" (ext) );
29
30    return value;
31}
32
33/**********************************************************************
34 * Read an 16 bits memory mapped hardware register
35 *********************************************************************/
36static inline unsigned short ioread16(void * addr)
37{
38        return *(volatile unsigned short *) addr;
39}
40
41/**********************************************************************
42 * Read an 8 bits memory mapped hardware register
43 *********************************************************************/
44static inline unsigned char ioread8(void * addr)
45{
46        return *(volatile unsigned char *) addr;
47}
48
49/**********************************************************************
50 * Write an 32 bits memory mapped hardware register
51 * with physical address extension to access cluster_io
52 *********************************************************************/
53static inline void iowrite32(void * addr, unsigned int value)
54{
55    unsigned int ext = CLUSTER_IO;
56
57    asm volatile(
58        "mtc2  %2,    $24            \n"  /* PADDR_EXT <= cluster_io */
59        "sw    %0,    0(%1)          \n"  /* *(ext\addr) <= value    */
60        "mtc2  $0,    $24            \n"  /* PADDR_EXT <= 0          */
61            "sync                        \n"  /* sync barrier            */
62        :
63        : "r" (value), "r" (addr), "r" (ext) );
64}
65
66/**********************************************************************
67 * Write an 16 bits memory mapped hardware register
68 *********************************************************************/
69static inline void iowrite16(void * addr, unsigned short value)
70{
71        *(volatile unsigned short *) addr = value;
72        asm volatile("sync" ::: "memory");
73}
74
75/**********************************************************************
76 * Write an 8 bits memory mapped hardware register
77 *********************************************************************/
78static inline void iowrite8(void * addr, unsigned char value)
79{
80        *(volatile unsigned char *) addr = value;
81        asm volatile("sync" ::: "memory");
82}
83
84#endif
Note: See TracBrowser for help on using the repository browser.