[v821]remove v821 uart test payload

This commit is contained in:
Jiang Jianjun 2025-05-01 21:34:45 +08:00
parent 936512d6a4
commit fa8a294cd0
16 changed files with 0 additions and 968 deletions

View File

@ -1,10 +0,0 @@
#
# Normal rules
#
*~
#
# Generated files
#
/.obj
/output

View File

@ -1,120 +0,0 @@
#
# Top makefile
#
CROSS ?= ~/Documents/Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.8.1/bin/riscv64-unknown-linux-gnu-
NAME := uart
#
# System environment variable.
#
ifeq ($(OS), Windows_NT)
HOSTOS := windows
else
ifneq (,$(findstring Linux, $(shell uname -a)))
HOSTOS := linux
endif
endif
#
# Load default variables.
#
ASFLAGS := -g -ggdb -Wall -O3 -ffreestanding
CFLAGS := -g -ggdb -Wall -O3 -ffreestanding
CXXFLAGS := -g -ggdb -Wall -O3 -ffreestanding
LDFLAGS := -T link.ld -nostdlib
ARFLAGS := -rcs
OCFLAGS := -v -O binary
ODFLAGS :=
MCFLAGS := -march=rv32imacxtheade -mabi=ilp32 -mtune=e907 -mcmodel=medany -fno-stack-protector
LIBDIRS :=
LIBS :=
INCDIRS :=
SRCDIRS :=
#
# Add external library
#
INCDIRS += include \
include/external
SRCDIRS += source \
source/external
#
# 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
#
X_ASFLAGS := $(MCFLAGS) $(ASFLAGS)
X_CFLAGS := $(MCFLAGS) $(CFLAGS)
X_CXXFLAGS := $(MCFLAGS) $(CXXFLAGS)
X_LDFLAGS := $(LDFLAGS)
X_OCFLAGS := $(OCFLAGS)
X_LIBDIRS := $(LIBDIRS)
X_LIBS := $(LIBS) -lgcc
X_OUT := output
X_NAME := $(patsubst %, $(X_OUT)/%, $(NAME))
X_INCDIRS := $(patsubst %, -I %, $(INCDIRS))
X_SRCDIRS := $(patsubst %, %, $(SRCDIRS))
X_OBJDIRS := $(patsubst %, .obj/%, $(X_SRCDIRS))
X_SFILES := $(foreach dir, $(X_SRCDIRS), $(wildcard $(dir)/*.S))
X_CFILES := $(foreach dir, $(X_SRCDIRS), $(wildcard $(dir)/*.c))
X_CPPFILES := $(foreach dir, $(X_SRCDIRS), $(wildcard $(dir)/*.cpp))
X_SDEPS := $(patsubst %, .obj/%, $(X_SFILES:.S=.o.d))
X_CDEPS := $(patsubst %, .obj/%, $(X_CFILES:.c=.o.d))
X_CPPDEPS := $(patsubst %, .obj/%, $(X_CPPFILES:.cpp=.o.d))
X_DEPS := $(X_SDEPS) $(X_CDEPS) $(X_CPPDEPS)
X_SOBJS := $(patsubst %, .obj/%, $(X_SFILES:.S=.o))
X_COBJS := $(patsubst %, .obj/%, $(X_CFILES:.c=.o))
X_CPPOBJS := $(patsubst %, .obj/%, $(X_CPPFILES:.cpp=.o))
X_OBJS := $(X_SOBJS) $(X_COBJS) $(X_CPPOBJS)
VPATH := $(X_OBJDIRS)
.PHONY: all clean
all : $(X_NAME)
$(X_NAME) : $(X_OBJS)
@echo [LD] Linking $@.elf
@$(CC) $(X_LDFLAGS) $(X_LIBDIRS) -Wl,--cref,-Map=$@.map $^ -o $@.elf $(X_LIBS)
@echo [OC] Objcopying $@.bin
@$(OC) $(X_OCFLAGS) $@.elf $@.bin
$(X_SOBJS) : .obj/%.o : %.S
@echo [AS] $<
@$(AS) $(X_ASFLAGS) -MD -MP -MF $@.d $(X_INCDIRS) -c $< -o $@
$(X_COBJS) : .obj/%.o : %.c
@echo [CC] $<
@$(CC) $(X_CFLAGS) -MD -MP -MF $@.d $(X_INCDIRS) -c $< -o $@
$(X_CPPOBJS) : .obj/%.o : %.cpp
@echo [CXX] $<
@$(CXX) $(X_CXXFLAGS) -MD -MP -MF $@.d $(X_INCDIRS) -c $< -o $@
clean:
@$(RM) .obj $(X_OUT)
#
# Include the dependency files, should be place the last of makefile
#
sinclude $(shell $(MKDIR) $(X_OBJDIRS) $(X_OUT)) $(X_DEPS)

View File

@ -1,83 +0,0 @@
#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__ */

View File

@ -1,27 +0,0 @@
#ifndef __RISCV64_ENDIAN_H__
#define __RISCV64_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 /* __RISCV64_ENDIAN_H__ */

View File

@ -1,54 +0,0 @@
#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__ */

View File

@ -1,24 +0,0 @@
#ifndef __RISCV_LINKAGE_H__
#define __RISCV_LINKAGE_H__
#ifdef __cplusplus
extern "C" {
#endif
#if __riscv_xlen == 64
#define LREG ld
#define SREG sd
#define REGSZ 8
#define RVPTR .dword
#elif __riscv_xlen == 32
#define LREG lw
#define SREG sw
#define REGSZ 4
#define RVPTR .word
#endif
#ifdef __cplusplus
}
#endif
#endif /* __RISCV_LINKAGE_H__ */

View File

@ -1,113 +0,0 @@
#ifndef __RISCV32_H__
#define __RISCV32_H__
#ifdef __cplusplus
extern "C" {
#endif
#define MSTATUS_UIE (1 << 0)
#define MSTATUS_SIE (1 << 1)
#define MSTATUS_MIE (1 << 3)
#define MSTATUS_UPIE (1 << 4)
#define MSTATUS_SPIE (1 << 5)
#define MSTATUS_MPIE (1 << 7)
#define MSTATUS_SPP (1 << 8)
#define MSTATUS_MPP (3 << 11)
#define MSTATUS_FS (3 << 13)
#define MSTATUS_XS (3 << 15)
#define MSTATUS_MPRV (1 << 17)
#define MSTATUS_SUM (1 << 18)
#define MSTATUS_MXR (1 << 19)
#define MSTATUS_TVM (1 << 20)
#define MSTATUS_TW (1 << 21)
#define MSTATUS_TSR (1 << 22)
#define MSTATUS32_SD (1 << 31)
#define MSTATUS_UXL (3ULL << 32)
#define MSTATUS_SXL (3ULL << 34)
#define MSTATUS64_SD (1ULL << 63)
#define MIP_USIP (1 << 0)
#define MIP_SSIP (1 << 1)
#define MIP_MSIP (1 << 3)
#define MIP_UTIP (1 << 4)
#define MIP_STIP (1 << 5)
#define MIP_MTIP (1 << 7)
#define MIP_UEIP (1 << 8)
#define MIP_SEIP (1 << 9)
#define MIP_MEIP (1 << 11)
#define MIE_USIE (1 << 0)
#define MIE_SSIE (1 << 1)
#define MIE_MSIE (1 << 3)
#define MIE_UTIE (1 << 4)
#define MIE_STIE (1 << 5)
#define MIE_MTIE (1 << 7)
#define MIE_UEIE (1 << 8)
#define MIE_SEIE (1 << 9)
#define MIE_MEIE (1 << 11)
#define csr_swap(csr, val) \
({ \
unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrrw %0, " #csr ", %1" \
: "=r" (__v) : "rK" (__v) \
: "memory"); \
__v; \
})
#define csr_read(csr) \
({ \
register unsigned long __v; \
__asm__ __volatile__ ("csrr %0, " #csr \
: "=r" (__v) : \
: "memory"); \
__v; \
})
#define csr_write(csr, val) \
({ \
unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrw " #csr ", %0" \
: : "rK" (__v) \
: "memory"); \
})
#define csr_read_set(csr, val) \
({ \
unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrrs %0, " #csr ", %1" \
: "=r" (__v) : "rK" (__v) \
: "memory"); \
__v; \
})
#define csr_set(csr, val) \
({ \
unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrs " #csr ", %0" \
: : "rK" (__v) \
: "memory"); \
})
#define csr_read_clear(csr, val) \
({ \
unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrrc %0, " #csr ", %1" \
: "=r" (__v) : "rK" (__v) \
: "memory"); \
__v; \
})
#define csr_clear(csr, val) \
({ \
unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrc " #csr ", %0" \
: : "rK" (__v) \
: "memory"); \
})
#ifdef __cplusplus
}
#endif
#endif /* __RISCV32_H__ */

View File

@ -1,34 +0,0 @@
#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__ */

View File

@ -1,49 +0,0 @@
#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__ */

View File

@ -1,31 +0,0 @@
#ifndef __STDINT_H__
#define __STDINT_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <types.h>
typedef s8_t int8_t;
typedef u8_t uint8_t;
typedef s16_t int16_t;
typedef u16_t uint16_t;
typedef s32_t int32_t;
typedef u32_t uint32_t;
typedef s64_t int64_t;
typedef u64_t uint64_t;
#define UINT8_MAX (0xff)
#define UINT16_MAX (0xffff)
#define UINT32_MAX (0xffffffff)
#define UINT64_MAX (0xffffffffffffffffULL)
#ifdef __cplusplus
}
#endif
#endif /* __STDINT_H__ */

View File

@ -1,17 +0,0 @@
#ifndef __STRING_H__
#define __STRING_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <types.h>
void * memset(void * s, int c, size_t n);
void * memcpy(void * dest, const void * src, size_t len);
#ifdef __cplusplus
}
#endif
#endif /* __STRING_H__ */

View File

@ -1,53 +0,0 @@
#ifndef __RISCV32_TYPES_H__
#define __RISCV32_TYPES_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef signed char s8_t;
typedef unsigned char u8_t;
typedef signed short s16_t;
typedef unsigned short u16_t;
typedef signed int s32_t;
typedef unsigned int u32_t;
typedef signed long long s64_t;
typedef unsigned long long u64_t;
typedef signed long long intmax_t;
typedef unsigned long long uintmax_t;
typedef signed int ptrdiff_t;
typedef signed int intptr_t;
typedef unsigned int uintptr_t;
typedef unsigned int size_t;
typedef signed int ssize_t;
typedef signed int off_t;
typedef signed long long loff_t;
typedef signed int bool_t;
typedef unsigned int irq_flags_t;
typedef unsigned int virtual_addr_t;
typedef unsigned int virtual_size_t;
typedef unsigned int physical_addr_t;
typedef unsigned int physical_size_t;
typedef struct {
volatile int counter;
} atomic_t;
typedef struct {
volatile int lock;
} spinlock_t;
#ifdef __cplusplus
}
#endif
#endif /* __RISCV32_TYPES_H__ */

View File

@ -1,21 +0,0 @@
#ifndef __XBOOT_H__
#define __XBOOT_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <types.h>
#include <io.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <endian.h>
#include <byteorder.h>
#ifdef __cplusplus
}
#endif
#endif /* __XBOOT_H__ */

View File

@ -1,82 +0,0 @@
OUTPUT_FORMAT("elf32-littleriscv", "elf32-littleriscv", "elf32-littleriscv")
OUTPUT_ARCH(riscv)
ENTRY(_start)
STACK_SIZE = 0x100;
MEMORY
{
ram : org = 0x02020800, len = 0x00001000 /* 4KB */
}
SECTIONS
{
.text :
{
PROVIDE(__image_start = .);
PROVIDE(__text_start = .);
.obj/source/start.o (.text*)
*(.text*)
*(.iplt)
*(.note.gnu.build-id)
PROVIDE(__text_end = .);
} > ram
.ksymtab ALIGN(16) :
{
PROVIDE(__ksymtab_start = .);
KEEP(*(.ksymtab.text))
PROVIDE(__ksymtab_end = .);
} > ram
.romdisk ALIGN(8) :
{
PROVIDE(__romdisk_start = .);
KEEP(*(.romdisk))
PROVIDE(__romdisk_end = .);
} > ram
.rodata ALIGN(8) :
{
PROVIDE(__rodata_start = .);
*(.rodata*)
*(.srodata*)
PROVIDE(__rodata_end = .);
} > ram
.data ALIGN(8) :
{
PROVIDE(__data_start = .);
PROVIDE(__global_pointer$ = . + 0x800);
*(.sdata*)
*(.data*)
. = ALIGN(8);
PROVIDE(__data_end = .);
PROVIDE(__image_end = .);
} > ram
.bss ALIGN(8) (NOLOAD) :
{
PROVIDE(__bss_start = .);
*(.bss*)
*(.sbss*)
*(COMMON)
. = ALIGN(8);
PROVIDE(__bss_end = .);
} > ram
.stack ALIGN(16) (NOLOAD) :
{
PROVIDE(__stack_start = .);
. += STACK_SIZE;
. = ALIGN(16);
PROVIDE(__stack_end = .);
} > ram
/DISCARD/ : { *(.dynsym) }
/DISCARD/ : { *(.dynstr*) }
/DISCARD/ : { *(.dynamic*) }
/DISCARD/ : { *(.plt*) }
/DISCARD/ : { *(.interp*) }
/DISCARD/ : { *(.gnu*) }
}

View File

@ -1,58 +0,0 @@
/*
* start.S
*
* Copyright(c) 2007-2021 Jianjun Jiang <8192542@qq.com>
* Official site: http://xboot.org
* Mobile phone: +86-18665388956
* QQ: 8192542
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#include <linkage.h>
#include <riscv32.h>
.global _start
_start:
li t1, 0x1 << 22
csrs mxstatus, t1
fence.i
j reset
reset:
addi sp, sp, -32
sw s0, 8(sp)
sw s1, 16(sp)
sw ra, 24(sp)
mv s0, a0
jal sys_uart_init
li a0, 'O'
jal sys_uart_putc
li a0, 'K'
jal sys_uart_putc
li a0, 'X'
jal sys_uart_putc
lw ra, 24(sp)
lw s0, 8(sp)
lw s1, 16(sp)
addi sp, sp, 32
jr ra

View File

@ -1,192 +0,0 @@
/*
* sys-uart.c
*
* Copyright(c) 2007-2021 Jianjun Jiang <8192542@qq.com>
* Official site: http://xboot.org
* Mobile phone: +86-18665388956
* QQ: 8192542
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#include <xboot.h>
void sys_uart_init(void)
{
#if 0
virtual_addr_t addr;
u32_t val;
/* Config GPIOE2 and GPIOE3 to txd0 and rxd0 */
addr = 0x020000c0 + 0x0;
val = read32(addr);
val &= ~(0xf << ((2 & 0x7) << 2));
val |= ((0x6 & 0xf) << ((2 & 0x7) << 2));
write32(addr, val);
val = read32(addr);
val &= ~(0xf << ((3 & 0x7) << 2));
val |= ((0x6 & 0xf) << ((3 & 0x7) << 2));
write32(addr, val);
/* Open the clock gate for uart0 */
addr = 0x0200190c;
val = read32(addr);
val |= 1 << 0;
write32(addr, val);
/* Deassert uart0 reset */
addr = 0x0200190c;
val = read32(addr);
val |= 1 << 16;
write32(addr, val);
/* Config uart0 to 115200-8-1-0 */
addr = 0x42500000;
write32(addr + 0x04, 0x0);
write32(addr + 0x08, 0xf7);
write32(addr + 0x10, 0x0);
val = read32(addr + 0x0c);
val |= (1 << 7);
write32(addr + 0x0c, val);
write32(addr + 0x00, 0xd & 0xff);
write32(addr + 0x04, (0xd >> 8) & 0xff);
val = read32(addr + 0x0c);
val &= ~(1 << 7);
write32(addr + 0x0c, val);
val = read32(addr + 0x0c);
val &= ~0x1f;
val |= (0x3 << 0) | (0 << 2) | (0x0 << 3);
write32(addr + 0x0c, val);
#endif
}
void sys_uart_putc(char c)
{
virtual_addr_t addr = 0x42500000;
while((read32(addr + 0x7c) & (0x1 << 1)) == 0);
write32(addr + 0x00, c);
}
#if 0
static int vpf_str_to_num(const char * fmt, int * num)
{
const char * p;
int res, d, isd;
res = 0;
for(p = fmt; *fmt != '\0'; p++)
{
isd = (*p >= '0' && *p <= '9');
if(!isd)
break;
d = *p - '0';
res *= 10;
res += d;
}
*num = res;
return ((int)(p - fmt));
}
static void vpf_num_to_str(uint32_t a, int ish, int pl, int pc)
{
char buf[32];
uint32_t base;
int idx, i, t;
for(i = 0; i < sizeof(buf); i++)
buf[i] = pc;
base = 10;
if(ish)
base = 16;
idx = 0;
do {
t = a % base;
if(t >= 10)
buf[idx] = t - 10 + 'a';
else
buf[idx] = t + '0';
a /= base;
idx++;
} while (a > 0);
if(pl > 0)
{
if(pl >= sizeof(buf))
pl = sizeof(buf) - 1;
if(idx < pl)
idx = pl;
}
buf[idx] = '\0';
for(i = idx - 1; i >= 0; i--)
sys_uart_putc(buf[i]);
}
static int vpf(const char * fmt, va_list va)
{
const char * p, * q;
int f, c, vai, pl, pc, i;
unsigned char t;
pc = ' ';
for(p = fmt; *p != '\0'; p++)
{
f = 0;
pl = 0;
c = *p;
q = p;
if(*p == '%')
{
q = p;
p++;
if(*p >= '0' && *p <= '9')
p += vpf_str_to_num(p, &pl);
f = *p;
}
if((f == 'd') || (f == 'x'))
{
vai = va_arg(va, int);
vpf_num_to_str(vai, f == 'x', pl, pc);
}
else
{
for(i = 0; i < (p - q); i++)
sys_uart_putc(q[i]);
t = (unsigned char)(f != 0 ? f : c);
sys_uart_putc(t);
}
}
return 0;
}
int sys_uart_printf(const char * fmt, ...)
{
va_list va;
va_start(va, fmt);
vpf(fmt, va);
va_end(va);
return 0;
}
#endif