File: chip_gen_ppi.c

package info (click to toggle)
faumachine 20180503-4
  • links: PTS
  • area: main
  • in suites: buster
  • size: 61,272 kB
  • sloc: ansic: 272,290; makefile: 6,199; asm: 4,251; sh: 3,022; perl: 886; xml: 563; pascal: 311; lex: 214; vhdl: 204
file content (218 lines) | stat: -rw-r--r-- 4,292 bytes parent folder | download
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
 * Copyright (C) 2003-2009 FAUmachine Team <info@faumachine.org>.
 * This program is free software. You can redistribute it and/or modify it
 * under the terms of the GNU General Public License, either version 2 of
 * the License, or (at your option) any later version. See COPYING.
 */

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "fixme.h"
#include "glue-shm.h"
#include "glue-suspend.h"

#include "chip_gen_ppi.h"

struct cpssp {
	/*
	 * Config
	 */

	/*
	 * Signals
	 */
	struct sig_std_logic *port_gate2;

	/*
	 * State
	 */
	unsigned int state_power;
	unsigned char state_in4;
	unsigned char state_in5;

#define STATE

#define NAME		chip_ppi_io
#define NAME_(x)	chip_ppi_io_ ## x
#define SNAME		"chip_ppi_io"
#include "arch_ppi.c"
#undef SNAME
#undef NAME_
#undef NAME

#undef STATE
};

extern inline unsigned char
chip_ppi_io_in4_get(struct cpssp *cpssp)
{
	return cpssp->state_in4;
}

extern inline unsigned char
chip_ppi_io_in5_get(struct cpssp *cpssp)
{
	return cpssp->state_in5;
}

static inline void
chip_ppi_io_out0_set(struct cpssp *cpssp, unsigned char val)
{
	sig_std_logic_or_set(cpssp->port_gate2, cpssp, val);
}

extern inline void
chip_ppi_io_out1_set(struct cpssp *cpssp, unsigned char val)
{
	/* speaker */
}

#define BEHAVIOR

#define NAME		chip_ppi_io
#define NAME_(x)	chip_ppi_io_ ## x
#define SNAME		"chip_ppi_io"
#include "arch_ppi.c"
#undef SNAME
#undef NAME_
#undef NAME

#undef BEHAVIOR

static void
chip_gen_ppi_power_set(void *_css, unsigned int val)
{
	struct cpssp *cpssp = (struct cpssp *) _css;

	cpssp->state_power = val;
}

static void
chip_gen_ppi_in4_set(void *_css, unsigned int val)
{
	struct cpssp *cpssp = (struct cpssp *) _css;
	unsigned char _val = (unsigned char) val;	

	cpssp->state_in4 = _val;
}

static void
chip_gen_ppi_in5_set(void *_css, unsigned int val)
{
	struct cpssp *cpssp = (struct cpssp *) _css;
	unsigned char _val = (unsigned char) val;

	cpssp->state_in5 = _val;
}

static void
chip_gen_ppi_n_reset_set(void *_css, unsigned int val)
{
	struct cpssp *cpssp = (struct cpssp *) _css;

	chip_ppi_io_reset(cpssp);
}

static int
chip_gen_ppi_inb(void *_css, uint32_t addr, uint8_t *valp)
{
	struct cpssp *cpssp = (struct cpssp *) _css;

	chip_ppi_io_inb(cpssp, valp);
	
	return 0;
}

static int
chip_gen_ppi_outb(void *_css, uint32_t addr, uint8_t val)
{
	struct cpssp *cpssp = (struct cpssp *) _css;

	chip_ppi_io_outb(cpssp, val);
	
	return 0;
}

void *
chip_gen_ppi_create(
	const char *name,
	struct sig_manage *port_manage,
	struct sig_std_logic *port_power,
	struct sig_std_logic *port_reset_hash_,
	struct sig_cs *port_cs,
	struct sig_isa_bus *port_bus,
	struct sig_std_logic *port_gate2,
	struct sig_std_logic *port_pit_out1,
	struct sig_std_logic *port_pit_out2
)
{
	static const struct sig_std_logic_funcs power_funcs = {
		.boolean_or_set = chip_gen_ppi_power_set,
	};
	static const struct sig_std_logic_funcs reset_hash__funcs = {
		.boolean_or_set = chip_gen_ppi_n_reset_set,
	};
	static const struct sig_cs_funcs cs_funcs = {
		.readb = chip_gen_ppi_inb,
		.writeb = chip_gen_ppi_outb,
	};
	static const struct sig_std_logic_funcs pit_out1_funcs = {
		.boolean_or_set = chip_gen_ppi_in4_set,
	};
	static const struct sig_std_logic_funcs pit_out2_funcs = {
		.boolean_or_set = chip_gen_ppi_in5_set,
	};
	struct cpssp *cpssp;

	cpssp = shm_alloc(sizeof(*cpssp));
	assert(cpssp);

	chip_ppi_io_init(cpssp);

	/* Out */
	cpssp->port_gate2 = port_gate2;
	sig_std_logic_connect_out(port_gate2, cpssp, SIG_STD_LOGIC_L);

	/* Call */
	sig_cs_connect(port_cs, cpssp, &cs_funcs);

	/* In */
	sig_std_logic_connect_in(port_power, cpssp, &power_funcs);

	sig_std_logic_connect_in(port_reset_hash_, cpssp, &reset_hash__funcs);

	cpssp->state_in4 = 0;
	sig_std_logic_connect_in(port_pit_out1, cpssp, &pit_out1_funcs);

	cpssp->state_in5 = 0;
	sig_std_logic_connect_in(port_pit_out2, cpssp, &pit_out2_funcs);

	return cpssp;
}

void
chip_gen_ppi_destroy(void *_cpssp)
{
	struct cpssp *cpssp = _cpssp;

	shm_free(cpssp);
}

void
chip_gen_ppi_suspend(void *_cpssp, FILE *fp)
{
	struct cpssp *cpssp = _cpssp;
	
	generic_suspend(cpssp, sizeof(*cpssp), fp);
}

void
chip_gen_ppi_resume(void *_cpssp, FILE *fp)
{
	struct cpssp *cpssp = _cpssp;
	
	generic_resume(cpssp, sizeof(*cpssp), fp);
}