Skip to content

Commit 59b7d98

Browse files
committed
Merge branch 'feature/dfs' into 'master'
Dynamic frequency scaling See merge request !1189
2 parents 22756b6 + f6ef536 commit 59b7d98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1989
-157
lines changed

components/app_trace/Kconfig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ config SYSVIEW_ENABLE
6363
help
6464
Enables supporrt for SEGGER SystemView tracing functionality.
6565

66-
if !FREERTOS_UNICORE
6766
choice SYSVIEW_TS_SOURCE
6867
prompt "ESP32 timer to use as SystemView timestamp source"
6968
depends on SYSVIEW_ENABLE
7069
default SYSVIEW_TS_SOURCE_TIMER_00
7170
help
72-
SystemView needs one source for timestamps when tracing events from both cores.
71+
SystemView needs to use a hardware timer as the source of timestamps
72+
when tracing
7373
This option selects HW timer for it.
7474

7575
config SYSVIEW_TS_SOURCE_TIMER_00
@@ -93,7 +93,6 @@ config SYSVIEW_TS_SOURCE_TIMER_11
9393
Select this to use timer 1 of group 1
9494

9595
endchoice
96-
endif #FREERTOS_UNICORE
9796

9897
config SYSVIEW_EVT_OVERFLOW_ENABLE
9998
bool "Trace Buffer Overflow Event"

components/app_trace/app_trace.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ const static char *TAG = "esp_apptrace";
203203
#define ESP_APPTRACE_LOGV( format, ... ) ESP_APPTRACE_LOG_LEV(V, ESP_LOG_VERBOSE, format, ##__VA_ARGS__)
204204
#define ESP_APPTRACE_LOGO( format, ... ) ESP_APPTRACE_LOG_LEV(E, ESP_LOG_NONE, format, ##__VA_ARGS__)
205205

206-
#define ESP_APPTRACE_CPUTICKS2US(_t_) ((_t_)/(XT_CLOCK_FREQ/1000000))
207-
208206
// TODO: move these (and same definitions in trax.c to dport_reg.h)
209207
#define TRACEMEM_MUX_PROBLK0_APPBLK1 0
210208
#define TRACEMEM_MUX_BLK0_ONLY 1

components/app_trace/app_trace_util.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,24 @@
1515
#include "freertos/FreeRTOS.h"
1616
#include "freertos/task.h"
1717
#include "esp_app_trace_util.h"
18+
#include "esp_clk.h"
1819

1920
///////////////////////////////////////////////////////////////////////////////
2021
///////////////////////////////// TIMEOUT /////////////////////////////////////
2122
///////////////////////////////////////////////////////////////////////////////
2223

23-
// TODO: get actual clock from PLL config
24-
#define ESP_APPTRACE_CPUTICKS2US(_t_) ((_t_)/(XT_CLOCK_FREQ/1000000))
25-
#define ESP_APPTRACE_US2CPUTICKS(_t_) ((_t_)*(XT_CLOCK_FREQ/1000000))
24+
#define ESP_APPTRACE_CPUTICKS2US(_t_, _cpu_freq_) ((_t_)/(_cpu_freq_/1000000))
25+
#define ESP_APPTRACE_US2CPUTICKS(_t_, _cpu_freq_) ((_t_)*(_cpu_freq_/1000000))
2626

