From a07cc4a4c14e5d3505afe27f532b26ae147cdcc9 Mon Sep 17 00:00:00 2001 From: cuz Date: Fri, 18 Apr 2003 16:29:51 +0000 Subject: [PATCH] Working on new serial API git-svn-id: svn://svn.cc65.org/cc65/trunk@2069 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- asminc/ser-error.inc | 50 ++++++++++++ asminc/ser-kernel.inc | 148 ++++++++++++++++++++++++++++++++++++ include/serial.h | 2 +- libsrc/serial/.cvsignore | 1 + libsrc/serial/Makefile | 8 +- libsrc/serial/ser-kernel.s | 6 ++ libsrc/serial/ser_get.s | 25 ++++++ libsrc/serial/ser_load.c | 21 ++++- libsrc/serial/ser_params.s | 24 ++++++ libsrc/serial/ser_pause.s | 12 +++ libsrc/serial/ser_put.s | 14 ++++ libsrc/serial/ser_status.s | 21 +++++ libsrc/serial/ser_unload.s | 1 + libsrc/serial/ser_unpause.s | 11 +++ 14 files changed, 339 insertions(+), 5 deletions(-) create mode 100644 asminc/ser-error.inc create mode 100644 asminc/ser-kernel.inc create mode 100644 libsrc/serial/.cvsignore create mode 100644 libsrc/serial/ser_get.s create mode 100644 libsrc/serial/ser_params.s create mode 100644 libsrc/serial/ser_pause.s create mode 100644 libsrc/serial/ser_put.s create mode 100644 libsrc/serial/ser_status.s create mode 100644 libsrc/serial/ser_unpause.s diff --git a/asminc/ser-error.inc b/asminc/ser-error.inc new file mode 100644 index 000000000..736846aae --- /dev/null +++ b/asminc/ser-error.inc @@ -0,0 +1,50 @@ +;**************************************************************************** +;* * +;* ser-error.inc * +;* * +;* Serial communication API * +;* * +;* * +;* * +;*(C) 2003 Ullrich von Bassewitz * +;* Römerstrasse 52 * +;* D-70794 Filderstadt * +;*EMail: uz@cc65.org * +;* * +;* * +;*This software is provided 'as-is', without any expressed or implied * +;*warranty. In no event will the authors be held liable for any damages * +;*arising from the use of this software. * +;* * +;*Permission is granted to anyone to use this software for any purpose, * +;*including commercial applications, and to alter it and redistribute it * +;*freely, subject to the following restrictions: * +;* * +;*1. The origin of this software must not be misrepresented; you must not * +;* claim that you wrote the original software. If you use this software * +;* in a product, an acknowledgment in the product documentation would be * +;* appreciated but is not required. * +;*2. Altered source versions must be plainly marked as such, and must not * +;* be misrepresented as being the original software. * +;*3. This notice may not be removed or altered from any source * +;* distribution. * +;* * +;**************************************************************************** + + + +;------------------------------------------------------------------------------ +; Error codes + +SER_ERR_OK = $00 ; Not an error - relax +SER_ERR_NO_DRIVER = $01 ; No driver available +SER_ERR_CANNOT_LOAD = $02 ; Error loading driver +SER_ERR_INV_DRIVER = $03 ; Invalid driver +SER_ERR_NO_DEVICE = $04 ; Device (hardware) not found +SER_ERR_BAUD_UNAVAIL = $05 ; Baud rate not available +SER_ERR_NO_DATA = $06 ; Nothing to read +SER_ERR_OVERFLOW = $07 ; No room in send buffer +SER_ERR_INIT_FAILED = $08 ; Initialization failed + + + diff --git a/asminc/ser-kernel.inc b/asminc/ser-kernel.inc new file mode 100644 index 000000000..66ce8aea7 --- /dev/null +++ b/asminc/ser-kernel.inc @@ -0,0 +1,148 @@ +;**************************************************************************** +;* * +;* ser-kernel.inc * +;* * +;* Serial communication API * +;* * +;* * +;* * +;*(C) 2003 Ullrich von Bassewitz * +;* Römerstrasse 52 * +;* D-70794 Filderstadt * +;*EMail: uz@cc65.org * +;* * +;* * +;*This software is provided 'as-is', without any expressed or implied * +;*warranty. In no event will the authors be held liable for any damages * +;*arising from the use of this software. * +;* * +;*Permission is granted to anyone to use this software for any purpose, * +;*including commercial applications, and to alter it and redistribute it * +;*freely, subject to the following restrictions: * +;* * +;*1. The origin of this software must not be misrepresented; you must not * +;* claim that you wrote the original software. If you use this software * +;* in a product, an acknowledgment in the product documentation would be * +;* appreciated but is not required. * +;*2. Altered source versions must be plainly marked as such, and must not * +;* be misrepresented as being the original software. * +;*3. This notice may not be removed or altered from any source * +;* distribution. * +;* * +;**************************************************************************** + + + +;------------------------------------------------------------------------------ +; Offsets into the driver header + +SER_HDR_ID = 0 ; Contains 0x73, 0x65, 0x72 ("ser") +SER_HDR_VERSION = 3 ; Interface version + +SER_HDR_JUMPTAB = 4 +SER_HDR_INSTALL = SER_HDR_JUMPTAB+0 ; INSTALL routine +SER_HDR_UNINSTALL = SER_HDR_JUMPTAB+2 ; UNINSTALL routine +SER_HDR_PARAMS = SER_HDR_JUMPTAB+4 ; PARAMS routine +SER_HDR_GET = SER_HDR_JUMPTAB+6 ; GET routine +SER_HDR_PUT = SER_HDR_JUMPTAB+8 ; PUT routine +SER_HDR_PAUSE = SER_HDR_JUMPTAB+10 ; PAUSE routine +SER_HDR_UNPAUSE = SER_HDR_JUMPTAB+12 ; UNPAUSE routine +SER_HDR_STATUS = SER_HDR_JUMPTAB+14 ; STATUS routine + +SER_HDR_JUMPCOUNT = 8 ; Number of jump vectors + +;------------------------------------------------------------------------------ +; Offsets into the struct passed to ser_params + +SER_PARAMS_BAUDRATE = 0 ; Baudrate +SER_PARAMS_DATABITS = 1 ; Number of data bits +SER_PARAMS_STOPBITS = 2 ; Number of stop bits +SER_PARAMS_PARITY = 3 ; Parity setting +SER_PARAMS_HANDSHAKE = 4 ; Type of handshake to use + +;------------------------------------------------------------------------------ +; Serial parameters + +; Baudrate +SER_BAUD_45_5 = $00 +SER_BAUD_50 = $01 +SER_BAUD_75 = $02 +SER_BAUD_110 = $03 +SER_BAUD_134_5 = $04 +SER_BAUD_150 = $05 +SER_BAUD_300 = $06 +SER_BAUD_600 = $07 +SER_BAUD_1200 = $08 +SER_BAUD_1800 = $09 +SER_BAUD_2400 = $0A +SER_BAUD_4800 = $0B +SER_BAUD_9600 = $0C +SER_BAUD_19200 = $0D +SER_BAUD_38400 = $0E +SER_BAUD_57600 = $0F +SER_BAUD_115200 = $10 +SER_BAUD_230400 = $11 + +; Data bit settings +SER_BITS_5 = $00 +SER_BITS_6 = $01 +SER_BITS_7 = $02 +SER_BITS_8 = $03 + +; Stop bit settings +SER_STOP_1 = $00 +SER_STOP_2 = $01 + +; Parity +SER_PAR_NONE = $00 +SER_PAR_ODD = $01 +SER_PAR_EVEN = $02 +SER_PAR_MARK = $03 +SER_PAR_SPACE = $04 + +; Handshake +SER_HS_NONE = $00 ; No handshake +SER_HS_HW = $01 ; Hardware (RTS/CTS) handshake +SER_HS_SW = $02 ; Software handshake + +; Bit masks to mask out things from the status returned by rs232_status +SER_STATUS_PE = $01 ; Parity error +SER_STATUS_FE = $02 ; Framing error +SER_STATUS_OE = $04 ; Overrun error +SER_STATUS_DCD = $20 ; NOT data carrier detect +SER_STATUS_DSR = $40 ; NOT data set ready + +;------------------------------------------------------------------------------ +; Variables + + .global _ser_drv ; Pointer to driver + +;------------------------------------------------------------------------------ +; Driver entry points + + .global ser_install + .global ser_uninstall + .global ser_params + .global ser_get + .global ser_put + .global ser_pause + .global ser_unpause + .global ser_status + + + +;------------------------------------------------------------------------------ +; ASM functions + + .global _ser_unload + .global _ser_install + .global _ser_uninstall + .global _ser_params + .global _ser_get + .global _ser_put + .global _ser_pause + .global _ser_unpause + .global _ser_status + + + diff --git a/include/serial.h b/include/serial.h index 910c92f0b..8ccb5ac38 100644 --- a/include/serial.h +++ b/include/serial.h @@ -154,7 +154,7 @@ unsigned char __fastcall__ ser_pause (void); unsigned char __fastcall__ ser_unpause (void); /* Re-enable interrupts and release flow control */ -unsigned char __fastcall__ rs232_status (unsigned char* status); +unsigned char __fastcall__ ser_status (unsigned char* status); /* Return the serial port status. */ diff --git a/libsrc/serial/.cvsignore b/libsrc/serial/.cvsignore new file mode 100644 index 000000000..c81f22f08 --- /dev/null +++ b/libsrc/serial/.cvsignore @@ -0,0 +1 @@ +ser_load.s diff --git a/libsrc/serial/Makefile b/libsrc/serial/Makefile index ab723cf15..798dc1012 100644 --- a/libsrc/serial/Makefile +++ b/libsrc/serial/Makefile @@ -20,7 +20,13 @@ C_OBJS = ser_load.o S_OBJS = ser-kernel.o \ - ser_unload.o + ser_get.o \ + ser_params.o \ + ser_pause.o \ + ser_put.o \ + ser_status.o \ + ser_unload.o \ + ser_unpause.o #-------------------------------------------------------------------------- diff --git a/libsrc/serial/ser-kernel.s b/libsrc/serial/ser-kernel.s index a1ac462a8..69c45df5e 100644 --- a/libsrc/serial/ser-kernel.s +++ b/libsrc/serial/ser-kernel.s @@ -24,6 +24,12 @@ _ser_drv: .res 2 ; Pointer to driver ser_vectors: ser_install: jmp return0 ser_uninstall: jmp return0 +ser_params: jmp return0 +ser_get: jmp return0 +ser_put: jmp return0 +ser_pause: jmp return0 +ser_unpause: jmp return0 +ser_status: jmp return0 ; Driver header signature .rodata diff --git a/libsrc/serial/ser_get.s b/libsrc/serial/ser_get.s new file mode 100644 index 000000000..dccd92000 --- /dev/null +++ b/libsrc/serial/ser_get.s @@ -0,0 +1,25 @@ +; +; Ullrich von Bassewitz, 2003-04-18 +; +; unsigned char __fastcall__ ser_get (char* b); +; /* Get a character from the serial port. If no characters are available, the +; * function will return SER_ERR_NO_DATA, so this is not a fatal error. +; */ + + + .importzp ptr1 + + .include "ser-kernel.inc" + + +.proc _ser_get + + sta ptr1 + stx ptr1+1 ; Save pointer to char + jmp ser_get ; Call the driver + +.endproc + + + + diff --git a/libsrc/serial/ser_load.c b/libsrc/serial/ser_load.c index 580f826fe..692a9cde3 100644 --- a/libsrc/serial/ser_load.c +++ b/libsrc/serial/ser_load.c @@ -36,8 +36,24 @@ #include #include #include -#include -#include +#include + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +/* Pointer to serial driver, exported from ser-kernel.s */ +extern void* ser_drv; + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ @@ -79,4 +95,3 @@ unsigned char __fastcall__ ser_load_driver (const char* name) - diff --git a/libsrc/serial/ser_params.s b/libsrc/serial/ser_params.s new file mode 100644 index 000000000..58cf35e99 --- /dev/null +++ b/libsrc/serial/ser_params.s @@ -0,0 +1,24 @@ +; +; Ullrich von Bassewitz, 2003-04-18 +; +; unsigned char __fastcall__ ser_params (const struct ser_params* params); +; /* Set the port parameters. This will also enable the port. */ + + + .importzp ptr1 + + .include "ser-kernel.inc" + + + +.proc _ser_params + + sta ptr1 + stx ptr1+1 ; Save pointer to params + jmp ser_params ; Call the driver + +.endproc + + + + diff --git a/libsrc/serial/ser_pause.s b/libsrc/serial/ser_pause.s new file mode 100644 index 000000000..c77d0acf7 --- /dev/null +++ b/libsrc/serial/ser_pause.s @@ -0,0 +1,12 @@ +; +; Ullrich von Bassewitz, 2003-04-18 +; +; unsigned char __fastcall__ ser_pause (void); +; /* Assert flow control and disable interrupts. */ + + + + .include "ser-kernel.inc" + + _ser_pause = ser_pause + diff --git a/libsrc/serial/ser_put.s b/libsrc/serial/ser_put.s new file mode 100644 index 000000000..7bbdbdeb4 --- /dev/null +++ b/libsrc/serial/ser_put.s @@ -0,0 +1,14 @@ +; +; Ullrich von Bassewitz, 2003-04-18 +; +; unsigned char __fastcall__ ser_put (char b); +; /* Send a character via the serial port. There is a transmit buffer, but +; * transmitting is not done via interrupt. The function returns +; * SER_ERR_OVERFLOW if there is no space left in the transmit buffer. +; */ + + + .include "ser-kernel.inc" + + _ser_put = ser_put + diff --git a/libsrc/serial/ser_status.s b/libsrc/serial/ser_status.s new file mode 100644 index 000000000..ac56daa39 --- /dev/null +++ b/libsrc/serial/ser_status.s @@ -0,0 +1,21 @@ +; +; Ullrich von Bassewitz, 2003-04-18 +; +; unsigned char __fastcall__ ser_status (unsigned char* status); +; /* Return the serial port status. */ + + + .importzp ptr1 + + .include "ser-kernel.inc" + + +.proc _ser_status + + sta ptr1 + stx ptr1+1 ; Save pointer to status + jmp ser_status ; Call the driver + +.endproc + + diff --git a/libsrc/serial/ser_unload.s b/libsrc/serial/ser_unload.s index 6dbad90cd..64ffb99bc 100644 --- a/libsrc/serial/ser_unload.s +++ b/libsrc/serial/ser_unload.s @@ -11,6 +11,7 @@ .include "ser-error.inc" .include "modload.inc" + _ser_unload: lda _ser_drv ora _ser_drv+1 diff --git a/libsrc/serial/ser_unpause.s b/libsrc/serial/ser_unpause.s new file mode 100644 index 000000000..31ad42204 --- /dev/null +++ b/libsrc/serial/ser_unpause.s @@ -0,0 +1,11 @@ +; +; Ullrich von Bassewitz, 2003-04-18 +; +; unsigned char __fastcall__ ser_unpause (void); +; /* Re-enable interrupts and release flow control */ + + + .include "ser-kernel.inc" + + _ser_unpause = ser_unpause +