-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd2dfa2
commit 0670e5c
Showing
24 changed files
with
2,200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
output/ | ||
.obj/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# | ||
# Top makefile | ||
# | ||
|
||
CROSS ?= arm-none-eabi- | ||
NAME := ddr | ||
|
||
# | ||
# System environment variable. | ||
# | ||
ifeq ($(OS), Windows_NT) | ||
HOSTOS := windows | ||
else | ||
ifneq (,$(findstring Linux, $(shell uname -a))) | ||
HOSTOS := linux | ||
endif | ||
endif | ||
|
||
# | ||
# Load default variables. | ||
# | ||
ASFLAGS := -Os | ||
CFLAGS := -Os | ||
CXXFLAGS := -Os | ||
LDFLAGS := -T link.ld -nostdlib | ||
ARFLAGS := -rcs | ||
OCFLAGS := -v -O binary | ||
ODFLAGS := | ||
MCFLAGS := -nostdinc -nostdlib -g -ggdb -O3 -mcpu=cortex-a53 -Wno-builtin-declaration-mismatch -fno-short-enums | ||
|
||
LIBDIRS := -Llib | ||
LIBS := -lchipid -ldram | ||
INCDIRS := | ||
SRCDIRS := | ||
|
||
# | ||
# Add external library | ||
# | ||
INCDIRS += include | ||
SRCDIRS += source | ||
|
||
# | ||
# You shouldn't need to change anything below this point. | ||
# | ||
AS := $(CROSS)gcc -x assembler-with-cpp | ||
CC := $(CROSS)gcc | ||
CXX := $(CROSS)g++ | ||
LD := $(CROSS)ld | ||
AR := $(CROSS)ar | ||
OC := $(CROSS)objcopy | ||
OD := $(CROSS)objdump | ||
MKDIR := mkdir -p | ||
CP := cp -af | ||
RM := rm -fr | ||
CD := cd | ||
FIND := find | ||
|
||
# | ||
# X variables | ||
# | ||
G_ASFLAGS := $(MCFLAGS) $(ASFLAGS) | ||
G_CFLAGS := $(MCFLAGS) $(CFLAGS) | ||
G_CXXFLAGS := $(MCFLAGS) $(CXXFLAGS) | ||
G_LDFLAGS := $(LDFLAGS) | ||
G_OCFLAGS := $(OCFLAGS) | ||
G_LIBDIRS := $(LIBDIRS) | ||
G_LIBS := $(LIBS) -lgcc | ||
|
||
G_OUT := output | ||
G_NAME := $(patsubst %, $(G_OUT)/%, $(NAME)) | ||
G_INCDIRS := $(patsubst %, -I %, $(INCDIRS)) | ||
G_SRCDIRS := $(patsubst %, %, $(SRCDIRS)) | ||
G_OBJDIRS := $(patsubst %, .obj/%, $(G_SRCDIRS)) | ||
|
||
G_SFILES := $(foreach dir, $(G_SRCDIRS), $(wildcard $(dir)/*.S)) | ||
G_CFILES := $(foreach dir, $(G_SRCDIRS), $(wildcard $(dir)/*.c)) | ||
G_CPPFILES := $(foreach dir, $(G_SRCDIRS), $(wildcard $(dir)/*.cpp)) | ||
|
||
G_SDEPS := $(patsubst %, .obj/%, $(G_SFILES:.S=.o.d)) | ||
G_CDEPS := $(patsubst %, .obj/%, $(G_CFILES:.c=.o.d)) | ||
G_CPPDEPS := $(patsubst %, .obj/%, $(G_CPPFILES:.cpp=.o.d)) | ||
G_DEPS := $(G_SDEPS) $(G_CDEPS) $(G_CPPDEPS) | ||
|
||
G_SOBJS := $(patsubst %, .obj/%, $(G_SFILES:.S=.o)) | ||
G_COBJS := $(patsubst %, .obj/%, $(G_CFILES:.c=.o)) | ||
G_CPPOBJS := $(patsubst %, .obj/%, $(G_CPPFILES:.cpp=.o)) | ||
G_OBJS := $(G_SOBJS) $(G_COBJS) $(G_CPPOBJS) | ||
|
||
VPATH := $(G_OBJDIRS) | ||
|
||
.PHONY: all clean | ||
all : $(G_NAME) | ||
|
||
$(G_NAME) : $(G_OBJS) | ||
@echo [LD] Linking $@.elf | ||
@$(CC) $(G_LDFLAGS) $(G_LIBDIRS) -Wl,--cref,-Map=$@.map $^ -o $@.elf $(G_LIBS) | ||
@echo [OC] Objcopying $@.bin | ||
@$(OC) $(G_OCFLAGS) $@.elf $@.bin | ||
|
||
$(G_SOBJS) : .obj/%.o : %.S | ||
@echo [AS] $< | ||
@$(AS) $(G_ASFLAGS) -MD -MP -MF $@.d $(G_INCDIRS) -c $< -o $@ | ||
|
||
$(G_COBJS) : .obj/%.o : %.c | ||
@echo [CC] $< | ||
@$(CC) $(G_CFLAGS) -MD -MP -MF $@.d $(G_INCDIRS) -c $< -o $@ | ||
|
||
$(G_CPPOBJS) : .obj/%.o : %.cpp | ||
@echo [CXX] $< | ||
@$(CXX) $(G_CXXFLAGS) -MD -MP -MF $@.d $(G_INCDIRS) -c $< -o $@ | ||
|
||
clean: | ||
@$(RM) .obj $(G_OUT) | ||
|
||
# | ||
# Include the dependency files, should be place the last of makefile | ||
# | ||
sinclude $(shell $(MKDIR) $(G_OBJDIRS) $(G_OUT)) $(G_DEPS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#ifndef __BYTEORDER_H__ | ||
#define __BYTEORDER_H__ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <types.h> | ||
|
||
static inline u16_t __swab16(u16_t x) | ||
{ | ||
return ( (x<<8) | (x>>8) ); | ||
} | ||
|
||
static inline u32_t __swab32(u32_t x) | ||
{ | ||
return ( (x<<24) | (x>>24) | \ | ||
((x & (u32_t)0x0000ff00UL)<<8) | \ | ||
((x & (u32_t)0x00ff0000UL)>>8) ); | ||
} | ||
|
||
static inline u64_t __swab64(u64_t x) | ||
{ | ||
return ( (x<<56) | (x>>56) | \ | ||
((x & (u64_t)0x000000000000ff00ULL)<<40) | \ | ||
((x & (u64_t)0x0000000000ff0000ULL)<<24) | \ | ||
((x & (u64_t)0x00000000ff000000ULL)<< 8) | \ | ||
((x & (u64_t)0x000000ff00000000ULL)>> 8) | \ | ||
((x & (u64_t)0x0000ff0000000000ULL)>>24) | \ | ||
((x & (u64_t)0x00ff000000000000ULL)>>40) ); | ||
} | ||
|
||
/* | ||
* swap bytes bizarrely. | ||
* swahw32 - swap 16-bit half-words in a 32-bit word | ||
*/ | ||
static inline u32_t __swahw32(u32_t x) | ||
{ | ||
return ( ((x & (u32_t)0x0000ffffUL)<<16) | ((x & (u32_t)0xffff0000UL)>>16) ); | ||
} | ||
|
||
/* | ||
* swap bytes bizarrely. | ||
* swahb32 - swap 8-bit halves of each 16-bit half-word in a 32-bit word | ||
*/ | ||
static inline u32_t __swahb32(u32_t x) | ||
{ | ||
return ( ((x & (u32_t)0x00ff00ffUL)<<8) | ((x & (u32_t)0xff00ff00UL)>>8) ); | ||
} | ||
|
||
#if (BYTE_ORDER == BIG_ENDIAN) | ||
#define cpu_to_le64(x) (__swab64((u64_t)(x))) | ||
#define le64_to_cpu(x) (__swab64((u64_t)(x))) | ||
#define cpu_to_le32(x) (__swab32((u32_t)(x))) | ||
#define le32_to_cpu(x) (__swab32((u32_t)(x))) | ||
#define cpu_to_le16(x) (__swab16((u16_t)(x))) | ||
#define le16_to_cpu(x) (__swab16((u16_t)(x))) | ||
#define cpu_to_be64(x) ((u64_t)(x)) | ||
#define be64_to_cpu(x) ((u64_t)(x)) | ||
#define cpu_to_be32(x) ((u32_t)(x)) | ||
#define be32_to_cpu(x) ((u32_t)(x)) | ||
#define cpu_to_be16(x) ((u16_t)(x)) | ||
#define be16_to_cpu(x) ((u16_t)(x)) | ||
#else | ||
#define cpu_to_le64(x) ((u64_t)(x)) | ||
#define le64_to_cpu(x) ((u64_t)(x)) | ||
#define cpu_to_le32(x) ((u32_t)(x)) | ||
#define le32_to_cpu(x) ((u32_t)(x)) | ||
#define cpu_to_le16(x) ((u16_t)(x)) | ||
#define le16_to_cpu(x) ((u16_t)(x)) | ||
#define cpu_to_be64(x) (__swab64((u64_t)(x))) | ||
#define be64_to_cpu(x) (__swab64((u64_t)(x))) | ||
#define cpu_to_be32(x) (__swab32((u32_t)(x))) | ||
#define be32_to_cpu(x) (__swab32((u32_t)(x))) | ||
#define cpu_to_be16(x) (__swab16((u16_t)(x))) | ||
#define be16_to_cpu(x) (__swab16((u16_t)(x))) | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* __BYTEORDER_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef __ARM32_ENDIAN_H__ | ||
#define __ARM32_ENDIAN_H__ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#define LITTLE_ENDIAN (0x1234) | ||
#define BIG_ENDIAN (0x4321) | ||
|
||
#if ( !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN) ) | ||
#define __LITTLE_ENDIAN | ||
#endif | ||
|
||
#if defined(__LITTLE_ENDIAN) | ||
#define BYTE_ORDER LITTLE_ENDIAN | ||
#elif defined(__BIG_ENDIAN) | ||
#define BYTE_ORDER BIG_ENDIAN | ||
#else | ||
#error "Unknown byte order!" | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* __ARM32_ENDIAN_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#ifndef __IO_H__ | ||
#define __IO_H__ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <types.h> | ||
|
||
static inline u8_t read8(virtual_addr_t addr) | ||
{ | ||
return( *((volatile u8_t *)(addr)) ); | ||
} | ||
|
||
static inline u16_t read16(virtual_addr_t addr) | ||
{ | ||
return( *((volatile u16_t *)(addr)) ); | ||
} | ||
|
||
static inline u32_t read32(virtual_addr_t addr) | ||
{ | ||
return( *((volatile u32_t *)(addr)) ); | ||
} | ||
|
||
static inline u64_t read64(virtual_addr_t addr) | ||
{ | ||
return( *((volatile u64_t *)(addr)) ); | ||
} | ||
|
||
static inline void write8(virtual_addr_t addr, u8_t value) | ||
{ | ||
*((volatile u8_t *)(addr)) = value; | ||
} | ||
|
||
static inline void write16(virtual_addr_t addr, u16_t value) | ||
{ | ||
*((volatile u16_t *)(addr)) = value; | ||
} | ||
|
||
static inline void write32(virtual_addr_t addr, u32_t value) | ||
{ | ||
*((volatile u32_t *)(addr)) = value; | ||
} | ||
|
||
static inline void write64(virtual_addr_t addr, u64_t value) | ||
{ | ||
*((volatile u64_t *)(addr)) = value; | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* __IO_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef __RTC_H__ | ||
#define __RTC_H__ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#define SUNXI_RTC_BASE (0x07000000) | ||
#define SUNXI_RTC_DATA_BASE (SUNXI_RTC_BASE + 0x100) | ||
|
||
#define RTC_FEL_INDEX 2 | ||
|
||
void set_timer_count(); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* __RTC_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef __STDARG_H__ | ||
#define __STDARG_H__ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef __builtin_va_list va_list; | ||
|
||
/* | ||
* prepare to access variable args | ||
*/ | ||
#define va_start(v, l) __builtin_va_start(v, l) | ||
|
||
/* | ||
* the caller will get the value of current argument | ||
*/ | ||
#define va_arg(v, l) __builtin_va_arg(v, l) | ||
|
||
/* | ||
* end for variable args | ||
*/ | ||
#define va_end(v) __builtin_va_end(v) | ||
|
||
/* | ||
* copy variable args | ||
*/ | ||
#define va_copy(d, s) __builtin_va_copy(d, s) | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* __STDARG_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#ifndef __STDDEF_H__ | ||
#define __STDDEF_H__ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#if defined(__cplusplus) | ||
#define NULL (0) | ||
#else | ||
#define NULL ((void *)0) | ||
#endif | ||
|
||
#if (defined(__GNUC__) && (__GNUC__ >= 4)) | ||
#define offsetof(type, member) __builtin_offsetof(type, member) | ||
#else | ||
#define offsetof(type, field) ((size_t)(&((type *)0)->field)) | ||
#endif | ||
#define container_of(ptr, type, member) ({const typeof(((type *)0)->member) *__mptr = (ptr); (type *)((char *)__mptr - offsetof(type,member));}) | ||
|
||
#if (defined(__GNUC__) && (__GNUC__ >= 3)) | ||
#define likely(expr) (__builtin_expect(!!(expr), 1)) | ||
#define unlikely(expr) (__builtin_expect(!!(expr), 0)) | ||
#else | ||
#define likely(expr) (!!(expr)) | ||
#define unlikely(expr) (!!(expr)) | ||
#endif | ||
|
||
#define min(a, b) ({typeof(a) _amin = (a); typeof(b) _bmin = (b); (void)(&_amin == &_bmin); _amin < _bmin ? _amin : _bmin;}) | ||
#define max(a, b) ({typeof(a) _amax = (a); typeof(b) _bmax = (b); (void)(&_amax == &_bmax); _amax > _bmax ? _amax : _bmax;}) | ||
#define clamp(v, a, b) min(max(a, v), b) | ||
|
||
#define ifloor(x) ((x) > 0 ? (int)(x) : (int)((x) - 0.9999999999)) | ||
#define iround(x) ((x) > 0 ? (int)((x) + 0.5) : (int)((x) - 0.5)) | ||
#define iceil(x) ((x) > 0 ? (int)((x) + 0.9999999999) : (int)(x)) | ||
#define idiv255(x) ((((int)(x) + 1) * 257) >> 16) | ||
|
||
#define X(...) ("" #__VA_ARGS__ "") | ||
|
||
enum { | ||
FALSE = 0, | ||
TRUE = 1, | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* __STDDEF_H__ */ |
Oops, something went wrong.