BLDC control on ATAVRMC303 with ATxMega128A1
TC_driver.c
Go to the documentation of this file.
1 /* This file has been prepared for Doxygen automatic documentation generation.*/
68 #include "avr_compiler.h"
69 #include "TC_driver.h"
70 
79 void TC0_ConfigClockSource( volatile TC0_t * tc, TC_CLKSEL_t clockSelection )
80 {
81  tc->CTRLA = ( tc->CTRLA & ~TC0_CLKSEL_gm ) | clockSelection;
82 }
83 
92 void TC1_ConfigClockSource( volatile TC1_t * tc, TC_CLKSEL_t clockSelection )
93 {
94  tc->CTRLA = ( tc->CTRLA & ~TC1_CLKSEL_gm ) | clockSelection;
95 }
96 
97 
106 void TC0_ConfigWGM( volatile TC0_t * tc, TC_WGMODE_t wgm )
107 {
108  tc->CTRLB = ( tc->CTRLB & ~TC0_WGMODE_gm ) | wgm;
109 }
110 
111 
120 void TC1_ConfigWGM( volatile TC1_t * tc, TC_WGMODE_t wgm )
121 {
122  tc->CTRLB = ( tc->CTRLB & ~TC1_WGMODE_gm ) | wgm;
123 }
124 
125 
137 void TC0_ConfigInputCapture( volatile TC0_t * tc, TC_EVSEL_t eventSource )
138 {
139  tc->CTRLD = ( tc->CTRLD & ~( TC0_EVSEL_gm | TC0_EVACT_gm ) ) |
140  eventSource |
141  TC_EVACT_CAPT_gc;
142 }
143 
144 
156 void TC1_ConfigInputCapture( volatile TC1_t * tc, TC_EVSEL_t eventSource )
157 {
158  tc->CTRLD = ( tc->CTRLD & ~( TC1_EVSEL_gm | TC1_EVACT_gm ) ) |
159  eventSource |
160  TC_EVACT_CAPT_gc;
161 }
162 
163 
182 void TC0_EnableCCChannels( volatile TC0_t * tc, uint8_t enableMask )
183 {
184  /* Make sure only CCxEN bits are set in enableMask. */
185  enableMask &= ( TC0_CCAEN_bm | TC0_CCBEN_bm | TC0_CCCEN_bm | TC0_CCDEN_bm );
186 
187  /* Enable channels. */
188  tc->CTRLB |= enableMask;
189 }
190 
207 void TC1_EnableCCChannels( volatile TC1_t * tc, uint8_t enableMask )
208 {
209  /* Make sure only CCxEN bits are set in enableMask. */
210  enableMask &= ( TC1_CCAEN_bm | TC1_CCBEN_bm );
211 
212  /* Enable channels. */
213  tc->CTRLB |= enableMask;
214 }
215 
216 
232 void TC0_DisableCCChannels( volatile TC0_t * tc, uint8_t disableMask )
233 {
234  /* Make sure only CCxEN bits are set in disableMask. */
235  disableMask &= ( TC0_CCAEN_bm | TC0_CCBEN_bm | TC0_CCCEN_bm | TC0_CCDEN_bm );
236 
237  /* Disable channels. */
238  tc->CTRLB &= ~disableMask;
239 }
240 
241 
255 void TC1_DisableCCChannels( volatile TC1_t * tc, uint8_t disableMask )
256 {
257  /* Make sure only CCxEN bits are set in disableMask. */
258  disableMask &= ( TC1_CCAEN_bm | TC1_CCBEN_bm );
259 
260  /* Disable channels. */
261  tc->CTRLB &= ~disableMask;
262 }
263 
271 void TC0_SetOverflowIntLevel( volatile TC0_t * tc, TC_OVFINTLVL_t intLevel )
272 {
273  tc->INTCTRLA = ( tc->INTCTRLA & ~TC0_OVFINTLVL_gm ) | intLevel;
274 }
275 
276 
284 void TC1_SetOverflowIntLevel( volatile TC1_t * tc, TC_OVFINTLVL_t intLevel )
285 {
286  tc->INTCTRLA = ( tc->INTCTRLA & ~TC1_OVFINTLVL_gm ) | intLevel;
287 }
288 
289 
297 void TC0_SetErrorIntLevel( volatile TC0_t * tc, TC_ERRINTLVL_t intLevel )
298 {
299  tc->INTCTRLA = ( tc->INTCTRLA & ~TC0_ERRINTLVL_gm ) | intLevel;
300 }
301 
302 
310 void TC1_SetErrorIntLevel( volatile TC1_t * tc, TC_ERRINTLVL_t intLevel )
311 {
312  tc->INTCTRLA = ( tc->INTCTRLA & ~TC1_ERRINTLVL_gm ) | intLevel;
313 }
314 
315 
324 void TC0_SetCCAIntLevel( volatile TC0_t * tc, TC_CCAINTLVL_t intLevel )
325 {
326  tc->INTCTRLB = ( tc->INTCTRLB & ~TC0_CCAINTLVL_gm ) | intLevel;
327 }
328 
329 
338 void TC1_SetCCAIntLevel( volatile TC1_t * tc, TC_CCAINTLVL_t intLevel )
339 {
340  tc->INTCTRLB = ( tc->INTCTRLB & ~TC1_CCAINTLVL_gm ) | intLevel;
341 }
342 
343 
352 void TC0_SetCCBIntLevel( volatile TC0_t * tc, TC_CCBINTLVL_t intLevel )
353 {
354  tc->INTCTRLB = ( tc->INTCTRLB & ~TC0_CCBINTLVL_gm ) | intLevel;
355 }
356 
357 
366 void TC1_SetCCBIntLevel( volatile TC1_t * tc, TC_CCBINTLVL_t intLevel )
367 {
368  tc->INTCTRLB = ( tc->INTCTRLB & ~TC1_CCBINTLVL_gm ) | intLevel;
369 }
370 
371 
380 void TC0_SetCCCIntLevel( volatile TC0_t * tc, TC_CCCINTLVL_t intLevel )
381 {
382  tc->INTCTRLB = ( tc->INTCTRLB & ~TC0_CCCINTLVL_gm ) | intLevel;
383 }
384 
385 
394 void TC0_SetCCDIntLevel( volatile TC0_t * tc, TC_CCDINTLVL_t intLevel )
395 {
396  tc->INTCTRLB = ( tc->INTCTRLB & ~TC0_CCDINTLVL_gm ) | intLevel;
397 }
398 
399 
408 void TC0_Reset( volatile TC0_t * tc )
409 {
410  /* TC must be turned off before a Reset command. */
411  tc->CTRLA = ( tc->CTRLA & ~TC0_CLKSEL_gm ) | TC_CLKSEL_OFF_gc;
412 
413  /* Issue Reset command. */
414  tc->CTRLFSET = TC_CMD_RESET_gc;
415 }
416 
417 
426 void TC1_Reset( volatile TC1_t * tc )
427 {
428  /* TC must be turned off before a Reset command. */
429  tc->CTRLA = ( tc->CTRLA & ~TC1_CLKSEL_gm ) | TC_CLKSEL_OFF_gc;
430 
431  /* Issue Reset command. */
432  tc->CTRLFSET = TC_CMD_RESET_gc;
433 }
void TC1_ConfigInputCapture(volatile TC1_t *tc, TC_EVSEL_t eventSource)
Configures the Timer/Counter 1 for input capture operation.
Definition: TC_driver.c:156
void TC0_SetCCBIntLevel(volatile TC0_t *tc, TC_CCBINTLVL_t intLevel)
Sets the interrupt level for compare/capture channel B interrupt.
Definition: TC_driver.c:352
void TC0_EnableCCChannels(volatile TC0_t *tc, uint8_t enableMask)
Enables compare/capture channels for Timer/Counter 0.
Definition: TC_driver.c:182
void TC1_ConfigWGM(volatile TC1_t *tc, TC_WGMODE_t wgm)
Configures the Waveform Generation Mode for the Timer/Counter 1.
Definition: TC_driver.c:120
void TC0_ConfigInputCapture(volatile TC0_t *tc, TC_EVSEL_t eventSource)
Configures the Timer/Counter 0 for input capture operation.
Definition: TC_driver.c:137
This file implements some macros that makes the IAR C-compiler and avr-gcc work with the same code ba...
void TC0_SetCCCIntLevel(volatile TC0_t *tc, TC_CCCINTLVL_t intLevel)
Sets the interrupt level for compare/capture channel C interrupt.
Definition: TC_driver.c:380
void TC1_DisableCCChannels(volatile TC1_t *tc, uint8_t disableMask)
Disables compare/capture channels on Timer/Counter 1.
Definition: TC_driver.c:255
void TC0_Reset(volatile TC0_t *tc)
Resets the Timer/Counter 0.
Definition: TC_driver.c:408
void TC1_Reset(volatile TC1_t *tc)
Resets the Timer/Counter 1.
Definition: TC_driver.c:426
void TC0_SetCCDIntLevel(volatile TC0_t *tc, TC_CCDINTLVL_t intLevel)
Sets the interrupt level for compare/capture channel D interrupt.
Definition: TC_driver.c:394
XMEGA Timer/Counter driver header file.
void TC0_SetCCAIntLevel(volatile TC0_t *tc, TC_CCAINTLVL_t intLevel)
Sets the interrupt level for compare/capture channel A interrupt.
Definition: TC_driver.c:324
void TC1_SetCCAIntLevel(volatile TC1_t *tc, TC_CCAINTLVL_t intLevel)
Sets the interrupt level for compare/capture channel A interrupt.
Definition: TC_driver.c:338
void TC0_ConfigWGM(volatile TC0_t *tc, TC_WGMODE_t wgm)
Configures the Waveform Generation Mode for the Timer/Counter 0.
Definition: TC_driver.c:106
void TC0_SetErrorIntLevel(volatile TC0_t *tc, TC_ERRINTLVL_t intLevel)
Sets the Error interrupt level.
Definition: TC_driver.c:297
void TC1_ConfigClockSource(volatile TC1_t *tc, TC_CLKSEL_t clockSelection)
Configures clock source for the Timer/Counter 1.
Definition: TC_driver.c:92
void TC1_SetCCBIntLevel(volatile TC1_t *tc, TC_CCBINTLVL_t intLevel)
Sets the interrupt level for compare/capture channel B interrupt.
Definition: TC_driver.c:366
void TC0_DisableCCChannels(volatile TC0_t *tc, uint8_t disableMask)
Disables compare/capture channels on Timer/Counter 0.
Definition: TC_driver.c:232
void TC1_SetOverflowIntLevel(volatile TC1_t *tc, TC_OVFINTLVL_t intLevel)
Sets the overflow interrupt level.
Definition: TC_driver.c:284
void TC0_SetOverflowIntLevel(volatile TC0_t *tc, TC_OVFINTLVL_t intLevel)
Sets the overflow interrupt level.
Definition: TC_driver.c:271
void TC1_EnableCCChannels(volatile TC1_t *tc, uint8_t enableMask)
Enables compare/capture channels for Timer/Counter 1.
Definition: TC_driver.c:207
void TC1_SetErrorIntLevel(volatile TC1_t *tc, TC_ERRINTLVL_t intLevel)
Sets the Error interrupt level.
Definition: TC_driver.c:310
void TC0_ConfigClockSource(volatile TC0_t *tc, TC_CLKSEL_t clockSelection)
Configures clock source for the Timer/Counter 0.
Definition: TC_driver.c:79