source: soft/giet_vm/giet_common/io.h @ 370

Last change on this file since 370 was 345, checked in by cfuguet, 10 years ago

giet_vm optimizations:

  • Several modifications in GIET_VM in order to support compilation with GCC optimizations (-O2) activated.
  • Adding missing volatile in some global variables.
  • Using ioread and iowrite utility functions in peripheral drivers which prevent GCC to remove writes or reads in hardware memory mapped registers.
  • Code refactoring of stdio printf functions. Now, shr_printf and tty_printf function reuse the same function body. The only difference is that shr_printf wraps printf function call with TTY get lock and release lock.
File size: 2.5 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : io.h
3// Date     : 05/09/2012
4// Author   : cesar fuguet
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7// Utility functions to write or read memory mapped hardware registers
8///////////////////////////////////////////////////////////////////////////////////
9#ifndef IO_H
10#define IO_H
11
12///////////////////////////////////////////////////////////////////////////////////
13// Read an 32 bits memory mapped hardware register
14///////////////////////////////////////////////////////////////////////////////////
15static inline unsigned int ioread32(void * addr)
16{
17        return *(volatile unsigned int *) addr;
18}
19
20///////////////////////////////////////////////////////////////////////////////////
21// Read an 16 bits memory mapped hardware register
22///////////////////////////////////////////////////////////////////////////////////
23static inline unsigned short ioread16(void * addr)
24{
25        return *(volatile unsigned short *) addr;
26}
27
28///////////////////////////////////////////////////////////////////////////////////
29// Read an 8 bits memory mapped hardware register
30///////////////////////////////////////////////////////////////////////////////////
31static inline unsigned char ioread8(void * addr)
32{
33        return *(volatile unsigned char *) addr;
34}
35
36///////////////////////////////////////////////////////////////////////////////////
37// Write an 32 bits memory mapped hardware register
38///////////////////////////////////////////////////////////////////////////////////
39static inline void iowrite32(void * addr, unsigned int value)
40{
41        *(volatile unsigned int *) addr = value;
42        asm volatile("sync" ::: "memory");
43}
44
45///////////////////////////////////////////////////////////////////////////////////
46// Write an 16 bits memory mapped hardware register
47///////////////////////////////////////////////////////////////////////////////////
48static inline void iowrite16(void * addr, unsigned short value)
49{
50        *(volatile unsigned short *) addr = value;
51        asm volatile("sync" ::: "memory");
52}
53
54///////////////////////////////////////////////////////////////////////////////////
55// Write an 8 bits memory mapped hardware register
56///////////////////////////////////////////////////////////////////////////////////
57static inline void iowrite8(void * addr, unsigned char value)
58{
59        *(volatile unsigned char *) addr = value;
60        asm volatile("sync" ::: "memory");
61}
62
63#undef in_reset
64
65#endif
Note: See TracBrowser for help on using the repository browser.