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