]> rtime.felk.cvut.cz Git - arc.git/blob - boards/mpc5516it/config/Pwm_Cfg.h
Cleanup of some drivers. Re-generated examples for mpc551xsim
[arc.git] / boards / mpc5516it / config / Pwm_Cfg.h
1 /* -------------------------------- Arctic Core ------------------------------\r
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
3  *\r
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
5  *\r
6  * This source code is free software; you can redistribute it and/or modify it\r
7  * under the terms of the GNU General Public License version 2 as published by the\r
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
9  *\r
10  * This program is distributed in the hope that it will be useful, but\r
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
13  * for more details.\r
14  * -------------------------------- Arctic Core ------------------------------*/\r
15 \r
16 /** @addtogroup Pwm PWM Driver\r
17  *  @{ */\r
18 \r
19 /** @file Pwm_Cfg.h\r
20  *  Definitions of configuration parameters for PWM Driver.\r
21  */\r
22 \r
23 #warning "This default file may only be used as an example!"\r
24 \r
25 #ifndef PWM_CFG_H_\r
26 #define PWM_CFG_H_\r
27 \r
28 /*\r
29  * PwmGeneral\r
30  */\r
31 \r
32 /*\r
33  * PWM003: The detection of development errors is configurable (ON/OFF) at\r
34  * pre-compile time. The switch PwmDevErorDetect shall activate or disable\r
35  * the detection of all development errors\r
36  */\r
37 /** Enable Development Error Trace */\r
38 #define PWM_DEV_EROR_DETECT STD_ON\r
39 /** Build GetOutputState() */\r
40 #define PWM_GET_OUTPUT_STATE STD_ON\r
41 /** Determines if module is configurable at runtime */\r
42 #define PWM_STATICALLY_CONFIGURED STD_OFF\r
43 /** Use notifications */\r
44 #define PWM_NOTIFICATION_SUPPORTED STD_ON\r
45 /** Build period and duty API */\r
46 #define PWM_SET_PERIOD_AND_DUTY STD_ON\r
47 \r
48 /**\r
49  * PWM106: This is implementation specific but not all values may be valid\r
50  * within the type. This shall be chosen in order to have the most efficient\r
51  * implementation on a specific microcontroller platform.\r
52  *\r
53  * PWM106 => Pwm_ChannelType == eemios channel id.\r
54  */\r
55 typedef uint8 Pwm_ChannelType;\r
56 \r
57 /**\r
58  * PWM070: All time units used within the API services of the PWM module shall\r
59  * be of the unit ticks.\r
60  */\r
61 typedef uint16 Pwm_PeriodType;\r
62 \r
63 \r
64 /**\r
65  * PWM132: Switch for enabling the update of duty cycle parameter at the end\r
66  * of the current period.\r
67  *\r
68  * Note: Currently only ON mode is supported.\r
69  */\r
70 #define PWM_DUTYCYCLE_UPDATED_ENDPERIOD STD_ON\r
71 \r
72 /****************************************************************************\r
73  * Not defined in AUTOSAR.\r
74  */\r
75 #define PWM_ISR_PRIORITY 1\r
76 #define PWM_PRESCALER 64\r
77 /**\r
78  * Setting to ON freezes the current output state of a PWM channel when in\r
79  * debug mode.\r
80  */\r
81 #define PWM_FREEZE_ENABLE STD_ON\r
82 \r
83 /****************************************************************************\r
84  * Enumeration of channels\r
85  * Maps a symbolic name to a hardware channel\r
86  */\r
87 typedef enum {\r
88 #if defined(CFG_BRD_MPC5516IT)\r
89     PWM_CHANNEL_1 = 13, /* Emios channel 13 and 12 map to the */\r
90     PWM_CHANNEL_2 = 12, /* LEDs LD4 and LD5 of MPC5516IT      */\r
91 \r
92 #elif defined(CFG_BRD_MPC5567QRTECH)\r
93     PWM_CHANNEL_1 = 10, /* Emios channel 10 maps to PCR189 which\r
94                          * is available on pin 54 of the\r
95                          * ERNI 154822 connector\r
96                          */\r
97     PWM_CHANNEL_2 = 12, /* Channel 12 goes to PCR191, also\r
98                          * available on the ERNI 154822 connector\r
99                          */\r
100 #else\r
101 #warning "Unknown board or CFG_BRD_* undefined"\r
102 #endif\r
103     PWM_NUMBER_OF_CHANNELS = 2\r
104 } Pwm_NamedChannelsType;\r
105 \r
106 typedef enum {\r
107         PWM_CHANNEL_PRESCALER_1=0,\r
108         PWM_CHANNEL_PRESCALER_2,\r
109         PWM_CHANNEL_PRESCALER_3,\r
110         PWM_CHANNEL_PRESCALER_4,\r
111 } Pwm_ChannelPrescalerType;\r
112 \r
113 /**\r
114  * Since the AUTOSAR PWM specification uses a different unit for the duty,\r
115  * the following macro can be used to convert between that format and the\r
116  * mpc5516 format.\r
117  */\r
118 #define DUTY_AND_PERIOD(_duty,_period) .duty = (_duty*_period)>>15, .period = _period\r
119 \r
120 #if defined(CFG_MPC5516)\r
121         /** Mode is buffered PWM output (OPWM)\r
122          *  Mode is buffered Output PW and frequency modulation mode */\r
123 #define PWM_EMIOS_OPWM 0x5A\r
124 #elif defined(CFG_MPC5567)\r
125         /** Mode is buffered OPWM with frequency modulation (allows change of\r
126          *  period) */\r
127 #define PWM_EMIOS_OPWM 0x19\r
128 #endif\r
129 \r
130 \r
131 typedef struct {\r
132         /** Number of duty ticks */\r
133         uint32_t                 duty:32;\r
134         /** Length of period, in ticks */\r
135         uint32_t                 period:32;\r
136         /** Counter */\r
137         uint32_t                 counter:32;\r
138         /** Enable freezing the channel when in debug mode */\r
139         uint32_t                 freezeEnable:1;\r
140         /** Disable output */\r
141         uint32_t                 outputDisable:1;\r
142         /** Select which bus disables the bus\r
143          *  TODO: Figure out how this works, i.e. what bus does it refer to? */\r
144         uint32_t                                 outputDisableSelect:2;\r
145         /** Prescale the emios clock some more? */\r
146         Pwm_ChannelPrescalerType prescaler:2;\r
147         /** Prescale the emios clock some more? */\r
148         uint32_t                                 usePrescaler:1;\r
149         /** Whether to use DMA. Currently unsupported */\r
150         uint32_t                                 useDma:1;\r
151         uint32_t                                 reserved_2:1;\r
152         /** Input filter. Ignored in output mode. */\r
153         uint32_t                                 inputFilter:4;\r
154         /** Input filter clock source. Ignored in output mode */\r
155         uint32_t                                 filterClockSelect:1;\r
156         /** Enable interrupts/flags on this channel? Required for DMA as well. */\r
157         uint32_t                                 flagEnable:1;\r
158         uint32_t                                 reserved_3:3;\r
159         /** Trigger a match on channel A */\r
160         uint32_t                                 forceMatchA:1;\r
161         /** Triggers a match on channel B */\r
162         uint32_t                                 forceMatchB:1;\r
163         uint32_t                                 reserved_4:1;\r
164         /** We can use different buses for the counter. Use the internal counter */\r
165         uint32_t                                 busSelect:2;\r
166         /** What edges to flag on? */\r
167         uint32_t                                 edgeSelect:1;\r
168         /** Polarity of the channel */\r
169         uint32_t                                 edgePolarity:1;\r
170         /** EMIOS mode. 0x58 for buffered output PWM */\r
171         uint32_t                                 mode:7;\r
172 } Pwm_ChannelRegisterType;\r
173 \r
174 typedef struct {\r
175         Pwm_ChannelRegisterType r;\r
176         Pwm_ChannelType channel;\r
177 } Pwm_ChannelConfigurationType;\r
178 \r
179 \r
180 typedef struct {\r
181         Pwm_ChannelConfigurationType Channels[PWM_NUMBER_OF_CHANNELS];\r
182 #if PWM_NOTIFICATION_SUPPORTED==STD_ON\r
183         Pwm_NotificationHandlerType NotificationHandlers[PWM_NUMBER_OF_CHANNELS];\r
184 #endif\r
185 } Pwm_ConfigType;\r
186 \r
187 /** Channel configuration macro. */\r
188 #define PWM_CHANNEL_CONFIG(_hwchannel, _period, _duty, _prescaler, _polarity) \\r
189     {\\r
190         .channel = _hwchannel,\\r
191         .r = {\\r
192             DUTY_AND_PERIOD(_duty, _period),\\r
193             .freezeEnable = 1,\\r
194             .outputDisable = 0,\\r
195             .usePrescaler = 1,\\r
196             .prescaler = _prescaler,\\r
197             .useDma = 0,\\r
198             .flagEnable = 0, /* See PWM052 */ \\r
199             .busSelect = 3, /* Use the internal counter bus */\\r
200             .edgePolarity = _polarity,\\r
201             .mode = PWM_EMIOS_OPWM\\r
202         }\\r
203     }\r
204 \r
205 #endif /* PWM_CFG_H_ */\r
206 /** @} */\r