Skip to content

Commit

Permalink
bugfix: replace portTICK_PERIOD_MS with pdMS_TO_TICKS
Browse files Browse the repository at this point in the history
portTICK_PERIOD_MS has been deprecated.

fixes UncleRus#466
  • Loading branch information
trombik committed Nov 14, 2022
1 parent 7ff291a commit 311c6fe
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 33 deletions.
5 changes: 2 additions & 3 deletions components/bme680/bme680.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,9 +724,8 @@ esp_err_t bme680_get_measurement_duration(const bme680_t *dev, uint32_t *duratio
// some ms tolerance
*duration += 5;

// ceil to next integer value that is divisible by portTICK_PERIOD_MS and
// compute RTOS ticks (1 ... portTICK_PERIOD_MS = 1 tick)
*duration = (*duration + portTICK_PERIOD_MS - 1) / portTICK_PERIOD_MS;
// convert ms into FreeRTOS tick
*duration = pdMS_TO_TICKS(*duration);

// Since first RTOS tick can be shorter than the half of defined tick period,
// the delay caused by vTaskDelay(duration) might be 1 or 2 ms shorter than
Expand Down
2 changes: 1 addition & 1 deletion components/ccs811/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ void user_task(void *pvParameters)
if (ccs811_get_results(&sensor, &tvoc, &eco2, 0, 0) == ESP_OK)
...
// passive waiting until 1 second is over
vTaskDelayUntil(&last_wakeup, 1000 / portTICK_PERIOD_MS);
vTaskDelayUntil(&last_wakeup, pdMS_TO_TICKS(1000));
}
}
...
Expand Down
5 changes: 2 additions & 3 deletions components/ds18x20/ds18x20.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
#define ds18x20_ALARMSEARCH 0xEC
#define ds18x20_CONVERT_T 0x44

#define SLEEP_MS(x) vTaskDelay(((x) + portTICK_PERIOD_MS - 1) / portTICK_PERIOD_MS)
#define CHECK(x) do { esp_err_t __; if ((__ = x) != ESP_OK) return __; } while (0)
#define CHECK_ARG(VAL) do { if (!(VAL)) return ESP_ERR_INVALID_ARG; } while (0)

Expand Down Expand Up @@ -95,7 +94,7 @@ esp_err_t ds18x20_measure(gpio_num_t pin, ds18x20_addr_t addr, bool wait)

if (wait)
{
SLEEP_MS(750);
vTaskDelay(pdMS_TO_TICKS(750));
onewire_depower(pin);
}

Expand Down Expand Up @@ -170,7 +169,7 @@ esp_err_t ds18x20_copy_scratchpad(gpio_num_t pin, ds18x20_addr_t addr)
PORT_EXIT_CRITICAL;

// And then it needs to keep that power up for 10ms.
SLEEP_MS(10);
vTaskDelay(pdMS_TO_TICKS(10));
onewire_depower(pin);

return ESP_OK;
Expand Down
2 changes: 1 addition & 1 deletion components/led_strip_spi/led_strip_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static SemaphoreHandle_t mutex;

#define CHECK(x) do { esp_err_t __; if ((__ = x) != ESP_OK) return __; } while (0)
#define CHECK_ARG(VAL) do { if (!(VAL)) return ESP_ERR_INVALID_ARG; } while (0)
#define MUTEX_TIMEOUT (CONFIG_LED_STRIP_SPI_MUTEX_TIMEOUT_MS / portTICK_PERIOD_MS)
#define MUTEX_TIMEOUT (pdMS_TO_TICKS(CONFIG_LED_STRIP_SPI_MUTEX_TIMEOUT_MS)

