mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 13:07:03 +03:00
Network manager implemented and relatively stable
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
idf_component_register(SRC_DIRS .
|
||||
INCLUDE_DIRS . ${IDF_PATH}/components/driver
|
||||
REQUIRES json tools platform_config display
|
||||
REQUIRES json tools platform_config display wifi-manager
|
||||
PRIV_REQUIRES soc esp32 squeezelite
|
||||
)
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "trace.h"
|
||||
#include "monitor.h"
|
||||
#include "messaging.h"
|
||||
#include "network_ethernet.h"
|
||||
|
||||
|
||||
static const char *TAG = "services";
|
||||
@@ -62,6 +63,7 @@ static char * config_spdif_get_string(){
|
||||
",ws=" STR(CONFIG_SPDIF_WS_IO) ",do=" STR(CONFIG_SPDIF_DO_IO));
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
@@ -122,7 +124,6 @@ const i2s_platform_config_t * config_get_i2s_from_str(char * dac_config ){
|
||||
set_i2s_pin(dac_config, &i2s_dac_pin.pin);
|
||||
strcpy(i2s_dac_pin.model, "i2s");
|
||||
char * p=NULL;
|
||||
|
||||
if ((p = strcasestr(dac_config, "i2c")) != NULL) i2s_dac_pin.i2c_addr = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(dac_config, "sda")) != NULL) i2s_dac_pin.sda = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(dac_config, "scl")) != NULL) i2s_dac_pin.scl = atoi(strchr(p, '=') + 1);
|
||||
@@ -143,9 +144,8 @@ const eth_config_t * config_get_eth_from_str(char * eth_config ){
|
||||
char * p=NULL;
|
||||
static EXT_RAM_ATTR eth_config_t eth_pin;
|
||||
memset(ð_pin, 0xFF, sizeof(eth_pin));
|
||||
memset(ð_pin.model, 0xFF, sizeof(eth_pin.model));
|
||||
eth_pin.spi = false;
|
||||
eth_pin.rmii = false;
|
||||
memset(ð_pin.model, 0x00, sizeof(eth_pin.model));
|
||||
eth_pin.valid = true;
|
||||
|
||||
if ((p = strcasestr(eth_config, "model")) != NULL) sscanf(p, "%*[^=]=%15[^,]", eth_pin.model);
|
||||
if ((p = strcasestr(eth_config, "mdc")) != NULL) eth_pin.mdc = atoi(strchr(p, '=') + 1);
|
||||
@@ -158,15 +158,32 @@ const eth_config_t * config_get_eth_from_str(char * eth_config ){
|
||||
if ((p = strcasestr(eth_config, "speed")) != NULL) eth_pin.speed = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(eth_config, "clk")) != NULL) eth_pin.clk = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(eth_config, "host")) != NULL) eth_pin.host = atoi(strchr(p, '=') + 1);
|
||||
eth_pin.valid = eth_pin.model && strlen(eth_pin.model)>0 && GPIO_IS_VALID_GPIO(eth_pin.mdio) && GPIO_IS_VALID_GPIO(eth_pin.mdc);
|
||||
|
||||
if(strcasestr(eth_pin.model, "LAN8720")){
|
||||
eth_pin.rmii = true;
|
||||
|
||||
if(!eth_pin.model || strlen(eth_pin.model)==0){
|
||||
eth_pin.valid = false;
|
||||
return ð_pin;
|
||||
}
|
||||
else {
|
||||
eth_pin.spi = true;
|
||||
/* here we must also check that we have at least a CS gpio */
|
||||
eth_pin.valid = eth_pin.valid && GPIO_IS_VALID_GPIO(eth_pin.cs);
|
||||
network_ethernet_driver_t* network_driver = network_ethernet_driver_autodetect(eth_pin.model);
|
||||
if(!network_driver || !network_driver->valid){
|
||||
messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"Ethernet config invalid: model %s %s",eth_pin.model,network_driver?"was not compiled in":"was not found");
|
||||
eth_pin.valid = false;
|
||||
}
|
||||
if(network_driver){
|
||||
eth_pin.rmii = network_driver->rmii;
|
||||
eth_pin.spi = network_driver->spi;
|
||||
|
||||
if(network_driver->rmii){
|
||||
if(!GPIO_IS_VALID_GPIO(eth_pin.mdio) || !GPIO_IS_VALID_GPIO(eth_pin.mdc)){
|
||||
messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"Ethernet config invalid: %s %s",!GPIO_IS_VALID_GPIO(eth_pin.mdc)?"Invalid MDC":"",!GPIO_IS_VALID_GPIO(eth_pin.mdio)?"Invalid mdio":"");
|
||||
eth_pin.valid = false;
|
||||
}
|
||||
}
|
||||
else if(network_driver->spi){
|
||||
if(!GPIO_IS_VALID_GPIO(eth_pin.cs)){
|
||||
messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"Ethernet config invalid: invalid CS pin");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ð_pin;
|
||||
}
|
||||
@@ -216,10 +233,12 @@ const eth_config_t * config_eth_get( ){
|
||||
#endif
|
||||
#endif
|
||||
",mdc=" STR(CONFIG_ETH_MDC_IO) ",mdio=" STR(CONFIG_ETH_MDIO_IO)) ;
|
||||
if(config && strlen(config)>0){
|
||||
ESP_LOGD(TAG,"Parsing ethernet configuration %s", config);
|
||||
}
|
||||
static EXT_RAM_ATTR eth_config_t eth_config;
|
||||
ESP_LOGD(TAG, "Ethernet config string %s", config);
|
||||
memcpy(ð_config, config_get_eth_from_str(config), sizeof(eth_config));
|
||||
free(config);
|
||||
FREE_AND_NULL(config);
|
||||
return ð_config;
|
||||
}
|
||||
/****************************************************************************************
|
||||
@@ -236,7 +255,7 @@ void config_eth_init( eth_config_t * target ){
|
||||
esp_err_t config_i2c_set(const i2c_config_t * config, int port){
|
||||
int buffer_size=255;
|
||||
esp_err_t err=ESP_OK;
|
||||
char * config_buffer=calloc(buffer_size,1);
|
||||
char * config_buffer=malloc_init_external(buffer_size);
|
||||
if(config_buffer) {
|
||||
snprintf(config_buffer,buffer_size,"scl=%u,sda=%u,speed=%u,port=%u",config->scl_io_num,config->sda_io_num,config->master.clk_speed,port);
|
||||
log_send_messaging(MESSAGING_INFO,"Updating I2C configuration to %s",config_buffer);
|
||||
@@ -255,8 +274,8 @@ esp_err_t config_i2c_set(const i2c_config_t * config, int port){
|
||||
esp_err_t config_rotary_set(rotary_struct_t * config){
|
||||
int buffer_size=512;
|
||||
esp_err_t err=ESP_OK;
|
||||
char * config_buffer=calloc(buffer_size,1);
|
||||
char * config_buffer2=calloc(buffer_size,1);
|
||||
char * config_buffer=malloc_init_external(buffer_size);
|
||||
char * config_buffer2=malloc_init_external(buffer_size);
|
||||
if(config_buffer && config_buffer2) {
|
||||
snprintf(config_buffer,buffer_size,"A=%i,B=%i",config->A, config->B);
|
||||
if(config->SW >=0 ){
|
||||
@@ -296,8 +315,8 @@ esp_err_t config_rotary_set(rotary_struct_t * config){
|
||||
esp_err_t config_display_set(const display_config_t * config){
|
||||
int buffer_size=512;
|
||||
esp_err_t err=ESP_OK;
|
||||
char * config_buffer=calloc(buffer_size,1);
|
||||
char * config_buffer2=calloc(buffer_size,1);
|
||||
char * config_buffer=malloc_init_external(buffer_size);
|
||||
char * config_buffer2=malloc_init_external(buffer_size);
|
||||
if(config_buffer && config_buffer2) {
|
||||
snprintf(config_buffer,buffer_size,"%s,width=%i,height=%i",config->type,config->width,config->height);
|
||||
if(strcasecmp("I2C",config->type)==0){
|
||||
@@ -348,8 +367,8 @@ esp_err_t config_display_set(const display_config_t * config){
|
||||
esp_err_t config_i2s_set(const i2s_platform_config_t * config, const char * nvs_name){
|
||||
int buffer_size=255;
|
||||
esp_err_t err=ESP_OK;
|
||||
char * config_buffer=calloc(buffer_size,1);
|
||||
char * config_buffer2=calloc(buffer_size,1);
|
||||
char * config_buffer=malloc_init_external(buffer_size);
|
||||
char * config_buffer2=malloc_init_external(buffer_size);
|
||||
if(config_buffer && config_buffer2) {
|
||||
snprintf(config_buffer,buffer_size,"model=%s,bck=%u,ws=%u,do=%u",config->model,config->pin.bck_io_num,config->pin.ws_io_num,config->pin.data_out_num);
|
||||
if(config->mute_gpio>=0){
|
||||
@@ -384,7 +403,7 @@ esp_err_t config_i2s_set(const i2s_platform_config_t * config, const char * nvs_
|
||||
esp_err_t config_spdif_set(const i2s_platform_config_t * config){
|
||||
int buffer_size=255;
|
||||
esp_err_t err=ESP_OK;
|
||||
char * config_buffer=calloc(buffer_size,1);
|
||||
char * config_buffer=malloc_init_external(buffer_size);
|
||||
if(config_buffer ) {
|
||||
snprintf(config_buffer,buffer_size,"bck=%u,ws=%u,do=%u",config->pin.bck_io_num,config->pin.ws_io_num,config->pin.data_out_num);
|
||||
log_send_messaging(MESSAGING_INFO,"Updating SPDIF configuration to %s",config_buffer);
|
||||
@@ -406,7 +425,7 @@ esp_err_t config_spdif_set(const i2s_platform_config_t * config){
|
||||
esp_err_t config_spi_set(const spi_bus_config_t * config, int host, int dc){
|
||||
int buffer_size=255;
|
||||
esp_err_t err = ESP_OK;
|
||||
char * config_buffer=calloc(buffer_size,1);
|
||||
char * config_buffer=malloc_init_external(buffer_size);
|
||||
if(config_buffer) {
|
||||
snprintf(config_buffer,buffer_size,"data=%u,clk=%u,dc=%u,host=%u,miso=%d",config->mosi_io_num,config->sclk_io_num,dc,host,config->miso_io_num);
|
||||
log_send_messaging(MESSAGING_INFO,"Updating SPI configuration to %s",config_buffer);
|
||||
@@ -855,7 +874,7 @@ cJSON * get_Rotary_GPIO(cJSON * list){
|
||||
*/
|
||||
esp_err_t get_gpio_structure(cJSON * gpio_entry, gpio_entry_t ** gpio){
|
||||
esp_err_t err = ESP_OK;
|
||||
*gpio = malloc(sizeof(gpio_entry_t));
|
||||
*gpio = malloc_init_external(sizeof(gpio_entry_t));
|
||||
cJSON * val = cJSON_GetObjectItem(gpio_entry,"gpio");
|
||||
if(val){
|
||||
(*gpio)->gpio= (int)val->valuedouble;
|
||||
@@ -865,14 +884,14 @@ esp_err_t get_gpio_structure(cJSON * gpio_entry, gpio_entry_t ** gpio){
|
||||
}
|
||||
val = cJSON_GetObjectItem(gpio_entry,"name");
|
||||
if(val){
|
||||
(*gpio)->name= strdup(cJSON_GetStringValue(val));
|
||||
(*gpio)->name= strdup_psram(cJSON_GetStringValue(val));
|
||||
} else {
|
||||
ESP_LOGE(TAG,"gpio name value not found");
|
||||
err=ESP_FAIL;
|
||||
}
|
||||
val = cJSON_GetObjectItem(gpio_entry,"group");
|
||||
if(val){
|
||||
(*gpio)->group= strdup(cJSON_GetStringValue(val));
|
||||
(*gpio)->group= strdup_psram(cJSON_GetStringValue(val));
|
||||
} else {
|
||||
ESP_LOGE(TAG,"gpio group value not found");
|
||||
err=ESP_FAIL;
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "driver/i2c.h"
|
||||
#include "driver/i2s.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "freertos/queue.h"
|
||||
|
||||
extern const char *i2c_name_type;
|
||||
extern const char *spi_name_type;
|
||||
typedef struct {
|
||||
@@ -30,7 +32,7 @@ typedef struct {
|
||||
bool rotate;
|
||||
} display_config_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct eth_config_struct {
|
||||
char model[16];
|
||||
bool valid;
|
||||
bool rmii;
|
||||
@@ -98,6 +100,7 @@ const spi_bus_config_t * config_spi_get(spi_host_device_t * spi_host);
|
||||
void parse_set_GPIO(void (*cb)(int gpio, char *value));
|
||||
const i2s_platform_config_t * config_dac_get();
|
||||
const i2s_platform_config_t * config_spdif_get( );
|
||||
const i2s_platform_config_t * config_get_i2s_from_str(char * dac_config );
|
||||
esp_err_t config_spdif_set(const i2s_platform_config_t * config);
|
||||
bool is_spdif_config_locked();
|
||||
esp_err_t free_gpio_entry( gpio_entry_t ** gpio);
|
||||
|
||||
@@ -21,7 +21,6 @@ typedef struct {
|
||||
int timer, base_channel, max;
|
||||
} pwm_system_t;
|
||||
extern pwm_system_t pwm_system;
|
||||
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
#define ADAC dac_tas57xx
|
||||
#elif defined(CONFIG_A1S)
|
||||
@@ -29,3 +28,6 @@ extern pwm_system_t pwm_system;
|
||||
#else
|
||||
#define ADAC dac_external
|
||||
#endif
|
||||
void * malloc_init_external(size_t sz);
|
||||
void * clone_obj_psram(void * source, size_t source_sz);
|
||||
char * strdup_psram(const char * source);
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "platform_esp32.h"
|
||||
#include "messaging.h"
|
||||
#include "trace.h"
|
||||
#include "globdefs.h"
|
||||
/************************************
|
||||
* Globals
|
||||
*/
|
||||
@@ -38,7 +39,7 @@ messaging_handle_t get_handle_ptr(messaging_list_t * handle){
|
||||
|
||||
RingbufHandle_t messaging_create_ring_buffer(uint8_t max_count){
|
||||
RingbufHandle_t buf_handle = NULL;
|
||||
StaticRingbuffer_t *buffer_struct = malloc(sizeof(StaticRingbuffer_t));
|
||||
StaticRingbuffer_t *buffer_struct = malloc_init_external(sizeof(StaticRingbuffer_t));
|
||||
if (buffer_struct != NULL) {
|
||||
size_t buf_size = (size_t )(sizeof(single_message_t)+8+MSG_LENGTH_AVG)*(size_t )(max_count>0?max_count:5); // no-split buffer requires an additional 8 bytes
|
||||
buf_size = buf_size - (buf_size % 4);
|
||||
@@ -76,7 +77,7 @@ messaging_handle_t messaging_register_subscriber(uint8_t max_count, char * name)
|
||||
while(cur->next){
|
||||
cur = get_struct_ptr(cur->next);
|
||||
}
|
||||
cur->next=heap_caps_malloc(sizeof(messaging_list_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
cur->next=malloc_init_external(sizeof(messaging_list_t));
|
||||
if(!cur->next){
|
||||
ESP_LOGE(tag,"subscriber alloc failed");
|
||||
return NULL;
|
||||
@@ -84,7 +85,7 @@ messaging_handle_t messaging_register_subscriber(uint8_t max_count, char * name)
|
||||
memset(cur->next,0x00,sizeof(messaging_list_t));
|
||||
cur = get_struct_ptr(cur->next);
|
||||
cur->max_count=max_count;
|
||||
cur->subscriber_name=strdup(name);
|
||||
cur->subscriber_name=strdup_psram(name);
|
||||
cur->buf_handle = messaging_create_ring_buffer(max_count);
|
||||
if(cur->buf_handle){
|
||||
messaging_fill_messages(cur);
|
||||
@@ -99,7 +100,7 @@ void messaging_service_init(){
|
||||
}
|
||||
else {
|
||||
top.max_count = max_count;
|
||||
top.subscriber_name = strdup("messaging");
|
||||
top.subscriber_name = strdup_psram("messaging");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -161,10 +162,7 @@ single_message_t * messaging_retrieve_message(RingbufHandle_t buf_handle){
|
||||
vRingbufferGetInfo(buf_handle, NULL, NULL, NULL, NULL, &uxItemsWaiting);
|
||||
if(uxItemsWaiting>0){
|
||||
message = (single_message_t *)xRingbufferReceive(buf_handle, &item_size, pdMS_TO_TICKS(50));
|
||||
message_copy = heap_caps_malloc(item_size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if(message_copy){
|
||||
memcpy(message_copy,message,item_size);
|
||||
}
|
||||
message_copy = clone_obj_psram(message,item_size);
|
||||
vRingbufferReturnItem(buf_handle, (void *)message);
|
||||
}
|
||||
return message_copy;
|
||||
@@ -231,7 +229,7 @@ void messaging_post_message(messaging_types type,messaging_classes msg_class, co
|
||||
va_start(va, fmt);
|
||||
ln = vsnprintf(NULL, 0, fmt, va)+1;
|
||||
msg_size = sizeof(single_message_t)+ln;
|
||||
message = (single_message_t *)heap_caps_malloc(msg_size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
message = (single_message_t *)malloc_init_external(msg_size);
|
||||
vsprintf(message->message, fmt, va);
|
||||
va_end(va);
|
||||
message->msg_size = msg_size;
|
||||
@@ -256,11 +254,25 @@ void messaging_post_message(messaging_types type,messaging_classes msg_class, co
|
||||
return;
|
||||
|
||||
}
|
||||
char * messaging_alloc_format_string(const char *fmt, ...) {
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
size_t ln = vsnprintf(NULL, 0, fmt, va)+1;
|
||||
char * message_txt = malloc_init_external(ln);
|
||||
if(message_txt){
|
||||
vsprintf(message_txt, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
else{
|
||||
ESP_LOGE(tag, "Memory allocation failed while sending message");
|
||||
}
|
||||
return message_txt;
|
||||
}
|
||||
void log_send_messaging(messaging_types msgtype,const char *fmt, ...) {
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
size_t ln = vsnprintf(NULL, 0, fmt, va)+1;
|
||||
char * message_txt = malloc(ln);
|
||||
char * message_txt = malloc_init_external(ln);
|
||||
if(message_txt){
|
||||
vsprintf(message_txt, fmt, va);
|
||||
va_end(va);
|
||||
@@ -272,12 +284,13 @@ void log_send_messaging(messaging_types msgtype,const char *fmt, ...) {
|
||||
ESP_LOGE(tag, "Memory allocation failed while sending message");
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_send_messaging(const char * cmdname,messaging_types msgtype, const char *fmt, ...){
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
size_t cmd_len = strlen(cmdname)+1;
|
||||
size_t ln = vsnprintf(NULL, 0, fmt, va)+1;
|
||||
char * message_txt = malloc(ln+cmd_len);
|
||||
char * message_txt = malloc_init_external(ln+cmd_len);
|
||||
if(message_txt){
|
||||
strcpy(message_txt,cmdname);
|
||||
strcat(message_txt,"\n");
|
||||
|
||||
@@ -39,6 +39,7 @@ single_message_t * messaging_retrieve_message(RingbufHandle_t buf_handle);
|
||||
void log_send_messaging(messaging_types msgtype,const char *fmt, ...);
|
||||
void cmd_send_messaging(const char * cmdname,messaging_types msgtype, const char *fmt, ...);
|
||||
esp_err_t messaging_type_to_err_type(messaging_types type);
|
||||
char * messaging_alloc_format_string(const char *fmt, ...) ;
|
||||
void messaging_service_init();
|
||||
|
||||
#define REALLOC_CAT(e,n) e=realloc(e,strlen(n)); e=strcat(e,n)
|
||||
|
||||
@@ -54,7 +54,7 @@ static void task_stats( cJSON* top ) {
|
||||
} current, previous;
|
||||
cJSON * tlist=cJSON_CreateArray();
|
||||
current.n = uxTaskGetNumberOfTasks();
|
||||
current.tasks = malloc( current.n * sizeof( TaskStatus_t ) );
|
||||
current.tasks = malloc_init_external( current.n * sizeof( TaskStatus_t ) );
|
||||
current.n = uxTaskGetSystemState( current.tasks, current.n, ¤t.total );
|
||||
cJSON_AddNumberToObject(top,"ntasks",current.n);
|
||||
|
||||
@@ -126,11 +126,13 @@ static void monitor_callback(TimerHandle_t xTimer) {
|
||||
cJSON_AddNumberToObject(top,"free_spiram",heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
|
||||
cJSON_AddNumberToObject(top,"min_free_spiram",heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
|
||||
|
||||
ESP_LOGI(TAG, "Heap internal:%zu (min:%zu) external:%zu (min:%zu)",
|
||||
ESP_LOGI(TAG, "Heap internal:%zu (min:%zu) external:%zu (min:%zu) dma:%zu (min:%zu)",
|
||||
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_free_size(MALLOC_CAP_DMA),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_DMA));
|
||||
|
||||
task_stats(top);
|
||||
char * top_a= cJSON_PrintUnformatted(top);
|
||||
@@ -248,11 +250,13 @@ void monitor_svc_init(void) {
|
||||
}
|
||||
FREE_AND_NULL(p);
|
||||
|
||||
ESP_LOGI(TAG, "Heap internal:%zu (min:%zu) external:%zu (min:%zu)",
|
||||
ESP_LOGI(TAG, "Heap internal:%zu (min:%zu) external:%zu (min:%zu) dma:%zu (min:%zu)",
|
||||
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_free_size(MALLOC_CAP_DMA),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_DMA));
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
#include "globdefs.h"
|
||||
#include "accessors.h"
|
||||
#include "messaging.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
|
||||
extern void battery_svc_init(void);
|
||||
extern void monitor_svc_init(void);
|
||||
@@ -35,6 +38,43 @@ pwm_system_t pwm_system = {
|
||||
|
||||
static const char *TAG = "services";
|
||||
|
||||
|
||||
void * malloc_init_external(size_t sz){
|
||||
void * ptr=NULL;
|
||||
ptr = heap_caps_malloc(sz, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if(ptr==NULL){
|
||||
ESP_LOGE(TAG,"malloc_init_external: unable to allocate %d bytes of PSRAM!",sz);
|
||||
}
|
||||
else {
|
||||
memset(ptr,0x00,sz);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
void * clone_obj_psram(void * source, size_t source_sz){
|
||||
void * ptr=NULL;
|
||||
ptr = heap_caps_malloc(source_sz, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if(ptr==NULL){
|
||||
ESP_LOGE(TAG,"clone_obj_psram: unable to allocate %d bytes of PSRAM!",source_sz);
|
||||
}
|
||||
else {
|
||||
memcpy(ptr,source,source_sz);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
char * strdup_psram(const char * source){
|
||||
void * ptr=NULL;
|
||||
size_t source_sz = strlen(source)+1;
|
||||
ptr = heap_caps_malloc(source_sz, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if(ptr==NULL){
|
||||
ESP_LOGE(TAG,"strdup_psram: unable to allocate %d bytes of PSRAM! Cannot clone string %s",source_sz,source);
|
||||
}
|
||||
else {
|
||||
memset(ptr,0x00,source_sz);
|
||||
strcpy(ptr,source);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user