]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/IA32_flat_GCC_Galileo_Gen_2/Support_Files/HPET.h
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / IA32_flat_GCC_Galileo_Gen_2 / Support_Files / HPET.h
1 /*--------------------------------------------------------------------\r
2  Copyright(c) 2015 Intel Corporation. All rights reserved.\r
3 \r
4  Redistribution and use in source and binary forms, with or without\r
5  modification, are permitted provided that the following conditions\r
6  are met:\r
7 \r
8  * Redistributions of source code must retain the above copyright\r
9  notice, this list of conditions and the following disclaimer.\r
10  * Redistributions in binary form must reproduce the above copyright\r
11  notice, this list of conditions and the following disclaimer in\r
12  the documentation and/or other materials provided with the\r
13  distribution.\r
14  * Neither the name of Intel Corporation nor the names of its\r
15  contributors may be used to endorse or promote products derived\r
16  from this software without specific prior written permission.\r
17 \r
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
19  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
20  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
21  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
22  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
23  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
24  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
25  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
26  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
27  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
29  --------------------------------------------------------------------*/\r
30 \r
31 #ifndef HPET_H\r
32 #define HPET_H\r
33 \r
34 #ifdef __cplusplus\r
35         extern "C" {\r
36 #endif\r
37 \r
38 //---------------------------------------------------------------------\r
39 // HPET support definitions\r
40 //---------------------------------------------------------------------\r
41 #define hpetUSE_HPET_TIMER_NUMBER_0                     ( 1 )     // 0 = false, 1 = true\r
42 #define hpetUSE_HPET_TIMER_NUMBER_1                     ( 1 )     // 0 = false, 1 = true\r
43 #define hpetUSE_HPET_TIMER_NUMBER_2                     ( 1 )     // 0 = false, 1 = true\r
44 \r
45 //---------------------------------------------------------------------\r
46 // HPE timers general purpose register addresses\r
47 //---------------------------------------------------------------------\r
48 #define hpetHPET_GENERAL_ID                                     ( *( ( volatile uint32_t * ) 0xFED00000UL ) )\r
49 #define hpetHPET_COUNTER_TICK_PERIOD            ( *( ( volatile uint32_t * ) 0xFED00004UL ) )\r
50 #define hpetHPET_GENERAL_CONFIGURATION          ( *( ( volatile uint32_t * ) 0xFED00010UL ) )\r
51 #define hpetHPET_GENERAL_STATUS                         ( *( ( volatile uint32_t * ) 0xFED00020UL ) )\r
52 #define hpetHPET_MAIN_CTR_LOW                           ( *( ( volatile uint32_t * ) 0xFED000F0UL ) )\r
53 #define hpetHPET_MAIN_CTR_HIGH                          ( *( ( volatile uint32_t * ) 0xFED000F4UL ) )\r
54 \r
55 //---------------------------------------------------------------------\r
56 // HPE timer specific support definitions\r
57 //---------------------------------------------------------------------\r
58 #if (hpetUSE_HPET_TIMER_NUMBER_0 == 1)\r
59         #define TIMER0_TRIGGERING                               ( 0 )           // 1 = level, 0 = edge\r
60         #define TIMER0_POLARITY                                 ( 0 )           // 0 = active high, 1 = active low\r
61         #define TIMER0_IRQ                                              ( 2 )           // 0 is default for legacy 8259, 2 for IO APIC\r
62         #define hpetHPET_TIMER0_ISR_VECTOR              ( 0x32 )        // HPET Timer - I/O APIC\r
63         #define hpetHPET_TIMER0_INTERRUPT_RATE  ( 2000 )        // Number of times per second to interrupt\r
64         #define hpetHPET_TMR0_CONFIG_LOW                ( *( ( volatile uint32_t * ) 0xFED00100UL ) )\r
65         #define hpetHPET_TMR0_CONFIG_HIGH               ( *( ( volatile uint32_t * ) 0xFED00104UL ) )\r
66         #define hpetHPET_TMR0_COMPARATOR_LOW    ( *( ( volatile uint32_t * ) 0xFED00108UL ) )\r
67         #define hpetHPET_TMR0_COMPARATOR_HIGH   ( *( ( volatile uint32_t * ) 0xFED0010CUL ) )\r
68 #endif\r
69 #if (hpetUSE_HPET_TIMER_NUMBER_1 == 1)\r
70         #define TIMER1_TRIGGERING                               ( 0 )           // 1 = level, 0 = edge\r
71         #define TIMER1_POLARITY                                 ( 0 )           // 0 = active high, 1 = active low\r
72         #define TIMER1_IRQ                                              ( 8 )           // 8 is default for 8259 & IO APIC\r
73         #define hpetHPET_TIMER1_ISR_VECTOR              ( 0x85 )        // HPET Timer - I/O APIC\r
74         #define hpetHPET_TIMER1_INTERRUPT_RATE  ( 1500 )        // Number of times per second to interrupt\r
75         #define hpetHPET_TMR1_CONFIG_LOW                ( *( ( volatile uint32_t * ) 0xFED00120UL ) )\r
76         #define hpetHPET_TMR1_CONFIG_HIGH               ( *( ( volatile uint32_t * ) 0xFED00124UL ) )\r
77         #define hpetHPET_TMR1_COMPARATOR_LOW    ( *( ( volatile uint32_t * ) 0xFED00128UL ) )\r
78         #define hpetHPET_TMR1_COMPARATOR_HIGH   ( *( ( volatile uint32_t * ) 0xFED0012CUL ) )\r
79 #endif\r
80 #if (hpetUSE_HPET_TIMER_NUMBER_2 == 1)\r
81         #define TIMER2_TRIGGERING                               ( 0 )           // 1 = level, 0 = edge\r
82         #define TIMER2_POLARITY                                 ( 0 )           // 0 = active high, 1 = active low\r
83         #define TIMER2_IRQ                                              ( 11 )          // 11 is default for 8259 & IO APIC\r
84         #define hpetHPET_TIMER2_ISR_VECTOR              ( 0x95 )        // HPET Timer - I/O APIC\r
85         #define hpetHPET_TIMER2_INTERRUPT_RATE  ( 1400 )        // Number of times per second to interrupt\r
86         #define hpetHPET_TMR2_CONFIG_LOW                ( *( ( volatile uint32_t * ) 0xFED00140UL ) )\r
87         #define hpetHPET_TMR2_CONFIG_HIGH               ( *( ( volatile uint32_t * ) 0xFED00144UL ) )\r
88         #define hpetHPET_TMR2_COMPARATOR_LOW    ( *( ( volatile uint32_t * ) 0xFED00148UL ) )\r
89         #define hpetHPET_TMR2_COMPARATOR_HIGH   ( *( ( volatile uint32_t * ) 0xFED0014CUL ) )\r
90 #endif\r
91 \r
92 //---------------------------------------------------------------------\r
93 // Disables code if no timer is enabled (quiets the compiler)\r
94 //---------------------------------------------------------------------\r
95 #define hpetHPET_TIMER_IN_USE (hpetUSE_HPET_TIMER_NUMBER_0 | hpetUSE_HPET_TIMER_NUMBER_1 | hpetUSE_HPET_TIMER_NUMBER_2)\r
96 \r
97 //---------------------------------------------------------------------\r
98 // Allow HPET variable printout on screen (1 = allow)\r
99 //---------------------------------------------------------------------\r
100 #define hpetHPET_PRINT_INFO                             0\r
101 \r
102 //---------------------------------------------------------------------\r
103 // HPET bit checking and manipulation definitions\r
104 //---------------------------------------------------------------------\r
105 #define hpetHPET_CFG_ENABLE                             0x001\r
106 #define hpetHPET_CFG_LEGACY                             0x002\r
107 #define hpetHPET_TN_ENABLE                      0x004\r
108 #define hpetHPET_TN_PERIODIC                    0x008\r
109 #define hpetHPET_TN_PERIODIC_CAP                0x010\r
110 #define hpetHPET_TN_SETVAL                      0x040\r
111 #define hpetHPET_TN_32BIT                       0x100\r
112 #define hpetHPET_INT_EDGE                                       0x000\r
113 #define hpetHPET_INT_LEVEL                                      0x001\r
114 #define hpetHPET_POL_HIGH                                       0x000\r
115 #define hpetHPET_POL_LOW                                        0x001\r
116 \r
117 //---------------------------------------------------------------------\r
118 // I/O APIC register addresses and definitions\r
119 //---------------------------------------------------------------------\r
120 #define hpetIO_APIC_IDX                                         ( *( ( volatile uint32_t * ) 0xFEC00000UL ) )\r
121 #define hpetIO_APIC_WDW                                         ( *( ( volatile uint32_t * ) 0xFEC00010UL ) )\r
122 #define hpetIO_APIC_EOI                                         ( *( ( volatile uint32_t * ) 0xFEC00040UL ) )\r
123 \r
124 #define hpetIO_APIC_ID                                          0x00    // Get/Set APIC ID information\r
125 #define hpetIO_APIC_VERSION                                     0x01    // Get APIC version information\r
126 #define hpetIO_APIC_RTE_OFFSET                          0x10    // add 2* RTE Table (0-23) to this offset\r
127 \r
128 //---------------------------------------------------------------------\r
129 // Used for timer calibration\r
130 //---------------------------------------------------------------------\r
131 #define hpetLVTIMER                                             ( 0 )    // Constant definition\r
132 #define hpetHPETIMER                                            ( 1 )    // Constant definition\r
133 \r
134 //---------------------------------------------------------------------\r
135 // HPET variables Structure\r
136 //---------------------------------------------------------------------\r
137 struct __attribute__ ((__packed__)) hpet_info\r
138 {\r
139         unsigned int    timer_number;\r
140         unsigned int    main_counter_h;\r
141         unsigned int    main_counter_l;\r
142         unsigned int    comparator_h;\r
143         unsigned int    comparator_l;\r
144         unsigned int    total_interrupts;\r
145         unsigned int    elapsed_seconds;\r
146 };\r
147 \r
148 //---------------------------------------------------------------------\r
149 // Variables other modules may want to access\r
150 //---------------------------------------------------------------------\r
151 extern volatile uint32_t hpet_general_status;\r
152 extern volatile uint32_t ulHPETTimerNumber [3];\r
153 extern volatile uint32_t ulHPETTotalInterrupts [3];\r
154 extern volatile uint32_t ulHPETElapsedSeconds [3];\r
155 extern volatile uint32_t ulHPETInterruptFrequency [3];\r
156 extern volatile uint32_t ulHPETTicksToInterrupt [3];\r
157 extern struct hpet_info PrintInfo[3];\r
158 \r
159 //---------------------------------------------------------------------\r
160 // Function prototypes\r
161 //---------------------------------------------------------------------\r
162 #if (hpetHPET_TIMER_IN_USE)\r
163         void vClearHPETElapsedSeconds( void );\r
164         uint32_t uiCalibrateTimer(uint32_t TimerNumber, uint32_t TimerType );\r
165         void vInitializeAllHPETInterrupts( void );\r
166         void vCreateHPETInfoUpdateTask( void  );\r
167 #endif\r
168 \r
169 #ifdef __cplusplus\r
170         } /* extern C */\r
171 #endif\r
172 \r
173 #endif /* HPET_H */\r
174 \r