Merge branch 'bugfix/small_fixes_jd' into 'master'

Some small fixes

- Kill unused uxReturn in task.c,  https://github.com/espressif/esp-idf/issues/48
- Line end conversion in gpio.c
- Move heap_alloc_caps.h so components can also use it

See merge request !135
This commit is contained in:
Jeroen Domburg 2016-10-12 21:13:34 +08:00
commit fa476c8ba9
5 changed files with 549 additions and 516 deletions

View file

@ -1,368 +1,368 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <esp_types.h> #include <esp_types.h>
#include "esp_err.h" #include "esp_err.h"
#include "esp_intr.h" #include "esp_intr.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/xtensa_api.h" #include "freertos/xtensa_api.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "soc/soc.h" #include "soc/soc.h"
//TODO: move debug options to menuconfig //TODO: move debug options to menuconfig
#define GPIO_DBG_ENABLE (0) #define GPIO_DBG_ENABLE (0)
#define GPIO_WARNING_ENABLE (0) #define GPIO_WARNING_ENABLE (0)
#define GPIO_ERROR_ENABLE (0) #define GPIO_ERROR_ENABLE (0)
#define GPIO_INFO_ENABLE (0) #define GPIO_INFO_ENABLE (0)
//DBG INFOR //DBG INFOR
#if GPIO_INFO_ENABLE #if GPIO_INFO_ENABLE
#define GPIO_INFO ets_printf #define GPIO_INFO ets_printf
#else #else
#define GPIO_INFO(...) #define GPIO_INFO(...)
#endif #endif
#if GPIO_WARNING_ENABLE #if GPIO_WARNING_ENABLE
#define GPIO_WARNING(format,...) do{\ #define GPIO_WARNING(format,...) do{\
ets_printf("[waring][%s#%u]",__FUNCTION__,__LINE__);\ ets_printf("[waring][%s#%u]",__FUNCTION__,__LINE__);\
ets_printf(format,##__VA_ARGS__);\ ets_printf(format,##__VA_ARGS__);\
}while(0) }while(0)
#else #else
#define GPIO_WARNING(...) #define GPIO_WARNING(...)
#endif #endif
#if GPIO_ERROR_ENABLE #if GPIO_ERROR_ENABLE
#define GPIO_ERROR(format,...) do{\ #define GPIO_ERROR(format,...) do{\
ets_printf("[error][%s#%u]",__FUNCTION__,__LINE__);\ ets_printf("[error][%s#%u]",__FUNCTION__,__LINE__);\
ets_printf(format,##__VA_ARGS__);\ ets_printf(format,##__VA_ARGS__);\
}while(0) }while(0)
#else #else
#define GPIO_ERROR(...) #define GPIO_ERROR(...)
#endif #endif
const uint32_t GPIO_PIN_MUX_REG[GPIO_PIN_COUNT] = { const uint32_t GPIO_PIN_MUX_REG[GPIO_PIN_COUNT] = {
GPIO_PIN_REG_0, GPIO_PIN_REG_0,
GPIO_PIN_REG_1, GPIO_PIN_REG_1,
GPIO_PIN_REG_2, GPIO_PIN_REG_2,
GPIO_PIN_REG_3, GPIO_PIN_REG_3,
GPIO_PIN_REG_4, GPIO_PIN_REG_4,
GPIO_PIN_REG_5, GPIO_PIN_REG_5,
GPIO_PIN_REG_6, GPIO_PIN_REG_6,
GPIO_PIN_REG_7, GPIO_PIN_REG_7,
GPIO_PIN_REG_8, GPIO_PIN_REG_8,
GPIO_PIN_REG_9, GPIO_PIN_REG_9,
GPIO_PIN_REG_10, GPIO_PIN_REG_10,
GPIO_PIN_REG_11, GPIO_PIN_REG_11,
GPIO_PIN_REG_12, GPIO_PIN_REG_12,
GPIO_PIN_REG_13, GPIO_PIN_REG_13,
GPIO_PIN_REG_14, GPIO_PIN_REG_14,
GPIO_PIN_REG_15, GPIO_PIN_REG_15,
GPIO_PIN_REG_16, GPIO_PIN_REG_16,
GPIO_PIN_REG_17, GPIO_PIN_REG_17,
GPIO_PIN_REG_18, GPIO_PIN_REG_18,
GPIO_PIN_REG_19, GPIO_PIN_REG_19,
0, 0,
GPIO_PIN_REG_21, GPIO_PIN_REG_21,
GPIO_PIN_REG_22, GPIO_PIN_REG_22,
GPIO_PIN_REG_23, GPIO_PIN_REG_23,
0, 0,
GPIO_PIN_REG_25, GPIO_PIN_REG_25,
GPIO_PIN_REG_26, GPIO_PIN_REG_26,
GPIO_PIN_REG_27, GPIO_PIN_REG_27,
0, 0,
0, 0,
0, 0,
0, 0,
GPIO_PIN_REG_32, GPIO_PIN_REG_32,
GPIO_PIN_REG_33, GPIO_PIN_REG_33,
GPIO_PIN_REG_34, GPIO_PIN_REG_34,
GPIO_PIN_REG_35, GPIO_PIN_REG_35,
GPIO_PIN_REG_36, GPIO_PIN_REG_36,
GPIO_PIN_REG_37, GPIO_PIN_REG_37,
GPIO_PIN_REG_38, GPIO_PIN_REG_38,
GPIO_PIN_REG_39 GPIO_PIN_REG_39
}; };
static int is_valid_gpio(int gpio_num) static int is_valid_gpio(int gpio_num)
{ {
if(gpio_num >= GPIO_PIN_COUNT || GPIO_PIN_MUX_REG[gpio_num] == 0) { if(gpio_num >= GPIO_PIN_COUNT || GPIO_PIN_MUX_REG[gpio_num] == 0) {
GPIO_ERROR("GPIO io_num=%d does not exist\n",gpio_num); GPIO_ERROR("GPIO io_num=%d does not exist\n",gpio_num);
return 0; return 0;
} }
return 1; return 1;
} }
esp_err_t gpio_set_intr_type(gpio_num_t gpio_num, gpio_int_type_t intr_type) esp_err_t gpio_set_intr_type(gpio_num_t gpio_num, gpio_int_type_t intr_type)
{ {
if(!is_valid_gpio(gpio_num)) { if(!is_valid_gpio(gpio_num)) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
if(intr_type >= GPIO_INTR_MAX) { if(intr_type >= GPIO_INTR_MAX) {
GPIO_ERROR("Unknown GPIO intr:%u\n",intr_type); GPIO_ERROR("Unknown GPIO intr:%u\n",intr_type);
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
GPIO.pin[gpio_num].int_type = intr_type; GPIO.pin[gpio_num].int_type = intr_type;
return ESP_OK; return ESP_OK;
} }
esp_err_t gpio_intr_enable(gpio_num_t gpio_num) esp_err_t gpio_intr_enable(gpio_num_t gpio_num)
{ {
if(!is_valid_gpio(gpio_num)) { if(!is_valid_gpio(gpio_num)) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
if(xPortGetCoreID() == 0) { if(xPortGetCoreID() == 0) {
GPIO.pin[gpio_num].int_ena = GPIO_PRO_CPU_INTR_ENA; //enable pro cpu intr GPIO.pin[gpio_num].int_ena = GPIO_PRO_CPU_INTR_ENA; //enable pro cpu intr
} else { } else {
GPIO.pin[gpio_num].int_ena = GPIO_APP_CPU_INTR_ENA; //enable pro cpu intr GPIO.pin[gpio_num].int_ena = GPIO_APP_CPU_INTR_ENA; //enable pro cpu intr
} }
return ESP_OK; return ESP_OK;
} }
esp_err_t gpio_intr_disable(gpio_num_t gpio_num) esp_err_t gpio_intr_disable(gpio_num_t gpio_num)
{ {
if(!is_valid_gpio(gpio_num)) { if(!is_valid_gpio(gpio_num)) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
GPIO.pin[gpio_num].int_ena = 0; //disable GPIO intr GPIO.pin[gpio_num].int_ena = 0; //disable GPIO intr
return ESP_OK; return ESP_OK;
} }
static esp_err_t gpio_output_disable(gpio_num_t gpio_num) static esp_err_t gpio_output_disable(gpio_num_t gpio_num)
{ {
if(!is_valid_gpio(gpio_num)) { if(!is_valid_gpio(gpio_num)) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
if(gpio_num < 32) { if(gpio_num < 32) {
GPIO.enable_w1tc = (0x1 << gpio_num); GPIO.enable_w1tc = (0x1 << gpio_num);
} else { } else {
GPIO.enable1_w1tc.data = (0x1 << (gpio_num - 32)); GPIO.enable1_w1tc.data = (0x1 << (gpio_num - 32));
} }
return ESP_OK; return ESP_OK;
} }
static esp_err_t gpio_output_enable(gpio_num_t gpio_num) static esp_err_t gpio_output_enable(gpio_num_t gpio_num)
{ {
if(gpio_num >= 34) { if(gpio_num >= 34) {
GPIO_ERROR("io_num=%d can only be input\n",gpio_num); GPIO_ERROR("io_num=%d can only be input\n",gpio_num);
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
if(!is_valid_gpio(gpio_num)) { if(!is_valid_gpio(gpio_num)) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
if(gpio_num < 32) { if(gpio_num < 32) {
GPIO.enable_w1ts = (0x1 << gpio_num); GPIO.enable_w1ts = (0x1 << gpio_num);
} else { } else {
GPIO.enable1_w1ts.data = (0x1 << (gpio_num - 32)); GPIO.enable1_w1ts.data = (0x1 << (gpio_num - 32));
} }
return ESP_OK; return ESP_OK;
} }
esp_err_t gpio_set_level(gpio_num_t gpio_num, uint32_t level) esp_err_t gpio_set_level(gpio_num_t gpio_num, uint32_t level)
{ {
if(!GPIO_IS_VALID_GPIO(gpio_num)) { if(!GPIO_IS_VALID_GPIO(gpio_num)) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
if(level) { if(level) {
if(gpio_num < 32) { if(gpio_num < 32) {
GPIO.out_w1ts = (1 << gpio_num); GPIO.out_w1ts = (1 << gpio_num);
} else { } else {
GPIO.out1_w1ts.data = (1 << (gpio_num - 32)); GPIO.out1_w1ts.data = (1 << (gpio_num - 32));
} }
} else { } else {
if(gpio_num < 32) { if(gpio_num < 32) {
GPIO.out_w1tc = (1 << gpio_num); GPIO.out_w1tc = (1 << gpio_num);
} else { } else {
GPIO.out1_w1tc.data = (1 << (gpio_num - 32)); GPIO.out1_w1tc.data = (1 << (gpio_num - 32));
} }
} }
return ESP_OK; return ESP_OK;
} }
int gpio_get_level(gpio_num_t gpio_num) int gpio_get_level(gpio_num_t gpio_num)
{ {
if(gpio_num < 32) { if(gpio_num < 32) {
return (GPIO.in >> gpio_num) & 0x1; return (GPIO.in >> gpio_num) & 0x1;
} else { } else {
return (GPIO.in1.data >> (gpio_num - 32)) & 0x1; return (GPIO.in1.data >> (gpio_num - 32)) & 0x1;
} }
} }
esp_err_t gpio_set_pull_mode(gpio_num_t gpio_num, gpio_pull_mode_t pull) esp_err_t gpio_set_pull_mode(gpio_num_t gpio_num, gpio_pull_mode_t pull)
{ {
if(!is_valid_gpio(gpio_num)) { if(!is_valid_gpio(gpio_num)) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
switch(pull) { switch(pull) {
case GPIO_PULLUP_ONLY: case GPIO_PULLUP_ONLY:
PIN_PULLUP_EN(GPIO_PIN_MUX_REG[gpio_num]); PIN_PULLUP_EN(GPIO_PIN_MUX_REG[gpio_num]);
PIN_PULLDWN_DIS(GPIO_PIN_MUX_REG[gpio_num]); PIN_PULLDWN_DIS(GPIO_PIN_MUX_REG[gpio_num]);
break; break;
case GPIO_PULLDOWN_ONLY: case GPIO_PULLDOWN_ONLY:
PIN_PULLUP_DIS(GPIO_PIN_MUX_REG[gpio_num]); PIN_PULLUP_DIS(GPIO_PIN_MUX_REG[gpio_num]);
PIN_PULLDWN_EN(GPIO_PIN_MUX_REG[gpio_num]); PIN_PULLDWN_EN(GPIO_PIN_MUX_REG[gpio_num]);
break; break;
case GPIO_PULLUP_PULLDOWN: case GPIO_PULLUP_PULLDOWN:
PIN_PULLUP_EN(GPIO_PIN_MUX_REG[gpio_num]); PIN_PULLUP_EN(GPIO_PIN_MUX_REG[gpio_num]);
PIN_PULLDWN_EN(GPIO_PIN_MUX_REG[gpio_num]); PIN_PULLDWN_EN(GPIO_PIN_MUX_REG[gpio_num]);
break; break;
case GPIO_FLOATING: case GPIO_FLOATING:
PIN_PULLUP_DIS(GPIO_PIN_MUX_REG[gpio_num]); PIN_PULLUP_DIS(GPIO_PIN_MUX_REG[gpio_num]);
PIN_PULLDWN_DIS(GPIO_PIN_MUX_REG[gpio_num]); PIN_PULLDWN_DIS(GPIO_PIN_MUX_REG[gpio_num]);
break; break;
default: default:
GPIO_ERROR("Unknown pull up/down mode,gpio_num=%u,pull=%u\n",gpio_num,pull); GPIO_ERROR("Unknown pull up/down mode,gpio_num=%u,pull=%u\n",gpio_num,pull);
ret = ESP_ERR_INVALID_ARG; ret = ESP_ERR_INVALID_ARG;
break; break;
} }
return ret; return ret;
} }
esp_err_t gpio_set_direction(gpio_num_t gpio_num, gpio_mode_t mode) esp_err_t gpio_set_direction(gpio_num_t gpio_num, gpio_mode_t mode)
{ {
if(!is_valid_gpio(gpio_num)) { if(!is_valid_gpio(gpio_num)) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
if(gpio_num >= 34 && (mode & (GPIO_MODE_DEF_OUTPUT))) { if(gpio_num >= 34 && (mode & (GPIO_MODE_DEF_OUTPUT))) {
GPIO_ERROR("io_num=%d can only be input\n",gpio_num); GPIO_ERROR("io_num=%d can only be input\n",gpio_num);
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
if(mode & GPIO_MODE_DEF_INPUT) { if(mode & GPIO_MODE_DEF_INPUT) {
PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[gpio_num]); PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[gpio_num]);
} else { } else {
PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[gpio_num]); PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[gpio_num]);
} }
if(mode & GPIO_MODE_DEF_OUTPUT) { if(mode & GPIO_MODE_DEF_OUTPUT) {
if(gpio_num < 32) { if(gpio_num < 32) {
GPIO.enable_w1ts = (0x1 << gpio_num); GPIO.enable_w1ts = (0x1 << gpio_num);
} else { } else {
GPIO.enable1_w1ts.data = (0x1 << (gpio_num - 32)); GPIO.enable1_w1ts.data = (0x1 << (gpio_num - 32));
} }
} else { } else {
if(gpio_num < 32) { if(gpio_num < 32) {
GPIO.enable_w1tc = (0x1 << gpio_num); GPIO.enable_w1tc = (0x1 << gpio_num);
} else { } else {
GPIO.enable1_w1tc.data = (0x1 << (gpio_num - 32)); GPIO.enable1_w1tc.data = (0x1 << (gpio_num - 32));
} }
} }
if(mode & GPIO_MODE_DEF_OD) { if(mode & GPIO_MODE_DEF_OD) {
GPIO.pin[gpio_num].pad_driver = 1; GPIO.pin[gpio_num].pad_driver = 1;
} else { } else {
GPIO.pin[gpio_num].pad_driver = 0; GPIO.pin[gpio_num].pad_driver = 0;
} }
return ret; return ret;
} }
esp_err_t gpio_config(gpio_config_t *pGPIOConfig) esp_err_t gpio_config(gpio_config_t *pGPIOConfig)
{ {
uint64_t gpio_pin_mask = (pGPIOConfig->pin_bit_mask); uint64_t gpio_pin_mask = (pGPIOConfig->pin_bit_mask);
uint32_t io_reg = 0; uint32_t io_reg = 0;
uint32_t io_num = 0; uint32_t io_num = 0;
uint64_t bit_valid = 0; uint64_t bit_valid = 0;
if(pGPIOConfig->pin_bit_mask == 0 || pGPIOConfig->pin_bit_mask >= (((uint64_t) 1) << GPIO_PIN_COUNT)) { if(pGPIOConfig->pin_bit_mask == 0 || pGPIOConfig->pin_bit_mask >= (((uint64_t) 1) << GPIO_PIN_COUNT)) {
GPIO_ERROR("GPIO_PIN mask error \n"); GPIO_ERROR("GPIO_PIN mask error \n");
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
if((pGPIOConfig->mode) & (GPIO_MODE_DEF_OUTPUT)) { if((pGPIOConfig->mode) & (GPIO_MODE_DEF_OUTPUT)) {
//GPIO 34/35/36/37/38/39 can only be used as input mode; //GPIO 34/35/36/37/38/39 can only be used as input mode;
if((gpio_pin_mask & ( GPIO_SEL_34 | GPIO_SEL_35 | GPIO_SEL_36 | GPIO_SEL_37 | GPIO_SEL_38 | GPIO_SEL_39))) { if((gpio_pin_mask & ( GPIO_SEL_34 | GPIO_SEL_35 | GPIO_SEL_36 | GPIO_SEL_37 | GPIO_SEL_38 | GPIO_SEL_39))) {
GPIO_ERROR("GPIO34-39 can only be used as input mode\n"); GPIO_ERROR("GPIO34-39 can only be used as input mode\n");
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
} }
do { do {
io_reg = GPIO_PIN_MUX_REG[io_num]; io_reg = GPIO_PIN_MUX_REG[io_num];
if(((gpio_pin_mask >> io_num) & BIT(0)) && io_reg) { if(((gpio_pin_mask >> io_num) & BIT(0)) && io_reg) {
GPIO_INFO("Gpio%02d |Mode:",io_num); GPIO_INFO("Gpio%02d |Mode:",io_num);
if((pGPIOConfig->mode) & GPIO_MODE_DEF_INPUT) { if((pGPIOConfig->mode) & GPIO_MODE_DEF_INPUT) {
GPIO_INFO("INPUT "); GPIO_INFO("INPUT ");
PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[io_num]); PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[io_num]);
} else { } else {
PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[io_num]); PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[io_num]);
} }
if((pGPIOConfig->mode) & GPIO_MODE_DEF_OD) { if((pGPIOConfig->mode) & GPIO_MODE_DEF_OD) {
GPIO_INFO("OD "); GPIO_INFO("OD ");
GPIO.pin[io_num].pad_driver = 1; /*0x01 Open-drain */ GPIO.pin[io_num].pad_driver = 1; /*0x01 Open-drain */
} else { } else {
GPIO.pin[io_num].pad_driver = 0; /*0x00 Normal gpio output */ GPIO.pin[io_num].pad_driver = 0; /*0x00 Normal gpio output */
} }
if((pGPIOConfig->mode) & GPIO_MODE_DEF_OUTPUT) { if((pGPIOConfig->mode) & GPIO_MODE_DEF_OUTPUT) {
GPIO_INFO("OUTPUT "); GPIO_INFO("OUTPUT ");
gpio_output_enable(io_num); gpio_output_enable(io_num);
} else { } else {
gpio_output_disable(io_num); gpio_output_disable(io_num);
} }
GPIO_INFO("|"); GPIO_INFO("|");
if(pGPIOConfig->pull_up_en) { if(pGPIOConfig->pull_up_en) {
GPIO_INFO("PU "); GPIO_INFO("PU ");
PIN_PULLUP_EN(io_reg); PIN_PULLUP_EN(io_reg);
} else { } else {
PIN_PULLUP_DIS(io_reg); PIN_PULLUP_DIS(io_reg);
} }
if(pGPIOConfig->pull_down_en) { if(pGPIOConfig->pull_down_en) {
GPIO_INFO("PD "); GPIO_INFO("PD ");
PIN_PULLDWN_EN(io_reg); PIN_PULLDWN_EN(io_reg);
} else { } else {
PIN_PULLDWN_DIS(io_reg); PIN_PULLDWN_DIS(io_reg);
} }
GPIO_INFO("Intr:%d |\n",pGPIOConfig->intr_type); GPIO_INFO("Intr:%d |\n",pGPIOConfig->intr_type);
gpio_set_intr_type(io_num, pGPIOConfig->intr_type); gpio_set_intr_type(io_num, pGPIOConfig->intr_type);
if(pGPIOConfig->intr_type) { if(pGPIOConfig->intr_type) {
gpio_intr_enable(io_num); gpio_intr_enable(io_num);
} else { } else {
gpio_intr_disable(io_num); gpio_intr_disable(io_num);
} }
PIN_FUNC_SELECT(io_reg, PIN_FUNC_GPIO); /*function number 2 is GPIO_FUNC for each pin */ PIN_FUNC_SELECT(io_reg, PIN_FUNC_GPIO); /*function number 2 is GPIO_FUNC for each pin */
} else if(bit_valid && (io_reg == 0)) { } else if(bit_valid && (io_reg == 0)) {
GPIO_WARNING("io_num=%d does not exist\n",io_num); GPIO_WARNING("io_num=%d does not exist\n",io_num);
} }
io_num++; io_num++;
} while(io_num < GPIO_PIN_COUNT); } while(io_num < GPIO_PIN_COUNT);
return ESP_OK; return ESP_OK;
} }
esp_err_t gpio_isr_register(uint32_t gpio_intr_num, void (*fn)(void*), void * arg) esp_err_t gpio_isr_register(uint32_t gpio_intr_num, void (*fn)(void*), void * arg)
{ {
if(fn == NULL) { if(fn == NULL) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
ESP_INTR_DISABLE(gpio_intr_num); ESP_INTR_DISABLE(gpio_intr_num);
intr_matrix_set(xPortGetCoreID(), ETS_GPIO_INTR_SOURCE, gpio_intr_num); intr_matrix_set(xPortGetCoreID(), ETS_GPIO_INTR_SOURCE, gpio_intr_num);
xt_set_interrupt_handler(gpio_intr_num, fn, arg); xt_set_interrupt_handler(gpio_intr_num, fn, arg);
ESP_INTR_ENABLE(gpio_intr_num); ESP_INTR_ENABLE(gpio_intr_num);
return ESP_OK; return ESP_OK;
} }
/*only level interrupt can be used for wake-up function*/ /*only level interrupt can be used for wake-up function*/
esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type) esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type)
{ {
if(!is_valid_gpio(gpio_num)) { if(!is_valid_gpio(gpio_num)) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
if((intr_type == GPIO_INTR_LOW_LEVEL) || (intr_type == GPIO_INTR_HIGH_LEVEL)) { if((intr_type == GPIO_INTR_LOW_LEVEL) || (intr_type == GPIO_INTR_HIGH_LEVEL)) {
GPIO.pin[gpio_num].int_type = intr_type; GPIO.pin[gpio_num].int_type = intr_type;
GPIO.pin[gpio_num].wakeup_enable = 0x1; GPIO.pin[gpio_num].wakeup_enable = 0x1;
} else { } else {
GPIO_ERROR("GPIO wakeup only support Level mode,but edge mode set. gpio_num:%u\n",gpio_num); GPIO_ERROR("GPIO wakeup only support Level mode,but edge mode set. gpio_num:%u\n",gpio_num);
ret = ESP_ERR_INVALID_ARG; ret = ESP_ERR_INVALID_ARG;
} }
return ret; return ret;
} }
esp_err_t gpio_wakeup_disable(gpio_num_t gpio_num) esp_err_t gpio_wakeup_disable(gpio_num_t gpio_num)
{ {
if(!is_valid_gpio(gpio_num)) { if(!is_valid_gpio(gpio_num)) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
GPIO.pin[gpio_num].wakeup_enable = 0; GPIO.pin[gpio_num].wakeup_enable = 0;
return ESP_OK; return ESP_OK;
} }

View file

@ -15,7 +15,7 @@
#include <freertos/heap_regions.h> #include <freertos/heap_regions.h>
#include "heap_alloc_caps.h" #include "esp_heap_alloc_caps.h"
#include "spiram.h" #include "spiram.h"
#include "esp_log.h" #include "esp_log.h"
@ -40,23 +40,23 @@ Tag descriptors. These describe the capabilities of a bit of memory that's tagge
Each tag contains NO_PRIOS entries; later entries are only taken if earlier ones can't fulfill the memory request. Each tag contains NO_PRIOS entries; later entries are only taken if earlier ones can't fulfill the memory request.
*/ */
static const uint32_t tagDesc[][NO_PRIOS]={ static const uint32_t tagDesc[][NO_PRIOS]={
{ MALLOC_CAP_DMA|MALLOC_CAP_8BIT, MALLOC_CAP_32BIT, 0 }, //Tag 0: Plain ole D-port RAM { MALLOC_CAP_DMA|MALLOC_CAP_8BIT, MALLOC_CAP_32BIT, 0 }, //Tag 0: Plain ole D-port RAM
{ 0, MALLOC_CAP_DMA|MALLOC_CAP_8BIT, MALLOC_CAP_32BIT|MALLOC_CAP_EXEC }, //Tag 1: Plain ole D-port RAM which has an alias on the I-port { 0, MALLOC_CAP_DMA|MALLOC_CAP_8BIT, MALLOC_CAP_32BIT|MALLOC_CAP_EXEC }, //Tag 1: Plain ole D-port RAM which has an alias on the I-port
{ MALLOC_CAP_EXEC|MALLOC_CAP_32BIT, 0, 0 }, //Tag 2: IRAM { MALLOC_CAP_EXEC|MALLOC_CAP_32BIT, 0, 0 }, //Tag 2: IRAM
{ MALLOC_CAP_PID2, 0, MALLOC_CAP_EXEC|MALLOC_CAP_32BIT }, //Tag 3-8: PID 2-7 IRAM { MALLOC_CAP_PID2, 0, MALLOC_CAP_EXEC|MALLOC_CAP_32BIT }, //Tag 3-8: PID 2-7 IRAM
{ MALLOC_CAP_PID3, 0, MALLOC_CAP_EXEC|MALLOC_CAP_32BIT }, // { MALLOC_CAP_PID3, 0, MALLOC_CAP_EXEC|MALLOC_CAP_32BIT }, //
{ MALLOC_CAP_PID4, 0, MALLOC_CAP_EXEC|MALLOC_CAP_32BIT }, // { MALLOC_CAP_PID4, 0, MALLOC_CAP_EXEC|MALLOC_CAP_32BIT }, //
{ MALLOC_CAP_PID5, 0, MALLOC_CAP_EXEC|MALLOC_CAP_32BIT }, // { MALLOC_CAP_PID5, 0, MALLOC_CAP_EXEC|MALLOC_CAP_32BIT }, //
{ MALLOC_CAP_PID6, 0, MALLOC_CAP_EXEC|MALLOC_CAP_32BIT }, // { MALLOC_CAP_PID6, 0, MALLOC_CAP_EXEC|MALLOC_CAP_32BIT }, //
{ MALLOC_CAP_PID7, 0, MALLOC_CAP_EXEC|MALLOC_CAP_32BIT }, // { MALLOC_CAP_PID7, 0, MALLOC_CAP_EXEC|MALLOC_CAP_32BIT }, //
{ MALLOC_CAP_PID2, MALLOC_CAP_8BIT, MALLOC_CAP_32BIT }, //Tag 9-14: PID 2-7 DRAM { MALLOC_CAP_PID2, MALLOC_CAP_8BIT, MALLOC_CAP_32BIT }, //Tag 9-14: PID 2-7 DRAM
{ MALLOC_CAP_PID3, MALLOC_CAP_8BIT, MALLOC_CAP_32BIT }, // { MALLOC_CAP_PID3, MALLOC_CAP_8BIT, MALLOC_CAP_32BIT }, //
{ MALLOC_CAP_PID4, MALLOC_CAP_8BIT, MALLOC_CAP_32BIT }, // { MALLOC_CAP_PID4, MALLOC_CAP_8BIT, MALLOC_CAP_32BIT }, //
{ MALLOC_CAP_PID5, MALLOC_CAP_8BIT, MALLOC_CAP_32BIT }, // { MALLOC_CAP_PID5, MALLOC_CAP_8BIT, MALLOC_CAP_32BIT }, //
{ MALLOC_CAP_PID6, MALLOC_CAP_8BIT, MALLOC_CAP_32BIT }, // { MALLOC_CAP_PID6, MALLOC_CAP_8BIT, MALLOC_CAP_32BIT }, //
{ MALLOC_CAP_PID7, MALLOC_CAP_8BIT, MALLOC_CAP_32BIT }, // { MALLOC_CAP_PID7, MALLOC_CAP_8BIT, MALLOC_CAP_32BIT }, //
{ MALLOC_CAP_SPISRAM, 0, MALLOC_CAP_DMA|MALLOC_CAP_8BIT|MALLOC_CAP_32BIT}, //Tag 15: SPI SRAM data { MALLOC_CAP_SPISRAM, 0, MALLOC_CAP_DMA|MALLOC_CAP_8BIT|MALLOC_CAP_32BIT}, //Tag 15: SPI SRAM data
{ MALLOC_CAP_INVALID, MALLOC_CAP_INVALID, MALLOC_CAP_INVALID } //End { MALLOC_CAP_INVALID, MALLOC_CAP_INVALID, MALLOC_CAP_INVALID } //End
}; };
/* /*
@ -79,81 +79,81 @@ be sorted from low to high start address.
This array is *NOT* const because it gets modified depending on what pools are/aren't available. This array is *NOT* const because it gets modified depending on what pools are/aren't available.
*/ */
static HeapRegionTagged_t regions[]={ static HeapRegionTagged_t regions[]={
{ (uint8_t *)0x3F800000, 0x20000, 15, 0}, //SPI SRAM, if available { (uint8_t *)0x3F800000, 0x20000, 15, 0}, //SPI SRAM, if available
{ (uint8_t *)0x3FFAE000, 0x2000, 0, 0}, //pool 16 <- used for rom code { (uint8_t *)0x3FFAE000, 0x2000, 0, 0}, //pool 16 <- used for rom code
{ (uint8_t *)0x3FFB0000, 0x8000, 0, 0}, //pool 15 <- can be used for BT { (uint8_t *)0x3FFB0000, 0x8000, 0, 0}, //pool 15 <- can be used for BT
{ (uint8_t *)0x3FFB8000, 0x8000, 0, 0}, //pool 14 <- can be used for BT { (uint8_t *)0x3FFB8000, 0x8000, 0, 0}, //pool 14 <- can be used for BT
{ (uint8_t *)0x3FFC0000, 0x2000, 0, 0}, //pool 10-13, mmu page 0 { (uint8_t *)0x3FFC0000, 0x2000, 0, 0}, //pool 10-13, mmu page 0
{ (uint8_t *)0x3FFC2000, 0x2000, 0, 0}, //pool 10-13, mmu page 1 { (uint8_t *)0x3FFC2000, 0x2000, 0, 0}, //pool 10-13, mmu page 1
{ (uint8_t *)0x3FFC4000, 0x2000, 0, 0}, //pool 10-13, mmu page 2 { (uint8_t *)0x3FFC4000, 0x2000, 0, 0}, //pool 10-13, mmu page 2
{ (uint8_t *)0x3FFC6000, 0x2000, 0, 0}, //pool 10-13, mmu page 3 { (uint8_t *)0x3FFC6000, 0x2000, 0, 0}, //pool 10-13, mmu page 3
{ (uint8_t *)0x3FFC8000, 0x2000, 0, 0}, //pool 10-13, mmu page 4 { (uint8_t *)0x3FFC8000, 0x2000, 0, 0}, //pool 10-13, mmu page 4
{ (uint8_t *)0x3FFCA000, 0x2000, 0, 0}, //pool 10-13, mmu page 5 { (uint8_t *)0x3FFCA000, 0x2000, 0, 0}, //pool 10-13, mmu page 5
{ (uint8_t *)0x3FFCC000, 0x2000, 0, 0}, //pool 10-13, mmu page 6 { (uint8_t *)0x3FFCC000, 0x2000, 0, 0}, //pool 10-13, mmu page 6
{ (uint8_t *)0x3FFCE000, 0x2000, 0, 0}, //pool 10-13, mmu page 7 { (uint8_t *)0x3FFCE000, 0x2000, 0, 0}, //pool 10-13, mmu page 7
{ (uint8_t *)0x3FFD0000, 0x2000, 0, 0}, //pool 10-13, mmu page 8 { (uint8_t *)0x3FFD0000, 0x2000, 0, 0}, //pool 10-13, mmu page 8
{ (uint8_t *)0x3FFD2000, 0x2000, 0, 0}, //pool 10-13, mmu page 9 { (uint8_t *)0x3FFD2000, 0x2000, 0, 0}, //pool 10-13, mmu page 9
{ (uint8_t *)0x3FFD4000, 0x2000, 0, 0}, //pool 10-13, mmu page 10 { (uint8_t *)0x3FFD4000, 0x2000, 0, 0}, //pool 10-13, mmu page 10
{ (uint8_t *)0x3FFD6000, 0x2000, 0, 0}, //pool 10-13, mmu page 11 { (uint8_t *)0x3FFD6000, 0x2000, 0, 0}, //pool 10-13, mmu page 11
{ (uint8_t *)0x3FFD8000, 0x2000, 0, 0}, //pool 10-13, mmu page 12 { (uint8_t *)0x3FFD8000, 0x2000, 0, 0}, //pool 10-13, mmu page 12
{ (uint8_t *)0x3FFDA000, 0x2000, 0, 0}, //pool 10-13, mmu page 13 { (uint8_t *)0x3FFDA000, 0x2000, 0, 0}, //pool 10-13, mmu page 13
{ (uint8_t *)0x3FFDC000, 0x2000, 0, 0}, //pool 10-13, mmu page 14 { (uint8_t *)0x3FFDC000, 0x2000, 0, 0}, //pool 10-13, mmu page 14
{ (uint8_t *)0x3FFDE000, 0x2000, 0, 0}, //pool 10-13, mmu page 15 { (uint8_t *)0x3FFDE000, 0x2000, 0, 0}, //pool 10-13, mmu page 15
{ (uint8_t *)0x3FFE0000, 0x4000, 1, 0x400BC000}, //pool 9 blk 1 { (uint8_t *)0x3FFE0000, 0x4000, 1, 0x400BC000}, //pool 9 blk 1
{ (uint8_t *)0x3FFE4000, 0x4000, 1, 0x400B8000}, //pool 9 blk 0 { (uint8_t *)0x3FFE4000, 0x4000, 1, 0x400B8000}, //pool 9 blk 0
{ (uint8_t *)0x3FFE8000, 0x8000, 1, 0x400B0000}, //pool 8 <- can be remapped to ROM, used for MAC dump { (uint8_t *)0x3FFE8000, 0x8000, 1, 0x400B0000}, //pool 8 <- can be remapped to ROM, used for MAC dump
{ (uint8_t *)0x3FFF0000, 0x8000, 1, 0x400A8000}, //pool 7 <- can be used for MAC dump { (uint8_t *)0x3FFF0000, 0x8000, 1, 0x400A8000}, //pool 7 <- can be used for MAC dump
{ (uint8_t *)0x3FFF8000, 0x4000, 1, 0x400A4000}, //pool 6 blk 1 <- can be used as trace memory { (uint8_t *)0x3FFF8000, 0x4000, 1, 0x400A4000}, //pool 6 blk 1 <- can be used as trace memory
{ (uint8_t *)0x3FFFC000, 0x4000, 1, 0x400A0000}, //pool 6 blk 0 <- can be used as trace memory { (uint8_t *)0x3FFFC000, 0x4000, 1, 0x400A0000}, //pool 6 blk 0 <- can be used as trace memory
{ (uint8_t *)0x40070000, 0x8000, 2, 0}, //pool 0 { (uint8_t *)0x40070000, 0x8000, 2, 0}, //pool 0
{ (uint8_t *)0x40078000, 0x8000, 2, 0}, //pool 1 { (uint8_t *)0x40078000, 0x8000, 2, 0}, //pool 1
{ (uint8_t *)0x40080000, 0x2000, 2, 0}, //pool 2-5, mmu page 0 { (uint8_t *)0x40080000, 0x2000, 2, 0}, //pool 2-5, mmu page 0
{ (uint8_t *)0x40082000, 0x2000, 2, 0}, //pool 2-5, mmu page 1 { (uint8_t *)0x40082000, 0x2000, 2, 0}, //pool 2-5, mmu page 1
{ (uint8_t *)0x40084000, 0x2000, 2, 0}, //pool 2-5, mmu page 2 { (uint8_t *)0x40084000, 0x2000, 2, 0}, //pool 2-5, mmu page 2
{ (uint8_t *)0x40086000, 0x2000, 2, 0}, //pool 2-5, mmu page 3 { (uint8_t *)0x40086000, 0x2000, 2, 0}, //pool 2-5, mmu page 3
{ (uint8_t *)0x40088000, 0x2000, 2, 0}, //pool 2-5, mmu page 4 { (uint8_t *)0x40088000, 0x2000, 2, 0}, //pool 2-5, mmu page 4
{ (uint8_t *)0x4008A000, 0x2000, 2, 0}, //pool 2-5, mmu page 5 { (uint8_t *)0x4008A000, 0x2000, 2, 0}, //pool 2-5, mmu page 5
{ (uint8_t *)0x4008C000, 0x2000, 2, 0}, //pool 2-5, mmu page 6 { (uint8_t *)0x4008C000, 0x2000, 2, 0}, //pool 2-5, mmu page 6
{ (uint8_t *)0x4008E000, 0x2000, 2, 0}, //pool 2-5, mmu page 7 { (uint8_t *)0x4008E000, 0x2000, 2, 0}, //pool 2-5, mmu page 7
{ (uint8_t *)0x40090000, 0x2000, 2, 0}, //pool 2-5, mmu page 8 { (uint8_t *)0x40090000, 0x2000, 2, 0}, //pool 2-5, mmu page 8
{ (uint8_t *)0x40092000, 0x2000, 2, 0}, //pool 2-5, mmu page 9 { (uint8_t *)0x40092000, 0x2000, 2, 0}, //pool 2-5, mmu page 9
{ (uint8_t *)0x40094000, 0x2000, 2, 0}, //pool 2-5, mmu page 10 { (uint8_t *)0x40094000, 0x2000, 2, 0}, //pool 2-5, mmu page 10
{ (uint8_t *)0x40096000, 0x2000, 2, 0}, //pool 2-5, mmu page 11 { (uint8_t *)0x40096000, 0x2000, 2, 0}, //pool 2-5, mmu page 11
{ (uint8_t *)0x40098000, 0x2000, 2, 0}, //pool 2-5, mmu page 12 { (uint8_t *)0x40098000, 0x2000, 2, 0}, //pool 2-5, mmu page 12
{ (uint8_t *)0x4009A000, 0x2000, 2, 0}, //pool 2-5, mmu page 13 { (uint8_t *)0x4009A000, 0x2000, 2, 0}, //pool 2-5, mmu page 13
{ (uint8_t *)0x4009C000, 0x2000, 2, 0}, //pool 2-5, mmu page 14 { (uint8_t *)0x4009C000, 0x2000, 2, 0}, //pool 2-5, mmu page 14
{ (uint8_t *)0x4009E000, 0x2000, 2, 0}, //pool 2-5, mmu page 15 { (uint8_t *)0x4009E000, 0x2000, 2, 0}, //pool 2-5, mmu page 15
{ NULL, 0, 0, 0} //end { NULL, 0, 0, 0} //end
}; };
//Modify regions array to disable the given range of memory. //Modify regions array to disable the given range of memory.
static void disable_mem_region(void *from, void *to) { static void disable_mem_region(void *from, void *to) {
int i; int i;
//Align from and to on word boundaries //Align from and to on word boundaries
from=(void*)((uint32_t)from&~3); from=(void*)((uint32_t)from&~3);
to=(void*)(((uint32_t)to+3)&~3); to=(void*)(((uint32_t)to+3)&~3);
for (i=0; regions[i].xSizeInBytes!=0; i++) { for (i=0; regions[i].xSizeInBytes!=0; i++) {
void *regStart=regions[i].pucStartAddress; void *regStart=regions[i].pucStartAddress;
void *regEnd=regions[i].pucStartAddress+regions[i].xSizeInBytes; void *regEnd=regions[i].pucStartAddress+regions[i].xSizeInBytes;
if (regStart>=from && regEnd<=to) { if (regStart>=from && regEnd<=to) {
//Entire region falls in the range. Disable entirely. //Entire region falls in the range. Disable entirely.
regions[i].xTag=-1; regions[i].xTag=-1;
} else if (regStart>=from && regEnd>to && regStart<to) { } else if (regStart>=from && regEnd>to && regStart<to) {
//Start of the region falls in the range. Modify address/len. //Start of the region falls in the range. Modify address/len.
int overlap=(uint8_t *)to-(uint8_t *)regStart; int overlap=(uint8_t *)to-(uint8_t *)regStart;
regions[i].pucStartAddress+=overlap; regions[i].pucStartAddress+=overlap;
regions[i].xSizeInBytes-=overlap; regions[i].xSizeInBytes-=overlap;
if (regions[i].xExecAddr) regions[i].xExecAddr+=overlap; if (regions[i].xExecAddr) regions[i].xExecAddr+=overlap;
} else if (regStart<from && regEnd>from && regEnd<=to) { } else if (regStart<from && regEnd>from && regEnd<=to) {
//End of the region falls in the range. Modify length. //End of the region falls in the range. Modify length.
regions[i].xSizeInBytes-=(uint8_t *)regEnd-(uint8_t *)from; regions[i].xSizeInBytes-=(uint8_t *)regEnd-(uint8_t *)from;
} else if (regStart<from && regEnd>to) { } else if (regStart<from && regEnd>to) {
//Range punches a hole in the region! We do not support this. //Range punches a hole in the region! We do not support this.
ESP_EARLY_LOGE(TAG, "region %d: hole punching is not supported!", i); ESP_EARLY_LOGE(TAG, "region %d: hole punching is not supported!", i);
regions[i].xTag=-1; //Just disable memory region. That'll teach them! regions[i].xTag=-1; //Just disable memory region. That'll teach them!
} }
} }
} }
@ -170,52 +170,52 @@ ToDo: The regions are different when stuff like trace memory, BT, ... is used. M
Same with loading of apps. Same with using SPI RAM. Same with loading of apps. Same with using SPI RAM.
*/ */
void heap_alloc_caps_init() { void heap_alloc_caps_init() {
int i; int i;
//Disable the bits of memory where this code is loaded. //Disable the bits of memory where this code is loaded.
disable_mem_region(&_bss_start, &_heap_start); disable_mem_region(&_bss_start, &_heap_start);
disable_mem_region((void*)0x3ffae000, (void*)0x3ffb0000); //knock out ROM data region disable_mem_region((void*)0x3ffae000, (void*)0x3ffb0000); //knock out ROM data region
disable_mem_region((void*)0x40070000, (void*)0x40078000); //CPU0 cache region disable_mem_region((void*)0x40070000, (void*)0x40078000); //CPU0 cache region
disable_mem_region((void*)0x40078000, (void*)0x40080000); //CPU1 cache region disable_mem_region((void*)0x40078000, (void*)0x40080000); //CPU1 cache region
disable_mem_region((void*)0x40080000, (void*)0x400a0000); //pool 2-5 disable_mem_region((void*)0x40080000, (void*)0x400a0000); //pool 2-5
// TODO: this region should be checked, since we don't need to knock out all region finally // TODO: this region should be checked, since we don't need to knock out all region finally
disable_mem_region((void*)0x3ffe0000, (void*)0x3ffe8000); //knock out ROM data region disable_mem_region((void*)0x3ffe0000, (void*)0x3ffe8000); //knock out ROM data region
#if CONFIG_MEMMAP_BT #if CONFIG_MEMMAP_BT
disable_mem_region((void*)0x3ffb0000, (void*)0x3ffc0000); //knock out BT data region disable_mem_region((void*)0x3ffb0000, (void*)0x3ffc0000); //knock out BT data region
#endif #endif
#if CONFIG_MEMMAP_TRACEMEM #if CONFIG_MEMMAP_TRACEMEM
disable_mem_region((void*)0x3fff8000, (void*)0x40000000); //knock out trace mem region disable_mem_region((void*)0x3fff8000, (void*)0x40000000); //knock out trace mem region
#endif #endif
#if 0 #if 0
enable_spi_sram(); enable_spi_sram();
#else #else
disable_mem_region((void*)0x3f800000, (void*)0x3f820000); //SPI SRAM not installed disable_mem_region((void*)0x3f800000, (void*)0x3f820000); //SPI SRAM not installed
#endif #endif
//The heap allocator will treat every region given to it as separate. In order to get bigger ranges of contiguous memory, //The heap allocator will treat every region given to it as separate. In order to get bigger ranges of contiguous memory,
//it's useful to coalesce adjacent regions that have the same tag. //it's useful to coalesce adjacent regions that have the same tag.
for (i=1; regions[i].xSizeInBytes!=0; i++) { for (i=1; regions[i].xSizeInBytes!=0; i++) {
if (regions[i].pucStartAddress == (regions[i-1].pucStartAddress + regions[i-1].xSizeInBytes) && if (regions[i].pucStartAddress == (regions[i-1].pucStartAddress + regions[i-1].xSizeInBytes) &&
regions[i].xTag == regions[i-1].xTag ) { regions[i].xTag == regions[i-1].xTag ) {
regions[i-1].xTag=-1; regions[i-1].xTag=-1;
regions[i].pucStartAddress=regions[i-1].pucStartAddress; regions[i].pucStartAddress=regions[i-1].pucStartAddress;
regions[i].xSizeInBytes+=regions[i-1].xSizeInBytes; regions[i].xSizeInBytes+=regions[i-1].xSizeInBytes;
} }
} }
ESP_EARLY_LOGI(TAG, "Initializing heap allocator:"); ESP_EARLY_LOGI(TAG, "Initializing heap allocator:");
for (i=0; regions[i].xSizeInBytes!=0; i++) { for (i=0; regions[i].xSizeInBytes!=0; i++) {
if (regions[i].xTag != -1) { if (regions[i].xTag != -1) {
ESP_EARLY_LOGI(TAG, "Region %02d: %08X len %08X tag %d", i, ESP_EARLY_LOGI(TAG, "Region %02d: %08X len %08X tag %d", i,
(int)regions[i].pucStartAddress, regions[i].xSizeInBytes, regions[i].xTag); (int)regions[i].pucStartAddress, regions[i].xSizeInBytes, regions[i].xTag);
} }
} }
//Initialize the malloc implementation. //Initialize the malloc implementation.
vPortDefineHeapRegionsTagged( regions ); vPortDefineHeapRegionsTagged( regions );
} }
/* /*
@ -223,7 +223,7 @@ Standard malloc() implementation. Will return ho-hum byte-accessible data memory
*/ */
void *pvPortMalloc( size_t xWantedSize ) void *pvPortMalloc( size_t xWantedSize )
{ {
return pvPortMallocCaps( xWantedSize, MALLOC_CAP_8BIT ); return pvPortMallocCaps( xWantedSize, MALLOC_CAP_8BIT );
} }
/* /*
@ -231,30 +231,30 @@ Routine to allocate a bit of memory with certain capabilities. caps is a bitfiel
*/ */
void *pvPortMallocCaps( size_t xWantedSize, uint32_t caps ) void *pvPortMallocCaps( size_t xWantedSize, uint32_t caps )
{ {
int prio; int prio;
int tag, j; int tag, j;
void *ret=NULL; void *ret=NULL;
uint32_t remCaps; uint32_t remCaps;
for (prio=0; prio<NO_PRIOS; prio++) { for (prio=0; prio<NO_PRIOS; prio++) {
//Iterate over tag descriptors for this priority //Iterate over tag descriptors for this priority
for (tag=0; tagDesc[tag][prio]!=MALLOC_CAP_INVALID; tag++) { for (tag=0; tagDesc[tag][prio]!=MALLOC_CAP_INVALID; tag++) {
if ((tagDesc[tag][prio]&caps)!=0) { if ((tagDesc[tag][prio]&caps)!=0) {
//Tag has at least one of the caps requested. If caps has other bits set that this prio //Tag has at least one of the caps requested. If caps has other bits set that this prio
//doesn't cover, see if they're available in other prios. //doesn't cover, see if they're available in other prios.
remCaps=caps&(~tagDesc[tag][prio]); //Remaining caps to be fulfilled remCaps=caps&(~tagDesc[tag][prio]); //Remaining caps to be fulfilled
j=prio+1; j=prio+1;
while (remCaps!=0 && j<NO_PRIOS) { while (remCaps!=0 && j<NO_PRIOS) {
remCaps=remCaps&(~tagDesc[tag][j]); remCaps=remCaps&(~tagDesc[tag][j]);
j++; j++;
} }
if (remCaps==0) { if (remCaps==0) {
//This tag can satisfy all the requested capabilities. See if we can grab some memory using it. //This tag can satisfy all the requested capabilities. See if we can grab some memory using it.
ret=pvPortMallocTagged(xWantedSize, tag); ret=pvPortMallocTagged(xWantedSize, tag);
if (ret!=NULL) return ret; if (ret!=NULL) return ret;
} }
} }
} }
} }
//Nothing usable found. //Nothing usable found.
return NULL; return NULL;
} }

View file

@ -0,0 +1,34 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef HEAP_ALLOC_CAPS_H
#define HEAP_ALLOC_CAPS_H
#define MALLOC_CAP_EXEC (1<<0) //Memory must be able to run executable code
#define MALLOC_CAP_32BIT (1<<1) //Memory must allow for aligned 32-bit data accesses
#define MALLOC_CAP_8BIT (1<<2) //Memory must allow for 8/16/...-bit data accesses
#define MALLOC_CAP_DMA (1<<3) //Memory must be able to accessed by DMA
#define MALLOC_CAP_PID2 (1<<4) //Memory must be mapped to PID2 memory space
#define MALLOC_CAP_PID3 (1<<5) //Memory must be mapped to PID3 memory space
#define MALLOC_CAP_PID4 (1<<6) //Memory must be mapped to PID4 memory space
#define MALLOC_CAP_PID5 (1<<7) //Memory must be mapped to PID5 memory space
#define MALLOC_CAP_PID6 (1<<8) //Memory must be mapped to PID6 memory space
#define MALLOC_CAP_PID7 (1<<9) //Memory must be mapped to PID7 memory space
#define MALLOC_CAP_SPISRAM (1<<10) //Memory must be in SPI SRAM
#define MALLOC_CAP_INVALID (1<<31) //Memory can't be used / list end marker
void heap_alloc_caps_init();
void *pvPortMallocCaps(size_t xWantedSize, uint32_t caps);
#endif

View file

@ -3342,7 +3342,6 @@ TCB_t *pxNewTCB;
BaseType_t xTaskGetAffinity( TaskHandle_t xTask ) BaseType_t xTaskGetAffinity( TaskHandle_t xTask )
{ {
TCB_t *pxTCB; TCB_t *pxTCB;
UBaseType_t uxReturn;
pxTCB = prvGetTCBFromHandle( xTask ); pxTCB = prvGetTCBFromHandle( xTask );