rel_1.6.0 init

This commit is contained in:
guocheng.kgc 2020-06-18 20:06:52 +08:00 committed by shengdong.dsd
commit 27b3e2883d
19359 changed files with 8093121 additions and 0 deletions

View file

@ -0,0 +1,209 @@
#include <stdio.h>
#include "board.h"
#include "lega_cm4.h"
#include "lega_common.h"
#include "systick_delay.h"
#include "lega_uart.h"
#include "lega_wdg.h"
#include "lega_flash.h"
#include "lega_common.h"
#include "lega_wlan_api.h"
#define EFUSE_SEL 0xd6
#define SEL_VIRGIN 0x00
#define SEL_MAC1 0x01
#define SEL_MAC2 0x03
#define SYS_APP_VERSION_SEG __attribute__((section("app_version_sec")))
SYS_APP_VERSION_SEG const char app_version[] = SYSINFO_APP_VERSION;
extern hal_wifi_module_t sim_aos_wifi_lega;
extern void NVIC_init();
extern int soc_pre_init(void);
#ifdef ALIOS_SUPPORT
extern void ota_roll_back_pro(void);
#endif
static void efuse_read(uint8_t *data,uint8_t addr,uint8_t len)
{
for (int i = 0; i < len; i++)
{
data[i] = lega_efuse_byte_read(addr + i);
}
}
void efuse_info_update_cb(efuse_info_t *efuse_info)
{
printf("efuse_info_update\r\n");
if (lega_efuse_byte_read(EFUSE_SEL) == SEL_MAC1)
{
efuse_read(efuse_info->mac_addr2,0x90,6);
}else if(lega_efuse_byte_read(EFUSE_SEL) == SEL_MAC2)
{
efuse_read(efuse_info->mac_addr2,0xC8,6);
}else{
printf("empty mac\r\n");
}
efuse_read(&(efuse_info->freq_err),0x96,1);
efuse_read(&(efuse_info->tmmt1),0x97,1);
efuse_read(&(efuse_info->tmmt2),0x98,1);
efuse_read(efuse_info->cal_tx_pwr2,0xAC,6);
efuse_read(efuse_info->cal_tx_evm2,0xB5,6);
efuse_read(efuse_info->cus_tx_pwr,0x99,19);
efuse_read(efuse_info->cus_tx_total_pwr,0xB2,3);
}
static void wifi_common_init()
{
printf("start------wifi_hal\r\n");
lega_wlan_register_efuse_info_update_cb(efuse_info_update_cb);
hal_wifi_register_module(&sim_aos_wifi_lega);
hal_wifi_init();
}
/***********************************************************
* init IRQ, set priority and enable IRQ
*
**********************************************************/
void NVIC_init()
{
//set irq priority, default set configLIBRARY_NORMAL_INTERRUPT_PRIORITY
NVIC_SetPriority(UART0_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(UART1_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(UART2_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(CEVA_RW_IP_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(D_APLL_UNLOCK_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(D_SX_UNLOCK_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(SLEEP_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(WDG_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(FLASH_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(GPIO_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(TIMER_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(CRYPTOCELL310_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(DMA_CTRL_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(SPI0_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(SPI1_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(SPI2_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(I2C0_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(I2C1_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(SDIO_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
NVIC_SetPriority(PLF_WAKEUP_IRQn,configLIBRARY_NORMAL_INTERRUPT_PRIORITY);
}
#ifdef ALIOS_SUPPORT
uart_dev_t uart_0;
void hal_uart1_callback_handler(char ch);
#endif
void uart_init(void)
{
#ifdef ALIOS_SUPPORT
//uart_0.port=LEGA_UART1_INDEX;
uart_0.port = PORT_UART_STD; /*logic port*/
#ifdef HIGHFREQ_MCU160_SUPPORT
uart_0.config.baud_rate=UART_BAUDRATE_1000000;
#else
uart_0.config.baud_rate=UART_BAUDRATE_115200;
#endif
uart_0.config.data_width = DATA_8BIT;
uart_0.config.flow_control = FLOW_CTRL_DISABLED;
uart_0.config.parity = PARITY_NO;
uart_0.config.stop_bits = STOP_1BIT;
//uart_0.priv = (void *)(hal_uart1_callback_handler);
hal_uart_init(&uart_0);
#endif
}
#ifdef HIGHFREQ_MCU160_SUPPORT
//all peripheral reinit code should place here
void peripheral_reinit(void)
{
uart_init();
}
#endif
#ifdef SYSTEM_RECOVERY
lega_wdg_dev_t lega_wdg;
void wdg_init(void)
{
lega_wdg.port = 0;
lega_wdg.config.timeout = WDG_TIMEOUT_MS;
lega_wdg_init(&lega_wdg);
}
#endif
/***********************************************************
* init device, such as irq, system clock, uart
**********************************************************/
uint32_t system_bus_clk = SYSTEM_BUS_CLOCK_INIT;
uint32_t system_core_clk = SYSTEM_CORE_CLOCK_INIT;
void lega_devInit()
{
#ifdef _SPI_FLASH_ENABLE_
lega_flash_init();
#endif
#ifdef ALIOS_SUPPORT
ota_roll_back_pro();
#endif
#ifdef SYSTEM_RECOVERY
wdg_init();
#endif
NVIC_init();
#ifdef DCDC_PFMMODE_CLOSE
lega_drv_close_dcdc_pfm();
#endif
lega_drv_rco_cal();
SysTick_Config(SYSTEM_CORE_CLOCK/RHINO_CONFIG_TICKS_PER_SECOND);
//init uart
uart_init();
#ifdef CFG_MIMO_UF
//config to support smartconfig in MIMO scenario
//lega_wlan_smartconfig_mimo_enable();
#endif
#ifdef ALIOS_SUPPORT
hw_start_hal();
#endif
}
/**************************************************
* after task run use board_sys_init to init board
**************************************************/
int board_after_init(void)
{
lega_devInit();
//hw_start_hal();
//NVIC_init();
tcpip_init( NULL, NULL );
wifi_common_init();
//init_uwifi();
return 0;
}
/**************************************************
* before task run use board_sys_init to init board
**************************************************/
void board_init(void)
{
#ifdef LEGA_A0V1
// Clear RFA Only Mode
REG_PMU_CTRL &= ~ENABLE_RFA_DEBUG;
REG_WR(SYS_REG_BASE_FLASH_CLK, 0x01); //26MHz flash,default 13MHz
#endif
flash_partition_init();
}

View file

@ -0,0 +1,82 @@
/*
* Copyright (C) 2015-2019 Alibaba Group Holding Limited
*/
#include "aos/init.h"
#include "board.h"
#include <k_api.h>
#include <stdio.h>
#include <stdlib.h>
#include "lega_cm4.h"
#include "systick_delay.h"
/*
main task stask size(byte)
*/
#define OS_MAIN_TASK_STACK (4096/4)
#define OS_MAIN_TASK_PRI 32
/* For user config
kinit.argc = 0;
kinit.argv = NULL;
kinit.cli_enable = 1;
*/
static kinit_t kinit = {0, NULL, 1};
static ktask_t *g_main_task;
extern void board_init(void);
static void sys_init(void)
{
board_after_init();
/*aos components init including middleware and protocol and so on !*/
aos_kernel_init(&kinit);
}
void HCLK_SW_IRQHandler(void)
{
SYS_CRM_CLR_HCLK_REC = 0x1;
}
void delay_nop(unsigned int dly)
{
volatile unsigned int i;
for(i=dly; i>0; i--)
{
}
}
void ahb_sync_brid_open(void)
{
unsigned int is_using_sync_down = (REG_AHB_BUS_CTRL & (0x1<<1));
if(!is_using_sync_down)
{
REG_AHB_BUS_CTRL |= (0x1<<1); //0x40000A90 bit1 sw_use_hsync
__enable_irq();
NVIC_EnableIRQ(24);
__asm volatile("DSB");
__asm volatile("WFI");
__asm volatile("ISB");
delay_nop(50);
}
}
int main(void)
{
ahb_sync_brid_open();
lega_flash_alg_cache_flush();
board_init();
/*kernel init, malloc can use after this!*/
krhino_init();
/*main task to run */
krhino_task_dyn_create(&g_main_task, "main_task", 0, OS_MAIN_TASK_PRI, 0, OS_MAIN_TASK_STACK, (task_entry_t)sys_init, 1);
/*kernel start schedule!*/
krhino_start();
/*never run here*/
return 0;
}

View file

@ -0,0 +1,244 @@
/************************** startup_cm4.s **********************************************/
.syntax unified
.cpu cortex-m4
.fpu softvfp
.thumb
.global g_pfnVectors
.global Default_Handler
/* start address for the initialization values of the .data section.
defined in linker script */
.word _sidata
/* start address for the .data section. defined in linker script */
.word _sdata
/* end address for the .data section. defined in linker script */
.word _edata
/* start address for the .bss section. defined in linker script */
.word _sbss
/* end address for the .bss section. defined in linker script */
.word _ebss
/* stack used for SystemInit_ExtMemCtl; always internal RAM used */
/**
* @brief This is the code that gets called when the processor first
* starts execution following a reset event. Only the absolutely
* necessary set is performed, after which the application
* supplied main() routine is called.
* @param None
* @retval : None
*/
.section .text.Reset_Handler
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
ldr sp, =_estack /* set stack pointer */
/* Copy the data segment initializers from flash to SRAM */
movs r1, #0
b LoopCopyDataInit
CopyDataInit:
ldr r3, =_sidata
ldr r3, [r3, r1]
str r3, [r0, r1]
adds r1, r1, #4
LoopCopyDataInit:
ldr r0, =_sdata
ldr r3, =_edata
adds r2, r0, r1
cmp r2, r3
bcc CopyDataInit
ldr r2, =_sbss
b LoopFillZerobss
/* Zero fill the bss segment. */
FillZerobss:
movs r3, #0
str r3, [r2], #4
LoopFillZerobss:
ldr r3, = _ebss
cmp r2, r3
bcc FillZerobss
/* Call the clock system intitialization function.*/
bl SystemInit
/* Call static constructors */
/* bl __libc_init_array */
/* Call the application's entry point.*/
bl main
bx lr
.size Reset_Handler, .-Reset_Handler
/**
* @brief This is the code that gets called when the processor receives an
* unexpected interrupt. This simply enters an infinite loop, preserving
* the system state for examination by a debugger.
* @param None
* @retval None
*/
.section .text.Default_Handler,"ax",%progbits
Default_Handler:
Infinite_Loop:
b Infinite_Loop
.size Default_Handler, .-Default_Handler
/******************************************************************************
*
* The minimal vector table for a Cortex M3. Note that the proper constructs
* must be placed on this to ensure that it ends up at physical address
* 0x0000.0000.
*
*******************************************************************************/
.section .isr_vector,"a",%progbits
.type g_pfnVectors, %object
.size g_pfnVectors, .-g_pfnVectors
g_pfnVectors:
.word _estack
.word Reset_Handler
.word NMI_Handler
.word HardFault_Handler
.word MemManage_Handler
.word BusFault_Handler
.word UsageFault_Handler
.word 0
.word 0
.word 0
.word 0
.word SVC_Handler
.word DebugMon_Handler
.word 0
.word PendSV_Handler
.word SysTick_Handler
/* External Interrupts */
.word intc_irq /* intc_irq CEVA RW IP Interrupt */
.word SLEEP_IRQHandler /* Sleep Wake-Up Interrupt */
.word WDG_IRQHandler /* Window WatchDog */
.word FLASH_IRQHandler /* FLASH */
.word GPIO_IRQHandler /* GPIO */
.word TIMER_IRQHandler /* Timer interrupt */
.word CRYPTOCELL310_IRQHandler /* CryptoCell 310 Interrupt */
.word DMA_CTRL_IRQHandler /* Generic DMA Ctrl Interrupt */
.word UART0_IRQHandler /* UART0 Interrupt */
.word UART1_IRQHandler /* UART1 Interrupt */
.word UART2_IRQHandler /* UART2 Interrupt */
.word SPI0_IRQHandler /* SPI0 */
.word SPI1_IRQHandler /* SPI1 */
.word SPI2_IRQHandler /* SPI2 */
.word I2C0_IRQHandler /* I2C0 */
.word I2C1_IRQHandler /* I2C1 */
.word SDIO_IRQHandler /* SDIO Combined Interrupt */
.word D_APLL_UNLOCK_IRQHandler /* RF added: D_APLL_UNLOCK */
.word D_SX_UNLOCK_IRQHandler /* RF added: D_SX_UNLOCK */
.word 0x00000000
.word 0x00000000
.word 0x00000000
.word 0x00000000
.word PLATFORM_WAKEUP_IRQHandler /*!< WiFi SOC Wake-Up Interrupt */
.word HCLK_SW_IRQHandler
/*******************************************************************************
*
* Provide weak aliases for each Exception handler to the Default_Handler.
* As they are weak aliases, any function with the same name will override
* this definition.
*
*******************************************************************************/
.weak NMI_Handler
.thumb_set NMI_Handler,Default_Handler
.weak HardFault_Handler
.thumb_set HardFault_Handler,Default_Handler
.weak MemManage_Handler
.thumb_set MemManage_Handler,Default_Handler
.weak BusFault_Handler
.thumb_set BusFault_Handler,Default_Handler
.weak UsageFault_Handler
.thumb_set UsageFault_Handler,Default_Handler
.weak SVC_Handler
.thumb_set SVC_Handler,Default_Handler
.weak DebugMon_Handler
.thumb_set DebugMon_Handler,Default_Handler
.weak PendSV_Handler
.thumb_set PendSV_Handler,Default_Handler
.weak SysTick_Handler
.thumb_set SysTick_Handler,Default_Handler
.weak intc_irq
.thumb_set intc_irq,Default_Handler
.weak SLEEP_IRQHandler
.thumb_set SLEEP_IRQHandler,Default_Handler
.weak WDG_IRQHandler
.thumb_set WDG_IRQHandler,Default_Handler
.weak FLASH_IRQHandler
.thumb_set FLASH_IRQHandler,Default_Handler
.weak GPIO_IRQHandler
.thumb_set GPIO_IRQHandler,Default_Handler
.weak TIMER_IRQHandler
.thumb_set TIMER_IRQHandler,Default_Handler
.weak CRYPTOCELL310_IRQHandler
.thumb_set CRYPTOCELL310_IRQHandler,Default_Handler
.weak DMA_CTRL_IRQHandler
.thumb_set DMA_CTRL_IRQHandler,Default_Handler
.weak UART0_IRQHandler
.thumb_set UART0_IRQHandler,Default_Handler
.weak UART1_IRQHandler
.thumb_set UART1_IRQHandler,Default_Handler
.weak UART2_IRQHandler
.thumb_set UART2_IRQHandler,Default_Handler
.weak SPI0_IRQHandler
.thumb_set SPI0_IRQHandler,Default_Handler
.weak SPI1_IRQHandler
.thumb_set SPI1_IRQHandler,Default_Handler
.weak SPI2_IRQHandler
.thumb_set SPI2_IRQHandler,Default_Handler
.weak I2C0_IRQHandler
.thumb_set I2C0_IRQHandler,Default_Handler
.weak I2C1_IRQHandler
.thumb_set I2C1_IRQHandler,Default_Handler
.weak SDIO_IRQHandler
.thumb_set SDIO_IRQHandler,Default_Handler
.weak D_APLL_UNLOCK_IRQHandler
.thumb_set D_APLL_UNLOCK_IRQHandler,Default_Handler
.weak D_SX_UNLOCK_IRQHandler
.thumb_set D_SX_UNLOCK_IRQHandler,Default_Handler
.weak PLATFORM_WAKEUP_IRQHandler
.thumb_set PLATFORM_WAKEUP_IRQHandler,Default_Handler
.weak HCLK_SW_IRQHandler
.thumb_set HCLK_SW_IRQHandler,Default_Handler
/*****************END OF FILE*********************/