1 /* Declarations to support the SPIM-compatible console device.
2    Copyright 2002, 2003 Paul Twohey.
3 
4 This file is part of VMIPS.
5 
6 VMIPS is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10 
11 VMIPS is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15 
16 You should have received a copy of the GNU General Public License along
17 with VMIPS; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
19 
20 #ifndef _SPIMCONSOLE_H_
21 #define _SPIMCONSOLE_H_
22 
23 #include "deviceint.h"
24 #include "devicemap.h"
25 #include "task.h"
26 #include "terminalcontroller.h"
27 #include <new>
28 class Clock;
29 
30 /* SPIM-compatible console device. */
31 class SpimConsoleDevice : public TerminalController, public DeviceMap,
32                           public DeviceInt
33 {
34 public:
35 	/* Create a new SPIM-compatible console device with CLOCK as the time
36 	   source for the device. */
37 	SpimConsoleDevice( Clock *clock );
38 
39 	/* Destroy the device and cancel the clock trigger. */
40 	virtual ~SpimConsoleDevice();
41 
42 	/* Call the routines in TerminalController and then assert or
43 	   deassert the appropriate interrupt. */
44 	virtual void ready_display( int line );
45 	virtual void unready_display( int line, char data );
46 	virtual void unready_keyboard( int line );
47 protected:
48 	virtual void ready_keyboard( int line );
49 
50 public:
51 
52 	/* Transition the clock component fom either the READY or UNREADY
53 	   states into the READY state, asserting IRQ2 if clock interrupts
54 	   are enabled. Called by ClockTrigger to allow the SPIM console to
55 	   mark the passage of time. */
56 	virtual void ready_clock();
57 
58 	/* Transition the clock component from either the READY or UNREADY
59 	   states into the UNREADY state. */
60 	virtual void unready_clock();
61 
62 	/* Fetch and store console control words. */
63 	virtual uint32 fetch_word(uint32 offset, int mode, DeviceExc *client);
64 	virtual void store_word(uint32 offset, uint32 data, DeviceExc *client);
65 
66 	/* Return a description of this device. */
67 	virtual const char *descriptor_str() const;
68 
69 protected:
70 	class ClockTrigger : public CancelableTask
71 	{
72 	public:
73 		ClockTrigger( SpimConsoleDevice *console );
74 		virtual ~ClockTrigger();
75 
76 	protected:
77 		virtual void real_task();
78 
79 	protected:
80 		SpimConsoleDevice	*console;
81 	};
82 
83 protected:
84 	static const long KEYBOARD_POLL_NS	= 400 * 1000;		//400us
85 	static const long KEYBOARD_REPOLL_NS	= 40 * 1000 * 1000;	// 40ms
86 	static const long DISPLAY_READY_DELAY_NS= 40 * 1000 * 1000;	// 40ms
87 	static const long CLOCK_TRIGGER_NS	= 1000 * 1000 *1000;	// 1s
88 
89 protected:
90 	ClockTrigger	*trigger;
91 	bool		display_interrupt_enable[2];
92 	bool		keyboard_interrupt_enable[2];
93 	bool		clock_interrupt;
94 	State		clock_state;
95 };
96 
97 #endif /* _SPIMCONSOLE_H_ */
98