From 44aa4e25a9e0817bb5d0764eb0d4c736fd2dc50f Mon Sep 17 00:00:00 2001 From: Howard Mao Date: Mon, 29 May 2017 14:33:30 -0700 Subject: [PATCH] move generic mmio functions to header file --- tests/Makefile | 2 +- tests/mmio.h | 16 ++++++++++++++++ tests/pwm.c | 12 +----------- 3 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 tests/mmio.h diff --git a/tests/Makefile b/tests/Makefile index 000856ac..94d7d434 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -12,7 +12,7 @@ dumps: $(addsuffix .dump,$(PROGRAMS)) %.o: %.S $(GCC) $(CFLAGS) -D__ASSEMBLY__=1 -c $< -o $@ -%.o: %.c +%.o: %.c mmio.h $(GCC) $(CFLAGS) -c $< -o $@ %.riscv: %.o crt.o syscalls.o diff --git a/tests/mmio.h b/tests/mmio.h new file mode 100644 index 00000000..3fb791c6 --- /dev/null +++ b/tests/mmio.h @@ -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 diff --git a/tests/pwm.c b/tests/pwm.c index 5b99bfff..77c56424 100644 --- a/tests/pwm.c +++ b/tests/pwm.c @@ -2,17 +2,7 @@ #define PWM_DUTY 0x2004 #define PWM_ENABLE 0x2008 -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; -} +#include "mmio.h" int main(void) {