FreeCalypso > hg > fc-tourmaline
comparison src/cs/drivers/drv_app/pwr/pwr_env.c @ 0:4e78acac3d88
src/{condat,cs,gpf,nucleus}: import from Selenite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 16 Oct 2020 06:23:26 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4e78acac3d88 |
---|---|
1 /*****************************************************************************/ | |
2 /* */ | |
3 /* File Name: pwr_env.c */ | |
4 /* */ | |
5 /* Purpose: This file contains definitions for RV manager related */ | |
6 /* functions used to get info, start and stop the PWR SWE. */ | |
7 /* */ | |
8 /* Version 0.1 */ | |
9 /* */ | |
10 /* Date Modification */ | |
11 /* ------------------------------------ */ | |
12 /* 20/08/2000 Create */ | |
13 /* */ | |
14 /* Author Candice Bazanegue (c-brille@ti.com) */ | |
15 /* */ | |
16 /* (C) Copyright 2000 by Texas Instruments Incorporated, All Rights Reserved */ | |
17 /*****************************************************************************/ | |
18 | |
19 #include "rv/rv_defined_swe.h" // for RVM_PWR_SWE | |
20 | |
21 #ifdef RVM_PWR_SWE | |
22 | |
23 #include "rvm/rvm_priorities.h" | |
24 #include "rvm/rvm_api.h" | |
25 #include "pwr/pwr_env.h" | |
26 #include "spi/spi_env.h" | |
27 #include "pwr/pwr_cust.h" | |
28 #include "pwr/pwr_analog_dev.h" | |
29 #include "rvm/rvm_use_id_list.h" | |
30 #include <string.h> | |
31 | |
32 /* Define a pointer to the PWR environment control block */ | |
33 T_PWR_ENV_CTRL_BLK *pwr_env_ctrl_blk = NULL; | |
34 | |
35 /* Define global pointer to the error function */ | |
36 static T_RVM_RETURN (*pwr_error_ft) (T_RVM_NAME swe_name, | |
37 T_RVM_RETURN error_cause, | |
38 T_RVM_ERROR_TYPE error_type, | |
39 T_RVM_STRING error_msg); | |
40 | |
41 | |
42 /****************************************************************************** | |
43 * Function name: pwr_get_info | |
44 * | |
45 * Description : Generic PWR get info function : provide general information | |
46 * regarding the PWR SWE to the Riviera Manager | |
47 * For more details, see Riviera Manager documentation | |
48 * | |
49 * Parameters : Pointer on the info structure | |
50 * | |
51 * Return : Always OK | |
52 * | |
53 * History : | |
54 * | |
55 ******************************************************************************/ | |
56 T_RVM_RETURN pwr_get_info (T_RVM_INFO_SWE *infoSWE) | |
57 { | |
58 /* SWE info */ | |
59 infoSWE->swe_type = RVM_SWE_TYPE_1; | |
60 infoSWE->type_info.type1.swe_use_id = PWR_USE_ID; | |
61 | |
62 memcpy( infoSWE->type_info.type1.swe_name, "PWR", sizeof("PWR") ); | |
63 | |
64 /* Set the return path */ | |
65 infoSWE->type_info.type1.return_path.callback_func = NULL; | |
66 infoSWE->type_info.type1.return_path.addr_id = 0; | |
67 | |
68 | |
69 /* memory bank info */ | |
70 infoSWE->type_info.type1.nb_mem_bank = 1; | |
71 | |
72 memcpy ((UINT8 *) infoSWE->type_info.type1.mem_bank[0].bank_name, "PWR_PRIM", 9); | |
73 infoSWE->type_info.type1.mem_bank[0].initial_params.size = PWR_MB_PRIM_SIZE; | |
74 infoSWE->type_info.type1.mem_bank[0].initial_params.watermark = PWR_MB_PRIM_WATERMARK; | |
75 | |
76 | |
77 /* Linked SW entities : PWR needs SPI */ | |
78 infoSWE->type_info.type1.nb_linked_swe = 1; | |
79 infoSWE->type_info.type1.linked_swe_id[0] = SPI_USE_ID; | |
80 | |
81 /* generic functions */ | |
82 infoSWE->type_info.type1.set_info = pwr_set_info; | |
83 infoSWE->type_info.type1.init = pwr_init; | |
84 infoSWE->type_info.type1.start = pwr_start; | |
85 infoSWE->type_info.type1.stop = pwr_stop; | |
86 infoSWE->type_info.type1.kill = pwr_kill; | |
87 | |
88 return RV_OK; | |
89 } | |
90 | |
91 | |
92 /****************************************************************************** | |
93 * Function : pwr_set_info | |
94 * | |
95 * Description : This function is called by the RV manager to inform | |
96 * the pwr SWE about task_id, mb_id and error function. | |
97 * | |
98 * Parameters : - T_RVM_TASK_ID taskId[]: array of task_id. | |
99 * taskId[0] contains pwr task_id. | |
100 * - T_RVF_MB_ID mbId[]: array of memory bank ids. | |
101 * - callback function to call in case of unrecoverable error. | |
102 * | |
103 * Return : T_RVM_RETURN | |
104 * | |
105 * History : | |
106 * | |
107 * | |
108 ******************************************************************************/ | |
109 T_RVM_RETURN pwr_set_info(T_RVF_ADDR_ID addr_id, | |
110 T_RV_RETURN return_path[], | |
111 T_RVF_MB_ID mbId[], | |
112 T_RVM_RETURN (*callBackFct) (T_RVM_NAME SWEntName, | |
113 T_RVM_RETURN errorCause, | |
114 T_RVM_ERROR_TYPE errorType, | |
115 T_RVM_STRING errorMsg)) | |
116 { | |
117 T_RVF_MB_STATUS mb_status; | |
118 | |
119 | |
120 rvf_send_trace("PWR: pwr_set_info: try to init GLOBAL INFO PWR structure ...",60, | |
121 NULL_PARAM, | |
122 RV_TRACE_LEVEL_DEBUG_HIGH, | |
123 PWR_USE_ID); | |
124 | |
125 mb_status = rvf_get_buf(mbId[0],sizeof(T_PWR_ENV_CTRL_BLK),(void **) &pwr_env_ctrl_blk); | |
126 | |
127 if (mb_status == RVF_RED) | |
128 { | |
129 rvf_send_trace("PWR : pwr_set_info: Not enough memory to initiate GLOBAL INFO PWR structure ... ",86, | |
130 NULL_PARAM, | |
131 RV_TRACE_LEVEL_ERROR, | |
132 PWR_USE_ID); | |
133 | |
134 return (RVM_MEMORY_ERR); | |
135 } | |
136 | |
137 | |
138 /* store the pointer to the error function */ | |
139 pwr_error_ft = callBackFct ; | |
140 | |
141 /* Store the addr id */ | |
142 /* Same task id than SPI but different mailbox */ | |
143 pwr_env_ctrl_blk->addr_id = SPI_GBL_INFO_PTR->addr_id; | |
144 | |
145 pwr_env_ctrl_blk->prim_id = mbId[0]; | |
146 | |
147 pwr_env_ctrl_blk->charging_state = CHARGE_STOPPED; | |
148 pwr_env_ctrl_blk->madc_eoc_current_code = (UINT16)(1000 * END_OF_CHARGE_I / MADC_CURRENT_STEP); /* modified after i2v calibration */ | |
149 pwr_env_ctrl_blk->max_voltage_code = (UINT16)(1000 * ((END_OF_CHARGE_V + MADC_OFFSET)/4) / MADC_VOLTAGE_STEP); | |
150 | |
151 pwr_env_ctrl_blk->power_info.info_enable = FALSE; | |
152 /* initalize the return path */ | |
153 pwr_env_ctrl_blk->power_info.return_path.addr_id = RVF_INVALID_ADDR_ID; | |
154 pwr_env_ctrl_blk->power_info.return_path.callback_func = NULL; | |
155 pwr_env_ctrl_blk->power_alert.remain_capa_threshold =0x0A; | |
156 /* initalize the return path */ | |
157 pwr_env_ctrl_blk->power_alert.return_path.addr_id = RVF_INVALID_ADDR_ID; | |
158 pwr_env_ctrl_blk->power_alert.return_path.callback_func = NULL; | |
159 /* initalize the return path */ | |
160 pwr_env_ctrl_blk->power_emergency.addr_id = RVF_INVALID_ADDR_ID; | |
161 pwr_env_ctrl_blk->power_emergency.callback_func = NULL; | |
162 | |
163 pwr_env_ctrl_blk->bat_celsius_temp = 0; | |
164 pwr_env_ctrl_blk->timer0_state = BATTERY_SHORT_TEST; | |
165 | |
166 return RV_OK; | |
167 } | |
168 | |
169 | |
170 /****************************************************************************** | |
171 * Function : pwr_init | |
172 * | |
173 * Description : This function is called by the RV manager to initialize the | |
174 * pwr SWE before creating the task and calling pwr_start. | |
175 * | |
176 * Parameters : None | |
177 * | |
178 * Return : T_RVM_RETURN | |
179 * | |
180 * History : | |
181 * | |
182 * | |
183 ******************************************************************************/ | |
184 T_RVM_RETURN pwr_init(void) | |
185 { | |
186 return RV_OK; | |
187 } | |
188 | |
189 | |
190 | |
191 /****************************************************************************** | |
192 * Function : pwr_start | |
193 * | |
194 * Description : This function is called by the RV manager to start the pwr | |
195 * SWE, it is the body of the task. | |
196 * | |
197 * Parameters : None | |
198 * | |
199 * Return : T_RVM_RETURN | |
200 * | |
201 * History : | |
202 * | |
203 * | |
204 ******************************************************************************/ | |
205 T_RVM_RETURN pwr_start(void) | |
206 { | |
207 return RV_OK; | |
208 } | |
209 | |
210 | |
211 /****************************************************************************** | |
212 * Function : pwr_stop | |
213 * | |
214 * Description : This function is called by the RV manager to stop the pwr SWE. | |
215 * | |
216 * Parameters : None | |
217 * | |
218 * Return : T_RVM_RETURN | |
219 * | |
220 * History : | |
221 * | |
222 * | |
223 ******************************************************************************/ | |
224 T_RVM_RETURN pwr_stop(void) | |
225 { | |
226 return RV_OK; | |
227 } | |
228 | |
229 | |
230 /****************************************************************************** | |
231 * Function : pwr_kill | |
232 * | |
233 * Description : This function is called by the RV manager to kill the pwr | |
234 * SWE, after the pwr_stop function has been called. | |
235 * | |
236 * Parameters : None | |
237 * | |
238 * Return : T_RVM_RETURN | |
239 * | |
240 * History : | |
241 * | |
242 * | |
243 ******************************************************************************/ | |
244 T_RVM_RETURN pwr_kill (void) | |
245 { | |
246 /* free all memory buffer previously allocated */ | |
247 rvf_free_buf ((void *) pwr_env_ctrl_blk); | |
248 | |
249 return RV_OK; | |
250 } | |
251 | |
252 #endif /* #ifdef RVM_PWR_SWE */ | |
253 |