fremoclock  1_3A01
FREMO Clock - Software for UTG
UserInterfaceCommonData.c
Go to the documentation of this file.
1 
25 /*
26  Copyright (C) 2007 Bernd Wisotzki
27 
28  This library is free software; you can redistribute it and/or
29  modify it under the terms of the GNU Lesser General Public
30  License as published by the Free Software Foundation; either
31  version 2.1 of the License, or (at your option) any later version.
32 
33  This library is distributed in the hope that it will be useful,
34  but WITHOUT ANY WARRANTY; without even the implied warranty of
35  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36  Lesser General Public License for more details.
37 
38  You should have received a copy of the GNU Lesser General Public
39  License along with this library; if not, write to the Free Software
40  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 */
42 
43 /* -- System wide includes -------------------------------------------------- */
44 #include <stdint.h> // typedef uint8_t, typedef uint16_t
45 #include <avr/io.h> // _BV
46 
47 /* -- Special Includes e.g. Onboard or direct attached Equipment ------------ */
48 //TODO: cleanup of imports, add comments what is imported
49 #include "ClockKernel.h" // clock kernel
50 #include "uart.h" // logging
51 #include "UserSettings.h"
53 
54 /* -- global Variables ------------------------------------------------------ */
55 
56 /* -- ram ------------------------------------------------------------------- */
57 static uint8_t ucSystemStatus;
58 static uint8_t ucEepromStatus;
59 
60 /* -- Standard functions ---------------------------------------------------- */
61 
68 {
69  LOG_P("\n\rUserInterfaceCommonDataInit\n\r");
70 
71  // get data from eeprom
73  //1. Check against erased eeprom and set to meaningfull values
74  // Remark 070407: Are there other possible EEPROM errors??
75  if (ucEepromStatus >=250) // eeprom empty :-(
76  {
77  LOG_P("\n\rEEPROM Geloescht.:-((\n\r");
78 
79  // set meaningfull values
80  ucEepromStatus = 0;
82  ClockSetTimeFactor(100); // 1:10
83  ClockSetStartTimeMinute(45); // Start: 05:45
85  ClockSetEndTimeMinute(15); // End: 18:15
87  ClockSetPulse(10);
88  ClockSetTime((fclock_t) {12, 0}); // Current: 12:00
89 
90  // write to eeprom
93  fclock_t clock = ClockGetTime();
97  clock.minute, clock.hour);
98 
99  ucSystemStatus |= _BV(SYSTEM_STATUS_EEPROM_ERASED); //set System status
100  }
101  //2. normal mode
102  else // eeprom ok?? We have to rely on this.
103  {
104  LOG_P("\n\rEEPROM OK!!:-))\n\r");
105 
106  // read from eeprom. eucEEPROMStatus above.
115  ClockSetTime(clock);
116 
117  // What to check ucSystemStatus against??
118  // 1. Dirtybit
119  // 2.
120  // Write back of dirty status.
121 
122  //if (ucSystemStatus && _BV(SYSTEM_STATUS_DIRTY == 1)) // original code which looks wrong
123  if ((ucSystemStatus & _BV(SYSTEM_STATUS_DIRTY)) != 0)
124  {
125  ucSystemStatus |= _BV(SYSTEM_STATUS_GOT_DIRTY); // Got dirty from eeprom!!
126  }
127  else
128  {
129  ucSystemStatus |= _BV(SYSTEM_STATUS_DIRTY); // now we are dirty.
131  }
132  }
133  // Set (clock) values from these data
134  LOG_P("%u, %u\n\r", ucSystemStatus, ClockReadTimeFactor());
135 
136  return ucSystemStatus;
137 }
138 
143 {
144  LOG_P("\n\rUserInterfaceCommonDataShutDown\n\r");
145 
146  ucSystemStatus &= _BV(SYSTEM_STATUS_ENDTIME); //clear for shutdown, system ok.
147 
148  // write to eeprom
151  fclock_t clock = ClockGetTime();
155  clock.minute, clock.hour);
156 }
Minimal uart library with output only for debugging.
A struct with hour and minute.
Definition: ClockKernel.h:69
void ClockSetTime(fclock_t newValue)
Set actual time.
Definition: ClockKernel.c:301
uint8_t UserSettingsGetFactor(void)
Read factor from EEPROM.
Definition: UserSettings.c:163
void UserInterfaceCommonDataShutDown(void)
Write common data to EEPROM.
uint8_t ClockReadTimeFactor(void)
Get time factor.
Definition: ClockKernel.c:350
uint8_t ClockReadEndTimeMinute(void)
Get the minute of the end time.
Definition: ClockKernel.c:422
Subroutines for UserInterfaceCommonData.
void ClockSetStartTimeMinute(uint8_t ucMinute)
Set the minute of the start time.
Definition: ClockKernel.c:362
uint8_t UserSettingsGetStartMinute(void)
Read minute of startTime from EEPROM.
Definition: UserSettings.c:127
#define SYSTEM_STATUS_ENDTIME
end time active? default 0
static uint8_t ucEepromStatus
EEPROM Status.
#define SYSTEM_STATUS_GOT_DIRTY
got dirty bit fromm eeprom -> no shutdown happend
void ClockSetStartTimeHour(uint8_t ucHour)
Set the hour of the start time.
Definition: ClockKernel.c:386
uint8_t minute
minute value 0..59
Definition: ClockKernel.h:71
void ClockSetEndTimeHour(uint8_t ucHour)
Set the hour of the end time.
Definition: ClockKernel.c:434
#define LOG_P(FMT,...)
Printf like macro to log to uart.
Definition: uart.h:32
void ClockSetEndTimeMinute(uint8_t ucMinute)
Set the minute of the end time.
Definition: ClockKernel.c:410
void UserSettingsSetSystemStatus(uint8_t status)
Write system status to EEPROM.
Definition: UserSettings.c:98
Subroutines for UserSettings.
uint8_t UserSettingsGetEepromStatus(void)
Read eeprom status from EEPROM.
Definition: UserSettings.c:86
uint8_t UserSettingsGetCurrentMinute(void)
Read minute of current clock time from EEPROM.
Definition: UserSettings.c:151
uint16_t UserSettingsGetPulse(void)
Read pulse width from EEPROM.
Definition: UserSettings.c:170
#define SYSTEM_STATUS_EEPROM_ERASED
eeprom erased; set default parameter.
uint8_t ClockReadEndTimeHour(void)
Get the hour of the end time.
Definition: ClockKernel.c:446
void UserSettingsSaveClockValues(uint8_t factor, uint16_t pulse, uint8_t startMinute, uint8_t startHour, uint8_t endMinute, uint8_t endHour, uint8_t minute, uint8_t hour)
Write factor, pulse width, startTime, endTime and current clock to EEPROM.
Definition: UserSettings.c:111
uint8_t hour
hour value 0..23
Definition: ClockKernel.h:70
void ClockSetTimeFactor(uint8_t ucFactor)
Set time factor.
Definition: ClockKernel.c:331
uint16_t ClockReadPulse(void)
Get length of pulse length in 100ms.
Definition: ClockKernel.c:286
uint8_t UserSettingsGetStartHour(void)
Read hour of startTime from EEPROM.
Definition: UserSettings.c:133
#define SYSTEM_STATUS_DIRTY
dirty bit, set by init, cleared by shutdown
uint8_t ClockReadStartTimeHour(void)
Get the hour of the start time.
Definition: ClockKernel.c:398
void ClockSetPulse(uint16_t uiPulse)
Set length of pulse length in 100ms.
Definition: ClockKernel.c:270
uint8_t ClockReadStartTimeMinute(void)
Get the minute of the start time.
Definition: ClockKernel.c:374
uint8_t UserSettingsGetEndHour(void)
Read hour of endTime from EEPROM.
Definition: UserSettings.c:145
static uint8_t ucSystemStatus
System Status.
User function called by timer ISR.
uint8_t UserSettingsGetSystemStatus(void)
Read system status from EEPROM.
Definition: UserSettings.c:92
void UserSettingsSetEepromStatus(uint8_t status)
Write eeprom status to EEPROM.
Definition: UserSettings.c:104
uint8_t UserInterfaceCommonDataInit(void)
Read data from EEPROM and initialize common data.
fclock_t ClockGetTime(void)
Get actual time.
Definition: ClockKernel.c:317
uint8_t UserSettingsGetEndMinute(void)
Read minute of endTime from EEPROM.
Definition: UserSettings.c:139
uint8_t UserSettingsGetCurrentHour(void)
Read hour of current clock time from EEPROM.
Definition: UserSettings.c:157