Skip to content

Commit a8453ff

Browse files
author
Konstantin Kondrashov
committed
Merge branch 'feature/ulp_ticks_and_cycles' into 'master'
feat(ulp): Removes ambiguity between ticks and cycles in ULP APIs Closes IDFGH-16733 See merge request espressif/esp-idf!43153
2 parents 83c315c + e705475 commit a8453ff

File tree

6 files changed

+41
-41
lines changed

6 files changed

+41
-41
lines changed

components/ulp/lp_core/lp_core/include/ulp_lp_core_i2c.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -25,7 +25,7 @@ extern "C" {
2525
* @param device_addr I2C device address (7-bit)
2626
* @param data_rd Buffer to hold data to be read
2727
* @param size Size of data to be read in bytes
28-
* @param ticks_to_wait Operation timeout in CPU cycles. Set to -1 to wait forever.
28+
* @param cycles_to_wait Operation timeout in CPU cycles. Set to -1 to wait forever.
2929
*
3030
* @return esp_err_t ESP_OK when successful
3131
*
@@ -34,7 +34,7 @@ extern "C" {
3434
*/
3535
esp_err_t lp_core_i2c_master_read_from_device(i2c_port_t lp_i2c_num, uint16_t device_addr,
3636
uint8_t *data_rd, size_t size,
37-
int32_t ticks_to_wait);
37+
int32_t cycles_to_wait);
3838

3939
/**
4040
* @brief Write to I2C device
@@ -46,7 +46,7 @@ esp_err_t lp_core_i2c_master_read_from_device(i2c_port_t lp_i2c_num, uint16_t de
4646
* @param device_addr I2C device address (7-bit)
4747
* @param data_wr Buffer which holds the data to be written
4848
* @param size Size of data to be written in bytes
49-
* @param ticks_to_wait Operation timeout in CPU cycles. Set to -1 to wait forever.
49+
* @param cycles_to_wait Operation timeout in CPU cycles. Set to -1 to wait forever.
5050
*
5151
* @return esp_err_t ESP_OK when successful
5252
*
@@ -55,7 +55,7 @@ esp_err_t lp_core_i2c_master_read_from_device(i2c_port_t lp_i2c_num, uint16_t de
5555
*/
5656
esp_err_t lp_core_i2c_master_write_to_device(i2c_port_t lp_i2c_num, uint16_t device_addr,
5757
const uint8_t *data_wr, size_t size,
58-
int32_t ticks_to_wait);
58+
int32_t cycles_to_wait);
5959

6060
/**
6161
* @brief Write to and then read from an I2C device in a single transaction
@@ -69,7 +69,7 @@ esp_err_t lp_core_i2c_master_write_to_device(i2c_port_t lp_i2c_num, uint16_t dev
6969
* @param write_size Size of data to be written in bytes
7070
* @param data_rd Buffer to hold data to be read
7171
* @param read_size Size of data to be read in bytes
72-
* @param ticks_to_wait Operation timeout in CPU cycles. Set to -1 to wait forever.
72+
* @param cycles_to_wait Operation timeout in CPU cycles. Set to -1 to wait forever.
7373
*
7474
* @return esp_err_t ESP_OK when successful
7575
*
@@ -79,7 +79,7 @@ esp_err_t lp_core_i2c_master_write_to_device(i2c_port_t lp_i2c_num, uint16_t dev
7979
esp_err_t lp_core_i2c_master_write_read_device(i2c_port_t lp_i2c_num, uint16_t device_addr,
8080
const uint8_t *data_wr, size_t write_size,
8181
uint8_t *data_rd, size_t read_size,
82-
int32_t ticks_to_wait);
82+
int32_t cycles_to_wait);
8383

8484
/**
8585
* @brief Enable or disable ACK checking by the LP_I2C controller during write operations

components/ulp/lp_core/lp_core/include/ulp_lp_core_spi.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -39,26 +39,26 @@ typedef struct {
3939
* from the device.
4040
*
4141
* @param trans_desc LP SPI transaction configuration descriptor
42-
* @param ticks_to_wait Operation timeout in CPU cycles. Set to -1 to wait forever.
42+
* @param cycles_to_wait Operation timeout in CPU cycles. Set to -1 to wait forever.
4343
*
4444
* @return esp_err_t ESP_OK when successful
4545
* ESP_ERR_INVALID_ARG if the configuration is invalid
4646
* ESP_ERR_TIMEOUT when the operation times out
4747
*/
48-
esp_err_t lp_core_lp_spi_master_transfer(lp_spi_transaction_t *trans_desc, int32_t ticks_to_wait);
48+
esp_err_t lp_core_lp_spi_master_transfer(lp_spi_transaction_t *trans_desc, int32_t cycles_to_wait);
4949

