1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-25 17:29:50 +00:00

Working on new serial API

git-svn-id: svn://svn.cc65.org/cc65/trunk@2069 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2003-04-18 16:29:51 +00:00
parent 2cba160622
commit a07cc4a4c1
14 changed files with 339 additions and 5 deletions

50
asminc/ser-error.inc Normal file
View File

@ -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

148
asminc/ser-kernel.inc Normal file
View File

@ -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

View File

@ -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. */

1
libsrc/serial/.cvsignore Normal file
View File

@ -0,0 +1 @@
ser_load.s

View File

@ -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
#--------------------------------------------------------------------------

View File

@ -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

25
libsrc/serial/ser_get.s Normal file
View File

@ -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

View File

@ -36,8 +36,24 @@
#include <string.h>
#include <fcntl.h>
#include <modload.h>
#include <ser.h>
#include <ser/ser-kernel.h>
#include <serial.h>
/*****************************************************************************/
/* 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)

View File

@ -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

12
libsrc/serial/ser_pause.s Normal file
View File

@ -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

14
libsrc/serial/ser_put.s Normal file
View File

@ -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

View File

@ -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

View File

@ -11,6 +11,7 @@
.include "ser-error.inc"
.include "modload.inc"
_ser_unload:
lda _ser_drv
ora _ser_drv+1

View File

@ -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