commit ea93ab30870a475cd26d35916345849e58db6ac5 Author: Slyvtt Date: Wed May 11 12:58:14 2022 +0200 first commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f8374f3 --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +CC=sh-elf-gcc +AS=sh-elf-gcc +AR=sh-elf-gcc-ar +RANLIB=sh-elf-gcc-ranlib + +CFLAGS=-c -ffunction-sections -fdata-sections -Os -Lr -I./include \ + -lm -m4-nofpu -mb -ffreestanding -nostdlib -Wa,--dsp -flto -std=c99 -Wall -Wextra +ARFLAGS=rs +VPATH=syscalls +SHSOURCES=$(wildcard src/*.S) $(wildcard src/*.S) +CSOURCES=$(wildcard src/*.c) + +OBJECTS=$(SHSOURCES:.S=.o) $(CSOURCES:.c=.o) $(CXXSOURCES:.cpp=.o) +LIBRARY=./libserial.a + +all: $(SOURCES) $(LIBRARY) + +$(LIBRARY): $(OBJECTS) + $(AR) $(ARFLAGS) $@ $(OBJECTS) + +.S.o: + $(CC) $(CFLAGS) -x assembler-with-cpp $(abspath $<) -o $@ + +.c.o: + $(CC) $(CFLAGS) $< -o $@ + +.cpp.o: + $(CC) $(CFLAGS) $< -o $@ + +clean: + rm -f $(OBJECTS) $(LIBRARY) + diff --git a/README.md b/README.md new file mode 100644 index 0000000..a93a045 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Sources for compiling a lib devoted to use Serial port 3-pins of CG10/20/50 + +just run `make` in the root directory of the project. +it will produce the library `libserial.a` + +installation into the right compiler folder is not automatic. + +So you need to copy `libserial.a` in the lib folder of sh-elf-gcc compiler +and the file `include/serial.h` into the include directory + +`make clean` cleans all the `.o` and the library from the sources folders. + + + + diff --git a/include/asm.h b/include/asm.h new file mode 100644 index 0000000..7bf84f2 --- /dev/null +++ b/include/asm.h @@ -0,0 +1,30 @@ +#ifndef _SYSCALL_H_ +#define _SYSCALL_H_ + +/* template for generic functions with global name */ +/*#define _C_LABEL(x) _ ## x*/ /* prefix fn name with _ */ +#define _C_LABEL(x) x +#define _ENTRY(name) \ + .text; .align 2; .global name; name: +#define ENTRY(name) \ + _ENTRY(_C_LABEL(name)) + +/* template for syscalls */ +#define SYSCALL_BARE(name, x) \ +ENTRY(name) \ + mov.l sc_addr, r2; \ + mov.l 1f, r0; \ + jmp @r2; \ + nop; \ +1: .long x + +/* allow to have several calls in one object, by specifying + * the SYSCALL_ADDRESS separately at the end */ +#define SYSCALL_ADDRESS \ +sc_addr: .long 0x80020070 + +#define SYSCALL(name, x) \ + SYSCALL_BARE(name, x) ; \ + SYSCALL_ADDRESS + +#endif \ No newline at end of file diff --git a/include/serial.h b/include/serial.h new file mode 100644 index 0000000..775fb8d --- /dev/null +++ b/include/serial.h @@ -0,0 +1,95 @@ +#ifndef _FXCG_SERIAL_H +#define _FXCG_SERIAL_H + +#ifdef __cplusplus +extern "C" { +#endif + +int Serial_Open(unsigned char *mode); +int Serial_IsOpen(void); +int Serial_Close(int mode); + +int Serial_Read(unsigned char *out, int sz, short *count); +int Serial_ReadSingle(unsigned char *out); +int Serial_Peek(int idx, unsigned char *out); +int Serial_PollRX(void); +int Serial_ClearRX(void); + +int Serial_Write(const unsigned char *buf, int count); +int Serial_WriteSingle(unsigned char x); +int Serial_WriteUnbuffered(unsigned char x); +int Serial_PollTX(void); +int Serial_ClearTX(void); + +// higher-level link functions. used to transfer files between calculators + +struct TTransmitBuffer { + char device[0x008]; // fls0 + char directoryname[0x10A]; +// 0x112 + char fname1[0x10A]; + char dummy[0x28]; + char fname2[0x00E]; +// 0x252 + unsigned short filename[0x10A]; +// 0x466 + char dummy2[0x1A]; +// 0x480 + int filesize; +// 0x484 + short dummy3; +// 0x486 + char command; + char subcommand; +// 0x488 + char datatype; + char dummy4_3; + char dummy4_4; + char dummy4_5; +// 0x48C + int handle; +// 0x490 + char dummy5[8]; +// 0x498 + char source; + char dummy6_1; + char dummy6_2; + char dummy6_3; +// 0x49C + int zero; +}; + +int App_LINK_GetReceiveTimeout_ms( void ); +void App_LINK_SetReceiveTimeout_ms( int timeout ); +int Comm_Open( unsigned short parameters ); +int Comm_Close( int mode ); +int Comm_TryCheckPacket( unsigned char subtype ); +int Comm_Terminate( unsigned char subtype ); +int App_LINK_SetRemoteBaud( void ); //Switch the remote calculator to 115200 baud, no parity and 1 stop bit (command '02'; (fxReverse.PDF, p. 17)). Close the serial interface. Open the serial interface with 115200 baud, no parity and 1 stop bit. +int App_LINK_Send_ST9_Packet( void ); +int App_LINK_GetDeviceInfo( unsigned int* calcType, unsigned short* osVer); +int App_LINK_TransmitInit( struct TTransmitBuffer*ttb ); +int App_LINK_Transmit( struct TTransmitBuffer*ttb ); + + +#ifdef _FXCG_MINICOMPAT + +#define Serial_ReadNBytes Serial_Read +#define Serial_ReadOneByte Serial_ReadSingle +#define Serial_SpyNthByte Serial_Peek +#define Serial_GetReceivedBytesAvailable Serial_PollRX +#define Serial_ClearReceiveBuffer Serial_ClearRX + +#define Serial_BufferedTransmitNBytes Serial_Write +#define Serial_BufferedTransmitOneByte Serial_WriteSingle +#define Serial_DirectTransmitOneByte Serial_WriteUnbuffered +#define Serial_GetFreeTransmitSpace Serial_PollTX +#define Serial_ClearTransmitBuffer Serial_ClearTX + +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/App_LINK_GetDeviceInfo.S b/src/App_LINK_GetDeviceInfo.S new file mode 100644 index 0000000..8c3efbf --- /dev/null +++ b/src/App_LINK_GetDeviceInfo.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_App_LINK_GetDeviceInfo, 0x1399) + diff --git a/src/App_LINK_GetReceiveTimeout_ms.S b/src/App_LINK_GetReceiveTimeout_ms.S new file mode 100644 index 0000000..a4efd97 --- /dev/null +++ b/src/App_LINK_GetReceiveTimeout_ms.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_App_LINK_GetReceiveTimeout_ms, 0x140A) + diff --git a/src/App_LINK_Send_ST9_Packet.S b/src/App_LINK_Send_ST9_Packet.S new file mode 100644 index 0000000..7d139d4 --- /dev/null +++ b/src/App_LINK_Send_ST9_Packet.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_App_LINK_Send_ST9_Packet, 0x1398) + diff --git a/src/App_LINK_SetReceiveTimeout_ms.S b/src/App_LINK_SetReceiveTimeout_ms.S new file mode 100644 index 0000000..4673889 --- /dev/null +++ b/src/App_LINK_SetReceiveTimeout_ms.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_App_LINK_SetReceiveTimeout_ms, 0x1409) + diff --git a/src/App_LINK_SetRemoteBaud.S b/src/App_LINK_SetRemoteBaud.S new file mode 100644 index 0000000..baafc21 --- /dev/null +++ b/src/App_LINK_SetRemoteBaud.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_App_LINK_SetRemoteBaud, 0x1397) + diff --git a/src/App_LINK_Transmit.S b/src/App_LINK_Transmit.S new file mode 100644 index 0000000..d681dea --- /dev/null +++ b/src/App_LINK_Transmit.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_App_LINK_Transmit, 0x13A7) + diff --git a/src/App_LINK_TransmitInit.S b/src/App_LINK_TransmitInit.S new file mode 100644 index 0000000..5c6ec4a --- /dev/null +++ b/src/App_LINK_TransmitInit.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_App_LINK_TransmitInit, 0x13A6) + diff --git a/src/Comm_Close.S b/src/Comm_Close.S new file mode 100644 index 0000000..2410040 --- /dev/null +++ b/src/Comm_Close.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Comm_Close, 0x1354) + diff --git a/src/Comm_Open.S b/src/Comm_Open.S new file mode 100644 index 0000000..c3f1959 --- /dev/null +++ b/src/Comm_Open.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Comm_Open, 0x1353) + diff --git a/src/Comm_Terminate.S b/src/Comm_Terminate.S new file mode 100644 index 0000000..1383a3a --- /dev/null +++ b/src/Comm_Terminate.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Comm_Terminate, 0x13F1) + diff --git a/src/Comm_TryCheckPacket.S b/src/Comm_TryCheckPacket.S new file mode 100644 index 0000000..2e9f6ce --- /dev/null +++ b/src/Comm_TryCheckPacket.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Comm_TryCheckPacket, 0x1396) + diff --git a/src/Serial_ClearRX.S b/src/Serial_ClearRX.S new file mode 100644 index 0000000..374f64f --- /dev/null +++ b/src/Serial_ClearRX.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Serial_ClearRX, 0x1BC1) + diff --git a/src/Serial_ClearTX.S b/src/Serial_ClearTX.S new file mode 100644 index 0000000..397467f --- /dev/null +++ b/src/Serial_ClearTX.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Serial_ClearTX, 0x1BC2) + diff --git a/src/Serial_Close.S b/src/Serial_Close.S new file mode 100644 index 0000000..c714e7f --- /dev/null +++ b/src/Serial_Close.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Serial_Close, 0x1BB8) + diff --git a/src/Serial_IsOpen.S b/src/Serial_IsOpen.S new file mode 100644 index 0000000..09de8d1 --- /dev/null +++ b/src/Serial_IsOpen.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Serial_IsOpen, 0x1BC6) + diff --git a/src/Serial_Open.S b/src/Serial_Open.S new file mode 100644 index 0000000..5513b57 --- /dev/null +++ b/src/Serial_Open.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Serial_Open, 0x1BB7) + diff --git a/src/Serial_Peek.S b/src/Serial_Peek.S new file mode 100644 index 0000000..47da890 --- /dev/null +++ b/src/Serial_Peek.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Serial_Peek, 0x1BBB) + diff --git a/src/Serial_PollRX.S b/src/Serial_PollRX.S new file mode 100644 index 0000000..9c3f8d7 --- /dev/null +++ b/src/Serial_PollRX.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Serial_PollRX, 0x1BBF) + diff --git a/src/Serial_PollTX.S b/src/Serial_PollTX.S new file mode 100644 index 0000000..f1811d6 --- /dev/null +++ b/src/Serial_PollTX.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Serial_PollTX, 0x1BC0) + diff --git a/src/Serial_Read.S b/src/Serial_Read.S new file mode 100644 index 0000000..f38330d --- /dev/null +++ b/src/Serial_Read.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Serial_Read, 0x1BBA) + diff --git a/src/Serial_ReadSingle.S b/src/Serial_ReadSingle.S new file mode 100644 index 0000000..a4ec3b5 --- /dev/null +++ b/src/Serial_ReadSingle.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Serial_ReadSingle, 0x1BB9) + diff --git a/src/Serial_Write.S b/src/Serial_Write.S new file mode 100644 index 0000000..c065a0d --- /dev/null +++ b/src/Serial_Write.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Serial_Write, 0x1BBE) + diff --git a/src/Serial_WriteSingle.S b/src/Serial_WriteSingle.S new file mode 100644 index 0000000..9cbe0d7 --- /dev/null +++ b/src/Serial_WriteSingle.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Serial_WriteSingle, 0x1BBC) + diff --git a/src/Serial_WriteUnbuffered.S b/src/Serial_WriteUnbuffered.S new file mode 100644 index 0000000..4afb2bd --- /dev/null +++ b/src/Serial_WriteUnbuffered.S @@ -0,0 +1,4 @@ +#include + +SYSCALL(_Serial_WriteUnbuffered, 0x1BBD) +