Subversion Repositories HomeAutomation

Rev

Rev 372 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  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() {
  27.     #if defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__)
  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);
  32.     CLKPR=0; // 8 MHZ
  33.     #endif
  34. }
  35.  
  36. /**
  37.  * Enable interrupts.
  38.  */
  39. void Mcu_EnableIRQ() {
  40.     #if MCU == atmega8
  41.         sei();
  42.     #endif
  43. }
  44.  
  45. /**
  46.  * Disable interrupts.
  47.  */
  48. void Mcu_DisableIRQ() {
  49.     #if MCU == atmega8
  50.         cli();
  51.     #endif
  52. }
  53.