1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\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
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
14 * -------------------------------- Arctic Core ------------------------------*/
\r
19 * Created on: 2009-okt-02
\r
22 #warning "This default file may only be used as an example!"
\r
27 /****************************************************************************
\r
28 * Global configuration options and defines
\r
31 * PWM003: The detection of development errors is configurable (STD_ON/STD_OFF) at
\r
32 * pre-compile time. The switch PwmDevErorDetect shall activate or disable
\r
33 * the detection of all development errors
\r
35 #define PWM_DEV_EROR_DETECT STD_ON
\r
36 #define PWM_GET_OUTPUT_STATE STD_ON
\r
37 #define PWM_STATICALLY_CONFIGURED STD_OFF
\r
38 #define PWM_NOTIFICATION_SUPPORTED STD_ON
\r
40 #define PWM_SET_PERIOD_AND_DUTY STD_ON
\r
43 * PWM132: Switch for enabling the update of duty cycle parameter at the end
\r
44 * of the current period.
\r
46 * Note: Currently only STD_ON mode is supported.
\r
48 #define PWM_DUTYCYCLE_UPDATED_ENDPERIOD STD_ON
\r
51 * Setting to STD_ON freezes the current output state of a PWM channel when in
\r
54 #define PWM_FREEZE_ENABLE STD_ON
\r
56 typedef uint16 Pwm_PeriodType;
\r
59 * PWM106: This is implementation specific but not all values may be valid
\r
60 * within the type. This shall be chosen in order to have the most efficient
\r
61 * implementation on a specific microcontroller platform.
\r
63 * PWM106 => Pwm_ChannelType == eemios channel id.
\r
66 PWM_CHANNEL_11 = 0, // TIM1 Channel 1
\r
70 PWM_CHANNEL_21, // TIM2 Channel 1
\r
74 PWM_CHANNEL_31, // TIM3 Channel 1
\r
78 PWM_CHANNEL_41, // TIM4 Channel 1
\r
82 PWM_TOTAL_NOF_CHANNELS,
\r
85 /****************************************************************************
\r
86 * Enumeration of channels
\r
87 * Maps a symbolic name to a hardware channel
\r
90 PWM_CHANNEL_1 = PWM_CHANNEL_23, //PB10
\r
91 PWM_CHANNEL_2 = PWM_CHANNEL_24, //PB11
\r
92 PWM_NUMBER_OF_CHANNELS = 2
\r
93 } Pwm_NamedChannelsType;
\r
99 PWM_CHANNEL_PRESCALER_1=0,
\r
100 PWM_CHANNEL_PRESCALER_2,
\r
101 PWM_CHANNEL_PRESCALER_3,
\r
102 PWM_CHANNEL_PRESCALER_4,
\r
103 } Pwm_ChannelPrescalerType;
\r
105 #define DUTY_AND_PERIOD(_duty,_period) .duty = (_duty*_period)>>15, .period = _period
\r
108 /* Number of duty ticks */
\r
110 /* Length of period, in ticks */
\r
111 uint32_t period:32;
\r
113 uint32_t counter:32;
\r
114 /* Enable freezing the channel when in debug mode */
\r
115 uint32_t freezeEnable:1;
\r
116 /* Disable output */
\r
117 uint32_t outputDisable:1;
\r
118 /* Select which bus disables the bus
\r
119 * TODO: Figure out how this works, i.e. what bus does it refer to? */
\r
120 uint32_t outputDisableSelect:2;
\r
121 /* Prescale the emios clock some more? */
\r
122 Pwm_ChannelPrescalerType prescaler:2;
\r
123 /* Prescale the emios clock some more? */
\r
124 uint32_t usePrescaler:1;
\r
125 /* Whether to use DMA. Currently unsupported */
\r
127 uint32_t reserved_2:1;
\r
128 /* Input filter. Ignored in output mode. */
\r
129 uint32_t inputFilter:4;
\r
130 /* Input filter clock source. Ignored in output mode */
\r
131 uint32_t filterClockSelect:1;
\r
132 /* Enable interrupts/flags on this channel? Required for DMA as well. */
\r
133 uint32_t flagEnable:1;
\r
134 uint32_t reserved_3:3;
\r
135 /* Trigger a match on channel A */
\r
136 uint32_t forceMatchA:1;
\r
137 /* Triggers a match on channel B */
\r
138 uint32_t forceMatchB:1;
\r
139 uint32_t reserved_4:1;
\r
140 /* We can use different buses for the counter. Use the internal counter */
\r
141 uint32_t busSelect:2;
\r
142 /* What edges to flag on? */
\r
143 uint32_t edgeSelect:1;
\r
144 /* Polarity of the channel */
\r
145 uint32_t edgePolarity:1;
\r
146 /* EMIOS mode. 0x58 for buffered output PWM */
\r
148 } Pwm_ChannelRegisterType;
\r
151 Pwm_ChannelRegisterType r;
\r
152 Pwm_ChannelType channel;
\r
153 } Pwm_ChannelConfigurationType;
\r
157 Pwm_ChannelConfigurationType Channels[PWM_NUMBER_OF_CHANNELS];
\r
158 #if PWM_NOTIFICATION_SUPPORTED==STD_ON
\r
159 Pwm_NotificationHandlerType NotificationHandlers[PWM_NUMBER_OF_CHANNELS];
\r
163 // Channel configuration macro.
\r
164 #define PWM_CHANNEL_CONFIG(_hwchannel, _period, _duty, _prescaler, _polarity) \
\r
166 .channel = _hwchannel,\
\r
168 DUTY_AND_PERIOD(_duty, _period),\
\r
169 .freezeEnable = 1,\
\r
170 .outputDisable = 0,\
\r
171 .usePrescaler = 1,\
\r
172 .prescaler = _prescaler,\
\r
174 .flagEnable = 0, /* See PWM052 */ \
\r
175 .busSelect = 3, /* Use the internal counter bus */\
\r
176 .edgePolarity = _polarity,\
\r
181 #endif /*PWM_CFG_H_*/
\r