move generic mmio functions to header file
This commit is contained in:
@@ -12,7 +12,7 @@ dumps: $(addsuffix .dump,$(PROGRAMS))
|
|||||||
%.o: %.S
|
%.o: %.S
|
||||||
$(GCC) $(CFLAGS) -D__ASSEMBLY__=1 -c $< -o $@
|
$(GCC) $(CFLAGS) -D__ASSEMBLY__=1 -c $< -o $@
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c mmio.h
|
||||||
$(GCC) $(CFLAGS) -c $< -o $@
|
$(GCC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
%.riscv: %.o crt.o syscalls.o
|
%.riscv: %.o crt.o syscalls.o
|
||||||
|
|||||||
16
tests/mmio.h
Normal file
16
tests/mmio.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef __MMIO_H__
|
||||||
|
#define __MMIO_H__
|
||||||
|
|
||||||
|
static inline void write_reg(unsigned long addr, unsigned int data)
|
||||||
|
{
|
||||||
|
volatile unsigned int *ptr = (volatile unsigned int *) addr;
|
||||||
|
*ptr = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline unsigned long read_reg(unsigned long addr)
|
||||||
|
{
|
||||||
|
volatile unsigned int *ptr = (volatile unsigned int *) addr;
|
||||||
|
return *ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
12
tests/pwm.c
12
tests/pwm.c
@@ -2,17 +2,7 @@
|
|||||||
#define PWM_DUTY 0x2004
|
#define PWM_DUTY 0x2004
|
||||||
#define PWM_ENABLE 0x2008
|
#define PWM_ENABLE 0x2008
|
||||||
|
|
||||||
static inline void write_reg(unsigned long addr, unsigned int data)
|
#include "mmio.h"
|
||||||
{
|
|
||||||
volatile unsigned int *ptr = (volatile unsigned int *) addr;
|
|
||||||
*ptr = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline unsigned long read_reg(unsigned long addr)
|
|
||||||
{
|
|
||||||
volatile unsigned int *ptr = (volatile unsigned int *) addr;
|
|
||||||
return *ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user