Defines | Functions

# Clock management drivers

## Defines
#define | Enable_external_clock() (CLKSEL0 |= (1<<EXTE))
#define | Disable_external_clock() (CLKSEL0 &= ~(1<<EXTE))
#define | Enable_RC_clock() (CLKSEL0 |= (1<<RCE))
#define | Disable_RC_clock() (CLKSEL0 &= ~(1<<RCE))
#define | External_clock_ready() (((CLKSTA&(1<<EXTON)) != 0) ? TRUE : FALSE)
#define | RC_clock_ready() (((CLKSTA&(1<<RCON)) != 0) ? TRUE : FALSE)
#define | Select_external_clock() (CLKSEL0 |= (1<<CLKS))
#define | Select_RC_clock() (CLKSEL0 &= ~(1<<CLKS))
#define | Load_ext_clock_config(cfg)
#define | Load_RC_clock_config(cfg)
#define | OSC_INTRC_0MS 0x02
#define | OSC_INTRC_4MS 0x12
#define | OSC_INTRC_65MS 0x22
#define | OSC_XTAL_RANGE1_258CK_4MS 0x08
#define | OSC_XTAL_RANGE1_258CK_65MS 0x18
#define | OSC_XTAL_RANGE1_1KCK_0MS 0x28
#define | OSC_XTAL_RANGE1_1KCK_4MS 0x38
#define | OSC_XTAL_RANGE1_1KCK_65MS 0x09
#define | OSC_XTAL_RANGE1_16KCK_0MS 0x19
#define | OSC_XTAL_RANGE1_16KCK_4MS 0x29
#define | OSC_XTAL_RANGE1_16KCK_65MS 0x39
#define | OSC_XTAL_RANGE2_258CK_4MS 0x0A
#define | OSC_XTAL_RANGE2_258CK_65MS 0x1A
#define | OSC_XTAL_RANGE2_1KCK_0MS 0x2A
#define | OSC_XTAL_RANGE2_1KCK_4MS 0x3A
#define | OSC_XTAL_RANGE2_1KCK_65MS 0x0B
#define | OSC_XTAL_RANGE2_16KCK_0MS 0x1B
#define | OSC_XTAL_RANGE2_16KCK_4MS 0x2B
#define | OSC_XTAL_RANGE2_16KCK_65MS 0x3B
#define | OSC_XTAL_RANGE3_258CK_4MS 0x0C
#define | OSC_XTAL_RANGE3_258CK_65MS 0x1C
#define | OSC_XTAL_RANGE3_1KCK_0MS 0x2C
#define | OSC_XTAL_RANGE3_1KCK_4MS 0x3C
#define | OSC_XTAL_RANGE3_1KCK_65MS 0x0D
#define | OSC_XTAL_RANGE3_16KCK_0MS 0x1D
#define | OSC_XTAL_RANGE3_16KCK_4MS 0x2D
#define | OSC_XTAL_RANGE3_16KCK_65MS 0x3D
#define | OSC_XTAL_RANGE4_258CK_4MS 0x0E
#define | OSC_XTAL_RANGE4_258CK_65MS 0x1E
#define | OSC_XTAL_RANGE4_1KCK_0MS 0x2E
#define | OSC_XTAL_RANGE4_1KCK_4MS 0x3E
#define | OSC_XTAL_RANGE4_1KCK_65MS 0x0F
#define | OSC_XTAL_RANGE4_16KCK_0MS 0x1F
#define | OSC_XTAL_RANGE4_16KCK_4MS 0x2F
#define | OSC_XTAL_RANGE4_16KCK_65MS 0x3F
#define | OSC_EXTCLK_0MS 0x00
#define | OSC_EXTCLK_4MS 0x10
#define | OSC_EXTCLK_65MS 0x20
## Functions
void | Clock_switch_external (void)
| This function makes the AVR selects the EXTERNAL clock source (CRYSTAL)
void | Clock_switch_internal (void)
| This function makes the AVR selects the INTERNAL clock source (RC)

## Define Documentation

#define Enable_external_clock | ( | ) | (CLKSEL0 |= (1<<EXTE))

Definition at line 175 of file power_drv.h.

Referenced by Clock_switch_external().

#define Disable_external_clock | ( | ) | (CLKSEL0 &= ~(1<<EXTE))

Definition at line 176 of file power_drv.h.

Referenced by Clock_switch_internal().

#define Enable_RC_clock | ( | ) | (CLKSEL0 |= (1<<RCE))

Definition at line 177 of file power_drv.h.

Referenced by Clock_switch_internal().

#define Disable_RC_clock | ( | ) | (CLKSEL0 &= ~(1<<RCE))

Definition at line 178 of file power_drv.h.

Referenced by Clock_switch_external().

#define External_clock_ready | ( | ) | (((CLKSTA&(1<<EXTON)) != 0) ? TRUE : FALSE)

Definition at line 181 of file power_drv.h.

Referenced by Clock_switch_external().

#define RC_clock_ready | ( | ) | (((CLKSTA&(1<<RCON)) != 0) ? TRUE : FALSE)

Definition at line 182 of file power_drv.h.

Referenced by Clock_switch_internal().

#define Select_external_clock | ( | ) | (CLKSEL0 |= (1<<CLKS))

Definition at line 185 of file power_drv.h.

Referenced by Clock_switch_external().

#define Select_RC_clock | ( | ) | (CLKSEL0 &= ~(1<<CLKS))

Definition at line 186 of file power_drv.h.

Referenced by Clock_switch_internal().

#define Load_ext_clock_config | ( |  | cfg ) |

Value:

    (CLKSEL1 = (CLKSEL1&0xF0) | ((cfg&0x0F)<<EXCKSEL0), \
                                             CLKSEL0 = (CLKSEL0&0xCF) | (((cfg&0x30)>>4)<<EXSUT0))

