- fixed bootloader

- bootloader added board file
- refactored header files
- constify constants

git-svn-id: http://moon:8086/svn/mips@99 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
2017-01-18 22:28:07 +00:00
parent 702cb814a1
commit cf233c4d81
21 changed files with 289 additions and 172 deletions
+21 -15
View File
@@ -12,7 +12,7 @@ else
ENDIAN_FLAGS=-EB
endif
CFLAGS=$(ENDIAN_FLAGS) -Os -I. -I../ -I../libsys -msoft-float -march=r3000 -G0
CFLAGS=$(ENDIAN_FLAGS) -Os -I. -I../libsys -msoft-float -march=r3000 -G0 -I../libsys/boards/$(BOARD) -D$(BOARD)
LFLAGS=$(ENDIAN_FLAGS)
ifeq ($(TLB),yes)
@@ -38,9 +38,15 @@ ROMGEN=$(MIPS_HOME)/tools/romgen
all: $(BUILD_DIR) $(BUILD_DIR)/bootloader.elf $(BUILD_DIR)/bootloader_with_flash.elf
OBJS-ml402=$(addprefix $(BUILD_DIR)/, startup.o kernel.o libsys.o)
OBJS-denano=$(addprefix $(BUILD_DIR)/, startup.o kernel.o libsys.o)
OBJS-ml402=$(addprefix $(BUILD_DIR)/, startup.o kernel.o libsys.o board.o uart.o)
OBJS-denano=$(addprefix $(BUILD_DIR)/, startup.o kernel.o libsys.o board.o uart.o)
$(BUILD_DIR)/uart.o : ../libsys/uart.c
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR)/board.o : boards/$(BOARD)/board.c
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR)/%.o : %.c
$(CC) $(CFLAGS) -c -o $@ $<
@@ -48,20 +54,20 @@ $(BUILD_DIR)/%.o : %.S
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR)/bootloader.elf: $(OBJS-$(BOARD)) bootloader.c
$(CC) $(CFLAGS) -g -c bootloader.c
$(LD) $(LFLAGS) $(LIB_DIRS) $(OBJS-$(BOARD)) bootloader.o -o $@.elf $(LIBS) >$@.map
$(OBJDUMP) -D $@.elf > $@.dis
$(OBJCOPY) $@.elf -j ROM --output-target=binary $@.ROM.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(CC) $(CFLAGS) -o $(BUILD_DIR)/bootloader.o -g -c bootloader.c
$(LD) $(LFLAGS) $(LIB_DIRS) $(OBJS-$(BOARD)) bootloader.o -o $@ $(LIBS) >$@.map
$(OBJDUMP) -D $@ > $@.dis
$(OBJCOPY) $@ -j ROM --output-target=binary $@.ROM.bin
$(OBJCOPY) -O srec $@ $@.srec
$(ROMGEN) $@.ROM.bin 11 $(ENDIAN_FLAGS)
$(BUILD_DIR)/bootloader_with_flash.elf: $(OBJS-$(BOARD)) bootloader_with_flash.c ../cfiflash.c
$(CC) $(CFLAGS) -g -c bootloader_with_flash.c
$(CC) $(CFLAGS) -g -c ../cfiflash.c
$(LD) $(LFLAGS) $(LIB_DIRS) $(OBJS-$(BOARD)) cfiflash.o bootloader_with_flash.o -o $@.elf $(LIBS) >$@.map
$(OBJDUMP) -D $@.elf > $@.dis
$(OBJCOPY) $@.elf -j ROM --output-target=binary $@.ROM.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(CC) $(CFLAGS) -o $(BUILD_DIR)/bootloader_with_flash.o -g -c bootloader_with_flash.c
$(CC) $(CFLAGS) -o $(BUILD_DIR)/cfiflash.o -g -c ../cfiflash.c
$(LD) $(LFLAGS) $(LIB_DIRS) $(OBJS-$(BOARD)) cfiflash.o bootloader_with_flash.o -o $@ $(LIBS) >$@.map
$(OBJDUMP) -D $@ > $@.dis
$(OBJCOPY) $@ -j ROM --output-target=binary $@.ROM.bin
$(OBJCOPY) -O srec $@ $@.srec
$(ROMGEN) $@.ROM.bin 11 $(ENDIAN_FLAGS)
$(BUILD_DIR):
+89
View File
@@ -0,0 +1,89 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
#include <stddef.h>
#include "../../../libsys/boards/denano/board.h"
#include "../../../libsys/uart.h"
#include "../../../libsys/irq.h"
#define DEBUGGER gdb_stub
extern uart_if_t uart_if[];
#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
static uart_if_t const *dbg_uart = NULL;
static volatile uint32_t *pGpioData = (uint32_t*)SYS_GPIO_0_DATA;
static volatile uint32_t *pGpioDir = (uint32_t*)SYS_GPIO_0_DIR;
static uint32_t led_count = 0;
extern int dbg_handler(struct xcptcontext * xcp);
extern void handle_exception (unsigned long *registers);
int gdb_stub(struct xcptcontext * xcp)
{
// handle_exception((unsigned long *)xcp);
return 0;
}
void dbg_uart_isr(struct xcptcontext *xcp)
{
if(SYS_UART_BIT_RX_AVAIL & *dbg_uart->pCTRL)
{
char c = *dbg_uart->pDATA;
if (c == 3)
{
DEBUGGER(xcp);
}
}
}
void dbg_uart_setup()
{
const int UART_INT = SYS_INT_UART1;
dbg_uart = (uart_if_t*)&uart_if[1];
*dbg_uart->pCTRL = SYS_UART_BIT_RX_INTEN;
}
inline void _dbg_writechar(uart_if_t const *pUart, char c)
{
while((SYS_UART_BIT_TX_HALFFULL & *pUart->pCTRL) != 0);
*pUart->pDATA = (uint32_t)c;
}
inline char _dbg_readchar(uart_if_t const *pUart)
{
// busy read
while(!(SYS_UART_BIT_RX_AVAIL & *pUart->pCTRL))
{
(*pGpioData) = (led_count++) >> 16;
}
led_count = 0;
return (*pUart->pDATA & 0xFF);
}
void dbg_putchar(char c)
{
if (c == 0x0A)
{
_dbg_writechar(dbg_uart, 0x0D);
}
_dbg_writechar(dbg_uart, c);
}
char dbg_getchar()
{
return (char)_dbg_readchar(dbg_uart);
}
void board_init(void)
{
}
+89
View File
@@ -0,0 +1,89 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
#include <stddef.h>
#include "../../../libsys/boards/ml402/board.h"
#include "../../../libsys/uart.h"
#include "../../../libsys/irq.h"
#define DEBUGGER gdb_stub
extern uart_if_t uart_if[];
#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
static uart_if_t const *dbg_uart = NULL;
static volatile uint32_t *pGpioData = (uint32_t*)SYS_GPIO_0_DATA;
static volatile uint32_t *pGpioDir = (uint32_t*)SYS_GPIO_0_DIR;
static uint32_t led_count = 0;
extern int dbg_handler(struct xcptcontext * xcp);
extern void handle_exception (unsigned long *registers);
int gdb_stub(struct xcptcontext * xcp)
{
// handle_exception((unsigned long *)xcp);
return 0;
}
void dbg_uart_isr(struct xcptcontext *xcp)
{
if(SYS_UART_BIT_RX_AVAIL & *dbg_uart->pCTRL)
{
char c = *dbg_uart->pDATA;
if (c == 3)
{
DEBUGGER(xcp);
}
}
}
void dbg_uart_setup()
{
const int UART_INT = SYS_INT_UART;
dbg_uart = (uart_if_t*)&uart_if[1];
*dbg_uart->pCTRL = SYS_UART_BIT_RX_INTEN;
}
inline void _dbg_writechar(uart_if_t const *pUart, char c)
{
while((SYS_UART_BIT_TX_HALFFULL & *pUart->pCTRL) != 0);
*pUart->pDATA = (uint32_t)c;
}
inline char _dbg_readchar(uart_if_t const *pUart)
{
// busy read
while(!(SYS_UART_BIT_RX_AVAIL & *pUart->pCTRL))
{
(*pGpioData) = (led_count++) >> 16;
}
led_count = 0;
return (*pUart->pDATA & 0xFF);
}
void dbg_putchar(char c)
{
if (c == 0x0A)
{
_dbg_writechar(dbg_uart, 0x0D);
}
_dbg_writechar(dbg_uart, c);
}
char dbg_getchar()
{
return (char)_dbg_readchar(dbg_uart);
}
void board_init(void)
{
}
+1
View File
@@ -1,3 +1,4 @@
#include <board.h>
#include "libsys.h"
#define MAGIC_EB 0x4A464931 // "JFI1" in big-endian;
+4 -3
View File
@@ -1,5 +1,6 @@
#include <board.h>
#include "libsys.h"
#include "cfiflash.h"
#include "../cfiflash.h"
#define MAGIC_EB 0x4A464931 // "JFI1" in big-endian;
#define MAGIC_EL 0x3149464A // "JFI1" in little-endian;
@@ -235,7 +236,7 @@ int main(int argc, char *argv[])
*pGPIO_DIR = GPIO_0_DFLT_DIR;
*pGPIO_DATA = GPIO_0_DFLT_DATA;
haddr = 0;
block_sel = 0x7F & (uint32_t)((*pGPIO_DATA & GPIO_0_DIP) >> GPIO_0_ALIGN_DIP);
block_sel = 0x7F & (uint32_t)((*pGPIO_DATA & GPIO_0_MASK_DIP) >> GPIO_0_ALIGN_DIP);
sputs("\nMIPS bootloader\n");
// ----------------------------------------------------------
@@ -251,7 +252,7 @@ int main(int argc, char *argv[])
ram32 = (uint32_t*)(SDRAM_BASE);
pFlashIO = (uint32_t*)(SYS_FLASH_IO + flash_offset);
if (!(((*pGPIO_DATA & GPIO_0_BTN) >> GPIO_0_ALIGN_BTN) & 8))
if (!(((*pGPIO_DATA & GPIO_0_MASK_BTN) >> GPIO_0_ALIGN_BTN) & 8))
{
sputs("Loading image from flash at ");print_word(flash_offset);sputs("\n");
pImg_hdr = (flash_img_hdr_t*)pFlashIO;
+13 -17
View File
@@ -5,6 +5,9 @@
#include <errno.h>
#include <stdlib.h>
#include "libsys.h"
#include "../../uart.h"
extern uart_if_t uart_if[];
// ---------------------------------------------------------------------------------
void _exit(int reason)
@@ -14,12 +17,6 @@ void _exit(int reason)
while(1);
}
void libsys_init()
{
// Initialzie interrupt support
// interrupt_init();
}
// MIPS specific
uint32_t CP0_SR_read(void)
{
@@ -141,22 +138,21 @@ void DCACHE_invalidate_at(uint32_t* pPtr)
// ---------------------------------------------------------------------------------
char readchar(void)
{
volatile uint32_t *pUART_stat = (uint32_t*)SYS_UART_STAT;
volatile uint32_t *pUART_data = (uint32_t*)SYS_UART_DATA;
int c;
while(!(0x10 & *pUART_stat));
return (char)*pUART_data;
// busy read
do
{
c = UART_readchar(&uart_if[0]);
} while(c < 0);
return (char)c;
}
void writechar(char c)
{
volatile uint32_t *pUART_stat = (uint32_t*)SYS_UART_STAT;
volatile uint32_t *pUART_data = (uint32_t*)SYS_UART_DATA;
while((0x02 & *pUART_stat) != 0);
*pUART_data = (uint32_t)c;
UART_writechar(&uart_if[0], c);
}
void _putchar(char c)
-90
View File
@@ -9,96 +9,6 @@
#define LSYS_ERR_BASE 0x80000000
#define IS_ERROR(e) ((e & LSYS_ERR_BASE) == LSYS_ERR_BASE)
#ifndef SYS_IO_BASE
#define SYS_IO_BASE 0xA0000000
#endif
#ifndef SDRAM_BASE
#define SDRAM_BASE 0x40000000
#endif
#ifndef FLASH_BASE_IO
#define FLASH_BASE_IO 0xA4000000
#endif
#ifndef FLASH_BASE_MEM
#define FLASH_BASE_MEM 0x00000000
#endif
#define SYS_GPIO_0_DATA (SYS_IO_BASE + 0x0)
#define SYS_GPIO_0_DIR (SYS_IO_BASE + 0x4)
#define GPIO_0_DFLT_DIR (GPIO_0_LED | GPIO_0_USB_RST | GPIO_0_USB_INTEN | GPIO_0_AC97_INTEN | GPIO_0_PHY_RST | GPIO_0_PHY_MDC)
#define GPIO_0_DFLT_DATA ((~GPIO_0_LED & GPIO_0_LED) | GPIO_0_USB_RST | (~GPIO_0_USB_INTEN & GPIO_0_USB_INTEN) | (~GPIO_0_AC97_INTEN & GPIO_0_AC97_INTEN) | GPIO_0_PHY_RST | (~GPIO_0_PHY_MDC & GPIO_0_PHY_MDC))
#define GPIO_0_LED 0x000001FF
#define GPIO_0_BTN 0x1F000000
#define GPIO_0_DIP 0x00FF0000
#define GPIO_0_USB_RST 0x00001000
#define GPIO_0_USB_INTEN 0x00002000
#define GPIO_0_AC97_INTEN 0x00008000
#define GPIO_0_PHY_RST 0x20000000
#define GPIO_0_PHY_MDC 0x40000000
#define GPIO_0_PHY_MDIO 0x80000000
#define GPIO_0_ALIGN_LED 0
#define GPIO_0_ALIGN_DIP 16
#define GPIO_0_ALIGN_BTN 24
#define GPIO_0_ALIGN_MDIO 31
#define SYS_TIMER_USEC (SYS_IO_BASE + 0x8)
#define SYS_TIMER_SEC (SYS_IO_BASE + 0xC)
#define SYS_ITIM_CTRL (SYS_IO_BASE + 0x18)
#define SYS_ITIM_STAT (SYS_IO_BASE + 0x1C)
#define SYS_ITIM0_CNT (SYS_IO_BASE + 0x20)
#define SYS_ITIM1_CNT (SYS_IO_BASE + 0x24)
#define SYS_ITIM2_CNT (SYS_IO_BASE + 0x28)
#define SYS_ITIM3_CNT (SYS_IO_BASE + 0x2C)
#define SYS_ITIM0_CMP (SYS_IO_BASE + 0x30)
#define SYS_ITIM1_CMP (SYS_IO_BASE + 0x34)
#define SYS_ITIM2_CMP (SYS_IO_BASE + 0x38)
#define SYS_ITIM3_CMP (SYS_IO_BASE + 0x3C)
#define SYS_UART_DATA (SYS_IO_BASE + 0x10000)
#define SYS_UART_STAT (SYS_IO_BASE + 0x10004)
#define SYS_UART_BAUD (SYS_IO_BASE + 0x10008)
#define SYS_SPI_STAT (SYS_IO_BASE + 0x20000)
// Read
#define SPI_STAT_CMDRDY (0x01)
#define SPI_STAT_DINRDY (0x02)
#define SPI_STAT_DOUTRDY (0x04)
#define SPI_STAT_CMD_FIFO_FULL (0x0100)
#define SPI_STAT_CMD_FIFO_EMPTY (0x0200)
#define SPI_STAT_WRITE_FIFO_FULL (0x0400)
#define SPI_STAT_WRITE_FIFO_EMPTY (0x0800)
#define SPI_STAT_READ_FIFO_FULL (0x1000)
#define SPI_STAT_READ_FIFO_EMPTY (0x2000)
#define SPI_STAT_RX_VALID (0x4000)
#define SPI_STAT_SPI_HOLD (0x8000)
// Write
#define SPI_STAT_COMMIT (1)
#define SYS_SPI_XFER_SIZE (SYS_IO_BASE + 0x20004)
#define SYS_SPI_DATA_SIZE (SYS_IO_BASE + 0x20008)
#define SYS_SPI_DATA (SYS_IO_BASE + 0x2000C)
#define SYS_SPI_CTRL (SYS_IO_BASE + 0x20010)
#define SYS_FLASH_IO FLASH_BASE_IO
#define SYS_FLASH_MEM FLASH_BASE_MEM
// RTC
#define SYS_TIMER_USEC (SYS_IO_BASE + 0x8)
#define SYS_TIMER_SEC (SYS_IO_BASE + 0xC)
// TIMERs
#define SYS_ITIM_CTRL (SYS_IO_BASE + 0x18)
#define SYS_ITIM_STAT (SYS_IO_BASE + 0x1C)
#define SYS_ITIM0_CNT (SYS_IO_BASE + 0x20)
#define SYS_ITIM1_CNT (SYS_IO_BASE + 0x24)
#define SYS_ITIM2_CNT (SYS_IO_BASE + 0x28)
#define SYS_ITIM3_CNT (SYS_IO_BASE + 0x2C)
#define SYS_ITIM0_CMP (SYS_IO_BASE + 0x30)
#define SYS_ITIM1_CMP (SYS_IO_BASE + 0x34)
#define SYS_ITIM2_CMP (SYS_IO_BASE + 0x38)
#define SYS_ITIM3_CMP (SYS_IO_BASE + 0x3C)
// MIPS specific
uint32_t CP0_SR_read(void);
void CP0_SR_write(uint32_t val);
+6 -5
View File
@@ -2,6 +2,7 @@
.text
.section .init,"ax"
.extern board_init
.align 2
_start:
@@ -14,7 +15,7 @@ _start:
# Kernel mode (SR[1]=0), Int disabled(SR[0]=0), after RFE into main
li $26, 0x1040000C
mtc0 $26, $12
li $26, 0x00000000
li $26, 0x00000000
mtc0 $26, $13
mfc0 $26, $15
@@ -36,14 +37,14 @@ $zeroise:
addiu $8, 4
_init:
# Call libsys_init
la $k0, libsys_init
# Call board_init
la $k0, board_init
jalr $k0
nop
la $26, main
la $k0, main
jalr $26
jalr $k0
nop
_terminate:
nop
-2
View File
@@ -1,5 +1,3 @@
#include <stdio.h>
#include <stdlib.h>
#include "cfiflash.h"
uint32_t cfi_get_status(flash_t *pObj)
+1
View File
@@ -1,6 +1,7 @@
#ifndef HPI_H
#define HPI_H
#include <irq.h>
// ---------------------------------------------------------
// API related
// ---------------------------------------------------------
+4 -1
View File
@@ -6,6 +6,9 @@
#include <stddef.h>
#include "board.h"
#include "../../irq.h"
#include "../../uart.h"
#include "../../console.h"
#include "../../regdef.h"
#define DEBUGGER gdb_stub
@@ -23,7 +26,7 @@ const con_if_entry_t con_if_entry[] =
{4, "UART-1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar}
};
con_if_t con_if =
const con_if_t con_if =
{
con_if_entry, ARRAYSIZE(con_if_entry)
};
+6 -4
View File
@@ -14,10 +14,6 @@
#ifndef BOARD_H
#define BOARD_H
#include "../../irq.h"
#include "../../uart.h"
#include "../../console.h"
#define CPU_FREQ_HZ 50000000
// ---------------------------------------------------------
@@ -61,6 +57,12 @@
#define GPIO_0_MASK_LED 0x000000FF
#define GPIO_0_ALIGN_LED 0
#define GPIO_0_MASK_DIP 0x000000FF
#define GPIO_0_ALIGN_DIP 16
#define GPIO_0_MASK_BTN 0x0000001F
#define GPIO_0_ALIGN_BTN 24
// RTC
#define SYS_TIMER_USEC (SYS_IO_BASE + 0x8)
#define SYS_TIMER_SEC (SYS_IO_BASE + 0xC)
+28 -5
View File
@@ -6,10 +6,16 @@
#include <stddef.h>
#include "../../irq.h"
#include "../../mips_ps2.h"
#include "../../mips_gfx.h"
#include "../../screen.h"
#include "../../uart.h"
#include "../../console.h"
#include "board.h"
extern void dbg_init();
extern void dbg_handler(struct xcptcontext * xcp);
extern int dbg_handler(struct xcptcontext * xcp);
#define DEBUGGER dbg_handler
extern uart_if_t uart_if[];
extern ps2_if_t ps2_if[];
@@ -17,7 +23,7 @@ extern vga_if_t vga_if;
#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
static const con_if_entry_t con_if_entry[] =
const con_if_entry_t con_if_entry[] =
{
{0, "stdin", &uart_if[0], NULL, NULL, UART_readchar, NULL},
{1, "stdout", &uart_if[0], NULL, NULL, NULL, UART_writechar},
@@ -29,11 +35,28 @@ static const con_if_entry_t con_if_entry[] =
{30, "VGA-0", &vga_if, cg_open, cg_close, NULL, cg_writechar}
};
con_if_t con_if =
const con_if_t con_if =
{
con_if_entry, ARRAYSIZE(con_if_entry)
};
void handle_debugger_int(struct xcptcontext * xcp)
{
dbg_handler(xcp);
}
void dbg_init()
{
xcpt_register(EXC_ADEL, DEBUGGER);
xcpt_register(EXC_ADES, DEBUGGER);
xcpt_register(EXC_IBE, DEBUGGER);
xcpt_register(EXC_DBE, DEBUGGER);
xcpt_register(EXC_BP, DEBUGGER);
xcpt_register(EXC_RI, DEBUGGER);
xcpt_register(EXC_CPU, DEBUGGER);
xcpt_register(EXC_OV, DEBUGGER);
}
void board_init(void)
{
uint32_t volatile *pITIM_ctrl = (uint32_t*)SYS_ITIM_CTRL;
@@ -54,7 +77,7 @@ void board_init(void)
// Initalize debugger
dbg_init();
interrupt_register(2, dbg_handler);
interrupt_register(2, handle_debugger_int);
interrupt_enable(2);
// flush stdin
-7
View File
@@ -14,13 +14,6 @@
#ifndef BOARD_H
#define BOARD_H
#include "../../irq.h"
#include "../../mips_ps2.h"
#include "../../mips_gfx.h"
#include "../../screen.h"
#include "../../uart.h"
#include "../../console.h"
#define CPU_FREQ_HZ 100000000
// ---------------------------------------------------------
+4 -4
View File
@@ -5,9 +5,9 @@
#include "libsys.h"
#include "mips_ps2.h"
uint32_t con_readchar(ps2_if_t *pIF);
uint32_t ps2_readchar(ps2_if_t *pIF);
ps2_if_t ps2_if[2] =
const ps2_if_t ps2_if[2] =
{
{ps2_type_unknown, (uint32_t*)SYS_PS2_0_STAT, (uint32_t*)SYS_PS2_0_DATA},
{ps2_type_unknown, (uint32_t*)SYS_PS2_1_STAT, (uint32_t*)SYS_PS2_1_DATA}
@@ -23,7 +23,7 @@ int PS2_readchar(void const *pInst)
assert(pInst);
ps2_if_t *pIF = (ps2_if_t*)pInst;
return (int)con_readchar(pIF);
return (int)ps2_readchar(pIF);
}
void PS2_open(void const *pInst)
@@ -396,7 +396,7 @@ static char __findkey(char scancode, int mode)
#define ARROW_LEFT (SPECIALKEY|EXTENDED|0x6b)
#define ARROW_RIGHT (SPECIALKEY|EXTENDED|0x74)
uint32_t con_readchar(ps2_if_t *pIF)
uint32_t ps2_readchar(ps2_if_t *pIF)
{
uint8_t c;
static char mode = 0;
+1 -1
View File
@@ -11,7 +11,7 @@
#include <board.h>
#include "screen.h"
vga_if_t vga_if =
const vga_if_t vga_if =
{
(uint32_t*)SYS_VGA_CTRL, (uint32_t*)SYS_VGA_ASCII, (uint32_t*)SYS_VGA_POSX, (uint32_t*)SYS_VGA_POSY
};
+4 -9
View File
@@ -4,14 +4,13 @@
* and open the template in the editor.
*/
#include <assert.h>
#include <board.h>
#include "uart.h"
// ---------------------------------------------------------------------------------
// Globals
// ---------------------------------------------------------------------------------
uart_if_t uart_if[2] =
const uart_if_t uart_if[2] =
{
{(uint32_t*)SYS_UART0_STAT, (uint32_t*)SYS_UART0_DATA, (uint32_t*)SYS_UART0_BAUD},
{(uint32_t*)SYS_UART1_STAT, (uint32_t*)SYS_UART1_DATA, (uint32_t*)SYS_UART1_BAUD}
@@ -21,12 +20,10 @@ uart_if_t uart_if[2] =
// Low-level I/O
// ------------------------------------
#define CALC_BAUD(b) \
((uint32_t)((float)CPU_FREQ_HZ/(16*b) + 0.5f) - 1);
(((10*CPU_FREQ_HZ)/((16*b) + 5))/10 - 1)
void UART_setbaud(void const *pInst, uint32_t baudrate)
{
assert(pInst);
uart_if_t *pReg = (uart_if_t*)pInst;
*pReg->pBAUD = CALC_BAUD(baudrate);
@@ -34,20 +31,18 @@ void UART_setbaud(void const *pInst, uint32_t baudrate)
int UART_readchar(void const *pInst)
{
assert(pInst);
uart_if_t *pReg = (uart_if_t*)pInst;
if (SYS_UART_BIT_RX_AVAIL & *pReg->pCTRL)
{
return (*pReg->pDATA & 0xFF);
}
return -1;
}
void UART_writechar(void const *pInst, char c)
{
assert(pInst);
uart_if_t *pReg = (uart_if_t*)pInst;
while((SYS_UART_BIT_TX_HALFFULL & *pReg->pCTRL) != 0);
+4 -4
View File
@@ -3,10 +3,10 @@
#include <string.h>
#include <time.h>
#include <libsys/libsys.h>
#include <libsys/gpio.h>
#include "cfiflash.h"
#include <libsys.h>
#include <gpio.h>
#include <irq.h>
#include <cfiflash.h>
#include "hpi.h"
static volatile uint32_t _g_uart_msg;
+4 -1
View File
@@ -5,7 +5,10 @@
#include <sys/times.h>
#include <sys/time.h>
#include "libsys.h"
#include <libsys.h>
#include <irq.h>
#include <mips_gfx.h>
#include <mips_ps2.h>
#define PS2_NUM_IF 2
char buffer[16384];
+5 -1
View File
@@ -5,7 +5,11 @@
#include <sys/times.h>
#include <sys/time.h>
#include "libsys.h"
#include <libsys.h>
#include <gpio.h>
#include <irq.h>
#include <mips_gfx.h>
#include <mips_ps2.h>
#define PS2_NUM_IF 2
static volatile int32_t mouse_x;
+5 -3
View File
@@ -5,9 +5,11 @@
#include <time.h>
#include <sys/times.h>
#include <sys/time.h>
#include "libsys.h"
#include "gpio.h"
#include "mips_gfx.h"
#include <libsys.h>
#include <gpio.h>
#include <irq.h>
#include <mips_gfx.h>
#include <mips_ps2.h>
#define TEST10_ERROR (ERROR | 0x1000)
#define TEST11_ERROR (ERROR | 0x1100)