BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
seriallib.c File Reference
#include "blitzlib.h"
#include "blitzexec.h"
#include <devices/serial.h>
#include <stddef.h>

Data Structures

struct  serio

Functions

ULONG openserial (UBYTE *name, ULONG unit, ULONG baud, ULONG flag)
 OpenSerial(device$,unit#,baud,io_serflags) - open a unit of a serial device (_openserial).
void writebyte (UWORD unit, UBYTE byte)
 WriteSerial unit#,byte - write one byte (_writebyte).
void writestring2 (UWORD unit, ULONG data)
 WriteSerialString unit#,address - write a null terminated string (_writestring2).
void writestring3 (UWORD unit, ULONG data, UWORD flags, const ULONG *lens)
 WriteSerialString unit#,string,flags - write a string (_writestring3).
ULONG readobyte (UWORD unit)
 ReadSerial(unit#) - read one byte without waiting (_readobyte).
ULONG readbyte (UWORD unit, UWORD flags)
 ReadSerial(unit#,flags) - read one byte (_readbyte).
ULONG readstring (UWORD unit, const UBYTE *sbuf)
 ReadSerialString(unit#) - read everything waiting as a string (_readstring).
void closeserial (UWORD unit)
 CloseSerial unit# - close a unit (_closeserial).
void serialbuffer (UWORD unit, ULONG len)
 SetSerialBuffer unit#,bufferlength - set io_RBufLen (_serialbuffer).
void seriallens (UWORD unit, UBYTE rlen, UBYTE wlen, UBYTE stop)
 SetSerialLens unit#,readlen,writelen,stopbits - set the bit lengths and stop bits (_seriallens).
void serialsetparams (UWORD unit)
 SetSerialParams unit# - SDCMD_SETPARAMS with the request's current values (_serialsetparams).
void checkevent (void)
void readmem (UWORD unit, ULONG addr, ULONG len)
 ReadSerialMem unit#,Address,Length - read into memory (_readmem).
void writemem (UWORD unit, ULONG addr, ULONG len)
 WriteSerialMem unit#,Address,Length - write memory (_writemem).
void closeallio (void)
 Library finit (_closeallio): AbortIO, WaitIO, CloseDevice and FreeSignal for every unit still open (both halves' signals).
static struct serio * slot (UWORD unit, int shift, UWORD add)
static void noser (void)
static void freesig (struct serio *s)
static void initport (struct serio *s)
static void memio (UWORD unit, UWORD add, UWORD cmd, ULONG addr, ULONG len)
static struct serio * paramslot (UWORD unit)
static void setparams (struct serio *s)
static ULONG checkevent_c (UWORD unit, const ULONG *sigs)
 SerialEvent(unit#) - which of the unit's signals came (_checkevent).
 BLITZ_ALIAS (checkevent, checkevent_c)

Variables

static struct serio allio [16]
static ULONG oname
static ULONG ounit
static ULONG obaud
static ULONG oflag
static UBYTE wb1 [4]
static UBYTE rb1 [4]
static const char error [] = "Serial Device Not Open"

Function Documentation

◆ BLITZ_ALIAS()

BLITZ_ALIAS ( checkevent ,
checkevent_c  )

◆ checkevent()

void checkevent ( void )

◆ checkevent_c()

ULONG checkevent_c ( UWORD unit,
const ULONG * sigs )
static

SerialEvent(unit#) - which of the unit's signals came (_checkevent).

No check whether the unit is open (not a bug: it tests bit 0 of a cleared slot and returns 0). Fixed (#252): the slot is unit*256 (the original computed unit*128).

Parameters
unitd0.w: the unit
sigsa0: utillib's signals (the result of its Wait)
Returns
d0: 1 if the write port's signal is set, 2 if the read port's (2 wins), else 0

◆ closeallio()

void closeallio ( void )

Library finit (_closeallio): AbortIO, WaitIO, CloseDevice and FreeSignal for every unit still open (both halves' signals).

Fixed (#258): the write half's request is aborted and waited for too (the original freed only its signal: a pending SendIO write was replied after the end of the program).

◆ closeserial()

void closeserial ( UWORD unit)

CloseSerial unit# - close a unit (_closeserial).

AbortIO and WaitIO of both halves' requests, CloseDevice through the read half's request, both signals freed. Nothing happens for a unit that is not open.

Fixed (#252): the slot is unit*256 (the original computed unit*128: CloseSerial 1 closed the device through unit 0's write request and freed unit 1's read signal). Fixed (#258): the original called AbortIO without WaitIO for the read request and left the write request alone (a pending SendIO write stayed pending after the close).

Parameters
unitd0.w: the unit

◆ freesig()

void freesig ( struct serio * s)
static

◆ initport()

void initport ( struct serio * s)
static

◆ memio()

void memio ( UWORD unit,
UWORD add,
UWORD cmd,
ULONG addr,
ULONG len )
static

◆ noser()

void noser ( void )
static

◆ openserial()

ULONG openserial ( UBYTE * name,
ULONG unit,
ULONG baud,
ULONG flag )

OpenSerial(device$,unit#,baud,io_serflags) - open a unit of a serial device (_openserial).

Sets up the read half (port, signal, IOExtSer), opens the device with the serflags, sets the baud rate and flags (SDCMD_SETPARAMS), copies the 128 bytes to the write half and gives that its own port and signal.

Fixed (#260): a unit that is open is left alone, the result is 0 (the original set up the read half again and, when OpenDevice failed with exclusive access, cleared it: the open device was never closed, also not at the end of the program). Fixed (#259): if the write half's AllocSignal failed, the original left the device open and the write half with its request pointer; the device is closed and both halves are cleared now.

Parameters
named0: the device name
unitd1: the unit (the slot is unit*256, word arithmetic)
baudd2: the baud rate
flagd3: io_SerFlags
Returns
d0: the address of the unit's read half, 0 on failure or if the unit is open

◆ paramslot()

struct serio * paramslot ( UWORD unit)
static

◆ readbyte()

ULONG readbyte ( UWORD unit,
UWORD flags )

ReadSerial(unit#,flags) - read one byte (_readbyte).

Without the wait flag SDCMD_QUERY first: -1 if nothing is waiting; then CMD_READ of one byte, DoIO.

With bit 0 or bit 1 of the flags the query is skipped and the read waits for a byte. Fixed (#255): the original tested bit 1 (value 2) only, the help names flag 1, which did not wait. DIFF: a3 is not changed (the original leaves it on its one byte buffer rb1 inside the library).

Errors: "Serial Device Not Open" (TRAP #0, #262; returns 0).

Parameters
unitd0.w: the unit
flagsd1.w: 1 (the help) or 2 (the original's flag) = wait
Returns
d0: the byte, -1 if nothing is waiting

◆ readmem()

void readmem ( UWORD unit,
ULONG addr,
ULONG len )

ReadSerialMem unit#,Address,Length - read into memory (_readmem).

CMD_READ through the read half, DoIO. Fixed (#253): the original read through the WRITE request (+128), whose parameters SetSerialParams does not set (EOF mode had no effect).

Errors: "Serial Device Not Open" (TRAP #0, #262).

Parameters
unitd0.w: the unit
addrd1: the address
lend2: the length in bytes

◆ readobyte()

ULONG readobyte ( UWORD unit)

ReadSerial(unit#) - read one byte without waiting (_readobyte).

MOVEQ #0,d1 then _readbyte.

Parameters
unitd0.w: the unit
Returns
d0: the byte, -1 if nothing is waiting

◆ readstring()

ULONG readstring ( UWORD unit,
const UBYTE * sbuf )

ReadSerialString(unit#) - read everything waiting as a string (_readstring).

SDCMD_QUERY, then CMD_READ of io_Actual bytes to a3 (the string buffer), which is advanced over them, at most as many as fit in front of the end of the buffer with the 0 behind them; the rest stays waiting. Fixed (#256): the original did not limit the number of bytes and wrote behind the buffer. No terminating 0 (not a bug: the compiler appends clr.b (a3)+ itself where it passes a string on, blitz2.s:8767 sbtolong, #257).

Errors: "Serial Device Not Open" (TRAP #0, #262; returns 0).

Parameters
unitd0.w: the unit
sbufa0: strings1lib's init value, the string buffer (memlib globalloc: its block length, size + 8, at -4)
Returns
d0: the number of bytes (string length), 0 if nothing is waiting

◆ serialbuffer()

void serialbuffer ( UWORD unit,
ULONG len )

SetSerialBuffer unit#,bufferlength - set io_RBufLen (_serialbuffer).

SDCMD_SETPARAMS, DoIO. Fixed (#252): the slot is unit*256 (the original computed unit*128).

Errors: "Serial Device Not Open" (TRAP #0, #262).

Parameters
unitd0.w: the unit
lend1: the read buffer length

◆ seriallens()

void seriallens ( UWORD unit,
UBYTE rlen,
UBYTE wlen,
UBYTE stop )

SetSerialLens unit#,readlen,writelen,stopbits - set the bit lengths and stop bits (_seriallens).

SDCMD_SETPARAMS, DoIO. Fixed (#252): the slot is unit*256 (the original computed unit*128).

Errors: "Serial Device Not Open" (TRAP #0, #262).

Parameters
unitd0.w: the unit
rlend1.b: io_ReadLen
wlend2.b: io_WriteLen
stopd3.b: io_StopBits

◆ serialsetparams()

void serialsetparams ( UWORD unit)

SetSerialParams unit# - SDCMD_SETPARAMS with the request's current values (_serialsetparams).

Fixed (#252): the slot is unit*256 (the original computed unit*128).

Errors: "Serial Device Not Open" (TRAP #0, #262).

Parameters
unitd0.w: the unit

◆ setparams()

void setparams ( struct serio * s)
static

◆ slot()

struct serio * slot ( UWORD unit,
int shift,
UWORD add )
static

◆ writebyte()

void writebyte ( UWORD unit,
UBYTE byte )

WriteSerial unit#,byte - write one byte (_writebyte).

CMD_WRITE of one byte through the write half, DoIO.

Errors: "Serial Device Not Open" (TRAP #0, also without the debugger; the C version returns if the trap does, #262).

Parameters
unitd0.w: the unit
byted1.b: the byte

◆ writemem()

void writemem ( UWORD unit,
ULONG addr,
ULONG len )

WriteSerialMem unit#,Address,Length - write memory (_writemem).

CMD_WRITE through the write half, DoIO.

Errors: "Serial Device Not Open" (TRAP #0, #262).

Parameters
unitd0.w: the unit
addrd1: the address
lend2: the length in bytes

◆ writestring2()

void writestring2 ( UWORD unit,
ULONG data )

WriteSerialString unit#,address - write a null terminated string (_writestring2).

MOVEQ #0,d2 then _writestring3 (the length popped there is not used with flags 0, so it is not read here): SendIO with length -1, not waited for. The two argument form takes a long (an address), as in the original.

Errors: "Serial Device Not Open" (TRAP #0, #262).

Parameters
unitd0.w: the unit
datad1: the address of the string

◆ writestring3()

void writestring3 ( UWORD unit,
ULONG data,
UWORD flags,
const ULONG * lens )

WriteSerialString unit#,string,flags - write a string (_writestring3).

CMD_WRITE through the write half. Flags as in the help: bit 0 (1) = DoIO, else SendIO, not waited for; bit 1 (2) = TrueString, the length of the string, else -1 (null terminated).

Fixed (#254): the original selected TrueString and DoIO both with bit 1 and never tested bit 0.

Errors: "Serial Device Not Open" (TRAP #0, #262).

Parameters
unitd0.w: the unit
datad1: the string
flagsd2.w: the flags (1 = DoIO, 2 = TrueString)
lensa2: the argument stack, -4(a2) = the string's length

Variable Documentation

◆ allio

struct serio allio[16]
static

◆ error

const char error[] = "Serial Device Not Open"
static

◆ obaud

ULONG obaud
static

◆ oflag

ULONG oflag
static

◆ oname

ULONG oname
static

◆ ounit

ULONG ounit
static

◆ rb1

UBYTE rb1[4]
static

◆ wb1

UBYTE wb1[4]
static