148 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			148 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/****************************************************************************
 | 
						|
 | 
						|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | 
						|
 | 
						|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | 
						|
be copied by any method or incorporated into another program without
 | 
						|
the express written consent of Aerospace C.Power. This Information or any portion
 | 
						|
thereof remains the property of Aerospace C.Power. The Information contained herein
 | 
						|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | 
						|
liability for its use in any way and conveys no license or title under
 | 
						|
any patent or copyright and makes no representation or warranty that this
 | 
						|
Information is free from patent or copyright infringement.
 | 
						|
 | 
						|
****************************************************************************/
 | 
						|
/* os shim includes */
 | 
						|
#include "os_types.h"
 | 
						|
#include "os_task.h"
 | 
						|
#include "os_utils.h"
 | 
						|
 | 
						|
#include "system.h"
 | 
						|
 | 
						|
/* common includes */
 | 
						|
#include "iot_config.h"
 | 
						|
#include "iot_io.h"
 | 
						|
#include "iot_system.h"
 | 
						|
#include "iot_version.h"
 | 
						|
#include "iot_mtd.h"
 | 
						|
 | 
						|
#include "iot_board_api.h"
 | 
						|
#include "iot_gpio_api.h"
 | 
						|
 | 
						|
os_task_h _init_handle;
 | 
						|
extern uint32_t _sp;
 | 
						|
 | 
						|
/* working mode for fw
 | 
						|
 * 0 - Mission Mode
 | 
						|
 * 1 - FTM mode
 | 
						|
 */
 | 
						|
extern uint32_t g_fw_mode;
 | 
						|
 | 
						|
extern void iot_hw_init();
 | 
						|
extern void iot_sub_system_init();
 | 
						|
extern void proto_mm_init();
 | 
						|
extern void proto_ftm_init();
 | 
						|
extern void iot_mode_set(int fw_mode);
 | 
						|
 | 
						|
static void startup_mm_init()
 | 
						|
{
 | 
						|
    proto_mm_init();
 | 
						|
}
 | 
						|
 | 
						|
static void startup_ftm_init()
 | 
						|
{
 | 
						|
#if (BUILD_AMP_TYPE == IOT_BUILD_AMP_CUSTOM)
 | 
						|
    proto_mm_init();
 | 
						|
#else
 | 
						|
    proto_ftm_init();
 | 
						|
#endif
 | 
						|
}
 | 
						|
 | 
						|
void iot_startup_init_task(void *arg)
 | 
						|
{
 | 
						|
    uint8_t gpio_3v3;
 | 
						|
    uint8_t gpio_eth_rst;
 | 
						|
 | 
						|
    for (;;) {
 | 
						|
        /* sub system init */
 | 
						|
        iot_sub_system_init();
 | 
						|
 | 
						|
        /* open the 3v3 power for bluetooth, wifi, rtc and em_ext module */
 | 
						|
        gpio_3v3 = iot_board_get_gpio(GPIO_P3V3_EN);
 | 
						|
        if (gpio_3v3 != GPIO_INVALID) {
 | 
						|
            iot_gpio_open_as_output(gpio_3v3);
 | 
						|
            iot_gpio_value_set(gpio_3v3, 0);
 | 
						|
        }
 | 
						|
 | 
						|
        /* output high to reset of ethernet phy */
 | 
						|
        gpio_eth_rst = iot_board_get_gpio(GPIO_ETH_PHY_RESET);
 | 
						|
        if (gpio_eth_rst != GPIO_INVALID) {
 | 
						|
            iot_gpio_open_as_output(gpio_eth_rst);
 | 
						|
            iot_gpio_value_set(gpio_eth_rst, 1);
 | 
						|
        }
 | 
						|
 | 
						|
        if(g_fw_mode == MM_MODE){
 | 
						|
            //mm mode or mt mode
 | 
						|
            startup_mm_init();
 | 
						|
        } else {
 | 
						|
            //mp mode or ftm mode
 | 
						|
            startup_ftm_init();
 | 
						|
        }
 | 
						|
 | 
						|
        os_delete_task(_init_handle);
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
int32_t iot_startup_init()
 | 
						|
{
 | 
						|
    /* startup task */
 | 
						|
    _init_handle = os_create_task_ext(iot_startup_init_task, NULL,
 | 
						|
        IOT_INIT_TASK_PRIO, PLC_STARTUP_INIT_SIZE, __FUNCTION__);
 | 
						|
 | 
						|
    /* create the tasks */
 | 
						|
    if(_init_handle != NULL) {
 | 
						|
        iot_printf("init task create successfully...\n");
 | 
						|
    }
 | 
						|
 | 
						|
    return 0;
 | 
						|
}
 | 
						|
 | 
						|
int32_t iot_module_init(void)
 | 
						|
{
 | 
						|
    /* hardware init */
 | 
						|
    iot_hw_init();
 | 
						|
 | 
						|
    /* startup task init */
 | 
						|
    iot_startup_init();
 | 
						|
 | 
						|
    return 0;
 | 
						|
}
 | 
						|
 | 
						|
int32_t iot_module_start(void)
 | 
						|
{
 | 
						|
    os_start_kernel();
 | 
						|
 | 
						|
    return 0;
 | 
						|
}
 | 
						|
 | 
						|
uint32_t iot_plc_entry(iot_build_info_t *info)
 | 
						|
{
 | 
						|
    sbl_param_input_t param = {0};
 | 
						|
 | 
						|
    iot_system_get_fw_boot_param(¶m);
 | 
						|
 | 
						|
    iot_version_set_user_build_info(info);
 | 
						|
 | 
						|
    iot_mode_set(param.fw_mode);
 | 
						|
    mtd_set_flash_size(param.flash_size);
 | 
						|
    mtd_set_psram_state(param.run_in_psram);
 | 
						|
 | 
						|
    /* module init */
 | 
						|
    iot_module_init();
 | 
						|
 | 
						|
    /* module start */
 | 
						|
    iot_module_start();
 | 
						|
 | 
						|
    return -1;
 | 
						|
}
 |