Skip to content

Commit

Permalink
fix: optimize memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
LynnL4 committed Nov 5, 2024
1 parent 7b52b92 commit 44ab9c4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
41 changes: 28 additions & 13 deletions porting/himax/we2/drivers/drv_shared_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,34 @@ static_assert(YUV422_BASE_SIZE <= SRAM_1_TAIL_SIZE, "SRAM1 is not enough");
#define JPEG_BASE_SIZE_EXP(w, h) \
(((623 + (size_t)(w / 16) * (size_t)(h / 16) * 128 + 35) >> 2) << 2) // 4x quantization

#define JPEG_BASE_ADDR ALIGN_32BIT(WDMA_1_BASE_ADDR + WDMA_1_BASE_SIZE)
#define JPEG_BASE_SIZE JPEG_BASE_SIZE_EXP(FRAME_WIDTH_MAX, FRAME_HEIGHT_MAX) // 150KB

#define JPEG_FILL_BASE_ADDR ALIGN_32BIT(JPEG_BASE_ADDR + JPEG_BASE_SIZE)
#define JPEG_FILL_SIZE 0x1000 // 4KB

#define SPI_TRANSPORT_TX_BASE_ADDR ALIGN_32BIT(JPEG_FILL_BASE_ADDR + JPEG_FILL_SIZE)
#define SPI_TRANSPORT_TX_BASE_SIZE 64 * 1024 // 64KB
#define SPI_TRANSPORT_RX_BASE_ADDR ALIGN_32BIT(SPI_TRANSPORT_TX_BASE_ADDR + SPI_TRANSPORT_TX_BASE_SIZE)
#define SPI_TRANSPORT_RX_BASE_SIZE 8 * 1024 // 8KB

#define SRAM_2_START_ADDR_FREE (SPI_TRANSPORT_RX_BASE_ADDR + SPI_TRANSPORT_RX_BASE_SIZE)
#define SRAM_2_SIZE_FREE (SRAM_2_SIZE - (SRAM_2_START_ADDR_FREE - SRAM_2_START_ADDR))
#define JPEG_BASE_ADDR ALIGN_32BIT(WDMA_1_BASE_ADDR + WDMA_1_BASE_SIZE)
#define JPEG_BASE_SIZE JPEG_BASE_SIZE_EXP(FRAME_WIDTH_MAX, FRAME_HEIGHT_MAX) // 150KB

#define JPEG_FILL_BASE_ADDR ALIGN_32BIT(JPEG_BASE_ADDR + JPEG_BASE_SIZE)
#define JPEG_FILL_SIZE 0x1000 // 4KB

#define SPI_TRANSPORT_TX_BASE_ADDR ALIGN_32BIT(JPEG_FILL_BASE_ADDR + JPEG_FILL_SIZE)
#define SPI_TRANSPORT_TX_BASE_SIZE 64 * 1024 // 64KB
#define SPI_TRANSPORT_RX_BASE_ADDR ALIGN_32BIT(SPI_TRANSPORT_TX_BASE_ADDR + SPI_TRANSPORT_TX_BASE_SIZE)
#define SPI_TRANSPORT_RX_BASE_SIZE 8 * 1024 // 8KB

#define SERIAL1_TRANSPORT_TX_BASE_ADDR ALIGN_32BIT(SPI_TRANSPORT_RX_BASE_ADDR + SPI_TRANSPORT_RX_BASE_SIZE)
#define SERIAL1_TRANSPORT_TX_BASE_SIZE 32 * 1024
#define SERIAL1_TRANSPORT_RX_BASE_ADDR ALIGN_32BIT(SERIAL1_TRANSPORT_TX_BASE_ADDR + SERIAL1_TRANSPORT_TX_BASE_SIZE)
#define SERIAL1_TRANSPORT_RX_BASE_SIZE 8 * 1024

#define SERIAL2_TRANSPORT_TX_BASE_ADDR ALIGN_32BIT(SERIAL1_TRANSPORT_RX_BASE_ADDR + SERIAL1_TRANSPORT_RX_BASE_SIZE)
#define SERIAL2_TRANSPORT_TX_BASE_SIZE 32 * 1024
#define SERIAL2_TRANSPORT_RX_BASE_ADDR ALIGN_32BIT(SERIAL2_TRANSPORT_TX_BASE_ADDR + SERIAL2_TRANSPORT_TX_BASE_SIZE)
#define SERIAL2_TRANSPORT_RX_BASE_SIZE 8 * 1024

