FreeCalypso > hg > fc-magnetite
annotate src/cs/riviera/rvt/rvt_keepalive.c @ 411:ee49b250774f
tpudrv10.c: initial rf_path[] reconstruction
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 19 Jan 2018 07:38:43 +0000 |
parents | 9ffdfacfe969 |
children |
rev | line source |
---|---|
319
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module is a FreeCalypso addition. Here we implement the special |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * operation mode that is only used when a device that was originally |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * meant to be a phone handset is turned into a pseudo-modem with no UI, |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * requiring connection to a host computer running rvinterf for control. |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #ifdef PSEUDO_MODEM_KEEPALIVE |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "nucleus.h" |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "abb.h" |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "rv/general.h" |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "rv/rv_general.h" |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "rvf/rvf_api.h" |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "rvt/rvt_gen.h" |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include "rvt/rvt_def_i.h" |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include "rvt/rvt_env.h" |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include "rvt/rvt_env_i.h" |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "rvm/rvm_use_id_list.h" |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 #include "uart/serialswitch.h" |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 #include <string.h> |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 volatile UINT8 rvt_keepalive_counter; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 void rvt_keepalive_input(T_RVT_BUFFER p_msg, UINT16 msg_length) |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 { |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 /* Checking for an invalid PDU. */ |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if ((p_msg == NULL) || (msg_length != 1)) |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 return; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 /* Check for the correct opcode */ |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (*p_msg != 'A') |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 return; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 /* good keepalive response from external host */ |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 rvt_keepalive_counter = 0; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 void rvt_keepalive_register(void) |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 { |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 T_RVT_USER_ID rvt_id; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 rvt_register_id("KEEPALIVE", &rvt_id, rvt_keepalive_input); |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 static void keepalive_send(UINT8 *buf, UINT32 size) |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 { |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 UINT32 sent; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 for (sent = 0; sent < size; ) |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 sent += SER_tr_WriteNBytes(SER_LAYER_1, buf + sent, |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 size - sent); |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 #ifdef PSEUDO_MODEM_USB |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 static char poweroff_msg[] = "System: USB unplugged, powering off"; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 #else |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 static char poweroff_msg[] = "System: no keepalive response, powering off"; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 static UINT8 keepalive_msg[2] = {RVT_KEEPALIVE_HEADER, 'Q'}; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 #endif |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 static void keepalive_poweroff(void) |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 { |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 UINT8 poweroff_msg_buf[50], *p; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 p = poweroff_msg_buf; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 *p++ = RVT_RV_HEADER; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 *p++ = 0; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 *p++ = 0; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 *p++ = 0; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 *p++ = 0; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 *p++ = RV_TRACE_LEVEL_ERROR; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 strcpy((char *)p, poweroff_msg); |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 keepalive_send(poweroff_msg_buf, strlen(poweroff_msg) + 6); |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 /* do it */ |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 ABB_Power_Off(); |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 void rvt_keepalive_process(void) |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 { |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 SYS_UWORD16 abb_status; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 abb_status = ABB_Read_Status(); |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (abb_status & CHGPRES) { |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 rvt_keepalive_counter = 0; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 return; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 #ifdef PSEUDO_MODEM_USB |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 keepalive_poweroff(); |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 #else |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 if (rvt_keepalive_counter >= 3) |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 keepalive_poweroff(); |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 else { |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 rvt_keepalive_counter++; |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 keepalive_send(keepalive_msg, sizeof keepalive_msg); |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 } |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 #endif |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 |
9ffdfacfe969
implemented pseudo-modem keepalive for C139 and Pirelli targets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 #endif |