5050
/**
5151
* @brief Initiate an LP SPI transaction in slave mode to receive data from an SPI master and optionally transmit data
5252
* back to the master.
5353
*
5454
* @param trans_desc LP SPI transaction configuration descriptor
55-
* @param ticks_to_wait Operation timeout in CPU cycles. Set to -1 to wait forever.
55+
* @param cycles_to_wait Operation timeout in CPU cycles. Set to -1 to wait forever.
5656
*
5757
* @return esp_err_t ESP_OK when successful
5858
* ESP_ERR_INVALID_ARG if the configuration is invalid
5959
* ESP_ERR_TIMEOUT when the operation times out
6060
*/
61-
esp_err_t lp_core_lp_spi_slave_transfer(lp_spi_transaction_t *trans_desc, int32_t ticks_to_wait);
61+
esp_err_t lp_core_lp_spi_slave_transfer(lp_spi_transaction_t *trans_desc, int32_t cycles_to_wait);
6262

6363
#ifdef __cplusplus
6464
}

components/ulp/lp_core/lp_core/lp_core_i2c.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void lp_core_i2c_format_cmd(uint32_t cmd_idx, uint8_t op_code, uint8_t ac
6565
i2c_ll_master_write_cmd_reg(dev, hw_cmd, cmd_idx);
6666
}
6767

