timer_group: correct timer_ll_set_divider

This commit is contained in:
morris
2021-02-01 14:17:10 +08:00
parent be30289364
commit 5a520cacf1
10 changed files with 41 additions and 74 deletions

View File

@@ -43,11 +43,9 @@ _Static_assert(TIMER_INTR_WDT == TIMG_WDT_INT_CLR, "Add mapping to LL interrupt
*/ */
static inline void timer_ll_set_divider(timg_dev_t *hw, timer_idx_t timer_num, uint32_t divider) static inline void timer_ll_set_divider(timg_dev_t *hw, timer_idx_t timer_num, uint32_t divider)
{ {
// refer to TRM 18.2.1 assert(divider >= 2 && divider <= 65536);
if (divider == 65536) { if (divider >= 65536) {
divider = 0; divider = 0;
} else if (divider == 1) {
divider = 2;
} }
int timer_en = hw->hw_timer[timer_num].config.enable; int timer_en = hw->hw_timer[timer_num].config.enable;
hw->hw_timer[timer_num].config.enable = 0; hw->hw_timer[timer_num].config.enable = 0;

View File

@@ -45,10 +45,15 @@ typedef struct {
* *
* @return None * @return None
*/ */
static inline void timer_ll_set_divider(timg_dev_t *hw, timer_idx_t timer_num, uint16_t divider) static inline void timer_ll_set_divider(timg_dev_t *hw, timer_idx_t timer_num, uint32_t divider)
{ {
assert(divider >= 2 && divider <= 65536);
if (divider >= 65536) {
divider = 0;
}
int timer_en = hw->hw_timer[timer_num].config.enable; int timer_en = hw->hw_timer[timer_num].config.enable;
hw->hw_timer[timer_num].config.enable = 0; hw->hw_timer[timer_num].config.enable = 0;
hw->hw_timer[timer_num].config.divcnt_rst = 1;
hw->hw_timer[timer_num].config.divider = divider; hw->hw_timer[timer_num].config.divider = divider;
hw->hw_timer[timer_num].config.enable = timer_en; hw->hw_timer[timer_num].config.enable = timer_en;
} }
@@ -67,6 +72,8 @@ static inline void timer_ll_get_divider(timg_dev_t *hw, timer_idx_t timer_num, u
uint32_t d = hw->hw_timer[timer_num].config.divider; uint32_t d = hw->hw_timer[timer_num].config.divider;
if (d == 0) { if (d == 0) {
d = 65536; d = 65536;
} else if (d == 1) {
d = 2;
} }
*divider = d; *divider = d;
} }

View File

@@ -43,8 +43,8 @@ _Static_assert(TIMER_INTR_WDT == TIMG_WDT_INT_CLR, "Add mapping to LL interrupt
*/ */
static inline void timer_ll_set_divider(timg_dev_t *hw, timer_idx_t timer_num, uint32_t divider) static inline void timer_ll_set_divider(timg_dev_t *hw, timer_idx_t timer_num, uint32_t divider)
{ {
// refer to TRM 12.2.1 assert(divider >= 2 && divider <= 65536);
if (divider == 65536) { if (divider >= 65536) {
divider = 0; divider = 0;
} }
int timer_en = hw->hw_timer[timer_num].config.enable; int timer_en = hw->hw_timer[timer_num].config.enable;
@@ -67,6 +67,8 @@ static inline void timer_ll_get_divider(timg_dev_t *hw, timer_idx_t timer_num, u
uint32_t d = hw->hw_timer[timer_num].config.divider; uint32_t d = hw->hw_timer[timer_num].config.divider;
if (d == 0) { if (d == 0) {
d = 65536; d = 65536;
} else if (d == 1) {
d = 2;
} }
*divider = d; *divider = d;
} }

View File

@@ -46,8 +46,12 @@ typedef struct {
* *
* @return None * @return None
*/ */
static inline void timer_ll_set_divider(timg_dev_t *hw, timer_idx_t timer_num, uint16_t divider) static inline void timer_ll_set_divider(timg_dev_t *hw, timer_idx_t timer_num, uint32_t divider)
{ {
assert(divider >= 2 && divider <= 65536);
if (divider >= 65536) {
divider = 0;
}
int timer_en = hw->hw_timer[timer_num].config.enable; int timer_en = hw->hw_timer[timer_num].config.enable;
hw->hw_timer[timer_num].config.enable = 0; hw->hw_timer[timer_num].config.enable = 0;
hw->hw_timer[timer_num].config.divider = divider; hw->hw_timer[timer_num].config.divider = divider;
@@ -68,6 +72,8 @@ static inline void timer_ll_get_divider(timg_dev_t *hw, timer_idx_t timer_num, u
uint32_t d = hw->hw_timer[timer_num].config.divider; uint32_t d = hw->hw_timer[timer_num].config.divider;
if (d == 0) { if (d == 0) {
d = 65536; d = 65536;
} else if (d == 1) {
d = 2;
} }
*divider = d; *divider = d;
} }
@@ -326,16 +332,7 @@ FORCE_INLINE_ATTR void timer_ll_get_intr_raw_status(timer_group_t group_num, uin
*/ */
static inline void timer_ll_set_level_int_enable(timg_dev_t *hw, timer_idx_t timer_num, bool level_int_en) static inline void timer_ll_set_level_int_enable(timg_dev_t *hw, timer_idx_t timer_num, bool level_int_en)
{ {
switch (timer_num) { // Only "level" interrupts are supported on this target
case 0:
hw->int_ena.t0 = level_int_en;
break;
case 1:
hw->int_ena.t1 = level_int_en;
break;
default:
break;
}
} }
/** /**
@@ -350,18 +347,7 @@ static inline void timer_ll_set_level_int_enable(timg_dev_t *hw, timer_idx_t tim
*/ */
static inline bool timer_ll_get_level_int_enable(timg_dev_t *hw, timer_idx_t timer_num) static inline bool timer_ll_get_level_int_enable(timg_dev_t *hw, timer_idx_t timer_num)
{ {
bool enable = false; return true;
switch (timer_num) {
case 0:
enable = hw->int_ena.t0;
break;
case 1:
enable = hw->int_ena.t1;
break;
default:
break;
}
return enable;
} }
/** /**

View File

@@ -205,12 +205,10 @@
#define SOC_SPI_PERIPH_SUPPORT_MULTILINE_MODE(spi_host) ({(void)spi_host; 1;}) #define SOC_SPI_PERIPH_SUPPORT_MULTILINE_MODE(spi_host) ({(void)spi_host; 1;})
/*-------------------------- TIMER GROUP CAPS --------------------------------*/ /*-------------------------- TIMER GROUP CAPS --------------------------------*/
#define SOC_TIMER_GROUP_COUNTER_BIT_WIDTH (64) #define SOC_TIMER_GROUPS (2)
#define SOC_TIMER_GROUP_PRESCALE_BIT_WIDTH (16) #define SOC_TIMER_GROUP_TIMERS_PER_GROUP (2)
#define SOC_TIMER_GROUPS (2) #define SOC_TIMER_GROUP_COUNTER_BIT_WIDTH (64)
#define SOC_TIMER_GROUP_TIMERS_PER_GROUP (2)
#define SOC_TIMER_GROUP_TOTAL_TIMERS (SOC_TIMER_GROUPS * SOC_TIMER_GROUP_TIMERS_PER_GROUP) #define SOC_TIMER_GROUP_TOTAL_TIMERS (SOC_TIMER_GROUPS * SOC_TIMER_GROUP_TIMERS_PER_GROUP)
#define SOC_TIMER_GROUP_LAYOUT {2,2}
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/ /*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
#define SOC_TOUCH_SENSOR_NUM (10) #define SOC_TOUCH_SENSOR_NUM (10)

View File

@@ -26,7 +26,6 @@
#include "i2s_caps.h" #include "i2s_caps.h"
#include "rtc_io_caps.h" #include "rtc_io_caps.h"
#include "soc_caps.h" #include "soc_caps.h"
#include "timer_group_caps.h"
#include "cpu_caps.h" #include "cpu_caps.h"
#include "gpio_caps.h" #include "gpio_caps.h"
#include "ledc_caps.h" #include "ledc_caps.h"
@@ -76,6 +75,12 @@
#define SOC_SHA_SUPPORT_SHA224 (1) #define SOC_SHA_SUPPORT_SHA224 (1)
#define SOC_SHA_SUPPORT_SHA256 (1) #define SOC_SHA_SUPPORT_SHA256 (1)
/*--------------------------- TIMER GROUP CAPS ---------------------------------------*/
#define SOC_TIMER_GROUPS (2)
#define SOC_TIMER_GROUP_TIMERS_PER_GROUP (1)
#define SOC_TIMER_GROUP_COUNTER_BIT_WIDTH (54)
#define SOC_TIMER_GROUP_SUPPORT_XTAL (1)
#define SOC_TIMER_GROUP_TOTAL_TIMERS (SOC_TIMER_GROUPS * SOC_TIMER_GROUP_TIMERS_PER_GROUP)
/*--------------------------- RMT CAPS ---------------------------------------*/ /*--------------------------- RMT CAPS ---------------------------------------*/
#define SOC_RMT_GROUPS (1) /*!< One RMT group */ #define SOC_RMT_GROUPS (1) /*!< One RMT group */

View File

@@ -1,24 +0,0 @@
// Copyright 2020 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.
#pragma once
#define SOC_TIMER_GROUP_SUPPORT_XTAL (1)
#define SOC_TIMER_GROUP_XTAL_MHZ (40)
#define SOC_TIMER_GROUP_COUNTER_BIT_WIDTH (54)
#define SOC_TIMER_GROUP_PRESCALE_BIT_WIDTH (16)
#define SOC_TIMER_GROUPS (2)
#define SOC_TIMER_GROUP_TIMERS_PER_GROUP (1)
#define SOC_TIMER_GROUP_TOTAL_TIMERS (SOC_TIMER_GROUPS * SOC_TIMER_GROUP_TIMERS_PER_GROUP)
#define SOC_TIMER_GROUP_LAYOUT {1,1}

View File

@@ -206,7 +206,7 @@ typedef volatile struct {
union { union {
struct { struct {
uint32_t reserved0: 29; uint32_t reserved0: 29;
uint32_t clk_is_active: 1; uint32_t wdt_clk_is_active: 1;
uint32_t timer_clk_is_active: 1; uint32_t timer_clk_is_active: 1;
uint32_t en: 1; uint32_t en: 1;
}; };

View File

@@ -217,14 +217,11 @@
#define SOC_SYSTIMER_BIT_WIDTH_HI (32) // Bit width of systimer high part #define SOC_SYSTIMER_BIT_WIDTH_HI (32) // Bit width of systimer high part
/*-------------------------- TIMER GROUP CAPS --------------------------------*/ /*-------------------------- TIMER GROUP CAPS --------------------------------*/
#define SOC_TIMER_GROUP_SUPPORT_XTAL (1) #define SOC_TIMER_GROUP_COUNTER_BIT_WIDTH (64)
#define SOC_TIMER_GROUP_XTAL_MHZ (40) #define SOC_TIMER_GROUPS (2)
#define SOC_TIMER_GROUP_COUNTER_BIT_WIDTH (64) #define SOC_TIMER_GROUP_TIMERS_PER_GROUP (2)
#define SOC_TIMER_GROUP_PRESCALE_BIT_WIDTH (16) #define SOC_TIMER_GROUP_SUPPORT_XTAL (1)
#define SOC_TIMER_GROUPS (2)
#define SOC_TIMER_GROUP_TIMERS_PER_GROUP (2)
#define SOC_TIMER_GROUP_TOTAL_TIMERS (SOC_TIMER_GROUPS * SOC_TIMER_GROUP_TIMERS_PER_GROUP) #define SOC_TIMER_GROUP_TOTAL_TIMERS (SOC_TIMER_GROUPS * SOC_TIMER_GROUP_TIMERS_PER_GROUP)
#define SOC_TIMER_GROUP_LAYOUT {2,2}
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/ /*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
#define SOC_TOUCH_SENSOR_NUM (15) /*! 15 Touch channels */ #define SOC_TOUCH_SENSOR_NUM (15) /*! 15 Touch channels */

View File

@@ -95,13 +95,11 @@
#include "systimer_caps.h" #include "systimer_caps.h"
/*-------------------------- TIMER GROUP CAPS --------------------------------*/ /*-------------------------- TIMER GROUP CAPS --------------------------------*/
#define SOC_TIMER_GROUP_SUPPORT_XTAL (1) #define SOC_TIMER_GROUPS (2)
#define SOC_TIMER_GROUP_COUNTER_BIT_WIDTH (54) #define SOC_TIMER_GROUP_TIMERS_PER_GROUP (2)
#define SOC_TIMER_GROUP_PRESCALE_BIT_WIDTH (16) #define SOC_TIMER_GROUP_COUNTER_BIT_WIDTH (54)
#define SOC_TIMER_GROUPS (2) #define SOC_TIMER_GROUP_SUPPORT_XTAL (1)
#define SOC_TIMER_GROUP_TIMERS_PER_GROUP (2)
#define SOC_TIMER_GROUP_TOTAL_TIMERS (SOC_TIMER_GROUPS * SOC_TIMER_GROUP_TIMERS_PER_GROUP) #define SOC_TIMER_GROUP_TOTAL_TIMERS (SOC_TIMER_GROUPS * SOC_TIMER_GROUP_TIMERS_PER_GROUP)
#define SOC_TIMER_GROUP_LAYOUT {2,2}
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/ /*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
#include "touch_sensor_caps.h" #include "touch_sensor_caps.h"