FreeCalypso > hg > leo2moko-debug
comparison chipsetsw/drivers/drv_app/abb/board/abb_inth.c @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
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 | |
41 | |
42 #include "l1_macro.h" | |
43 #include "l1_confg.h" | |
44 #include <string.h> | |
45 #include "abb/abb_inth.h" | |
46 #include "nucleus.h" | |
47 | |
48 #include "rv/rv_defined_swe.h" // for RVM_PWR_SWE | |
49 | |
50 #if (CHIPSET == 12) | |
51 #include "sys_inth.h" | |
52 #else | |
53 #include "inth/iq.h" | |
54 #endif | |
55 | |
56 #include "cust_os.h" | |
57 #include "l1_signa.h" | |
58 #include "abb/abb.h" | |
59 | |
60 #if defined (OP_WCP) | |
61 #include "ffs/ffs.h" | |
62 #include "ffs/board/ffspcm.h" | |
63 #endif | |
64 | |
65 #include "rvm/rvm_use_id_list.h" // for SPI_USE_ID | |
66 #include "spi/spi_env.h" | |
67 #include "spi/spi_process.h" // for ABB_EXT_IRQ_EVT | |
68 #include "kpd/kpd_power_api.h" // for kpd_power_key_pressed() | |
69 #include "power/power.h" | |
70 | |
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 /* */ | |
80 /* Function Name: spi_abb_read_int_reg_callback */ | |
81 /* */ | |
82 /* Purpose: Callback function */ | |
83 /* Called when an external interrupt has occured and the */ | |
84 /* ABB interrupt register has been read. */ | |
85 /* */ | |
86 /********************************************************************************/ | |
87 void spi_abb_read_int_reg_callback(SYS_UWORD16 *read_value) | |
88 { | |
89 SYS_UWORD16 loop_count; | |
90 SYS_UWORD16 status_value; | |
91 xSignalHeaderRec *adc_msg; | |
92 volatile SYS_UWORD8 i; | |
93 | |
94 #ifdef RVM_LCC_SWE | |
95 struct pwr_adc_ind_s *addr; | |
96 extern T_PWR_CTRL_BLOCK *pwr_ctrl; | |
97 #endif | |
98 | |
99 | |
100 // check all the possible causes of the ABB IT | |
101 if (*read_value & PUSHOFF_IT_STS) | |
102 { | |
103 /* Push Button from ON to OFF */ | |
104 if (SPI_GBL_INFO_PTR->is_gsm_on == TRUE) | |
105 { | |
106 NU_Sleep(SHORT_OFF_KEY_PRESSED); | |
107 | |
108 // WCP Patch | |
109 #if (OP_WCP == 1) | |
110 // Backup of GSM FFS is remotely handled by MPU-S | |
111 // we trigger the backup upon each ON->OFF transition | |
112 ffs_backup (); | |
113 #else | |
114 /* Since this callback function is called from the SPI task | |
115 it can't be interrupted by another task | |
116 so we can directly access the SPI through the low-level driver */ | |
117 | |
118 #if ((ANLG_FAM == 1) || (ANLG_FAM == 2)) | |
119 status_value = (ABB_Read_Status() & ONREFLT); | |
120 #elif (ANLG_FAM == 3) | |
121 status_value = (ABB_Read_Register_on_page(PAGE1, VRPCCFG) & PWOND); | |
122 #endif | |
123 | |
124 if (status_value == PWR_OFF_KEY_PRESSED) | |
125 { | |
126 /* Inform keypad that key ON/OFF has been pressed */ | |
127 kpd_power_key_pressed(); | |
128 | |
129 loop_count = 0; | |
130 /* Wait loop for Power-OFF */ | |
131 while ((loop_count < OFF_LOOP_COUNT) && | |
132 (status_value == PWR_OFF_KEY_PRESSED)) | |
133 { | |
134 NU_Sleep(SHORT_OFF_KEY_PRESSED); | |
135 #if ((ANLG_FAM == 1) || (ANLG_FAM == 2)) | |
136 status_value = (ABB_Read_Status() & ONREFLT); | |
137 #elif (ANLG_FAM == 3) | |
138 status_value = (ABB_Read_Register_on_page(PAGE1, VRPCCFG) & PWOND); | |
139 #endif | |
140 loop_count++; | |
141 } | |
142 | |
143 if (status_value == PWR_OFF_KEY_PRESSED) /* Power-OFF request detected */ | |
144 { | |
145 rvf_send_trace("IQ EXT: Power Off request",25, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID); | |
146 | |
147 Power_OFF_Button(); | |
148 } | |
149 } | |
150 #endif //WCP | |
151 } | |
152 else /* GSM OFF */ | |
153 { | |
154 rvf_send_trace("IQ EXT: Power On request",24, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID); | |
155 | |
156 Power_ON_Button(); | |
157 } | |
158 } | |
159 | |
160 else if (*read_value & REMOT_IT_STS) | |
161 { | |
162 rvf_send_trace("IQ EXT: Power Off remote request",32, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID); | |
163 | |
164 /* 'Remote Power' from ON to OFF */ | |
165 Power_OFF_Remote(); | |
166 } | |
167 | |
168 else if (*read_value & ADCEND_IT_STS) | |
169 { | |
170 rvf_send_trace("IQ EXT: ADC End",15, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID); | |
171 | |
172 /* ADC end of conversion */ | |
173 ABB_Read_ADC(&SPI_GBL_INFO_PTR->adc_result[0]); | |
174 adc_msg = os_alloc_sig(sizeof(T_CST_ADC_RESULT)); | |
175 if(adc_msg != NULL) | |
176 { | |
177 adc_msg->SignalCode = CST_ADC_RESULT; | |
178 | |
179 for(i=0;i<MADC_NUMBER_OF_MEAS;i++) | |
180 { | |
181 ((T_CST_ADC_RESULT *)(adc_msg->SigP))->adc_result[i] = SPI_GBL_INFO_PTR->adc_result[i]; | |
182 } | |
183 os_send_sig(adc_msg, RRM1_QUEUE); | |
184 #ifdef RVM_LCC_SWE | |
185 // Send ADC measurement to PWR (LCC) task | |
186 // NOTE that memory is allocated externally in the PWR task | |
187 if (rvf_get_buf(pwr_ctrl->prim_id, sizeof(struct pwr_adc_ind_s), (void *)&addr) == RVF_RED) { | |
188 rvf_send_trace("rvf_get_buf failed",18, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID); | |
189 /* Unmask External interrupt */ | |
190 IQ_Unmask(IQ_EXT); | |
191 // rvf_dump_mem(); | |
192 return; | |
193 } | |
194 addr->header.msg_id = PWR_ADC_IND; | |
195 addr->header.src_addr_id = SPI_GBL_INFO_PTR->addr_id; | |
196 addr->header.dest_addr_id = pwr_ctrl->addr_id; | |
197 addr->header.callback_func = NULL; | |
198 // FIXME: memcpy from SPI_GBL_INFO_PTR->adc_result - make sure it has not been de-allocated | |
199 memcpy(addr->data, SPI_GBL_INFO_PTR->adc_result, 8*2); | |
200 addr->data[9] = ABB_Read_Status();; // Read & assign ITSTATREG status so we save the polling in PWR task!! | |
201 if (rvf_send_msg(pwr_ctrl->addr_id, addr) != RV_OK) { | |
202 rvf_send_trace("SPI FATAL: Send failed!",23, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID); | |
203 } | |
204 #endif | |
205 } | |
206 } | |
207 | |
208 #if (defined(RVM_PWR_SWE) || defined(RVM_LCC_SWE)) | |
209 else if (*read_value & CHARGER_IT_STS) | |
210 { | |
211 /* Charger plug IN or OUT */ | |
212 #if ((ANLG_FAM == 1) || (ANLG_FAM == 2)) | |
213 status_value = ABB_Read_Status(); | |
214 #elif (ANLG_FAM == 3) | |
215 status_value = ABB_Read_Register_on_page(PAGE1, VRPCCFG); | |
216 #endif | |
217 if (status_value & CHGPRES) | |
218 { | |
219 rvf_send_trace("IQ EXT: Charger Plug",20, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID); | |
220 #ifdef RVM_PWR_SWE | |
221 PWR_Charger_Plug(); /* charger plugged IN */ | |
222 #endif | |
223 #ifdef RVM_LCC_SWE | |
224 // Forward charger plug indication to PWR (LCC) task | |
225 // NOTE that memory is allocated externally in the PWR task | |
226 if (rvf_get_buf(pwr_ctrl->prim_id, sizeof(struct pwr_req_s), (void *)&addr) == RVF_RED) { | |
227 rvf_send_trace("rvf_get_buf failed#1",20, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID); | |
228 rvf_dump_mem(); | |
229 } | |
230 addr->header.msg_id = PWR_CHARGER_PLUGGED_IND; | |
231 addr->header.src_addr_id = SPI_GBL_INFO_PTR->addr_id; | |
232 addr->header.dest_addr_id = pwr_ctrl->addr_id; | |
233 addr->header.callback_func = NULL; | |
234 if (rvf_send_msg(pwr_ctrl->addr_id, addr) != RV_OK) { | |
235 rvf_send_trace("SPI FATAL: Send failed!",23, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID); | |
236 } | |
237 #endif | |
238 } | |
239 else | |
240 { | |
241 rvf_send_trace("IQ EXT: Charger Unplug",22, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID); | |
242 | |
243 #ifdef RVM_PWR_SWE | |
244 PWR_Charger_Unplug(); /* charger plugged OUT */ | |
245 #endif | |
246 #ifdef RVM_LCC_SWE | |
247 // Forward charger unplug indication to PWR (LCC) task | |
248 // NOTE that memory is allocated externally in the PWR task | |
249 if (rvf_get_buf(pwr_ctrl->prim_id, sizeof(struct pwr_req_s), (void *)&addr) == RVF_RED) { | |
250 rvf_send_trace("rvf_get_buf failed#2",20, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID); | |
251 rvf_dump_mem(); | |
252 } | |
253 addr->header.msg_id = PWR_CHARGER_UNPLUGGED_IND; | |
254 addr->header.src_addr_id = SPI_GBL_INFO_PTR->addr_id; | |
255 addr->header.dest_addr_id = pwr_ctrl->addr_id; | |
256 addr->header.callback_func = NULL; | |
257 if (rvf_send_msg(pwr_ctrl->addr_id, addr) != RV_OK) { | |
258 rvf_send_trace("SPI FATAL: Send failed!",23, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID); | |
259 } | |
260 #endif | |
261 } | |
262 } | |
263 | |
264 #endif /* RVM_PWR_SWE || RVM_LCC_SWE */ | |
265 | |
266 /* Unmask External interrupt */ | |
267 #if (CHIPSET == 12) | |
268 // Unmask ABB ext interrupt | |
269 F_INTH_ENABLE_ONE_IT(C_INTH_ABB_IRQ_IT); | |
270 #else | |
271 // Unmask external (ABB) interrupt | |
272 IQ_Unmask(IQ_EXT); | |
273 #endif | |
274 } |