From 8e2e18128b2ee9315216e9307bb9eac331f2adce Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sun, 17 Dec 2017 10:48:59 +0100 Subject: [PATCH] Exported code as submodule --- .gitmodules | 3 - ds3231.atsln | 22 -- ds3231/bootloader.h | 56 ----- ds3231/clock.h | 14 -- ds3231/ds3231.cppproj | 247 -------------------- ds3231/main.cpp | 178 -------------- ds3231/usart | 1 - ds3231/rtc.cpp => rtc.cpp | 0 ds3231/rtc.h => rtc.h | 0 ds3231/systime.cpp => systime.cpp | 0 ds3231/systime.h => systime.h | 0 ds3231/twi-lowlevel.cpp => twi-lowlevel.cpp | 0 ds3231/twi-lowlevel.h => twi-lowlevel.h | 0 ds3231/twi.cpp => twi.cpp | 0 ds3231/twi.h => twi.h | 0 15 files changed, 521 deletions(-) delete mode 100644 .gitmodules delete mode 100644 ds3231.atsln delete mode 100644 ds3231/bootloader.h delete mode 100644 ds3231/clock.h delete mode 100644 ds3231/ds3231.cppproj delete mode 100644 ds3231/main.cpp delete mode 160000 ds3231/usart rename ds3231/rtc.cpp => rtc.cpp (100%) rename ds3231/rtc.h => rtc.h (100%) rename ds3231/systime.cpp => systime.cpp (100%) rename ds3231/systime.h => systime.h (100%) rename ds3231/twi-lowlevel.cpp => twi-lowlevel.cpp (100%) rename ds3231/twi-lowlevel.h => twi-lowlevel.h (100%) rename ds3231/twi.cpp => twi.cpp (100%) rename ds3231/twi.h => twi.h (100%) diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e82c854..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "ds3231/usart"] - path = ds3231/usart - url = git@blackmark.me:usart.git diff --git a/ds3231.atsln b/ds3231.atsln deleted file mode 100644 index 74635dc..0000000 --- a/ds3231.atsln +++ /dev/null @@ -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 diff --git a/ds3231/bootloader.h b/ds3231/bootloader.h deleted file mode 100644 index a4516c7..0000000 --- a/ds3231/bootloader.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -* Copyright (c) by BlackMark 2016 -* Date 09/09/2016 -* Version 1.4 -*/ - -#ifndef BOOTLOADER_H -#define BOOTLOADER_H - -#include -#include -#include - -typedef void (*flash)() __attribute__ ((noreturn)); - -flash boot = reinterpret_cast( 0x0000 ); -flash bootloader = reinterpret_cast( 0x7E00 / 2 ); - -inline bool checkBootloader() -{ - if( pgm_read_byte( reinterpret_cast( 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 \ No newline at end of file diff --git a/ds3231/clock.h b/ds3231/clock.h deleted file mode 100644 index a04b5ea..0000000 --- a/ds3231/clock.h +++ /dev/null @@ -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 - -#endif \ No newline at end of file diff --git a/ds3231/ds3231.cppproj b/ds3231/ds3231.cppproj deleted file mode 100644 index 15ee949..0000000 --- a/ds3231/ds3231.cppproj +++ /dev/null @@ -1,247 +0,0 @@ - - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.CPP - dce6c7e3-ee26-4d79-826b-08594b9ad897 - ATmega328P - none - Executable - CPP - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - ds3231 - ds3231 - ds3231 - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 0 - - - - - - - - - - - - - com.atmel.avrdbg.tool.stk500 - - 0x1E950F - - - - - - - - custom - - - Custom Programming Tool - - ISP - - - - - - - - com.atmel.avrdbg.tool.simulator - - - Simulator - - 0 - - - - - 125000 - - ISP - - com.atmel.avrdbg.tool.stk500 - - - STK500 - - 125000 - - - - - -mmcu=atmega328p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\gcc\dev\atmega328p" - True - True - True - True - False - True - True - - - NDEBUG - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\include - - - Optimize for size (-Os) - True - True - True - True - True - - - NDEBUG - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\include - - - Optimize for size (-Os) - True - True - True - True - -Wextra -std=c++14 - - - libm - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\include - - - - - echo "C:\bin\avrdude-6.3\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i > "$(MSBuildProjectDirectory)\avrdude.bat" - - - - - -mmcu=atmega328p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\gcc\dev\atmega328p" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\include - - - Optimize (-O1) - True - True - Default (-g2) - True - True - True - - - DEBUG - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\include - - - Optimize (-O1) - True - True - Default (-g2) - True - True - -Wextra -std=c++14 - - - libm - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.2.193\include - - - Default (-Wa,-g) - - - echo "C:\bin\avrdude-6.3\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i > "$(MSBuildProjectDirectory)\avrdude.bat" - - - - compile - - - compile - - - compile - - - compile - - - compile - - - compile - - - compile - - - compile - - - compile - - - compile - - - compile - - - compile - - - compile - - - - - - - \ No newline at end of file diff --git a/ds3231/main.cpp b/ds3231/main.cpp deleted file mode 100644 index cd24039..0000000 --- a/ds3231/main.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* -* Copyright (c) by BlackMark 2017 -* Date 17/12/2017 -* Version 1.2 -*/ - -#include -#include -#include -#include - -#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; -} \ No newline at end of file diff --git a/ds3231/usart b/ds3231/usart deleted file mode 160000 index b2a3b03..0000000 --- a/ds3231/usart +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b2a3b03867858da5d1f8eb955fcbfc106c851ac2 diff --git a/ds3231/rtc.cpp b/rtc.cpp similarity index 100% rename from ds3231/rtc.cpp rename to rtc.cpp diff --git a/ds3231/rtc.h b/rtc.h similarity index 100% rename from ds3231/rtc.h rename to rtc.h diff --git a/ds3231/systime.cpp b/systime.cpp similarity index 100% rename from ds3231/systime.cpp rename to systime.cpp diff --git a/ds3231/systime.h b/systime.h similarity index 100% rename from ds3231/systime.h rename to systime.h diff --git a/ds3231/twi-lowlevel.cpp b/twi-lowlevel.cpp similarity index 100% rename from ds3231/twi-lowlevel.cpp rename to twi-lowlevel.cpp diff --git a/ds3231/twi-lowlevel.h b/twi-lowlevel.h similarity index 100% rename from ds3231/twi-lowlevel.h rename to twi-lowlevel.h diff --git a/ds3231/twi.cpp b/twi.cpp similarity index 100% rename from ds3231/twi.cpp rename to twi.cpp diff --git a/ds3231/twi.h b/twi.h similarity index 100% rename from ds3231/twi.h rename to twi.h