bl_iot_sdk/components/hal_drv/bl602_hal/bl_sys.c
2020-10-26 20:35:25 +08:00

144 lines
3.6 KiB
C

/*
* Copyright (c) 2020 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <bl602_romdriver.h>
#include <bl602_glb.h>
#include <stdio.h>
#include <stdbool.h>
#include "bl_sys.h"
#define MFG_CONFIG_REG (0x4000F100)
#define MFG_CONFIG_VAL ("0mfg")
volatile bool sys_log_all_enable = true;
int bl_sys_logall_enable(void)
{
sys_log_all_enable = true;
return 0;
}
int bl_sys_logall_disable(void)
{
sys_log_all_enable = false;
return 0;
}
void bl_sys_mfg_config(void)
{
union _reg_t {
uint8_t byte[4];
uint32_t word;
} mfg = {
.byte = MFG_CONFIG_VAL,
};
*(volatile uint32_t*)(MFG_CONFIG_REG) = mfg.word;
}
int bl_sys_reset_por(void)
{
__disable_irq();
GLB_SW_POR_Reset();
while (1) {
/*empty dead loop*/
}
return 0;
}
void bl_sys_reset_system(void)
{
__disable_irq();
GLB_SW_System_Reset();
while (1) {
/*empty dead loop*/
}
}
int bl_sys_isxipaddr(uint32_t addr)
{
if (((addr & 0xFF000000) == 0x23000000) || ((addr & 0xFF000000) == 0x43000000)) {
return 1;
}
return 0;
}
int bl_sys_em_config(void)
{
extern uint8_t __LD_CONFIG_EM_SEL;
uint32_t em_size;
em_size = (uint32_t)&__LD_CONFIG_EM_SEL;
switch (em_size) {
case 0 * 1024:
{
GLB_Set_EM_Sel(GLB_EM_0KB);
}
break;
case 8 * 1024:
{
GLB_Set_EM_Sel(GLB_EM_8KB);
}
break;
case 16 * 1024:
{
GLB_Set_EM_Sel(GLB_EM_16KB);
}
break;
default:
{
/*nothing here*/
}
}
return 0;
}
int bl_sys_early_init(void)
{
extern BL_Err_Type HBN_Aon_Pad_IeSmt_Cfg(uint8_t padCfg);
HBN_Aon_Pad_IeSmt_Cfg(1);
extern void freertos_risc_v_trap_handler(void); //freertos_riscv_ram/portable/GCC/RISC-V/portASM.S
write_csr(mtvec, &freertos_risc_v_trap_handler);
/*debuger may NOT ready don't print anything*/
return 0;
}
int bl_sys_init(void)
{
bl_sys_em_config();
return 0;
}