mirror of
https://github.com/bouffalolab/bouffalo_sdk.git
synced 2025-05-09 03:11:58 +08:00
[feat][tlsf] add tlsf component
This commit is contained in:
parent
d9adf21997
commit
05e403062c
@ -3,7 +3,11 @@
|
||||
#include "bflb_clock.h"
|
||||
#include "bflb_rtc.h"
|
||||
#include "bflb_flash.h"
|
||||
#include "mmheap.h"
|
||||
#ifdef CONFIG_TLSF
|
||||
#include "bflb_tlsf.h"
|
||||
#else
|
||||
#include "bflb_mmheap.h"
|
||||
#endif
|
||||
#include "board.h"
|
||||
#include "bl602_glb.h"
|
||||
#include "bl602_sflash.h"
|
||||
@ -11,14 +15,20 @@
|
||||
extern uint32_t __HeapBase;
|
||||
extern uint32_t __HeapLimit;
|
||||
|
||||
#ifndef CONFIG_TLSF
|
||||
struct heap_info mmheap_root;
|
||||
|
||||
static struct bflb_device_s *uart0;
|
||||
|
||||
static struct heap_region system_mmheap[] = {
|
||||
{ NULL, 0 },
|
||||
{ NULL, 0 }, /* Terminates the array. */
|
||||
};
|
||||
#endif
|
||||
|
||||
static struct bflb_device_s *uart0;
|
||||
|
||||
#if defined(CONFIG_BFLOG)
|
||||
static struct bflb_device_s *rtc;
|
||||
#endif
|
||||
|
||||
static void system_clock_init(void)
|
||||
{
|
||||
@ -126,19 +136,28 @@ void board_init(void)
|
||||
|
||||
bflb_irq_restore(flag);
|
||||
|
||||
#ifdef CONFIG_TLSF
|
||||
bflb_mmheap_init((void *)&__HeapBase, ((size_t)&__HeapLimit - (size_t)&__HeapBase));
|
||||
#else
|
||||
system_mmheap[0].addr = (uint8_t *)&__HeapBase;
|
||||
system_mmheap[0].mem_size = ((size_t)&__HeapLimit - (size_t)&__HeapBase);
|
||||
|
||||
if (system_mmheap[0].mem_size > 0) {
|
||||
mmheap_init(&mmheap_root, system_mmheap);
|
||||
bflb_mmheap_init(&mmheap_root, system_mmheap);
|
||||
}
|
||||
#endif
|
||||
|
||||
console_init();
|
||||
|
||||
bl_show_log();
|
||||
bl_show_flashinfo();
|
||||
|
||||
printf("dynamic memory init success,heap size = %d Kbyte \r\n", system_mmheap[0].mem_size / 1024);
|
||||
printf("dynamic memory init success,heap size = %d Kbyte \r\n", ((size_t)&__HeapLimit - (size_t)&__HeapBase) / 1024);
|
||||
|
||||
printf("cgen1:%08x\r\n", getreg32(BFLB_GLB_CGEN1_BASE));
|
||||
#if defined(CONFIG_BFLOG)
|
||||
rtc = bflb_device_get_by_name("rtc");
|
||||
#endif
|
||||
}
|
||||
|
||||
void board_uartx_gpio_init()
|
||||
@ -183,6 +202,19 @@ void board_pwm_gpio_init()
|
||||
// bflb_gpio_init(gpio, GPIO_PIN_4, GPIO_FUNC_PWM0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
}
|
||||
|
||||
void board_ir_gpio_init(void)
|
||||
{
|
||||
struct bflb_device_s *gpio;
|
||||
|
||||
gpio = bflb_device_get_by_name("gpio");
|
||||
/* IR TX only support GPIO 11 */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_11, GPIO_ANALOG | GPIO_SMT_EN | GPIO_DRV_0);
|
||||
|
||||
/* IR RX support GPIO 11 ~ GPIO 13 */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_12, GPIO_INPUT | GPIO_SMT_EN | GPIO_DRV_0);
|
||||
GLB_IR_RX_GPIO_Sel(GLB_GPIO_PIN_12);
|
||||
}
|
||||
|
||||
void board_adc_gpio_init()
|
||||
{
|
||||
// struct bflb_device_s *gpio;
|
||||
@ -202,4 +234,21 @@ void board_dac_gpio_init()
|
||||
// bflb_gpio_init(gpio, GPIO_PIN_11, GPIO_ANALOG | GPIO_SMT_EN | GPIO_DRV_0);
|
||||
// /* DAC_CHB */
|
||||
// bflb_gpio_init(gpio, GPIO_PIN_17, GPIO_ANALOG | GPIO_SMT_EN | GPIO_DRV_0);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BFLOG
|
||||
__attribute__((weak)) uint64_t bflog_clock(void)
|
||||
{
|
||||
return bflb_mtimer_get_time_us();
|
||||
}
|
||||
|
||||
__attribute__((weak)) uint32_t bflog_time(void)
|
||||
{
|
||||
return BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc));
|
||||
}
|
||||
|
||||
__attribute__((weak)) char *bflog_thread(void)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
#endif
|
@ -10,6 +10,7 @@ void board_adc_gpio_init();
|
||||
void board_dac_gpio_init();
|
||||
void board_emac_gpio_init();
|
||||
void board_pwm_gpio_init();
|
||||
void board_ir_gpio_init();
|
||||
|
||||
#define DEFAULT_TEST_UART "uart1"
|
||||
#define DEFAULT_TEST_UART_DMA_TX_REQUEST DMA_REQUEST_UART1_TX
|
||||
|
@ -3,7 +3,11 @@
|
||||
#include "bflb_clock.h"
|
||||
#include "bflb_rtc.h"
|
||||
#include "bflb_flash.h"
|
||||
#include "mmheap.h"
|
||||
#ifdef CONFIG_TLSF
|
||||
#include "bflb_tlsf.h"
|
||||
#else
|
||||
#include "bflb_mmheap.h"
|
||||
#endif
|
||||
#include "board.h"
|
||||
#include "bl616_tzc_sec.h"
|
||||
#include "bl616_psram.h"
|
||||
@ -19,12 +23,14 @@
|
||||
extern uint32_t __HeapBase;
|
||||
extern uint32_t __HeapLimit;
|
||||
|
||||
#ifndef CONFIG_TLSF
|
||||
struct heap_info mmheap_root;
|
||||
|
||||
static struct heap_region system_mmheap[] = {
|
||||
{ NULL, 0 },
|
||||
{ NULL, 0 }, /* Terminates the array. */
|
||||
};
|
||||
#endif
|
||||
|
||||
static struct bflb_device_s *uart0;
|
||||
|
||||
@ -54,6 +60,7 @@ static void peripheral_clock_init(void)
|
||||
PERIPHERAL_CLOCK_IR_ENABLE();
|
||||
PERIPHERAL_CLOCK_I2S_ENABLE();
|
||||
PERIPHERAL_CLOCK_USB_ENABLE();
|
||||
PERIPHERAL_CLOCK_CAN_ENABLE();
|
||||
|
||||
GLB_Set_UART_CLK(ENABLE, HBN_UART_CLK_XCLK, 0);
|
||||
GLB_Set_SPI_CLK(ENABLE, GLB_SPI_CLK_MCU_MUXPLL_160M, 0);
|
||||
@ -63,13 +70,12 @@ static void peripheral_clock_init(void)
|
||||
GLB_Set_DIG_512K_CLK(ENABLE, ENABLE, 0x4E);
|
||||
GLB_Set_PWM1_IO_Sel(GLB_PWM1_IO_DIFF_END);
|
||||
GLB_Set_IR_CLK(ENABLE, GLB_IR_CLK_SRC_XCLK, 19);
|
||||
GLB_Set_CAM_CLK(ENABLE, GLB_CAM_CLK_WIFIPLL_96M, 3);
|
||||
|
||||
GLB_Set_PKA_CLK_Sel(GLB_PKA_CLK_MCU_MUXPLL_160M);
|
||||
#ifdef CONFIG_BSP_SDH_SDCARD
|
||||
PERIPHERAL_CLOCK_SDH_ENABLE();
|
||||
GLB_Set_SDH_CLK(ENABLE, GLB_SDH_CLK_WIFIPLL_96M, 0);
|
||||
GLB_AHB_MCU_Software_Reset(GLB_AHB_MCU_SW_EXT_SDH);
|
||||
SDH_ClockSet(400000, 96000000, 48000000);
|
||||
#endif
|
||||
|
||||
GLB_Set_USB_CLK_From_WIFIPLL(1);
|
||||
@ -210,22 +216,26 @@ void board_init(void)
|
||||
|
||||
bflb_irq_restore(flag);
|
||||
|
||||
#ifdef CONFIG_TLSF
|
||||
bflb_mmheap_init((void *)&__HeapBase, ((size_t)&__HeapLimit - (size_t)&__HeapBase));
|
||||
#else
|
||||
system_mmheap[0].addr = (uint8_t *)&__HeapBase;
|
||||
system_mmheap[0].mem_size = ((size_t)&__HeapLimit - (size_t)&__HeapBase);
|
||||
|
||||
if (system_mmheap[0].mem_size > 0) {
|
||||
mmheap_init(&mmheap_root, system_mmheap);
|
||||
bflb_mmheap_init(&mmheap_root, system_mmheap);
|
||||
}
|
||||
|
||||
#endif
|
||||
console_init();
|
||||
|
||||
bl_show_log();
|
||||
bl_show_flashinfo();
|
||||
|
||||
printf("dynamic memory init success,heap size = %d Kbyte \r\n", system_mmheap[0].mem_size / 1024);
|
||||
printf("dynamic memory init success,heap size = %d Kbyte \r\n", ((size_t)&__HeapLimit - (size_t)&__HeapBase) / 1024);
|
||||
|
||||
printf("sig1:%08lx\r\n", BL_RD_REG(GLB_BASE, GLB_UART_CFG1));
|
||||
printf("sig2:%08lx\r\n", BL_RD_REG(GLB_BASE, GLB_UART_CFG2));
|
||||
printf("sig1:%08x\r\n", BL_RD_REG(GLB_BASE, GLB_UART_CFG1));
|
||||
printf("sig2:%08x\r\n", BL_RD_REG(GLB_BASE, GLB_UART_CFG2));
|
||||
printf("cgen1:%08x\r\n", getreg32(BFLB_GLB_CGEN1_BASE));
|
||||
|
||||
#if (defined(CONFIG_LUA) || defined(CONFIG_BFLOG) || defined(CONFIG_FATFS))
|
||||
rtc = bflb_device_get_by_name("rtc");
|
||||
@ -361,15 +371,90 @@ void board_ir_gpio_init(void)
|
||||
GLB_IR_RX_GPIO_Sel(GLB_GPIO_PIN_10);
|
||||
}
|
||||
|
||||
void board_dvp1_gpio_init(void)
|
||||
{
|
||||
struct bflb_device_s *gpio;
|
||||
|
||||
gpio = bflb_device_get_by_name("gpio");
|
||||
/* I2C GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_0, GPIO_FUNC_I2C0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_1, GPIO_FUNC_I2C0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
|
||||
/* Power down GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_2, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_reset(gpio, GPIO_PIN_2);
|
||||
|
||||
/* Reset GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_3, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_set(gpio, GPIO_PIN_3);
|
||||
|
||||
/* MCLK GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_23, GPIO_FUNC_CLKOUT | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
|
||||
/* DVP1 GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_24, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_25, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_26, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_27, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_28, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_29, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_30, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_31, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_32, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_33, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_34, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
}
|
||||
|
||||
void board_dvp2_gpio_init(void)
|
||||
{
|
||||
struct bflb_device_s *gpio;
|
||||
|
||||
gpio = bflb_device_get_by_name("gpio");
|
||||
/* I2C GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_28, GPIO_FUNC_I2C0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_27, GPIO_FUNC_I2C0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
|
||||
/* Power down GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_29, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_reset(gpio, GPIO_PIN_29);
|
||||
|
||||
/* Reset GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_30, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_set(gpio, GPIO_PIN_30);
|
||||
|
||||
/* MCLK GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_20, GPIO_FUNC_CLKOUT | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
|
||||
/* DVP2 GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_0, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_1, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_3, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_10, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_11, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_12, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_13, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_14, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_15, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_16, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_17, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
}
|
||||
|
||||
void board_iso11898_gpio_init()
|
||||
{
|
||||
// struct bflb_device_s *gpio;
|
||||
|
||||
// gpio = bflb_device_get_by_name("gpio");
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BFLOG
|
||||
__attribute__((weak)) uint64_t bflog_clock(void)
|
||||
{
|
||||
return CPU_Get_MTimer_Counter();
|
||||
return bflb_mtimer_get_time_us();
|
||||
}
|
||||
|
||||
__attribute__((weak)) uint32_t bflog_time(void)
|
||||
{
|
||||
return BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc)) + 1640995200;
|
||||
return BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc));
|
||||
}
|
||||
|
||||
__attribute__((weak)) char *bflog_thread(void)
|
||||
@ -381,12 +466,12 @@ __attribute__((weak)) char *bflog_thread(void)
|
||||
#ifdef CONFIG_LUA
|
||||
__attribute__((weak)) clock_t luaport_clock(void)
|
||||
{
|
||||
return (clock_t)CPU_Get_MTimer_Counter();
|
||||
return (clock_t)bflb_mtimer_get_time_us();
|
||||
}
|
||||
|
||||
__attribute__((weak)) time_t luaport_time(time_t *seconds)
|
||||
{
|
||||
time_t t = (time_t)BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc)) + 1640995200;
|
||||
time_t t = (time_t)BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc));
|
||||
if (seconds != NULL) {
|
||||
*seconds = t;
|
||||
}
|
||||
@ -401,7 +486,7 @@ __attribute__((weak)) uint32_t get_fattime(void)
|
||||
{
|
||||
bflb_timestamp_t tm;
|
||||
|
||||
bflb_timestamp_utc2time(BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc)) + 1640995200, &tm);
|
||||
bflb_timestamp_utc2time(BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc)), &tm);
|
||||
|
||||
return ((uint32_t)(tm.year - 1980) << 25) /* Year 2015 */
|
||||
| ((uint32_t)tm.mon << 21) /* Month 1 */
|
||||
|
@ -12,6 +12,9 @@ void board_dac_gpio_init();
|
||||
void board_emac_gpio_init();
|
||||
void board_sdh_gpio_init();
|
||||
void board_ir_gpio_init();
|
||||
void board_dvp1_gpio_init();
|
||||
void board_dvp2_gpio_init();
|
||||
void board_iso11898_gpio_init();
|
||||
|
||||
#define DEFAULT_TEST_UART "uart1"
|
||||
#define DEFAULT_TEST_UART_DMA_TX_REQUEST DMA_REQUEST_UART1_TX
|
||||
|
@ -3,7 +3,11 @@
|
||||
#include "bflb_clock.h"
|
||||
#include "bflb_rtc.h"
|
||||
#include "bflb_flash.h"
|
||||
#include "mmheap.h"
|
||||
#ifdef CONFIG_TLSF
|
||||
#include "bflb_tlsf.h"
|
||||
#else
|
||||
#include "bflb_mmheap.h"
|
||||
#endif
|
||||
#include "board.h"
|
||||
#include "bl702_glb.h"
|
||||
#include "bl702_sflash.h"
|
||||
@ -11,14 +15,20 @@
|
||||
extern uint32_t __HeapBase;
|
||||
extern uint32_t __HeapLimit;
|
||||
|
||||
#ifndef CONFIG_TLSF
|
||||
struct heap_info mmheap_root;
|
||||
|
||||
static struct bflb_device_s *uart0;
|
||||
|
||||
static struct heap_region system_mmheap[] = {
|
||||
{ NULL, 0 },
|
||||
{ NULL, 0 }, /* Terminates the array. */
|
||||
};
|
||||
#endif
|
||||
|
||||
static struct bflb_device_s *uart0;
|
||||
|
||||
#if defined(CONFIG_BFLOG)
|
||||
static struct bflb_device_s *rtc;
|
||||
#endif
|
||||
|
||||
static void system_clock_init(void)
|
||||
{
|
||||
@ -44,6 +54,7 @@ static void peripheral_clock_init(void)
|
||||
GLB_Set_UART_CLK(ENABLE, HBN_UART_CLK_96M, 0);
|
||||
GLB_Set_SPI_CLK(ENABLE, 0);
|
||||
GLB_Set_I2C_CLK(ENABLE, 0);
|
||||
GLB_Set_IR_CLK(ENABLE, GLB_IR_CLK_SRC_XCLK, 15);
|
||||
|
||||
GLB_Set_ADC_CLK(ENABLE, GLB_ADC_CLK_XCLK, 1);
|
||||
GLB_Set_DAC_CLK(ENABLE, GLB_DAC_CLK_XCLK, 0x3E);
|
||||
@ -131,20 +142,28 @@ void board_init(void)
|
||||
|
||||
bflb_irq_restore(flag);
|
||||
|
||||
#ifdef CONFIG_TLSF
|
||||
bflb_mmheap_init((void *)&__HeapBase, ((size_t)&__HeapLimit - (size_t)&__HeapBase));
|
||||
#else
|
||||
system_mmheap[0].addr = (uint8_t *)&__HeapBase;
|
||||
system_mmheap[0].mem_size = ((size_t)&__HeapLimit - (size_t)&__HeapBase);
|
||||
|
||||
if (system_mmheap[0].mem_size > 0) {
|
||||
mmheap_init(&mmheap_root, system_mmheap);
|
||||
bflb_mmheap_init(&mmheap_root, system_mmheap);
|
||||
}
|
||||
#endif
|
||||
|
||||
console_init();
|
||||
|
||||
bl_show_log();
|
||||
|
||||
bl_show_flashinfo();
|
||||
|
||||
printf("dynamic memory init success,heap size = %d Kbyte \r\n", system_mmheap[0].mem_size / 1024);
|
||||
printf("dynamic memory init success,heap size = %d Kbyte \r\n", ((size_t)&__HeapLimit - (size_t)&__HeapBase) / 1024);
|
||||
|
||||
printf("cgen1:%08x\r\n", getreg32(BFLB_GLB_CGEN1_BASE));
|
||||
#if defined(CONFIG_BFLOG)
|
||||
rtc = bflb_device_get_by_name("rtc");
|
||||
#endif
|
||||
}
|
||||
|
||||
void board_uartx_gpio_init()
|
||||
@ -192,6 +211,21 @@ void board_pwm_gpio_init()
|
||||
bflb_gpio_init(gpio, GPIO_PIN_4, GPIO_FUNC_PWM0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
}
|
||||
|
||||
void board_ir_gpio_init(void)
|
||||
{
|
||||
struct bflb_device_s *gpio;
|
||||
|
||||
gpio = bflb_device_get_by_name("gpio");
|
||||
/* IR TX support GPIO 22 or GPIO 23 */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_22, GPIO_ANALOG | GPIO_SMT_EN | GPIO_DRV_0);
|
||||
GLB_IR_LED_Driver_Output_Disable(GLB_GPIO_PIN_23);
|
||||
GLB_IR_LED_Driver_Output_Enable(GLB_GPIO_PIN_22);
|
||||
|
||||
/* IR RX support GPIO 17 ~ GPIO 31 */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_18, GPIO_INPUT | GPIO_SMT_EN | GPIO_DRV_0);
|
||||
GLB_IR_RX_GPIO_Sel(GLB_GPIO_PIN_18);
|
||||
}
|
||||
|
||||
void board_adc_gpio_init()
|
||||
{
|
||||
struct bflb_device_s *gpio;
|
||||
@ -232,4 +266,39 @@ void board_emac_gpio_init()
|
||||
/* enable audio clock */
|
||||
PDS_Enable_PLL_Clk(PDS_PLL_CLK_48M);
|
||||
PDS_Set_Audio_PLL_Freq(AUDIO_PLL_50000000_HZ);
|
||||
}
|
||||
}
|
||||
|
||||
void board_keyscan_gpio_init(void)
|
||||
{
|
||||
struct bflb_device_s *gpio;
|
||||
|
||||
gpio = bflb_device_get_by_name("gpio");
|
||||
bflb_gpio_init(gpio, GPIO_PIN_0, GPIO_FUN_KEY_SCAN_COL | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_OUTPUT | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_1, GPIO_FUN_KEY_SCAN_COL | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_OUTPUT | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_2, GPIO_FUN_KEY_SCAN_COL | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_OUTPUT | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_3, GPIO_FUN_KEY_SCAN_COL | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_OUTPUT | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
|
||||
bflb_gpio_init(gpio, GPIO_PIN_16, GPIO_FUN_KEY_SCAN_ROW | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_INPUT | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_17, GPIO_FUN_KEY_SCAN_ROW | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_INPUT | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_18, GPIO_FUN_KEY_SCAN_ROW | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_INPUT | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_19, GPIO_FUN_KEY_SCAN_ROW | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_INPUT | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
|
||||
GLB_Set_QDEC_CLK(GLB_QDEC_CLK_F32K, 0);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BFLOG
|
||||
__attribute__((weak)) uint64_t bflog_clock(void)
|
||||
{
|
||||
return bflb_mtimer_get_time_us();
|
||||
}
|
||||
|
||||
__attribute__((weak)) uint32_t bflog_time(void)
|
||||
{
|
||||
return BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc));
|
||||
}
|
||||
|
||||
__attribute__((weak)) char *bflog_thread(void)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
#endif
|
@ -10,6 +10,7 @@ void board_adc_gpio_init();
|
||||
void board_dac_gpio_init();
|
||||
void board_emac_gpio_init();
|
||||
void board_pwm_gpio_init();
|
||||
void board_ir_gpio_init();
|
||||
|
||||
#define DEFAULT_TEST_UART "uart1"
|
||||
#define DEFAULT_TEST_UART_DMA_TX_REQUEST DMA_REQUEST_UART1_TX
|
||||
|
@ -26,7 +26,7 @@ MEMORY
|
||||
itcm_memory (rx) : ORIGIN = 0x3eff0000, LENGTH = 28K
|
||||
dtcm_memory (rx) : ORIGIN = 0x3eff7000, LENGTH = 4K
|
||||
nocache_ram_memory (!rx) : ORIGIN = 0x3eff8000, LENGTH = 0K
|
||||
ram_memory (!rx) : ORIGIN = 0x3eff8000, LENGTH = 64K
|
||||
ram_memory (!rx) : ORIGIN = 0x3eff8000, LENGTH = 32K + 32K
|
||||
xram_memory (!rx) : ORIGIN = 0x40004000, LENGTH = 16K
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,11 @@
|
||||
#include "bflb_clock.h"
|
||||
#include "bflb_rtc.h"
|
||||
#include "bflb_flash.h"
|
||||
#include "mmheap.h"
|
||||
#ifdef CONFIG_TLSF
|
||||
#include "bflb_tlsf.h"
|
||||
#else
|
||||
#include "bflb_mmheap.h"
|
||||
#endif
|
||||
#include "bl808_glb.h"
|
||||
#include "bl808_sflash.h"
|
||||
#include "bl808_psram_uhs.h"
|
||||
@ -19,18 +23,21 @@
|
||||
extern uint32_t __HeapBase;
|
||||
extern uint32_t __HeapLimit;
|
||||
|
||||
#ifndef CONFIG_TLSF
|
||||
struct heap_info mmheap_root;
|
||||
|
||||
static struct heap_region system_mmheap[] = {
|
||||
{ NULL, 0 },
|
||||
{ NULL, 0 }, /* Terminates the array. */
|
||||
};
|
||||
#endif
|
||||
|
||||
static struct bflb_device_s *uart0;
|
||||
|
||||
#if (defined(CONFIG_LUA) || defined(CONFIG_BFLOG) || defined(CONFIG_FATFS))
|
||||
static struct bflb_device_s *rtc;
|
||||
#endif
|
||||
|
||||
#if defined(CPU_M0)
|
||||
static void system_clock_init(void)
|
||||
{
|
||||
@ -42,6 +49,7 @@ static void system_clock_init(void)
|
||||
|
||||
GLB_Set_MCU_System_CLK(GLB_MCU_SYS_CLK_WIFIPLL_320M);
|
||||
GLB_Set_DSP_System_CLK(GLB_DSP_SYS_CLK_CPUPLL_400M);
|
||||
GLB_Config_CPU_PLL(GLB_XTAL_40M, cpuPllCfg_480M);
|
||||
|
||||
CPU_Set_MTimer_CLK(ENABLE, CPU_Get_MTimer_Source_Clock() / 1000 / 1000 - 1);
|
||||
}
|
||||
@ -60,6 +68,7 @@ static void peripheral_clock_init(void)
|
||||
PERIPHERAL_CLOCK_IR_ENABLE();
|
||||
PERIPHERAL_CLOCK_I2S_ENABLE();
|
||||
PERIPHERAL_CLOCK_USB_ENABLE();
|
||||
PERIPHERAL_CLOCK_CAN_UART2_ENABLE();
|
||||
|
||||
GLB_Set_ADC_CLK(ENABLE, GLB_ADC_CLK_XCLK, 4);
|
||||
GLB_Set_UART_CLK(ENABLE, HBN_UART_CLK_XCLK, 0);
|
||||
@ -71,8 +80,10 @@ static void peripheral_clock_init(void)
|
||||
GLB_Set_DIG_CLK_Sel(GLB_DIG_CLK_XCLK);
|
||||
GLB_Set_DIG_512K_CLK(ENABLE, ENABLE, 0x4E);
|
||||
GLB_Set_PWM1_IO_Sel(GLB_PWM1_IO_DIFF_END);
|
||||
GLB_Set_CAM_CLK(ENABLE, GLB_CAM_CLK_WIFIPLL_96M, 3);
|
||||
|
||||
GLB_Set_PKA_CLK_Sel(GLB_PKA_CLK_MCU_MUXPLL_160M);
|
||||
|
||||
#ifdef CONFIG_BSP_SDH_SDCARD
|
||||
PERIPHERAL_CLOCK_SDH_ENABLE();
|
||||
uint32_t tmp_val;
|
||||
@ -81,12 +92,11 @@ static void peripheral_clock_init(void)
|
||||
tmp_val2 &= ~(1 << 0);
|
||||
tmp_val = BL_SET_REG_BITS_VAL(tmp_val, PDS_CR_PDS_GPIO_KEEP_EN, tmp_val2);
|
||||
BL_WR_REG(PDS_BASE, PDS_CTL5, tmp_val);
|
||||
|
||||
GLB_Set_SDH_CLK(ENABLE, GLB_SDH_CLK_WIFIPLL_96M, 0);
|
||||
GLB_AHB_MCU_Software_Reset(GLB_AHB_MCU_SW_SDH);
|
||||
#endif
|
||||
GLB_Set_USB_CLK_From_WIFIPLL(1);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PSRAM
|
||||
#define WB_4MB_PSRAM (1)
|
||||
#define UHS_32MB_PSRAM (2)
|
||||
@ -236,12 +246,16 @@ void board_init(void)
|
||||
|
||||
bflb_irq_restore(flag);
|
||||
|
||||
#ifdef CONFIG_TLSF
|
||||
bflb_mmheap_init((void *)&__HeapBase, ((size_t)&__HeapLimit - (size_t)&__HeapBase));
|
||||
#else
|
||||
system_mmheap[0].addr = (uint8_t *)&__HeapBase;
|
||||
system_mmheap[0].mem_size = ((size_t)&__HeapLimit - (size_t)&__HeapBase);
|
||||
|
||||
if (system_mmheap[0].mem_size > 0) {
|
||||
mmheap_init(&mmheap_root, system_mmheap);
|
||||
bflb_mmheap_init(&mmheap_root, system_mmheap);
|
||||
}
|
||||
#endif
|
||||
|
||||
console_init();
|
||||
|
||||
@ -275,21 +289,26 @@ void board_init(void)
|
||||
|
||||
bflb_irq_initialize();
|
||||
|
||||
#ifdef CONFIG_TLSF
|
||||
bflb_mmheap_init((void *)&__HeapBase, ((size_t)&__HeapLimit - (size_t)&__HeapBase));
|
||||
#else
|
||||
system_mmheap[0].addr = (uint8_t *)&__HeapBase;
|
||||
system_mmheap[0].mem_size = ((size_t)&__HeapLimit - (size_t)&__HeapBase);
|
||||
|
||||
if (system_mmheap[0].mem_size > 0) {
|
||||
mmheap_init(&mmheap_root, system_mmheap);
|
||||
bflb_mmheap_init(&mmheap_root, system_mmheap);
|
||||
}
|
||||
#endif
|
||||
|
||||
console_init();
|
||||
|
||||
bl_show_log();
|
||||
|
||||
printf("dynamic memory init success,heap size = %d Kbyte \r\n", system_mmheap[0].mem_size / 1024);
|
||||
printf("dynamic memory init success,heap size = %d Kbyte \r\n", ((size_t)&__HeapLimit - (size_t)&__HeapBase) / 1024);
|
||||
|
||||
printf("sig1:%08x\r\n", BL_RD_REG(GLB_BASE, GLB_UART_CFG1));
|
||||
printf("sig2:%08x\r\n", BL_RD_REG(GLB_BASE, GLB_UART_CFG2));
|
||||
printf("cgen1:%08x\r\n", getreg32(BFLB_GLB_CGEN1_BASE));
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -419,7 +438,6 @@ void board_emac_gpio_init(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BSP_SDH_SDCARD
|
||||
void board_sdh_gpio_init(void)
|
||||
{
|
||||
struct bflb_device_s *gpio;
|
||||
@ -431,27 +449,58 @@ void board_sdh_gpio_init(void)
|
||||
bflb_gpio_init(gpio, GPIO_PIN_3, GPIO_FUNC_SDH | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_2);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_4, GPIO_FUNC_SDH | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_2);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_5, GPIO_FUNC_SDH | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_2);
|
||||
|
||||
/* config sdh clock */
|
||||
SDH_ClockSet(400000, 96000000, 48000000);
|
||||
|
||||
#ifdef CONFIG_BSP_FATFS_SDH_SDCARD
|
||||
extern void fatfs_sdh_driver_register(void);
|
||||
fatfs_sdh_driver_register();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
void board_dvp1_gpio_init(void)
|
||||
{
|
||||
struct bflb_device_s *gpio;
|
||||
|
||||
gpio = bflb_device_get_by_name("gpio");
|
||||
/* I2C GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_22, GPIO_FUNC_I2C0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_23, GPIO_FUNC_I2C0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
|
||||
/* Power down GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_21, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_reset(gpio, GPIO_PIN_21);
|
||||
|
||||
/* Reset GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_20, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_set(gpio, GPIO_PIN_20);
|
||||
|
||||
/* MCLK GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_33, GPIO_FUNC_CLKOUT | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
|
||||
/* DVP1 GPIO */
|
||||
bflb_gpio_init(gpio, GPIO_PIN_16, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_17, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_24, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_25, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_26, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_27, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_28, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_29, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_30, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_31, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
bflb_gpio_init(gpio, GPIO_PIN_32, GPIO_FUNC_CAM | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
|
||||
}
|
||||
|
||||
void board_iso11898_gpio_init()
|
||||
{
|
||||
// struct bflb_device_s *gpio;
|
||||
|
||||
// gpio = bflb_device_get_by_name("gpio");
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BFLOG
|
||||
__attribute__((weak)) uint64_t bflog_clock(void)
|
||||
{
|
||||
return CPU_Get_MTimer_Counter();
|
||||
return bflb_mtimer_get_time_us();
|
||||
}
|
||||
|
||||
__attribute__((weak)) uint32_t bflog_time(void)
|
||||
{
|
||||
return BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc)) + 1640995200;
|
||||
return BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc));
|
||||
}
|
||||
|
||||
__attribute__((weak)) char *bflog_thread(void)
|
||||
@ -463,12 +512,12 @@ __attribute__((weak)) char *bflog_thread(void)
|
||||
#ifdef CONFIG_LUA
|
||||
__attribute__((weak)) clock_t luaport_clock(void)
|
||||
{
|
||||
return (clock_t)CPU_Get_MTimer_Counter();
|
||||
return (clock_t)bflb_mtimer_get_time_us();
|
||||
}
|
||||
|
||||
__attribute__((weak)) time_t luaport_time(time_t *seconds)
|
||||
{
|
||||
time_t t = (time_t)BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc)) + 1640995200;
|
||||
time_t t = (time_t)BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc));
|
||||
if (seconds != NULL) {
|
||||
*seconds = t;
|
||||
}
|
||||
@ -483,7 +532,7 @@ __attribute__((weak)) uint32_t get_fattime(void)
|
||||
{
|
||||
bflb_timestamp_t tm;
|
||||
|
||||
bflb_timestamp_utc2time(BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc)) + 1640995200, &tm);
|
||||
bflb_timestamp_utc2time(BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc)), &tm);
|
||||
|
||||
return ((uint32_t)(tm.year - 1980) << 25) /* Year 2015 */
|
||||
| ((uint32_t)tm.mon << 21) /* Month 1 */
|
||||
|
@ -12,15 +12,14 @@ void board_adc_gpio_init(void);
|
||||
void board_dac_gpio_init(void);
|
||||
void board_ir_gpio_init(void);
|
||||
void board_emac_gpio_init(void);
|
||||
|
||||
#ifdef CONFIG_BSP_SDH_SDCARD
|
||||
void board_sdh_gpio_init(void);
|
||||
#endif
|
||||
void board_dvp1_gpio_init(void);
|
||||
void board_iso11898_gpio_init();
|
||||
|
||||
#define DEFAULT_TEST_UART "uart1"
|
||||
#define DEFAULT_TEST_UART "uart1"
|
||||
#define DEFAULT_TEST_UART_DMA_TX_REQUEST DMA_REQUEST_UART1_TX
|
||||
#define DEFAULT_TEST_UART_DMA_RX_REQUEST DMA_REQUEST_UART1_RX
|
||||
#define DEFAULT_TEST_UART_DMA_TDR DMA_ADDR_UART1_TDR
|
||||
#define DEFAULT_TEST_UART_DMA_RDR DMA_ADDR_UART1_RDR
|
||||
#define DEFAULT_TEST_UART_DMA_TDR DMA_ADDR_UART1_TDR
|
||||
#define DEFAULT_TEST_UART_DMA_RDR DMA_ADDR_UART1_RDR
|
||||
|
||||
#endif
|
@ -6,8 +6,9 @@ sdk_add_subdirectory_ifdef(CONFIG_BFLOG bflog)
|
||||
sdk_add_subdirectory_ifdef(CONFIG_LUA lua)
|
||||
sdk_add_subdirectory_ifdef(CONFIG_LVGL lvgl)
|
||||
sdk_add_subdirectory_ifdef(CONFIG_LWIP lwip)
|
||||
sdk_add_subdirectory_ifdef(CONFIG_BLE ble)
|
||||
sdk_add_subdirectory_ifdef(CONFIG_BLUETOOTH bluetooth)
|
||||
sdk_add_subdirectory_ifdef(CONFIG_XZ xz)
|
||||
sdk_add_subdirectory_ifdef(CONFIG_TINYMAIX TinyMaix)
|
||||
sdk_add_subdirectory_ifdef(CONFIG_TENSORFLOWLITE TensorFlowLite)
|
||||
sdk_add_subdirectory_ifdef(CONFIG_TLSF tlsf)
|
||||
add_subdirectory(utils)
|
||||
|
4
components/tlsf/CMakeLists.txt
Normal file
4
components/tlsf/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
sdk_generate_library()
|
||||
sdk_library_add_sources(tlsf.c bflb_tlsf.c)
|
||||
sdk_add_include_directories(.)
|
||||
sdk_add_compile_definitions(-DCONFIG_TLSF)
|
59
components/tlsf/bflb_tlsf.c
Normal file
59
components/tlsf/bflb_tlsf.c
Normal file
@ -0,0 +1,59 @@
|
||||
#include "tlsf.h"
|
||||
#include "bflb_tlsf.h"
|
||||
|
||||
static tlsf_t tlsf_ptr = 0;
|
||||
|
||||
int bflb_mmheap_init(void *begin_addr, uint32_t size)
|
||||
{
|
||||
tlsf_ptr = (tlsf_t)tlsf_create_with_pool(begin_addr, size);
|
||||
|
||||
if (tlsf_ptr == 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *bflb_malloc(size_t nbytes)
|
||||
{
|
||||
void *ptr;
|
||||
ptr = tlsf_malloc(tlsf_ptr, nbytes);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void bflb_free(void *ptr)
|
||||
{
|
||||
tlsf_free(tlsf_ptr, ptr);
|
||||
}
|
||||
|
||||
void *bflb_realloc(void *ptr, size_t nbytes)
|
||||
{
|
||||
if (tlsf_ptr) {
|
||||
ptr = tlsf_realloc(tlsf_ptr, ptr, nbytes);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *bflb_calloc(size_t count, size_t nbytes)
|
||||
{
|
||||
void *ptr = NULL;
|
||||
size_t total_size;
|
||||
|
||||
total_size = count * nbytes;
|
||||
ptr = tlsf_malloc(tlsf_ptr, nbytes);
|
||||
if (ptr != NULL) {
|
||||
/* clean memory */
|
||||
memset(ptr, 0, total_size);
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *bflb_malloc_align(size_t align, size_t size)
|
||||
{
|
||||
void *ptr = NULL;
|
||||
|
||||
ptr = tlsf_memalign(tlsf_ptr, align, size);
|
||||
|
||||
return ptr;
|
||||
}
|
14
components/tlsf/bflb_tlsf.h
Normal file
14
components/tlsf/bflb_tlsf.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef BFLB_TLSF_H
|
||||
#define BFLB_TLSF_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
int bflb_mmheap_init(void *begin_addr, uint32_t size);
|
||||
void *bflb_malloc(size_t nbytes);
|
||||
void bflb_free(void *ptr);
|
||||
void *bflb_realloc(void *ptr, size_t nbytes);
|
||||
void *bflb_calloc(size_t count, size_t size);
|
||||
void *bflb_malloc_align(size_t align, size_t size);
|
||||
|
||||
#endif
|
1286
components/tlsf/tlsf.c
Normal file
1286
components/tlsf/tlsf.c
Normal file
File diff suppressed because it is too large
Load Diff
90
components/tlsf/tlsf.h
Normal file
90
components/tlsf/tlsf.h
Normal file
@ -0,0 +1,90 @@
|
||||
#ifndef INCLUDED_tlsf
|
||||
#define INCLUDED_tlsf
|
||||
|
||||
/*
|
||||
** Two Level Segregated Fit memory allocator, version 3.1.
|
||||
** Written by Matthew Conte
|
||||
** http://tlsf.baisoku.org
|
||||
**
|
||||
** Based on the original documentation by Miguel Masmano:
|
||||
** http://www.gii.upv.es/tlsf/main/docs
|
||||
**
|
||||
** This implementation was written to the specification
|
||||
** of the document, therefore no GPL restrictions apply.
|
||||
**
|
||||
** Copyright (c) 2006-2016, Matthew Conte
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * 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.
|
||||
** * Neither the name of the copyright holder 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 MATTHEW CONTE 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 <stddef.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* tlsf_t: a TLSF structure. Can contain 1 to N pools. */
|
||||
/* pool_t: a block of memory that TLSF can manage. */
|
||||
typedef void *tlsf_t;
|
||||
typedef void *pool_t;
|
||||
|
||||
/* Create/destroy a memory pool. */
|
||||
tlsf_t tlsf_create(void *mem);
|
||||
tlsf_t tlsf_create_with_pool(void *mem, size_t bytes);
|
||||
void tlsf_destroy(tlsf_t tlsf);
|
||||
pool_t tlsf_get_pool(tlsf_t tlsf);
|
||||
|
||||
/* Add/remove memory pools. */
|
||||
pool_t tlsf_add_pool(tlsf_t tlsf, void *mem, size_t bytes);
|
||||
void tlsf_remove_pool(tlsf_t tlsf, pool_t pool);
|
||||
|
||||
/* malloc/memalign/realloc/free replacements. */
|
||||
void *tlsf_malloc(tlsf_t tlsf, size_t bytes);
|
||||
void *tlsf_memalign(tlsf_t tlsf, size_t align, size_t bytes);
|
||||
void *tlsf_realloc(tlsf_t tlsf, void *ptr, size_t size);
|
||||
void tlsf_free(tlsf_t tlsf, void *ptr);
|
||||
|
||||
/* Returns internal block size, not original request size */
|
||||
size_t tlsf_block_size(void *ptr);
|
||||
|
||||
/* Overheads/limits of internal structures. */
|
||||
size_t tlsf_size(void);
|
||||
size_t tlsf_align_size(void);
|
||||
size_t tlsf_block_size_min(void);
|
||||
size_t tlsf_block_size_max(void);
|
||||
size_t tlsf_pool_overhead(void);
|
||||
size_t tlsf_alloc_overhead(void);
|
||||
|
||||
/* Debugging. */
|
||||
typedef void (*tlsf_walker)(void *ptr, size_t size, int used, void *user);
|
||||
void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void *user);
|
||||
/* Returns nonzero if any internal consistency check fails. */
|
||||
int tlsf_check(tlsf_t tlsf);
|
||||
int tlsf_check_pool(pool_t pool);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user