/*
Diplomova prace : Palubni pocitac

pwrctrl.h - sprava napajeni

Atmega128A 10 MHz XTAL

Autor: Ondrej Lutera

2011/2012

*/
#ifndef PWRCTRL_H_INCLUDED
#define PWRCTRL_H_INCLUDED

#include <avr/io.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include "define.h"
#include "car_meas.h"
#include "timer.h"
#include "keys.h"
#include "backlight.h"

#define PWR_PIN     PG3
#define PWR_DDR     DDRG
#define PWR_PORT    PORTG

#define PWR_DCDC_ON()     PWR_PORT&=~(1<<PWR_PIN)
#define PWR_DCDC_OFF()    PWR_PORT|=(1<<PWR_PIN)

#define SLEEP_TICK 192  // 32* tj 6s
#define SLEEP_TIME  10  // 1min

void pwrInit(void);

void SetSleep(void); // nastavi sleep flag do EEPROM pro prechod do Power-down

void SleepPoll(void);   // v main testuje zda prejit na sleep

void DisSleep(void);    // zakaze sleep flag

uint8_t CheckReboot(void);      // kontrola flagu restartu

void SetReboot(void);           // nastaveni flagu restartu

void CheckWakeUp(void);         // provadi kontrolu probuzeni ve vyvolanem preruseni od externiho eventu ktery zpusobil probuzeni

uint8_t isSleep(void);          // test zda se MCU ma nachazet ve spanku..provadi se pro probuzeni ..flag sleep umisten v EEPROM
#endif // PWRCTRL_H_INCLUDED
