aboutsummaryrefslogtreecommitdiff
path: root/SrcShared/Hardware/EmUARTDragonball.h
blob: 8c777be4ce8d82c5c5d34e981a59b9357610e61c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* -*- mode: C++; tab-width: 4 -*- */
/* ===================================================================== *\
	Copyright (c) 1998-2001 Palm, Inc. or its subsidiaries.
	All rights reserved.

	This file is part of the Palm OS Emulator.

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
\* ===================================================================== */

#ifndef EmUARTDragonball_h
#define EmUARTDragonball_h

#include "EmThreadSafeQueue.h"	// EmByteQueue

class EmTransport;
class SessionFile;


class EmUARTDragonball
{
	public:
		enum UART_Type
		{
			kUART_Dragonball,
			kUART_DragonballEZ,
			kUART_DragonballVZ,
			kUART_DragonballSZ
		};

		struct State
		{
			State (UART_Type type) { UART_TYPE = type; }

			UART_Type	UART_TYPE;

		// +	= Supported
		//		= Unsupported
		// ->	= Input value
		// <-	= Output value

			// UART control register bits
			// These are all values the user sets; we just look at them.

		/*  +  ->  */	unsigned int	UART_ENABLE:1;
		/*  +  ->  */	unsigned int	RX_ENABLE:1;
		/*  +  ->  */	unsigned int	TX_ENABLE:1;
		/*     ->  */	unsigned int	RX_CLK_CONT:1;
		/*  +  ->  */	unsigned int	PARITY_EN:1;
		/*  +  ->  */	unsigned int	ODD_EVEN:1;
		/*  +  ->  */	unsigned int	STOP_BITS:1;
		/*  +  ->  */	unsigned int	CHAR8_7:1;
		/*     ->  */	unsigned int	GPIO_DELTA_ENABLE:1;	// 68328 only
		/*     ->  */	unsigned int	OLD_ENABLE:1;			// 68EZ328 only
		/*     ->  */	unsigned int	CTS_DELTA_ENABLE:1;
		/*  +  ->  */	unsigned int	RX_FULL_ENABLE:1;
		/*  +  ->  */	unsigned int	RX_HALF_ENABLE:1;
		/*  +  ->  */	unsigned int	RX_RDY_ENABLE:1;
		/*  +  ->  */	unsigned int	TX_EMPTY_ENABLE:1;
		/*  +  ->  */	unsigned int	TX_HALF_ENABLE:1;
		/*  +  ->  */	unsigned int	TX_AVAIL_ENABLE:1;

			// Baud control register bits
			// These are all values the user sets; we just look at them.

		/*     ->  */	unsigned int	GPIO_DELTA:1;			// 68328 only
		/*     ->  */	unsigned int	GPIO:1;					// 68328 only
		/*     ->  */	unsigned int	GPIO_DIR:1;				// 68328 only
		/*     ->  */	unsigned int	GPIO_SRC:1;				// 68328 only
		/*     ->  */	unsigned int	UCLK_DIR:1;				// 68EZ328 only
		/*     ->  */	unsigned int	BAUD_SRC:1;
		/*  +  ->  */	unsigned int	DIVIDE;
		/*  +  ->  */	unsigned int	PRESCALER;

			// Receive register bits
			// These are all input bits; we set them, not the user.

		/*  +  <-  */	unsigned int	RX_FIFO_FULL:1;
		/*  +  <-  */	unsigned int	RX_FIFO_HALF:1;
		/*  +  <-  */	unsigned int	DATA_READY:1;
		/*     <-  */	unsigned int	OLD_DATA:1;				// 68EZ328 only
		/*     <-  */	unsigned int	OVRUN:1;
		/*     <-  */	unsigned int	FRAME_ERROR:1;
		/*     <-  */	unsigned int	BREAK:1;
		/*     <-  */	unsigned int	PARITY_ERROR:1;
		/*  +  <-  */	unsigned int	RX_DATA;

			// Transmitter register bits
			// The user sets TX_DATA, IGNORE_CTS, and SEND_BREAK.
			// We set the rest.

		/*  +  <-  */	unsigned int	TX_FIFO_EMPTY:1;
		/*  +  <-  */	unsigned int	TX_FIFO_HALF:1;
		/*  +  <-  */	unsigned int	TX_AVAIL:1;
		/*     ->  */	unsigned int	SEND_BREAK:1;
		/*  +  ->  */	unsigned int	IGNORE_CTS:1;
		/*  +  <-  */	unsigned int	BUSY:1;					// 68EZ328 only
		/*  +  <-  */	unsigned int	CTS_STATUS:1;
		/*     <-  */	unsigned int	CTS_DELTA:1;
		/*  +  ->  */	unsigned int	TX_DATA;

			// Misc register bits
			// These are all values the user sets; we just look at them.

		/*     ->  */	unsigned int	BAUD_TEST:1;			// 68EZ328 only
		/*     ->  */	unsigned int	CLK_SRC:1;
		/*     ->  */	unsigned int	FORCE_PERR:1;
		/*  +  ->  */	unsigned int	LOOP:1;
		/*     ->  */	unsigned int	BAUD_RESET:1;			// 68EZ328 only
		/*     ->  */	unsigned int	IR_TEST:1;				// 68EZ328 only
		/*  +  ->  */	unsigned int	RTS_CONT:1;
		/*  +  ->  */	unsigned int	RTS:1;
		/*  +  ->  */	unsigned int	IRDA_ENABLE:1;
		/*     ->  */	unsigned int	IRDA_LOOP:1;
		/*     ->  */	unsigned int	RX_POL:1;				// 68EZ328 only
		/*     ->  */	unsigned int	TX_POL:1;				// 68EZ328 only

			// Level Marker Interrupt

		/*  +  ->  */	unsigned int	TXFIFO_LEVEL_MARKER:4;	// 68SZ328 only
		/*  +  ->  */	unsigned int	RXFIFO_LEVEL_MARKER:4;	// 68SZ328 only
		};

								EmUARTDragonball	(UART_Type, int uartNum);
								~EmUARTDragonball	(void);

		void					StateChanged		(State&, Bool sendRxData);
		void					UpdateState			(State&, Bool refreshRxData);

		void					TransmitTxFIFO		(EmTransport*);
		void					ReceiveRxFIFO		(EmTransport*);

		EmTransport*			GetTransport		(void);

	private:
		int						PrvFIFOSize			(Bool forRX);
		int						PrvLevelMarker		(Bool forRX);

	private:
		int						fUARTNum;
		State					fState;
		EmByteQueue				fRxFIFO;
		EmByteQueue				fTxFIFO;
};

#endif /* EmUARTDragonball_h */