Last change
on this file since 851 was
850,
checked in by cfuguet, 10 years ago
|
reconf: introducing a softs directory in the reconfiguration branch
- This softs directory contains a minimalistic (giet-like) library
of drivers and some utility functions.
- Introducing a simple unit test in the vci_cc_vcache_wrapper
component to test the newly introduced watchdog timer mechanism.
This unit test uses the minimalistic library.
|
File size:
1.6 KB
|
Rev | Line | |
---|
[850] | 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 | #include <cpu.h> |
---|
| 12 | |
---|
| 13 | /** |
---|
| 14 | * \brief Read an 32 bits memory mapped hardware register |
---|
| 15 | * |
---|
| 16 | * \note interrupts should be disabled while executing this function |
---|
| 17 | */ |
---|
| 18 | static inline unsigned int ioread32(uint64_t paddr) |
---|
| 19 | { |
---|
| 20 | uint32_t value; |
---|
| 21 | uint32_t msb = paddr >> CLUSTER_OFFSET_BITS; |
---|
| 22 | uint32_t lsb = paddr & ((1ULL << CLUSTER_OFFSET_BITS)-1); |
---|
| 23 | |
---|
| 24 | asm volatile("mtc2 %2, $24 \n" /* DATA_PADDR_EXT <= msb */ |
---|
| 25 | "lw %0, 0(%1) \n" /* value <= *paddr */ |
---|
| 26 | "mtc2 $0, $24 \n" /* DATA_PADDR_EXT <= 0 */ |
---|
| 27 | : "=r"(value) |
---|
| 28 | : "r"(lsb), "r"(msb) |
---|
| 29 | : "memory"); |
---|
| 30 | |
---|
| 31 | return value; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * \brief Write an 32 bits memory mapped hardware register |
---|
| 36 | * |
---|
| 37 | * \note interrupts should be disabled while executing this function |
---|
| 38 | */ |
---|
| 39 | static inline void iowrite32(uint64_t paddr, uint32_t value) |
---|
| 40 | { |
---|
| 41 | uint32_t msb = paddr >> CLUSTER_OFFSET_BITS; |
---|
| 42 | uint32_t lsb = paddr & ((1ULL << CLUSTER_OFFSET_BITS)-1); |
---|
| 43 | |
---|
| 44 | asm volatile("mtc2 %2, $24 \n" /* DATA_PADDR_EXT <= msb */ |
---|
| 45 | "sw %0, 0(%1) \n" /* value <= *paddr */ |
---|
| 46 | "mtc2 $0, $24 \n" /* DATA_PADDR_EXT <= 0 */ |
---|
| 47 | "sync \n" |
---|
| 48 | : /* no outputs */ |
---|
| 49 | : "r"(value), "r"(lsb), "r"(msb) |
---|
| 50 | : "memory"); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | #endif |
---|
| 54 | |
---|
| 55 | /* |
---|
| 56 | * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab |
---|
| 57 | */ |
---|
Note: See
TracBrowser
for help on using the repository browser.