1 |
|
/* |
2 |
|
* serial_unix.cpp - Serial device driver, Unix specific stuff |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-1999 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2001 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
101 |
|
} |
102 |
|
} |
103 |
|
|
104 |
< |
virtual int16 Open(uint16 config); |
105 |
< |
virtual int16 PrimeIn(uint32 pb, uint32 dce); |
106 |
< |
virtual int16 PrimeOut(uint32 pb, uint32 dce); |
107 |
< |
virtual int16 Control(uint32 pb, uint32 dce, uint16 code); |
108 |
< |
virtual int16 Status(uint32 pb, uint32 dce, uint16 code); |
109 |
< |
virtual int16 Close(void); |
104 |
> |
virtual int16 open(uint16 config); |
105 |
> |
virtual int16 prime_in(uint32 pb, uint32 dce); |
106 |
> |
virtual int16 prime_out(uint32 pb, uint32 dce); |
107 |
> |
virtual int16 control(uint32 pb, uint32 dce, uint16 code); |
108 |
> |
virtual int16 status(uint32 pb, uint32 dce, uint16 code); |
109 |
> |
virtual int16 close(void); |
110 |
|
|
111 |
|
private: |
112 |
|
bool configure(uint16 config); |
166 |
|
* Open serial port |
167 |
|
*/ |
168 |
|
|
169 |
< |
int16 XSERDPort::Open(uint16 config) |
169 |
> |
int16 XSERDPort::open(uint16 config) |
170 |
|
{ |
171 |
|
// Don't open NULL name devices |
172 |
|
if (device_name == NULL) |
177 |
|
quitting = false; |
178 |
|
|
179 |
|
// Open port |
180 |
< |
fd = open(device_name, O_RDWR); |
180 |
> |
fd = ::open(device_name, O_RDWR); |
181 |
|
if (fd < 0) |
182 |
|
goto open_error; |
183 |
|
|
184 |
< |
#ifdef __linux__ |
184 |
> |
#if defined(__linux__) |
185 |
|
// Parallel port? |
186 |
|
struct stat st; |
187 |
|
if (fstat(fd, &st) == 0) |
188 |
|
if (S_ISCHR(st.st_mode)) |
189 |
|
is_parallel = (MAJOR(st.st_rdev) == LP_MAJOR); |
190 |
< |
#elif defined(__FreeBSD__) |
190 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
191 |
|
// Parallel port? |
192 |
|
struct stat st; |
193 |
|
if (fstat(fd, &st) == 0) |
238 |
|
output_thread_active = false; |
239 |
|
} |
240 |
|
if (fd > 0) { |
241 |
< |
close(fd); |
241 |
> |
::close(fd); |
242 |
|
fd = -1; |
243 |
|
} |
244 |
|
return openErr; |
249 |
|
* Read data from port |
250 |
|
*/ |
251 |
|
|
252 |
< |
int16 XSERDPort::PrimeIn(uint32 pb, uint32 dce) |
252 |
> |
int16 XSERDPort::prime_in(uint32 pb, uint32 dce) |
253 |
|
{ |
254 |
|
// Send input command to input_thread |
255 |
|
read_done = false; |
265 |
|
* Write data to port |
266 |
|
*/ |
267 |
|
|
268 |
< |
int16 XSERDPort::PrimeOut(uint32 pb, uint32 dce) |
268 |
> |
int16 XSERDPort::prime_out(uint32 pb, uint32 dce) |
269 |
|
{ |
270 |
|
// Send output command to output_thread |
271 |
|
write_done = false; |
281 |
|
* Control calls |
282 |
|
*/ |
283 |
|
|
284 |
< |
int16 XSERDPort::Control(uint32 pb, uint32 dce, uint16 code) |
284 |
> |
int16 XSERDPort::control(uint32 pb, uint32 dce, uint16 code) |
285 |
|
{ |
286 |
|
switch (code) { |
287 |
|
case 1: // KillIO |
446 |
|
* Status calls |
447 |
|
*/ |
448 |
|
|
449 |
< |
int16 XSERDPort::Status(uint32 pb, uint32 dce, uint16 code) |
449 |
> |
int16 XSERDPort::status(uint32 pb, uint32 dce, uint16 code) |
450 |
|
{ |
451 |
|
switch (code) { |
452 |
|
case kSERDInputCount: { |
493 |
|
* Close serial port |
494 |
|
*/ |
495 |
|
|
496 |
< |
int16 XSERDPort::Close() |
496 |
> |
int16 XSERDPort::close() |
497 |
|
{ |
498 |
|
// Kill threads |
499 |
|
if (input_thread_active) { |
513 |
|
|
514 |
|
// Close port |
515 |
|
if (fd > 0) |
516 |
< |
close(fd); |
516 |
> |
::close(fd); |
517 |
|
fd = -1; |
518 |
|
return noErr; |
519 |
|
} |
663 |
|
// KillIO called? Then simply return |
664 |
|
if (s->io_killed) { |
665 |
|
|
666 |
< |
WriteMacInt16(s->input_pb + ioResult, abortErr); |
666 |
> |
WriteMacInt16(s->input_pb + ioResult, uint16(abortErr)); |
667 |
|
WriteMacInt32(s->input_pb + ioActCount, 0); |
668 |
|
s->read_pending = s->read_done = false; |
669 |
|
|
675 |
|
WriteMacInt32(s->input_dt + serdtResult, noErr); |
676 |
|
} else { |
677 |
|
WriteMacInt32(s->input_pb + ioActCount, 0); |
678 |
< |
WriteMacInt32(s->input_dt + serdtResult, readErr); |
678 |
> |
WriteMacInt32(s->input_dt + serdtResult, uint16(readErr)); |
679 |
|
} |
680 |
|
|
681 |
|
// Trigger serial interrupt |
723 |
|
// KillIO called? Then simply return |
724 |
|
if (s->io_killed) { |
725 |
|
|
726 |
< |
WriteMacInt16(s->output_pb + ioResult, abortErr); |
726 |
> |
WriteMacInt16(s->output_pb + ioResult, uint16(abortErr)); |
727 |
|
WriteMacInt32(s->output_pb + ioActCount, 0); |
728 |
|
s->write_pending = s->write_done = false; |
729 |
|
|
735 |
|
WriteMacInt32(s->output_dt + serdtResult, noErr); |
736 |
|
} else { |
737 |
|
WriteMacInt32(s->output_pb + ioActCount, 0); |
738 |
< |
WriteMacInt32(s->output_dt + serdtResult, writErr); |
738 |
> |
WriteMacInt32(s->output_dt + serdtResult, uint16(writErr)); |
739 |
|
} |
740 |
|
|
741 |
|
// Trigger serial interrupt |