Exported code as submodule
This commit is contained in:
parent
20e7392201
commit
8e2e18128b
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
|||||||
[submodule "ds3231/usart"]
|
|
||||||
path = ds3231/usart
|
|
||||||
url = git@blackmark.me:usart.git
|
|
22
ds3231.atsln
22
ds3231.atsln
@ -1,22 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Atmel Studio Solution File, Format Version 11.00
|
|
||||||
VisualStudioVersion = 14.0.25420.1
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{E66E83B9-2572-4076-B26E-6BE79FF3018A}") = "ds3231", "ds3231\ds3231.cppproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|AVR = Debug|AVR
|
|
||||||
Release|AVR = Release|AVR
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR
|
|
||||||
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR
|
|
||||||
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR
|
|
||||||
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) by BlackMark 2016
|
|
||||||
* Date 09/09/2016
|
|
||||||
* Version 1.4
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BOOTLOADER_H
|
|
||||||
#define BOOTLOADER_H
|
|
||||||
|
|
||||||
#include <avr/pgmspace.h>
|
|
||||||
#include <avr/interrupt.h>
|
|
||||||
#include <avr/wdt.h>
|
|
||||||
|
|
||||||
typedef void (*flash)() __attribute__ ((noreturn));
|
|
||||||
|
|
||||||
flash boot = reinterpret_cast<flash>( 0x0000 );
|
|
||||||
flash bootloader = reinterpret_cast<flash>( 0x7E00 / 2 );
|
|
||||||
|
|
||||||
inline bool checkBootloader()
|
|
||||||
{
|
|
||||||
if( pgm_read_byte( reinterpret_cast<uint16_t>( bootloader ) * 2 ) == 0xF8 )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void callBootloader()
|
|
||||||
{
|
|
||||||
if( checkBootloader() )
|
|
||||||
{
|
|
||||||
bootloader();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
boot();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline uint8_t handleReset()
|
|
||||||
{
|
|
||||||
wdt_reset();
|
|
||||||
uint8_t ui8MCUSR = MCUSR;
|
|
||||||
MCUSR &= ~( 1 << WDRF );
|
|
||||||
wdt_disable();
|
|
||||||
return ui8MCUSR;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void reset()
|
|
||||||
{
|
|
||||||
wdt_enable( WDTO_15MS );
|
|
||||||
while( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,14 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) by BlackMark 2015
|
|
||||||
* Date 24/11/2015
|
|
||||||
* Version 1.1
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CLOCK_H
|
|
||||||
#define CLOCK_H
|
|
||||||
|
|
||||||
#define F_CPU 8000000
|
|
||||||
|
|
||||||
#include <util/delay.h>
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,247 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
|
|
||||||
<PropertyGroup>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
<ProjectVersion>7.0</ProjectVersion>
|
|
||||||
<ToolchainName>com.Atmel.AVRGCC8.CPP</ToolchainName>
|
|
||||||
<ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
|
|
||||||
<avrdevice>ATmega328P</avrdevice>
|
|
||||||
<avrdeviceseries>none</avrdeviceseries>
|
|
||||||
<OutputType>Executable</OutputType>
|
|
||||||
<Language>CPP</Language>
|
|
||||||
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
|
|
||||||
<OutputFileExtension>.elf</OutputFileExtension>
|
|
||||||
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
|
||||||
<AssemblyName>ds3231</AssemblyName>
|
|
||||||
<Name>ds3231</Name>
|
|
||||||
<RootNamespace>ds3231</RootNamespace>
|
|
||||||
<ToolchainFlavour>Native</ToolchainFlavour>
|
|
||||||
<KeepTimersRunning>true</KeepTimersRunning>
|
|
||||||
<OverrideVtor>false</OverrideVtor>
|
|
||||||
<CacheFlash>true</CacheFlash>
|
|
||||||
<ProgFlashFromRam>true</ProgFlashFromRam>
|
|
||||||
<RamSnippetAddress>0x20000000</RamSnippetAddress>
|
|
||||||
<UncachedRange />
|
|
||||||
<preserveEEPROM>true</preserveEEPROM>
|
|
||||||
<OverrideVtorValue>exception_table</OverrideVtorValue>
|
|
||||||
<BootSegment>2</BootSegment>
|
|
||||||
<eraseonlaunchrule>0</eraseonlaunchrule>
|
|
||||||
<AsfFrameworkConfig>
|
|
||||||
<framework-data xmlns="">
|
|
||||||
<options />
|
|
||||||
<configurations />
|
|
||||||
<files />
|
|
||||||
<documentation help="" />
|
|
||||||
<offline-documentation help="" />
|
|
||||||
<dependencies>
|
|
||||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.34.2" />
|
|
||||||
</dependencies>
|
|
||||||
</framework-data>
|
|
||||||
</AsfFrameworkConfig>
|
|
||||||
<avrtool>com.atmel.avrdbg.tool.stk500</avrtool>
|
|
||||||
<avrtoolserialnumber />
|
|
||||||
<avrdeviceexpectedsignature>0x1E950F</avrdeviceexpectedsignature>
|
|
||||||
<custom>
|
|
||||||
<ToolOptions>
|
|
||||||
<InterfaceProperties>
|
|
||||||
</InterfaceProperties>
|
|
||||||
<InterfaceName>
|
|
||||||
</InterfaceName>
|
|
||||||
</ToolOptions>
|
|
||||||
<ToolType>custom</ToolType>
|
|
||||||
<ToolNumber>
|
|
||||||
</ToolNumber>
|
|
||||||
<ToolName>Custom Programming Tool</ToolName>
|
|
||||||
</custom>
|
|
||||||
<avrtoolinterface>ISP</avrtoolinterface>
|
|
||||||
<com_atmel_avrdbg_tool_simulator>
|
|
||||||
<ToolOptions xmlns="">
|
|
||||||
<InterfaceProperties>
|
|
||||||
</InterfaceProperties>
|
|
||||||
<InterfaceName>
|
|
||||||
</InterfaceName>
|
|
||||||
</ToolOptions>
|
|
||||||
<ToolType xmlns="">com.atmel.avrdbg.tool.simulator</ToolType>
|
|
||||||
<ToolNumber xmlns="">
|
|
||||||
</ToolNumber>
|
|
||||||
<ToolName xmlns="">Simulator</ToolName>
|
|
||||||
</com_atmel_avrdbg_tool_simulator>
|
|
||||||
<ResetRule>0</ResetRule>
|
|
||||||
<EraseKey />
|
|
||||||
<com_atmel_avrdbg_tool_stk500>
|
|
||||||
<ToolOptions>
|
|
||||||
<InterfaceProperties>
|
|
||||||
<IspClock>125000</IspClock>
|
|
||||||
</InterfaceProperties>
|
|
||||||
<InterfaceName>ISP</InterfaceName>
|
|
||||||
</ToolOptions>
|
|
||||||
<ToolType>com.atmel.avrdbg.tool.stk500</ToolType>
|
|
||||||
<ToolNumber>
|
|
||||||
</ToolNumber>
|
|
||||||
<ToolName>STK500</ToolName>
|
|
||||||
</com_atmel_avrdbg_tool_stk500>
|
|
||||||
<avrtoolinterfaceclock>125000</avrtoolinterfaceclock>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
|
||||||
<ToolchainSettings>
|
|
||||||
<AvrGccCpp>
|
|
||||||
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\gcc\dev\atmega328p"</avrgcc.common.Device>
|
|
||||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
|
||||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
|
||||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
|
||||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
|
||||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
|
||||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
|
||||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
|
||||||
<avrgcc.compiler.symbols.DefSymbols>
|
|
||||||
<ListValues>
|
|
||||||
<Value>NDEBUG</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcc.compiler.symbols.DefSymbols>
|
|
||||||
<avrgcc.compiler.directories.IncludePaths>
|
|
||||||
<ListValues>
|
|
||||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\include</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcc.compiler.directories.IncludePaths>
|
|
||||||
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
|
||||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
|
||||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
|
||||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
|
||||||
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
|
|
||||||
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
|
|
||||||
<avrgcccpp.compiler.symbols.DefSymbols>
|
|
||||||
<ListValues>
|
|
||||||
<Value>NDEBUG</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcccpp.compiler.symbols.DefSymbols>
|
|
||||||
<avrgcccpp.compiler.directories.IncludePaths>
|
|
||||||
<ListValues>
|
|
||||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\include</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcccpp.compiler.directories.IncludePaths>
|
|
||||||
<avrgcccpp.compiler.optimization.level>Optimize for size (-Os)</avrgcccpp.compiler.optimization.level>
|
|
||||||
<avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>
|
|
||||||
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
|
|
||||||
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
|
|
||||||
<avrgcccpp.compiler.warnings.Pedantic>True</avrgcccpp.compiler.warnings.Pedantic>
|
|
||||||
<avrgcccpp.compiler.miscellaneous.OtherFlags>-Wextra -std=c++14</avrgcccpp.compiler.miscellaneous.OtherFlags>
|
|
||||||
<avrgcccpp.linker.libraries.Libraries>
|
|
||||||
<ListValues>
|
|
||||||
<Value>libm</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcccpp.linker.libraries.Libraries>
|
|
||||||
<avrgcccpp.assembler.general.IncludePaths>
|
|
||||||
<ListValues>
|
|
||||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\include</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcccpp.assembler.general.IncludePaths>
|
|
||||||
</AvrGccCpp>
|
|
||||||
</ToolchainSettings>
|
|
||||||
<PreBuildEvent>echo "C:\bin\avrdude-6.3\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i > "$(MSBuildProjectDirectory)\avrdude.bat"</PreBuildEvent>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
|
||||||
<ToolchainSettings>
|
|
||||||
<AvrGccCpp>
|
|
||||||
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\gcc\dev\atmega328p"</avrgcc.common.Device>
|
|
||||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
|
||||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
|
||||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
|
||||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
|
||||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
|
||||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
|
||||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
|
||||||
<avrgcc.compiler.symbols.DefSymbols>
|
|
||||||
<ListValues>
|
|
||||||
<Value>DEBUG</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcc.compiler.symbols.DefSymbols>
|
|
||||||
<avrgcc.compiler.directories.IncludePaths>
|
|
||||||
<ListValues>
|
|
||||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\include</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcc.compiler.directories.IncludePaths>
|
|
||||||
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
|
|
||||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
|
||||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
|
||||||
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
|
|
||||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
|
||||||
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
|
|
||||||
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
|
|
||||||
<avrgcccpp.compiler.symbols.DefSymbols>
|
|
||||||
<ListValues>
|
|
||||||
<Value>DEBUG</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcccpp.compiler.symbols.DefSymbols>
|
|
||||||
<avrgcccpp.compiler.directories.IncludePaths>
|
|
||||||
<ListValues>
|
|
||||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\include</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcccpp.compiler.directories.IncludePaths>
|
|
||||||
<avrgcccpp.compiler.optimization.level>Optimize (-O1)</avrgcccpp.compiler.optimization.level>
|
|
||||||
<avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>
|
|
||||||
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
|
|
||||||
<avrgcccpp.compiler.optimization.DebugLevel>Default (-g2)</avrgcccpp.compiler.optimization.DebugLevel>
|
|
||||||
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
|
|
||||||
<avrgcccpp.compiler.warnings.Pedantic>True</avrgcccpp.compiler.warnings.Pedantic>
|
|
||||||
<avrgcccpp.compiler.miscellaneous.OtherFlags>-Wextra -std=c++14</avrgcccpp.compiler.miscellaneous.OtherFlags>
|
|
||||||
<avrgcccpp.linker.libraries.Libraries>
|
|
||||||
<ListValues>
|
|
||||||
<Value>libm</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcccpp.linker.libraries.Libraries>
|
|
||||||
<avrgcccpp.assembler.general.IncludePaths>
|
|
||||||
<ListValues>
|
|
||||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\include</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcccpp.assembler.general.IncludePaths>
|
|
||||||
<avrgcccpp.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcccpp.assembler.debugging.DebugLevel>
|
|
||||||
</AvrGccCpp>
|
|
||||||
</ToolchainSettings>
|
|
||||||
<PreBuildEvent>echo "C:\bin\avrdude-6.3\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i > "$(MSBuildProjectDirectory)\avrdude.bat"</PreBuildEvent>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="bootloader.h">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="clock.h">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="main.cpp">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="rtc.cpp">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="rtc.h">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="systime.cpp">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="systime.h">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="twi-lowlevel.cpp">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="twi-lowlevel.h">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="twi.cpp">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="twi.h">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="usart\usart.cpp">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="usart\usart.h">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="usart" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
|
||||||
</Project>
|
|
178
ds3231/main.cpp
178
ds3231/main.cpp
@ -1,178 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) by BlackMark 2017
|
|
||||||
* Date 17/12/2017
|
|
||||||
* Version 1.2
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <avr/interrupt.h>
|
|
||||||
|
|
||||||
#include "usart/usart.h"
|
|
||||||
#include "clock.h"
|
|
||||||
#include "bootloader.h"
|
|
||||||
#include "systime.h"
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
USART0 &cSerial = USART0::inst();
|
|
||||||
|
|
||||||
if( SysTime::init() )
|
|
||||||
{
|
|
||||||
cSerial << "DS3231 detected!" << "\r\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cSerial << "ERROR - No RTC detected!" << "\r\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setTime()
|
|
||||||
{
|
|
||||||
USART0 &cSerial = USART0::inst();
|
|
||||||
|
|
||||||
tm sTime;
|
|
||||||
|
|
||||||
constexpr auto BUFFER_SIZE = 32;
|
|
||||||
char szBuffer[BUFFER_SIZE];
|
|
||||||
|
|
||||||
cSerial << "Set time:" << "\r\n" << "Year: ";
|
|
||||||
cSerial.receiveLine( szBuffer, BUFFER_SIZE, "\r" );
|
|
||||||
cSerial << szBuffer << "\r\n";
|
|
||||||
sTime.tm_year = atoi( szBuffer ) - 1900;
|
|
||||||
|
|
||||||
cSerial << "Set time:" << "\r\n" << "Month: ";
|
|
||||||
cSerial.receiveLine( szBuffer, BUFFER_SIZE, "\r" );
|
|
||||||
cSerial << szBuffer << "\r\n";
|
|
||||||
sTime.tm_mon = atoi( szBuffer ) - 1;
|
|
||||||
|
|
||||||
cSerial << "Set time:" << "\r\n" << "Day: ";
|
|
||||||
cSerial.receiveLine( szBuffer, BUFFER_SIZE, "\r" );
|
|
||||||
cSerial << szBuffer << "\r\n";
|
|
||||||
sTime.tm_mday = atoi( szBuffer );
|
|
||||||
|
|
||||||
cSerial << "Set time:" << "\r\n" << "Hour: ";
|
|
||||||
cSerial.receiveLine( szBuffer, BUFFER_SIZE, "\r" );
|
|
||||||
cSerial << szBuffer << "\r\n";
|
|
||||||
sTime.tm_hour = atoi( szBuffer );
|
|
||||||
|
|
||||||
cSerial << "Minute: ";
|
|
||||||
cSerial.receiveLine( szBuffer, BUFFER_SIZE, "\r" );
|
|
||||||
cSerial << szBuffer << "\r\n";
|
|
||||||
sTime.tm_min = atoi( szBuffer );
|
|
||||||
|
|
||||||
cSerial << "Second: ";
|
|
||||||
cSerial.receiveLine( szBuffer, BUFFER_SIZE, "\r" );
|
|
||||||
cSerial << szBuffer << "\r\n";
|
|
||||||
sTime.tm_sec = atoi( szBuffer );
|
|
||||||
|
|
||||||
mktime( &sTime );
|
|
||||||
|
|
||||||
SysTime::setTime( sTime );
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAlarm()
|
|
||||||
{
|
|
||||||
USART0 &cSerial = USART0::inst();
|
|
||||||
|
|
||||||
rtc_tm* tmAlarm = rtc_get_alarm();
|
|
||||||
|
|
||||||
constexpr auto BUFFER_SIZE = 32;
|
|
||||||
char szBuffer[BUFFER_SIZE];
|
|
||||||
|
|
||||||
cSerial << "Set alarm:" << "\r\n" << "Hour: ";
|
|
||||||
cSerial.receiveLine( szBuffer, BUFFER_SIZE, "\r" );
|
|
||||||
cSerial << szBuffer << "\r\n";
|
|
||||||
tmAlarm->hour = atoi( szBuffer );
|
|
||||||
|
|
||||||
cSerial << "Minute: ";
|
|
||||||
cSerial.receiveLine( szBuffer, BUFFER_SIZE, "\r" );
|
|
||||||
cSerial << szBuffer << "\r\n";
|
|
||||||
tmAlarm->min = atoi( szBuffer );
|
|
||||||
|
|
||||||
cSerial << "Second: ";
|
|
||||||
cSerial.receiveLine( szBuffer, BUFFER_SIZE, "\r" );
|
|
||||||
cSerial << szBuffer << "\r\n";
|
|
||||||
tmAlarm->sec = atoi( szBuffer );
|
|
||||||
|
|
||||||
rtc_set_alarm( tmAlarm );
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
uint8_t ui8MCUSR = handleReset();
|
|
||||||
|
|
||||||
if( ui8MCUSR & ( 1 << WDRF ) )
|
|
||||||
{
|
|
||||||
callBootloader();
|
|
||||||
}
|
|
||||||
|
|
||||||
USART0 &cSerial = USART0::inst();
|
|
||||||
|
|
||||||
cSerial.init( 9600 );
|
|
||||||
sei();
|
|
||||||
|
|
||||||
setup();
|
|
||||||
|
|
||||||
constexpr auto BUFFER_SIZE = 32;
|
|
||||||
char szBuffer[BUFFER_SIZE];
|
|
||||||
|
|
||||||
while( true )
|
|
||||||
{
|
|
||||||
if( !SysTime::checkSync() )
|
|
||||||
{
|
|
||||||
SysTime::syncSysTime();
|
|
||||||
|
|
||||||
time_t timeNow = time( nullptr );
|
|
||||||
tm *psLocalTime = localtime( &timeNow );
|
|
||||||
|
|
||||||
strftime( szBuffer, BUFFER_SIZE, "%F %T %z", psLocalTime );
|
|
||||||
|
|
||||||
cSerial << "Time: " << szBuffer << "\r\n";
|
|
||||||
|
|
||||||
if( rtc_check_alarm() )
|
|
||||||
{
|
|
||||||
cSerial << "ALARM!" << "\r\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t ui8Cmd;
|
|
||||||
|
|
||||||
if( cSerial.receiveByte( ui8Cmd ) )
|
|
||||||
{
|
|
||||||
if( ui8Cmd == 'b' )
|
|
||||||
{
|
|
||||||
cSerial << "Bootloader . . . " << "\r\n";
|
|
||||||
_delay_ms( 1000 );
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
else if( ui8Cmd == 's' )
|
|
||||||
{
|
|
||||||
setTime();
|
|
||||||
}
|
|
||||||
else if( ui8Cmd == 'a' )
|
|
||||||
{
|
|
||||||
setAlarm();
|
|
||||||
}
|
|
||||||
else if( ui8Cmd == 'p' )
|
|
||||||
{
|
|
||||||
uint8_t ui8Hour;
|
|
||||||
uint8_t ui8Minute;
|
|
||||||
uint8_t ui8Second;
|
|
||||||
|
|
||||||
rtc_get_alarm_s( &ui8Hour, &ui8Minute, &ui8Second );
|
|
||||||
sprintf( szBuffer, "Alarm set to: %02d:%02d:%02d", ui8Hour, ui8Minute, ui8Second );
|
|
||||||
cSerial << szBuffer << "\r\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cSerial << "Invalid char: '";
|
|
||||||
cSerial.transmitByte( ui8Cmd );
|
|
||||||
cSerial << "'" << "\r\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
Subproject commit b2a3b03867858da5d1f8eb955fcbfc106c851ac2
|
|
Loading…
Reference in New Issue
Block a user