comparison src/cs/drivers/drv_app/lcc/lcc_env.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
comparison
equal deleted inserted replaced
-1:000000000000 0:b6a5e36de839
1 /******************************************************************************
2 * Power Task (pwr)
3 * Design and coding by Svend Kristian Lindholm, skl@ti.com
4 *
5 * Environment (Riviera) functions
6 *
7 * $Id: pwr_env.c 1.2 Wed, 20 Aug 2003 12:54:50 +0200 skl $
8 *
9 ******************************************************************************/
10
11 #include "lcc/lcc.h"
12 #include "lcc/lcc_env.h"
13 #include "lcc/lcc_task.h"
14 #include "lcc/lcc_trace.h"
15 #include "lcc/lcc_handle_timers.h"
16
17 #include "rv/rv_defined_swe.h"
18 #include "rvm/rvm_priorities.h"
19 #include "rvm/rvm_api.h"
20 #include "rvm/rvm_use_id_list.h"
21
22 #include <string.h>
23 #include "abb/abb.h"
24
25 /* Define a pointer to the PWR environment control block */
26 T_PWR_CTRL_BLOCK *pwr_ctrl = NULL;
27
28 /* Define a pointer to the PWR configuration block */
29 T_PWR_CFG_BLOCK *pwr_cfg = NULL;
30
31 // Function Prototypes
32 T_RVM_RETURN pwr_init(void);
33 T_RVM_RETURN pwr_start(void);
34 T_RVM_RETURN pwr_stop(T_RV_HDR *msg);
35 T_RVM_RETURN pwr_kill (void);
36
37 void ttr(unsigned trmask, char *format, ...);
38 void str(unsigned mask, char *string);
39
40
41 T_RVM_RETURN pwr_task_init (void);
42
43 /* Define global pointer to the error function */
44 static T_RVM_RETURN (*pwr_error_ft) (T_RVM_NAME swe_name,
45 T_RVM_RETURN error_cause,
46 T_RVM_ERROR_TYPE error_type,
47 T_RVM_STRING error_msg);
48
49 // Handle timers
50 #include "lcc/lcc_handle_timers.c"
51
52 T_RVM_RETURN lcc_get_info (T_RVM_INFO_SWE *infoSWE)
53 {
54 #if 1
55 ttw(ttr(TTrEnv, "lcc_get_info(%d):" NL, 0));
56 #endif
57 /* SWE info */
58
59 /* TYPE3 : Blocking by using FFS */
60 infoSWE->swe_type = RVM_SWE_TYPE_3;
61 infoSWE->type_info.type3.swe_use_id = LCC_USE_ID;
62 infoSWE->type_info.type3.stack_size = LCC_STACK_SIZE;
63 infoSWE->type_info.type3.priority = RVM_LCC_TASK_PRIORITY;
64 infoSWE->type_info.type3.version = LCC_TASK_VERSION;
65
66 memcpy( infoSWE->type_info.type3.swe_name, "LCC", sizeof("LCC") );
67
68 /* Set the return path */
69 infoSWE->type_info.type3.return_path.callback_func = NULL;
70 infoSWE->type_info.type3.return_path.addr_id = 0;
71
72 /* memory bank info */
73 infoSWE->type_info.type3.nb_mem_bank = 1;
74
75 memcpy ((UINT8 *) infoSWE->type_info.type3.mem_bank[0].bank_name, "LCC_PRIM", 9);
76 infoSWE->type_info.type3.mem_bank[0].initial_params.size = LCC_MB_PRIM_SIZE;
77 infoSWE->type_info.type3.mem_bank[0].initial_params.watermark = LCC_MB_PRIM_WATERMARK;
78
79 /* Linked SW entities : FIXME: LCC needs SPI & FFS */
80 infoSWE->type_info.type3.nb_linked_swe = 0;
81
82 /* generic functions */
83 infoSWE->type_info.type3.set_info = pwr_set_info;
84 infoSWE->type_info.type3.init = pwr_init;
85 infoSWE->type_info.type3.start = pwr_start;
86 infoSWE->type_info.type3.stop = pwr_stop;
87 infoSWE->type_info.type3.kill = pwr_kill;
88
89 return RV_OK;
90
91 }
92
93
94 T_RVM_RETURN pwr_set_info(T_RVF_ADDR_ID addr_id,
95 T_RV_RETURN return_path[],
96 T_RVF_MB_ID mbId[],
97 T_RVM_RETURN (*callBackFct) (T_RVM_NAME SWEntName,
98 T_RVM_RETURN errorCause,
99 T_RVM_ERROR_TYPE errorType,
100 T_RVM_STRING errorMsg))
101 {
102
103 T_RVF_MB_STATUS mb_status;
104
105 ttw(ttr(TTrEnv, "pwr_set_info(%d)" NL, addr_id));
106 ttw(ttr(TTrEnvLow, " mbId[0] = %d" NL, mbId[0]));
107
108 mb_status = rvf_get_buf(mbId[0],sizeof(T_PWR_CTRL_BLOCK),(void **) &pwr_ctrl);
109 if (mb_status == RVF_RED)
110 {
111 ttr(TTrFatal, "LCC FATAL: no memory: %d" NL, addr_id);
112 return (RVM_MEMORY_ERR);
113 }
114 memset(&pwr_ctrl->state, 0xBA, sizeof(T_PWR_CTRL_BLOCK));
115
116 mb_status = rvf_get_buf(mbId[0],sizeof(T_PWR_CFG_BLOCK),(void **) &pwr_cfg);
117 if (mb_status == RVF_RED)
118 {
119 ttr(TTrFatal, "LCC FATAL: no memory: %d" NL, addr_id);
120 return (RVM_MEMORY_ERR);
121 }
122 memset(&pwr_cfg->cal.i2v , 0xBA, sizeof(T_PWR_CFG_BLOCK));
123
124 /* store the pointer to the error function */
125 pwr_error_ft = callBackFct ;
126
127 /* Store the addr id */
128 pwr_ctrl->addr_id = addr_id;
129
130
131 /* Store the memory bank id */
132 pwr_ctrl->prim_id = mbId[0];
133
134 /* Battery & charging related initialisation */
135
136 // State initialisation
137 pwr_ctrl->state = CAL;
138
139 // Create timers (Initialize...)
140 pwr_create_timer(&pwr_ctrl->time_begin_T0);
141 pwr_create_timer(&pwr_ctrl->time_begin_T1);
142 pwr_create_timer(&pwr_ctrl->time_begin_T2);
143 pwr_create_timer(&pwr_ctrl->time_begin_T3);
144 pwr_create_timer(&pwr_ctrl->time_begin_T4);
145 pwr_create_timer(&pwr_ctrl->time_begin_mod_cycle);
146 pwr_create_timer(&pwr_ctrl->time_begin_mmi_rep);
147
148 /* Flags initialisation and other state related init */
149
150 // Calibration configuration file not read
151 pwr_ctrl->flag_cal_cfg_read = 0;
152
153 // Charger configuration file not read
154 pwr_ctrl->flag_chg_cfg_read = 0;
155
156 // Default configuration id used
157 pwr_cfg->data.cfg_id = '1';
158
159 // Number of battery identification measurements reported
160 pwr_ctrl->count_bat_type = 0;
161 pwr_ctrl->count_chg_type = 0;
162
163 // Precharge PRE state - Applies only for 3.2V < Vbat < 3.6V
164 pwr_ctrl->flag_prechg_started = 0;
165
166 // Charger Interrupts are disabled from the start
167 pwr_ctrl->flag_chg_int_disabled = 1;
168
169 // First time in INI state
170 pwr_ctrl->flag_ini_virgo = 0;
171
172 // Default charger type is UNREGULATED
173 // Meaning charger interrupts will not be enabled
174 pwr_cfg->chg.type = UNREGULATED;
175
176 // Unplug default is that charger is unplugged (0)
177 memset(&pwr_ctrl->chg_unplug_vec , 0x0, CONSECUTIVE_CHG_UNPLUGS);
178 pwr_ctrl->index = 0;
179
180
181 // MMI hasn't registered
182 pwr_ctrl->flag_mmi_registered = 0;
183
184 // Init of plug/unplug state machine - from default the charger is not plugged
185 pwr_ctrl->flag_chg_prev_plugged = 0;
186
187 return RV_OK;
188 }
189
190
191 T_RVM_RETURN pwr_init(void)
192 {
193 T_RVM_RETURN error;
194 // Mask off the charger interrupts (plug/unplug) - in case it was a linear charger
195 // Don't want to get killed in a vast number of interrupts...
196 ABB_Write_Register_on_page(PAGE0, ITMASK, CHARGER_IT_MSK);
197 pwr_ttr_init(0xff000000);
198 pwr_ctrl->tmask = 0xff000000;
199 ttw(ttr(TTrEnv, "pwr_init(%d)" NL, 0));
200 return RV_OK;
201 }
202
203 T_RVM_RETURN pwr_start(void)
204 {
205 T_RVM_RETURN error;
206 ttw(ttr(TTrEnv, "pwr_start(%d)" NL, 0));
207 pwr_task();
208 ttw(ttr(TTrEnv, "pwr_start(%d)" NL, 0xFF));
209 return RV_OK;
210 }
211
212 T_RVM_RETURN pwr_stop(T_RV_HDR *msg)
213 {
214 ttw(ttr(TTrEnv, "pwr_stop(%d)" NL, 0));
215 return RV_OK;
216 }
217
218 T_RVM_RETURN pwr_kill (void)
219 {
220 T_RVM_RETURN error;
221
222 ttw(ttr(TTrEnv, "pwr_kill(%d)" NL, 0));
223
224 /* free all memory buffer previously allocated */
225 rvf_free_buf ((void *) pwr_ctrl);
226 rvf_free_buf ((void *) pwr_cfg);
227 ttw(ttr(TTrEnv, "pwr_kill(%d)" NL, 0xFF));
228
229 return RV_OK;
230 }
231