#define WIRE_TRANSPORT_TX_BASE_ADDR ALIGN_32BIT(SERIAL2_TRANSPORT_RX_BASE_ADDR + SERIAL2_TRANSPORT_RX_BASE_SIZE)
#define WIRE_TRANSPORT_TX_BASE_SIZE 32 * 1024
#define WIRE_TRANSPORT_RX_BASE_ADDR ALIGN_32BIT(WIRE_TRANSPORT_TX_BASE_ADDR + WIRE_TRANSPORT_TX_BASE_SIZE)
#define WIRE_TRANSPORT_RX_BASE_SIZE 8 * 1024

#define SRAM_2_START_ADDR_FREE (WIRE_TRANSPORT_TX_BASE_ADDR + WIRE_TRANSPORT_TX_BASE_SIZE)
#define SRAM_2_SIZE_FREE (SRAM_2_SIZE - (SRAM_2_START_ADDR_FREE - SRAM_2_START_ADDR))

static_assert(SRAM_2_SIZE_FREE > 0, "SRAM2 is not enough");

Expand Down
4 changes: 0 additions & 4 deletions porting/himax/we2/el_flash_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ bool _el_flash_enable_xip() {

bool el_flash_mmap_init(uint32_t* flash_addr, uint32_t* size, const uint8_t** mmap, uint32_t* handler) {
*flash_addr = 0x00400000;
#ifdef CONFIG_EL_BOARD_GROVE_VISION_AI_WE2
*size = 0x00400000;
#else
*size = 0x00A00000;
#endif

if (!_el_flash_init()) [[unlikely]]
return false;
Expand Down
4 changes: 2 additions & 2 deletions porting/himax/we2/el_serial2_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ el_err_code_t Serial2WE2::init() {
_console_uart->uart_open(UART_BAUDRATE_921600);

if (!_rb_rx) [[likely]]
_rb_rx = new lwRingBuffer{8192};
_rb_rx = new lwRingBuffer{(char*)SERIAL2_TRANSPORT_RX_BASE_ADDR, SERIAL2_TRANSPORT_RX_BASE_SIZE};

if (!_rb_tx) [[likely]]
_rb_tx = new lwRingBuffer{32768};
_rb_tx = new lwRingBuffer{(char*)SERIAL2_TRANSPORT_TX_BASE_ADDR, SERIAL2_TRANSPORT_TX_BASE_SIZE};

_mutex_tx = xSemaphoreCreateMutex();

Expand Down
4 changes: 2 additions & 2 deletions porting/himax/we2/el_serial_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ el_err_code_t SerialWE2::init() {
_console_uart->uart_open(UART_BAUDRATE_921600);

if (!_rb_rx) [[likely]]
_rb_rx = new lwRingBuffer{8192};
_rb_rx = new lwRingBuffer{(char*)SERIAL1_TRANSPORT_RX_BASE_ADDR, SERIAL1_TRANSPORT_RX_BASE_SIZE};

if (!_rb_tx) [[likely]]
_rb_tx = new lwRingBuffer{32768};
_rb_tx = new lwRingBuffer{(char*)SERIAL1_TRANSPORT_TX_BASE_ADDR, SERIAL1_TRANSPORT_TX_BASE_SIZE};

_mutex_tx = xSemaphoreCreateMutex();

Expand Down
4 changes: 2 additions & 2 deletions porting/himax/we2/el_wire_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ el_err_code_t WireWE2::init() {

this->_is_present = this->i2c ? true : false;

this->rx_ring_buffer = new lwRingBuffer(1024);
this->tx_ring_buffer = new lwRingBuffer(1024 * 24);
this->rx_ring_buffer = new lwRingBuffer((char*)WIRE_TRANSPORT_RX_BASE_ADDR, WIRE_TRANSPORT_RX_BASE_SIZE);
this->tx_ring_buffer = new lwRingBuffer((char*)WIRE_TRANSPORT_TX_BASE_ADDR, WIRE_TRANSPORT_TX_BASE_SIZE);

this->wire_read_enable(sizeof(this->tx_buffer));

Expand Down

0 comments on commit 44ab9c4

Please sign in to comment.