ISF  2.1
Intelligent Sensing Framework for Kinetis with Processor Expert
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
bm_timer.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014, Freescale Semiconductor, Inc.
4  *
5 */
6 
7 /*!
8  * @file bm_timer.h
9  * @brief Bus managment internal header file.
10  *
11  */
12 
13 
14 #ifndef BM_TIMER_H
15 #define BM_TIMER_H
16 
17 #include "bm_internal.h"
18 
19 
20 #if (ISF_BM_USE_TPM == 0)
21  #define TPM_IRQ_VECTOR INT_TPM0
22  #define TPM_INDEX 0
23  #define TPM_BASE_ADDR TPM0_BASE_PTR
24  #define TPM_CLK_SRC TPM_PDD_SYSTEM
25 #elif (ISF_BM_USE_TPM == 1)
26  #define TPM_IRQ_VECTOR INT_TPM1
27  #define TPM_INDEX 1
28  #define TPM_BASE_ADDR TPM1_BASE_PTR
29  #define TPM_CLK_SRC TPM_PDD_SYSTEM
30 #elif (ISF_BM_USE_TPM == 2)
31  #define TPM_IRQ_VECTOR INT_TPM2
32  #define TPM_INDEX 2
33  #define TPM_BASE_ADDR TPM2_BASE_PTR
34  #define TPM_CLK_SRC TPM_PDD_SYSTEM
35 #else
36  #Error: Unknown TPM timer defined!!
37 #endif
38 
39 
40 #if (ISF_BM_TIMER_COUNTER_CLKSRC == 0)
41  #define TPM_COUNTER_CLK_SRC TPM_COUNTER_CLKSRC_DISABLE
42 #elif (ISF_BM_TIMER_COUNTER_CLKSRC == 1)
43  #define TPM_COUNTER_CLK_SRC TPM_COUNTER_CLKSRC_MCGFLLCLK_MCGPLLCLK2
44 #elif (ISF_BM_TIMER_COUNTER_CLKSRC == 2)
45  #define TPM_COUNTER_CLK_SRC TPM_COUNTER_CLKSRC_EXTREF
46 #elif (ISF_BM_TIMER_COUNTER_CLKSRC == 3)
47  #define TPM_COUNTER_CLK_SRC TPM_COUNTER_CLKSRC_INTREF
48 #else
49  #Error: Invalid tpm counter clock source defined!
50 #endif
51 
52 
54 
55 #define BM_TIMER_STOP() TPM_TIMER_STOP(TPM_BASE_ADDR)
56 
57 #define BM_TIMER_START() TPM_TIMER_START(TPM_BASE_ADDR, TPM_CLK_SRC)
58 
59 #define BM_TIMER_CLEAR_IRQ() TPM_TIMER_CLEAR_IRQ(TPM_BASE_ADDR)
60 
61 #define BM_TIMER_SAVE_RUN_STATE() TPM_TIMER_SAVE_RUN_STATE(TPM_BASE_ADDR, TPM_INDEX)
62 
63 #define BM_TIMER_RESTORE_RUN_STATE() TPM_TIMER_RESTORE_RUN_STATE(TPM_BASE_ADDR, TPM_INDEX)
64 
65 // Save the run state and stop timer.
66 #define BM_TIMER_SAVE_STOP() { BM_TIMER_SAVE_RUN_STATE() BM_TIMER_STOP() }
67 
68 #define BM_TIMER_GET_MODULO() TPM_TIMER_GET_MODULO(TPM_BASE_ADDR)
69 #define BM_TIMER_SET_MODULO(x) TPM_TIMER_SET_MODULO(TPM_BASE_ADDR, x)
70 
71 #define BM_TIMER_GET_COUNT() TPM_TIMER_GET_COUNT(TPM_BASE_ADDR)
72 
73 #define BM_TIMER_COUNTER_RESET() TPM_TIMER_COUNTER_RESET(TPM_BASE_ADDR)
74 
75 // Get time remaining until timer rollover.
76 #define BM_TIMER_GET_TIME_REMAINING() TPM_TIMER_GET_TIME_REMAINING(TPM_BASE_ADDR)
77 
78 #define BM_TIMER_SET_PRESCALER(x) TPM_TIMER_SET_PRESCALER(TPM_BASE_ADDR, x)
79 
80 #define BM_TIMER_ENABLE_IRQ() TPM_TIMER_ENABLE_TOF_IRQ(TPM_BASE_ADDR)
81 
82 #define BM_TIMER_INSTALL_ISR(isr, ptr) tpm_install_isr(isr, ptr, TPM_INDEX)
83 
84 //#define ISF_BM_PIT_INSTANCE (0)
85 
86 
87 void bm_timer_init(boolean bEnableirq, uint32 usec);
88 
89 #ifdef BM_DEBUG_LATENCY_TEST
90 
91 #define TIMER_TPM_GET_CNT() ((uint32)TPM0_CNT)
92 #define TIMER_TPM_CLEAR_OVF_FLAG() { TPM0_SC &= ~0x80; }
93 
94 #define TIMER_TPM_START() { TPM0_CNT = (uint_16)0xffff; }
95 #define TIMER_TPM_STOP() { TPM0_SC &= ~0x18; }
96 
97 // Starts timer running again. Does not affect current timer count or rollover count.
98 #define TIMER_TPM_RESTORE_RUNSTATE() { TPM0_SC &= ~0x18; TPM0_SC |= (0x18 & tpm_TPM0_SC); }
99 
100 //Prescale = 3 or div by 8, assume ext ref clk 8MHzhz (1 count means 1 usec), free running timer, no irq.
101 #define TIMER_TPM_INIT() { TPM0_SC = 0x00; TPM0_MOD = 0xffff; TPM0_SC = (1 << 3) | 3; TPM0_CNT = (uint_16)0xffff; }
102 
103 #endif
104 
105 #define TIMER_TPM_GET_CNT() ((uint32)TPM0_CNT)
106 #define TIMER_TPM_CLEAR_OVF_FLAG() { TPM0_SC &= ~0x80; }
107 
108 #define TIMER_TPM_START() { TPM0_CNT = (uint_16)0xffff; }
109 #define TIMER_TPM_STOP() { TPM0_SC &= ~0x18; }
110 
111 // Starts timer running again. Does not affect current timer count or rollover count.
112 #define TIMER_TPM_RESTORE_RUNSTATE() { TPM0_SC &= ~0x18; TPM0_SC |= (0x18 & tpm_TPM0_SC); }
113 
114 //Prescale = 3 or div by 8, assume ext ref clk 8MHzhz (1 count means 1 usec), free running timer, no irq.
115 #define TIMER_TPM_INIT() { TPM0_SC = 0x00; TPM0_MOD = 0xffff; TPM0_SC = (1 << 3) | 3; TPM0_CNT = (uint_16)0xffff; }
116 
117 #endif // BM_INTERNAL_H
118 
unsigned char uint8
This defines uint8 as unsigned char.
Definition: isf_types.h:18
unsigned long uint32
This defines uint32 as unsigned long.
Definition: isf_types.h:36
BM_VOLATILE uint8 gBm_timer_run_state
ISF bus management internal header file.
#define BM_VOLATILE
Definition: bm_internal.h:33
void bm_timer_init(boolean bEnableirq, uint32 usec)
Timer initialization .
Definition: bm_timer.c:31