1 | /*-------------------------------------------------------------------------+ |
---|
2 | | inch.c v1.1 - PC386 BSP - 1997/08/07 |
---|
3 | +--------------------------------------------------------------------------+ |
---|
4 | | (C) Copyright 1997 - |
---|
5 | | - NavIST Group - Real-Time Distributed Systems and Industrial Automation |
---|
6 | | |
---|
7 | | http://pandora.ist.utl.pt |
---|
8 | | |
---|
9 | | Instituto Superior Tecnico * Lisboa * PORTUGAL |
---|
10 | +--------------------------------------------------------------------------+ |
---|
11 | | Disclaimer: |
---|
12 | | |
---|
13 | | This file is provided "AS IS" without warranty of any kind, either |
---|
14 | | expressed or implied. |
---|
15 | +--------------------------------------------------------------------------+ |
---|
16 | | This code is based on: |
---|
17 | | inch.c,v 1.3 1995/12/19 20:07:25 joel Exp - go32 BSP |
---|
18 | | With the following copyright notice: |
---|
19 | | With the following copyright notice: |
---|
20 | | ************************************************************************** |
---|
21 | | * COPYRIGHT (c) 1989-1998. |
---|
22 | | * On-Line Applications Research Corporation (OAR). |
---|
23 | | * Copyright assigned to U.S. Government, 1994. |
---|
24 | | * |
---|
25 | | * The license and distribution terms for this file may be |
---|
26 | | * found in found in the file LICENSE in this distribution or at |
---|
27 | | * http://www.OARcorp.com/rtems/license.html. |
---|
28 | | ************************************************************************** |
---|
29 | | |
---|
30 | | $Id$ |
---|
31 | +--------------------------------------------------------------------------*/ |
---|
32 | |
---|
33 | #include <bsp.h> |
---|
34 | #include <irq.h> |
---|
35 | |
---|
36 | /*-------------------------------------------------------------------------+ |
---|
37 | | Constants |
---|
38 | +--------------------------------------------------------------------------*/ |
---|
39 | #define KBD_BUF_SIZE 256 |
---|
40 | |
---|
41 | static unsigned short kbd_buffer[KBD_BUF_SIZE]; |
---|
42 | static rtems_unsigned16 kbd_first = 0; |
---|
43 | static rtems_unsigned16 kbd_last = 0; |
---|
44 | static rtems_unsigned16 kbd_end = KBD_BUF_SIZE - 1; |
---|
45 | |
---|
46 | /*-------------------------------------------------------------------------+ |
---|
47 | | Function: rtemsReboot |
---|
48 | | Description: Reboot the PC. |
---|
49 | | Global Variables: None. |
---|
50 | | Arguments: None. |
---|
51 | | Returns: Nothing. |
---|
52 | +--------------------------------------------------------------------------*/ |
---|
53 | void rtemsReboot(void) |
---|
54 | { |
---|
55 | /* shutdown and reboot */ |
---|
56 | outport_byte(0x64, 0xFE); /* use keyboard controler to do the job... */ |
---|
57 | } /* rtemsReboot */ |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | #define disable __asm__ __volatile__("cli") |
---|
62 | #define enable __asm__ __volatile__("sti"); |
---|
63 | /* |
---|
64 | * Check if a key has been pressed. This is a non-destructive |
---|
65 | * call, meaning, it keeps the key in the buffer. |
---|
66 | */ |
---|
67 | int rtems_kbpoll( void ) |
---|
68 | { |
---|
69 | int rc; |
---|
70 | disable; |
---|
71 | rc = ( kbd_first != kbd_last ) ? TRUE : FALSE; |
---|
72 | enable; |
---|
73 | return rc; |
---|
74 | } |
---|
75 | |
---|
76 | int getch( void ) |
---|
77 | { |
---|
78 | int c; |
---|
79 | while( kbd_first == kbd_last ) |
---|
80 | { |
---|
81 | rtems_task_wake_after( 10 ); |
---|
82 | } |
---|
83 | c = kbd_buffer[ kbd_first ]; |
---|
84 | kbd_first = (kbd_first + 1) % KBD_BUF_SIZE; |
---|
85 | return c; |
---|
86 | } |
---|
87 | |
---|
88 | void add_to_queue( unsigned short b ) |
---|
89 | { |
---|
90 | unsigned int next; |
---|
91 | kbd_buffer[ kbd_last ] = b; |
---|
92 | next = (kbd_last == kbd_end) ? 0 : kbd_last + 1; |
---|
93 | if( next != kbd_first ) |
---|
94 | { |
---|
95 | kbd_last = next; |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|