2727
esp_err_t esp_apptrace_tmo_check(esp_apptrace_tmo_t *tmo)
2828
{
29+
int cpu_freq = esp_clk_cpu_freq();
2930
if (tmo->tmo != ESP_APPTRACE_TMO_INFINITE) {
3031
unsigned cur = portGET_RUN_TIME_COUNTER_VALUE();
3132
if (tmo->start <= cur) {
32-
tmo->elapsed = ESP_APPTRACE_CPUTICKS2US(cur - tmo->start);
33+
tmo->elapsed = ESP_APPTRACE_CPUTICKS2US(cur - tmo->start, cpu_freq);
3334
} else {
34-
tmo->elapsed = ESP_APPTRACE_CPUTICKS2US(0xFFFFFFFF - tmo->start + cur);
35+
tmo->elapsed = ESP_APPTRACE_CPUTICKS2US(0xFFFFFFFF - tmo->start + cur, cpu_freq);
3536
}
3637
if (tmo->elapsed >= tmo->tmo) {
3738
return ESP_ERR_TIMEOUT;

components/app_trace/sys_view/Sample/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Revision: $Rev: 3734 $
7070
#include "esp_app_trace.h"
7171
#include "esp_app_trace_util.h"
7272
#include "esp_intr_alloc.h"
73+
#include "esp_clk.h"
7374

7475
extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI;
7576

@@ -85,14 +86,12 @@ extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI;
8586
// The target device name
8687
#define SYSVIEW_DEVICE_NAME "ESP32"
8788

89+
// Timer group timer divisor
90+
#define SYSVIEW_TIMER_DIV 2
8891
// Frequency of the timestamp.
89-
#if CONFIG_FREERTOS_UNICORE == 0
90-
#define SYSVIEW_TIMESTAMP_FREQ (TIMER_BASE_CLK/2)
91-
#else
92-
#define SYSVIEW_TIMESTAMP_FREQ (XT_CLOCK_FREQ)
93-
#endif
92+
#define SYSVIEW_TIMESTAMP_FREQ (esp_clk_apb_freq() / SYSVIEW_TIMER_DIV)
9493
// System Frequency.
95-
#define SYSVIEW_CPU_FREQ (XT_CLOCK_FREQ)
94+
#define SYSVIEW_CPU_FREQ (esp_clk_cpu_freq())
9695

9796
// The lowest RAM address used for IDs (pointers)
9897
#define SYSVIEW_RAM_BASE (0x3F400000)
@@ -104,10 +103,8 @@ extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI;
104103
#define SYSTICK_INTR_ID (ETS_INTERNAL_TIMER1_INTR_SOURCE+ETS_INTERNAL_INTR_SOURCE_OFF)
105104
#endif
106105

107-
#if CONFIG_FREERTOS_UNICORE == 0
108106
static timer_idx_t s_ts_timer_idx;
109107
static timer_group_t s_ts_timer_group;
110-
#endif
111108

112109
// SystemView is single core specific: it implies that SEGGER_SYSVIEW_LOCK()
113110
// disables IRQs (disables rescheduling globaly). So we can not use finite timeouts for locks and return error
@@ -214,7 +211,6 @@ static void _cbSendSystemDesc(void) {
214211
*
215212
**********************************************************************
216213
*/
217-
#if CONFIG_FREERTOS_UNICORE == 0
218214
static void SEGGER_SYSVIEW_TS_Init()
219215
{
220216
timer_config_t config;
@@ -238,7 +234,7 @@ static void SEGGER_SYSVIEW_TS_Init()
238234
config.alarm_en = 0;
239235
config.auto_reload = 0;
240236
config.counter_dir = TIMER_COUNT_UP;
241-
config.divider = 2;
237+
config.divider = SYSVIEW_TIMER_DIV;
242238
config.counter_en = 0;
243239
/*Configure timer*/
244240
timer_init(s_ts_timer_group, s_ts_timer_idx, &config);
@@ -247,14 +243,11 @@ static void SEGGER_SYSVIEW_TS_Init()
247243
/*Enable timer interrupt*/
248244
timer_start(s_ts_timer_group, s_ts_timer_idx);
249245
}
250-
#endif
251246

252247
void SEGGER_SYSVIEW_Conf(void) {
253248
U32 disable_evts = 0;
254249

255-
#if CONFIG_FREERTOS_UNICORE == 0
256250
SEGGER_SYSVIEW_TS_Init();
257-
#endif
258251
SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ,
259252
&SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc);
260253
SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE);

components/app_trace/sys_view/esp32/SEGGER_RTT_esp32.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@ const static char *TAG = "segger_rtt";
2626

2727
#define SYSVIEW_EVENTS_BUF_SZ 255U
2828

29-
#if SYSVIEW_RTT_MAX_DATA_RATE > 0
30-
#include "SEGGER_SYSVIEW_Conf.h"
31-
#if CONFIG_FREERTOS_UNICORE == 0
32-
#include "driver/timer.h"
33-
#define SYSVIEW_TIMESTAMP_FREQ (TIMER_BASE_CLK/2)
34-
#else
35-
#define SYSVIEW_TIMESTAMP_FREQ (XT_CLOCK_FREQ)
36-
#endif
37-
#endif
38-
3929
// size of down channel data buf
4030
#define SYSVIEW_DOWN_BUF_SIZE 32
4131
#define SEGGER_HOST_WAIT_TMO 500 //us

components/app_trace/test/test_trace.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ static void esp_apptrace_test_timer_init(int timer_group, int timer_idx, uint32_
8787
#define ESP_APPTRACE_TEST_WRITE_FROM_ISR(_b_, _s_) esp_apptrace_write(ESP_APPTRACE_DEST_TRAX, _b_, _s_, 0UL)
8888
#define ESP_APPTRACE_TEST_WRITE_NOWAIT(_b_, _s_) esp_apptrace_write(ESP_APPTRACE_DEST_TRAX, _b_, _s_, 0)
8989

90-
#define ESP_APPTRACE_TEST_CPUTICKS2US(_t_) ((_t_)/(XT_CLOCK_FREQ/1000000))
91-
9290
typedef struct {
9391
uint8_t *buf;
9492
uint32_t buf_sz;

components/bt/bt.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "bt.h"
3434
#include "esp_err.h"
3535
#include "esp_log.h"
36+
#include "esp_pm.h"
3637

3738
#if CONFIG_BT_ENABLED
3839

@@ -147,6 +148,10 @@ static esp_bt_controller_status_t btdm_controller_status = ESP_BT_CONTROLLER_STA
147148

148149
static portMUX_TYPE global_int_mux = portMUX_INITIALIZER_UNLOCKED;
149150

151+
#ifdef CONFIG_PM_ENABLE
152+
static esp_pm_lock_handle_t s_pm_lock;
153+
#endif
154+
150155
static void IRAM_ATTR interrupt_disable(void)
151156
{
152157
portENTER_CRITICAL(&global_int_mux);
@@ -442,6 +447,13 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
442447
return ESP_ERR_INVALID_ARG;
443448
}
444449

450+
#ifdef CONFIG_PM_ENABLE
451+
esp_err_t err = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "bt", &s_pm_lock);
452+
if (err != ESP_OK) {
453+
return err;
454+
}
455+
#endif
456+
445457
btdm_osi_funcs_register(&osi_funcs);
446458

447459
btdm_controller_mem_init();
@@ -450,6 +462,10 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
450462

451463
ret = btdm_controller_init(btdm_cfg_mask, cfg);
452464
if (ret) {
465+
#ifdef CONFIG_PM_ENABLE
466+
esp_pm_lock_delete(s_pm_lock);
467+
s_pm_lock = NULL;
468+
#endif
453469
return ESP_ERR_NO_MEM;
454470
}
455471

@@ -468,6 +484,12 @@ esp_err_t esp_bt_controller_deinit(void)
468484
}
469485

470486
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE;
487+
488+
#ifdef CONFIG_PM_ENABLE
489+
esp_pm_lock_delete(s_pm_lock);
490+
s_pm_lock = NULL;
491+
#endif
492+
471493
return ESP_OK;
472494
}
473495

@@ -484,6 +506,10 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
484506
return ESP_ERR_INVALID_ARG;
485507
}
486508

509+
#ifdef CONFIG_PM_ENABLE
510+
esp_pm_lock_acquire(s_pm_lock);
511+
#endif
512+
487513
esp_phy_load_cal_and_init();
488514

489515
if (btdm_bb_init_flag == false) {
@@ -519,6 +545,10 @@ esp_err_t esp_bt_controller_disable(void)
519545
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED;
520546
}
521547

548+
#ifdef CONFIG_PM_ENABLE
549+
esp_pm_lock_release(s_pm_lock);
550+
#endif
551+
522552
return ESP_OK;
523553
}
524554

