aboutsummaryrefslogtreecommitdiffstats
path: root/Projects
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2013-07-20 10:35:28 +0200
committerDean Camera <dean@fourwalledcubicle.com>2013-07-20 10:35:28 +0200
commitb4af3f1fc9513d9f89df71c334862d5101807334 (patch)
tree3219bdec774d11c8fcdf33092fcd15a0e119ce84 /Projects
parentfc61e88a8d7fa209da63342be50faa507c393571 (diff)
downloadlufa-b4af3f1fc9513d9f89df71c334862d5101807334.tar.gz
lufa-b4af3f1fc9513d9f89df71c334862d5101807334.tar.bz2
lufa-b4af3f1fc9513d9f89df71c334862d5101807334.zip
Add volatile software RTC to the TempDataLogger application if the dummy RTC mode is enabled.
Diffstat (limited to 'Projects')
-rw-r--r--Projects/TempDataLogger/Config/AppConfig.h8
-rw-r--r--Projects/TempDataLogger/Lib/DS1307.c107
-rw-r--r--Projects/TempDataLogger/Lib/DS1307.h12
-rw-r--r--Projects/TempDataLogger/Lib/FATFs/diskio.c2
-rw-r--r--Projects/TempDataLogger/TempDataLogger.c13
-rw-r--r--Projects/TempDataLogger/TemperatureDataLogger.txt4
6 files changed, 115 insertions, 31 deletions
diff --git a/Projects/TempDataLogger/Config/AppConfig.h b/Projects/TempDataLogger/Config/AppConfig.h
index d457081ae..6806613df 100644
--- a/Projects/TempDataLogger/Config/AppConfig.h
+++ b/Projects/TempDataLogger/Config/AppConfig.h
@@ -33,16 +33,16 @@
*
* This is a header file which is be used to configure some of
* the application's compile time options, as an alternative to
- * specifying the compile time constants supplied through a
+ * specifying the compile time constants supplied through a
* makefile or build system.
*
- * For information on what each token does, refer to the
+ * For information on what each token does, refer to the
* \ref Sec_Options section of the application documentation.
*/
#ifndef _APP_CONFIG_H_
#define _APP_CONFIG_H_
-// #define DUMMY_RTC
+ #define DUMMY_RTC
-#endif \ No newline at end of file
+#endif
diff --git a/Projects/TempDataLogger/Lib/DS1307.c b/Projects/TempDataLogger/Lib/DS1307.c
index 0a702a333..d3ee95a77 100644
--- a/Projects/TempDataLogger/Lib/DS1307.c
+++ b/Projects/TempDataLogger/Lib/DS1307.c
@@ -7,9 +7,98 @@
#include "DS1307.h"
-bool DS1307_SetTimeDate(const TimeDate_t* NewTimeDate)
+#if defined(DUMMY_RTC)
+
+/** Current dummy RTC time and date */
+static volatile TimeDate_t DummyRTC_Count;
+
+void RTC_Init(void)
+{
+ DummyRTC_Count.Hour = 0;
+ DummyRTC_Count.Minute = 0;
+ DummyRTC_Count.Second = 0;
+ DummyRTC_Count.Day = 1;
+ DummyRTC_Count.Month = 1;
+ DummyRTC_Count.Year = 00;
+}
+
+void RTC_Tick500ms(void)
+{
+ static bool HalfSecondElapsed = false;
+
+ HalfSecondElapsed = !HalfSecondElapsed;
+ if (HalfSecondElapsed == false)
+ return;
+
+ if (++DummyRTC_Count.Second < 60)
+ return;
+
+ DummyRTC_Count.Second = 0;
+
+ if (++DummyRTC_Count.Minute < 60)
+ return;
+
+ DummyRTC_Count.Minute = 0;
+
+ if (++DummyRTC_Count.Hour < 24)
+ return;
+
+ DummyRTC_Count.Hour = 0;
+
+ static const char MonthLength[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+ uint8_t DaysInMonth = MonthLength[DummyRTC_Count.Month - 1];
+
+ /* Check if we need to account for a leap year */
+ if ((DummyRTC_Count.Month == 2) &&
+ ((!(DummyRTC_Count.Year % 400)) || ((DummyRTC_Count.Year % 100) && !(DummyRTC_Count.Year % 4))))
+ {
+ DaysInMonth++;
+ }
+
+ if (++DummyRTC_Count.Day <= DaysInMonth)
+ return;
+
+ DummyRTC_Count.Day = 1;
+
+ if (++DummyRTC_Count.Month <= 12)
+ return;
+
+ DummyRTC_Count.Month = 1;
+ DummyRTC_Count.Year++;
+}
+
+bool RTC_SetTimeDate(const TimeDate_t* NewTimeDate)
+{
+ GlobalInterruptDisable();
+ DummyRTC_Count = *NewTimeDate;
+ GlobalInterruptEnable();
+
+ return true;
+}
+
+bool RTC_GetTimeDate(TimeDate_t* const TimeDate)
+{
+ GlobalInterruptDisable();
+ *TimeDate = DummyRTC_Count;
+ GlobalInterruptEnable();
+
+ return true;
+}
+
+#else
+
+void RTC_Init(void)
+{
+ /* Unused for a real external DS1307 RTC device */
+}
+
+void RTC_Tick500ms(void)
+{
+ /* Unused for a real external DS1307 RTC device */
+}
+
+bool RTC_SetTimeDate(const TimeDate_t* NewTimeDate)
{
-#if !defined(DUMMY_RTC)
DS1307_DateTimeRegs_t NewRegValues;
const uint8_t WriteAddress = 0;
@@ -38,22 +127,12 @@ bool DS1307_SetTimeDate(const TimeDate_t* NewTimeDate)
{
return false;
}
-#endif
return true;
}
-bool DS1307_GetTimeDate(TimeDate_t* const TimeDate)
+bool RTC_GetTimeDate(TimeDate_t* const TimeDate)
{
-#if defined(DUMMY_RTC)
- TimeDate->Hour = 1;
- TimeDate->Minute = 1;
- TimeDate->Second = 1;
-
- TimeDate->Day = 1;
- TimeDate->Month = 1;
- TimeDate->Year = 1;
-#else
DS1307_DateTimeRegs_t CurrentRegValues;
const uint8_t ReadAddress = 0;
@@ -73,8 +152,8 @@ bool DS1307_GetTimeDate(TimeDate_t* const TimeDate)
TimeDate->Day = (CurrentRegValues.Byte5.Fields.TenDay * 10) + CurrentRegValues.Byte5.Fields.Day;
TimeDate->Month = (CurrentRegValues.Byte6.Fields.TenMonth * 10) + CurrentRegValues.Byte6.Fields.Month;
TimeDate->Year = (CurrentRegValues.Byte7.Fields.TenYear * 10) + CurrentRegValues.Byte7.Fields.Year;
-#endif
return true;
}
+#endif
diff --git a/Projects/TempDataLogger/Lib/DS1307.h b/Projects/TempDataLogger/Lib/DS1307.h
index dee4cb84d..2e20dbf33 100644
--- a/Projects/TempDataLogger/Lib/DS1307.h
+++ b/Projects/TempDataLogger/Lib/DS1307.h
@@ -5,14 +5,14 @@
www.lufa-lib.org
*/
-#ifndef _DS1307_H_
-#define _DS1307_H_
+#ifndef _RTC_H_
+#define _RTC_H_
/* Includes: */
#include <avr/io.h>
#include <LUFA/Drivers/Peripheral/TWI.h>
-
+
#include "Config/AppConfig.h"
/* Type Defines: */
@@ -117,8 +117,10 @@
#define DS1307_ADDRESS 0xD0
/* Function Prototypes: */
- bool DS1307_SetTimeDate(const TimeDate_t* NewTimeDate);
- bool DS1307_GetTimeDate(TimeDate_t* const TimeDate);
+ void RTC_Init(void);
+ void RTC_Tick500ms(void);
+ bool RTC_SetTimeDate(const TimeDate_t* NewTimeDate);
+ bool RTC_GetTimeDate(TimeDate_t* const TimeDate);
#endif
diff --git a/Projects/TempDataLogger/Lib/FATFs/diskio.c b/Projects/TempDataLogger/Lib/FATFs/diskio.c
index 085d5aec6..8cc8cd404 100644
--- a/Projects/TempDataLogger/Lib/FATFs/diskio.c
+++ b/Projects/TempDataLogger/Lib/FATFs/diskio.c
@@ -85,7 +85,7 @@ DWORD get_fattime (void)
{
TimeDate_t CurrTimeDate;
- DS1307_GetTimeDate(&CurrTimeDate);
+ RTC_GetTimeDate(&CurrTimeDate);
return ((DWORD)(20 + CurrTimeDate.Year) << 25) |
diff --git a/Projects/TempDataLogger/TempDataLogger.c b/Projects/TempDataLogger/TempDataLogger.c
index 0c59bc843..15c3e6a44 100644
--- a/Projects/TempDataLogger/TempDataLogger.c
+++ b/Projects/TempDataLogger/TempDataLogger.c
@@ -103,7 +103,8 @@ static FIL TempLogFile;
/** ISR to handle the 500ms ticks for sampling and data logging */
ISR(TIMER1_COMPA_vect, ISR_BLOCK)
{
- uint8_t LEDMask = LEDs_GetLEDs();
+ /* Signal a 500ms tick has elapsed to the RTC */
+ RTC_Tick500ms();
/* Check to see if the logging interval has expired */
if (++CurrentLoggingTicks < LoggingInterval500MS_SRAM)
@@ -112,13 +113,14 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK)
/* Reset log tick counter to prepare for next logging interval */
CurrentLoggingTicks = 0;
+ uint8_t LEDMask = LEDs_GetLEDs();
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
/* Only log when not connected to a USB host */
if (USB_DeviceState == DEVICE_STATE_Unattached)
{
TimeDate_t CurrentTimeDate;
- DS1307_GetTimeDate(&CurrentTimeDate);
+ RTC_GetTimeDate(&CurrentTimeDate);
char LineBuffer[100];
uint16_t BytesWritten;
@@ -170,7 +172,7 @@ void OpenLogFile(void)
/* Get the current date for the filename as "DDMMYY.csv" */
TimeDate_t CurrentTimeDate;
- DS1307_GetTimeDate(&CurrentTimeDate);
+ RTC_GetTimeDate(&CurrentTimeDate);
sprintf(LogFileName, "%02d%02d%02d.csv", CurrentTimeDate.Day, CurrentTimeDate.Month, CurrentTimeDate.Year);
/* Mount the storage device, open the file */
@@ -206,6 +208,7 @@ void SetupHardware(void)
Dataflash_Init();
USB_Init();
TWI_Init(TWI_BIT_PRESCALE_4, TWI_BITLENGTH_FROM_FREQ(4, 50000));
+ RTC_Init();
/* 500ms logging interval timer configuration */
OCR1A = (((F_CPU / 1024) / 2) - 1);
@@ -292,7 +295,7 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
{
Device_Report_t* ReportParams = (Device_Report_t*)ReportData;
- DS1307_GetTimeDate(&ReportParams->TimeDate);
+ RTC_GetTimeDate(&ReportParams->TimeDate);
ReportParams->LogInterval500MS = LoggingInterval500MS_SRAM;
@@ -316,7 +319,7 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI
{
Device_Report_t* ReportParams = (Device_Report_t*)ReportData;
- DS1307_SetTimeDate(&ReportParams->TimeDate);
+ RTC_SetTimeDate(&ReportParams->TimeDate);
/* If the logging interval has changed from its current value, write it to EEPROM */
if (LoggingInterval500MS_SRAM != ReportParams->LogInterval500MS)
diff --git a/Projects/TempDataLogger/TemperatureDataLogger.txt b/Projects/TempDataLogger/TemperatureDataLogger.txt
index 3daaa2a70..4d4e0b5e8 100644
--- a/Projects/TempDataLogger/TemperatureDataLogger.txt
+++ b/Projects/TempDataLogger/TemperatureDataLogger.txt
@@ -78,8 +78,8 @@
* <tr>
* <td>DUMMY_RTC</td>
* <td>AppConfig.h</td>
- * <td>When a DS1307 RTC chip is not fitted, this token can be defined to make the demo assume a 1/1/1 01:01:01 date/time
- * stamp at all times, effectively transforming the project into a basic data logger with no specified sample times.</td>
+ * <td>When a DS1307 RTC chip is not fitted, this token can be defined to make the demo use a dummy software RTC using the system
+ * clock. This is less accurate and does not store the set time and date into non-volatile memory.</td>
* </tr>
* </table>
*/