rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2018 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /******************************************************************************* |
| 37 | * Filename: |
| 38 | * --------- |
| 39 | * mcf_task.c |
| 40 | * |
| 41 | * Project: |
| 42 | * -------- |
| 43 | * UMOLYA |
| 44 | * |
| 45 | * Description: |
| 46 | * ------------ |
| 47 | * MD Configuration Framework task implementation. |
| 48 | * |
| 49 | * Author: |
| 50 | * ------- |
| 51 | * ------- |
| 52 | * |
| 53 | *============================================================================== |
| 54 | * HISTORY |
| 55 | * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 56 | *------------------------------------------------------------------------------ |
| 57 | * removed! |
| 58 | * |
| 59 | * removed! |
| 60 | * removed! |
| 61 | * removed! |
| 62 | * removed! |
| 63 | * |
| 64 | * removed! |
| 65 | * removed! |
| 66 | * removed! |
| 67 | * removed! |
| 68 | * |
| 69 | * removed! |
| 70 | * removed! |
| 71 | * removed! |
| 72 | * removed! |
| 73 | * |
| 74 | * removed! |
| 75 | * removed! |
| 76 | * removed! |
| 77 | * |
| 78 | * removed! |
| 79 | * removed! |
| 80 | * removed! |
| 81 | * removed! |
| 82 | * |
| 83 | * removed! |
| 84 | * removed! |
| 85 | * removed! |
| 86 | * removed! |
| 87 | * |
| 88 | * removed! |
| 89 | * removed! |
| 90 | * removed! |
| 91 | * |
| 92 | * removed! |
| 93 | * removed! |
| 94 | * removed! |
| 95 | * |
| 96 | * removed! |
| 97 | * removed! |
| 98 | * removed! |
| 99 | * |
| 100 | * removed! |
| 101 | * removed! |
| 102 | * removed! |
| 103 | * |
| 104 | * removed! |
| 105 | * |
| 106 | * removed! |
| 107 | * removed! |
| 108 | * removed! |
| 109 | * |
| 110 | * removed! |
| 111 | * removed! |
| 112 | * removed! |
| 113 | * |
| 114 | * removed! |
| 115 | * removed! |
| 116 | * removed! |
| 117 | * |
| 118 | * removed! |
| 119 | * removed! |
| 120 | * removed! |
| 121 | * |
| 122 | * removed! |
| 123 | * removed! |
| 124 | * removed! |
| 125 | * removed! |
| 126 | * |
| 127 | * removed! |
| 128 | * removed! |
| 129 | * removed! |
| 130 | * removed! |
| 131 | * |
| 132 | * removed! |
| 133 | * removed! |
| 134 | * removed! |
| 135 | * |
| 136 | * removed! |
| 137 | * removed! |
| 138 | * removed! |
| 139 | * |
| 140 | *------------------------------------------------------------------------------ |
| 141 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 142 | *============================================================================== |
| 143 | *******************************************************************************/ |
| 144 | |
| 145 | #include "kal_public_api.h" |
| 146 | #include "syscomp_config.h" |
| 147 | #include "nvram_interface.h" |
| 148 | |
| 149 | #include "mcf_if.h" |
| 150 | #include "mcf_util.h" |
| 151 | #include "mcf_defs.h" |
| 152 | #include "mcf_object.h" |
| 153 | #include "mcf_debug.h" |
| 154 | |
| 155 | /*------------------------------------------------------------------------------ |
| 156 | * Global variables. |
| 157 | *----------------------------------------------------------------------------*/ |
| 158 | extern nvram_ltable_entry_struct logical_data_item_table_mcf[]; |
| 159 | |
| 160 | /*------------------------------------------------------------------------------ |
| 161 | * Helper macro. |
| 162 | *----------------------------------------------------------------------------*/ |
| 163 | |
| 164 | /*------------------------------------------------------------------------------ |
| 165 | * Private data structure. |
| 166 | *----------------------------------------------------------------------------*/ |
| 167 | |
| 168 | /*------------------------------------------------------------------------------ |
| 169 | * Private variables. |
| 170 | *----------------------------------------------------------------------------*/ |
| 171 | |
| 172 | /*------------------------------------------------------------------------------ |
| 173 | * Private fucntions. |
| 174 | *----------------------------------------------------------------------------*/ |
| 175 | static void mcf_dump_boot_trace_timeout(void *event_hf_param) |
| 176 | { |
| 177 | if (mcf_timer_eventid_g != NULL) { |
| 178 | mcf_timer_eventid_g = NULL; |
| 179 | } |
| 180 | |
| 181 | mcf_dump_boot_trace(); |
| 182 | } |
| 183 | |
| 184 | static void mcf_dump_important_info_timeout(void *event_hf_param) |
| 185 | { |
| 186 | if (mcf_timer_eventid_g != NULL) { |
| 187 | mcf_timer_eventid_g = NULL; |
| 188 | } |
| 189 | |
| 190 | mcf_dump_important_info(); |
| 191 | |
| 192 | mcf_timer_eventid_g = evshed_set_event_userid(mcf_timer_es_g, |
| 193 | mcf_dump_important_info_timeout, |
| 194 | NULL, KAL_TICKS_5_SEC_REAL * 6, |
| 195 | 2); |
| 196 | ASSERT(mcf_timer_eventid_g); |
| 197 | } |
| 198 | |
| 199 | static void mcf_task_main(task_entry_struct *task_entry_ptr) |
| 200 | { |
| 201 | ilm_struct current_ilm; |
| 202 | |
| 203 | kal_set_active_module_id(MOD_MCF); |
| 204 | kal_mem_set(¤t_ilm, 0, sizeof(ilm_struct)); |
| 205 | MCF_BOOT_TRACE(MCF_BOOT_TR_TASK_MAIN_OTA_DURATION, com_Mcf.ota_api_duration); |
| 206 | |
| 207 | mcf_timer_eventid_g = evshed_set_event_userid(mcf_timer_es_g, |
| 208 | mcf_dump_boot_trace_timeout, |
| 209 | NULL, KAL_TICKS_5_SEC_REAL * 2, |
| 210 | 1); |
| 211 | |
| 212 | mcf_timer_eventid_g = evshed_set_event_userid(mcf_timer_es_g, |
| 213 | mcf_dump_important_info_timeout, |
| 214 | NULL, KAL_TICKS_5_SEC_REAL * 6, |
| 215 | 2); |
| 216 | |
| 217 | ASSERT(mcf_timer_eventid_g); |
| 218 | |
| 219 | while(1) { |
| 220 | if (KAL_TRUE == msg_receive_extq(¤t_ilm)) { |
| 221 | mcf_on_ilm(¤t_ilm); |
| 222 | destroy_ilm(¤t_ilm); |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | static kal_bool mcf_init(void) |
| 228 | { |
| 229 | mcf_t *pMcf; |
| 230 | mcf_ota_file_t *ota_file; |
| 231 | mcf_tlvota_file_t *tlvota_file; |
| 232 | kal_uint32 i; |
| 233 | |
| 234 | /* Register MCF nvram LID table */ |
| 235 | nvram_ltable_register(logical_data_item_table_mcf); |
| 236 | |
| 237 | pMcf = mcf_get_instance(); |
| 238 | ota_file = &(pMcf->ota_file); |
| 239 | kal_mem_set(pMcf, 0, sizeof(mcf_t)); |
| 240 | kal_mem_set(&com_Mcf, 0, sizeof(mcf_common_t)); |
| 241 | |
| 242 | /* enh_mutex init */ |
| 243 | ASSERT(!mcf_enhmutex_g); |
| 244 | mcf_enhmutex_g = kal_create_enh_mutex(MCF_LOCK_NAME); |
| 245 | |
| 246 | /* Object init */ |
| 247 | MCF_INIT_OBJECT_BEGIN(ota_file, mcf_enhmutex_g); |
| 248 | MCF_INIT_OBJECT_END(ota_file, mcf_enhmutex_g); |
| 249 | |
| 250 | for (i = 0; i < MAX_SIM_NUM; i++) { |
| 251 | tlvota_file = &(pMcf->tlvota_file[i]); |
| 252 | tlvota_file->sbp_id = SBP_ID_INVALID; |
| 253 | MCF_INIT_OBJECT_BEGIN(tlvota_file, mcf_enhmutex_g); |
| 254 | MCF_INIT_OBJECT_END(tlvota_file, mcf_enhmutex_g); |
| 255 | } |
| 256 | |
| 257 | tlvota_file = &(pMcf->general_tlvota_file); |
| 258 | MCF_INIT_OBJECT_BEGIN(tlvota_file, mcf_enhmutex_g); |
| 259 | MCF_INIT_OBJECT_END(tlvota_file, mcf_enhmutex_g); |
| 260 | |
| 261 | #if defined(__MCF_UT_FRAMEWORK_SUPPORT__) |
| 262 | /* enh_mutex init */ |
| 263 | ASSERT(!mcf_utfwk_enhmutex_g); |
| 264 | mcf_utfwk_enhmutex_g = kal_create_enh_mutex(MCF_UTFWK_LOCK_NAME); |
| 265 | #endif |
| 266 | /* Timer init */ |
| 267 | mcf_timer_es_g = evshed_create("MCF_TIMER", MOD_MCF, 0, MAX_DELAY_UNLIMITED); |
| 268 | |
| 269 | if (mcf_timer_es_g == NULL) { |
| 270 | ASSERT(KAL_FALSE); |
| 271 | } |
| 272 | |
| 273 | /* Init boot trace buff ptr */ |
| 274 | com_Mcf.boot_trace_buff_ptr = (kal_uint32 *)com_Mcf.boot_trace_buff; |
| 275 | |
| 276 | return KAL_TRUE; |
| 277 | } |
| 278 | |
| 279 | static kal_bool mcf_reset(void) |
| 280 | { |
| 281 | mcf_t *pMcf; |
| 282 | mcf_ota_file_t *ota_file; |
| 283 | mcf_tlvota_file_t *tlvota_file; |
| 284 | kal_uint32 i; |
| 285 | |
| 286 | pMcf = mcf_get_instance(); |
| 287 | ota_file = &(pMcf->ota_file); |
| 288 | |
| 289 | /* Cancel Event */ |
| 290 | if (mcf_timer_eventid_g != NULL) { |
| 291 | evshed_cancel_event(mcf_timer_es_g, &mcf_timer_eventid_g); |
| 292 | } |
| 293 | |
| 294 | /* Object deinit */ |
| 295 | MCF_DEINIT_OBJECT_BEGIN(ota_file, mcf_enhmutex_g); |
| 296 | MCF_DEINIT_OBJECT_END(ota_file, mcf_enhmutex_g); |
| 297 | |
| 298 | for (i = 0; i < MAX_SIM_NUM; i++) { |
| 299 | tlvota_file = &(pMcf->tlvota_file[i]); |
| 300 | MCF_DEINIT_OBJECT_BEGIN(tlvota_file, mcf_enhmutex_g); |
| 301 | MCF_DEINIT_OBJECT_END(tlvota_file, mcf_enhmutex_g); |
| 302 | } |
| 303 | |
| 304 | kal_mem_set(pMcf, 0, sizeof(mcf_t)); |
| 305 | |
| 306 | /* Object init */ |
| 307 | MCF_INIT_OBJECT_BEGIN(ota_file, mcf_enhmutex_g); |
| 308 | MCF_INIT_OBJECT_END(ota_file, mcf_enhmutex_g); |
| 309 | |
| 310 | for (i = 0; i < MAX_SIM_NUM; i++) { |
| 311 | tlvota_file = &(pMcf->tlvota_file[i]); |
| 312 | tlvota_file->sbp_id = SBP_ID_INVALID; |
| 313 | MCF_INIT_OBJECT_BEGIN(tlvota_file, mcf_enhmutex_g); |
| 314 | MCF_INIT_OBJECT_END(tlvota_file, mcf_enhmutex_g); |
| 315 | } |
| 316 | |
| 317 | return KAL_TRUE; |
| 318 | } |
| 319 | |
| 320 | /*------------------------------------------------------------------------------ |
| 321 | * Public fucntions. |
| 322 | *----------------------------------------------------------------------------*/ |
| 323 | kal_bool mcf_create(comptask_handler_struct **handle) |
| 324 | { |
| 325 | static const comptask_handler_struct info = |
| 326 | { |
| 327 | mcf_task_main, /* task entry function */ |
| 328 | mcf_init, /* task initialization function */ |
| 329 | mcf_reset, /* task reset handler */ |
| 330 | }; |
| 331 | |
| 332 | *handle = (comptask_handler_struct *)&info; |
| 333 | return KAL_TRUE; |
| 334 | } |
| 335 | |