Browse Source

first commit

master
Sylvain PILLOT 1 month ago
commit
ea93ab3087
  1. 32
      Makefile
  2. 15
      README.md
  3. 30
      include/asm.h
  4. 95
      include/serial.h
  5. 4
      src/App_LINK_GetDeviceInfo.S
  6. 4
      src/App_LINK_GetReceiveTimeout_ms.S
  7. 4
      src/App_LINK_Send_ST9_Packet.S
  8. 4
      src/App_LINK_SetReceiveTimeout_ms.S
  9. 4
      src/App_LINK_SetRemoteBaud.S
  10. 4
      src/App_LINK_Transmit.S
  11. 4
      src/App_LINK_TransmitInit.S
  12. 4
      src/Comm_Close.S
  13. 4
      src/Comm_Open.S
  14. 4
      src/Comm_Terminate.S
  15. 4
      src/Comm_TryCheckPacket.S
  16. 4
      src/Serial_ClearRX.S
  17. 4
      src/Serial_ClearTX.S
  18. 4
      src/Serial_Close.S
  19. 4
      src/Serial_IsOpen.S
  20. 4
      src/Serial_Open.S
  21. 4
      src/Serial_Peek.S
  22. 4
      src/Serial_PollRX.S
  23. 4
      src/Serial_PollTX.S
  24. 4
      src/Serial_Read.S
  25. 4
      src/Serial_ReadSingle.S
  26. 4
      src/Serial_Write.S
  27. 4
      src/Serial_WriteSingle.S
  28. 4
      src/Serial_WriteUnbuffered.S

32
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)

15
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.

30
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

95
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

4
src/App_LINK_GetDeviceInfo.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_App_LINK_GetDeviceInfo, 0x1399)

4
src/App_LINK_GetReceiveTimeout_ms.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_App_LINK_GetReceiveTimeout_ms, 0x140A)

4
src/App_LINK_Send_ST9_Packet.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_App_LINK_Send_ST9_Packet, 0x1398)

4
src/App_LINK_SetReceiveTimeout_ms.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_App_LINK_SetReceiveTimeout_ms, 0x1409)

4
src/App_LINK_SetRemoteBaud.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_App_LINK_SetRemoteBaud, 0x1397)

4
src/App_LINK_Transmit.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_App_LINK_Transmit, 0x13A7)

4
src/App_LINK_TransmitInit.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_App_LINK_TransmitInit, 0x13A6)

4
src/Comm_Close.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Comm_Close, 0x1354)

4
src/Comm_Open.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Comm_Open, 0x1353)

4
src/Comm_Terminate.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Comm_Terminate, 0x13F1)

4
src/Comm_TryCheckPacket.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Comm_TryCheckPacket, 0x1396)

4
src/Serial_ClearRX.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Serial_ClearRX, 0x1BC1)

4
src/Serial_ClearTX.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Serial_ClearTX, 0x1BC2)

4
src/Serial_Close.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Serial_Close, 0x1BB8)

4
src/Serial_IsOpen.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Serial_IsOpen, 0x1BC6)

4
src/Serial_Open.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Serial_Open, 0x1BB7)

4
src/Serial_Peek.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Serial_Peek, 0x1BBB)

4
src/Serial_PollRX.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Serial_PollRX, 0x1BBF)

4
src/Serial_PollTX.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Serial_PollTX, 0x1BC0)

4
src/Serial_Read.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Serial_Read, 0x1BBA)

4
src/Serial_ReadSingle.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Serial_ReadSingle, 0x1BB9)

4
src/Serial_Write.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Serial_Write, 0x1BBE)

4
src/Serial_WriteSingle.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Serial_WriteSingle, 0x1BBC)

4
src/Serial_WriteUnbuffered.S

@ -0,0 +1,4 @@
#include <asm.h>
SYSCALL(_Serial_WriteUnbuffered, 0x1BBD)
Loading…
Cancel
Save