nios2: add _nios2_reg_write/read functions
The technical manuals and example HAL code frequently refer to register bank numbers from some base address. Add these helper functions to read and write registers correctly using this notation. Change-Id: Ia082f5cc89081fcea2cb6ad8204c1b9b2650d3fd Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
280340162d
commit
7bd697b0d5
2 changed files with 19 additions and 1 deletions
|
@ -25,6 +25,7 @@
|
|||
#define _ARCH_IFACE_H
|
||||
|
||||
#include <system.h>
|
||||
#include <arch/nios2/asm_inline.h>
|
||||
#include "nios2.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -41,7 +42,6 @@ extern "C" {
|
|||
#ifndef _ASMLANGUAGE
|
||||
#include <stdint.h>
|
||||
#include <irq.h>
|
||||
#include <arch/nios2/asm_inline.h>
|
||||
|
||||
/* STUB. Eventually port ARC/ARM interrupt stuff */
|
||||
#define _ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p)
|
||||
|
|
|
@ -46,9 +46,14 @@ extern "C"
|
|||
*/
|
||||
#define NIOS2_NIRQ 32
|
||||
|
||||
/* Size in bits of registers */
|
||||
#define SYSTEM_BUS_WIDTH 32
|
||||
|
||||
#ifndef _ASMLANGUAGE
|
||||
|
||||
#include <stdint.h>
|
||||
#include <arch/cpu.h>
|
||||
#include <sys_io.h>
|
||||
|
||||
/*
|
||||
* Functions for accessing select Nios II general-purpose registers.
|
||||
|
@ -128,6 +133,19 @@ enum nios2_creg {
|
|||
#define _nios2_creg_read(reg) __builtin_rdctl(reg)
|
||||
#define _nios2_creg_write(reg, val) __builtin_wrctl(reg, val)
|
||||
|
||||
#define _nios2_get_register_address(base, regnum) \
|
||||
((void *)(((uint8_t *)base) + ((regnum) * (SYSTEM_BUS_WIDTH / 8))))
|
||||
|
||||
static inline void _nios2_reg_write(void *base, int regnum, uint32_t data)
|
||||
{
|
||||
sys_write32(data, (mm_reg_t)_nios2_get_register_address(base, regnum));
|
||||
}
|
||||
|
||||
static inline uint32_t _nios2_reg_read(void *base, int regnum)
|
||||
{
|
||||
return sys_read32((mm_reg_t)_nios2_get_register_address(base, regnum));
|
||||
}
|
||||
|
||||
#endif /* _ASMLANGUAGE */
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue