Rev 1415 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 361 | andfri | 1 | /** |
| 2 | * MCU driver. |
||
| 3 | * |
||
| 4 | * @date 2006-11-19 |
||
| 5 | * |
||
| 6 | * @author Jimmy Myhrman |
||
| 7 | * |
||
| 8 | */ |
||
| 9 | |||
| 10 | /*----------------------------------------------------------------------------- |
||
| 11 | * Includes |
||
| 12 | *---------------------------------------------------------------------------*/ |
||
| 13 | #include <avr/interrupt.h> |
||
| 14 | #include <config.h> |
||
| 15 | #include <drivers/mcu/mcu.h> |
||
| 16 | |||
| 17 | |||
| 18 | /*----------------------------------------------------------------------------- |
||
| 19 | * Public Functions |
||
| 20 | *---------------------------------------------------------------------------*/ |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Initialize MCU. If the MCU is mega88, the internal clock frequency will be |
||
| 24 | * set to 8MHz. Interrupts must not be enabled when calling this function! |
||
| 25 | */ |
||
| 26 | void Mcu_Init() { |
||
| 1468 | arune | 27 | #if defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__) |
| 361 | andfri | 28 | // set the clock speed to 8MHz |
| 29 | // set the clock prescaler. First write CLKPCE to enable setting of clock the |
||
| 30 | // next four instructions. |
||
| 31 | CLKPR=(1<<CLKPCE); |
||
| 657 | arune | 32 | #ifndef AVR_CLOCK_PRESC |
| 33 | CLKPR=0; // 8 MHZ |
||
| 361 | andfri | 34 | #endif |
| 657 | arune | 35 | |
| 36 | #if AVR_CLOCK_PRESC == 1 |
||
| 37 | CLKPR=0; // 8 MHZ |
||
| 38 | #elif AVR_CLOCK_PRESC == 2 |
||
| 39 | CLKPR=1; // 4 MHZ |
||
| 40 | #elif AVR_CLOCK_PRESC == 4 |
||
| 41 | CLKPR=2; // 2 MHZ |
||
| 42 | #elif AVR_CLOCK_PRESC == 8 |
||
| 43 | CLKPR=3; // 1 MHZ |
||
| 44 | #elif AVR_CLOCK_PRESC == 16 |
||
| 45 | CLKPR=4; // 500 kHZ |
||
| 46 | #elif AVR_CLOCK_PRESC == 32 |
||
| 47 | CLKPR=5; // 250 kHZ |
||
| 48 | #elif AVR_CLOCK_PRESC == 64 |
||
| 49 | CLKPR=6; // 125 kHZ |
||
| 50 | #elif AVR_CLOCK_PRESC == 128 |
||
| 51 | CLKPR=7; // 62.5 kHZ |
||
| 52 | #elif AVR_CLOCK_PRESC == 256 |
||
| 53 | CLKPR=8; // 31.25 kHZ |
||
| 54 | #endif |
||
| 55 | #endif |
||
| 361 | andfri | 56 | } |
| 57 | |||
| 58 | /** |
||
| 59 | * Enable interrupts. |
||
| 60 | */ |
||
| 61 | void Mcu_EnableIRQ() { |
||
| 62 | #if MCU == atmega8 |
||
| 63 | sei(); |
||
| 64 | #endif |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Disable interrupts. |
||
| 69 | */ |
||
| 70 | void Mcu_DisableIRQ() { |
||
| 71 | #if MCU == atmega8 |
||
| 72 | cli(); |
||
| 73 | #endif |
||
| 74 | } |