comparison src/cs/drivers/drv_app/abb/board/abb_inth.c @ 0:b6a5e36de839

src/cs: initial import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 04:39:26 +0000
parents
children 7409b22cac61
comparison
equal deleted inserted replaced
-1:000000000000 0:b6a5e36de839
1 /**********************************************************************************/
2 /* TEXAS INSTRUMENTS INCORPORATED PROPRIETARY INFORMATION */
3 /* */
4 /* Property of Texas Instruments -- For Unrestricted Internal Use Only */
5 /* Unauthorized reproduction and/or distribution is strictly prohibited. This */
6 /* product is protected under copyright law and trade secret law as an */
7 /* unpublished work. Created 1987, (C) Copyright 1997 Texas Instruments. All */
8 /* rights reserved. */
9 /* */
10 /* */
11 /* Filename : abb_inth.c */
12 /* */
13 /* Description : Functions to manage the ABB device interrupt. */
14 /* The Serial Port Interface is used to connect the TI */
15 /* Analog BaseBand (ABB). */
16 /* It is assumed that the ABB is connected as the SPI */
17 /* device 0, and ABB interrupt is mapped as external IT. */
18 /* */
19 /* Author : Pascal PUEL */
20 /* */
21 /* Version number : 1.2 */
22 /* */
23 /* Date and time : 07/02/03 */
24 /* */
25 /* Previous delta : Creation */
26 /* */
27 /**********************************************************************************/
28 /* */
29 /* 17/12/03 */
30 /* The original abb_inth.c has been splitted between the actual abb_inth.c */
31 /* located in drv_apps directory and abb_inth_core.c located in drv_core */
32 /* directory. */
33 /* */
34 /**********************************************************************************/
35
36 #include "l1sw.cfg"
37 #include "chipset.cfg"
38 #include "swconfig.cfg"
39 #include "sys.cfg"
40 #include "fc-target.cfg"
41
42
43 #include "l1_macro.h"
44 #include "l1_confg.h"
45 #include <string.h>
46 #include "abb/abb_inth.h"
47 #include "nucleus.h"
48
49 #include "rv/rv_defined_swe.h" // for RVM_PWR_SWE
50
51 #if (CHIPSET == 12)
52 #include "sys_inth.h"
53 #else
54 #include "inth/iq.h"
55 #endif
56
57 #include "cust_os.h"
58 #include "l1_signa.h"
59 #include "abb/abb.h"
60
61 #if defined (OP_WCP)
62 #include "ffs/ffs.h"
63 #include "ffs/board/ffspcm.h"
64 #endif
65
66 #include "rvm/rvm_use_id_list.h" // for SPI_USE_ID
67 #include "spi/spi_env.h"
68 #include "spi/spi_process.h" // for ABB_EXT_IRQ_EVT
69 #include "kpd/kpd_power_api.h" // for kpd_power_key_pressed()
70 #include "power/power.h"
71
72 #ifdef RVM_LCC_SWE
73 #include "lcc/lcc_api.h"
74 #include "lcc/lcc_cfg_i.h"
75 #include "lcc/lcc.h"
76 #include "lcc/lcc_env.h"
77 #endif
78
79 #ifdef RVM_FCHG_SWE
80 #include "fchg/fchg_struct.h"
81 #include "fchg/fchg_messages.h"
82 #endif
83
84 /********************************************************************************/
85 /* */
86 /* Function Name: spi_abb_read_int_reg_callback */
87 /* */
88 /* Purpose: Callback function */
89 /* Called when an external interrupt has occured and the */
90 /* ABB interrupt register has been read. */
91 /* */
92 /********************************************************************************/
93 void spi_abb_read_int_reg_callback(SYS_UWORD16 *read_value)
94 {
95 SYS_UWORD16 loop_count;
96 SYS_UWORD16 status_value;
97 xSignalHeaderRec *adc_msg;
98 volatile SYS_UWORD8 i;
99
100 #if (defined(RVM_LCC_SWE) || defined(RVM_FCHG_SWE))
101 struct pwr_adc_ind_s *addr;
102 extern T_PWR_CTRL_BLOCK *pwr_ctrl;
103 #endif
104
105 // check all the possible causes of the ABB IT
106 if (*read_value & PUSHOFF_IT_STS)
107 {
108 /* Push Button from ON to OFF */
109 if (SPI_GBL_INFO_PTR->is_gsm_on == TRUE)
110 {
111 NU_Sleep(SHORT_OFF_KEY_PRESSED);
112
113 // WCP Patch
114 #if (OP_WCP == 1)
115 // Backup of GSM FFS is remotely handled by MPU-S
116 // we trigger the backup upon each ON->OFF transition
117 ffs_backup ();
118 #else
119 /* Since this callback function is called from the SPI task
120 it can't be interrupted by another task
121 so we can directly access the SPI through the low-level driver */
122
123 #if ((ANLG_FAM == 1) || (ANLG_FAM == 2))
124 status_value = (ABB_Read_Status() & ONREFLT);
125 #elif (ANLG_FAM == 3)
126 status_value = (ABB_Read_Register_on_page(PAGE1, VRPCCFG) & PWOND);
127 #endif
128
129 if (status_value == PWR_OFF_KEY_PRESSED)
130 {
131 /* Inform keypad that key ON/OFF has been pressed */
132 #ifndef CONFIG_TARGET_COMPAL
133 kpd_power_key_pressed();
134 #endif
135
136 loop_count = 0;
137 /* Wait loop for Power-OFF */
138 while ((loop_count < OFF_LOOP_COUNT) &&
139 (status_value == PWR_OFF_KEY_PRESSED))
140 {
141 NU_Sleep(SHORT_OFF_KEY_PRESSED);
142 #if ((ANLG_FAM == 1) || (ANLG_FAM == 2))
143 status_value = (ABB_Read_Status() & ONREFLT);
144 #elif (ANLG_FAM == 3)
145 status_value = (ABB_Read_Register_on_page(PAGE1, VRPCCFG) & PWOND);
146 #endif
147 loop_count++;
148 }
149
150 if (status_value == PWR_OFF_KEY_PRESSED) /* Power-OFF request detected */
151 {
152 rvf_send_trace("IQ EXT: Power Off request",25, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID);
153
154 Power_OFF_Button();
155 }
156 }
157 #endif //WCP
158 }
159 else /* GSM OFF */
160 {
161 rvf_send_trace("IQ EXT: Power On request",24, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID);
162
163 Power_ON_Button();
164 }
165 }
166
167 else if (*read_value & REMOT_IT_STS)
168 {
169 rvf_send_trace("IQ EXT: Power Off remote request",32, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID);
170
171 /* 'Remote Power' from ON to OFF */
172 Power_OFF_Remote();
173 }
174
175 else if (*read_value & ADCEND_IT_STS)
176 {
177 rvf_send_trace("IQ EXT: ADC End",15, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID);
178
179 /* ADC end of conversion */
180 ABB_Read_ADC(&SPI_GBL_INFO_PTR->adc_result[0]);
181 adc_msg = os_alloc_sig(sizeof(T_CST_ADC_RESULT));
182 if(adc_msg != NULL)
183 {
184 adc_msg->SignalCode = CST_ADC_RESULT;
185
186 for(i=0;i<MADC_NUMBER_OF_MEAS;i++)
187 {
188 ((T_CST_ADC_RESULT *)(adc_msg->SigP))->adc_result[i] = SPI_GBL_INFO_PTR->adc_result[i];
189 }
190 os_send_sig(adc_msg, RRM1_QUEUE);
191 #if (defined(RVM_LCC_SWE) || defined(RVM_FCHG_SWE))
192 // Send ADC measurement to PWR (LCC) task
193 // NOTE that memory is allocated externally in the PWR task
194 if (rvf_get_buf(pwr_ctrl->prim_id, sizeof(struct pwr_adc_ind_s), (void *)&addr) == RVF_RED) {
195 rvf_send_trace("rvf_get_buf failed",18, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID);
196 /* Unmask External interrupt */
197 IQ_Unmask(IQ_EXT);
198 // rvf_dump_mem();
199 return;
200 }
201 addr->header.msg_id = PWR_ADC_IND;
202 addr->header.src_addr_id = SPI_GBL_INFO_PTR->addr_id;
203 addr->header.dest_addr_id = pwr_ctrl->addr_id;
204 addr->header.callback_func = NULL;
205 // FIXME: memcpy from SPI_GBL_INFO_PTR->adc_result - make sure it has not been de-allocated
206 memcpy(addr->data, SPI_GBL_INFO_PTR->adc_result, 8*2);
207 addr->data[9] = ABB_Read_Status();; // Read & assign ITSTATREG status so we save the polling in PWR task!!
208 if (rvf_send_msg(pwr_ctrl->addr_id, addr) != RV_OK) {
209 rvf_send_trace("SPI FATAL: Send failed!",23, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID);
210 }
211 #endif
212 }
213 }
214
215 #if (defined(RVM_PWR_SWE) || defined(RVM_LCC_SWE) || defined(RVM_FCHG_SWE))
216 else if (*read_value & CHARGER_IT_STS)
217 {
218 /* Charger plug IN or OUT */
219 #if ((ANLG_FAM == 1) || (ANLG_FAM == 2))
220 status_value = ABB_Read_Status();
221 #elif (ANLG_FAM == 3)
222 status_value = ABB_Read_Register_on_page(PAGE1, VRPCCFG);
223 #endif
224 if (status_value & CHGPRES)
225 {
226 rvf_send_trace("IQ EXT: Charger Plug",20, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID);
227 #ifdef RVM_PWR_SWE
228 PWR_Charger_Plug(); /* charger plugged IN */
229 #endif
230 #if (defined(RVM_LCC_SWE) || defined(RVM_FCHG_SWE))
231 // Forward charger plug indication to PWR (LCC) task
232 // NOTE that memory is allocated externally in the PWR task
233 if (rvf_get_buf(pwr_ctrl->prim_id, sizeof(struct pwr_req_s), (void *)&addr) == RVF_RED) {
234 rvf_send_trace("rvf_get_buf failed#1",20, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID);
235 rvf_dump_mem();
236 }
237 addr->header.msg_id = PWR_CHARGER_PLUGGED_IND;
238 addr->header.src_addr_id = SPI_GBL_INFO_PTR->addr_id;
239 addr->header.dest_addr_id = pwr_ctrl->addr_id;
240 addr->header.callback_func = NULL;
241 if (rvf_send_msg(pwr_ctrl->addr_id, addr) != RV_OK) {
242 rvf_send_trace("SPI FATAL: Send failed!",23, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID);
243 }
244 #endif
245 }
246 else
247 {
248 rvf_send_trace("IQ EXT: Charger Unplug",22, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID);
249
250 #ifdef RVM_PWR_SWE
251 PWR_Charger_Unplug(); /* charger plugged OUT */
252 #endif
253 #if (defined(RVM_LCC_SWE) || defined(RVM_FCHG_SWE))
254 // Forward charger unplug indication to PWR (LCC) task
255 // NOTE that memory is allocated externally in the PWR task
256 if (rvf_get_buf(pwr_ctrl->prim_id, sizeof(struct pwr_req_s), (void *)&addr) == RVF_RED) {
257 rvf_send_trace("rvf_get_buf failed#2",20, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID);
258 rvf_dump_mem();
259 }
260 addr->header.msg_id = PWR_CHARGER_UNPLUGGED_IND;
261 addr->header.src_addr_id = SPI_GBL_INFO_PTR->addr_id;
262 addr->header.dest_addr_id = pwr_ctrl->addr_id;
263 addr->header.callback_func = NULL;
264 if (rvf_send_msg(pwr_ctrl->addr_id, addr) != RV_OK) {
265 rvf_send_trace("SPI FATAL: Send failed!",23, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID);
266 }
267 #endif
268 }
269 }
270
271 #endif /* RVM_PWR_SWE || RVM_LCC_SWE */
272
273 /* Unmask External interrupt */
274 #if (CHIPSET == 12)
275 // Unmask ABB ext interrupt
276 F_INTH_ENABLE_ONE_IT(C_INTH_ABB_IRQ_IT);
277 #else
278 // Unmask external (ABB) interrupt
279 IQ_Unmask(IQ_EXT);
280 #endif
281 }