summaryrefslogtreecommitdiff
path: root/bsp/x86/drivers
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2021-05-28 16:20:08 +0800
committerGitHub <[email protected]>2021-05-28 16:20:08 +0800
commit92beddf3bccf6346e26aa097f82464456fb8e6bd (patch)
tree197e4a108118dda016ea02274172f0c40e7ee8ed /bsp/x86/drivers
parentb18a99b44240ec3152011e159cc24a5af8dff0ce (diff)
parent03f4d40e30f3c94e1db0b3a65b3610dee695694a (diff)
Merge pull request #4737 from mysterywolf/3,1,xformatv3.1.5
[lts 3.1.x] format codes
Diffstat (limited to 'bsp/x86/drivers')
-rw-r--r--bsp/x86/drivers/board.c20
-rw-r--r--bsp/x86/drivers/console.c96
-rw-r--r--bsp/x86/drivers/include/bsp.h176
-rw-r--r--bsp/x86/drivers/include/grub.h80
-rw-r--r--bsp/x86/drivers/keyboard.c542
-rw-r--r--bsp/x86/drivers/serial.c42
6 files changed, 478 insertions, 478 deletions
diff --git a/bsp/x86/drivers/board.c b/bsp/x86/drivers/board.c
index 0c0d0222f7..cb92a3a0bf 100644
--- a/bsp/x86/drivers/board.c
+++ b/bsp/x86/drivers/board.c
@@ -21,13 +21,13 @@
static void rt_timer_handler(int vector, void* param)
{
- rt_tick_increase();
+ rt_tick_increase();
}
#ifdef RT_USING_HOOK
static void idle_hook(void)
{
- asm volatile("sti; hlt": : :"memory");
+ asm volatile("sti; hlt": : :"memory");
}
#endif
@@ -37,17 +37,17 @@ static void idle_hook(void)
*/
void rt_hw_board_init(void)
{
- /* initialize 8253 clock to interrupt 1000 times/sec */
- outb(TIMER_MODE, TIMER_SEL0|TIMER_RATEGEN|TIMER_16BIT);
- outb(IO_TIMER1, TIMER_DIV(RT_TICK_PER_SECOND) % 256);
- outb(IO_TIMER1, TIMER_DIV(RT_TICK_PER_SECOND) / 256);
+ /* initialize 8253 clock to interrupt 1000 times/sec */
+ outb(TIMER_MODE, TIMER_SEL0|TIMER_RATEGEN|TIMER_16BIT);
+ outb(IO_TIMER1, TIMER_DIV(RT_TICK_PER_SECOND) % 256);
+ outb(IO_TIMER1, TIMER_DIV(RT_TICK_PER_SECOND) / 256);
- /* install interrupt handler */
- rt_hw_interrupt_install(INTTIMER0, rt_timer_handler, RT_NULL, "tick");
- rt_hw_interrupt_umask(INTTIMER0);
+ /* install interrupt handler */
+ rt_hw_interrupt_install(INTTIMER0, rt_timer_handler, RT_NULL, "tick");
+ rt_hw_interrupt_umask(INTTIMER0);
#ifdef RT_USING_HOOK
- rt_thread_idle_sethook(idle_hook);
+ rt_thread_idle_sethook(idle_hook);
#endif
}
diff --git a/bsp/x86/drivers/console.c b/bsp/x86/drivers/console.c
index e8fc66093a..6741efb714 100644
--- a/bsp/x86/drivers/console.c
+++ b/bsp/x86/drivers/console.c
@@ -87,7 +87,7 @@ static void rt_cga_putc(int c)
break;
case '\n':
crt_pos += CRT_COLS;
- /* cascade */
+ /* cascade */
case '\r':
crt_pos -= (crt_pos % CRT_COLS);
break;
@@ -99,7 +99,7 @@ static void rt_cga_putc(int c)
rt_console_putc(' ');
break;
default:
- crt_buf[crt_pos++] = c; /* write the character */
+ crt_buf[crt_pos++] = c; /* write the character */
break;
}
@@ -214,47 +214,47 @@ static rt_size_t rt_console_read(rt_device_t dev, rt_off_t pos, void* buffer, rt
static void rt_console_isr(int vector, void* param)
{
char c;
- rt_bool_t ret;
+ rt_bool_t ret;
rt_base_t level;
- if(INTUART0_RX == vector)
- {
- c = rt_serial_getc();
- ret = RT_TRUE;
- }
- else
- {
- rt_keyboard_isr();
+ if(INTUART0_RX == vector)
+ {
+ c = rt_serial_getc();
+ ret = RT_TRUE;
+ }
+ else
+ {
+ rt_keyboard_isr();
- ret = rt_keyboard_getc(&c);
- }
+ ret = rt_keyboard_getc(&c);
+ }
- if(ret == RT_FALSE)
- {
- /* do nothing */
- }
- else
- {
- /* disable interrupt */
- level = rt_hw_interrupt_disable();
+ if(ret == RT_FALSE)
+ {
+ /* do nothing */
+ }
+ else
+ {
+ /* disable interrupt */
+ level = rt_hw_interrupt_disable();
- /* save character */
- rx_buffer[save_index] = c;
- save_index ++;
- if (save_index >= CONSOLE_RX_BUFFER_SIZE)
- save_index = 0;
+ /* save character */
+ rx_buffer[save_index] = c;
+ save_index ++;
+ if (save_index >= CONSOLE_RX_BUFFER_SIZE)
+ save_index = 0;
- /* if the next position is read index, discard this 'read char' */
- if (save_index == read_index)
- {
- read_index ++;
- if (read_index >= CONSOLE_RX_BUFFER_SIZE)
- read_index = 0;
- }
+ /* if the next position is read index, discard this 'read char' */
+ if (save_index == read_index)
+ {
+ read_index ++;
+ if (read_index >= CONSOLE_RX_BUFFER_SIZE)
+ read_index = 0;
+ }
- /* enable interrupt */
- rt_hw_interrupt_enable(level);
- }
+ /* enable interrupt */
+ rt_hw_interrupt_enable(level);
+ }
/* invoke callback */
if (console_device.rx_indicate != RT_NULL)
@@ -263,8 +263,8 @@ static void rt_console_isr(int vector, void* param)
/* get rx length */
rx_length = read_index > save_index ?
- CONSOLE_RX_BUFFER_SIZE - read_index + save_index :
- save_index - read_index;
+ CONSOLE_RX_BUFFER_SIZE - read_index + save_index :
+ save_index - read_index;
if(rx_length > 0)
{
@@ -284,8 +284,8 @@ static void rt_console_isr(int vector, void* param)
void rt_hw_console_init(void)
{
rt_cga_init();
- rt_serial_init();
- init_keyboard();
+ rt_serial_init();
+ init_keyboard();
/* install keyboard isr */
rt_hw_interrupt_install(INTKEYBOARD, rt_console_isr, RT_NULL, "kbd");
@@ -294,14 +294,14 @@ void rt_hw_console_init(void)
rt_hw_interrupt_install(INTUART0_RX, rt_console_isr, RT_NULL, "COM1");
rt_hw_interrupt_umask(INTUART0_RX);
- console_device.type = RT_Device_Class_Char;
+ console_device.type = RT_Device_Class_Char;
console_device.rx_indicate = RT_NULL;
console_device.tx_complete = RT_NULL;
- console_device.init = rt_console_init;
- console_device.open = rt_console_open;
- console_device.close = rt_console_close;
- console_device.read = rt_console_read;
- console_device.write = rt_console_write;
+ console_device.init = rt_console_init;
+ console_device.open = rt_console_open;
+ console_device.close = rt_console_close;
+ console_device.read = rt_console_read;
+ console_device.write = rt_console_write;
console_device.control = rt_console_control;
console_device.user_data = RT_NULL;
@@ -318,8 +318,8 @@ void rt_hw_console_init(void)
* @param str the displayed string
*
* Modified:
- * caoxl 2009-10-14
- * the name is change to rt_hw_console_output in the v0.3.0
+ * caoxl 2009-10-14
+ * the name is change to rt_hw_console_output in the v0.3.0
*
*/
void rt_hw_console_output(const char* str)
diff --git a/bsp/x86/drivers/include/bsp.h b/bsp/x86/drivers/include/bsp.h
index 724f518c6e..3c7960ed1c 100644
--- a/bsp/x86/drivers/include/bsp.h
+++ b/bsp/x86/drivers/include/bsp.h
@@ -19,127 +19,127 @@
#ifdef __cplusplus
extern "C" {
#endif
-
+
/*******************************************************************/
/* Timer Register */
/*******************************************************************/
-#define TIMER_CNTR0 (IO_TIMER1 + 0) /* timer 0 counter port */
-#define TIMER_CNTR1 (IO_TIMER1 + 1) /* timer 1 counter port */
-#define TIMER_CNTR2 (IO_TIMER1 + 2) /* timer 2 counter port */
-#define TIMER_MODE (IO_TIMER1 + 3) /* timer mode port */
-#define TIMER_SEL0 0x00 /* select counter 0 */
-#define TIMER_SEL1 0x40 /* select counter 1 */
-#define TIMER_INTTC 0x00 /* mode 0, intr on terminal cnt */
-#define TIMER_ONESHOT 0x02 /* mode 1, one shot */
-#define TIMER_RATEGEN 0x04 /* mode 2, rate generator */
-#define TIMER_SQWAVE 0x06 /* mode 3, square wave */
-#define TIMER_SWSTROBE 0x08 /* mode 4, s/w triggered strobe */
-#define TIMER_HWSTROBE 0x0a /* mode 5, h/w triggered strobe */
-#define TIMER_LATCH 0x00 /* latch counter for reading */
-#define TIMER_LSB 0x10 /* r/w counter LSB */
-#define TIMER_MSB 0x20 /* r/w counter MSB */
-#define TIMER_16BIT 0x30 /* r/w counter 16 bits, LSB first */
-#define TIMER_BCD 0x01 /* count in BCD */
+#define TIMER_CNTR0 (IO_TIMER1 + 0) /* timer 0 counter port */
+#define TIMER_CNTR1 (IO_TIMER1 + 1) /* timer 1 counter port */
+#define TIMER_CNTR2 (IO_TIMER1 + 2) /* timer 2 counter port */
+#define TIMER_MODE (IO_TIMER1 + 3) /* timer mode port */
+#define TIMER_SEL0 0x00 /* select counter 0 */
+#define TIMER_SEL1 0x40 /* select counter 1 */
+#define TIMER_INTTC 0x00 /* mode 0, intr on terminal cnt */
+#define TIMER_ONESHOT 0x02 /* mode 1, one shot */
+#define TIMER_RATEGEN 0x04 /* mode 2, rate generator */
+#define TIMER_SQWAVE 0x06 /* mode 3, square wave */
+#define TIMER_SWSTROBE 0x08 /* mode 4, s/w triggered strobe */
+#define TIMER_HWSTROBE 0x0a /* mode 5, h/w triggered strobe */
+#define TIMER_LATCH 0x00 /* latch counter for reading */
+#define TIMER_LSB 0x10 /* r/w counter LSB */
+#define TIMER_MSB 0x20 /* r/w counter MSB */
+#define TIMER_16BIT 0x30 /* r/w counter 16 bits, LSB first */
+#define TIMER_BCD 0x01 /* count in BCD */
-#define TIMER_FREQ 1193182
-#define TIMER_DIV(x) ((TIMER_FREQ+(x)/2)/(x))
+#define TIMER_FREQ 1193182
+#define TIMER_DIV(x) ((TIMER_FREQ+(x)/2)/(x))
-#define IO_TIMER1 0x040 /* 8253 Timer #1 */
+#define IO_TIMER1 0x040 /* 8253 Timer #1 */
/*******************************************************************/
/* Interrupt Controller */
/*******************************************************************/
/* these are processor defined */
-#define T_DIVIDE 0 /* divide error */
-#define T_DEBUG 1 /* debug exception */
-#define T_NMI 2 /* non-maskable interrupt */
-#define T_BRKPT 3 /* breakpoint */
-#define T_OFLOW 4 /* overflow */
-#define T_BOUND 5 /* bounds check */
-#define T_ILLOP 6 /* illegal opcode */
-#define T_DEVICE 7 /* device not available */
-#define T_DBLFLT 8 /* double fault */
+#define T_DIVIDE 0 /* divide error */
+#define T_DEBUG 1 /* debug exception */
+#define T_NMI 2 /* non-maskable interrupt */
+#define T_BRKPT 3 /* breakpoint */
+#define T_OFLOW 4 /* overflow */
+#define T_BOUND 5 /* bounds check */
+#define T_ILLOP 6 /* illegal opcode */
+#define T_DEVICE 7 /* device not available */
+#define T_DBLFLT 8 /* double fault */
/* 9 is reserved */
-#define T_TSS 10 /* invalid task switch segment */
-#define T_SEGNP 11 /* segment not present */
-#define T_STACK 12 /* stack exception */
-#define T_GPFLT 13 /* genernal protection fault */
-#define T_PGFLT 14 /* page fault */
+#define T_TSS 10 /* invalid task switch segment */
+#define T_SEGNP 11 /* segment not present */
+#define T_STACK 12 /* stack exception */
+#define T_GPFLT 13 /* genernal protection fault */
+#define T_PGFLT 14 /* page fault */
/* 15 is reserved */
-#define T_FPERR 16 /* floating point error */
-#define T_ALIGN 17 /* aligment check */
-#define T_MCHK 18 /* machine check */
-#define T_DEFAULT 500 /* catchall */
+#define T_FPERR 16 /* floating point error */
+#define T_ALIGN 17 /* aligment check */
+#define T_MCHK 18 /* machine check */
+#define T_DEFAULT 500 /* catchall */
-#define INTTIMER0 0
-#define INTKEYBOARD 1
-#define INTUART0_RX 4
-#define CLOCK_IRQ 0
-#define KEYBOARD_IRQ 1
-#define CASCADE_IRQ 2 /* cascade enable for 2nd AT controller */
-#define ETHER_IRQ 3 /* default ethernet interrupt vector */
-#define SECONDARY_IRQ 3 /* RS232 interrupt vector for port 2 */
-#define RS232_IRQ 4 /* RS232 interrupt vector for port 1 */
-#define XT_WINI_IRQ 5 /* xt winchester */
-#define FLOPPY_IRQ 6 /* floppy disk */
-#define PRINTER_IRQ 7
-#define AT_WINI_IRQ 14 /* at winchester */
+#define INTTIMER0 0
+#define INTKEYBOARD 1
+#define INTUART0_RX 4
+#define CLOCK_IRQ 0
+#define KEYBOARD_IRQ 1
+#define CASCADE_IRQ 2 /* cascade enable for 2nd AT controller */
+#define ETHER_IRQ 3 /* default ethernet interrupt vector */
+#define SECONDARY_IRQ 3 /* RS232 interrupt vector for port 2 */
+#define RS232_IRQ 4 /* RS232 interrupt vector for port 1 */
+#define XT_WINI_IRQ 5 /* xt winchester */
+#define FLOPPY_IRQ 6 /* floppy disk */
+#define PRINTER_IRQ 7
+#define AT_WINI_IRQ 14 /* at winchester */
/* I/O Addresses of the two 8259A programmable interrupt controllers */
-#define IO_PIC1 0x20 /* Master(IRQs 0-7) */
-#define IO_PIC2 0xa0 /* Slave(IRQs 8-15) */
-#define IRQ_SLAVE 0x2 /* IRQ at which slave connects to master */
-#define IRQ_OFFSET 0x20 /* IRQ 0 corresponds to int IRQ_OFFSET */
+#define IO_PIC1 0x20 /* Master(IRQs 0-7) */
+#define IO_PIC2 0xa0 /* Slave(IRQs 8-15) */
+#define IRQ_SLAVE 0x2 /* IRQ at which slave connects to master */
+#define IRQ_OFFSET 0x20 /* IRQ 0 corresponds to int IRQ_OFFSET */
-#define MAX_HANDLERS 16 /*max number of isr handler*/
+#define MAX_HANDLERS 16 /*max number of isr handler*/
/*******************************************************************/
/* CRT Register */
/*******************************************************************/
-#define MONO_BASE 0x3b4
-#define MONO_BUF 0xb0000
-#define CGA_BASE 0x3d4
-#define CGA_BUF 0xb8000
+#define MONO_BASE 0x3b4
+#define MONO_BUF 0xb0000
+#define CGA_BASE 0x3d4
+#define CGA_BUF 0xb8000
-#define CRT_ROWS 25
-#define CRT_COLS 80
-#define CRT_SIZE (CRT_ROWS * CRT_COLS)
+#define CRT_ROWS 25
+#define CRT_COLS 80
+#define CRT_SIZE (CRT_ROWS * CRT_COLS)
/*******************************************************************/
/* Keyboard Register */
/*******************************************************************/
-#define KBSTATP 0x64 /* kbd controller status port(I) */
-#define KBS_DIB 0x01 /* kbd data in buffer */
-#define KBDATAP 0x60 /* kbd data port(I) */
+#define KBSTATP 0x64 /* kbd controller status port(I) */
+#define KBS_DIB 0x01 /* kbd data in buffer */
+#define KBDATAP 0x60 /* kbd data port(I) */
/* AT keyboard */
/* 8042 ports */
-#define KB_DATA 0x60 /* I/O port for keyboard data
- Read : Read Output Buffer
- Write: Write Input Buffer(8042 Data&8048 Command) */
-#define KB_CMD 0x64 /* I/O port for keyboard command
- Read : Read Status Register
- Write: Write Input Buffer(8042 Command) */
-#define LED_CODE 0xED
-#define KB_ACK 0xFA
+#define KB_DATA 0x60 /* I/O port for keyboard data
+ Read : Read Output Buffer
+ Write: Write Input Buffer(8042 Data&8048 Command) */
+#define KB_CMD 0x64 /* I/O port for keyboard command
+ Read : Read Status Register
+ Write: Write Input Buffer(8042 Command) */
+#define LED_CODE 0xED
+#define KB_ACK 0xFA
/*******************************************************************/
/* Serial Register */
/*******************************************************************/
/*Serial I/O code */
-#define COM1 0x3F8
-#define COMSTATUS 5
-#define COMDATA 0x01
-#define COMREAD 0
-#define COMWRITE 0
+#define COM1 0x3F8
+#define COMSTATUS 5
+#define COMDATA 0x01
+#define COMREAD 0
+#define COMWRITE 0
/* Bits definition of the Line Status Register (LSR)*/
-#define DR 0x01 /* Data Ready */
-#define OE 0x02 /* Overrun Error */
-#define PE 0x04 /* Parity Error */
-#define FE 0x08 /* Framing Error */
-#define BI 0x10 /* Break Interrupt */
-#define THRE 0x20 /* Transmitter Holding Register Empty */
-#define TEMT 0x40 /* Transmitter Empty */
-#define ERFIFO 0x80 /* Error receive Fifo */
+#define DR 0x01 /* Data Ready */
+#define OE 0x02 /* Overrun Error */
+#define PE 0x04 /* Parity Error */
+#define FE 0x08 /* Framing Error */
+#define BI 0x10 /* Break Interrupt */
+#define THRE 0x20 /* Transmitter Holding Register Empty */
+#define TEMT 0x40 /* Transmitter Empty */
+#define ERFIFO 0x80 /* Error receive Fifo */
#ifdef __cplusplus
}
diff --git a/bsp/x86/drivers/include/grub.h b/bsp/x86/drivers/include/grub.h
index dcfa36b819..f50edbe8a2 100644
--- a/bsp/x86/drivers/include/grub.h
+++ b/bsp/x86/drivers/include/grub.h
@@ -9,7 +9,7 @@
*
* Change Logs:
* Date Author Notes
- * 2006-10-09 Bernard the grub related definitions
+ * 2006-10-09 Bernard the grub related definitions
* (multiboot)
*/
@@ -17,75 +17,75 @@
#define __GRUB_H__
/* the magic number for the multiboot header. */
-#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
+#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
/* the flags for the multiboot header. */
-#define MULTIBOOT_HEADER_FLAGS 0x00000003
+#define MULTIBOOT_HEADER_FLAGS 0x00000003
/* the magic number passed by a multiboot-compliant boot loader. */
-#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
+#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
#ifndef __ASM__
/* the multiboot header. */
typedef struct multiboot_header
{
- unsigned long magic;
- unsigned long flags;
- unsigned long checksum;
- unsigned long header_addr;
- unsigned long load_addr;
- unsigned long load_end_addr;
- unsigned long bss_end_addr;
- unsigned long entry_addr;
+ unsigned long magic;
+ unsigned long flags;
+ unsigned long checksum;
+ unsigned long header_addr;
+ unsigned long load_addr;
+ unsigned long load_end_addr;
+ unsigned long bss_end_addr;
+ unsigned long entry_addr;
} multiboot_header_t;
/* the section header table for elf. */
typedef struct elf_section_header_table
{
- unsigned long num;
- unsigned long size;
- unsigned long addr;
- unsigned long shndx;
+ unsigned long num;
+ unsigned long size;
+ unsigned long addr;
+ unsigned long shndx;
} elf_section_header_table_t;
/* the multiboot information. */
typedef struct multiboot_info
{
- unsigned long flags;
- unsigned long mem_lower;
- unsigned long mem_upper;
- unsigned long boot_device;
- unsigned long cmdline;
- unsigned long mods_count;
- unsigned long mods_addr;
- union
- {
- aout_symbol_table_t aout_sym;
- elf_section_header_table_t elf_sec;
- } u;
- unsigned long mmap_length;
- unsigned long mmap_addr;
+ unsigned long flags;
+ unsigned long mem_lower;
+ unsigned long mem_upper;
+ unsigned long boot_device;
+ unsigned long cmdline;
+ unsigned long mods_count;
+ unsigned long mods_addr;
+ union
+ {
+ aout_symbol_table_t aout_sym;
+ elf_section_header_table_t elf_sec;
+ } u;
+ unsigned long mmap_length;
+ unsigned long mmap_addr;
} multiboot_info_t;
/* the module structure. */
typedef struct module
{
- unsigned long mod_start;
- unsigned long mod_end;
- unsigned long string;
- unsigned long reserved;
+ unsigned long mod_start;
+ unsigned long mod_end;
+ unsigned long string;
+ unsigned long reserved;
} module_t;
/* the memory map. be careful that the offset 0 is base_addr_low
but no size. */
typedef struct memory_map
{
- unsigned long size;
- unsigned long base_addr_low;
- unsigned long base_addr_high;
- unsigned long length_low;
- unsigned long length_high;
- unsigned long type;
+ unsigned long size;
+ unsigned long base_addr_low;
+ unsigned long base_addr_high;
+ unsigned long length_low;
+ unsigned long length_high;
+ unsigned long type;
} memory_map_t;
#endif
diff --git a/bsp/x86/drivers/keyboard.c b/bsp/x86/drivers/keyboard.c
index 61f2846dc6..4890db380b 100644
--- a/bsp/x86/drivers/keyboard.c
+++ b/bsp/x86/drivers/keyboard.c
@@ -19,290 +19,290 @@
#define FALSE RT_FALSE
#define TRUE RT_TRUE
#define PRIVATE static
-#define PUBLIC
+#define PUBLIC
#define t_bool rt_bool_t
#define t_8 rt_uint8_t
#define t_32 rt_uint32_t
-PRIVATE KB_INPUT kb_in;
-PRIVATE t_bool code_with_E0 = FALSE;
-PRIVATE t_bool shift_l; /* l shift state */
-PRIVATE t_bool shift_r; /* r shift state */
-PRIVATE t_bool alt_l; /* l alt state */
-PRIVATE t_bool alt_r; /* r left state */
-PRIVATE t_bool ctrl_l; /* l ctrl state */
-PRIVATE t_bool ctrl_r; /* l ctrl state */
-PRIVATE t_bool caps_lock; /* Caps Lock */
-PRIVATE t_bool num_lock; /* Num Lock */
-PRIVATE t_bool scroll_lock; /* Scroll Lock */
-PRIVATE int column = 0; /* keyrow[column] is one value of keymap */
+PRIVATE KB_INPUT kb_in;
+PRIVATE t_bool code_with_E0 = FALSE;
+PRIVATE t_bool shift_l; /* l shift state */
+PRIVATE t_bool shift_r; /* r shift state */
+PRIVATE t_bool alt_l; /* l alt state */
+PRIVATE t_bool alt_r; /* r left state */
+PRIVATE t_bool ctrl_l; /* l ctrl state */
+PRIVATE t_bool ctrl_r; /* l ctrl state */
+PRIVATE t_bool caps_lock; /* Caps Lock */
+PRIVATE t_bool num_lock; /* Num Lock */
+PRIVATE t_bool scroll_lock; /* Scroll Lock */
+PRIVATE int column = 0; /* keyrow[column] is one value of keymap */
-PRIVATE t_8 get_byte_from_kb_buf();
-PRIVATE void set_leds();
-PRIVATE void kb_wait();
-PRIVATE void kb_ack();
+PRIVATE t_8 get_byte_from_kb_buf();
+PRIVATE void set_leds();
+PRIVATE void kb_wait();
+PRIVATE void kb_ack();
PUBLIC void init_keyboard()
{
- kb_in.count = 0;
- kb_in.p_head = kb_in.p_tail = kb_in.buf;
+ kb_in.count = 0;
+ kb_in.p_head = kb_in.p_tail = kb_in.buf;
- caps_lock = 0;
- num_lock = 1;
- scroll_lock = 0;
+ caps_lock = 0;
+ num_lock = 1;
+ scroll_lock = 0;
- set_leds();
+ set_leds();
}
PUBLIC rt_bool_t keyboard_read(rt_uint32_t *pkey)
{
- t_8 scan_code;
- t_bool make; /* TRUE : make */
- /* FALSE: break */
- t_32 key = 0;
- t_32* keyrow;
+ t_8 scan_code;
+ t_bool make; /* TRUE : make */
+ /* FALSE: break */
+ t_32 key = 0;
+ t_32* keyrow;
- if(kb_in.count > 0){
- code_with_E0 = FALSE;
- scan_code = get_byte_from_kb_buf();
+ if(kb_in.count > 0){
+ code_with_E0 = FALSE;
+ scan_code = get_byte_from_kb_buf();
- /* start scan */
- if (scan_code == 0xE1) {
- int i;
- static const t_8 pausebreak_scan_code[] = {0xE1, 0x1D, 0x45, 0xE1, 0x9D, 0xC5};
- t_bool is_pausebreak = TRUE;
- for(i=1;i<6;i++){
- if (get_byte_from_kb_buf() != pausebreak_scan_code[i]) {
- is_pausebreak = FALSE;
- break;
- }
- }
- if (is_pausebreak) {
- key = PAUSEBREAK;
- }
- }
- else if (scan_code == 0xE0) {
- code_with_E0 = TRUE;
- scan_code = get_byte_from_kb_buf();
+ /* start scan */
+ if (scan_code == 0xE1) {
+ int i;
+ static const t_8 pausebreak_scan_code[] = {0xE1, 0x1D, 0x45, 0xE1, 0x9D, 0xC5};
+ t_bool is_pausebreak = TRUE;
+ for(i=1;i<6;i++){
+ if (get_byte_from_kb_buf() != pausebreak_scan_code[i]) {
+ is_pausebreak = FALSE;
+ break;
+ }
+ }
+ if (is_pausebreak) {
+ key = PAUSEBREAK;
+ }
+ }
+ else if (scan_code == 0xE0) {
+ code_with_E0 = TRUE;
+ scan_code = get_byte_from_kb_buf();
- /* PrintScreen pressed */
- if (scan_code == 0x2A) {
- code_with_E0 = FALSE;
- if ((scan_code = get_byte_from_kb_buf()) == 0xE0) {
- code_with_E0 = TRUE;
- if ((scan_code = get_byte_from_kb_buf()) == 0x37) {
- key = PRINTSCREEN;
- make = TRUE;
- }
- }
- }
- /* PrintScreen released */
- else if (scan_code == 0xB7) {
- code_with_E0 = FALSE;
- if ((scan_code = get_byte_from_kb_buf()) == 0xE0) {
- code_with_E0 = TRUE;
- if ((scan_code = get_byte_from_kb_buf()) == 0xAA) {
- key = PRINTSCREEN;
- make = FALSE;
- }
- }
- }
- } /* if is not PrintScreen, scan_code is the one after 0xE0 */
- if ((key != PAUSEBREAK) && (key != PRINTSCREEN)) {
- /* is Make Code or Break Code */
- make = (scan_code & FLAG_BREAK ? FALSE : TRUE);
-
- keyrow = &keymap[(scan_code & 0x7F) * MAP_COLS];
+ /* PrintScreen pressed */
+ if (scan_code == 0x2A) {
+ code_with_E0 = FALSE;
+ if ((scan_code = get_byte_from_kb_buf()) == 0xE0) {
+ code_with_E0 = TRUE;
+ if ((scan_code = get_byte_from_kb_buf()) == 0x37) {
+ key = PRINTSCREEN;
+ make = TRUE;
+ }
+ }
+ }
+ /* PrintScreen released */
+ else if (scan_code == 0xB7) {
+ code_with_E0 = FALSE;
+ if ((scan_code = get_byte_from_kb_buf()) == 0xE0) {
+ code_with_E0 = TRUE;
+ if ((scan_code = get_byte_from_kb_buf()) == 0xAA) {
+ key = PRINTSCREEN;
+ make = FALSE;
+ }
+ }
+ }
+ } /* if is not PrintScreen, scan_code is the one after 0xE0 */
+ if ((key != PAUSEBREAK) && (key != PRINTSCREEN)) {
+ /* is Make Code or Break Code */
+ make = (scan_code & FLAG_BREAK ? FALSE : TRUE);
- column = 0;
+ keyrow = &keymap[(scan_code & 0x7F) * MAP_COLS];
- t_bool caps = shift_l || shift_r;
- if (caps_lock) {
- if ((keyrow[0] >= 'a') && (keyrow[0] <= 'z')){
- caps = !caps;
- }
- }
- if (caps) {
- column = 1;
- }
+ column = 0;
- if (code_with_E0) {
- column = 2;
- }
+ t_bool caps = shift_l || shift_r;
+ if (caps_lock) {
+ if ((keyrow[0] >= 'a') && (keyrow[0] <= 'z')){
+ caps = !caps;
+ }
+ }
+ if (caps) {
+ column = 1;
+ }
- key = keyrow[column];
+ if (code_with_E0) {
+ column = 2;
+ }
- switch(key) {
- case SHIFT_L:
- shift_l = make;
- break;
- case SHIFT_R:
- shift_r = make;
- break;
- case CTRL_L:
- ctrl_l = make;
- break;
- case CTRL_R:
- ctrl_r = make;
- break;
- case ALT_L:
- alt_l = make;
- break;
- case ALT_R:
- alt_l = make;
- break;
- case CAPS_LOCK:
- if (make) {
- caps_lock = !caps_lock;
- set_leds();
- }
- break;
- case NUM_LOCK:
- if (make) {
- num_lock = !num_lock;
- set_leds();
- }
- break;
- case SCROLL_LOCK:
- if (make) {
- scroll_lock = !scroll_lock;
- set_leds();
- }
- break;
- default:
- break;
- }
- }
+ key = keyrow[column];
- if(make){ /* ignore Break Code */
- t_bool pad = FALSE;
+ switch(key) {
+ case SHIFT_L:
+ shift_l = make;
+ break;
+ case SHIFT_R:
+ shift_r = make;
+ break;
+ case CTRL_L:
+ ctrl_l = make;
+ break;
+ case CTRL_R:
+ ctrl_r = make;
+ break;
+ case ALT_L:
+ alt_l = make;
+ break;
+ case ALT_R:
+ alt_l = make;
+ break;
+ case CAPS_LOCK:
+ if (make) {
+ caps_lock = !caps_lock;
+ set_leds();
+ }
+ break;
+ case NUM_LOCK:
+ if (make) {
+ num_lock = !num_lock;
+ set_leds();
+ }
+ break;
+ case SCROLL_LOCK:
+ if (make) {
+ scroll_lock = !scroll_lock;
+ set_leds();
+ }
+ break;
+ default:
+ break;
+ }
+ }
- /* handle the small pad first */
- if ((key >= PAD_SLASH) && (key <= PAD_9)) {
- pad = TRUE;
- switch(key) { /* '/', '*', '-', '+', and 'Enter' in num pad */
- case PAD_SLASH:
- key = '/';
- break;
- case PAD_STAR:
- key = '*';
- break;
- case PAD_MINUS:
- key = '-';
- break;
- case PAD_PLUS:
- key = '+';
- break;
- case PAD_ENTER:
- key = ENTER;
- break;
- default: /* keys whose value depends on the NumLock */
- if (num_lock) { /* '0' ~ '9' and '.' in num pad */
- if ((key >= PAD_0) && (key <= PAD_9)) {
- key = key - PAD_0 + '0';
- }
- else if (key == PAD_DOT) {
- key = '.';
- }
- }
- else{
- switch(key) {
- case PAD_HOME:
- key = HOME;
- break;
- case PAD_END:
- key = END;
- break;
- case PAD_PAGEUP:
- key = PAGEUP;
- break;
- case PAD_PAGEDOWN:
- key = PAGEDOWN;
- break;
- case PAD_INS:
- key = INSERT;
- break;
- case PAD_UP:
- key = UP;
- break;
- case PAD_DOWN:
- key = DOWN;
- break;
- case PAD_LEFT:
- key = LEFT;
- break;
- case PAD_RIGHT:
- key = RIGHT;
- break;
- case PAD_DOT:
- key = DELETE;
- break;
- default:
- break;
- }
- }
- break;
- }
- }
- key |= shift_l ? FLAG_SHIFT_L : 0;
- key |= shift_r ? FLAG_SHIFT_R : 0;
- key |= ctrl_l ? FLAG_CTRL_L : 0;
- key |= ctrl_r ? FLAG_CTRL_R : 0;
- key |= alt_l ? FLAG_ALT_L : 0;
- key |= alt_r ? FLAG_ALT_R : 0;
- key |= pad ? FLAG_PAD : 0;
+ if(make){ /* ignore Break Code */
+ t_bool pad = FALSE;
- *pkey = key;
- return TRUE;
- }
- }
+ /* handle the small pad first */
+ if ((key >= PAD_SLASH) && (key <= PAD_9)) {
+ pad = TRUE;
+ switch(key) { /* '/', '*', '-', '+', and 'Enter' in num pad */
+ case PAD_SLASH:
+ key = '/';
+ break;
+ case PAD_STAR:
+ key = '*';
+ break;
+ case PAD_MINUS:
+ key = '-';
+ break;
+ case PAD_PLUS:
+ key = '+';
+ break;
+ case PAD_ENTER:
+ key = ENTER;
+ break;
+ default: /* keys whose value depends on the NumLock */
+ if (num_lock) { /* '0' ~ '9' and '.' in num pad */
+ if ((key >= PAD_0) && (key <= PAD_9)) {
+ key = key - PAD_0 + '0';
+ }
+ else if (key == PAD_DOT) {
+ key = '.';
+ }
+ }
+ else{
+ switch(key) {
+ case PAD_HOME:
+ key = HOME;
+ break;
+ case PAD_END:
+ key = END;
+ break;
+ case PAD_PAGEUP:
+ key = PAGEUP;
+ break;
+ case PAD_PAGEDOWN:
+ key = PAGEDOWN;
+ break;
+ case PAD_INS:
+ key = INSERT;
+ break;
+ case PAD_UP:
+ key = UP;
+ break;
+ case PAD_DOWN:
+ key = DOWN;
+ break;
+ case PAD_LEFT:
+ key = LEFT;
+ break;
+ case PAD_RIGHT:
+ key = RIGHT;
+ break;
+ case PAD_DOT:
+ key = DELETE;
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ }
+ }
+ key |= shift_l ? FLAG_SHIFT_L : 0;
+ key |= shift_r ? FLAG_SHIFT_R : 0;
+ key |= ctrl_l ? FLAG_CTRL_L : 0;
+ key |= ctrl_r ? FLAG_CTRL_R : 0;
+ key |= alt_l ? FLAG_ALT_L : 0;
+ key |= alt_r ? FLAG_ALT_R : 0;
+ key |= pad ? FLAG_PAD : 0;
- return FALSE;
+ *pkey = key;
+ return TRUE;
+ }
+ }
+
+ return FALSE;
}
PRIVATE t_8 get_byte_from_kb_buf()
{
- t_8 scan_code;
+ t_8 scan_code;
- RT_ASSERT(kb_in.count>0);
- scan_code = *(kb_in.p_tail);
- kb_in.p_tail++;
- if (kb_in.p_tail == kb_in.buf + KB_IN_BYTES) {
- kb_in.p_tail = kb_in.buf;
- }
- kb_in.count--;
+ RT_ASSERT(kb_in.count>0);
+ scan_code = *(kb_in.p_tail);
+ kb_in.p_tail++;
+ if (kb_in.p_tail == kb_in.buf + KB_IN_BYTES) {
+ kb_in.p_tail = kb_in.buf;
+ }
+ kb_in.count--;
- return scan_code;
+ return scan_code;
}
PRIVATE void kb_wait() /* wait inpit cache of 8042 */
{
- t_8 kb_stat;
+ t_8 kb_stat;
- do {
- kb_stat = inb(KB_CMD);
- } while (kb_stat & 0x02);
+ do {
+ kb_stat = inb(KB_CMD);
+ } while (kb_stat & 0x02);
}
PRIVATE void kb_ack()
{
- t_8 kb_read;
+ t_8 kb_read;
- do {
- kb_read = inb(KB_DATA);
- } while (kb_read != KB_ACK);
+ do {
+ kb_read = inb(KB_DATA);
+ } while (kb_read != KB_ACK);
}
PRIVATE void set_leds()
{
- t_8 leds = (caps_lock << 2) | (num_lock << 1) | scroll_lock;
+ t_8 leds = (caps_lock << 2) | (num_lock << 1) | scroll_lock;
- kb_wait();
- outb(KB_DATA, LED_CODE);
- kb_ack();
+ kb_wait();
+ outb(KB_DATA, LED_CODE);
+ kb_ack();
- kb_wait();
- outb(KB_DATA, leds);
- kb_ack();
+ kb_wait();
+ outb(KB_DATA, leds);
+ kb_ack();
}
/**
@@ -312,51 +312,51 @@ PRIVATE void set_leds()
void rt_keyboard_isr(void)
{
- rt_uint8_t data;
+ rt_uint8_t data;
- if ((inb(KBSTATP) & KBS_DIB) == 0)
- return ;
+ if ((inb(KBSTATP) & KBS_DIB) == 0)
+ return ;
- data = inb(KBDATAP);
+ data = inb(KBDATAP);
- if (kb_in.count < KB_IN_BYTES) {
- *(kb_in.p_head) = data;
- kb_in.p_head++;
- if (kb_in.p_head == kb_in.buf + KB_IN_BYTES) {
- kb_in.p_head = kb_in.buf;
- }
- kb_in.count++;
- }
+ if (kb_in.count < KB_IN_BYTES) {
+ *(kb_in.p_head) = data;
+ kb_in.p_head++;
+ if (kb_in.p_head == kb_in.buf + KB_IN_BYTES) {
+ kb_in.p_head = kb_in.buf;
+ }
+ kb_in.count++;
+ }
}
/* generally, this should be called in task level for all key inpit support,
but here only support a key that is composed of 2 bytes */
rt_bool_t rt_keyboard_getc(char* c)
{
- if(kb_in.count>=2)
- {
- rt_uint32_t key = 0;
- rt_bool_t rv=keyboard_read(&key);
+ if(kb_in.count>=2)
+ {
+ rt_uint32_t key = 0;
+ rt_bool_t rv=keyboard_read(&key);
- switch(key)
- {
- case TAB:
- *c = '\t';
- break;
- case ENTER:
- *c = '\n';
- break;
- case BACKSPACE:
- *c = '\b';
- break;
- default:
- *c = key;
- break;
- }
+ switch(key)
+ {
+ case TAB:
+ *c = '\t';
+ break;
+ case ENTER:
+ *c = '\n';
+ break;
+ case BACKSPACE:
+ *c = '\b';
+ break;
+ default:
+ *c = key;
+ break;
+ }
- return rv;
- }
+ return rv;
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
/*@}*/
diff --git a/bsp/x86/drivers/serial.c b/bsp/x86/drivers/serial.c
index f5510ae0d5..3ed8d6fed5 100644
--- a/bsp/x86/drivers/serial.c
+++ b/bsp/x86/drivers/serial.c
@@ -8,7 +8,7 @@
* 2006-09-15 QiuYi the first version
* 2006-10-10 Bernard use keyboard instead of serial
*/
-
+
#include <rtthread.h>
#include <rthw.h>
@@ -24,26 +24,26 @@
*/
void rt_serial_init(void)
{
- outb(COM1+3,0x80); /* set DLAB of line control reg */
- outb(COM1,0x0c); /* LS of divisor (48 -> 2400 bps */
- outb(COM1+1,0x00); /* MS of divisor */
- outb(COM1+3,0x03); /* reset DLAB */
- outb(COM1+4,0x0b); /* set DTR,RTS, OUT_2 */
- outb(COM1+1,0x0d); /* enable all intrs but writes */
- inb(COM1); /* read data port to reset things (?) */
+ outb(COM1+3,0x80); /* set DLAB of line control reg */
+ outb(COM1,0x0c); /* LS of divisor (48 -> 2400 bps */
+ outb(COM1+1,0x00); /* MS of divisor */
+ outb(COM1+3,0x03); /* reset DLAB */
+ outb(COM1+4,0x0b); /* set DTR,RTS, OUT_2 */
+ outb(COM1+1,0x0d); /* enable all intrs but writes */
+ inb(COM1); /* read data port to reset things (?) */
}
/**
- * This function read a character from serial without interrupt enable mode
+ * This function read a character from serial without interrupt enable mode
*
* @return the read char
*/
char rt_serial_getc(void)
{
- while(!(inb(COM1+COMSTATUS) & COMDATA));
-
- return inb(COM1+COMREAD);
+ while(!(inb(COM1+COMSTATUS) & COMDATA));
+
+ return inb(COM1+COMREAD);
}
@@ -54,15 +54,15 @@ char rt_serial_getc(void)
*/
void rt_serial_putc(const char c)
{
- int val;
-
- while(1)
- {
- if ((val = inb(COM1+COMSTATUS)) & THRE)
- break;
- }
-
- outb(COM1+COMWRITE, c&0xff);
+ int val;
+
+ while(1)
+ {
+ if ((val = inb(COM1+COMSTATUS)) & THRE)
+ break;
+ }
+
+ outb(COM1+COMWRITE, c&0xff);
}
/*@}*/