esp_err_t led_strip_spi_install()
{
Expand Down
6 changes: 3 additions & 3 deletions components/mhz19b/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void app_main(void)
while (!mhz19b_detect(&dev))
{
ESP_LOGI(TAG, "MHZ-19B not detected, waiting...");
vTaskDelay(1000 / portTICK_PERIOD_MS);
vTaskDelay(pdMS_TO_TICKS(1000));
}

mhz19b_get_version(&dev, version, 5);
Expand All @@ -48,13 +48,13 @@ void app_main(void)
while (mhz19b_is_warming_up(&dev))
{
ESP_LOGI(TAG, "MHZ-19B is warming up");
vTaskDelay(1000 / portTICK_PERIOD_MS);
vTaskDelay(pdMS_TO_TICKS(1000));
}

while (1) {
mhz19b_read_CO2(&dev, &co2);
ESP_LOGI(TAG, "CO2: %d", co2);
vTaskDelay(5000 / portTICK_PERIOD_MS);
vTaskDelay(pdMS_TO_TICKS(5000));
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/mhz19b/mhz19b.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ esp_err_t mhz19b_send_command(mhz19b_dev_t *dev, uint8_t cmd, uint8_t b3, uint8_
// Read response from serial buffer
int len = uart_read_bytes(dev->uart_port, dev->buf,
MHZ19B_SERIAL_RX_BYTES,
MHZ19B_SERIAL_RX_TIMEOUT_MS / portTICK_PERIOD_MS);
pdMS_TO_TICKS(MHZ19B_SERIAL_RX_TIMEOUT_MS));
if (len < 9)
return ESP_ERR_TIMEOUT;

Expand Down
11 changes: 3 additions & 8 deletions components/sht3x/sht3x.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ static const uint16_t SHT3X_MEASURE_CMD[6][3] = {
{0x2737, 0x2721, 0x272a} // [PERIODIC_10][H,M,L]
};

// due to the fact that ticks can be smaller than portTICK_PERIOD_MS, one and
// a half tick period added to the duration to be sure that waiting time for
// the results is long enough
#define TIME_TO_TICKS(ms) (1 + ((ms) + (portTICK_PERIOD_MS-1) + portTICK_PERIOD_MS/2 ) / portTICK_PERIOD_MS)

#define SHT3X_MEAS_DURATION_REP_HIGH 15
#define SHT3X_MEAS_DURATION_REP_MEDIUM 6
#define SHT3X_MEAS_DURATION_REP_LOW 4
Expand All @@ -85,9 +80,9 @@ static const uint16_t SHT3X_MEAS_DURATION_US[3] = {

// measurement durations in RTOS ticks
static const uint8_t SHT3X_MEAS_DURATION_TICKS[3] = {
TIME_TO_TICKS(SHT3X_MEAS_DURATION_REP_HIGH),
TIME_TO_TICKS(SHT3X_MEAS_DURATION_REP_MEDIUM),
TIME_TO_TICKS(SHT3X_MEAS_DURATION_REP_LOW)
pdMS_TO_TICKS(SHT3X_MEAS_DURATION_REP_HIGH),
pdMS_TO_TICKS(SHT3X_MEAS_DURATION_REP_MEDIUM),
pdMS_TO_TICKS(SHT3X_MEAS_DURATION_REP_LOW)
};

#define CHECK(x) do { esp_err_t __; if ((__ = x) != ESP_OK) return __; } while (0)
Expand Down
2 changes: 1 addition & 1 deletion components/si7021/si7021.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static esp_err_t measure(i2c_dev_t *dev, uint8_t cmd, uint16_t *raw)
I2C_DEV_CHECK(dev, i2c_dev_write(dev, NULL, 0, &cmd, 1));

// wait
vTaskDelay(DELAY_MS / portTICK_PERIOD_MS);
vTaskDelay(pdMS_TO_TICKS(DELAY_MS));

// read data
uint8_t buf[3];
Expand Down
10 changes: 5 additions & 5 deletions docs/porting.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static esp_err_t ReadReg8(EEPROM_t * dev, i2c_port_t i2c_port, int chip_addr, ui
i2c_master_write_byte(cmd, chip_addr << 1 | I2C_MASTER_READ, ACK_CHECK_EN);
i2c_master_read_byte(cmd, data, NACK_VAL);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, 1000 / portTICK_PERIOD_MS);
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, pdMS_TO_TICKS(1000));
i2c_cmd_link_delete(cmd);
return ret;
}
Expand Down Expand Up @@ -187,7 +187,7 @@ static esp_err_t WriteReg8(EEPROM_t * dev, i2c_port_t i2c_port, int chip_addr, u
i2c_master_write_byte(cmd, data_addr, ACK_CHECK_EN);
i2c_master_write_byte(cmd, data, ACK_CHECK_EN);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, 1000 / portTICK_PERIOD_MS);
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, pdMS_TO_TICKS(1000));
i2c_cmd_link_delete(cmd);
usleep(1000*2);
return ret;
Expand Down Expand Up @@ -230,7 +230,7 @@ static esp_err_t ReadReg16(EEPROM_t * dev, i2c_port_t i2c_port, int chip_addr, u
i2c_master_write_byte(cmd, chip_addr << 1 | I2C_MASTER_READ, ACK_CHECK_EN);
i2c_master_read_byte(cmd, data, NACK_VAL);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, 1000 / portTICK_PERIOD_MS);
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, pdMS_TO_TICKS(1000));
i2c_cmd_link_delete(cmd);
return ret;
}
Expand Down Expand Up @@ -272,7 +272,7 @@ static esp_err_t WriteReg16(EEPROM_t * dev, i2c_port_t i2c_port, int chip_addr,
i2c_master_write_byte(cmd, low_addr, ACK_CHECK_EN);
i2c_master_write_byte(cmd, data, ACK_CHECK_EN);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, 1000 / portTICK_PERIOD_MS);
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, pdMS_TO_TICKS(1000));
i2c_cmd_link_delete(cmd);
usleep(1000*2);
return ret;
Expand Down Expand Up @@ -316,4 +316,4 @@ void app_main(void)

