SuperH-based fx calculators
Communication

Most of the Comm-functions should work like the corresponding serial functions.

The Comm-Functions are heavily used in the CommunicationsProtocol.

0x028D: int Comm_Open( unsigned short parameters );

If parameters ANDed with 0xF0 is 0x20, the USB communication channel will be opened,
else syscall 0x02AB (Serial_Open) is called with parameters.

0x028F: int Comm_WaitForAnyBuffer( int timeout_ms, int P2, int*P3 );
timeout
has to be at least 25 ms.
P2 : if 1 the wait for receive else wait for transmit
P3 :
returns 5 : comm not open
returns 6 : timeout
returns 8 : physically disconnected
returns 0x0A : manual break
 

0x0290: int Comm_ReadOneByte( unsigned char*result );

Fetches one byte from the actual opened communication pipe into result.
The function waits for 1000 ms max.
returns
0 if successful
5 if the channel is not open.
6 a timeout occurred

0x0292: int Comm_WaitForAndReadNBytes( char*buffer, int bytes_to_read ) );

Waits for bytes_to_read bytes and reads them as the case may be.
returns
0 if successful
5 if the channel is not open.
6 a timeout occurred
0x0A terminated

0x0296: int Comm_IsValidPacketAvailable( unsigned char*result );

Spies the bytes available in the receive-buffer to be a valid packet-type, which are 1, 2, 3, 5, 6, 0x15, 0x16 and 0x18. The code is mapped to 0x15, 0x16, 0x2C, 0x2D, 0x13, 0x14, 0x2E or 0x0B and stored into result.
returns
0 if successful
5 if the channel is not open.
0x18 buffer is empty

0x0299: int Comm_GetCurrentSelector( void );

returns the currently selected communicaton channel (0=serial, 1=USB)

0x02A5: int Comm_Padding_5C( unsigned char*source, unsigned short source_count, unsigned char*target, unsigned short*target_count );

Does the 0x5C-padding of bytes <= 0x20 and == 0x5C in source. Stores the result to target. The count of the resulting target-bytes is returned in target_count. The size of target has to be twice the size of bytes to process according to source_count.
returns target, which is useless.

0x02A6: int Comm_ReversePadding_5C( unsigned char*source, unsigned char*target, unsigned short source_count, unsigned short*target_count );

Does the reverse 0x5C-padding of bytes <= 0x20 and == 0x5C in source. Stores the result to target. The count of the resulting target-bytes is returned in target_count. The size of target has to equal the size of bytes to process according to source_count.
returns target, which is useless.

0x02AF: int Comm_Spy0thByte( unsigned char*result );

The next byte available in the current open communications channel is returned in result.
This function spies, it does not remove any byte.
returns
0 if successful,
5 if the communications channel is not open.
8 if the physical connection could nor be established.
9 unknown error
0x18 no byte available
 

0x02DB: int Comm_ProcessInPacket( TReceivePacketDesc*rpd );

Tries to retrieve the next data packet. The result is stored in rpd and as the case may be in rpd.databuffer.
Type is stored in TReceivePacketDesc.type
Subtype is stored in TReceivePacketDesc.subtype
If the packet contains data the field, TReceivePacketDesc.datasize is set accordingly.
TReceivePacketDesc.databuffer has to point to a memory range of sufficient size to receive the 5C-padded data.
The checksum is stored in TReceivePacketDesc.checksum.

returns
0 if successful
0x5 if the channel is not open
0x6 if a timeout occurred
0x17 if a checksum error occurred

typedef struct{
    unsigned char type;
    unsigned char subtype;
    unsigned short datasize;
    void*databuffer;
    char checksum;
} TReceivePacketDesc;

 

0x02E1: int Comm_PrepareAckPacket( TReceivePacketDesc*rpd, unsigned char subtype, void*datapointer, unsigned short datasize );

Prepares the fields of rpd as Ack packet.
type = 0x06
subtype = subtype
datasize = datasize
datapointer = datapointer
checksum = 0

returns 0 if sucessful
returns 0x17 if datasize > 0x808.

0x02E2: void Comm_PrepareErrorPacket( TReceivePacketDesc*rpd, unsigned char subtype );

Prepares the fields of rpd as Error packet.
type = 0x15
subtype = subtype
datasize = 0
checksum = 0

0x02E3: void Comm_PrepareTerminatePacket( TReceivePacketDesc*rpd, unsigned char subtype );

Prepares the fields of rpd as Terminate packet.
type = 0x18
subtype = subtype
datasize = 0
checksum = 0

0x02E4: void Comm_PrepareRoleswapPacket( TReceivePacketDesc*rpd, unsigned char subtype );

Prepares the fields of rpd as Roleswap packet.
type = 0x03
subtype = subtype
datasize = 0
checksum = 0

0x02E5: void Comm_PrepareCheckPacket( TReceivePacketDesc*rpd, unsigned char subtype );

Prepares the fields of rpd as Check packet.
type = 0x05
subtype = subtype
datasize = 0
checksum = 0

0x02E6: int Comm_PrepareCommandPacket( TReceivePacketDesc*rpd, unsigned char subtype, void*datapointer, unsigned short datasize );

Prepares the fields of rpd as Command packet.
type = 0x01
subtype = subtype
datasize = datasize
datapointer = datapointer
checksum = 0

returns 0 if sucessful
returns 0x17 if datasize > 0x808.

0x02E7: int Comm_PrepareDataPacket( TReceivePacketDesc*rpd, unsigned char subtype, void*datapointer, unsigned short datasize );

Prepares the fields of rpd as Data packet.
type = 0x02
subtype = subtype
datasize = datasize
datapointer = datapointer
checksum = 0

returns 0 if sucessful
returns 0x09 if datapointer is null.
returns 0x17 if datasize > 0x808.

0x04AE: void USB_TimerHandler( void );

This syscall is used as handler for timer 4, hence never called directly.

(02.06.2012 15:39:06)