summaryrefslogtreecommitdiff
path: root/chip/npcx/hwtimer.c
diff options
context:
space:
mode:
Diffstat (limited to 'chip/npcx/hwtimer.c')
-rw-r--r--chip/npcx/hwtimer.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/chip/npcx/hwtimer.c b/chip/npcx/hwtimer.c
index b479f237c0..dfa06f69b2 100644
--- a/chip/npcx/hwtimer.c
+++ b/chip/npcx/hwtimer.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -19,10 +19,10 @@
#include "util.h"
/* Depth of event timer */
-#define TICK_EVT_DEPTH 16 /* Depth of event timer Unit: bits */
-#define TICK_EVT_INTERVAL BIT(TICK_EVT_DEPTH) /* Unit: us */
+#define TICK_EVT_DEPTH 16 /* Depth of event timer Unit: bits */
+#define TICK_EVT_INTERVAL BIT(TICK_EVT_DEPTH) /* Unit: us */
#define TICK_EVT_INTERVAL_MASK (TICK_EVT_INTERVAL - 1) /* Mask of interval */
-#define TICK_EVT_MAX_CNT (TICK_EVT_INTERVAL - 1) /* Maximum event counter */
+#define TICK_EVT_MAX_CNT (TICK_EVT_INTERVAL - 1) /* Maximum event counter */
/* Time when event will be expired unit:us */
static volatile uint32_t evt_expired_us;
@@ -39,7 +39,7 @@ static volatile uint32_t cur_cnt_us_dbg;
#define CPRINTS(...)
#else
#define CPUTS(outstr) cputs(CC_CLOCK, outstr)
-#define CPRINTS(format, args...) cprints(CC_CLOCK, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_CLOCK, format, ##args)
#endif
/*****************************************************************************/
@@ -48,7 +48,7 @@ void init_hw_timer(int itim_no, enum ITIM_SOURCE_CLOCK_T source)
{
/* Select which clock to use for this timer */
UPDATE_BIT(NPCX_ITCTS(itim_no), NPCX_ITCTS_CKSEL,
- source != ITIM_SOURCE_CLOCK_APB2);
+ source != ITIM_SOURCE_CLOCK_APB2);
/* Clear timeout status */
SET_BIT(NPCX_ITCTS(itim_no), NPCX_ITCTS_TO_STS);
@@ -64,8 +64,8 @@ void init_hw_timer(int itim_no, enum ITIM_SOURCE_CLOCK_T source)
/* HWTimer event handlers */
void __hw_clock_event_set(uint32_t deadline)
{
- fp_t inv_evt_tick = FLOAT_TO_FP(INT_32K_CLOCK/(float)SECOND);
- int32_t evt_cnt_us;
+ fp_t inv_evt_tick = FLOAT_TO_FP(INT_32K_CLOCK / (float)SECOND);
+ int32_t evt_cnt_us;
/* Is deadline min value? */
if (evt_expired_us != 0 && evt_expired_us < deadline)
return;
@@ -87,10 +87,10 @@ void __hw_clock_event_set(uint32_t deadline)
* ITIM count down : event expired : Unit: 1/32768 sec
* It must exceed evt_expired_us for process_timers function
*/
- evt_cnt = FP_TO_INT((fp_inter_t)(evt_cnt_us) * inv_evt_tick);
+ evt_cnt = FP_TO_INT((fp_inter_t)(evt_cnt_us)*inv_evt_tick);
if (evt_cnt > TICK_EVT_MAX_CNT) {
- CPRINTS("Event overflow! 0x%08x, us is %d",
- evt_cnt, evt_cnt_us);
+ CPRINTS("Event overflow! 0x%08x, us is %d", evt_cnt,
+ evt_cnt_us);
evt_cnt = TICK_EVT_MAX_CNT;
}
@@ -136,16 +136,17 @@ uint16_t __hw_clock_event_count(void)
/* Returns time delay cause of deep idle */
uint32_t __hw_clock_get_sleep_time(uint16_t pre_evt_cnt)
{
- fp_t evt_tick = FLOAT_TO_FP(SECOND/(float)INT_32K_CLOCK);
+ fp_t evt_tick = FLOAT_TO_FP(SECOND / (float)INT_32K_CLOCK);
uint32_t sleep_time;
uint16_t cnt = __hw_clock_event_count();
/* Event has been triggered but timer ISR doesn't handle it */
if (IS_BIT_SET(NPCX_ITCTS(ITIM_EVENT_NO), NPCX_ITCTS_TO_STS))
- sleep_time = FP_TO_INT((fp_inter_t)(pre_evt_cnt+1) * evt_tick);
+ sleep_time =
+ FP_TO_INT((fp_inter_t)(pre_evt_cnt + 1) * evt_tick);
/* Event hasn't been triggered */
else
- sleep_time = FP_TO_INT((fp_inter_t)(pre_evt_cnt+1 - cnt) *
+ sleep_time = FP_TO_INT((fp_inter_t)(pre_evt_cnt + 1 - cnt) *
evt_tick);
return sleep_time;
@@ -194,7 +195,6 @@ static void __hw_clock_event_irq(void)
if (evt_expired_us == 0)
__hw_clock_event_set(EVT_MAX_EXPIRED_US);
#endif
-
}
DECLARE_IRQ(ITIM_INT(ITIM_EVENT_NO), __hw_clock_event_irq, 3);
@@ -295,10 +295,9 @@ static void update_prescaler(void)
* Ttick_unit = (PRE_8+1) * Tapb2_clk
* PRE_8 = (Ttick_unit/Tapb2_clk) -1
*/
- NPCX_ITPRE(ITIM_SYSTEM_NO) = (clock_get_apb2_freq() / SECOND) - 1;
+ NPCX_ITPRE(ITIM_SYSTEM_NO) = (clock_get_apb2_freq() / SECOND) - 1;
/* Set event tick unit = 1/32768 sec */
NPCX_ITPRE(ITIM_EVENT_NO) = 0;
-
}
DECLARE_HOOK(HOOK_FREQ_CHANGE, update_prescaler, HOOK_PRIO_DEFAULT);
@@ -311,10 +310,10 @@ void __hw_early_init_hwtimer(uint32_t start_t)
/* Enable clock for ITIM peripheral */
clock_enable_peripheral(CGC_OFFSET_TIMER, CGC_TIMER_MASK,
- CGC_MODE_RUN | CGC_MODE_SLEEP);
+ CGC_MODE_RUN | CGC_MODE_SLEEP);
/* init tick & event timer first */
- init_hw_timer(ITIM_SYSTEM_NO, ITIM_SOURCE_CLOCK_APB2);
+ init_hw_timer(ITIM_SYSTEM_NO, ITIM_SOURCE_CLOCK_APB2);
init_hw_timer(ITIM_EVENT_NO, ITIM_SOURCE_CLOCK_32K);
/* Set initial prescaler */