# HG changeset patch # User Mychaela Falconia # Date 1616275076 0 # Node ID 6cc3eea720cb713d55c75f62dbe16dd9d763a32f # Parent 5ee00413b8af2f9c1d6d022dd7b908fbb47f1f52 serial: speed enhancement implemented diff -r 5ee00413b8af -r 6cc3eea720cb serial/Makefile --- a/serial/Makefile Sat Mar 20 20:53:51 2021 +0000 +++ b/serial/Makefile Sat Mar 20 21:17:56 2021 +0000 @@ -7,7 +7,8 @@ INSTBIN=${INSTALL_PREFIX}/bin ATR_OBJS= atrmain.o baud_parse.o collect_atr.o invtable.o serport.o -MAIN_OBJS= baud_parse.o collect_atr.o invtable.o main.o serport.o xmit.o +MAIN_OBJS= baud_parse.o collect_atr.o invtable.o main.o serport.o spenh.o \ + xmit.o all: ${PROGS} diff -r 5ee00413b8af -r 6cc3eea720cb serial/main.c --- a/serial/main.c Sat Mar 20 20:53:51 2021 +0000 +++ b/serial/main.c Sat Mar 20 21:17:56 2021 +0000 @@ -5,7 +5,7 @@ #include #include -extern unsigned baud_base; +extern unsigned baud_base, baud_spenh; main(argc, argv) char **argv; @@ -25,6 +25,8 @@ if (rc < 0) exit(1); print_atr("A"); + if (baud_spenh) + spenh_logic(); /* remaining logic to be implemented */ exit(0); diff -r 5ee00413b8af -r 6cc3eea720cb serial/spenh.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/serial/spenh.c Sat Mar 20 21:17:56 2021 +0000 @@ -0,0 +1,72 @@ +/* + * This module implements speed enhancement logic for our serial + * SIM interface back end. + */ + +#include +#include +#include + +extern u_char atr_buf[]; +extern unsigned baud_spenh, spenh_host_max; + +void +spenh_logic() +{ + unsigned spenh_sim_max, use_spenh; + u_char pts_req[4], pts_resp[4]; + int rc; + + if (!(atr_buf[1] & 0x10)) { +no_spenh: printf("X SIM does not support speed enhancement\n"); + return; + } + switch (atr_buf[2]) { + case 0x94: + spenh_sim_max = 1; + break; + case 0x95: + spenh_sim_max = 2; + break; + case 0x96: + spenh_sim_max = 4; + break; + case 0x97: + spenh_sim_max = 8; + break; + default: + goto no_spenh; + } + use_spenh = spenh_sim_max; + if (use_spenh > spenh_host_max) + use_spenh = spenh_host_max; + pts_req[0] = 0xFF; + pts_req[1] = 0x10; + switch (use_spenh) { + case 1: + pts_req[2] = 0x94; + break; + case 2: + pts_req[2] = 0x95; + break; + case 4: + pts_req[2] = 0x96; + break; + case 8: + pts_req[2] = 0x97; + break; + } + pts_req[3] = pts_req[0] ^ pts_req[1] ^ pts_req[2]; + rc = send_bytes_to_sim(pts_req, 4); + if (rc < 0) + exit(1); + rc = collect_bytes_from_sim(pts_resp, 4); + if (rc < 0) + exit(1); + if (bcmp(pts_req, pts_resp, 4)) { + fprintf(stderr, "error: PTS response does not match request\n"); + exit(1); + } + set_serial_params(baud_spenh * use_spenh); + printf("X Using F=512 D=%u speed enhancement\n", use_spenh * 8); +}