components/driver/include/driver/uart.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ typedef struct {
106106
uart_parity_t parity; /*!< UART parity mode*/
107107
uart_stop_bits_t stop_bits; /*!< UART stop bits*/
108108
uart_hw_flowcontrol_t flow_ctrl; /*!< UART HW flow control mode (cts/rts)*/
109-
uint8_t rx_flow_ctrl_thresh ; /*!< UART HW RTS threshold*/
109+
uint8_t rx_flow_ctrl_thresh; /*!< UART HW RTS threshold*/
110+
bool use_ref_tick; /*!< Set to true if UART should be clocked from REF_TICK */
110111
} uart_config_t;
111112

112113
/**

components/driver/sdmmc_transaction.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <string.h>
1616
#include "esp_err.h"
1717
#include "esp_log.h"
18+
#include "esp_pm.h"
1819
#include "freertos/FreeRTOS.h"
1920
#include "freertos/queue.h"
2021
#include "freertos/semphr.h"
@@ -67,6 +68,9 @@ static sdmmc_desc_t s_dma_desc[SDMMC_DMA_DESC_CNT];
6768
static sdmmc_transfer_state_t s_cur_transfer = { 0 };
6869
static QueueHandle_t s_request_mutex;
6970
static bool s_is_app_cmd; // This flag is set if the next command is an APP command
71+
#ifdef CONFIG_PM_ENABLE
72+
static esp_pm_lock_handle_t s_pm_lock;
73+
#endif
7074

7175
static esp_err_t handle_idle_state_events();
7276
static sdmmc_hw_cmd_t make_hw_cmd(sdmmc_command_t* cmd);
@@ -83,19 +87,34 @@ esp_err_t sdmmc_host_transaction_handler_init()
8387
return ESP_ERR_NO_MEM;
8488
}
8589
s_is_app_cmd = false;
90+
#ifdef CONFIG_PM_ENABLE
91+
esp_err_t err = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "sdmmc", &s_pm_lock);
92+
if (err != ESP_OK) {
93+
vSemaphoreDelete(s_request_mutex);
94+
s_request_mutex = NULL;
95+
return err;
96+
}
97+
#endif
8698
return ESP_OK;
8799
}
88100

89101
void sdmmc_host_transaction_handler_deinit()
90102
{
91103
assert(s_request_mutex);
104+
#ifdef CONFIG_PM_ENABLE
105+
esp_pm_lock_delete(s_pm_lock);
106+
s_pm_lock = NULL;
107+
#endif
92108
vSemaphoreDelete(s_request_mutex);
93109
s_request_mutex = NULL;
94110
}
95111

96112
esp_err_t sdmmc_host_do_transaction(int slot, sdmmc_command_t* cmdinfo)
97113
{
98114
xSemaphoreTake(s_request_mutex, portMAX_DELAY);
115+
#ifdef CONFIG_PM_ENABLE
116+
esp_pm_lock_acquire(s_pm_lock);
117+
#endif
99118
// dispose of any events which happened asynchronously
100119
handle_idle_state_events();
101120
// convert cmdinfo to hardware register value
@@ -141,6 +160,9 @@ esp_err_t sdmmc_host_do_transaction(int slot, sdmmc_command_t* cmdinfo)
141160
}
142161
}
143162
s_is_app_cmd = (ret == ESP_OK && cmdinfo->opcode == MMC_APP_CMD);
163+
#ifdef CONFIG_PM_ENABLE
164+
esp_pm_lock_release(s_pm_lock);
165+
#endif
144166
xSemaphoreGive(s_request_mutex);
145167
return ret;
146168
}

components/driver/spi_master.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ queue and re-enabling the interrupt will trigger the interrupt again, which can
4747
#include "esp_intr_alloc.h"
4848
#include "esp_log.h"
4949
#include "esp_err.h"
50+
#include "esp_pm.h"
5051
#include "freertos/FreeRTOS.h"
5152
#include "freertos/semphr.h"
5253
#include "freertos/xtensa_api.h"
@@ -84,6 +85,9 @@ typedef struct {
8485
bool no_gpio_matrix;
8586
int dma_chan;
8687
int max_transfer_sz;
88+
#ifdef CONFIG_PM_ENABLE
89+
esp_pm_lock_handle_t pm_lock;
90+
#endif
8791
} spi_host_t;
8892

8993
struct spi_device_t {
@@ -129,6 +133,13 @@ esp_err_t spi_bus_initialize(spi_host_device_t host, const spi_bus_config_t *bus
129133
spihost[host]=malloc(sizeof(spi_host_t));
130134
if (spihost[host]==NULL) goto nomem;
131135
memset(spihost[host], 0, sizeof(spi_host_t));
136+
#ifdef CONFIG_PM_ENABLE
137+
esp_err_t err = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "spi_master",
138+
&spihost[host]->pm_lock);
139+
if (err != ESP_OK) {
140+
goto nomem;
141+
}
142+
#endif //CONFIG_PM_ENABLE
132143

133144
spicommon_bus_initialize_io(host, bus_config, dma_chan, SPICOMMON_BUSFLAG_MASTER|SPICOMMON_BUSFLAG_QUAD, &native);
134145
spihost[host]->no_gpio_matrix=native;
@@ -180,6 +191,11 @@ esp_err_t spi_bus_initialize(spi_host_device_t host, const spi_bus_config_t *bus
180191
if (spihost[host]) {
181192
free(spihost[host]->dmadesc_tx);
182193
free(spihost[host]->dmadesc_rx);
194+
#ifdef CONFIG_PM_ENABLE
195+
if (spihost[host]->pm_lock) {
196+
esp_pm_lock_delete(spihost[host]->pm_lock);
197+
}
198+
#endif
183199
}
184200
free(spihost[host]);
185201
spicommon_periph_free(host);
@@ -199,6 +215,9 @@ esp_err_t spi_bus_free(spi_host_device_t host)
199215
if ( spihost[host]->dma_chan > 0 ) {
200216
spicommon_dma_chan_free ( spihost[host]->dma_chan );
201217
}
218+
#ifdef CONFIG_PM_ENABLE
219+
esp_pm_lock_delete(spihost[host]->pm_lock);
220+
#endif
202221
spihost[host]->hw->slave.trans_inten=0;
203222
spihost[host]->hw->slave.trans_done=0;
204223
esp_intr_free(spihost[host]->intr);
@@ -412,6 +431,10 @@ static void IRAM_ATTR spi_intr(void *arg)
412431
if (i==NO_CS) {
413432
//No packet waiting. Disable interrupt.
414433
esp_intr_disable(host->intr);
434+
#ifdef CONFIG_PM_ENABLE
435+
//Release APB frequency lock
436+
esp_pm_lock_release(host->pm_lock);
437+
#endif
415438
} else {
416439
host->hw->slave.trans_done=0; //clear int bit
417440
//We have a transaction. Send it.
@@ -649,6 +672,9 @@ esp_err_t spi_device_queue_trans(spi_device_handle_t handle, spi_transaction_t *
649672
// else use the original buffer (forced-conversion) or assign to NULL
650673
trans_buf.buffer_to_send = (uint32_t*)txdata;
651674
}
675+
#ifdef CONFIG_PM_ENABLE
676+
esp_pm_lock_acquire(handle->host->pm_lock);
677+
#endif
652678

653679
r=xQueueSend(handle->trans_queue, (void*)&trans_buf, ticks_to_wait);
654680
if (!r) return ESP_ERR_TIMEOUT;

0 commit comments

Comments
 (0)