Definition at line 190 of file power_drv.h.

#define Load_RC_clock_config | ( |  | cfg ) |

Value:

    (CLKSEL1 = (CLKSEL1&0x0F) | ((cfg&0x0F)<<RCCKSEL0), \
                                             CLKSEL0 = (CLKSEL0&0x3F) | (((cfg&0x30)>>4)<<RCSUT0))

Definition at line 193 of file power_drv.h.

#define OSC_INTRC_0MS 0x02

Definition at line 200 of file power_drv.h.

#define OSC_INTRC_4MS 0x12

Definition at line 201 of file power_drv.h.

#define OSC_INTRC_65MS 0x22

Definition at line 202 of file power_drv.h.

#define OSC_XTAL_RANGE1_258CK_4MS 0x08

Definition at line 205 of file power_drv.h.

#define OSC_XTAL_RANGE1_258CK_65MS 0x18

Definition at line 206 of file power_drv.h.

#define OSC_XTAL_RANGE1_1KCK_0MS 0x28

Definition at line 207 of file power_drv.h.

#define OSC_XTAL_RANGE1_1KCK_4MS 0x38

Definition at line 208 of file power_drv.h.

#define OSC_XTAL_RANGE1_1KCK_65MS 0x09

Definition at line 209 of file power_drv.h.

#define OSC_XTAL_RANGE1_16KCK_0MS 0x19

Definition at line 210 of file power_drv.h.

#define OSC_XTAL_RANGE1_16KCK_4MS 0x29

Definition at line 211 of file power_drv.h.

#define OSC_XTAL_RANGE1_16KCK_65MS 0x39

Definition at line 212 of file power_drv.h.

#define OSC_XTAL_RANGE2_258CK_4MS 0x0A

Definition at line 215 of file power_drv.h.

#define OSC_XTAL_RANGE2_258CK_65MS 0x1A

Definition at line 216 of file power_drv.h.

#define OSC_XTAL_RANGE2_1KCK_0MS 0x2A

Definition at line 217 of file power_drv.h.

#define OSC_XTAL_RANGE2_1KCK_4MS 0x3A

Definition at line 218 of file power_drv.h.

#define OSC_XTAL_RANGE2_1KCK_65MS 0x0B

Definition at line 219 of file power_drv.h.

#define OSC_XTAL_RANGE2_16KCK_0MS 0x1B

Definition at line 220 of file power_drv.h.

#define OSC_XTAL_RANGE2_16KCK_4MS 0x2B

Definition at line 221 of file power_drv.h.

#define OSC_XTAL_RANGE2_16KCK_65MS 0x3B

Definition at line 222 of file power_drv.h.

#define OSC_XTAL_RANGE3_258CK_4MS 0x0C

Definition at line 225 of file power_drv.h.

#define OSC_XTAL_RANGE3_258CK_65MS 0x1C

Definition at line 226 of file power_drv.h.

#define OSC_XTAL_RANGE3_1KCK_0MS 0x2C

Definition at line 227 of file power_drv.h.

#define OSC_XTAL_RANGE3_1KCK_4MS 0x3C

Definition at line 228 of file power_drv.h.

#define OSC_XTAL_RANGE3_1KCK_65MS 0x0D

Definition at line 229 of file power_drv.h.

#define OSC_XTAL_RANGE3_16KCK_0MS 0x1D

Definition at line 230 of file power_drv.h.

#define OSC_XTAL_RANGE3_16KCK_4MS 0x2D

Definition at line 231 of file power_drv.h.

#define OSC_XTAL_RANGE3_16KCK_65MS 0x3D

Definition at line 232 of file power_drv.h.

#define OSC_XTAL_RANGE4_258CK_4MS 0x0E

Definition at line 235 of file power_drv.h.

#define OSC_XTAL_RANGE4_258CK_65MS 0x1E

Definition at line 236 of file power_drv.h.

#define OSC_XTAL_RANGE4_1KCK_0MS 0x2E

Definition at line 237 of file power_drv.h.

#define OSC_XTAL_RANGE4_1KCK_4MS 0x3E

Definition at line 238 of file power_drv.h.

#define OSC_XTAL_RANGE4_1KCK_65MS 0x0F

Definition at line 239 of file power_drv.h.

#define OSC_XTAL_RANGE4_16KCK_0MS 0x1F

Definition at line 240 of file power_drv.h.

#define OSC_XTAL_RANGE4_16KCK_4MS 0x2F

Definition at line 241 of file power_drv.h.

#define OSC_XTAL_RANGE4_16KCK_65MS 0x3F

Definition at line 242 of file power_drv.h.

#define OSC_EXTCLK_0MS 0x00

Definition at line 245 of file power_drv.h.

#define OSC_EXTCLK_4MS 0x10

Definition at line 246 of file power_drv.h.

#define OSC_EXTCLK_65MS 0x20

Definition at line 247 of file power_drv.h.

## Function Documentation

void Clock_switch_external | ( | void | ) |

This function makes the AVR selects the EXTERNAL clock source (CRYSTAL)

Definition at line 127 of file power_drv.c.

References Disable_RC_clock, Enable_external_clock, External_clock_ready, and Select_external_clock.

    {
      Enable_external_clock();
      while (!External_clock_ready());
      Select_external_clock();
      Disable_RC_clock();
    }

void Clock_switch_internal | ( | void | ) |

This function makes the AVR selects the INTERNAL clock source (RC)

Definition at line 138 of file power_drv.c.

References Disable_external_clock, Enable_RC_clock, RC_clock_ready, and Select_RC_clock.

    {
      Enable_RC_clock();
      while (!RC_clock_ready());
      Select_RC_clock();
      Disable_external_clock();
    }