[mips]
- libsys multitarget - apps multitarget git-svn-id: http://moon:8086/svn/mips@67 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
+36
-24
@@ -1,9 +1,19 @@
|
||||
# environment vaiables read:
|
||||
# BOARD
|
||||
# BOARD = {ml402, denano}
|
||||
# TLB = {no, yes}
|
||||
# ENDIANESS = {eb, el}
|
||||
BOARD ?= ml402
|
||||
TLB ?= no
|
||||
ENDIANESS ?= eb
|
||||
|
||||
ENDIAN_FLAGS=-EL
|
||||
|
||||
CFLAGS=$(ENDIAN_FLAGS) -msoft-float -O2 -march=r3000 -I. -Wl,-M -Iboards/$(BOARD)
|
||||
ifeq ($(ENDIANESS),el)
|
||||
ENDIAN_FLAGS=-EL
|
||||
else
|
||||
ENDIAN_FLAGS=-EB
|
||||
endif
|
||||
|
||||
CFLAGS=$(ENDIAN_FLAGS) -msoft-float -O2 -march=r3000 -I. -Wl,-M -Iboards/$(BOARD) -D$(BOARD)
|
||||
|
||||
ifeq ($(TLB),yes)
|
||||
CFLAGS+=-DSYS_IO_BASE=0xAC000000 -DSDRAM_BASE=0x80000000 -DFLASH_BASE_IO=0xA4000000 -DFLASH_BASE_MEM=0x88000000
|
||||
@@ -11,6 +21,8 @@ else
|
||||
CFLAGS+=-DSYS_IO_BASE=0xA0000000 -DSDRAM_BASE=0x40000000 -DFLASH_BASE_IO=0xA4000000 -DFLASH_BASE_MEM=0x00000000
|
||||
endif
|
||||
|
||||
BUILD_DIR=./build/$(BOARD)/$(ENDIANESS)
|
||||
|
||||
AS=mipsel-elf-as
|
||||
AR=mipsel-elf-ar
|
||||
CC=mipsel-elf-gcc
|
||||
@@ -19,31 +31,31 @@ OBJDUMP=mipsel-elf-objdump
|
||||
OBJCOPY=mipsel-elf-objcopy
|
||||
FLASHGEN=flashgen
|
||||
|
||||
SRCS=libsys.c xcpt.c syscalls.c irq.c mips_dbg.c mips_dis.c mips_gfx.c mips_ps2.c gpio.c
|
||||
OBJS=libsys.o xcpt.o syscalls.o irq.o mips_dbg.o mips_dis.o mips_gfx.o mips_ps2.o gpio.o
|
||||
OBJS-ml402=$(addprefix $(BUILD_DIR)/, libsys.o xcpt.o syscalls.o irq.o mips_dbg.o mips_dis.o mips_ps2.o mips_gfx.o console.o screen.o uart.o board.o gpio.o)
|
||||
OBJS-denano=$(addprefix $(BUILD_DIR)/, libsys.o xcpt.o syscalls.o irq.o mips_dbg.o mips_dis.o console.o uart.o board.o)
|
||||
|
||||
.PHONY : libsys.a
|
||||
|
||||
all: libsys.a
|
||||
$(MAKE) -C eb BOARD=$(BOARD)
|
||||
all: $(BUILD_DIR) $(BUILD_DIR)/libsys.a
|
||||
|
||||
$(OBJS): $(SRCS)
|
||||
$(CC) $(CFLAGS) -G 0 -c $(SRCS)
|
||||
$(BUILD_DIR)/%.o : %.c
|
||||
$(CC) $(CFLAGS) -G 0 -c -o $@ $<
|
||||
|
||||
libsys.a: $(OBJS) $(SRCS)
|
||||
$(AR) -r libsys.a $(OBJS)
|
||||
$(CC) $(CFLAGS) -G 0 -c startup.S
|
||||
$(CC) $(CFLAGS) -G 0 -c kernel.S
|
||||
$(BUILD_DIR)/%.o : %.S
|
||||
$(CC) $(CFLAGS) -G 0 -c -o $@ $<
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -G 0 -c *.c
|
||||
$(BUILD_DIR)/board.o : boards/$(BOARD)/board.c
|
||||
$(CC) $(CFLAGS) -G 0 -c -o $@ $<
|
||||
|
||||
$(BUILD_DIR)/libsys.a: $(OBJS-$(BOARD))
|
||||
$(AR) -r $(BUILD_DIR)/libsys.a $(OBJS-$(BOARD))
|
||||
$(CC) $(CFLAGS) -G 0 -c -o $(BUILD_DIR)/startup.o startup.S
|
||||
$(CC) $(CFLAGS) -G 0 -c -o $(BUILD_DIR)/kernel.o kernel.S
|
||||
|
||||
$(BUILD_DIR):
|
||||
mkdir -p $(BUILD_DIR)
|
||||
|
||||
libsys_sim.a: libsys_sim.o xcpt.o syscalls.o irq.o gpio.o
|
||||
$(AR) -r libsys_sim.a libsys_sim.o xcpt.o syscalls.o irq.o gpio.o
|
||||
$(CC) $(CFLAGS) -G 0 -c startup.S
|
||||
$(CC) $(CFLAGS) -G 0 -c kernel.S
|
||||
|
||||
clean:
|
||||
rm -rf *.a *.o *.map *.dis *.elf > /dev/null
|
||||
$(MAKE) -C eb clean
|
||||
rm -rf $(BUILD_DIR)/*.a $(BUILD_DIR)/*.o > /dev/null
|
||||
|
||||
mrproper:
|
||||
rm -rf $(BUILD_DIR)
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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 "../../uart.h"
|
||||
#include "../../console.h"
|
||||
|
||||
extern uart_if_t uart_if[];
|
||||
|
||||
#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
|
||||
|
||||
const con_if_entry_t con_if_entry[5] =
|
||||
{
|
||||
{"UART-0", &uart_if[0], NULL, NULL, UART_readchar, UART_writechar},
|
||||
{"UART-1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar}
|
||||
};
|
||||
|
||||
con_if_t con_if =
|
||||
{
|
||||
con_if_entry, ARRAYSIZE(con_if_entry)
|
||||
};
|
||||
@@ -93,6 +93,29 @@
|
||||
#define SYS_UART1_STAT (SYS_IO_BASE + 0x10104)
|
||||
#define SYS_UART1_BAUD (SYS_IO_BASE + 0x10108)
|
||||
|
||||
// SPI
|
||||
#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)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 "../../mips_ps2.h"
|
||||
#include "../../screen.h"
|
||||
#include "../../uart.h"
|
||||
#include "../../console.h"
|
||||
|
||||
extern uart_if_t uart_if[];
|
||||
extern ps2_if_t ps2_if[];
|
||||
extern vga_if_t vga_if;
|
||||
|
||||
#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
|
||||
|
||||
static const con_if_entry_t con_if_entry[5] =
|
||||
{
|
||||
{"UART-0", &uart_if[0], NULL, NULL, UART_readchar, UART_writechar},
|
||||
{"UART-1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar},
|
||||
{"PS2-0", &ps2_if[0], PS2_open, PS2_close, PS2_readchar, NULL},
|
||||
{"PS2-1", &ps2_if[1], PS2_open, PS2_close, PS2_readchar, NULL},
|
||||
{"VGA-0", &vga_if, cg_open, cg_close, NULL, cg_writechar}
|
||||
};
|
||||
|
||||
con_if_t con_if =
|
||||
{
|
||||
con_if_entry, ARRAYSIZE(con_if_entry)
|
||||
};
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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 <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "console.h"
|
||||
|
||||
extern con_if_t con_if;
|
||||
|
||||
// Funcs
|
||||
con_if_entry_t const* con_getPort(int file)
|
||||
{
|
||||
assert(file < con_if.length);
|
||||
|
||||
return &con_if.con_if_entry[file];
|
||||
}
|
||||
|
||||
int con_open(char const *pName)
|
||||
{
|
||||
int i;
|
||||
assert(pName);
|
||||
|
||||
for (i=0; i < con_if.length; i++)
|
||||
{
|
||||
if (!strcmp(pName, con_if.con_if_entry->pName))
|
||||
{
|
||||
if (con_if.con_if_entry->openFunc)
|
||||
{
|
||||
con_if.con_if_entry->openFunc(&con_if.con_if_entry[i].pInst);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int con_close(int fd)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void con_flush(int fd)
|
||||
{
|
||||
int c;
|
||||
con_if_entry_t const *pIF = con_getPort(fd);
|
||||
|
||||
do
|
||||
{
|
||||
c = pIF->readchar(pIF->pInst);
|
||||
|
||||
} while(c > 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
int readchar(int fd)
|
||||
{
|
||||
int c;
|
||||
con_if_entry_t const *pIF = con_getPort(fd);
|
||||
|
||||
assert(pIF);
|
||||
|
||||
// busy read
|
||||
do
|
||||
{
|
||||
c = pIF->readchar(pIF->pInst);
|
||||
|
||||
} while(c < 0);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void writechar(int fd, char c)
|
||||
{
|
||||
con_if_entry_t const *pIF = con_getPort(fd);
|
||||
|
||||
assert(pIF);
|
||||
|
||||
pIF->writechar(pIF->pInst, c);
|
||||
|
||||
}
|
||||
|
||||
void _putchar(int fd, char c)
|
||||
{
|
||||
con_if_entry_t const *pIF = con_getPort(fd);
|
||||
|
||||
assert(pIF);
|
||||
if (c == 0x0A)
|
||||
{
|
||||
pIF->writechar(pIF->pInst, 0x0D);
|
||||
}
|
||||
pIF->writechar(pIF->pInst, c);
|
||||
|
||||
}
|
||||
|
||||
char _getchar(int fd)
|
||||
{
|
||||
return readchar(fd);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* File: console.h
|
||||
* Author: jens
|
||||
*
|
||||
* Created on 8. Januar 2017, 14:25
|
||||
*/
|
||||
|
||||
#ifndef CONSOLE_H
|
||||
#define CONSOLE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int (*read_func_t)(void const *pInst);
|
||||
typedef void (*write_func_t)(void const *pInst, char c);
|
||||
typedef void (*open_func_t)(void const *pInst);
|
||||
typedef void (*close_func_t)(void const *pInst);
|
||||
|
||||
typedef struct _scon_if_entry_t
|
||||
{
|
||||
char const *pName;
|
||||
void const *pInst;
|
||||
open_func_t openFunc;
|
||||
close_func_t closeFunc;
|
||||
read_func_t readchar;
|
||||
write_func_t writechar;
|
||||
} con_if_entry_t;
|
||||
|
||||
typedef struct _scon_if_t
|
||||
{
|
||||
con_if_entry_t const *con_if_entry;
|
||||
size_t length;
|
||||
} con_if_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
// ---------------------------------------------------------------------------------
|
||||
int con_open(char const *pName);
|
||||
int con_close(int fd);
|
||||
void con_flush(int file);
|
||||
con_if_entry_t const* con_getPort(int file);
|
||||
|
||||
int readchar(int file);
|
||||
void writechar(int file, char c);
|
||||
char _getchar(int fd);
|
||||
void _putchar(int fd, char c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONSOLE_H */
|
||||
|
||||
+13
-621
@@ -5,21 +5,15 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "console.h"
|
||||
#include "libsys.h"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
// ---------------------------------------------------------------------------------
|
||||
void flush(uint32_t port);
|
||||
uint32_t GetPort(int file);
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// Types
|
||||
// ---------------------------------------------------------------------------------
|
||||
void libsys_init(void)
|
||||
{
|
||||
uint32_t volatile *pVGA_ctrl = (uint32_t*)SYS_VGA_CTRL;
|
||||
uint32_t volatile *pITIM_ctrl = (uint32_t*)SYS_ITIM_CTRL;
|
||||
|
||||
// Screen_clr();
|
||||
@@ -40,27 +34,12 @@ void libsys_init(void)
|
||||
dbg_init();
|
||||
|
||||
// flush stdin
|
||||
// flush(GetPort(0));
|
||||
// flush(con_getPort(0));
|
||||
|
||||
// Do some initializations here
|
||||
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
PORT_IN_UART_0 = 0,
|
||||
PORT_IN_UART_1,
|
||||
PORT_IN_PS2_0,
|
||||
PORT_IN_PS2_1
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
PORT_OUT_UART0 = 0,
|
||||
PORT_OUT_UART1,
|
||||
PORT_OUT_VGA
|
||||
};
|
||||
|
||||
#define CALC_BAUD(b) \
|
||||
((uint32_t)((float)CPU_FREQ_HZ/(16*b) + 0.5f) - 1);
|
||||
|
||||
@@ -74,97 +53,6 @@ void UART1_setbaud(uint32_t baudrate)
|
||||
*((uint32_t*)SYS_UART1_BAUD) = CALC_BAUD(baudrate);
|
||||
}
|
||||
|
||||
uint32_t GetPort(int file)
|
||||
{
|
||||
if (file == 0) // STDIN
|
||||
return PORT_IN_UART_0;
|
||||
|
||||
if (file == 1) // STDOUT
|
||||
return PORT_OUT_UART0;
|
||||
|
||||
if (file == 2) // STDERR
|
||||
return PORT_OUT_VGA;
|
||||
|
||||
if (file == 10) // AUX0
|
||||
return PORT_IN_UART_1;
|
||||
|
||||
if (file == 11) // AUX1
|
||||
return PORT_OUT_UART1;
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
IF_TYPE_INVALID = 0,
|
||||
IF_TYPE_UART,
|
||||
IF_TYPE_PS2,
|
||||
IF_TYPE_VGA
|
||||
};
|
||||
|
||||
typedef struct _suart_if_t
|
||||
{
|
||||
volatile uint32_t *pCTRL;
|
||||
volatile uint32_t *pDATA;
|
||||
volatile uint32_t *pBAUD;
|
||||
} uart_if_t;
|
||||
|
||||
typedef struct _sps2_if_t
|
||||
{
|
||||
volatile uint32_t *pCTRL;
|
||||
volatile uint32_t *pDATA;
|
||||
} ps2_if_t;
|
||||
|
||||
typedef struct _svga_if_t
|
||||
{
|
||||
volatile uint32_t *pCTRL;
|
||||
volatile uint32_t *pDATA;
|
||||
volatile uint32_t *pCSRX;
|
||||
volatile uint32_t *pCSRY;
|
||||
} vga_if_t;
|
||||
|
||||
typedef struct _scon_if_in_t
|
||||
{
|
||||
uint32_t type;
|
||||
void *pIF;
|
||||
} con_if_in_t;
|
||||
|
||||
typedef struct _scon_if_out_t
|
||||
{
|
||||
uint32_t type;
|
||||
void *pIF;
|
||||
} con_if_out_t;
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// Globals
|
||||
// ---------------------------------------------------------------------------------
|
||||
static 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}
|
||||
};
|
||||
|
||||
extern ps2_if_t ps2_if[];
|
||||
|
||||
static 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
|
||||
};
|
||||
|
||||
static con_if_in_t con_if_in[4] =
|
||||
{
|
||||
{IF_TYPE_UART, &uart_if[0]},
|
||||
{IF_TYPE_UART, &uart_if[1]},
|
||||
{IF_TYPE_PS2, &ps2_if[0]},
|
||||
{IF_TYPE_PS2, &ps2_if[1]}
|
||||
};
|
||||
|
||||
static con_if_out_t con_if_out[4] =
|
||||
{
|
||||
{IF_TYPE_UART, &uart_if[0]},
|
||||
{IF_TYPE_UART, &uart_if[1]},
|
||||
{IF_TYPE_VGA, &vga_if},
|
||||
{IF_TYPE_INVALID, NULL}
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// MIPS specific
|
||||
// ---------------------------------------------------------------------------------
|
||||
@@ -308,495 +196,6 @@ void DCACHE_invalidate_at(uint32_t* pPtr)
|
||||
);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// BEGIN QUICK AND DIRTY
|
||||
// -------------------------------------------------------------
|
||||
//keymap for the AT keyboard SG layout
|
||||
typedef struct
|
||||
{
|
||||
uint8_t scancode;
|
||||
uint8_t unshifted;
|
||||
uint8_t shifted;
|
||||
uint8_t altered;
|
||||
} libsys_key_entry_t;
|
||||
|
||||
#define SHIFTED (1<<0)
|
||||
#define ALTERED (1<<1)
|
||||
#define CONTROLLED (1<<2)
|
||||
|
||||
static const libsys_key_entry_t __keymap_german[] =
|
||||
{
|
||||
{0x1c, 'a', 'A', 'a'},
|
||||
{0x32, 'b', 'B', 'b'},
|
||||
{0x21, 'c', 'C', 'c'},
|
||||
{0x23, 'd', 'D', 'd'},
|
||||
{0x24, 'e', 'E', '€'},
|
||||
{0x2b, 'f', 'F', 'f'},
|
||||
{0x34, 'g', 'G', 'g'},
|
||||
{0x33, 'h', 'H', 'h'},
|
||||
{0x43, 'i', 'I', 'i'},
|
||||
{0x3b, 'j', 'J', 'j'},
|
||||
{0x42, 'k', 'K', 'k'},
|
||||
{0x4b, 'l', 'L', 'l'},
|
||||
{0x3a, 'm', 'M', 'µ'},
|
||||
{0x31, 'n', 'N', 'n'},
|
||||
{0x44, 'o', 'O', 'o'},
|
||||
{0x4d, 'p', 'P', 'p'},
|
||||
{0x15, 'q', 'Q', '@'},
|
||||
{0x2d, 'r', 'R', 'r'},
|
||||
{0x1b, 's', 'S', 's'},
|
||||
{0x2c, 't', 'T', 't'},
|
||||
{0x3c, 'u', 'U', 'u'},
|
||||
{0x2a, 'v', 'V', 'v'},
|
||||
{0x1d, 'w', 'W', 'w'},
|
||||
{0x22, 'x', 'X', 'x'},
|
||||
{0x1a, 'y', 'Y', 'y'},
|
||||
{0x35, 'z', 'Z', 'z'},
|
||||
{0x16, '1', '!', '1'},
|
||||
{0x1e, '2', '"', '2'},
|
||||
{0x26, '3', '§', '3'},
|
||||
{0x25, '4', '$', '4'},
|
||||
{0x2e, '5', '%', '5'},
|
||||
{0x36, '6', '&', '6'},
|
||||
{0x3d, '7', '/', '{'},
|
||||
{0x3e, '8', '(', '['},
|
||||
{0x46, '9', ')', ']'},
|
||||
{0x45, '0', '=', '}'},
|
||||
{0x4e, 'ß', '?', '\\'},
|
||||
{0x29, ' ', ' ', ' '},
|
||||
{0x41, ',', ';', ','},
|
||||
{0x49, '.', ':', '.'},
|
||||
{0x4a, '-', '_', '-'},
|
||||
{0x52, 'ä', 'Ä', 'ä'},
|
||||
{0x4c, 'ö', 'Ö', 'ö'},
|
||||
{0x54, 'ü', 'Ü', 'ü'},
|
||||
{0x5a, '\n', '\n', '\n'}, //RETURN
|
||||
{0x5b, '+', '*', '~'},
|
||||
{0x5d, '#', '\'', '#'},
|
||||
{0x0e, '^', '°', '^'},
|
||||
{0x61, '<', '>', '|'},
|
||||
{0x66, '\b', '\b', '\b'},
|
||||
{0} //sentinel
|
||||
|
||||
};
|
||||
|
||||
static char __findkey(char scancode, int mode)
|
||||
{
|
||||
const libsys_key_entry_t *p = __keymap_german;
|
||||
while (p->scancode)
|
||||
{
|
||||
if (p->scancode == scancode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case SHIFTED:
|
||||
return p->shifted;
|
||||
case ALTERED:
|
||||
return p->altered;
|
||||
case ALTERED|SHIFTED:
|
||||
default:
|
||||
return p->unshifted;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define RELEASE 0x8000
|
||||
#define SPECIALKEY 0x4000
|
||||
#define EXTENDED 0x2000
|
||||
#define X_CONTROLLED 0x0400
|
||||
#define X_ALTERED 0x0200
|
||||
#define X_SHIFTED 0x0100
|
||||
#define CAPS (SPECIALKEY|0x58)
|
||||
#define F1 (SPECIALKEY|0x05)
|
||||
#define F2 (SPECIALKEY|0x06)
|
||||
#define F3 (SPECIALKEY|0x04)
|
||||
#define F4 (SPECIALKEY|0x0c)
|
||||
#define F5 (SPECIALKEY|0x03)
|
||||
#define F6 (SPECIALKEY|0x0b)
|
||||
#define F7 (SPECIALKEY|0x83)
|
||||
#define F8 (SPECIALKEY|0x0a)
|
||||
#define F9 (SPECIALKEY|0x01)
|
||||
#define F10 (SPECIALKEY|0x09)
|
||||
#define F11 (SPECIALKEY|0x78)
|
||||
#define F12 (SPECIALKEY|0x07)
|
||||
#define ARROW_UP (SPECIALKEY|EXTENDED|0x75)
|
||||
#define ARROW_DOWN (SPECIALKEY|EXTENDED|0x72)
|
||||
#define ARROW_LEFT (SPECIALKEY|EXTENDED|0x6b)
|
||||
#define ARROW_RIGHT (SPECIALKEY|EXTENDED|0x74)
|
||||
|
||||
uint32_t PS2_readchar(ps2_if_t *pIF)
|
||||
{
|
||||
if (!pIF)
|
||||
return -1;
|
||||
|
||||
while (!(SYS_PS2_BIT_RX_AVAIL & *pIF->pCTRL));
|
||||
|
||||
return (*pIF->pDATA & 0xFF);
|
||||
|
||||
}
|
||||
|
||||
uint32_t con_readchar(ps2_if_t *pIF)
|
||||
{
|
||||
uint8_t c;
|
||||
static char mode = 0;
|
||||
static char nextrelease = 0;
|
||||
static char extended = 0;
|
||||
int flags = 0;
|
||||
int char_valid = 0;
|
||||
uint8_t key;
|
||||
|
||||
key = PS2_readchar(pIF);
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case 0xf0: //release key
|
||||
nextrelease = 1;
|
||||
break;
|
||||
case 0x14: //control key
|
||||
if (nextrelease)
|
||||
{
|
||||
mode &= ~CONTROLLED;
|
||||
} else
|
||||
{
|
||||
mode |= CONTROLLED;
|
||||
}
|
||||
nextrelease = 0;
|
||||
break;
|
||||
case 0x12: //left SHIFT
|
||||
case 0x59: //right SHIFT
|
||||
if (nextrelease)
|
||||
{
|
||||
mode &= ~SHIFTED;
|
||||
} else
|
||||
{
|
||||
mode |= SHIFTED;
|
||||
}
|
||||
nextrelease = 0;
|
||||
break;
|
||||
case 0x11: //left and right ALT (right one also with E0)
|
||||
if (nextrelease)
|
||||
{
|
||||
mode &= ~ALTERED;
|
||||
} else
|
||||
{
|
||||
mode |= ALTERED;
|
||||
}
|
||||
nextrelease = 0;
|
||||
break;
|
||||
case 0xe0: //extended key following
|
||||
extended = 1;
|
||||
break;
|
||||
default:
|
||||
if (nextrelease) flags |= RELEASE;
|
||||
if (extended) flags |= EXTENDED;
|
||||
flags |= mode << 8;
|
||||
c = __findkey(key, mode);
|
||||
char_valid = (c && ((flags & RELEASE) != RELEASE));
|
||||
nextrelease = 0;
|
||||
extended = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (char_valid)
|
||||
{
|
||||
// fprintf(stderr, "c = %c (%d), flags = 0x%08X, mode = 0x%08X\n", c, c, flags, mode);
|
||||
return c;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
// -------------------------------------------------------------
|
||||
// END QUICK AND DIRTY
|
||||
// -------------------------------------------------------------
|
||||
|
||||
// ------------------------------------
|
||||
// Low-level I/O
|
||||
// ------------------------------------
|
||||
int UART_readchar(uart_if_t *pIF)
|
||||
{
|
||||
if (!pIF)
|
||||
return -1;
|
||||
|
||||
if (SYS_UART_BIT_RX_AVAIL & *pIF->pCTRL)
|
||||
return (*pIF->pDATA & 0xFF);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void UART_writechar(uart_if_t *pIF, char c)
|
||||
{
|
||||
if (!pIF)
|
||||
return;
|
||||
|
||||
while((SYS_UART_BIT_TX_HALFFULL & *pIF->pCTRL) != 0);
|
||||
|
||||
*pIF->pDATA = (uint32_t)c;
|
||||
}
|
||||
|
||||
void cg_writechar(vga_if_t *pIF, char c)
|
||||
{
|
||||
uint32_t code;
|
||||
|
||||
if (!pIF)
|
||||
return;
|
||||
|
||||
// Output translation
|
||||
switch(c)
|
||||
{
|
||||
case 'Ä':
|
||||
code = 196;
|
||||
break;
|
||||
|
||||
case 'ä':
|
||||
code = 228;
|
||||
break;
|
||||
|
||||
case 'Ö':
|
||||
code = 214;
|
||||
break;
|
||||
|
||||
case 'ö':
|
||||
code = 246;
|
||||
break;
|
||||
|
||||
case 'Ü':
|
||||
code = 220;
|
||||
break;
|
||||
|
||||
case 'ü':
|
||||
code = 252;
|
||||
break;
|
||||
|
||||
case '&':
|
||||
code = 230;
|
||||
break;
|
||||
|
||||
case '§':
|
||||
code = 167;
|
||||
break;
|
||||
|
||||
case 'ß':
|
||||
code = 223;
|
||||
break;
|
||||
|
||||
case '°':
|
||||
code = 176;
|
||||
break;
|
||||
|
||||
case 'µ':
|
||||
code = 181;
|
||||
break;
|
||||
|
||||
default:
|
||||
code = (uint32_t)c;
|
||||
break;
|
||||
}
|
||||
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pDATA = code;
|
||||
}
|
||||
|
||||
void cg_set_csr_x(vga_if_t *pIF, uint32_t coord)
|
||||
{
|
||||
if (!pIF)
|
||||
return;
|
||||
|
||||
// Set cursor
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pCSRX = coord;
|
||||
}
|
||||
|
||||
void cg_set_csr_y(vga_if_t *pIF, uint32_t coord)
|
||||
{
|
||||
if (!pIF)
|
||||
return;
|
||||
|
||||
// Set cursor
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pCSRY = coord;
|
||||
}
|
||||
|
||||
void cg_clr_line(vga_if_t *pIF)
|
||||
{
|
||||
if (!pIF)
|
||||
return;
|
||||
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pCTRL |= SYS_VGA_BIT_CLRLINE;
|
||||
}
|
||||
|
||||
void cg_clr_screen(vga_if_t *pIF)
|
||||
{
|
||||
|
||||
if (!pIF)
|
||||
return;
|
||||
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pCTRL |= SYS_VGA_BIT_CLRSCR;
|
||||
|
||||
// Cursor home
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pCSRX = 0;
|
||||
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pCSRY = 0;
|
||||
|
||||
}
|
||||
|
||||
void Screen_clr(void)
|
||||
{
|
||||
cg_clr_screen(&vga_if);
|
||||
}
|
||||
|
||||
void Screen_line_clr(void)
|
||||
{
|
||||
cg_clr_line(&vga_if);
|
||||
}
|
||||
|
||||
void Screen_csr_set_x(uint32_t coord)
|
||||
{
|
||||
cg_set_csr_x(&vga_if, coord);
|
||||
}
|
||||
|
||||
void Screen_csr_set_y(uint32_t coord)
|
||||
{
|
||||
cg_set_csr_y(&vga_if, coord);
|
||||
}
|
||||
|
||||
uint32_t Screen_get_resx(void)
|
||||
{
|
||||
uint32_t volatile *pVGA_res = (uint32_t*)SYS_VGA_RES;
|
||||
|
||||
return (0xFFF & (*pVGA_res >> 0));
|
||||
}
|
||||
|
||||
uint32_t Screen_get_resy(void)
|
||||
{
|
||||
uint32_t volatile *pVGA_res = (uint32_t*)SYS_VGA_RES;
|
||||
|
||||
return (0xFFF & (*pVGA_res >> 12));
|
||||
}
|
||||
|
||||
uint32_t Screen_get_fps(void)
|
||||
{
|
||||
uint32_t volatile *pVGA_res = (uint32_t*)SYS_VGA_RES;
|
||||
|
||||
return (0xFF & (*pVGA_res >> 24));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
void flush(uint32_t port)
|
||||
{
|
||||
int c;
|
||||
con_if_in_t *pIF;
|
||||
|
||||
pIF = &con_if_in[port];
|
||||
|
||||
do
|
||||
{
|
||||
switch(pIF->type)
|
||||
{
|
||||
case IF_TYPE_UART:
|
||||
c = UART_readchar((uart_if_t*)pIF->pIF);
|
||||
break;
|
||||
|
||||
case IF_TYPE_PS2:
|
||||
c = con_readchar((ps2_if_t*)pIF->pIF);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} while(c > 0);
|
||||
}
|
||||
|
||||
char readchar(uint32_t port)
|
||||
{
|
||||
int c;
|
||||
con_if_in_t *pIF;
|
||||
|
||||
pIF = &con_if_in[port];
|
||||
|
||||
do
|
||||
{
|
||||
switch(pIF->type)
|
||||
{
|
||||
case IF_TYPE_UART:
|
||||
c = UART_readchar((uart_if_t*)pIF->pIF);
|
||||
break;
|
||||
|
||||
case IF_TYPE_PS2:
|
||||
c = con_readchar((ps2_if_t*)pIF->pIF);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} while(c < 0);
|
||||
|
||||
return (char)c;
|
||||
}
|
||||
|
||||
void writechar(uint32_t port, char c)
|
||||
{
|
||||
con_if_out_t *pIF;
|
||||
|
||||
pIF = &con_if_out[port];
|
||||
|
||||
switch(pIF->type)
|
||||
{
|
||||
case IF_TYPE_UART:
|
||||
UART_writechar((uart_if_t*)pIF->pIF, c);
|
||||
break;
|
||||
|
||||
case IF_TYPE_VGA:
|
||||
cg_writechar((vga_if_t*)pIF->pIF, c);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void _putchar(uint32_t port, char c)
|
||||
{
|
||||
|
||||
con_if_out_t *pIF;
|
||||
|
||||
pIF = &con_if_out[port];
|
||||
|
||||
switch(pIF->type)
|
||||
{
|
||||
case IF_TYPE_UART:
|
||||
if (c == 0x0A)
|
||||
UART_writechar((uart_if_t*)pIF->pIF, 0x0D);
|
||||
UART_writechar((uart_if_t*)pIF->pIF, c);
|
||||
break;
|
||||
|
||||
case IF_TYPE_VGA:
|
||||
cg_writechar((vga_if_t*)pIF->pIF, c);
|
||||
if (c == 0x0A)
|
||||
{
|
||||
cg_clr_line((vga_if_t*)pIF->pIF);
|
||||
cg_writechar((vga_if_t*)pIF->pIF, 0x0D);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char _getchar(void)
|
||||
{
|
||||
return readchar(GetPort(0));
|
||||
}
|
||||
|
||||
void _exit (int exitcode)
|
||||
{
|
||||
fflush(stdout);
|
||||
@@ -951,44 +350,39 @@ int lseek(int file, int ptr, int dir)
|
||||
|
||||
int open(const char *name, int flags, int mode)
|
||||
{
|
||||
// sputs("open (\""); sputs(name); sputs("\")\n");
|
||||
errno = EIO;
|
||||
return -1;
|
||||
return con_open(name);
|
||||
}
|
||||
|
||||
int close(int file)
|
||||
{
|
||||
// sputs("close ("); print_word(file); sputs(")\n");
|
||||
return 0;
|
||||
return con_close(file);
|
||||
}
|
||||
|
||||
int read(int file, char *ptr, int len)
|
||||
{
|
||||
uint32_t port;
|
||||
int i;
|
||||
char c;
|
||||
|
||||
// sputs("read (file="); print_word(file); sputs(", len ="); print_word(len); sputs(")\n");
|
||||
i = 0;
|
||||
port = GetPort(file);
|
||||
|
||||
|
||||
while (i < len)
|
||||
{
|
||||
c = readchar(port);
|
||||
c = readchar(file);
|
||||
|
||||
if (c == 0x04)
|
||||
break;
|
||||
|
||||
if ((c == 0x0D) || (c == 0x0A))
|
||||
{
|
||||
writechar(port, 0x0D);
|
||||
writechar(file, 0x0D);
|
||||
ptr[i++] = 0x0D;
|
||||
writechar(port, 0x0A);
|
||||
writechar(file, 0x0A);
|
||||
ptr[i++] = 0x0A;
|
||||
break;
|
||||
}
|
||||
|
||||
writechar(port, c);
|
||||
writechar(file, c);
|
||||
ptr[i++] = c;
|
||||
|
||||
}
|
||||
@@ -997,14 +391,12 @@ int read(int file, char *ptr, int len)
|
||||
|
||||
int write(int file, char *ptr, int len)
|
||||
{
|
||||
uint32_t port;
|
||||
int i = 0;
|
||||
|
||||
// sputs("write ("); print_word(file); sputs(")\n");
|
||||
|
||||
port = GetPort(file);
|
||||
for (i=0; i < len; i++)
|
||||
_putchar(port, *ptr++);
|
||||
_putchar(file, *ptr++);
|
||||
|
||||
return i;
|
||||
}
|
||||
@@ -1052,7 +444,7 @@ int sputs(char const *pStr)
|
||||
char const *start = pStr;
|
||||
|
||||
while(*pStr)
|
||||
_putchar(GetPort(1), *(pStr++));
|
||||
_putchar(1, *(pStr++));
|
||||
|
||||
return pStr - start;
|
||||
}
|
||||
@@ -1072,7 +464,7 @@ void print_byte(char byte)
|
||||
else
|
||||
c = nibble + 'A' - 10;
|
||||
|
||||
_putchar(GetPort(1), c);
|
||||
_putchar(1, c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1145,7 +537,7 @@ void memdump(uint8_t *pBuf, int print_offset_only, int num_bytes_per_row, int le
|
||||
if((c < 0x20) || (c > 0x7F))
|
||||
c = '.';
|
||||
|
||||
_putchar(GetPort(1), c);
|
||||
_putchar(1, c);
|
||||
cnt_asc--;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -85,10 +85,7 @@ void DCACHE_invalidate_at(uint32_t* pPtr);
|
||||
|
||||
void UART0_setbaud(uint32_t baudrate);
|
||||
void UART1_setbaud(uint32_t baudrate);
|
||||
void UART2_setbaud(uint32_t baudrate);
|
||||
|
||||
char readchar(uint32_t port);
|
||||
void writechar(uint32_t port, char c);
|
||||
int write(int file, char *ptr, int len);
|
||||
int sputs(char const *pStr);
|
||||
void print_byte(char byte);
|
||||
@@ -97,20 +94,8 @@ void _exit (int exitcode);
|
||||
void sleep(unsigned ms);
|
||||
void usleep(unsigned us);
|
||||
|
||||
char _getchar(void);
|
||||
|
||||
void PrintBuffer8(uint8_t *pBuf, int nbpr, int len);
|
||||
void memdump(uint8_t *pBuf, int print_offset_only, int num_bytes_per_row, int len);
|
||||
|
||||
void Screen_clr(void);
|
||||
void Screen_line_clr(void);
|
||||
void Screen_csr_set_x(uint32_t coord);
|
||||
void Screen_csr_set_y(uint32_t coord);
|
||||
uint32_t Screen_get_resx(void);
|
||||
uint32_t Screen_get_resy(void);
|
||||
uint32_t Screen_get_fps(void);
|
||||
|
||||
|
||||
|
||||
#endif // LIBSYS_H
|
||||
|
||||
|
||||
+266
-52
@@ -1,9 +1,12 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "libsys.h"
|
||||
#include "mips_ps2.h"
|
||||
|
||||
uint32_t con_readchar(ps2_if_t *pIF);
|
||||
|
||||
ps2_if_t ps2_if[2] =
|
||||
{
|
||||
{ps2_type_unknown, (uint32_t*)SYS_PS2_0_STAT, (uint32_t*)SYS_PS2_0_DATA},
|
||||
@@ -15,30 +18,40 @@ uint32_t PS2_get_num_if(void)
|
||||
return (sizeof(ps2_if)/sizeof(ps2_if_t));
|
||||
}
|
||||
|
||||
ps2_if_t *PS2_get_if(uint32_t port)
|
||||
int PS2_readchar(void const *pInst)
|
||||
{
|
||||
if (port < PS2_get_num_if())
|
||||
return &ps2_if[port];
|
||||
assert(pInst);
|
||||
ps2_if_t *pIF = (ps2_if_t*)pInst;
|
||||
|
||||
return NULL;
|
||||
return (int)con_readchar(pIF);
|
||||
}
|
||||
|
||||
void PS2_byte_write(uint32_t port, uint8_t byte)
|
||||
void PS2_open(void const *pInst)
|
||||
{
|
||||
ps2_if_t *pIF;
|
||||
assert(pInst);
|
||||
ps2_if_t *pIF = (ps2_if_t*)pInst;
|
||||
|
||||
pIF = &ps2_if[port];
|
||||
PS2_init(pIF);
|
||||
|
||||
}
|
||||
|
||||
void PS2_close(void const *pInst)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PS2_byte_write(ps2_if_t *pIF, uint8_t byte)
|
||||
{
|
||||
assert(pIF);
|
||||
|
||||
while(!(*pIF->pCTRL & SYS_PS2_BIT_TX_EMPTY));
|
||||
|
||||
*pIF->pDATA = (uint32_t)byte;
|
||||
}
|
||||
|
||||
uint32_t PS2_byte_read(uint32_t port, uint32_t timeout_ms)
|
||||
uint32_t PS2_byte_read(ps2_if_t *pIF, uint32_t timeout_ms)
|
||||
{
|
||||
ps2_if_t *pIF;
|
||||
|
||||
pIF = &ps2_if[port];
|
||||
assert(pIF);
|
||||
|
||||
while(!(*pIF->pCTRL & SYS_PS2_BIT_RX_AVAIL))
|
||||
{
|
||||
@@ -51,32 +64,30 @@ uint32_t PS2_byte_read(uint32_t port, uint32_t timeout_ms)
|
||||
return (uint32_t)*pIF->pDATA;
|
||||
}
|
||||
|
||||
uint32_t PS2_cmd(uint32_t port, uint8_t cmd, uint32_t ack_timeout_ms)
|
||||
uint32_t PS2_cmd(ps2_if_t *pIF, uint8_t cmd, uint32_t ack_timeout_ms)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
PS2_byte_write(port, cmd);
|
||||
result = PS2_byte_read(port, ack_timeout_ms);
|
||||
PS2_byte_write(pIF, cmd);
|
||||
result = PS2_byte_read(pIF, ack_timeout_ms);
|
||||
if (0xFA != result)
|
||||
{
|
||||
printf ("PS2_cmd(%d): no ACK received. Result = %08X\n", port, result);
|
||||
printf ("PS2_cmd(%p): no ACK received. Result = %08X\n", pIF->pCTRL, result);
|
||||
return PS2_ERR_PS2_PREFIX | result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PS2_flush(uint32_t port)
|
||||
void PS2_flush(ps2_if_t *pIF)
|
||||
{
|
||||
while (!IS_ERROR(PS2_byte_read(port, 10)));
|
||||
while (!IS_ERROR(PS2_byte_read(pIF, 10)));
|
||||
}
|
||||
|
||||
uint32_t PS2_init(uint32_t port)
|
||||
uint32_t PS2_init(ps2_if_t *pIF)
|
||||
{
|
||||
int i;
|
||||
ps2_if_t *pIF;
|
||||
uint8_t id[2];
|
||||
|
||||
pIF = &ps2_if[port];
|
||||
pIF->type = ps2_type_unknown;
|
||||
|
||||
uint32_t result;
|
||||
@@ -84,13 +95,13 @@ uint32_t PS2_init(uint32_t port)
|
||||
// Disable RX-interrupt
|
||||
*pIF->pCTRL &= ~SYS_PS2_BIT_RX_INTEN;
|
||||
|
||||
printf ("PS2_init(%d) - Initialize... ", port);
|
||||
printf ("PS2_init(%p) - Initialize... ", pIF->pCTRL);
|
||||
|
||||
// Flush buffer
|
||||
PS2_flush(port);
|
||||
PS2_flush(pIF);
|
||||
|
||||
// send RESET
|
||||
result = PS2_cmd(port, 0xFF, 1000);
|
||||
result = PS2_cmd(pIF, 0xFF, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("Reset error %08X\n", result);
|
||||
@@ -98,7 +109,7 @@ uint32_t PS2_init(uint32_t port)
|
||||
}
|
||||
|
||||
// Read BAT
|
||||
result = PS2_byte_read(port, 1000);
|
||||
result = PS2_byte_read(pIF, 1000);
|
||||
if (0xAA != result)
|
||||
{
|
||||
printf ("BAT error %08X\n", result);
|
||||
@@ -110,53 +121,53 @@ uint32_t PS2_init(uint32_t port)
|
||||
while(1)
|
||||
{
|
||||
// Read ID
|
||||
result = PS2_byte_read(port, 10);
|
||||
result = PS2_byte_read(pIF, 10);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
// No ID => keyboard
|
||||
printf ("PS2_init(%d) - Keyboard detected\n", port);
|
||||
printf ("PS2_init(%p) - Keyboard detected\n", pIF->pCTRL);
|
||||
|
||||
// send Get Device-ID
|
||||
result = PS2_cmd(port, 0xF2, 1000);
|
||||
result = PS2_cmd(pIF, 0xF2, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("Get Device-ID error %08X\n", result);
|
||||
break;
|
||||
}
|
||||
id[0] = PS2_byte_read(port, 1000);
|
||||
id[1] = PS2_byte_read(port, 1000);
|
||||
printf ("PS2_init(%d) - Device-ID: %02X%02X\n", port, id[0], id[1]);
|
||||
id[0] = PS2_byte_read(pIF, 1000);
|
||||
id[1] = PS2_byte_read(pIF, 1000);
|
||||
printf ("PS2_init(%p) - Device-ID: %02X%02X\n", pIF->pCTRL, id[0], id[1]);
|
||||
|
||||
// Get Scan code set (phase 1)
|
||||
result = PS2_cmd(port, 0xF0, 1000);
|
||||
result = PS2_cmd(pIF, 0xF0, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("1. Get Scan code error %08X\n", result);
|
||||
break;
|
||||
}
|
||||
// Get Scan code set (phase 2)
|
||||
result = PS2_cmd(port, 0x00, 1000);
|
||||
result = PS2_cmd(pIF, 0x00, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("2. Get Scan code error %08X\n", result);
|
||||
break;
|
||||
}
|
||||
result = PS2_byte_read(port, 1000);
|
||||
printf ("PS2_init(%d) - Current scan code set = %d\n", port, result);
|
||||
result = PS2_byte_read(pIF, 1000);
|
||||
printf ("PS2_init(%p) - Current scan code set = %d\n", pIF->pCTRL, result);
|
||||
|
||||
// if Scan code SET != 2
|
||||
if (result != 2)
|
||||
{
|
||||
printf ("PS2_init(%d) - Set scan code set = 2\n", port);
|
||||
printf ("PS2_init(%p) - Set scan code set = 2\n", pIF->pCTRL);
|
||||
// Set Scan code set (phase 1)
|
||||
result = PS2_cmd(port, 0xF0, 1000);
|
||||
result = PS2_cmd(pIF, 0xF0, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("1. Set Scan code error %08X\n", result);
|
||||
break;
|
||||
}
|
||||
// Set Scan code set (phase 2)
|
||||
result = PS2_cmd(port, 0x02, 1000);
|
||||
result = PS2_cmd(pIF, 0x02, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("2. Set Scan code error %08X\n", result);
|
||||
@@ -167,39 +178,39 @@ uint32_t PS2_init(uint32_t port)
|
||||
// Test LEDs
|
||||
for (i=0; i < 4; i++)
|
||||
{
|
||||
result = PS2_cmd(port, 0xED, 1000);
|
||||
result = PS2_cmd(pIF, 0xED, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("1. LED error %08X\n", result);
|
||||
break;
|
||||
}
|
||||
result = PS2_cmd(port, 0x02, 1000);
|
||||
result = PS2_cmd(pIF, 0x02, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("2. LED error %08X\n", result);
|
||||
break;
|
||||
}
|
||||
sleep(100);
|
||||
result = PS2_cmd(port, 0xED, 1000);
|
||||
result = PS2_cmd(pIF, 0xED, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("1. LED error %08X\n", result);
|
||||
break;
|
||||
}
|
||||
result = PS2_cmd(port, 0x04, 1000);
|
||||
result = PS2_cmd(pIF, 0x04, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("2. LED error %08X\n", result);
|
||||
break;
|
||||
}
|
||||
sleep(100);
|
||||
result = PS2_cmd(port, 0xED, 1000);
|
||||
result = PS2_cmd(pIF, 0xED, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("1. LED error %08X\n", result);
|
||||
break;
|
||||
}
|
||||
result = PS2_cmd(port, 0x01, 1000);
|
||||
result = PS2_cmd(pIF, 0x01, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("2. LED error %08X\n", result);
|
||||
@@ -207,13 +218,13 @@ uint32_t PS2_init(uint32_t port)
|
||||
}
|
||||
sleep(100);
|
||||
}
|
||||
result = PS2_cmd(port, 0xED, 1000);
|
||||
result = PS2_cmd(pIF, 0xED, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("1. LED error %08X\n", result);
|
||||
break;
|
||||
}
|
||||
result = PS2_cmd(port, 0x00, 1000);
|
||||
result = PS2_cmd(pIF, 0x00, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("2. LED error %08X\n", result);
|
||||
@@ -229,19 +240,19 @@ uint32_t PS2_init(uint32_t port)
|
||||
if (result == 0)
|
||||
{
|
||||
// We got zero => yes, it's a mouse
|
||||
printf ("PS2_init(%d) - Mouse device detected\n", port);
|
||||
printf ("PS2_init(%p) - Mouse device detected\n", pIF->pCTRL);
|
||||
|
||||
// send Get Device-ID
|
||||
result = PS2_cmd(port, 0xF2, 1000);
|
||||
result = PS2_cmd(pIF, 0xF2, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("Get Device-ID error %08X\n", result);
|
||||
break;
|
||||
}
|
||||
id[0] = PS2_byte_read(port, 1000);
|
||||
printf ("PS2_init(%d) - Device-ID: %02X\n", port, id[0]);
|
||||
printf ("PS2_init(%d) - Enable stream mode...", port);
|
||||
result = PS2_cmd(port, 0xF4, 1000);
|
||||
id[0] = PS2_byte_read(pIF, 1000);
|
||||
printf ("PS2_init(%p) - Device-ID: %02X\n", pIF->pCTRL, id[0]);
|
||||
printf ("PS2_init(%p) - Enable stream mode...", pIF->pCTRL);
|
||||
result = PS2_cmd(pIF, 0xF4, 1000);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf ("error %08X\n", result);
|
||||
@@ -255,7 +266,7 @@ uint32_t PS2_init(uint32_t port)
|
||||
}
|
||||
|
||||
// Flush buffer
|
||||
PS2_flush(port);
|
||||
PS2_flush(pIF);
|
||||
|
||||
if (IS_ERROR(result))
|
||||
return result;
|
||||
@@ -264,5 +275,208 @@ uint32_t PS2_init(uint32_t port)
|
||||
*pIF->pCTRL |= SYS_PS2_BIT_RX_INTEN;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// BEGIN QUICK AND DIRTY
|
||||
// -------------------------------------------------------------
|
||||
//keymap for the AT keyboard SG layout
|
||||
typedef struct
|
||||
{
|
||||
uint8_t scancode;
|
||||
uint8_t unshifted;
|
||||
uint8_t shifted;
|
||||
uint8_t altered;
|
||||
} libsys_key_entry_t;
|
||||
|
||||
#define SHIFTED (1<<0)
|
||||
#define ALTERED (1<<1)
|
||||
#define CONTROLLED (1<<2)
|
||||
|
||||
static const libsys_key_entry_t __keymap_german[] =
|
||||
{
|
||||
{0x1c, 'a', 'A', 'a'},
|
||||
{0x32, 'b', 'B', 'b'},
|
||||
{0x21, 'c', 'C', 'c'},
|
||||
{0x23, 'd', 'D', 'd'},
|
||||
{0x24, 'e', 'E', '€'},
|
||||
{0x2b, 'f', 'F', 'f'},
|
||||
{0x34, 'g', 'G', 'g'},
|
||||
{0x33, 'h', 'H', 'h'},
|
||||
{0x43, 'i', 'I', 'i'},
|
||||
{0x3b, 'j', 'J', 'j'},
|
||||
{0x42, 'k', 'K', 'k'},
|
||||
{0x4b, 'l', 'L', 'l'},
|
||||
{0x3a, 'm', 'M', 'µ'},
|
||||
{0x31, 'n', 'N', 'n'},
|
||||
{0x44, 'o', 'O', 'o'},
|
||||
{0x4d, 'p', 'P', 'p'},
|
||||
{0x15, 'q', 'Q', '@'},
|
||||
{0x2d, 'r', 'R', 'r'},
|
||||
{0x1b, 's', 'S', 's'},
|
||||
{0x2c, 't', 'T', 't'},
|
||||
{0x3c, 'u', 'U', 'u'},
|
||||
{0x2a, 'v', 'V', 'v'},
|
||||
{0x1d, 'w', 'W', 'w'},
|
||||
{0x22, 'x', 'X', 'x'},
|
||||
{0x1a, 'y', 'Y', 'y'},
|
||||
{0x35, 'z', 'Z', 'z'},
|
||||
{0x16, '1', '!', '1'},
|
||||
{0x1e, '2', '"', '2'},
|
||||
{0x26, '3', '§', '3'},
|
||||
{0x25, '4', '$', '4'},
|
||||
{0x2e, '5', '%', '5'},
|
||||
{0x36, '6', '&', '6'},
|
||||
{0x3d, '7', '/', '{'},
|
||||
{0x3e, '8', '(', '['},
|
||||
{0x46, '9', ')', ']'},
|
||||
{0x45, '0', '=', '}'},
|
||||
{0x4e, 'ß', '?', '\\'},
|
||||
{0x29, ' ', ' ', ' '},
|
||||
{0x41, ',', ';', ','},
|
||||
{0x49, '.', ':', '.'},
|
||||
{0x4a, '-', '_', '-'},
|
||||
{0x52, 'ä', 'Ä', 'ä'},
|
||||
{0x4c, 'ö', 'Ö', 'ö'},
|
||||
{0x54, 'ü', 'Ü', 'ü'},
|
||||
{0x5a, '\n', '\n', '\n'}, //RETURN
|
||||
{0x5b, '+', '*', '~'},
|
||||
{0x5d, '#', '\'', '#'},
|
||||
{0x0e, '^', '°', '^'},
|
||||
{0x61, '<', '>', '|'},
|
||||
{0x66, '\b', '\b', '\b'},
|
||||
{0} //sentinel
|
||||
|
||||
};
|
||||
|
||||
static char __findkey(char scancode, int mode)
|
||||
{
|
||||
const libsys_key_entry_t *p = __keymap_german;
|
||||
while (p->scancode)
|
||||
{
|
||||
if (p->scancode == scancode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case SHIFTED:
|
||||
return p->shifted;
|
||||
case ALTERED:
|
||||
return p->altered;
|
||||
case ALTERED|SHIFTED:
|
||||
default:
|
||||
return p->unshifted;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define RELEASE 0x8000
|
||||
#define SPECIALKEY 0x4000
|
||||
#define EXTENDED 0x2000
|
||||
#define X_CONTROLLED 0x0400
|
||||
#define X_ALTERED 0x0200
|
||||
#define X_SHIFTED 0x0100
|
||||
#define CAPS (SPECIALKEY|0x58)
|
||||
#define F1 (SPECIALKEY|0x05)
|
||||
#define F2 (SPECIALKEY|0x06)
|
||||
#define F3 (SPECIALKEY|0x04)
|
||||
#define F4 (SPECIALKEY|0x0c)
|
||||
#define F5 (SPECIALKEY|0x03)
|
||||
#define F6 (SPECIALKEY|0x0b)
|
||||
#define F7 (SPECIALKEY|0x83)
|
||||
#define F8 (SPECIALKEY|0x0a)
|
||||
#define F9 (SPECIALKEY|0x01)
|
||||
#define F10 (SPECIALKEY|0x09)
|
||||
#define F11 (SPECIALKEY|0x78)
|
||||
#define F12 (SPECIALKEY|0x07)
|
||||
#define ARROW_UP (SPECIALKEY|EXTENDED|0x75)
|
||||
#define ARROW_DOWN (SPECIALKEY|EXTENDED|0x72)
|
||||
#define ARROW_LEFT (SPECIALKEY|EXTENDED|0x6b)
|
||||
#define ARROW_RIGHT (SPECIALKEY|EXTENDED|0x74)
|
||||
|
||||
static uint32_t readchar(ps2_if_t *pIF)
|
||||
{
|
||||
if (!pIF)
|
||||
return -1;
|
||||
|
||||
while (!(SYS_PS2_BIT_RX_AVAIL & *pIF->pCTRL));
|
||||
|
||||
return (*pIF->pDATA & 0xFF);
|
||||
|
||||
}
|
||||
|
||||
uint32_t con_readchar(ps2_if_t *pIF)
|
||||
{
|
||||
uint8_t c;
|
||||
static char mode = 0;
|
||||
static char nextrelease = 0;
|
||||
static char extended = 0;
|
||||
int flags = 0;
|
||||
int char_valid = 0;
|
||||
uint8_t key;
|
||||
|
||||
key = readchar(pIF);
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case 0xf0: //release key
|
||||
nextrelease = 1;
|
||||
break;
|
||||
case 0x14: //control key
|
||||
if (nextrelease)
|
||||
{
|
||||
mode &= ~CONTROLLED;
|
||||
} else
|
||||
{
|
||||
mode |= CONTROLLED;
|
||||
}
|
||||
nextrelease = 0;
|
||||
break;
|
||||
case 0x12: //left SHIFT
|
||||
case 0x59: //right SHIFT
|
||||
if (nextrelease)
|
||||
{
|
||||
mode &= ~SHIFTED;
|
||||
} else
|
||||
{
|
||||
mode |= SHIFTED;
|
||||
}
|
||||
nextrelease = 0;
|
||||
break;
|
||||
case 0x11: //left and right ALT (right one also with E0)
|
||||
if (nextrelease)
|
||||
{
|
||||
mode &= ~ALTERED;
|
||||
} else
|
||||
{
|
||||
mode |= ALTERED;
|
||||
}
|
||||
nextrelease = 0;
|
||||
break;
|
||||
case 0xe0: //extended key following
|
||||
extended = 1;
|
||||
break;
|
||||
default:
|
||||
if (nextrelease) flags |= RELEASE;
|
||||
if (extended) flags |= EXTENDED;
|
||||
flags |= mode << 8;
|
||||
c = __findkey(key, mode);
|
||||
char_valid = (c && ((flags & RELEASE) != RELEASE));
|
||||
nextrelease = 0;
|
||||
extended = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (char_valid)
|
||||
{
|
||||
// fprintf(stderr, "c = %c (%d), flags = 0x%08X, mode = 0x%08X\n", c, c, flags, mode);
|
||||
return c;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
// -------------------------------------------------------------
|
||||
// END QUICK AND DIRTY
|
||||
// -------------------------------------------------------------
|
||||
|
||||
+10
-6
@@ -33,11 +33,15 @@ typedef struct _sps2_if_t
|
||||
// Functions
|
||||
// --------------------------------------------------
|
||||
uint32_t PS2_get_num_if(void);
|
||||
ps2_if_t *PS2_get_if(uint32_t port);
|
||||
uint32_t PS2_init(uint32_t port);
|
||||
void PS2_byte_write(uint32_t port, uint8_t byte);
|
||||
uint32_t PS2_byte_read(uint32_t port, uint32_t timeout_ms);
|
||||
uint32_t PS2_cmd(uint32_t port, uint8_t cmd, uint32_t ack_timeout_ms);
|
||||
void PS2_flush(uint32_t port);
|
||||
uint32_t PS2_init(ps2_if_t *pIF);
|
||||
void PS2_byte_write(ps2_if_t *pIF, uint8_t byte);
|
||||
uint32_t PS2_byte_read(ps2_if_t *pIF, uint32_t timeout_ms);
|
||||
|
||||
int PS2_readchar(void const *pInst);
|
||||
void PS2_open(void const *pInst);
|
||||
void PS2_close(void const *pInst);
|
||||
|
||||
uint32_t PS2_cmd(ps2_if_t *pIF, uint8_t cmd, uint32_t ack_timeout_ms);
|
||||
void PS2_flush(ps2_if_t *pIF);
|
||||
|
||||
#endif // PS2_H
|
||||
|
||||
Executable
+164
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* 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 <assert.h>
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <board.h>
|
||||
#include "screen.h"
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
void cg_open(void const *pInst)
|
||||
{
|
||||
assert (pInst);
|
||||
|
||||
vga_if_t *pIF = (vga_if_t*)pInst;
|
||||
cg_clr_screen(&vga_if);
|
||||
}
|
||||
|
||||
void cg_close(void const *pInst)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void cg_writechar(void const *pInst, char c)
|
||||
{
|
||||
assert (pInst);
|
||||
|
||||
vga_if_t *pIF = (vga_if_t*)pInst;
|
||||
uint32_t code;
|
||||
|
||||
// Output translation
|
||||
switch(c)
|
||||
{
|
||||
case 'Ä':
|
||||
code = 196;
|
||||
break;
|
||||
|
||||
case 'ä':
|
||||
code = 228;
|
||||
break;
|
||||
|
||||
case 'Ö':
|
||||
code = 214;
|
||||
break;
|
||||
|
||||
case 'ö':
|
||||
code = 246;
|
||||
break;
|
||||
|
||||
case 'Ü':
|
||||
code = 220;
|
||||
break;
|
||||
|
||||
case 'ü':
|
||||
code = 252;
|
||||
break;
|
||||
|
||||
case '&':
|
||||
code = 230;
|
||||
break;
|
||||
|
||||
case '§':
|
||||
code = 167;
|
||||
break;
|
||||
|
||||
case 'ß':
|
||||
code = 223;
|
||||
break;
|
||||
|
||||
case '°':
|
||||
code = 176;
|
||||
break;
|
||||
|
||||
case 'µ':
|
||||
code = 181;
|
||||
break;
|
||||
|
||||
default:
|
||||
code = (uint32_t)c;
|
||||
break;
|
||||
}
|
||||
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pDATA = code;
|
||||
|
||||
if (c == 0x0A)
|
||||
{
|
||||
cg_clr_line(pIF);
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pDATA = 0x0D;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void cg_set_csr_x(vga_if_t *pIF, uint32_t coord)
|
||||
{
|
||||
assert (pIF);
|
||||
|
||||
// Set cursor
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pCSRX = coord;
|
||||
}
|
||||
|
||||
void cg_set_csr_y(vga_if_t *pIF, uint32_t coord)
|
||||
{
|
||||
assert (pIF);
|
||||
|
||||
// Set cursor
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pCSRY = coord;
|
||||
}
|
||||
|
||||
void cg_clr_line(vga_if_t *pIF)
|
||||
{
|
||||
assert (pIF);
|
||||
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pCTRL |= SYS_VGA_BIT_CLRLINE;
|
||||
}
|
||||
|
||||
void cg_clr_screen(vga_if_t *pIF)
|
||||
{
|
||||
assert (pIF);
|
||||
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pCTRL |= SYS_VGA_BIT_CLRSCR;
|
||||
|
||||
// Cursor home
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pCSRX = 0;
|
||||
|
||||
while (!(*pIF->pCTRL & SYS_VGA_BIT_CGRDY));
|
||||
*pIF->pCSRY = 0;
|
||||
|
||||
}
|
||||
|
||||
uint32_t Screen_get_resx(void)
|
||||
{
|
||||
uint32_t volatile *pVGA_res = (uint32_t*)SYS_VGA_RES;
|
||||
|
||||
return (0xFFF & (*pVGA_res >> 0));
|
||||
}
|
||||
|
||||
uint32_t Screen_get_resy(void)
|
||||
{
|
||||
uint32_t volatile *pVGA_res = (uint32_t*)SYS_VGA_RES;
|
||||
|
||||
return (0xFFF & (*pVGA_res >> 12));
|
||||
}
|
||||
|
||||
uint32_t Screen_get_fps(void)
|
||||
{
|
||||
uint32_t volatile *pVGA_res = (uint32_t*)SYS_VGA_RES;
|
||||
|
||||
return (0xFF & (*pVGA_res >> 24));
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* File: screen.h
|
||||
* Author: jens
|
||||
*
|
||||
* Created on 8. Januar 2017, 14:22
|
||||
*/
|
||||
|
||||
#ifndef SCREEN_H
|
||||
#define SCREEN_H
|
||||
|
||||
typedef struct _svga_if_t
|
||||
{
|
||||
volatile uint32_t *pCTRL;
|
||||
volatile uint32_t *pDATA;
|
||||
volatile uint32_t *pCSRX;
|
||||
volatile uint32_t *pCSRY;
|
||||
} vga_if_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void cg_set_csr_x(vga_if_t *pIF, uint32_t coord);
|
||||
void cg_set_csr_y(vga_if_t *pIF, uint32_t coord);
|
||||
void cg_clr_line(vga_if_t *pIF);
|
||||
void cg_clr_screen(vga_if_t *pIF);
|
||||
|
||||
uint32_t Screen_get_resx(void);
|
||||
uint32_t Screen_get_resy(void);
|
||||
uint32_t Screen_get_fps(void);
|
||||
|
||||
void cg_writechar(void const *pInst, char c);
|
||||
void cg_open(void const *pInst);
|
||||
void cg_close(void const *pInst);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SCREEN_H */
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 <assert.h>
|
||||
#include <board.h>
|
||||
#include "uart.h"
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// Globals
|
||||
// ---------------------------------------------------------------------------------
|
||||
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}
|
||||
};
|
||||
|
||||
// ------------------------------------
|
||||
// Low-level I/O
|
||||
// ------------------------------------
|
||||
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);
|
||||
|
||||
*pReg->pDATA = (uint32_t)c;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* File: uart.h
|
||||
* Author: jens
|
||||
*
|
||||
* Created on 9. Januar 2017, 08:05
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef UART_H
|
||||
#define UART_H
|
||||
|
||||
typedef struct _suart_if_t
|
||||
{
|
||||
volatile uint32_t *pCTRL;
|
||||
volatile uint32_t *pDATA;
|
||||
volatile uint32_t *pBAUD;
|
||||
} uart_if_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int UART_readchar(void const *pInst);
|
||||
void UART_writechar(void const *pInst, char c);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* UART_H */
|
||||
|
||||
Reference in New Issue
Block a user