#include <stdint.h>
#define DEFAULT_BAUDRATE (115200)
#define NS16550_BASE (0x62300000ULL)
#define NS16550_CLOCK_RATE (1000ULL * CLOCK_KHZ)
enum __attribute__ ((__packed__)) ier_t {
IER_ERBI = (1<<0),
IER_ETBEI = (1<<1),
IER_ELSI = (1<<2),
IER_EDSSI = (1<<3),
IER_SLEEP = (1<<4), // 16650 only
};
enum __attribute__ ((__packed__)) iir_t {
IIR_IP = 1,
IIR_NONE = 1,
IIR_RLSI = 6,
IIR_RDAI = 4,
IIR_CTOI = 0xc,
IIR_THRI = 2,
IIR_MSRI = 0,
IIR_F64E = 0x20,
IIR_FE = 0xc0,
};
enum __attribute__ ((__packed__)) fcr_t {
FCR_FE = 1,
FCR_RXFR = 2,
FCR_TXFR = 4,
FCR_DMS = 8,
FCR_F64E = 0x20,
FCR_RT1 = 0,
FCR_RT4 = 0x40,
FCR_RT8 = 0x80,
FCR_RT14 = 0xc0,
FCR_RT16 = 0x40,
FCR_RT32 = 0x80,
FCR_RT56 = 0xc0,
};
enum __attribute__ ((__packed__)) lcr_t {
LCR_WLS5 = 0,
LCR_WLS6 = 1,
LCR_WLS7 = 2,
LCR_WLS8 = 3,
LCR_STB = 4,
LCR_PEN = 8,
LCR_EPS = 0x10,
LCR_SP = 0x20,
LCR_BC = 0x40,
LCR_DLAB = 0x80,
};
enum __attribute__ ((__packed__)) mcr_t {
MCR_DTR = 1,
MCR_RTS = 2,
MCR_OUT1 = 4,
MCR_OUT2 = 8,
MCR_LOOP = 0x10,
MCR_AFE = 0x20,
};
enum __attribute__ ((__packed__)) lsr_t {
LSR_DR = 1,
LSR_OE = 2,
LSR_PE = 4,
LSR_FE = 8,
LSR_BI = 0x10,
LSR_THRE = 0x20,
LSR_TEMT = 0x40,
LSR_RXFE = 0x80,
};
enum __attribute__ ((__packed__)) msr_t {
MSR_DCTS = 1,
MSR_DDSR = 2,
MSR_TERI = 4,
MSR_DDCD = 8,
MSR_CTS = 0x10,
MSR_DSR = 0x20,
MSR_RI = 0x40,
MSR_DCD = 0x80,
};
struct __attribute__ ((aligned (4))) ns16550_pio {
// 0x000
union __attribute__ ((aligned (4))) {
const volatile uint8_t rbr;
volatile uint8_t thr;
volatile uint8_t dll;
};
// 0x004
union __attribute__ ((aligned (4))) {
volatile uint8_t dlm;
volatile enum ier_t ier;
};
// 0x008
union __attribute__ ((aligned (4))) {
const volatile enum iir_t iir;
volatile enum fcr_t fcr;
};
// 0x00c
volatile enum lcr_t lcr __attribute__ ((aligned (4)));
// 0x010
volatile enum mcr_t mcr __attribute__ ((aligned (4)));
// 0x014
volatile enum lsr_t lsr __attribute__ ((aligned (4)));
// 0x018
volatile uint8_t msr __attribute__ ((aligned (4)));
// 0x01c
volatile uint8_t scr __attribute__ ((aligned (4)));
};
static struct ns16550_pio * pio = (void*)NS16550_BASE;
__attribute__ ((constructor))
static int ns16550_init(void) {
uint32_t divisor;
pio->ier = 0;
divisor = NS16550_CLOCK_RATE / (16 * DEFAULT_BAUDRATE);
pio->lcr |= LCR_DLAB;
pio->dll = divisor & 0xff;
pio->dlm = (divisor >> 8) & 0xff;
pio->lcr &= ~LCR_DLAB;
pio->lcr = LCR_WLS8;
pio->fcr = FCR_FE;
pio->mcr = MCR_RTS;
return 0;
}
int ns16550_rxready(void) {
return ((pio->lsr & LSR_DR) != 0);
}
int ns16550_rxchar(void) {
while ((pio->lsr & LSR_DR) == 0)
; // nothing
return pio->rbr;
}
int ns16550_txchar(int c) {
while ((pio->lsr & LSR_THRE) == 0)
; // nothing
pio->thr = c;
return c;
}
void ns16550_flush(void) {
while ((pio->lsr & LSR_TEMT) == 0)
; // nothing
}
int _read(int file, char *ptr, int len) {
int count = 0;
while (ns16550_rxready() && (count < len)) {
*ptr++ = ns16550_rxchar();
count++;
}
return count;
}
int _write(int file, char *ptr, int len) {
int todo;
for (todo = 0; todo < len; todo++) {
ns16550_txchar (*ptr++);
}
return len;
}
没有合适的资源?快使用搜索试试~ 我知道了~
RISCV32IM-MCU-Eval软核
需积分: 8 1 下载量 125 浏览量
2023-03-29
09:53:42
上传
评论
收藏 1.23MB GZ 举报
温馨提示
共62个文件
v:14个
c:8个
tcl:8个
Arty A7-100 board上的定制RISC-V核,可以参考!
资源推荐
资源详情
资源评论
收起资源包目录
RISCV32IM_MCU_Eval-20210921.tar.gz (62个子文件)
RISCV32IM_MCU_Eval
cores
RISCV32IM_MCU
component.xml 73KB
hdl
BRAM1BELoad.v 4KB
FIFO20.v 4KB
SyncHandshake.v 4KB
FIFO2.v 5KB
MakeResetA.v 3KB
RISCV32IM_MCU.vp 874KB
RegFile.v 4KB
SyncResetA.v 3KB
FIFO1.v 4KB
ASSIGN1.v 83B
SyncWire.v 1KB
SyncFIFOLevel.v 18KB
FIFO10.v 4KB
ResetInverter.v 1KB
xgui
RISCV32IM_MCU_vE_1_0.tcl 195B
mkMCUTop_v1_0.tcl 195B
ips
jtag
xilinx_jtag.v 808B
component.xml 19KB
xgui
xilinx_jtag_v1_0.tcl 195B
utils
gdb
openocd.cfg 187B
digilent-hs1a.cfg 307B
target.cfg 3KB
init_32.gdb 437B
program_fpga 656B
elf_to_hex 25KB
tcl
build.tcl 2KB
soc.tcl 7KB
uartterm 363B
detect_uart.pl 379B
build_bitstream 3KB
create_soc_project 2KB
ref_apps
blinky
syscalls.c 1KB
bare.lds 164B
Makefile 3KB
tcm.mem 1.36MB
soc_map.h 387B
riscv_counters.c 1KB
uart.c 3KB
bare.specs 306B
main.c 1KB
riscv_counters.h 1001B
startup.S 624B
docs
user-guide.adoc 19KB
quick-ref.html 36KB
user-guide.html 67KB
platforms
arty_adsoc
tcl
sim.tcl 395B
bd.tcl 14KB
examples
add_bram_device
app
syscalls.c 1KB
bare.lds 164B
Makefile 3KB
soc_map.h 426B
riscv_counters.c 1KB
uart.c 3KB
bare.specs 306B
main.c 2KB
riscv_counters.h 1001B
startup.S 624B
add_new_device.tcl 3KB
README.html 33KB
xdc
arty_adsoc.xdc 3KB
ref_designs
arty_adsoc_mcu
demo.bit 3.65MB
共 62 条
- 1
资源评论
胡须渣
- 粉丝: 2
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 适用于tensorflow-2.11.0 CUDA版本11.2的cuDNN8.1版本
- 5Y study学习平台2016计算机基础-综合测试(8)_哔哩哔哩_bilibili_2580252704.mp4
- (大赛作品)STM32实现的F072RB NUCLEO智能家居控制.zip
- STM32实现的数字示波器源码+数字信号处理教程、配套实例.zip
- 【cookie续续】【cookie续续】【cookie续续】
- 低功耗STM32实现的F411开发板(原理图+PCB源文件+官方例程+驱动等).zip
- 基于stm32实现的 nucleo-L476的智能灯(操作说明+源码).zip
- 基于STM32实现的 NUCLEO板设计彩色LED照明灯(纯cubeMX开发).zip
- 基于STM32实现的 的联合调试侦听设备解决方案(原理图、PCB源文件、调试工具、视频).zip
- 基于STM32实现的 人群定位、调速智能风扇设计(程序、设计报告、视频演示).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功