gptimer: clean up hal and ll for driver-ng

* Original commit: espressif/esp-idf@e2275b1f63
This commit is contained in:
morris
2021-09-27 12:46:51 +08:00
committed by aleks
parent 4fc2d83143
commit 23e78eb821
2 changed files with 24 additions and 40 deletions

View File

@ -1,16 +1,7 @@
/* Copyright 2018 Espressif Systems (Shanghai) PTE LTD /*
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * SPDX-License-Identifier: Apache-2.0
* 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.
*/ */
/* /*
* FreeModbus Libary: ESP32 Port Demo Application * FreeModbus Libary: ESP32 Port Demo Application
@ -57,7 +48,7 @@
#define MB_US50_FREQ (20000) // 20kHz 1/20000 = 50mks #define MB_US50_FREQ (20000) // 20kHz 1/20000 = 50mks
#define MB_DISCR_TIME_US (50) // 50uS = one discreet for timer #define MB_DISCR_TIME_US (50) // 50uS = one discreet for timer
#define MB_TIMER_PRESCALLER ((TIMER_BASE_CLK / MB_US50_FREQ) - 1); #define MB_TIMER_PRESCALLER ((TIMER_BASE_CLK / MB_US50_FREQ) - 1)
#define MB_TIMER_SCALE (TIMER_BASE_CLK / TIMER_DIVIDER) // convert counter value to seconds #define MB_TIMER_SCALE (TIMER_BASE_CLK / TIMER_DIVIDER) // convert counter value to seconds
#define MB_TIMER_DIVIDER ((TIMER_BASE_CLK / 1000000UL) * MB_DISCR_TIME_US - 1) // divider for 50uS #define MB_TIMER_DIVIDER ((TIMER_BASE_CLK / 1000000UL) * MB_DISCR_TIME_US - 1) // divider for 50uS
#define MB_TIMER_WITH_RELOAD (1) #define MB_TIMER_WITH_RELOAD (1)
@ -96,13 +87,14 @@ BOOL xMBPortTimersInit(USHORT usTim1Timerout50us)
MB_PORT_CHECK((usTim1Timerout50us > 0), FALSE, MB_PORT_CHECK((usTim1Timerout50us > 0), FALSE,
"Modbus timeout discreet is incorrect."); "Modbus timeout discreet is incorrect.");
esp_err_t xErr; esp_err_t xErr;
timer_config_t config; timer_config_t config = {
config.alarm_en = TIMER_ALARM_EN; .alarm_en = TIMER_ALARM_EN,
config.auto_reload = MB_TIMER_WITH_RELOAD; .auto_reload = MB_TIMER_WITH_RELOAD,
config.counter_dir = TIMER_COUNT_UP; .counter_dir = TIMER_COUNT_UP,
config.divider = MB_TIMER_PRESCALLER; .divider = MB_TIMER_PRESCALLER,
config.intr_type = TIMER_INTR_LEVEL; .intr_type = TIMER_INTR_LEVEL,
config.counter_en = TIMER_PAUSE; .counter_en = TIMER_PAUSE,
};
// Configure timer // Configure timer
xErr = timer_init(usTimerGroupIndex, usTimerIndex, &config); xErr = timer_init(usTimerGroupIndex, usTimerIndex, &config);
MB_PORT_CHECK((xErr == ESP_OK), FALSE, MB_PORT_CHECK((xErr == ESP_OK), FALSE,

View File

@ -1,16 +1,7 @@
/* Copyright 2018 Espressif Systems (Shanghai) PTE LTD /*
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * SPDX-License-Identifier: Apache-2.0
* 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.
*/ */
/* /*
* FreeModbus Libary: ESP32 Port Demo Application * FreeModbus Libary: ESP32 Port Demo Application
@ -45,7 +36,7 @@
#define MB_US50_FREQ (20000) // 20kHz 1/20000 = 50mks #define MB_US50_FREQ (20000) // 20kHz 1/20000 = 50mks
#define MB_TICK_TIME_US (50) // 50uS = one tick for timer #define MB_TICK_TIME_US (50) // 50uS = one tick for timer
#define MB_TIMER_PRESCALLER ((TIMER_BASE_CLK / MB_US50_FREQ) - 1); #define MB_TIMER_PRESCALLER ((TIMER_BASE_CLK / MB_US50_FREQ) - 1)
#define MB_TIMER_SCALE (TIMER_BASE_CLK / TIMER_DIVIDER) #define MB_TIMER_SCALE (TIMER_BASE_CLK / TIMER_DIVIDER)
#define MB_TIMER_DIVIDER ((TIMER_BASE_CLK / 1000000UL) * MB_TICK_TIME_US - 1) // divider for 50uS #define MB_TIMER_DIVIDER ((TIMER_BASE_CLK / 1000000UL) * MB_TICK_TIME_US - 1) // divider for 50uS
#define MB_TIMER_WITH_RELOAD (1) #define MB_TIMER_WITH_RELOAD (1)
@ -95,13 +86,14 @@ BOOL xMBMasterPortTimersInit(USHORT usTimeOut50us)
// Save timer reload value for Modbus T35 period // Save timer reload value for Modbus T35 period
usT35TimeOut50us = usTimeOut50us; usT35TimeOut50us = usTimeOut50us;
esp_err_t xErr; esp_err_t xErr;
timer_config_t config; timer_config_t config = {
config.alarm_en = TIMER_ALARM_EN; .alarm_en = TIMER_ALARM_EN,
config.auto_reload = MB_TIMER_WITH_RELOAD; .auto_reload = MB_TIMER_WITH_RELOAD,
config.counter_dir = TIMER_COUNT_UP; .counter_dir = TIMER_COUNT_UP,
config.divider = MB_TIMER_PRESCALLER; .divider = MB_TIMER_PRESCALLER,
config.intr_type = TIMER_INTR_LEVEL; .intr_type = TIMER_INTR_LEVEL,
config.counter_en = TIMER_PAUSE; .counter_en = TIMER_PAUSE,
};
// Configure timer // Configure timer
xErr = timer_init(usTimerGroupIndex, usTimerIndex, &config); xErr = timer_init(usTimerGroupIndex, usTimerIndex, &config);
MB_PORT_CHECK((xErr == ESP_OK), FALSE, MB_PORT_CHECK((xErr == ESP_OK), FALSE,