SuperH-based fx calculators
fx legacy: serial communication

0x02AB: int Serial_Open2( unsigned short parameters );

parameters bits 3..0: baud
0: 9600, 1: 19200, 2: 38400, 3: 57600, 4: 115200
parameters bits 15..14: parity
0: no parity, 1: even parity, 2: odd parity
parameters bits 13..12: stop bits
0: one stop bit, 1: two stop bits
parameters bits 7..4: mode[0] (see 0x0418)
0: mode[0]=0, 1: mode[0]=1
returns
0 : no error
4 : comm already open
0x12 : invalid parameter
0x05 : serial already open
else 0x09

 

0x0285: int Serial_Open_57600( void );

Opens the serial interface with 57600 baud, 8bit, even par and 1 stop bit.

 

0x0409: void*Serial_ResetAndDisable( void );

Resets the serial interrupt handlers to default and disables the serial hardware.

 

0x040A: void*Serial_GetInterruptHandler( int type );

Get serial interrupt handlers
type=0: return the pointer to the receive interrupt handler
type=1: return the pointer to the transmit interrupt handler
type=2: return the pointer to the reset receive errors interrupt handler
type=3: return the pointer to the reset transmit errors interrupt handler

actually the default error reset handlers are both identical.
 

0x040B: int Serial_SetInterruptHandler( int type, void*handler );

Set serial interrupt handler
if handler is zero, the default handlers are installed.
type=0: install receive interrupt handler
type=1: install transmit interrupt handler
type=2: install reset receive errors interrupt handler
type=3: install reset transmit errors interrupt handler
returns the content of register SCSCR_2.

actually the default serial error reset handlers are both identical.

 

0x040C: int Serial_ReadOneByte( unsigned char*result );

Fetches one byte from the serial receive buffer into result.
returns
0 if successful,
1 if no byte is available
3 if the serial channel is not open.

 

0x040D: int Serial_ReadNBytes( unsigned char*result, int max_size, short*actually_transferred );

Fetches at most max_size bytes from the serial receive buffer into result.
The count of actually transferred bytes is reported in actually_transferred.
returns
0 if successful,
1 if no byte is available
3 if the serial channel is not open.

 

0x040E: int Serial_BufferedTransmitOneByte( unsigned char byte_to_transmit );

Puts one byte into the serial transmit buffer.
returns
0 if successful,
2 if no space is available in the serial interrupt transmit buffer (256 bytes max)
3 if the serial channel is not open.

 

0x040F: int Serial_BufferedTransmitNBytes( unsigned char*bytes_to_transmit, int requested_count );

Puts requested_count bytes from the array bytes_to_transmit into the serial transmit buffer, if space allows.
returns
0 if successful,
2 if no space is available in the serial interrupt transmit buffer (256 bytes max)
3 if the serial channel is not open.

 

0x0410: int Serial_DirectTransmitOneByte( unsigned char byte_to_transmit );

Puts byte_to_transmit into the serial transmit FIFO, if it is empty!
0 if successful,
1 if the FIFO is not empty
3 if the serial channel is not open.

 

0x0411: int Serial_GetReceivedBytesAvailable( void );

returns the count of received bytes available.

 

0x0412: int Serial_GetFreeTransmitSpace( void );

returns the free space in the transmit buffer.

 

0x0413: int Serial_ClearReceiveBuffer( void );

Clears the serial receive buffer.
returns
0 if successful,
3 if the serial channel is not open.

Remark: the serial interrupt receive buffer accepts 1024 bytes at most.

 

0x0414: int Serial_ClearTransmitBuffer( void );

Clears the serial transmit buffer.
returns 0 in any case

 

0x0418: int Serial_Open( unsigned char *mode );

mode points to an array that holds the 6 bytes controlling the settings for the serial interface.
mode[0]: 0x00 (mode[0]!=0 sets some serial parameters like baud and then quits with result=4;
at present I can't figure out the function of mode[0]!=0, possibly the change of parameters of an open serial channel.
MayBe it is connected with the "set link settings"-command of the FX communication protocol.
mode[1]: 0=300, 1=600, 2=1200, 3=2400, 4=4800, 5=9600, 6=19200, 7=38400, 8=57600, 9=115200 baud
mode[2]: parity: 0=no; 1=odd; 2=even
mode[3]: datalength: 0=8 bit; 1=7 bit
mode[4]: stop bits: 0=one; 1=two
mode[5]: this parameter is not used by 0x418 at present. Functions inside the OS which use 0x418 set it to 0, though.
returns
0 if successful
3 if already open
4 if mode[0]!=0

 

0x0419: int Serial_Close( int mode );

Resets all buffers; disables the corresponding hardware
if mode=1 then Serial_Close does an immediate close, t. i. it does not wait for pending transmissions.
if mode!=1 then Serial_Close quits returning code 5 if transmissions are under way.
returns
0 if successful
5 if aware of pending transmissions and transmissions are under way

 

0x041B: void*Serial_CallReceiveIntErrorResetHandler( void );

called via interrupt, usually not called directly

 

0x041C: void*Serial_CallReceiveIntHandler( void );

called via interrupt, usually not called directly

 

0x041D: void*Serial_CallTransmitIntErrorResetHandler( void );

called via interrupt, usually not called directly

 

0x041E: void*Serial_CallTransmitIntHandler( void );

called via interrupt, usually not called directly

 

0x0422: int Serial_SpyNthByte( int byteno_to_spy, unsigned char*result );

The byte at the position byteno_to_spy in the serial receive buffer is returned in result.
byteno_to_spy starts at 0! This function spies, it does not remove any byte.
returns
0 if successful,
1 if the required count of bytes is not available
3 if the serial channel is not open.

 

0x0423: void Serial_GetStatus( unsigned int*serial_status );

Fetches the serial status into serial_status.
ORER 0x40 overrun error
ER 0x01 receive error
TEND 0x02 transmit end
TDFE 0x04 transmit FIFO data empty
BRK 0x08 break detect
FER 0x10000 framing error
PER 0x20000 parity error
RDF 0x10 receive FIFO full
DR 0x20 receive data ready

 

0x0425: int Serial_IsOpen( void );

returns 3 if not open
returns 1 if open
 

 

(02.06.2012 15:39:51)