FreeCalypso > hg > fc-sim-tools
comparison serial/spenh.c @ 42:6cc3eea720cb
serial: speed enhancement implemented
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sat, 20 Mar 2021 21:17:56 +0000 |
| parents | |
| children | fbedb67d234f |
comparison
equal
deleted
inserted
replaced
| 41:5ee00413b8af | 42:6cc3eea720cb |
|---|---|
| 1 /* | |
| 2 * This module implements speed enhancement logic for our serial | |
| 3 * SIM interface back end. | |
| 4 */ | |
| 5 | |
| 6 #include <sys/types.h> | |
| 7 #include <stdio.h> | |
| 8 #include <stdlib.h> | |
| 9 | |
| 10 extern u_char atr_buf[]; | |
| 11 extern unsigned baud_spenh, spenh_host_max; | |
| 12 | |
| 13 void | |
| 14 spenh_logic() | |
| 15 { | |
| 16 unsigned spenh_sim_max, use_spenh; | |
| 17 u_char pts_req[4], pts_resp[4]; | |
| 18 int rc; | |
| 19 | |
| 20 if (!(atr_buf[1] & 0x10)) { | |
| 21 no_spenh: printf("X SIM does not support speed enhancement\n"); | |
| 22 return; | |
| 23 } | |
| 24 switch (atr_buf[2]) { | |
| 25 case 0x94: | |
| 26 spenh_sim_max = 1; | |
| 27 break; | |
| 28 case 0x95: | |
| 29 spenh_sim_max = 2; | |
| 30 break; | |
| 31 case 0x96: | |
| 32 spenh_sim_max = 4; | |
| 33 break; | |
| 34 case 0x97: | |
| 35 spenh_sim_max = 8; | |
| 36 break; | |
| 37 default: | |
| 38 goto no_spenh; | |
| 39 } | |
| 40 use_spenh = spenh_sim_max; | |
| 41 if (use_spenh > spenh_host_max) | |
| 42 use_spenh = spenh_host_max; | |
| 43 pts_req[0] = 0xFF; | |
| 44 pts_req[1] = 0x10; | |
| 45 switch (use_spenh) { | |
| 46 case 1: | |
| 47 pts_req[2] = 0x94; | |
| 48 break; | |
| 49 case 2: | |
| 50 pts_req[2] = 0x95; | |
| 51 break; | |
| 52 case 4: | |
| 53 pts_req[2] = 0x96; | |
| 54 break; | |
| 55 case 8: | |
| 56 pts_req[2] = 0x97; | |
| 57 break; | |
| 58 } | |
| 59 pts_req[3] = pts_req[0] ^ pts_req[1] ^ pts_req[2]; | |
| 60 rc = send_bytes_to_sim(pts_req, 4); | |
| 61 if (rc < 0) | |
| 62 exit(1); | |
| 63 rc = collect_bytes_from_sim(pts_resp, 4); | |
| 64 if (rc < 0) | |
| 65 exit(1); | |
| 66 if (bcmp(pts_req, pts_resp, 4)) { | |
| 67 fprintf(stderr, "error: PTS response does not match request\n"); | |
| 68 exit(1); | |
| 69 } | |
| 70 set_serial_params(baud_spenh * use_spenh); | |
| 71 printf("X Using F=512 D=%u speed enhancement\n", use_spenh * 8); | |
| 72 } |
