Skip to content

Commit 4d93180

Browse files
committed
FEAT: including optional support for serial device as was used in the Atronix's branch
1 parent 122d3df commit 4d93180

File tree

9 files changed

+98
-11
lines changed

9 files changed

+98
-11
lines changed

make/rebol3.nest

+14-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ core-files: [
159159
%core/p-file.c
160160
%core/p-net.c
161161
; %core/p-midi.c ;optional, use: include-midi
162-
; %core/p-serial.c ;not implemented
162+
; %core/p-serial.c ;optional, use: include-serial
163163
; %core/p-timer.c ;not implemented
164164
%core/s-cases.c
165165
%core/s-crc.c
@@ -485,6 +485,18 @@ include-midi: [
485485
; there is no support yet
486486
]
487487
]
488+
include-serial: [
489+
#if (find [windows linux] system/platform) [
490+
core-files: %core/p-serial.c
491+
config: INCLUDE_SERIAL_DEVICE
492+
]
493+
#if Windows? [
494+
host-files: %os/win32/dev-serial.c
495+
]
496+
#if Linux? [
497+
host-files: %os/posix/dev-serial.c
498+
]
499+
]
488500

489501
;- native utilities:
490502
include-bincode: [core-files: %core/u-bincode.c]
@@ -853,6 +865,7 @@ include-rebol-bulk: [
853865
:include-base85-encoding
854866
:include-view
855867
:include-midi
868+
:include-serial
856869

857870
; Extended crypto features
858871
:include-cryptography-bulk

src/boot/sysobj.reb

+8
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,14 @@ standard: object [
331331
device-out: none
332332
]
333333

334+
port-spec-serial: make port-spec-head [
335+
speed: 115200
336+
data-size: 8
337+
parity: none
338+
stop-bits: 1
339+
flow-control: none ;not supported on all systems
340+
]
341+
334342
file-info: construct [
335343
name:
336344
size:

src/core/c-port.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
** REBOL [R3] Language Interpreter and Run-time Environment
44
**
55
** Copyright 2012 REBOL Technologies
6-
** Copyright 2012-2021 Rebol Open Source Developers
6+
** Copyright 2012-2023 Rebol Open Source Developers
77
** REBOL is a trademark of REBOL Technologies
88
**
99
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -512,7 +512,7 @@ xx*/ REBINT Wait_Device(REBREQ *req, REBCNT timeout)
512512
**
513513
***********************************************************************/
514514

515-
#define MAX_SCHEMES 13 // max native schemes
515+
#define MAX_SCHEMES 14 // max native schemes
516516

517517
typedef struct rebol_scheme_actions {
518518
REBCNT sym;
@@ -639,6 +639,9 @@ SCHEME_ACTIONS *Scheme_Actions; // Initial Global (not threaded)
639639
#ifdef INCLUDE_CRYPTOGRAPHY
640640
Init_Crypt_Scheme();
641641
#endif
642+
#ifdef INCLUDE_SERIAL_DEVICE
643+
Init_Serial_Scheme();
644+
#endif
642645
}
643646

644647
/***********************************************************************

src/core/p-serial.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
** REBOL [R3] Language Interpreter and Run-time Environment
44
**
55
** Copyright 2013 REBOL Technologies
6+
** Copyright 2013-2023 Rebol Open Source Developers
67
** REBOL is a trademark of REBOL Technologies
78
**
89
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +23,7 @@
2223
** Module: p-serial.c
2324
** Summary: serial port interface
2425
** Section: ports
25-
** Author: Carl Sassenrath
26+
** Author: Carl Sassenrath, Joshua Shireman, Shixin Zeng, Oldes
2627
** Notes:
2728
**
2829
***********************************************************************/
@@ -35,7 +36,7 @@
3536

3637
/***********************************************************************
3738
**
38-
*/ static int Serial_Actor(REBVAL *ds, REBSER *port, REBCNT action)
39+
*/ static int Serial_Actor(REBVAL *ds, REBVAL *port_value, REBCNT action)
3940
/*
4041
***********************************************************************/
4142
{
@@ -48,8 +49,9 @@
4849
REBCNT len; // generic length
4950
REBSER *ser; // simplifier
5051
REBVAL *path;
52+
REBSER *port;
5153

52-
Validate_Port(port, action);
54+
port = Validate_Port_Value(port_value);
5355

5456
*D_RET = *D_ARG(1);
5557

@@ -69,7 +71,7 @@
6971
switch (action) {
7072

7173
case A_OPEN:
72-
arg = Obj_Value(spec, STD_PORT_SPEC_SERIAL_PATH); //Should Obj_Value really return a char* ?
74+
arg = Obj_Value(spec, STD_PORT_SPEC_SERIAL_REF); //Should Obj_Value really return a char* ?
7375
if (! (IS_FILE(arg) || IS_STRING(arg) || IS_BINARY(arg))) {
7476
Trap1(RE_INVALID_PORT_ARG, arg);
7577
}

src/include/reb-device.h

+28
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
** REBOL [R3] Language Interpreter and Run-time Environment
44
**
55
** Copyright 2012 REBOL Technologies
6+
** Copyright 2013-2023 Rebol Open Source Developers
67
** REBOL is a trademark of REBOL Technologies
78
**
89
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -44,6 +45,7 @@ enum {
4445
RDI_CLIPBOARD,
4546
RDI_MIDI,
4647
RDI_CRYPT,
48+
RDI_SERIAL,
4749
RDI_MAX,
4850
RDI_LIMIT = 32
4951
};
@@ -118,6 +120,21 @@ enum {
118120
RDM_READ_LINE,
119121
};
120122

123+
// Serial Parity
124+
enum {
125+
SERIAL_PARITY_NONE,
126+
SERIAL_PARITY_ODD,
127+
SERIAL_PARITY_EVEN
128+
};
129+
130+
// Serial Flow Control
131+
enum {
132+
SERIAL_FLOW_CONTROL_NONE,
133+
SERIAL_FLOW_CONTROL_HARDWARE,
134+
SERIAL_FLOW_CONTROL_SOFTWARE
135+
};
136+
137+
121138
#pragma pack(4)
122139

123140
// Forward references:
@@ -205,6 +222,17 @@ struct rebol_devreq {
205222
u32 mode;
206223
u32 value;
207224
} modify;
225+
226+
struct {
227+
REBCHR *path; // device path string (in OS local format)
228+
void *prior_attr; // termios: retain previous settings to revert on close
229+
i32 baud; // baud rate of serial port
230+
u8 data_bits; // 5, 6, 7 or 8
231+
u8 parity; // odd, even, mark or space
232+
u8 stop_bits; // 1 or 2
233+
u8 flow_control; // hardware or software
234+
} serial;
235+
208236
};
209237
};
210238
#pragma pack()

src/mezz/sys-ports.reb

+23
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ REBOL [
33
Title: "REBOL 3 Boot Sys: Port and Scheme Functions"
44
Rights: {
55
Copyright 2012 REBOL Technologies
6+
Copyright 2012-2023 Rebol Open Source Contributors
67
REBOL is a trademark of REBOL Technologies
78
}
89
License: {
@@ -504,6 +505,28 @@ init-schemes: func [
504505
]
505506
]
506507

508+
make-scheme [
509+
title: "Serial Port"
510+
name: 'serial
511+
spec: system/standard/port-spec-serial
512+
init: func [port /local path speed] [
513+
if url? port/spec/ref [
514+
parse port/spec/ref [
515+
thru #":" 0 2 slash
516+
copy path [to slash | end] skip
517+
copy speed to end
518+
]
519+
try/except [port/spec/path: to file! path][
520+
cause-error 'access 'invalid-spec :path
521+
]
522+
try/except [port/spec/speed: to integer! speed][
523+
cause-error 'access 'invalid-spec :speed
524+
]
525+
]
526+
]
527+
]
528+
529+
507530
system/ports/system: open [scheme: 'system]
508531
system/ports/input:
509532
system/ports/output: open [scheme: 'console]

src/os/host-device.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
** REBOL [R3] Language Interpreter and Run-time Environment
44
**
55
** Copyright 2012 REBOL Technologies
6-
** Copyright 2012-2021 Rebol Open Source Developers
6+
** Copyright 2012-2023 Rebol Open Source Developers
77
** REBOL is a trademark of REBOL Technologies
88
**
99
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -92,6 +92,13 @@ extern REBDEV Dev_Crypt;
9292
#define DEVICE_PTR_CRYPT 0
9393
#endif
9494

95+
#ifdef INCLUDE_SERIAL_DEVICE
96+
extern REBDEV Dev_Serial;
97+
#define DEVICE_PTR_SERIAL &Dev_Serial
98+
#else
99+
#define DEVICE_PTR_SERIAL 0
100+
#endif
101+
95102
REBDEV *Devices[RDI_LIMIT] =
96103
{
97104
0,
@@ -104,7 +111,8 @@ REBDEV *Devices[RDI_LIMIT] =
104111
0,//&Dev_Checksum,
105112
DEVICE_PTR_CLIPBOARD,
106113
DEVICE_PTR_MIDI,
107-
0 //DEVICE_PTR_CRYPT
114+
0, //DEVICE_PTR_CRYPT
115+
DEVICE_PTR_SERIAL,
108116
};
109117

110118

src/os/posix/dev-serial.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
** REBOL [R3] Language Interpreter and Run-time Environment
44
**
55
** Copyright 2013 REBOL Technologies
6+
** Copyright 2013-2023 Rebol Open Source Developers
67
** REBOL is a trademark of REBOL Technologies
78
**
89
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +21,7 @@
2021
************************************************************************
2122
**
2223
** Title: Device: Serial port access for Posix
23-
** Author: Carl Sassenrath
24+
** Author: Carl Sassenrath, Joshua Shireman, Shixin Zeng
2425
**
2526
************************************************************************
2627
**

src/os/win32/dev-serial.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
** REBOL [R3] Language Interpreter and Run-time Environment
44
**
55
** Copyright 2013 REBOL Technologies
6+
** Copyright 2013-2023 Rebol Open Source Developers
67
** REBOL is a trademark of REBOL Technologies
78
**
89
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +21,7 @@
2021
************************************************************************
2122
**
2223
** Title: Device: Serial port access for Windows
23-
** Author: Carl Sassenrath, Joshua Shireman
24+
** Author: Carl Sassenrath, Joshua Shireman, Shixin Zeng
2425
**
2526
************************************************************************
2627
**

0 commit comments

Comments
 (0)