68-
static inline esp_err_t lp_core_i2c_wait_for_interrupt(uint32_t intr_mask, int32_t ticks_to_wait)
68+
static inline esp_err_t lp_core_i2c_wait_for_interrupt(uint32_t intr_mask, int32_t cycles_to_wait)
6969
{
7070
uint32_t intr_status = 0;
7171
uint32_t to = 0;
@@ -96,13 +96,13 @@ static inline esp_err_t lp_core_i2c_wait_for_interrupt(uint32_t intr_mask, int32
9696
break;
9797
}
9898

99-
if (ticks_to_wait > -1) {
100-
/* If the ticks_to_wait value is not -1, keep track of ticks and
99+
if (cycles_to_wait > -1) {
100+
/* If the cycles_to_wait value is not -1, keep track of cycles and
101101
* break from the loop once the timeout is reached.
102102
*/
103103
ulp_lp_core_delay_cycles(1);
104104
to++;
105-
if (to >= ticks_to_wait) {
105+
if (to >= cycles_to_wait) {
106106
/* Timeout. Clear interrupt bits and return an error */
107107
i2c_ll_clear_intr_mask(dev, intr_mask);
108108
return ESP_ERR_TIMEOUT;
@@ -142,7 +142,7 @@ void lp_core_i2c_master_set_ack_check_en(i2c_port_t lp_i2c_num, bool ack_check_e
142142

143143
esp_err_t lp_core_i2c_master_read_from_device(i2c_port_t lp_i2c_num, uint16_t device_addr,
144144
uint8_t *data_rd, size_t size,
145-
int32_t ticks_to_wait)
145+
int32_t cycles_to_wait)
146146
{
147147
(void)lp_i2c_num;
148148

@@ -215,7 +215,7 @@ esp_err_t lp_core_i2c_master_read_from_device(i2c_port_t lp_i2c_num, uint16_t de
215215
i2c_ll_start_trans(dev);
216216

217217
/* Wait for the transfer to complete */
218-
ret = lp_core_i2c_wait_for_interrupt(intr_mask, ticks_to_wait);
218+
ret = lp_core_i2c_wait_for_interrupt(intr_mask, cycles_to_wait);
219219
if (ret != ESP_OK) {
220220
/* Transaction error. Abort. */
221221
return ret;
@@ -233,7 +233,7 @@ esp_err_t lp_core_i2c_master_read_from_device(i2c_port_t lp_i2c_num, uint16_t de
233233

234234
esp_err_t lp_core_i2c_master_write_to_device(i2c_port_t lp_i2c_num, uint16_t device_addr,
235235
const uint8_t *data_wr, size_t size,
236-
int32_t ticks_to_wait)
236+
int32_t cycles_to_wait)
237237
{
238238
(void)lp_i2c_num;
239239

@@ -306,7 +306,7 @@ esp_err_t lp_core_i2c_master_write_to_device(i2c_port_t lp_i2c_num, uint16_t dev
306306
i2c_ll_start_trans(dev);
307307

308308
/* Wait for the transfer to complete */
309-
ret = lp_core_i2c_wait_for_interrupt(intr_mask, ticks_to_wait);
309+
ret = lp_core_i2c_wait_for_interrupt(intr_mask, cycles_to_wait);
310310
if (ret != ESP_OK) {
311311
/* Transaction error. Abort. */
312312
return ret;
@@ -325,7 +325,7 @@ esp_err_t lp_core_i2c_master_write_to_device(i2c_port_t lp_i2c_num, uint16_t dev
325325
esp_err_t lp_core_i2c_master_write_read_device(i2c_port_t lp_i2c_num, uint16_t device_addr,
326326
const uint8_t *data_wr, size_t write_size,
327327
uint8_t *data_rd, size_t read_size,
328-
int32_t ticks_to_wait)
328+
int32_t cycles_to_wait)
329329
{
330330
(void)lp_i2c_num;
331331

@@ -393,7 +393,7 @@ esp_err_t lp_core_i2c_master_write_read_device(i2c_port_t lp_i2c_num, uint16_t d
393393
i2c_ll_start_trans(dev);
394394

395395
/* Wait for the transfer to complete */
396-
ret = lp_core_i2c_wait_for_interrupt(intr_mask, ticks_to_wait);
396+
ret = lp_core_i2c_wait_for_interrupt(intr_mask, cycles_to_wait);
397397
if (ret != ESP_OK) {
398398
/* Transaction error. Abort. */
399399
return ret;
@@ -462,7 +462,7 @@ esp_err_t lp_core_i2c_master_write_read_device(i2c_port_t lp_i2c_num, uint16_t d
462462
i2c_ll_start_trans(dev);
463463

464464
/* Wait for the transfer to complete */
465-
ret = lp_core_i2c_wait_for_interrupt(intr_mask, ticks_to_wait);
465+
ret = lp_core_i2c_wait_for_interrupt(intr_mask, cycles_to_wait);
466466
if (ret != ESP_OK) {
467467
/* Transaction error. Abort. */
468468
return ret;

components/ulp/lp_core/lp_core/lp_core_spi.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -17,16 +17,16 @@
1717
/* Use the register structure to access LP_SPI module registers */
1818
lp_spi_dev_t *lp_spi_dev = &LP_SPI;
1919

20-
static inline esp_err_t lp_core_spi_wait_for_interrupt(int32_t ticks_to_wait)
20+
static inline esp_err_t lp_core_spi_wait_for_interrupt(int32_t cycles_to_wait)
2121
{
2222
uint32_t to = 0;
2323
while (!lp_spi_dev->spi_dma_int_raw.reg_trans_done_int_raw) {
24-
if (ticks_to_wait > -1) {
25-
/* If the ticks_to_wait value is not -1, keep track of ticks and
24+
if (cycles_to_wait > -1) {
25+
/* If the cycles_to_wait value is not -1, keep track of cycles and
2626
* break from the loop once the timeout is reached.
2727
*/
2828
to++;
29-
if (to >= ticks_to_wait) {
29+
if (to >= cycles_to_wait) {
3030
/* Clear interrupt bits */
3131
lp_spi_dev->spi_dma_int_clr.reg_trans_done_int_clr = 1;
3232
return ESP_ERR_TIMEOUT;
@@ -41,7 +41,7 @@ static inline esp_err_t lp_core_spi_wait_for_interrupt(int32_t ticks_to_wait)
4141
////////////////////////////////// Public APIs ///////////////////////////////////
4242
//////////////////////////////////////////////////////////////////////////////////
4343

44-
esp_err_t lp_core_lp_spi_master_transfer(lp_spi_transaction_t *trans_desc, int32_t ticks_to_wait)
44+
esp_err_t lp_core_lp_spi_master_transfer(lp_spi_transaction_t *trans_desc, int32_t cycles_to_wait)
4545
{
4646
esp_err_t ret = ESP_OK;
4747

@@ -130,7 +130,7 @@ esp_err_t lp_core_lp_spi_master_transfer(lp_spi_transaction_t *trans_desc, int32
130130
lp_spi_dev->spi_cmd.reg_usr = 1;
131131

132132
/* Wait for the transaction to complete */
133-
ret = lp_core_spi_wait_for_interrupt(ticks_to_wait);
133+
ret = lp_core_spi_wait_for_interrupt(cycles_to_wait);
134134
if (ret != ESP_OK) {
135135
return ret;
136136
}
@@ -152,7 +152,7 @@ esp_err_t lp_core_lp_spi_master_transfer(lp_spi_transaction_t *trans_desc, int32
152152
return ret;
153153
}
154154

155-
esp_err_t lp_core_lp_spi_slave_transfer(lp_spi_transaction_t *trans_desc, int32_t ticks_to_wait)
155+
esp_err_t lp_core_lp_spi_slave_transfer(lp_spi_transaction_t *trans_desc, int32_t cycles_to_wait)
156156
{
157157
esp_err_t ret = ESP_OK;
158158

@@ -203,7 +203,7 @@ esp_err_t lp_core_lp_spi_slave_transfer(lp_spi_transaction_t *trans_desc, int32_
203203

204204
while (rx_idx < length_in_bytes) {
205205
/* Wait for the transmission to complete */
206-
ret = lp_core_spi_wait_for_interrupt(ticks_to_wait);
206+
ret = lp_core_spi_wait_for_interrupt(cycles_to_wait);
207207
if (ret != ESP_OK) {
208208
return ret;
209209
}
@@ -247,7 +247,7 @@ esp_err_t lp_core_lp_spi_slave_transfer(lp_spi_transaction_t *trans_desc, int32_
247247
lp_spi_dev->spi_cmd.reg_usr = 1;
248248

249249
/* Wait for the transaction to complete */
250-
ret = lp_core_spi_wait_for_interrupt(ticks_to_wait);
250+
ret = lp_core_spi_wait_for_interrupt(cycles_to_wait);
251251
if (ret != ESP_OK) {
252252
return ret;
253253
}

components/ulp/lp_core/lp_core/lp_core_uart.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ uart_hal_context_t hal = {
2222
.dev = (uart_dev_t *)UART_LL_GET_HW(LP_UART_NUM_0),
2323
};
2424

25-
static esp_err_t lp_core_uart_check_timeout(uint32_t intr_mask, int32_t timeout, uint32_t *ticker)
25+
static esp_err_t lp_core_uart_check_timeout(uint32_t intr_mask, int32_t timeout, uint32_t *cycle_count)
2626
{
2727
if (timeout > -1) {
28-
/* If the timeout value is not -1, delay for 1 CPU cycle and keep track of ticks */
28+
/* If the timeout value is not -1, delay for 1 CPU cycle and keep track of cycles */
2929
ulp_lp_core_delay_cycles(1);
30-
*ticker = *ticker + 1;
31-
if (*ticker >= timeout) {
30+
(*cycle_count)++;
31+
if (*cycle_count >= (uint32_t)timeout) {
3232
/* Disable and clear interrupt bits */
3333
uart_hal_disable_intr_mask(&hal, intr_mask);
3434
uart_hal_clr_intsts_mask(&hal, intr_mask);

components/ulp/ulp_riscv/ulp_core/ulp_riscv_i2c.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static void ulp_riscv_i2c_format_cmd(uint32_t cmd_idx, uint8_t op_code, uint8_t
6767
((byte_num & 0xFF) << 0)); // Byte Num
6868
}
6969

70-
static inline int32_t ulp_riscv_i2c_wait_for_interrupt(int32_t ticks_to_wait)
70+
static inline int32_t ulp_riscv_i2c_wait_for_interrupt(int32_t cycles_to_wait)
7171
{
7272
uint32_t status = 0;
7373
uint32_t to = 0;
@@ -90,13 +90,13 @@ static inline int32_t ulp_riscv_i2c_wait_for_interrupt(int32_t ticks_to_wait)
9090
return -1;
9191
}
9292

93-
if (ticks_to_wait > -1) {
94-
/* If the ticks_to_wait value is not -1, keep track of ticks and
93+
if (cycles_to_wait > -1) {
94+
/* If the cycles_to_wait value is not -1, keep track of cycles and
9595
* break from the loop once the timeout is reached.
9696
*/
9797
ulp_riscv_delay_cycles(1);
9898
to++;
99-
if (to >= ticks_to_wait) {
99+
if (to >= cycles_to_wait) {
100100
return -1;
101101
}
102102
}

0 commit comments

Comments
 (0)