</details>

You may find [this](https://github.com/UncleRus/esp-idf-lib/discussions/367) discussion useful.
You may find [this](https://github.com/UncleRus/esp-idf-lib/discussions/367) discussion useful.
2 changes: 1 addition & 1 deletion docs/source/groups/ccs811.rst
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ quite simply and could look like following.
if (ccs811_get_results(&sensor, &tvoc, &eco2, 0, 0) == ESP_OK)
...
// passive waiting until 1 second is over
vTaskDelayUntil(&last_wakeup, 1000 / portTICK_PERIOD_MS);
vTaskDelayUntil(&last_wakeup, pdMS_TO_TICKS(1000));
}
}
...
Expand Down
6 changes: 3 additions & 3 deletions examples/ls7366r/default/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ static void gpio_toggle_task(void* arg)
for (;;)
{
gpio_set_level(TEST_PIN, 1);
vTaskDelay(100 / portTICK_PERIOD_MS);
vTaskDelay(pdMS_TO_TICKS(100));
gpio_set_level(TEST_PIN, 0);
vTaskDelay(100 / portTICK_PERIOD_MS);
vTaskDelay(pdMS_TO_TICKS(100));
vTaskDelay(1);
}
}
Expand Down Expand Up @@ -131,6 +131,6 @@ void app_main(void)
int32_t count;
ls7366r_get_count(&dev, &count);
ESP_LOGI(TAG, "Count: %" PRIi32, count);
vTaskDelay(500 / portTICK_PERIOD_MS);
vTaskDelay(pdMS_TO_TICKS(500));
}
}
6 changes: 3 additions & 3 deletions examples/mhz19b/default/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void app_main(void)
while (!mhz19b_detect(&dev))
{
ESP_LOGI(TAG, "MHZ-19B not detected, waiting...");
vTaskDelay(1000 / portTICK_PERIOD_MS);
vTaskDelay(pdMS_TO_TICKS(1000));
}

mhz19b_get_version(&dev, version);
Expand All @@ -38,12 +38,12 @@ void app_main(void)
while (mhz19b_is_warming_up(&dev, true)) // use smart warming up detection
{
ESP_LOGI(TAG, "MHZ-19B is warming up");
vTaskDelay(1000 / portTICK_PERIOD_MS);
vTaskDelay(pdMS_TO_TICKS(1000);
}

while (1) {
mhz19b_read_co2(&dev, &co2);
ESP_LOGI(TAG, "CO2: %d", co2);
vTaskDelay(5000 / portTICK_PERIOD_MS);
vTaskDelay(pdMS_TO_TICKS(1000);
}
}

0 comments on commit 311c6fe

Please sign in to comment.