From a6a04f58e4afd20f206fdf4a8a7b3ce4062f1b67 Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 16 Jun 2016 14:11:57 +0200 Subject: [PATCH] VOC Optimation --- DS18B20_BMP280/DS18B20_BMP280.atsln | 40 +- DS18B20_BMP280/DS18B20_BMP280.c | 302 ++-- DS18B20_BMP280/DS18B20_BMP280.cproj | 308 ++-- .../DS18B20_BMP280_DS2438_SHT.atsln | 44 +- .../DS18B20_BMP280_DS2438_SHT.cproj | 328 ++-- DS18B20_BMP280_DS2438_SHT/DS18B20_DS2438.c | 578 +++---- DS18B20_MAX44009/DS18B20_MAX44009.atsln | 40 +- DS18B20_MAX44009/DS18B20_MAX44009.c | 300 ++-- DS18B20_MAX44009/DS18B20_MAX44009.cproj | 308 ++-- DS18B20_MAX44009_DS2438_SHT/DS18B20_DS2438.c | 556 +++---- .../DS18B20_MAX44009_DS2438_SHT.atsln | 44 +- .../DS18B20_MAX44009_DS2438_SHT.cproj | 316 ++-- DS18B20_Thermocouble/DS18B20_TC.atsln | 40 +- DS18B20_Thermocouble/DS18B20_TC.c | 618 ++++---- DS18B20_Thermocouble/DS18B20_TC.cproj | 268 ++-- DS18B20_Thermocouble/Typ-J.csv | 282 ++-- DS18B20_Thermocouble/convthermocouple.py | 60 +- DS18B20_VOC/DS18B20_VOC.atsln | 44 +- DS18B20_VOC/DS18B20_VOC.c | 368 ++--- DS18B20_VOC/DS18B20_VOC.cproj | 312 ++-- DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c | 804 +++++----- .../DS18B20_VOC_DS2438_SHT.atsln | 44 +- .../DS18B20_VOC_DS2438_SHT.cproj | 322 ++-- DS18B20_VOC_DS2438_SHT/MAX1164x.h | 22 - DS2406/DS2406.atsln | 40 +- DS2406/DS2406.c | 234 +-- DS2406/DS2406.cproj | 236 +-- DS2406/OWDS2406.S | 638 ++++---- DS2423/DS2423.c | 532 +++---- DS2423/DS2423.cproj | 268 ++-- DS2423_BMP280/DS2423_BMP280.atsln | 40 +- DS2423_BMP280/DS2423_BMP280.c | 326 ++-- DS2423_BMP280/DS2423_BMP280.cproj | 284 ++-- DS2438_DHT22/.gitignore | 6 +- DS2438_DHT22/DS2438_DHT22 - Kopie.c | 886 +++++------ DS2438_DHT22/DS2438_DHT22.c | 600 ++++---- DS2438_DHT22/DS2438_DHT22.cproj | 268 ++-- DS2438_DHT22/OWDS2438.S | 372 ++--- DS2438_HIH9121/DS2438_9121.atsln | 44 +- DS2438_HIH9121/DS2438_HIH9121.c | 452 +++--- DS2438_HIH9121/DS2438_HIH9121.cproj | 276 ++-- DS2438_SHT2X/DS2438_SHT2X.atsln | 40 +- DS2438_SHT2X/DS2438_SHT2X.c | 418 +++--- DS2438_SHT2X/DS2438_SHT2X.cproj | 284 ++-- DS2450/DS2450.atsln | 44 +- DS2450/DS2450.c | 486 +++--- DS2450/DS2450.cproj | 240 +-- DS2450/OWDS2450.S | 492 +++--- .../DS2450_SHT2X_BMP280_MAX44009.atsln | 44 +- .../DS2450_SHT2X_BMP280_MAX44009.c | 634 ++++---- .../DS2450_SHT2X_BMP280_MAX44009.cproj | 306 ++-- DS2450_SHT2X_BMP280_MAX44009/OWDS2450.S | 492 +++--- common/I2C/BMP280.c | 316 ++-- common/I2C/BMP280.h | 24 +- common/I2C/MAX1164x.c | 110 +- common/I2C/MAX1164x.h | 44 +- common/I2C/MAX44009.c | 170 +-- common/I2C/MAX44009.h | 74 +- common/I2C/SHT2x.c | 432 +++--- common/I2C/SHT2x.h | 268 ++-- common/I2C/TSL256x.c | 292 ++-- common/I2C/TSL256x.h | 34 +- common/I2C/USI_TWI_Master.c | 644 ++++---- common/I2C/USI_TWI_Master.h | 274 ++-- common/OWCRC16.s | 164 +- common/OWCRC8.s | 134 +- common/OWConfig.s | 194 +-- common/OWDS18B20.S | 432 +++--- common/OWDS18B20_DS2438.S | 718 ++++----- common/OWDS2423.S | 676 ++++----- common/OWDS2438.S | 372 ++--- common/OWPinInterrupt.s | 402 ++--- common/OWRomFunctions.s | 984 ++++++------ common/OWRomFunctionsDual.s | 1328 ++++++++--------- common/OWSet_ATTINYX4.s | 286 ++-- common/OWSet_ATTINYX5.s | 292 ++-- common/OWTimerInterrupt.s | 172 +-- common/calibr.c | 44 +- common/calibr.h | 16 +- programmer/flash/flashp 2.7.bat | 4 +- programmer/flash/flashp.bat | 4 +- programmer/programmer.atsln | 40 +- programmer/programmer/programmer.asm | 976 ++++++------ programmer/programmer/programmer.asmproj | 184 +-- programmer/programmer/programmer_4mhz.asm | 978 ++++++------ programmer/programmer/programmer_8MHz.asm | 976 ++++++------ stest/fdiff.py | 148 +- stest/find.py | 582 ++++---- stest/log_all1.py | 680 ++++----- stest/separate1.py | 206 +-- tools_cmd/owtools.sdf | Bin 32243712 -> 32243712 bytes tools_cmd/owtools.sln | 44 +- tools_cmd/rwOW/crcutil.c | 238 +-- tools_cmd/rwOW/ibtmexcw.h | 468 +++--- tools_cmd/rwOW/main.cpp | 780 +++++----- tools_cmd/rwOW/owerr.c | 696 ++++----- tools_cmd/rwOW/ownet.h | 844 +++++------ tools_cmd/rwOW/tmexlnk.c | 734 ++++----- tools_cmd/rwOW/tmexnet.c | 498 +++---- tools_cmd/rwOW/tmexses.c | 424 +++--- tools_cmd/rwOW/tmextran.c | 398 ++--- 101 files changed, 17071 insertions(+), 17057 deletions(-) delete mode 100644 DS18B20_VOC_DS2438_SHT/MAX1164x.h diff --git a/DS18B20_BMP280/DS18B20_BMP280.atsln b/DS18B20_BMP280/DS18B20_BMP280.atsln index 764eb5c..c6afe44 100644 --- a/DS18B20_BMP280/DS18B20_BMP280.atsln +++ b/DS18B20_BMP280/DS18B20_BMP280.atsln @@ -1,20 +1,20 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Atmel Studio Solution File, Format Version 11.00 -Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_BMP280", "DS18B20_BMP280.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|AVR = Debug|AVR - Release|AVR = Release|AVR - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Atmel Studio Solution File, Format Version 11.00 +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_BMP280", "DS18B20_BMP280.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/DS18B20_BMP280/DS18B20_BMP280.c b/DS18B20_BMP280/DS18B20_BMP280.c index 4a78bad..261c78d 100644 --- a/DS18B20_BMP280/DS18B20_BMP280.c +++ b/DS18B20_BMP280/DS18B20_BMP280.c @@ -1,152 +1,152 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/BMP280.h" - - -extern void OWINIT(); -extern void EXTERN_SLEEP(); - - - - -uint8_t owid[8]={0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40};/**/ -uint8_t config_info[16]={0x02,0x03, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - -#if (owid>128) -#error "Variable not correct" -#endif - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; - - - - -typedef union { - volatile uint8_t bytes[8]; - struct { - uint16_t temp; //0 - uint8_t TH; //2 - uint8_t TL; //3 - uint8_t config; //4 - uint8_t rrFF; //5 - uint8_t rr00; //6 - uint8_t rr10; //7 - }; -} pack_t; -volatile pack_t pack; - - - - - - - - -int main(void){ - PRR|=(1<>4; - uint8_t af=0; - if (t8>pack.TH) af=1; - if (t8<=pack.TL) af=1; - cli(); - pack.temp=w; - //pack.temp++; - alarmflag=af; - sei(); - EXTERN_SLEEP(); - //PORTB&=~(1< +#include +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common/I2C/BMP280.h" + + +extern void OWINIT(); +extern void EXTERN_SLEEP(); + + + + +uint8_t owid[8]={0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40};/**/ +uint8_t config_info[16]={0x02,0x03, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +#if (owid>128) +#error "Variable not correct" +#endif + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; + + + + +typedef union { + volatile uint8_t bytes[8]; + struct { + uint16_t temp; //0 + uint8_t TH; //2 + uint8_t TL; //3 + uint8_t config; //4 + uint8_t rrFF; //5 + uint8_t rr00; //6 + uint8_t rr10; //7 + }; +} pack_t; +volatile pack_t pack; + + + + + + + + +int main(void){ + PRR|=(1<>4; + uint8_t af=0; + if (t8>pack.TH) af=1; + if (t8<=pack.TL) af=1; + cli(); + pack.temp=w; + //pack.temp++; + alarmflag=af; + sei(); + EXTERN_SLEEP(); + //PORTB&=~(1< - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.C - {7a5672fe-8226-4158-b931-e1f36b9a8858} - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS18B20_BMP280 - DS18B20_BMP280 - DS18B20_BMP280 - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800000779 - Atmel-ICE - - debugWIRE - - - - - - - - com.atmel.avrdbg.tool.simulator - - - Simulator - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - BMP280.c - - - compile - OWDS18B20.S - - - compile - USI_TWI_Master.c - - - compile - - - + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + {7a5672fe-8226-4158-b931-e1f36b9a8858} + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS18B20_BMP280 + DS18B20_BMP280 + DS18B20_BMP280 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000779 + Atmel-ICE + + debugWIRE + + + + + + + + com.atmel.avrdbg.tool.simulator + + + Simulator + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + BMP280.c + + + compile + OWDS18B20.S + + + compile + USI_TWI_Master.c + + + compile + + + \ No newline at end of file diff --git a/DS18B20_BMP280_DS2438_SHT/DS18B20_BMP280_DS2438_SHT.atsln b/DS18B20_BMP280_DS2438_SHT/DS18B20_BMP280_DS2438_SHT.atsln index 0a5815e..1b9d0ed 100644 --- a/DS18B20_BMP280_DS2438_SHT/DS18B20_BMP280_DS2438_SHT.atsln +++ b/DS18B20_BMP280_DS2438_SHT/DS18B20_BMP280_DS2438_SHT.atsln @@ -1,22 +1,22 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Atmel Studio Solution File, Format Version 11.00 -VisualStudioVersion = 14.0.23107.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_BMP280_DS2438_SHT", "DS18B20_BMP280_DS2438_SHT.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|AVR = Debug|AVR - Release|AVR = Release|AVR - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Atmel Studio Solution File, Format Version 11.00 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_BMP280_DS2438_SHT", "DS18B20_BMP280_DS2438_SHT.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/DS18B20_BMP280_DS2438_SHT/DS18B20_BMP280_DS2438_SHT.cproj b/DS18B20_BMP280_DS2438_SHT/DS18B20_BMP280_DS2438_SHT.cproj index 971060d..9c39af3 100644 --- a/DS18B20_BMP280_DS2438_SHT/DS18B20_BMP280_DS2438_SHT.cproj +++ b/DS18B20_BMP280_DS2438_SHT/DS18B20_BMP280_DS2438_SHT.cproj @@ -1,165 +1,165 @@ - - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.C - {7a5672fe-8226-4158-b931-e1f36b9a8858} - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS18B20_DS2438 - DS18B20_BMP280_DS2438_SHT - DS18B20_DS2438 - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800000789 - Atmel-ICE - - debugWIRE - - - - - - - - com.atmel.avrdbg.tool.simulator - - - Simulator - - - J41800000789 - 0x1E930C - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - SHT2x.c - - - compile - calibr.c - - - compile - BMP280.c - - - compile - USI_TWI_Master.c - - - compile - OWDS18B20_DS2438.S - - - compile - - - + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + {7a5672fe-8226-4158-b931-e1f36b9a8858} + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS18B20_DS2438 + DS18B20_BMP280_DS2438_SHT + DS18B20_DS2438 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000789 + Atmel-ICE + + debugWIRE + + + + + + + + com.atmel.avrdbg.tool.simulator + + + Simulator + + + J41800000789 + 0x1E930C + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + SHT2x.c + + + compile + calibr.c + + + compile + BMP280.c + + + compile + USI_TWI_Master.c + + + compile + OWDS18B20_DS2438.S + + + compile + + + \ No newline at end of file diff --git a/DS18B20_BMP280_DS2438_SHT/DS18B20_DS2438.c b/DS18B20_BMP280_DS2438_SHT/DS18B20_DS2438.c index d8b04bd..f7261e3 100644 --- a/DS18B20_BMP280_DS2438_SHT/DS18B20_DS2438.c +++ b/DS18B20_BMP280_DS2438_SHT/DS18B20_DS2438.c @@ -1,290 +1,290 @@ -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/SHT2x.h" -#include "../common/I2C/BMP280.h" -#include "../common/calibr.h" - -extern void OWINIT(); -extern void EXTERN_SLEEP(); - - -uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/ -uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/ -uint8_t config_info1[16]={0x02,0x03, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; -uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - -#if (owid>128) -#error "Variable not correct" -#endif - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; -volatile uint8_t wdcounter=3; - - -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) -ISR(WATCHDOG_vect) { - #else - ISR(WDT_vect) { - -#endif - //sleep_disable(); // Disable Sleep on Wakeup - wdcounter++; - if (reset_indicator==1) reset_indicator++; - else if (reset_indicator==2) mode=0; -/* if (timeout==2) { - DIS_TIMER; - EN_OWINT; - mode=OWM_SLEEP; - } - timeout++;*/ - //sleep_enable(); // Enable Sleep Mode - -} - - -typedef union { - volatile uint8_t bytes[8]; - struct { - uint16_t temp; //0 - uint8_t TH; //2 - uint8_t TL; //3 - uint8_t config; //4 - uint8_t rrFF; //5 - uint8_t rr00; //6 - uint8_t rr10; //7 - }; -} pack1_t; -volatile pack1_t pack1; - - - -typedef union { - #if defined(__AVR_ATtiny25__) - volatile uint8_t bytes[16]; - #else - volatile uint8_t bytes[64]; - #endif - struct { - uint8_t status; //1 - int16_t temp; //2 - uint16_t voltage; //4 - uint16_t current; //6 - uint8_t threshold; //8 - - uint8_t page1[8]; //9 - #if defined(__AVR_ATtiny25__) - #else - uint8_t page2[8]; //17 - uint8_t page3[8]; //25 - uint8_t page4[8]; //33 - uint8_t page5[8]; //41 - uint8_t page6[8]; //49 - uint8_t page7[8]; //57 - //uint8_t crc; //65 - #endif - }; -} pack2_t; -volatile pack2_t pack2; - - - - -volatile int16_t am2302_temp; -volatile uint16_t am2302_hum; - - -int testSW(void) { - uint8_t r; - DDRB&=~(1<2) { - SHT2x_MeasurePoll(HUMIDITY, &sRH); - // --- measure temperature with "Polling Mode" (no hold master) --- - SHT2x_MeasurePoll(TEMP, &sT); - //-- calculate humidity and temperature -- - temperatureC = SHT2x_CalcTemperatureC(sT); - humidityRH = SHT2x_CalcRH(sRH); - humidityRH=calibr_hum(temperatureC,-0.45,humidityRH)*10.0; - temperatureC=temperatureC*10.0-4.5; - if (testSW()) { - am2302_hum= humidityRH*10.0; - am2302_temp=temperatureC*25.6; - am2302_temp=am2302_temp-20; - config_info2[5]=8; - - }else{ - - double hhum=(1.0546-0.000216*temperatureC)*(humidityRH); - //am2302_hum=0.318*hhum +76.0; - am2302_hum=0.31*hhum +80; - am2302_temp=temperatureC*25.6; - am2302_temp=am2302_temp-20; - config_info2[5]=7; - } - wdcounter=0; - } - - if (gcontrol==1) { - - bmp280ConvertInt(&t,&P,1); - P=P-70000; - P=P/20; - uint16_t w=P; - uint8_t t8=w>>4; - uint8_t af=0; - if (t8>pack1.TH) af=1; - if (t8<=pack1.TL) af=1; - cli(); - pack1.temp=w; - //pack.temp++; - alarmflag=af; - sei(); - gcontrol=0; - EXTERN_SLEEP(); - } - if (gcontrol) { - gcontrol=0; - - } - - -#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - if (((TIMSK & (1< +#include +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common/I2C/SHT2x.h" +#include "../common/I2C/BMP280.h" +#include "../common/calibr.h" + +extern void OWINIT(); +extern void EXTERN_SLEEP(); + + +uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/ +uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/ +uint8_t config_info1[16]={0x02,0x03, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; +uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +#if (owid>128) +#error "Variable not correct" +#endif + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; +volatile uint8_t wdcounter=3; + + +#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) +ISR(WATCHDOG_vect) { + #else + ISR(WDT_vect) { + +#endif + //sleep_disable(); // Disable Sleep on Wakeup + wdcounter++; + if (reset_indicator==1) reset_indicator++; + else if (reset_indicator==2) mode=0; +/* if (timeout==2) { + DIS_TIMER; + EN_OWINT; + mode=OWM_SLEEP; + } + timeout++;*/ + //sleep_enable(); // Enable Sleep Mode + +} + + +typedef union { + volatile uint8_t bytes[8]; + struct { + uint16_t temp; //0 + uint8_t TH; //2 + uint8_t TL; //3 + uint8_t config; //4 + uint8_t rrFF; //5 + uint8_t rr00; //6 + uint8_t rr10; //7 + }; +} pack1_t; +volatile pack1_t pack1; + + + +typedef union { + #if defined(__AVR_ATtiny25__) + volatile uint8_t bytes[16]; + #else + volatile uint8_t bytes[64]; + #endif + struct { + uint8_t status; //1 + int16_t temp; //2 + uint16_t voltage; //4 + uint16_t current; //6 + uint8_t threshold; //8 + + uint8_t page1[8]; //9 + #if defined(__AVR_ATtiny25__) + #else + uint8_t page2[8]; //17 + uint8_t page3[8]; //25 + uint8_t page4[8]; //33 + uint8_t page5[8]; //41 + uint8_t page6[8]; //49 + uint8_t page7[8]; //57 + //uint8_t crc; //65 + #endif + }; +} pack2_t; +volatile pack2_t pack2; + + + + +volatile int16_t am2302_temp; +volatile uint16_t am2302_hum; + + +int testSW(void) { + uint8_t r; + DDRB&=~(1<2) { + SHT2x_MeasurePoll(HUMIDITY, &sRH); + // --- measure temperature with "Polling Mode" (no hold master) --- + SHT2x_MeasurePoll(TEMP, &sT); + //-- calculate humidity and temperature -- + temperatureC = SHT2x_CalcTemperatureC(sT); + humidityRH = SHT2x_CalcRH(sRH); + humidityRH=calibr_hum(temperatureC,-0.45,humidityRH)*10.0; + temperatureC=temperatureC*10.0-4.5; + if (testSW()) { + am2302_hum= humidityRH*10.0; + am2302_temp=temperatureC*25.6; + am2302_temp=am2302_temp-20; + config_info2[5]=8; + + }else{ + + double hhum=(1.0546-0.000216*temperatureC)*(humidityRH); + //am2302_hum=0.318*hhum +76.0; + am2302_hum=0.31*hhum +80; + am2302_temp=temperatureC*25.6; + am2302_temp=am2302_temp-20; + config_info2[5]=7; + } + wdcounter=0; + } + + if (gcontrol==1) { + + bmp280ConvertInt(&t,&P,1); + P=P-70000; + P=P/20; + uint16_t w=P; + uint8_t t8=w>>4; + uint8_t af=0; + if (t8>pack1.TH) af=1; + if (t8<=pack1.TL) af=1; + cli(); + pack1.temp=w; + //pack.temp++; + alarmflag=af; + sei(); + gcontrol=0; + EXTERN_SLEEP(); + } + if (gcontrol) { + gcontrol=0; + + } + + +#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) + if (((TIMSK & (1< -#include -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/MAX44009.h" - - -extern void OWINIT(); - -extern void EXTERN_SLEEP(); - - -uint8_t owid[8]={0x28, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x77, 0x6B};/**/ -uint8_t config_info[16]={0x03,0x04, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - -#if (owid>128) -#error "Variable not correct" -#endif - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; - - -uint8_t max_adr=0; - -typedef union { - volatile uint8_t bytes[8]; - struct { - uint16_t temp; //0 - uint8_t TH; //2 - uint8_t TL; //3 - uint8_t config; //4 - uint8_t rrFF; //5 - uint8_t rr00; //6 - uint8_t rr10; //7 - }; -} pack_t; -volatile pack_t pack; - - - - - - - - -int main(void){ - PRR|=(1<>4; - uint8_t af=0; - if (t8>pack.TH) af=1; - if (t8<=pack.TL) af=1; - cli(); - pack.temp=w; - //pack.temp++; - alarmflag=af; - sei(); - EXTERN_SLEEP(); - //PORTB&=~(1< +#include +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common/I2C/MAX44009.h" + + +extern void OWINIT(); + +extern void EXTERN_SLEEP(); + + +uint8_t owid[8]={0x28, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x77, 0x6B};/**/ +uint8_t config_info[16]={0x03,0x04, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +#if (owid>128) +#error "Variable not correct" +#endif + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; + + +uint8_t max_adr=0; + +typedef union { + volatile uint8_t bytes[8]; + struct { + uint16_t temp; //0 + uint8_t TH; //2 + uint8_t TL; //3 + uint8_t config; //4 + uint8_t rrFF; //5 + uint8_t rr00; //6 + uint8_t rr10; //7 + }; +} pack_t; +volatile pack_t pack; + + + + + + + + +int main(void){ + PRR|=(1<>4; + uint8_t af=0; + if (t8>pack.TH) af=1; + if (t8<=pack.TL) af=1; + cli(); + pack.temp=w; + //pack.temp++; + alarmflag=af; + sei(); + EXTERN_SLEEP(); + //PORTB&=~(1< - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.C - {7a5672fe-8226-4158-b931-e1f36b9a8858} - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS18B20_MAX44009 - DS18B20_MAX44009 - DS18B20_MAX44009 - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800000779 - Atmel-ICE - - debugWIRE - - - - - - - - com.atmel.avrdbg.tool.simulator - - - Simulator - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - OWDS18B20.S - - - compile - MAX44009.c - - - compile - USI_TWI_Master.c - - - compile - - - + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + {7a5672fe-8226-4158-b931-e1f36b9a8858} + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS18B20_MAX44009 + DS18B20_MAX44009 + DS18B20_MAX44009 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000779 + Atmel-ICE + + debugWIRE + + + + + + + + com.atmel.avrdbg.tool.simulator + + + Simulator + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + OWDS18B20.S + + + compile + MAX44009.c + + + compile + USI_TWI_Master.c + + + compile + + + \ No newline at end of file diff --git a/DS18B20_MAX44009_DS2438_SHT/DS18B20_DS2438.c b/DS18B20_MAX44009_DS2438_SHT/DS18B20_DS2438.c index affc509..f1d01be 100644 --- a/DS18B20_MAX44009_DS2438_SHT/DS18B20_DS2438.c +++ b/DS18B20_MAX44009_DS2438_SHT/DS18B20_DS2438.c @@ -1,279 +1,279 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/MAX44009.h" -#include "../common/I2C/SHT2x.h" - - -extern void OWINIT(); -extern void EXTERN_SLEEP(); - - -uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/ -uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/ -uint8_t config_info1[16]={0x03,0x04, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; -uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - -#if (owid>128) -#error "Variable not correct" -#endif - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; -volatile uint8_t wdcounter=5; - - -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) -ISR(WATCHDOG_vect) { -#else -ISR(WDT_vect) { -#endif - //sleep_disable(); // Disable Sleep on Wakeup - wdcounter++; - if (reset_indicator==1) reset_indicator++; - else if (reset_indicator==2) mode=0; -/* if (timeout==2) { - DIS_TIMER; - EN_OWINT; - mode=OWM_SLEEP; - } - timeout++;*/ - //sleep_enable(); // Enable Sleep Mode - -} - -int testSW(void) { - uint8_t r; - DDRB&=~(1<2) { - //PORTB|=(1<1000) humidityRH=1000; - if (testSW()) { - am2302_hum= humidityRH*10.0; - am2302_temp=temperatureC*25.6; - // - config_info2[5]=8; - - }else{ - - double hhum=(1.0546-0.000216*temperatureC)*(humidityRH); - //am2302_hum=0.318*hhum +76.0; - am2302_hum=0.31*hhum +80; - am2302_temp=temperatureC*25.6; - //am2302_temp=am2302_temp-45; - config_info2[5]=7; - } - wdcounter=0; - } - - if (gcontrol==1) { - gcontrol=0; - l=MAX44009getlux(max_adr); - if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045 - //double l=1000; - l=log(l)*10*16; - uint16_t w=l; - uint8_t t8=w>>4; - uint8_t af=0; - if (t8>pack1.TH) af=1; - if (t8<=pack1.TL) af=1; - cli(); - pack1.temp=w; - //pack.temp++; - alarmflag=af; - sei(); - EXTERN_SLEEP(); - } - - - -#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - if (((TIMSK & (1< +#include +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common/I2C/MAX44009.h" +#include "../common/I2C/SHT2x.h" + + +extern void OWINIT(); +extern void EXTERN_SLEEP(); + + +uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/ +uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/ +uint8_t config_info1[16]={0x03,0x04, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; +uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +#if (owid>128) +#error "Variable not correct" +#endif + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; +volatile uint8_t wdcounter=5; + + +#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) +ISR(WATCHDOG_vect) { +#else +ISR(WDT_vect) { +#endif + //sleep_disable(); // Disable Sleep on Wakeup + wdcounter++; + if (reset_indicator==1) reset_indicator++; + else if (reset_indicator==2) mode=0; +/* if (timeout==2) { + DIS_TIMER; + EN_OWINT; + mode=OWM_SLEEP; + } + timeout++;*/ + //sleep_enable(); // Enable Sleep Mode + +} + +int testSW(void) { + uint8_t r; + DDRB&=~(1<2) { + //PORTB|=(1<1000) humidityRH=1000; + if (testSW()) { + am2302_hum= humidityRH*10.0; + am2302_temp=temperatureC*25.6; + // + config_info2[5]=8; + + }else{ + + double hhum=(1.0546-0.000216*temperatureC)*(humidityRH); + //am2302_hum=0.318*hhum +76.0; + am2302_hum=0.31*hhum +80; + am2302_temp=temperatureC*25.6; + //am2302_temp=am2302_temp-45; + config_info2[5]=7; + } + wdcounter=0; + } + + if (gcontrol==1) { + gcontrol=0; + l=MAX44009getlux(max_adr); + if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045 + //double l=1000; + l=log(l)*10*16; + uint16_t w=l; + uint8_t t8=w>>4; + uint8_t af=0; + if (t8>pack1.TH) af=1; + if (t8<=pack1.TL) af=1; + cli(); + pack1.temp=w; + //pack.temp++; + alarmflag=af; + sei(); + EXTERN_SLEEP(); + } + + + +#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) + if (((TIMSK & (1< - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.C - {7a5672fe-8226-4158-b931-e1f36b9a8858} - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS18B20_DS2438 - DS18B20_MAX44009_DS2438_SHT - DS18B20_DS2438 - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800000779 - Atmel-ICE - - debugWIRE - - - - - - - - com.atmel.avrdbg.tool.simulator - - - Simulator - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - SHT2x.c - - - compile - MAX44009.c - - - compile - USI_TWI_Master.c - - - compile - OWDS18B20_DS2438.S - - - compile - - - + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + {7a5672fe-8226-4158-b931-e1f36b9a8858} + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS18B20_DS2438 + DS18B20_MAX44009_DS2438_SHT + DS18B20_DS2438 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000779 + Atmel-ICE + + debugWIRE + + + + + + + + com.atmel.avrdbg.tool.simulator + + + Simulator + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + SHT2x.c + + + compile + MAX44009.c + + + compile + USI_TWI_Master.c + + + compile + OWDS18B20_DS2438.S + + + compile + + + \ No newline at end of file diff --git a/DS18B20_Thermocouble/DS18B20_TC.atsln b/DS18B20_Thermocouble/DS18B20_TC.atsln index 6bb479f..450474d 100644 --- a/DS18B20_Thermocouble/DS18B20_TC.atsln +++ b/DS18B20_Thermocouble/DS18B20_TC.atsln @@ -1,20 +1,20 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Atmel Studio Solution File, Format Version 11.00 -Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_TC", "DS18B20_TC.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|AVR = Debug|AVR - Release|AVR = Release|AVR - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Atmel Studio Solution File, Format Version 11.00 +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_TC", "DS18B20_TC.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/DS18B20_Thermocouble/DS18B20_TC.c b/DS18B20_Thermocouble/DS18B20_TC.c index 154b3e5..6ed9a03 100644 --- a/DS18B20_Thermocouble/DS18B20_TC.c +++ b/DS18B20_Thermocouble/DS18B20_TC.c @@ -1,316 +1,316 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include - -extern void OWINIT(); -extern void EXTERN_SLEEP(); - -const float k_rs[54] PROGMEM ={0.000000,24.125000,48.585366,72.731707,96.829268,121.097561,145.700000,170.600000,195.650000,220.625000,245.365854,269.853659,294.119048,318.195122,342.166667,366.000000,389.761905,413.428571,437.023810,460.558140,484.047619,507.511628,530.976190,554.418605,577.883721,601.395349,624.952381,648.571429,672.285714,696.073171,719.976190,744.000000,768.146341,792.439024,816.853659,841.414634,866.125000,890.975000,916.000000,941.179487,966.525000,992.025641,1017.717949,1043.589744,1069.657895,1095.945946,1122.432432,1149.184211,1176.189189,1203.472222,1231.083333,1259.000000,1287.285714,1315.941176}; -//const float j_rs[70] PROGMEM ={0, 18.302913, 34.830476, 50.783019, 70.653704, 90.505455, 110.341818, 130.165455, 149.163636, 160.791071, 180.596364, 200.398214, 220.200000, 240.000000, 250.882883, 270.603636, 290.409091, 310.216364, 330.025455, 342.472727, 360.649091, 380.461818, 400.275000, 420.087273, 435.275676, 450.703636, 470.503636, 490.298214, 510.082456, 523.486726, 540.621053, 560.370175, 580.105172, 591.979487, 610.527119, 630.213559, 644.601653, 660.534426, 680.168852, 690.787097, 710.391935, 729.123810, 740.559375, 760.126562, 770.684615, 790.235385, 800.782812, 820.331250, 834.681250, 850.446032, 870.017460, 880.600000, 900.196774, 911.099187, 930.432787, 950.073333, 960.728333, 980.396667, 1000.078333, 1010.772881, 1030.475862, 1050.187931, 1065.717241, 1080.631034, 1100.358621, 1120.089655, 1131.840000,1150.556897, 1170.294737, 1190.035088}; - double gettemp_rs(double V) { - uint8_t iv=(uint8_t)(V); - float t0=pgm_read_float(&(k_rs[iv])); - float t1=pgm_read_float(&(k_rs[iv+1])); - return t0+(t1-t0)/1*(V-iv); - } - - -uint8_t owid[8]={0x28, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0xAC};/**/ -uint8_t config_info[16]={0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - -#if (owid>128) -#error "Variable not correct" -#endif - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; - - -volatile uint8_t wdcounter; - - -typedef union { - volatile uint8_t bytes[8]; - struct { - uint16_t temp; //0 - uint8_t TH; //2 - uint8_t TL; //3 - uint8_t config; //4 - uint8_t rrFF; //5 - uint8_t rr00; //6 - uint8_t rr10; //7 - }; -} pack_t; -volatile pack_t pack; - - - - -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) -ISR(WATCHDOG_vect) { -#else -ISR(WDT_vect) { -#endif - //sleep_disable(); // Disable Sleep on Wakeup - wdcounter++; - if (reset_indicator==1) reset_indicator++; - else if (reset_indicator==2) mode=0; -/* if (timeout==2) { - DIS_TIMER; - EN_OWINT; - mode=OWM_SLEEP; - } - timeout++;*/ - //sleep_enable(); // Enable Sleep Mode - -} - - -#define OWM_PORT PORTA -#define OWM_PIN PINA -#define OWM_PINN PINA0 -#define OWM_DD DDRA - -#define OWM_SET_LOW OWM_PORT&=~(1< +#include +#include +#include +#include +#include + +extern void OWINIT(); +extern void EXTERN_SLEEP(); + +const float k_rs[54] PROGMEM ={0.000000,24.125000,48.585366,72.731707,96.829268,121.097561,145.700000,170.600000,195.650000,220.625000,245.365854,269.853659,294.119048,318.195122,342.166667,366.000000,389.761905,413.428571,437.023810,460.558140,484.047619,507.511628,530.976190,554.418605,577.883721,601.395349,624.952381,648.571429,672.285714,696.073171,719.976190,744.000000,768.146341,792.439024,816.853659,841.414634,866.125000,890.975000,916.000000,941.179487,966.525000,992.025641,1017.717949,1043.589744,1069.657895,1095.945946,1122.432432,1149.184211,1176.189189,1203.472222,1231.083333,1259.000000,1287.285714,1315.941176}; +//const float j_rs[70] PROGMEM ={0, 18.302913, 34.830476, 50.783019, 70.653704, 90.505455, 110.341818, 130.165455, 149.163636, 160.791071, 180.596364, 200.398214, 220.200000, 240.000000, 250.882883, 270.603636, 290.409091, 310.216364, 330.025455, 342.472727, 360.649091, 380.461818, 400.275000, 420.087273, 435.275676, 450.703636, 470.503636, 490.298214, 510.082456, 523.486726, 540.621053, 560.370175, 580.105172, 591.979487, 610.527119, 630.213559, 644.601653, 660.534426, 680.168852, 690.787097, 710.391935, 729.123810, 740.559375, 760.126562, 770.684615, 790.235385, 800.782812, 820.331250, 834.681250, 850.446032, 870.017460, 880.600000, 900.196774, 911.099187, 930.432787, 950.073333, 960.728333, 980.396667, 1000.078333, 1010.772881, 1030.475862, 1050.187931, 1065.717241, 1080.631034, 1100.358621, 1120.089655, 1131.840000,1150.556897, 1170.294737, 1190.035088}; + double gettemp_rs(double V) { + uint8_t iv=(uint8_t)(V); + float t0=pgm_read_float(&(k_rs[iv])); + float t1=pgm_read_float(&(k_rs[iv+1])); + return t0+(t1-t0)/1*(V-iv); + } + + +uint8_t owid[8]={0x28, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0xAC};/**/ +uint8_t config_info[16]={0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +#if (owid>128) +#error "Variable not correct" +#endif + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; + + +volatile uint8_t wdcounter; + + +typedef union { + volatile uint8_t bytes[8]; + struct { + uint16_t temp; //0 + uint8_t TH; //2 + uint8_t TL; //3 + uint8_t config; //4 + uint8_t rrFF; //5 + uint8_t rr00; //6 + uint8_t rr10; //7 + }; +} pack_t; +volatile pack_t pack; + + + + +#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) +ISR(WATCHDOG_vect) { +#else +ISR(WDT_vect) { +#endif + //sleep_disable(); // Disable Sleep on Wakeup + wdcounter++; + if (reset_indicator==1) reset_indicator++; + else if (reset_indicator==2) mode=0; +/* if (timeout==2) { + DIS_TIMER; + EN_OWINT; + mode=OWM_SLEEP; + } + timeout++;*/ + //sleep_enable(); // Enable Sleep Mode + +} + + +#define OWM_PORT PORTA +#define OWM_PIN PINA +#define OWM_PINN PINA0 +#define OWM_DD DDRA + +#define OWM_SET_LOW OWM_PORT&=~(1<0) { - ares[par]=ADmess(); - par++; - if (par>15) par=0; - wdcounter=0; - } - if (gcontrol) { - PORTB|=(1<>4; - uint8_t af=0; - if (t8>pack.TH) af=1; - if (t8<=pack.TL) af=1; - cli(); - pack.temp=htemp; - alarmflag=af; - sei(); - EXTERN_SLEEP(); - PORTB&=~(1<0) { + ares[par]=ADmess(); + par++; + if (par>15) par=0; + wdcounter=0; + } + if (gcontrol) { + PORTB|=(1<>4; + uint8_t af=0; + if (t8>pack.TH) af=1; + if (t8<=pack.TL) af=1; + cli(); + pack.temp=htemp; + alarmflag=af; + sei(); + EXTERN_SLEEP(); + PORTB&=~(1< - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.C - {7a5672fe-8226-4158-b931-e1f36b9a8858} - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS18B20_TC - DS18B20_TC - DS18B20_TC - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800000779 - Atmel-ICE - - debugWIRE - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - OWDS18B20.S - - - compile - - - + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + {7a5672fe-8226-4158-b931-e1f36b9a8858} + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS18B20_TC + DS18B20_TC + DS18B20_TC + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000779 + Atmel-ICE + + debugWIRE + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + OWDS18B20.S + + + compile + + + \ No newline at end of file diff --git a/DS18B20_Thermocouble/Typ-J.csv b/DS18B20_Thermocouble/Typ-J.csv index ca48831..4b3629e 100644 --- a/DS18B20_Thermocouble/Typ-J.csv +++ b/DS18B20_Thermocouble/Typ-J.csv @@ -1,141 +1,141 @@ --210;-8.095;-8.076;-8.057;-8.037;-8.017;-7.996;-7.976;-7.955;-7.934;-7.912;-7.890 --200;-7.890;-7.868;-7.846;-7.824;-7.801;-7.778;-7.755;-7.731;-7.707;-7.683;-7.659 --190;-7.659;-7.634;-7.610;-7.585;-7.559;-7.534;-7.508;-7.482;-7.456;-7.429;-7.403 --180;-7.403;-7.376;-7.348;-7.321;-7.293;-7.265;-7.237;-7.209;-7.181;-7.152;-7.123 --170;-7.123;-7.094;-7.064;-7.035;-7.005;-6.975;-6.944;-6.914;-6.883;-6.853;-6.821 --160;-6.821;-6.790;-6.759;-6.727;-6.695;-6.663;-6.631;-6.598;-6.566;-6.533;-6.500 --150;-6.500;-6.467;-6.433;-6.400;-6.366;-6.332;-6.298;-6.263;-6.229;-6.194;-6.159 --140;-6.159;-6.124;-6.089;-6.054;-6.018;-5.982;-5.946;-5.910;-5.874;-5.838;-5.801 --130;-5.801;-5.764;-5.727;-5.690;-5.653;-5.616;-5.578;-5.541;-5.503;-5.465;-5.426 --120;-5.426;-5.388;-5.350;-5.311;-5.272;-5.233;-5.194;-5.155;-5.116;-5.076;-5.037 --110;-5.037;-4.997;-4.957;-4.917;-4.877;-4.836;-4.796;-4.755;-4.714;-4.674;-4.633 --100;-4.633;-4.591;-4.550;-4.509;-4.467;-4.425;-4.384;-4.342;-4.300;-4.257;-4.215 --90;-4.215;-4.173;-4.130;-4.088;-4.045;-4.002;-3.959;-3.916;-3.872;-3.829;-3.786 --80;-3.786;-3.742;-3.698;-3.654;-3.610;-3.566;-3.522;-3.478;-3.434;-3.389;-3.344 --70;-3.344;-3.300;-3.255;-3.210;-3.165;-3.120;-3.075;-3.029;-2.984;-2.938;-2.893 --60;-2.893;-2.847;-2.801;-2.755;-2.709;-2.663;-2.617;-2.571;-2.524;-2.478;-2.431 --50;-2.431;-2.385;-2.338;-2.291;-2.244;-2.197;-2.150;-2.103;-2.055;-2.008;-1.961 --40;-1.961;-1.913;-1.865;-1.818;-1.770;-1.722;-1.674;-1.626;-1.578;-1.530;-1.482 --30;-1.482;-1.433;-1.385;-1.336;-1.288;-1.239;-1.190;-1.142;-1.093;-1.044;-0.995 --20;-0.995;-0.946;-0.896;-0.847;-0.798;-0.749;-0.699;-0.650;-0.600;-0.550;-0.501 --10;-0.501;-0.451;-0.401;-0.351;-0.301;-0.251;-0.201;-0.151;-0.101;-0.050;0.000 -0;0.000;0.050;0.101;0.151;0.202;0.253;0.303;0.354;0.405;0.456;0.507 -10;0.507;0.558;0.609;0.660;0.711;0.762;0.814;0.865;0.916;0.968;1.019 -20;1.019;1.071;1.122;1.174;1.226;1.277;1.329;1.381;1.433;1.485;1.537 -30;1.537;1.589;1.641;1.693;1.745;1.797;1.849;1.902;1.954;2.006;2.059 -40;2.059;2.111;2.164;2.216;2.269;2.322;2.374;2.427;2.480;2.532;2.585 -50;2.585;2.638;2.691;2.744;2.797;2.850;2.903;2.956;3.009;3.062;3.116 -60;3.116;3.169;3.222;3.275;3.329;3.382;3.436;3.489;3.543;3.596;3.650 -70;3.650;3.703;3.757;3.810;3.864;3.918;3.971;4.025;4.079;4.133;4.187 -80;4.187;4.240;4.294;4.348;4.402;4.456;4.510;4.564;4.618;4.672;4.726 -90;4.726;4.781;4.835;4.889;4.943;4.997;5.052;5.106;5.160;5.215;5.269 -100;5.269;5.323;5.378;5.432;5.487;5.541;5.595;5.650;5.705;5.759;5.814 -110;5.814;5.868;5.923;5.977;6.032;6.087;6.141;6.196;6.251;6.306;6.360 -120;6.360;6.415;6.470;6.525;6.579;6.634;6.689;6.744;6.799;6.854;6.909 -130;6.909;6.964;7.019;7.074;7.129;7.184;7.239;7.294;7.349;7.404;7.459 -140;7.459;7.514;7.569;7.624;7.679;7.734;7.789;7.844;7.900;7.955;8.010 -150;8.010;8.065;8.120;8.175;8.231;8.286;8.341;8.396;8.452;8.507;8.562 -160;8.562;8.618;8.673;8.728;8.783;8.839;8.894;8.949;9.005;9.060;9.115 -170;9.115;9.171;9.226;9.282;9.337;9.392;9.448;9.503;9.559;9.614;9.669 -180;9.669;9.725;9.780;9.836;9.891;9.947;10.002;10.057;10.113;10.168;10.224 -190;10.224;10.279;10.335;10.390;10.446;10.501;10.557;10.612;10.668;10.723;10.779 -200;10.779;10.834;10.890;10.945;11.001;11.056;11.112;11.167;11.223;11.278;11.334 -210;11.334;11.389;11.445;11.501;11.556;11.612;11.667;11.723;11.778;11.834;11.889 -220;11.889;11.945;12.000;12.056;12.111;12.167;12.222;12.278;12.334;12.389;12.445 -230;12.445;12.500;12.556;12.611;12.667;12.722;12.778;12.833;12.889;12.944;13.000 -240;13.000;13.056;13.111;13.167;13.222;13.278;13.333;13.389;13.444;13.500;13.555 -250;13.555;13.611;13.666;13.722;13.777;13.833;13.888;13.944;13.999;14.055;14.110 -260;14.110;14.166;14.221;14.277;14.332;14.388;14.443;14.499;14.554;14.609;14.665 -270;14.665;14.720;14.776;14.831;14.887;14.942;14.998;15.053;15.109;15.164;15.219 -280;15.219;15.275;15.330;15.386;15.441;15.496;15.552;15.607;15.663;15.718;15.773 -290;15.773;15.829;15.884;15.940;15.995;16.050;16.106;16.161;16.216;16.272;16.327 -300;16.327;16.383;16.438;16.493;16.549;16.604;16.659;16.715;16.770;16.825;16.881 -310;16.881;16.936;16.991;17.046;17.102;17.157;17.212;17.268;17.323;17.378;17.434 -320;17.434;17.489;17.544;17.599;17.655;17.710;17.765;17.820;17.876;17.931;17.986 -330;17.986;18.041;18.097;18.152;18.207;18.262;18.318;18.373;18.428;18.483;18.538 -340;18.538;18.594;18.649;18.704;18.759;18.814;18.870;18.925;18.980;19.035;19.090 -350;19.090;19.146;19.201;19.256;19.311;19.366;19.422;19.477;19.532;19.587;19.642 -360;19.642;19.697;19.753;19.808;19.863;19.918;19.973;20.028;20.083;20.139;20.194 -370;20.194;20.249;20.304;20.359;20.414;20.469;20.525;20.580;20.635;20.690;20.745 -380;20.745;20.800;20.855;20.911;20.966;21.021;21.076;21.131;21.186;21.241;21.297 -390;21.297;21.352;21.407;21.462;21.517;21.572;21.627;21.683;21.738;21.793;21.848 -400;21.848;21.903;21.958;22.014;22.069;22.124;22.179;22.234;22.289;22.345;22.400 -410;22.400;22.455;22.510;22.565;22.620;22.676;22.731;22.786;22.841;22.896;22.952 -420;22.952;23.007;23.062;23.117;23.172;23.228;23.283;23.338;23.393;23.449;23.504 -430;23.504;23.559;23.614;23.670;23.725;23.780;23.835;23.891;23.946;24.001;24.057 -440;24.057;24.112;24.167;24.223;24.278;24.333;24.389;24.444;24.499;24.555;24.610 -450;24.610;24.665;24.721;24.776;24.832;24.887;24.943;24.998;25.053;25.109;25.164 -460;25.164;25.220;25.275;25.331;25.386;25.442;25.497;25.553;25.608;25.664;25.720 -470;25.720;25.775;25.831;25.886;25.942;25.998;26.053;26.109;26.165;26.220;26.276 -480;26.276;26.332;26.387;26.443;26.499;26.555;26.610;26.666;26.722;26.778;26.834 -490;26.834;26.889;26.945;27.001;27.057;27.113;27.169;27.225;27.281;27.337;27.393 -500;27.393;27.449;27.505;27.561;27.617;27.673;27.729;27.785;27.841;27.897;27.953 -510;27.953;28.010;28.066;28.122;28.178;28.234;28.291;28.347;28.403;28.460;28.516 -520;28.516;28.572;28.629;28.685;28.741;28.798;28.854;28.911;28.967;29.024;29.080 -530;29.080;29.137;29.194;29.250;29.307;29.363;29.420;29.477;29.534;29.590;29.647 -540;29.647;29.704;29.761;29.818;29.874;29.931;29.988;30.045;30.102;30.159;30.216 -550;30.216;30.273;30.330;30.387;30.444;30.502;30.559;30.616;30.673;30.730;30.788 -560;30.788;30.845;30.902;30.960;31.017;31.074;31.132;31.189;31.247;31.304;31.362 -570;31.362;31.419;31.477;31.535;31.592;31.650;31.708;31.766;31.823;31.881;31.939 -580;31.939;31.997;32.055;32.113;32.171;32.229;32.287;32.345;32.403;32.461;32.519 -590;32.519;32.577;32.636;32.694;32.752;32.810;32.869;32.927;32.985;33.044;33.102 -600;33.102;33.161;33.219;33.278;33.337;33.395;33.454;33.513;33.571;33.630;33.689 -610;33.689;33.748;33.807;33.866;33.925;33.984;34.043;34.102;34.161;34.220;34.279 -620;34.279;34.338;34.397;34.457;34.516;34.575;34.635;34.694;34.754;34.813;34.873 -630;34.873;34.932;34.992;35.051;35.111;35.171;35.230;35.290;35.350;35.410;35.470 -640;35.470;35.530;35.590;35.650;35.710;35.770;35.830;35.890;35.950;36.010;36.071 -650;36.071;36.131;36.191;36.252;36.312;36.373;36.433;36.494;36.554;36.615;36.675 -660;36.675;36.736;36.797;36.858;36.918;36.979;37.040;37.101;37.162;37.223;37.284 -670;37.284;37.345;37.406;37.467;37.528;37.590;37.651;37.712;37.773;37.835;37.896 -680;37.896;37.958;38.019;38.081;38.142;38.204;38.265;38.327;38.389;38.450;38.512 -690;38.512;38.574;38.636;38.698;38.760;38.822;38.884;38.946;39.008;39.070;39.132 -700;39.132;39.194;39.256;39.318;39.381;39.443;39.505;39.568;39.630;39.693;39.755 -710;39.755;39.818;39.880;39.943;40.005;40.068;40.131;40.193;40.256;40.319;40.382 -720;40.382;40.445;40.508;40.570;40.633;40.696;40.759;40.822;40.886;40.949;41.012 -730;41.012;41.075;41.138;41.201;41.265;41.328;41.391;41.455;41.518;41.581;41.645 -740;41.645;41.708;41.772;41.835;41.899;41.962;42.026;42.090;42.153;42.217;42.281 -750;42.281;42.344;42.408;42.472;42.536;42.599;42.663;42.727;42.791;42.855;42.919 -760;42.919;42.983;43.047;43.111;43.175;43.239;43.303;43.367;43.431;43.495;43.559 -770;43.559;43.624;43.688;43.752;43.817;43.881;43.945;44.010;44.074;44.139;44.203 -780;44.203;44.267;44.332;44.396;44.461;44.525;44.590;44.655;44.719;44.784;44.848 -790;44.848;44.913;44.977;45.042;45.107;45.171;45.236;45.301;45.365;45.430;45.494 -800;45.494;45.559;45.624;45.688;45.753;45.818;45.882;45.947;46.011;46.076;46.141 -810;46.141;46.205;46.270;46.334;46.399;46.464;46.528;46.593;46.657;46.722;46.786 -820;46.786;46.851;46.915;46.980;47.044;47.109;47.173;47.238;47.302;47.367;47.431 -830;47.431;47.495;47.560;47.624;47.688;47.753;47.817;47.881;47.946;48.010;48.074 -840;48.074;48.138;48.202;48.267;48.331;48.395;48.459;48.523;48.587;48.651;48.715 -850;48.715;48.779;48.843;48.907;48.971;49.034;49.098;49.162;49.226;49.290;49.353 -860;49.353;49.417;49.481;49.544;49.608;49.672;49.735;49.799;49.862;49.926;49.989 -870;49.989;50.052;50.116;50.179;50.243;50.306;50.369;50.432;50.495;50.559;50.622 -880;50.622;50.685;50.748;50.811;50.874;50.937;51.000;51.063;51.126;51.188;51.251 -890;51.251;51.314;51.377;51.439;51.502;51.565;51.627;51.690;51.752;51.815;51.877 -900;51.877;51.940;52.002;52.064;52.127;52.189;52.251;52.314;52.376;52.438;52.500 -910;52.500;52.562;52.624;52.686;52.748;52.810;52.872;52.934;52.996;53.057;53.119 -920;53.119;53.181;53.243;53.304;53.366;53.427;53.489;53.550;53.612;53.673;53.735 -930;53.735;53.796;53.857;53.919;53.980;54.041;54.102;54.164;54.225;54.286;54.347 -940;54.347;54.408;54.469;54.530;54.591;54.652;54.713;54.773;54.834;54.895;54.956 -950;54.956;55.016;55.077;55.138;55.198;55.259;55.319;55.380;55.440;55.501;55.561 -960;55.561;55.622;55.682;55.742;55.803;55.863;55.923;55.983;56.043;56.104;56.164 -970;56.164;56.224;56.284;56.344;56.404;56.464;56.524;56.584;56.643;56.703;56.763 -980;56.763;56.823;56.883;56.942;57.002;57.062;57.121;57.181;57.240;57.300;57.360 -990;57.360;57.419;57.479;57.538;57.597;57.657;57.716;57.776;57.835;57.894;57.953 -1000;57.953;58.013;58.072;58.131;58.190;58.249;58.309;58.368;58.427;58.486;58.545 -1010;58.545;58.604;58.663;58.722;58.781;58.840;58.899;58.957;59.016;59.075;59.134 -1020;59.134;59.193;59.252;59.310;59.369;59.428;59.487;59.545;59.604;59.663;59.721 -1030;59.721;59.780;59.838;59.897;59.956;60.014;60.073;60.131;60.190;60.248;60.307 -1040;60.307;60.365;60.423;60.482;60.540;60.599;60.657;60.715;60.774;60.832;60.890 -1050;60.890;60.949;61.007;61.065;61.123;61.182;61.240;61.298;61.356;61.415;61.473 -1060;61.473;61.531;61.589;61.647;61.705;61.763;61.822;61.880;61.938;61.996;62.054 -1070;62.054;62.112;62.170;62.228;62.286;62.344;62.402;62.460;62.518;62.576;62.634 -1080;62.634;62.692;62.750;62.808;62.866;62.924;62.982;63.040;63.098;63.156;63.214 -1090;63.214;63.271;63.329;63.387;63.445;63.503;63.561;63.619;63.677;63.734;63.792 -1100;63.792;63.850;63.908;63.966;64.024;64.081;64.139;64.197;64.255;64.313;64.370 -1110;64.370;64.428;64.486;64.544;64.602;64.659;64.717;64.775;64.833;64.890;64.948 -1120;64.948;65.006;65.064;65.121;65.179;65.237;65.295;65.352;65.410;65.468;65.525 -1130;65.525;65.583;65.641;65.699;65.756;65.814;65.872;65.929;65.987;66.045;66.102 -1140;66.102;66.160;66.218;66.275;66.333;66.391;66.448;66.506;66.564;66.621;66.679 -1150;66.679;66.737;66.794;66.852;66.910;66.967;67.025;67.082;67.140;67.198;67.255 -1160;67.255;67.313;67.370;67.428;67.486;67.543;67.601;67.658;67.716;67.773;67.831 -1170;67.831;67.888;67.946;68.003;68.061;68.119;68.176;68.234;68.291;68.348;68.406 -1180;68.406;68.463;68.521;68.578;68.636;68.693;68.751;68.808;68.865;68.923;68.980 -1190;68.980;69.037;69.095;69.152;69.209;69.267;69.324;69.381;69.439;69.496;69.553 +-210;-8.095;-8.076;-8.057;-8.037;-8.017;-7.996;-7.976;-7.955;-7.934;-7.912;-7.890 +-200;-7.890;-7.868;-7.846;-7.824;-7.801;-7.778;-7.755;-7.731;-7.707;-7.683;-7.659 +-190;-7.659;-7.634;-7.610;-7.585;-7.559;-7.534;-7.508;-7.482;-7.456;-7.429;-7.403 +-180;-7.403;-7.376;-7.348;-7.321;-7.293;-7.265;-7.237;-7.209;-7.181;-7.152;-7.123 +-170;-7.123;-7.094;-7.064;-7.035;-7.005;-6.975;-6.944;-6.914;-6.883;-6.853;-6.821 +-160;-6.821;-6.790;-6.759;-6.727;-6.695;-6.663;-6.631;-6.598;-6.566;-6.533;-6.500 +-150;-6.500;-6.467;-6.433;-6.400;-6.366;-6.332;-6.298;-6.263;-6.229;-6.194;-6.159 +-140;-6.159;-6.124;-6.089;-6.054;-6.018;-5.982;-5.946;-5.910;-5.874;-5.838;-5.801 +-130;-5.801;-5.764;-5.727;-5.690;-5.653;-5.616;-5.578;-5.541;-5.503;-5.465;-5.426 +-120;-5.426;-5.388;-5.350;-5.311;-5.272;-5.233;-5.194;-5.155;-5.116;-5.076;-5.037 +-110;-5.037;-4.997;-4.957;-4.917;-4.877;-4.836;-4.796;-4.755;-4.714;-4.674;-4.633 +-100;-4.633;-4.591;-4.550;-4.509;-4.467;-4.425;-4.384;-4.342;-4.300;-4.257;-4.215 +-90;-4.215;-4.173;-4.130;-4.088;-4.045;-4.002;-3.959;-3.916;-3.872;-3.829;-3.786 +-80;-3.786;-3.742;-3.698;-3.654;-3.610;-3.566;-3.522;-3.478;-3.434;-3.389;-3.344 +-70;-3.344;-3.300;-3.255;-3.210;-3.165;-3.120;-3.075;-3.029;-2.984;-2.938;-2.893 +-60;-2.893;-2.847;-2.801;-2.755;-2.709;-2.663;-2.617;-2.571;-2.524;-2.478;-2.431 +-50;-2.431;-2.385;-2.338;-2.291;-2.244;-2.197;-2.150;-2.103;-2.055;-2.008;-1.961 +-40;-1.961;-1.913;-1.865;-1.818;-1.770;-1.722;-1.674;-1.626;-1.578;-1.530;-1.482 +-30;-1.482;-1.433;-1.385;-1.336;-1.288;-1.239;-1.190;-1.142;-1.093;-1.044;-0.995 +-20;-0.995;-0.946;-0.896;-0.847;-0.798;-0.749;-0.699;-0.650;-0.600;-0.550;-0.501 +-10;-0.501;-0.451;-0.401;-0.351;-0.301;-0.251;-0.201;-0.151;-0.101;-0.050;0.000 +0;0.000;0.050;0.101;0.151;0.202;0.253;0.303;0.354;0.405;0.456;0.507 +10;0.507;0.558;0.609;0.660;0.711;0.762;0.814;0.865;0.916;0.968;1.019 +20;1.019;1.071;1.122;1.174;1.226;1.277;1.329;1.381;1.433;1.485;1.537 +30;1.537;1.589;1.641;1.693;1.745;1.797;1.849;1.902;1.954;2.006;2.059 +40;2.059;2.111;2.164;2.216;2.269;2.322;2.374;2.427;2.480;2.532;2.585 +50;2.585;2.638;2.691;2.744;2.797;2.850;2.903;2.956;3.009;3.062;3.116 +60;3.116;3.169;3.222;3.275;3.329;3.382;3.436;3.489;3.543;3.596;3.650 +70;3.650;3.703;3.757;3.810;3.864;3.918;3.971;4.025;4.079;4.133;4.187 +80;4.187;4.240;4.294;4.348;4.402;4.456;4.510;4.564;4.618;4.672;4.726 +90;4.726;4.781;4.835;4.889;4.943;4.997;5.052;5.106;5.160;5.215;5.269 +100;5.269;5.323;5.378;5.432;5.487;5.541;5.595;5.650;5.705;5.759;5.814 +110;5.814;5.868;5.923;5.977;6.032;6.087;6.141;6.196;6.251;6.306;6.360 +120;6.360;6.415;6.470;6.525;6.579;6.634;6.689;6.744;6.799;6.854;6.909 +130;6.909;6.964;7.019;7.074;7.129;7.184;7.239;7.294;7.349;7.404;7.459 +140;7.459;7.514;7.569;7.624;7.679;7.734;7.789;7.844;7.900;7.955;8.010 +150;8.010;8.065;8.120;8.175;8.231;8.286;8.341;8.396;8.452;8.507;8.562 +160;8.562;8.618;8.673;8.728;8.783;8.839;8.894;8.949;9.005;9.060;9.115 +170;9.115;9.171;9.226;9.282;9.337;9.392;9.448;9.503;9.559;9.614;9.669 +180;9.669;9.725;9.780;9.836;9.891;9.947;10.002;10.057;10.113;10.168;10.224 +190;10.224;10.279;10.335;10.390;10.446;10.501;10.557;10.612;10.668;10.723;10.779 +200;10.779;10.834;10.890;10.945;11.001;11.056;11.112;11.167;11.223;11.278;11.334 +210;11.334;11.389;11.445;11.501;11.556;11.612;11.667;11.723;11.778;11.834;11.889 +220;11.889;11.945;12.000;12.056;12.111;12.167;12.222;12.278;12.334;12.389;12.445 +230;12.445;12.500;12.556;12.611;12.667;12.722;12.778;12.833;12.889;12.944;13.000 +240;13.000;13.056;13.111;13.167;13.222;13.278;13.333;13.389;13.444;13.500;13.555 +250;13.555;13.611;13.666;13.722;13.777;13.833;13.888;13.944;13.999;14.055;14.110 +260;14.110;14.166;14.221;14.277;14.332;14.388;14.443;14.499;14.554;14.609;14.665 +270;14.665;14.720;14.776;14.831;14.887;14.942;14.998;15.053;15.109;15.164;15.219 +280;15.219;15.275;15.330;15.386;15.441;15.496;15.552;15.607;15.663;15.718;15.773 +290;15.773;15.829;15.884;15.940;15.995;16.050;16.106;16.161;16.216;16.272;16.327 +300;16.327;16.383;16.438;16.493;16.549;16.604;16.659;16.715;16.770;16.825;16.881 +310;16.881;16.936;16.991;17.046;17.102;17.157;17.212;17.268;17.323;17.378;17.434 +320;17.434;17.489;17.544;17.599;17.655;17.710;17.765;17.820;17.876;17.931;17.986 +330;17.986;18.041;18.097;18.152;18.207;18.262;18.318;18.373;18.428;18.483;18.538 +340;18.538;18.594;18.649;18.704;18.759;18.814;18.870;18.925;18.980;19.035;19.090 +350;19.090;19.146;19.201;19.256;19.311;19.366;19.422;19.477;19.532;19.587;19.642 +360;19.642;19.697;19.753;19.808;19.863;19.918;19.973;20.028;20.083;20.139;20.194 +370;20.194;20.249;20.304;20.359;20.414;20.469;20.525;20.580;20.635;20.690;20.745 +380;20.745;20.800;20.855;20.911;20.966;21.021;21.076;21.131;21.186;21.241;21.297 +390;21.297;21.352;21.407;21.462;21.517;21.572;21.627;21.683;21.738;21.793;21.848 +400;21.848;21.903;21.958;22.014;22.069;22.124;22.179;22.234;22.289;22.345;22.400 +410;22.400;22.455;22.510;22.565;22.620;22.676;22.731;22.786;22.841;22.896;22.952 +420;22.952;23.007;23.062;23.117;23.172;23.228;23.283;23.338;23.393;23.449;23.504 +430;23.504;23.559;23.614;23.670;23.725;23.780;23.835;23.891;23.946;24.001;24.057 +440;24.057;24.112;24.167;24.223;24.278;24.333;24.389;24.444;24.499;24.555;24.610 +450;24.610;24.665;24.721;24.776;24.832;24.887;24.943;24.998;25.053;25.109;25.164 +460;25.164;25.220;25.275;25.331;25.386;25.442;25.497;25.553;25.608;25.664;25.720 +470;25.720;25.775;25.831;25.886;25.942;25.998;26.053;26.109;26.165;26.220;26.276 +480;26.276;26.332;26.387;26.443;26.499;26.555;26.610;26.666;26.722;26.778;26.834 +490;26.834;26.889;26.945;27.001;27.057;27.113;27.169;27.225;27.281;27.337;27.393 +500;27.393;27.449;27.505;27.561;27.617;27.673;27.729;27.785;27.841;27.897;27.953 +510;27.953;28.010;28.066;28.122;28.178;28.234;28.291;28.347;28.403;28.460;28.516 +520;28.516;28.572;28.629;28.685;28.741;28.798;28.854;28.911;28.967;29.024;29.080 +530;29.080;29.137;29.194;29.250;29.307;29.363;29.420;29.477;29.534;29.590;29.647 +540;29.647;29.704;29.761;29.818;29.874;29.931;29.988;30.045;30.102;30.159;30.216 +550;30.216;30.273;30.330;30.387;30.444;30.502;30.559;30.616;30.673;30.730;30.788 +560;30.788;30.845;30.902;30.960;31.017;31.074;31.132;31.189;31.247;31.304;31.362 +570;31.362;31.419;31.477;31.535;31.592;31.650;31.708;31.766;31.823;31.881;31.939 +580;31.939;31.997;32.055;32.113;32.171;32.229;32.287;32.345;32.403;32.461;32.519 +590;32.519;32.577;32.636;32.694;32.752;32.810;32.869;32.927;32.985;33.044;33.102 +600;33.102;33.161;33.219;33.278;33.337;33.395;33.454;33.513;33.571;33.630;33.689 +610;33.689;33.748;33.807;33.866;33.925;33.984;34.043;34.102;34.161;34.220;34.279 +620;34.279;34.338;34.397;34.457;34.516;34.575;34.635;34.694;34.754;34.813;34.873 +630;34.873;34.932;34.992;35.051;35.111;35.171;35.230;35.290;35.350;35.410;35.470 +640;35.470;35.530;35.590;35.650;35.710;35.770;35.830;35.890;35.950;36.010;36.071 +650;36.071;36.131;36.191;36.252;36.312;36.373;36.433;36.494;36.554;36.615;36.675 +660;36.675;36.736;36.797;36.858;36.918;36.979;37.040;37.101;37.162;37.223;37.284 +670;37.284;37.345;37.406;37.467;37.528;37.590;37.651;37.712;37.773;37.835;37.896 +680;37.896;37.958;38.019;38.081;38.142;38.204;38.265;38.327;38.389;38.450;38.512 +690;38.512;38.574;38.636;38.698;38.760;38.822;38.884;38.946;39.008;39.070;39.132 +700;39.132;39.194;39.256;39.318;39.381;39.443;39.505;39.568;39.630;39.693;39.755 +710;39.755;39.818;39.880;39.943;40.005;40.068;40.131;40.193;40.256;40.319;40.382 +720;40.382;40.445;40.508;40.570;40.633;40.696;40.759;40.822;40.886;40.949;41.012 +730;41.012;41.075;41.138;41.201;41.265;41.328;41.391;41.455;41.518;41.581;41.645 +740;41.645;41.708;41.772;41.835;41.899;41.962;42.026;42.090;42.153;42.217;42.281 +750;42.281;42.344;42.408;42.472;42.536;42.599;42.663;42.727;42.791;42.855;42.919 +760;42.919;42.983;43.047;43.111;43.175;43.239;43.303;43.367;43.431;43.495;43.559 +770;43.559;43.624;43.688;43.752;43.817;43.881;43.945;44.010;44.074;44.139;44.203 +780;44.203;44.267;44.332;44.396;44.461;44.525;44.590;44.655;44.719;44.784;44.848 +790;44.848;44.913;44.977;45.042;45.107;45.171;45.236;45.301;45.365;45.430;45.494 +800;45.494;45.559;45.624;45.688;45.753;45.818;45.882;45.947;46.011;46.076;46.141 +810;46.141;46.205;46.270;46.334;46.399;46.464;46.528;46.593;46.657;46.722;46.786 +820;46.786;46.851;46.915;46.980;47.044;47.109;47.173;47.238;47.302;47.367;47.431 +830;47.431;47.495;47.560;47.624;47.688;47.753;47.817;47.881;47.946;48.010;48.074 +840;48.074;48.138;48.202;48.267;48.331;48.395;48.459;48.523;48.587;48.651;48.715 +850;48.715;48.779;48.843;48.907;48.971;49.034;49.098;49.162;49.226;49.290;49.353 +860;49.353;49.417;49.481;49.544;49.608;49.672;49.735;49.799;49.862;49.926;49.989 +870;49.989;50.052;50.116;50.179;50.243;50.306;50.369;50.432;50.495;50.559;50.622 +880;50.622;50.685;50.748;50.811;50.874;50.937;51.000;51.063;51.126;51.188;51.251 +890;51.251;51.314;51.377;51.439;51.502;51.565;51.627;51.690;51.752;51.815;51.877 +900;51.877;51.940;52.002;52.064;52.127;52.189;52.251;52.314;52.376;52.438;52.500 +910;52.500;52.562;52.624;52.686;52.748;52.810;52.872;52.934;52.996;53.057;53.119 +920;53.119;53.181;53.243;53.304;53.366;53.427;53.489;53.550;53.612;53.673;53.735 +930;53.735;53.796;53.857;53.919;53.980;54.041;54.102;54.164;54.225;54.286;54.347 +940;54.347;54.408;54.469;54.530;54.591;54.652;54.713;54.773;54.834;54.895;54.956 +950;54.956;55.016;55.077;55.138;55.198;55.259;55.319;55.380;55.440;55.501;55.561 +960;55.561;55.622;55.682;55.742;55.803;55.863;55.923;55.983;56.043;56.104;56.164 +970;56.164;56.224;56.284;56.344;56.404;56.464;56.524;56.584;56.643;56.703;56.763 +980;56.763;56.823;56.883;56.942;57.002;57.062;57.121;57.181;57.240;57.300;57.360 +990;57.360;57.419;57.479;57.538;57.597;57.657;57.716;57.776;57.835;57.894;57.953 +1000;57.953;58.013;58.072;58.131;58.190;58.249;58.309;58.368;58.427;58.486;58.545 +1010;58.545;58.604;58.663;58.722;58.781;58.840;58.899;58.957;59.016;59.075;59.134 +1020;59.134;59.193;59.252;59.310;59.369;59.428;59.487;59.545;59.604;59.663;59.721 +1030;59.721;59.780;59.838;59.897;59.956;60.014;60.073;60.131;60.190;60.248;60.307 +1040;60.307;60.365;60.423;60.482;60.540;60.599;60.657;60.715;60.774;60.832;60.890 +1050;60.890;60.949;61.007;61.065;61.123;61.182;61.240;61.298;61.356;61.415;61.473 +1060;61.473;61.531;61.589;61.647;61.705;61.763;61.822;61.880;61.938;61.996;62.054 +1070;62.054;62.112;62.170;62.228;62.286;62.344;62.402;62.460;62.518;62.576;62.634 +1080;62.634;62.692;62.750;62.808;62.866;62.924;62.982;63.040;63.098;63.156;63.214 +1090;63.214;63.271;63.329;63.387;63.445;63.503;63.561;63.619;63.677;63.734;63.792 +1100;63.792;63.850;63.908;63.966;64.024;64.081;64.139;64.197;64.255;64.313;64.370 +1110;64.370;64.428;64.486;64.544;64.602;64.659;64.717;64.775;64.833;64.890;64.948 +1120;64.948;65.006;65.064;65.121;65.179;65.237;65.295;65.352;65.410;65.468;65.525 +1130;65.525;65.583;65.641;65.699;65.756;65.814;65.872;65.929;65.987;66.045;66.102 +1140;66.102;66.160;66.218;66.275;66.333;66.391;66.448;66.506;66.564;66.621;66.679 +1150;66.679;66.737;66.794;66.852;66.910;66.967;67.025;67.082;67.140;67.198;67.255 +1160;67.255;67.313;67.370;67.428;67.486;67.543;67.601;67.658;67.716;67.773;67.831 +1170;67.831;67.888;67.946;68.003;68.061;68.119;68.176;68.234;68.291;68.348;68.406 +1180;68.406;68.463;68.521;68.578;68.636;68.693;68.751;68.808;68.865;68.923;68.980 +1190;68.980;69.037;69.095;69.152;69.209;69.267;69.324;69.381;69.439;69.496;69.553 diff --git a/DS18B20_Thermocouble/convthermocouple.py b/DS18B20_Thermocouble/convthermocouple.py index 79f65ef..c11c3dd 100644 --- a/DS18B20_Thermocouble/convthermocouple.py +++ b/DS18B20_Thermocouble/convthermocouple.py @@ -1,31 +1,31 @@ -fi=open("Typ-J.csv","r") -lastv=0 -v=0 -lastt=0 -t=0 -rs="" -wc=0 -for l in fi.readlines(): - #print(l) - ll=l.split(";") - i=0 - for n in ll[1:10]: - s=ll[0]+"."+str(i) - lastv=v - lastt=t - v=float(n) - t=float(s) - if (int(v)!=int(lastv)): - interp=lastt+(t-lastt)/(v-lastv)*(int(v)-lastv) - print int(v),interp - rs=rs+", %f" %(interp) - wc=wc+1 - if (v==0): - interp=lastt+(t-lastt)/(v-lastv)*(int(v)-lastv) - print int(v),interp - rs="{0" - wc=1 - - i=i+1 -print rs+"};" +fi=open("Typ-J.csv","r") +lastv=0 +v=0 +lastt=0 +t=0 +rs="" +wc=0 +for l in fi.readlines(): + #print(l) + ll=l.split(";") + i=0 + for n in ll[1:10]: + s=ll[0]+"."+str(i) + lastv=v + lastt=t + v=float(n) + t=float(s) + if (int(v)!=int(lastv)): + interp=lastt+(t-lastt)/(v-lastv)*(int(v)-lastv) + print int(v),interp + rs=rs+", %f" %(interp) + wc=wc+1 + if (v==0): + interp=lastt+(t-lastt)/(v-lastv)*(int(v)-lastv) + print int(v),interp + rs="{0" + wc=1 + + i=i+1 +print rs+"};" print wc \ No newline at end of file diff --git a/DS18B20_VOC/DS18B20_VOC.atsln b/DS18B20_VOC/DS18B20_VOC.atsln index 05272b9..710468e 100644 --- a/DS18B20_VOC/DS18B20_VOC.atsln +++ b/DS18B20_VOC/DS18B20_VOC.atsln @@ -1,22 +1,22 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Atmel Studio Solution File, Format Version 11.00 -VisualStudioVersion = 14.0.23107.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_VOC", "DS18B20_VOC.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|AVR = Debug|AVR - Release|AVR = Release|AVR - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Atmel Studio Solution File, Format Version 11.00 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_VOC", "DS18B20_VOC.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR + {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/DS18B20_VOC/DS18B20_VOC.c b/DS18B20_VOC/DS18B20_VOC.c index 3b14431..043f104 100644 --- a/DS18B20_VOC/DS18B20_VOC.c +++ b/DS18B20_VOC/DS18B20_VOC.c @@ -1,185 +1,185 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common//I2C/MAX1164x.h" - - -extern void OWINIT(); - -extern void EXTERN_SLEEP(); - - -uint8_t owid[8]={0x28, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x77, 0x6B};/**/ -uint8_t config_info[16]={0x01,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - -#if (owid>128) -#error "Variable not correct" -#endif - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; - - -uint8_t max_adr=0; - -typedef union { - volatile uint8_t bytes[8]; - struct { - uint16_t temp; //0 - uint8_t TH; //2 - uint8_t TL; //3 - uint8_t config; //4 - uint8_t rrFF; //5 - uint8_t rr00; //6 - uint8_t rr10; //7 - }; -} pack_t; -volatile pack_t pack; - -volatile uint8_t wdcounter; - -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) -ISR(WATCHDOG_vect) { -#else -ISR(WDT_vect) { -#endif - wdcounter++; - if (reset_indicator==1) reset_indicator++; - else if (reset_indicator==2) mode=0; -} - - - - -#define CH0_M MAX1164x_C_SCAN0|MAX1164x_C_SGL -#define CH1_M MAX1164x_C_SCAN0|MAX1164x_C_SGL|MAX1164x_C_CS0 -#define CH0_CH1 MAX1164x_C_SCAN0 - - - -int main(void){ - PRR|=(1< 1,5V - - gcontrol=1; - //DDRB|=(1<0) { - PORTB&=~(1<>4; - uint8_t af=0; - if (t8>pack.TH) af=1; - if (t8<=pack.TL) af=1; - cli(); - pack.temp=w; - //pack.temp++; - alarmflag=af; - sei(); - EXTERN_SLEEP(); - //PORTB&=~(1< +#include +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common//I2C/MAX1164x.h" + + +extern void OWINIT(); + +extern void EXTERN_SLEEP(); + + +uint8_t owid[8]={0x28, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x77, 0x6B};/**/ +uint8_t config_info[16]={0x01,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +#if (owid>128) +#error "Variable not correct" +#endif + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; + + +uint8_t max_adr=0; + +typedef union { + volatile uint8_t bytes[8]; + struct { + uint16_t temp; //0 + uint8_t TH; //2 + uint8_t TL; //3 + uint8_t config; //4 + uint8_t rrFF; //5 + uint8_t rr00; //6 + uint8_t rr10; //7 + }; +} pack_t; +volatile pack_t pack; + +volatile uint8_t wdcounter; + +#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) +ISR(WATCHDOG_vect) { +#else +ISR(WDT_vect) { +#endif + wdcounter++; + if (reset_indicator==1) reset_indicator++; + else if (reset_indicator==2) mode=0; +} + + + + +#define CH0_M MAX1164x_C_SCAN0|MAX1164x_C_SGL +#define CH1_M MAX1164x_C_SCAN0|MAX1164x_C_SGL|MAX1164x_C_CS0 +#define CH0_CH1 MAX1164x_C_SCAN0 + + + +int main(void){ + PRR|=(1< 1,5V + + gcontrol=1; + //DDRB|=(1<0) { + PORTB&=~(1<>4; + uint8_t af=0; + if (t8>pack.TH) af=1; + if (t8<=pack.TL) af=1; + cli(); + pack.temp=w; + //pack.temp++; + alarmflag=af; + sei(); + EXTERN_SLEEP(); + //PORTB&=~(1< - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.C - {7a5672fe-8226-4158-b931-e1f36b9a8858} - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS18B20_MAX44009 - DS18B20_VOC - DS18B20_MAX44009 - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800000789 - Atmel-ICE - - debugWIRE - - - - - - - - com.atmel.avrdbg.tool.simulator - - - Simulator - - - J41800000789 - 0x1E930C - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - OWDS18B20.S - - - compile - MAX1164x.c - - - compile - USI_TWI_Master.c - - - compile - - - + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + {7a5672fe-8226-4158-b931-e1f36b9a8858} + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS18B20_MAX44009 + DS18B20_VOC + DS18B20_MAX44009 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000789 + Atmel-ICE + + debugWIRE + + + + + + + + com.atmel.avrdbg.tool.simulator + + + Simulator + + + J41800000789 + 0x1E930C + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + OWDS18B20.S + + + compile + MAX1164x.c + + + compile + USI_TWI_Master.c + + + compile + + + \ No newline at end of file diff --git a/DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c b/DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c index 0e9ae0a..3e1aafc 100644 --- a/DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c +++ b/DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c @@ -1,381 +1,423 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/MAX1164x.h" -#include "../common/I2C/SHT2x.h" -#include "../common/calibr.h" - -extern void OWINIT(); -extern void EXTERN_SLEEP(); - - - -volatile uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/ -volatile uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/ -volatile uint8_t config_info1[16]={0x08,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; -volatile uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x07,0x08, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - -#if (owid>128) -#error "Variable not correct" -#endif - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; -volatile uint8_t wdcounter=1; - - -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) -ISR(WATCHDOG_vect) { -#else -ISR(WDT_vect) { -#endif - wdcounter++; - if (reset_indicator==1) reset_indicator++; - else if (reset_indicator==2) mode=0; - - -} - - -typedef union { - volatile uint8_t bytes[8]; - struct { - uint16_t temp; //0 - uint8_t TH; //2 - uint8_t TL; //3 - uint8_t config; //4 - uint8_t rrFF; //5 - uint8_t rr00; //6 - uint8_t rr10; //7 - }; -} pack1_t; -volatile pack1_t pack1; - - - -typedef union { - #if defined(__AVR_ATtiny25__) - volatile uint8_t bytes[16]; - #else - volatile uint8_t bytes[64]; - #endif - struct { - uint8_t status; //1 - int16_t temp; //2 - uint16_t voltage; //4 - int16_t current; //6 - uint8_t threshold; //8 - - uint8_t page1[8]; //9 - #if defined(__AVR_ATtiny25__) - #else - uint8_t page2[8]; //17 - uint8_t page3[8]; //25 - uint8_t page4[8]; //33 - uint8_t page5[8]; //41 - uint8_t page6[8]; //49 - uint8_t page7[8]; //57 - //uint8_t crc; //65 - #endif - }; -} pack2_t; -volatile pack2_t pack2; - - - - -volatile int16_t am2302_temp; -volatile uint16_t am2302_hum; - - -uint8_t userRegister[1]; -int16_t sRH,sT; -double temperatureC,humidityRH,hhum; -double l; - -uint8_t max_adr=0; -#define CH0_M MAX1164x_C_SCAN0|MAX1164x_C_SGL -#define CH1_M MAX1164x_C_SCAN0|MAX1164x_C_SGL|MAX1164x_C_CS0 -#define CH0_CH1 MAX1164x_C_SCAN0 -//|MAX1164x_C_CS0 - - -inline double interp(double t, double h) { - double h2; - double t2; - h2=h*h; - t2=t*t; - return 4.76111e-9*h2*t2-3.96956e-7*h2*t+0.0000408889*h2-1.07132e-6*h*t2+0.000115968*h*t-0.0101333*h+0.000163806*t2-0.0241179*t+1.80591; -} - -uint8_t cmode=0; -double R0=0; -int16_t hr; -uint8_t startup=5; -uint8_t reset_R0=0; -int16_t mr; -double ip; - -int main(void){ - //volatile double test=calibr_hum(20,1,20); - PRR|=(1<>8)&0xFF; - } - - - - WDTCSR |= ((1< 1,5V - gcontrol=1; - sei(); - //DDRB|=(1<>8)&0xFF; - - while(EECR & (1<>8; - EECR |= (1<0) { - if (startup!=0) startup--; - SHT2x_MeasurePoll(HUMIDITY, &sRH); - // --- measure temperature with "Polling Mode" (no hold master) --- - SHT2x_MeasurePoll(TEMP, &sT); - //-- calculate humidity and temperature -- - temperatureC = SHT2x_CalcTemperatureC(sT); - humidityRH = SHT2x_CalcRH(sRH); - ip=interp(temperatureC,humidityRH); - humidityRH=calibr_hum(temperatureC,-1,humidityRH)*10.0; - //humidityRH=humidityRH*10.0; - temperatureC =temperatureC *10.0-10; - hhum=(1.0546-0.000216*temperatureC)*(humidityRH); - am2302_hum=0.318*hhum +76.0; - am2302_temp=temperatureC*25.6; - //PORTB&=~(1<1.8) { - if (mr>7200) { - if (cmode==0) { - MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_CH1); - cmode=1; - pack2.page3[4]=cmode; - } - } - //if (l<1.6) { - if (mr<6400) { - if (cmode==1) { - MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M); - cmode=0; - pack2.page3[4]=cmode; - } - - - } - //hr=l*10000.0; - hr=mr*5/2; - pack2.page3[2]=hr&0xFF; - pack2.page3[3]=(hr>>8)&0xFF; - l=mr/4000.0; - l=( 3/l- 1) *30; - pack2.current=l*100; - //ip=interp(temperatureC,humidityRH); - hr=ip*1000; - pack2.page3[5]=hr&0xFF; - pack2.page3[6]=(hr>>8)&0xFF; - - l=l/ip; - - if (startup==0){ - if (l>R0) { - R0=l; - hr=R0*100; - pack2.page3[0]=hr&0xFF; - pack2.page3[1]=(hr>>8)&0xFF; - - while(EECR & (1<>8; - EECR |= (1<500) { - l=100; - } - wdcounter=0; - - } - - if (gcontrol==1) { - uint16_t w=l; - uint8_t t8=w>>4; - uint8_t af=0; - if (t8>pack1.TH) af=1; - if (t8<=pack1.TL) af=1; - cli(); - pack1.temp=w; - //pack.temp++; - alarmflag=af; - sei(); - EXTERN_SLEEP(); - } - if ((gcontrol==2)||(gcontrol==3)) { - gcontrol=0; - - } - - -#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - if (((TIMSK & (1< +#include +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common/I2C/MAX1164x.h" +#include "../common/I2C/SHT2x.h" +#include "../common/calibr.h" + +extern void OWINIT(void); +extern void EXTERN_SLEEP(void); + + + +volatile uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/ +volatile uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/ +volatile uint8_t config_info1[16]={0x08,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; +volatile uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x07,0x08, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +#if (owid>128) +#error "Variable not correct" +#endif + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; +volatile uint8_t wdcounter=1; + + +#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) +ISR(WATCHDOG_vect) { +#else +ISR(WDT_vect) { +#endif + wdcounter++; + if (reset_indicator==1) reset_indicator++; + else if (reset_indicator==2) mode=0; + + +} + + +typedef union { + volatile uint8_t bytes[8]; + struct { + uint16_t temp; //0 + uint8_t TH; //2 + uint8_t TL; //3 + uint8_t config; //4 + uint8_t rrFF; //5 + uint8_t rr00; //6 + uint8_t rr10; //7 + }; +} pack1_t; +volatile pack1_t pack1; + + + +typedef union { + #if defined(__AVR_ATtiny25__) + volatile uint8_t bytes[16]; + #else + volatile uint8_t bytes[64]; + #endif + struct { + uint8_t status; //1 + int16_t temp; //2 + uint16_t voltage; //4 + int16_t current; //6 + uint8_t threshold; //8 + + uint8_t page1[8]; //9 + #if defined(__AVR_ATtiny25__) + #else + uint8_t page2[8]; //17 + union{ + uint8_t page3[8]; //25 + struct { + uint16_t R0; + uint16_t VS; + uint8_t cmode; + int16_t ip; + uint8_t free; + }; + }; + union{ + uint8_t page4[8]; //33 + struct { + uint16_t tol_s8; + uint16_t tol_d; + uint16_t r_day_max; + uint16_t r_week_max; + }; + }; + uint8_t page5[8]; //41 + uint8_t page6[8]; //49 + uint8_t page7[8]; //57 + //uint8_t crc; //65 + #endif + }; +} pack2_t; +volatile pack2_t pack2; + + + + +volatile int16_t am2302_temp; +volatile uint16_t am2302_hum; + + +uint8_t userRegister[1]; +int16_t sRH,sT; +double temperatureC,humidityRH,hhum; +double l; + +uint8_t max_adr=0; +#define CH0_M MAX1164x_C_SCAN0|MAX1164x_C_SGL +#define CH1_M MAX1164x_C_SCAN0|MAX1164x_C_SGL|MAX1164x_C_CS0 +#define CH0_CH1 MAX1164x_C_SCAN0 +//|MAX1164x_C_CS0 + +uint16_t weekmaxarr[8]; + +inline double interp(double t, double h) { + double h2; + double t2; + h2=h*h; + t2=t*t; + return 4.76111e-9*h2*t2-3.96956e-7*h2*t+0.0000408889*h2-1.07132e-6*h*t2+0.000115968*h*t-0.0101333*h+0.000163806*t2-0.0241179*t+1.80591; +} + +double R0; +uint16_t mr; +uint8_t startup=10; +double ip; + +#define EEPROM_R0 0 +#define EEPROM_R0d 2 +#define EEPROM_R0w 4 +#define EEPROM_dol 6 + + +uint16_t readEEPROM(uint8_t addr,uint16_t def) { + uint16_t hr; + while(EECR & (1<>8; + EECR |= (1< 1,5V + gcontrol=1; + sei(); + //DDRB|=(1<0) { + pack2.tol_s8++; + if (pack2.tol_s8>(10000)) {//10800 ist theortisch der Tag aber meistens zu lang + pack2.tol_s8=0; + pack2.tol_d++; //rund 180 Jahre :-) + pack2.r_week_max=0; + weekmaxarr[7]=pack2.r_day_max; + for(uint8_t i=0;i<7;i++) { + weekmaxarr[i]=weekmaxarr[i+1]; + if (weekmaxarr[i]>pack2.r_week_max) pack2.r_week_max=weekmaxarr[i]; + } + if (pack2.tol_d>7) { + pack2.R0=pack2.r_week_max; + } else { + pack2.R0=pack2.r_day_max; + } + R0=pack2.R0/100.0-0.5*(pack2.R0/100-R0); + pack2.R0=R0*100; + writeEEPROM(EEPROM_R0,pack2.R0); + writeEEPROM(EEPROM_R0d,pack2.r_day_max); //Maximum des Tages + writeEEPROM(EEPROM_R0w,pack2.r_week_max); //Maximum der Letzten 7 Tage + writeEEPROM(EEPROM_dol,pack2.tol_d); //Anzahl der Betriebstage + pack2.r_day_max=0; + } + if (startup!=0) startup--; + SHT2x_MeasurePoll(HUMIDITY, &sRH); + // --- measure temperature with "Polling Mode" (no hold master) --- + SHT2x_MeasurePoll(TEMP, &sT); + //-- calculate humidity and temperature -- + temperatureC = SHT2x_CalcTemperatureC(sT); + humidityRH = SHT2x_CalcRH(sRH); + ip=interp(temperatureC,humidityRH); + pack2.ip=ip*1000; + humidityRH=calibr_hum(temperatureC,-0.45,humidityRH)*10.0; + //humidityRH=humidityRH*10.0; + temperatureC =temperatureC *10.0-4.5; + hhum=(1.0546-0.000216*temperatureC)*(humidityRH); + am2302_hum=0.318*hhum +76.0; + am2302_temp=temperatureC*25.6; + //PORTB&=~(1<1.8) { + if (mr>7200) { + if (pack2.cmode==0) { + MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_CH1); + pack2.cmode=1; + } + } + //if (l<1.6) { + if (mr<6400) { + if (pack2.cmode==1) { + MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M); + pack2.cmode=0; + } + + + } + //hr=l*10000.0; + pack2.VS=mr*5/2; + l=mr/4000.0; + l=( 3/l- 1) *30; + pack2.current=l*100; + + l=l/ip; + + if (startup==0){ + if (l>R0) { + R0=l; + pack2.R0=R0*100; + writeEEPROM(EEPROM_R0,pack2.R0); + + } + if (l*100>pack2.r_day_max) { + pack2.r_day_max=l*100; + } + } + l=l/R0; + l=log(1/l); + l=l*160*4; //fuer DS18B20 + // if (l>500) { + // l=100; + // } + wdcounter=0; + + } + + if (gcontrol==1) { + uint16_t w=l; + uint8_t t8=w>>4; + uint8_t af=0; + if (t8>pack1.TH) af=1; + if (t8<=pack1.TL) af=1; + cli(); + pack1.temp=w; + //pack.temp++; + alarmflag=af; + sei(); + EXTERN_SLEEP(); + } + if ((gcontrol==2)||(gcontrol==3)) { + gcontrol=0; + + } + + +#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) + if (((TIMSK & (1< - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.C - {7a5672fe-8226-4158-b931-e1f36b9a8858} - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS18B20_DS2438 - DS18B20_VOC_DS2438_SHT - DS18B20_DS2438 - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800000789 - Atmel-ICE - - debugWIRE - - - - - - - - com.atmel.avrdbg.tool.simulator - - - Simulator - - - J41800000789 - 0x1E930C - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - calibr.c - - - compile - SHT2x.c - - - compile - MAX1164x.c - - - compile - USI_TWI_Master.c - - - compile - OWDS18B20_DS2438.S - - - compile - - - + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + {7a5672fe-8226-4158-b931-e1f36b9a8858} + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS18B20_DS2438 + DS18B20_VOC_DS2438_SHT + DS18B20_DS2438 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000789 + Atmel-ICE + + debugWIRE + + + + + + + + com.atmel.avrdbg.tool.simulator + + + Simulator + + + J41800000789 + 0x1E930C + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + True + + + libm + + + Default (-Wa,-g) + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + calibr.c + + + compile + SHT2x.c + + + compile + MAX1164x.c + + + compile + USI_TWI_Master.c + + + compile + OWDS18B20_DS2438.S + + + compile + + + \ No newline at end of file diff --git a/DS18B20_VOC_DS2438_SHT/MAX1164x.h b/DS18B20_VOC_DS2438_SHT/MAX1164x.h deleted file mode 100644 index cf8977c..0000000 --- a/DS18B20_VOC_DS2438_SHT/MAX1164x.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MAX1164x_H -#define MAX1164x_H -#define MAX1164x_S_SEL2 0x40 -#define MAX1164x_S_SEL1 0x20 -#define MAX1164x_S_SEL0 0x10 -#define MAX1164x_S_ECLK 0x08 -#define MAX1164x_S_BIP 0x04 -#define MAX1164_S_RESET 0x02 - -#define MAX1164x_C_SCAN1 0x40 -#define MAX1164x_C_SCAN0 0x20 -#define MAX1164x_C_CS0 0x02 -#define MAX1164x_C_SGL 0x01 - - - -void MAX1164x_init(); -void MAX1164x_config(uint8_t setup,uint8_t config); -int16_t MAX1164x_read(); - - -#endif \ No newline at end of file diff --git a/DS2406/DS2406.atsln b/DS2406/DS2406.atsln index 2256c96..aec3ee8 100644 --- a/DS2406/DS2406.atsln +++ b/DS2406/DS2406.atsln @@ -1,20 +1,20 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Atmel Studio Solution File, Format Version 11.00 -Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2406", "DS2406.cproj", "{26106A5A-6618-4774-943F-65C46DDB610B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|AVR = Debug|AVR - Release|AVR = Release|AVR - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.ActiveCfg = Debug|AVR - {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.Build.0 = Debug|AVR - {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.ActiveCfg = Release|AVR - {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.Build.0 = Release|AVR - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Atmel Studio Solution File, Format Version 11.00 +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2406", "DS2406.cproj", "{26106A5A-6618-4774-943F-65C46DDB610B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.ActiveCfg = Debug|AVR + {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.Build.0 = Debug|AVR + {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.ActiveCfg = Release|AVR + {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/DS2406/DS2406.c b/DS2406/DS2406.c index 5332d97..e6826c4 100644 --- a/DS2406/DS2406.c +++ b/DS2406/DS2406.c @@ -1,118 +1,118 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -#define F_CPU 8000000UL -#include -#include -#include -#include -#include - - -extern void OWINIT(); - -uint8_t owid[8]={0x12, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x1E};/**/ - - - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; - - - -typedef union { - volatile uint8_t bytes[1]; - struct { - uint8_t status; - }; -} pack_t; -pack_t pack; - - - - -int main(void){ - PRR|=(1< +#include +#include +#include +#include + + +extern void OWINIT(); + +uint8_t owid[8]={0x12, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x1E};/**/ + + + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; + + + +typedef union { + volatile uint8_t bytes[1]; + struct { + uint8_t status; + }; +} pack_t; +pack_t pack; + + + + +int main(void){ + PRR|=(1< - - - 2.0 - 6.2 - com.Atmel.AVRGCC8.C - {26106a5a-6618-4774-943f-65c46ddb610b} - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS2406 - DS2406 - DS2406 - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800024445 - Atmel-ICE - - debugWIRE - - - - - True - True - True - True - False - True - True - - - NDEBUG - - - Optimize for size (-Os) - True - True - True - - - libm - - - - - - - - - True - True - True - True - False - True - True - - - DEBUG - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - - - compile - - - + + + + 2.0 + 6.2 + com.Atmel.AVRGCC8.C + {26106a5a-6618-4774-943f-65c46ddb610b} + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS2406 + DS2406 + DS2406 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800024445 + Atmel-ICE + + debugWIRE + + + + + True + True + True + True + False + True + True + + + NDEBUG + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + + + + + True + True + True + True + False + True + True + + + DEBUG + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + + + compile + + + \ No newline at end of file diff --git a/DS2406/OWDS2406.S b/DS2406/OWDS2406.S index 76addbf..5e80148 100644 --- a/DS2406/OWDS2406.S +++ b/DS2406/OWDS2406.S @@ -1,320 +1,320 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define _CHANGEABLE_ID_ -#include "../common/OWConfig.s" -#include "../common/OWCRC16.s" - -.extern pack,45 -.extern counters,8 - -.macro CHIP_INIT -.endm - -.macro COMMAND_TABLE - rjmp h_channelaccess -.endm - -#include "../common/OWRomFunctions.s" -#include "../common/OWTimerInterrupt.s" - - - -; Ab hier Geraeteabhaenging -#define OW_CHANNEL_ACCESS OW_FIRST_COMMAND+0 - -;--------------------------------------------------- -; READ COMMAND and start operation -;--------------------------------------------------- - - -h_readcommand: - clr r_bytep -#ifndef _DIS_FLASH_ - FLASH_COMMANDS ; muss zu erst sein.... -#endif - cset 0x0F,OW_WRITE_SCRATCHPAD - cjmp 0xAA,hrc_set_readscratchpad - cset 0x5A,OW_COPY_SCRATCHPAD - cset 0xF0,OW_READ_MEMORY_ADDR - cset 0xA5,OW_READ_MEMORYCOUNTER_ADDR -#ifdef _CHANGEABLE_ID_ - CHANGE_ID_COMMANDS -#endif - ldi r_mode,OW_SLEEP - rjmp handle_end - -hrc_set_readscratchpad: - ldi r_mode,OW_READ_SCRATCHPAD - ldi r_sendflag,1 - rjmp h_readscratchpad - -h_writescratchpad: - configZ pack,r_bytep - inc r_bytep - st Z,r_rwbyte - cpi r_bytep,2 - breq h_writescratchpad_block - brsh h_writescratchpad_set_eoffset ;;33 - rjmp handle_end ;handle_end zu weit entfernt fuer br... -h_writescratchpad_set_eoffset: - cpi r_bytep,35 - breq h_writescratchpad_setcrc - mov r_temp,r_bytep - subi r_temp,4 - sts pack+2,r_temp ;AA und PF cleared - rjmp handle_end -;Start writeing to 32 Byte Block ; skip status byte -h_writescratchpad_block: - lds r_temp,pack ; Adresse low byte - andi r_temp,0x1F ;32 byte - add r_bytep,r_temp ;Zur angegebenen Startadresse springen - ;ori r_temp,0x20 ; Set PF flag - sts pack+2,r_temp ;E4:E0 vorher setzen - ; Byte 3 ueberspringen - rjmp handle_end_inc - -h_writescratchpad_setcrc: - ;copy crc to pack - lds r_temp,crc - com r_temp - sts pack+43,r_temp - lds r_temp,crc+1 - com r_temp ; invertieren , komischer name..... - sts pack+44,r_temp - ldi r_mode,OW_WRITE_SCRATCHPAD_CRC - ldi r_sendflag,1 - ldi r_bytep,43 -h_writescratchpad_crc: - cpi r_bytep,45 - breq h_writescratchpad_crc_end - configZ pack,r_bytep - ld r_rwbyte,Z - rjmp handle_end_inc -h_writescratchpad_crc_end: - rjmp handle_end_sleep - - -h_readscratchpad: - cpi r_bytep,35 - breq h_readscratchpad_end - cpi r_bytep,3 - brne h_readscratchpad_read_byte -h_readscratchpad_set_offset: - lds r_temp,pack - andi r_temp,0x1F - ldi r_temp2,3 - add r_temp,r_temp2 - mov r_bytep,r_temp -h_readscratchpad_read_byte: - configZ pack,r_bytep - ld r_rwbyte,Z - rjmp handle_end_inc -h_readscratchpad_end: - rjmp handle_end_sleep - - - -h_copyscratchpad: - cpi r_bytep,3 - brsh h_copyscratchpad_ok - configZ pack,r_bytep - inc r_bytep - ld r_temp,Z - cp r_temp,r_rwbyte - brne h_copyscratchpad_nok - cpi r_bytep,3 - breq h_copyscratchpad_ok - ldi r_bcount,1 - rjmp handle_end -h_copyscratchpad_ok: - ldi r_rwbyte,0xAA - ldi r_sendflag,1 - rjmp handle_end -h_copyscratchpad_nok: - lds r_temp,pack+3 - andi r_temp,~0x80 - sts pack+3,r_temp - rjmp handle_end_sleep - - -h_readmemory_addr: - cpi r_bytep,0 - brne h_readmrmory_addr_byte1 - sts pack,r_rwbyte - rjmp handle_end_inc -h_readmrmory_addr_byte1: - sts pack+1,r_rwbyte - ldi r_mode,OW_READ_MEMORY - ldi r_sendflag,1 - clr r_bytep - rjmp h_readmemory2 -h_readmemory: - lds r_bytep,pack - lds r_temp2,pack+1 - inc r_bytep - clr r_temp - adc r_temp2,r_temp - sbrc r_temp2,1 - rjmp h_readmemory_end - sts pack+1,r_temp - sts pack,r_bytep -h_readmemory2: - lds r_bytep,pack - andi r_bytep,0x1F - configZ pack+3,r_bytep - ld r_rwbyte,Z - rjmp handle_end -h_readmemory_end: - rjmp handle_end_sleep - - - - - - - - -h_readmemorycounter_addr: - cpi r_bytep,0 - brne h_readmrmorycounter_addr_byte1 - sts pack,r_rwbyte - inc r_bytep - ;ldi r_bcount,1 - rjmp handle_end -h_readmrmorycounter_addr_byte1: - sts pack+1,r_rwbyte - ldi r_mode,OW_READ_MEMORYCOUNTER - ;ldi r_bcount,1 - ldi r_sendflag,1 - clr r_bytep - rjmp h_readmemorycounter2 -h_readmemorycounter: - lds r_bytep,pack - lds r_temp2,pack+1 - ldi r_temp,1 ;inc leider kein c flag - add r_bytep,r_temp - clr r_temp - adc r_temp2,r_temp - mov r_temp,r_bytep - andi r_temp,0x1F - breq h_readmemorycounter_next - sts pack+1,r_temp2 - sts pack,r_bytep -h_readmemorycounter2: ;Lesen von dem worauf die erstenzwei bytes zeigen - lds r_bytep,pack - andi r_bytep,0x1F - configZ pack+3,r_bytep - ld r_rwbyte,Z - ;ldi r_bcount,1 - rjmp handle_end -//h_readmemorycounter_end: -// ldi r_mode,OW_SLEEP -// clr r_sendflag -// rjmp handle_end -h_readmemorycounter_next: ; rest lesen - ldi r_mode,OW_READ_MEMORYCOUNTER_EX - ldi r_bytep,34 - lds r_temp2,pack - lds r_temp,pack+1 - //lsr r_temp - //ror r_temp2 - - lsl r_temp2 - rol r_temp - cpi r_temp,3 - brne h_readmemorycounter_cFF - andi r_temp2,0xC0 - swap r_temp2 - - ;cpi r_temp,0xE0 - - configZ counters,r_temp2 - ld r_temp,Z+ - sts pack+35,r_temp - ld r_temp,Z+ - sts pack+36,r_temp - ld r_temp,Z+ - sts pack+37,r_temp - ld r_temp,Z+ - sts pack+38,r_temp - rjmp h_readmemorycounter_ex -h_readmemorycounter_cFF: - ldi r_temp,0xFF - sts pack+35,r_temp - sts pack+36,r_temp - sts pack+37,r_temp - sts pack+38,r_temp - -h_readmemorycounter_ex: - inc r_bytep - cpi r_bytep,45 - breq h_readmemorycounter_ex_end - cpi r_bytep,43 - brne h_readmemorycounter_ex2 - lds r_temp,crc - com r_temp - sts pack+43,r_temp - lds r_temp,crc+1 - com r_temp - sts pack+44,r_temp -h_readmemorycounter_ex2: - ;ldi r_bcount,1 - configZ pack,r_bytep - ld r_rwbyte,Z - rjmp handle_end -h_readmemorycounter_ex_end: - lds r_bytep,pack - lds r_temp2,pack+1 - ldi r_temp,1 ;inc leider kein c flag - add r_bytep,r_temp - clr r_temp - adc r_temp2,r_temp - sbrc r_temp2,1 ;am ene von allem - rjmp h_readmemorycounter_ex_sleep - CRCInit1 - ldi r_mode,OW_READ_MEMORYCOUNTER - sts pack+1,r_temp2 - sts pack,r_bytep - rjmp h_readmemorycounter2 -h_readmemorycounter_ex_sleep: - ldi r_mode,OW_SLEEP - clr r_sendflag - rjmp handle_end - - - - - -#include "../common/OWPinInterrupt.s" + +// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the +// distribution. +// * All advertising materials mentioning features or use of this +// software must display the following acknowledgement: This product +// includes software developed by tm3d.de and its contributors. +// * Neither the name of tm3d.de nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#define _CHANGEABLE_ID_ +#include "../common/OWConfig.s" +#include "../common/OWCRC16.s" + +.extern pack,45 +.extern counters,8 + +.macro CHIP_INIT +.endm + +.macro COMMAND_TABLE + rjmp h_channelaccess +.endm + +#include "../common/OWRomFunctions.s" +#include "../common/OWTimerInterrupt.s" + + + +; Ab hier Geraeteabhaenging +#define OW_CHANNEL_ACCESS OW_FIRST_COMMAND+0 + +;--------------------------------------------------- +; READ COMMAND and start operation +;--------------------------------------------------- + + +h_readcommand: + clr r_bytep +#ifndef _DIS_FLASH_ + FLASH_COMMANDS ; muss zu erst sein.... +#endif + cset 0x0F,OW_WRITE_SCRATCHPAD + cjmp 0xAA,hrc_set_readscratchpad + cset 0x5A,OW_COPY_SCRATCHPAD + cset 0xF0,OW_READ_MEMORY_ADDR + cset 0xA5,OW_READ_MEMORYCOUNTER_ADDR +#ifdef _CHANGEABLE_ID_ + CHANGE_ID_COMMANDS +#endif + ldi r_mode,OW_SLEEP + rjmp handle_end + +hrc_set_readscratchpad: + ldi r_mode,OW_READ_SCRATCHPAD + ldi r_sendflag,1 + rjmp h_readscratchpad + +h_writescratchpad: + configZ pack,r_bytep + inc r_bytep + st Z,r_rwbyte + cpi r_bytep,2 + breq h_writescratchpad_block + brsh h_writescratchpad_set_eoffset ;;33 + rjmp handle_end ;handle_end zu weit entfernt fuer br... +h_writescratchpad_set_eoffset: + cpi r_bytep,35 + breq h_writescratchpad_setcrc + mov r_temp,r_bytep + subi r_temp,4 + sts pack+2,r_temp ;AA und PF cleared + rjmp handle_end +;Start writeing to 32 Byte Block ; skip status byte +h_writescratchpad_block: + lds r_temp,pack ; Adresse low byte + andi r_temp,0x1F ;32 byte + add r_bytep,r_temp ;Zur angegebenen Startadresse springen + ;ori r_temp,0x20 ; Set PF flag + sts pack+2,r_temp ;E4:E0 vorher setzen + ; Byte 3 ueberspringen + rjmp handle_end_inc + +h_writescratchpad_setcrc: + ;copy crc to pack + lds r_temp,crc + com r_temp + sts pack+43,r_temp + lds r_temp,crc+1 + com r_temp ; invertieren , komischer name..... + sts pack+44,r_temp + ldi r_mode,OW_WRITE_SCRATCHPAD_CRC + ldi r_sendflag,1 + ldi r_bytep,43 +h_writescratchpad_crc: + cpi r_bytep,45 + breq h_writescratchpad_crc_end + configZ pack,r_bytep + ld r_rwbyte,Z + rjmp handle_end_inc +h_writescratchpad_crc_end: + rjmp handle_end_sleep + + +h_readscratchpad: + cpi r_bytep,35 + breq h_readscratchpad_end + cpi r_bytep,3 + brne h_readscratchpad_read_byte +h_readscratchpad_set_offset: + lds r_temp,pack + andi r_temp,0x1F + ldi r_temp2,3 + add r_temp,r_temp2 + mov r_bytep,r_temp +h_readscratchpad_read_byte: + configZ pack,r_bytep + ld r_rwbyte,Z + rjmp handle_end_inc +h_readscratchpad_end: + rjmp handle_end_sleep + + + +h_copyscratchpad: + cpi r_bytep,3 + brsh h_copyscratchpad_ok + configZ pack,r_bytep + inc r_bytep + ld r_temp,Z + cp r_temp,r_rwbyte + brne h_copyscratchpad_nok + cpi r_bytep,3 + breq h_copyscratchpad_ok + ldi r_bcount,1 + rjmp handle_end +h_copyscratchpad_ok: + ldi r_rwbyte,0xAA + ldi r_sendflag,1 + rjmp handle_end +h_copyscratchpad_nok: + lds r_temp,pack+3 + andi r_temp,~0x80 + sts pack+3,r_temp + rjmp handle_end_sleep + + +h_readmemory_addr: + cpi r_bytep,0 + brne h_readmrmory_addr_byte1 + sts pack,r_rwbyte + rjmp handle_end_inc +h_readmrmory_addr_byte1: + sts pack+1,r_rwbyte + ldi r_mode,OW_READ_MEMORY + ldi r_sendflag,1 + clr r_bytep + rjmp h_readmemory2 +h_readmemory: + lds r_bytep,pack + lds r_temp2,pack+1 + inc r_bytep + clr r_temp + adc r_temp2,r_temp + sbrc r_temp2,1 + rjmp h_readmemory_end + sts pack+1,r_temp + sts pack,r_bytep +h_readmemory2: + lds r_bytep,pack + andi r_bytep,0x1F + configZ pack+3,r_bytep + ld r_rwbyte,Z + rjmp handle_end +h_readmemory_end: + rjmp handle_end_sleep + + + + + + + + +h_readmemorycounter_addr: + cpi r_bytep,0 + brne h_readmrmorycounter_addr_byte1 + sts pack,r_rwbyte + inc r_bytep + ;ldi r_bcount,1 + rjmp handle_end +h_readmrmorycounter_addr_byte1: + sts pack+1,r_rwbyte + ldi r_mode,OW_READ_MEMORYCOUNTER + ;ldi r_bcount,1 + ldi r_sendflag,1 + clr r_bytep + rjmp h_readmemorycounter2 +h_readmemorycounter: + lds r_bytep,pack + lds r_temp2,pack+1 + ldi r_temp,1 ;inc leider kein c flag + add r_bytep,r_temp + clr r_temp + adc r_temp2,r_temp + mov r_temp,r_bytep + andi r_temp,0x1F + breq h_readmemorycounter_next + sts pack+1,r_temp2 + sts pack,r_bytep +h_readmemorycounter2: ;Lesen von dem worauf die erstenzwei bytes zeigen + lds r_bytep,pack + andi r_bytep,0x1F + configZ pack+3,r_bytep + ld r_rwbyte,Z + ;ldi r_bcount,1 + rjmp handle_end +//h_readmemorycounter_end: +// ldi r_mode,OW_SLEEP +// clr r_sendflag +// rjmp handle_end +h_readmemorycounter_next: ; rest lesen + ldi r_mode,OW_READ_MEMORYCOUNTER_EX + ldi r_bytep,34 + lds r_temp2,pack + lds r_temp,pack+1 + //lsr r_temp + //ror r_temp2 + + lsl r_temp2 + rol r_temp + cpi r_temp,3 + brne h_readmemorycounter_cFF + andi r_temp2,0xC0 + swap r_temp2 + + ;cpi r_temp,0xE0 + + configZ counters,r_temp2 + ld r_temp,Z+ + sts pack+35,r_temp + ld r_temp,Z+ + sts pack+36,r_temp + ld r_temp,Z+ + sts pack+37,r_temp + ld r_temp,Z+ + sts pack+38,r_temp + rjmp h_readmemorycounter_ex +h_readmemorycounter_cFF: + ldi r_temp,0xFF + sts pack+35,r_temp + sts pack+36,r_temp + sts pack+37,r_temp + sts pack+38,r_temp + +h_readmemorycounter_ex: + inc r_bytep + cpi r_bytep,45 + breq h_readmemorycounter_ex_end + cpi r_bytep,43 + brne h_readmemorycounter_ex2 + lds r_temp,crc + com r_temp + sts pack+43,r_temp + lds r_temp,crc+1 + com r_temp + sts pack+44,r_temp +h_readmemorycounter_ex2: + ;ldi r_bcount,1 + configZ pack,r_bytep + ld r_rwbyte,Z + rjmp handle_end +h_readmemorycounter_ex_end: + lds r_bytep,pack + lds r_temp2,pack+1 + ldi r_temp,1 ;inc leider kein c flag + add r_bytep,r_temp + clr r_temp + adc r_temp2,r_temp + sbrc r_temp2,1 ;am ene von allem + rjmp h_readmemorycounter_ex_sleep + CRCInit1 + ldi r_mode,OW_READ_MEMORYCOUNTER + sts pack+1,r_temp2 + sts pack,r_bytep + rjmp h_readmemorycounter2 +h_readmemorycounter_ex_sleep: + ldi r_mode,OW_SLEEP + clr r_sendflag + rjmp handle_end + + + + + +#include "../common/OWPinInterrupt.s" .end \ No newline at end of file diff --git a/DS2423/DS2423.c b/DS2423/DS2423.c index 89b07db..c545126 100644 --- a/DS2423/DS2423.c +++ b/DS2423/DS2423.c @@ -1,267 +1,267 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define _4_COUNTERS_ -//#define _EEPROM_SAVE_ -#define _CPULLUP_ - -#define F_CPU 8000000UL -#include -#include -#include -#include -#include - - -#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - -#if defined(_4_COUNTERS_)&&defined(_EEPROM_SAVE_) -#error on ATtinyX5 you can not enable four counters and EEPROM save -#endif -#endif - - -extern void OWINIT(); - -uint8_t owid[8]={0x1D, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x5C};/**/ -uint8_t config_info[16]={0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - - - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; - - -volatile uint8_t wdcounter; - - - - -typedef union { - volatile uint8_t bytes[45]; - struct { - uint16_t addr; - uint8_t status; - uint8_t scratch[32];//3 - uint32_t counter; //35 - uint32_t zero; //39 - uint16_t crc; //43 - }; -} counterpack_t; -counterpack_t pack; - -volatile uint8_t lastcps; -typedef union { - uint32_t c32[4]; - uint8_t c8[16]; -} counters_t; - -volatile counters_t counters; - -volatile uint8_t istat; - -#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) -#define PCINT_VECTOR PCINT0_vect -#define PIN_REG PINB -#define PIN_DDR DDRB -#define PIN_CH2 (1< +#include +#include +#include +#include + + +#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) + +#if defined(_4_COUNTERS_)&&defined(_EEPROM_SAVE_) +#error on ATtinyX5 you can not enable four counters and EEPROM save +#endif +#endif + + +extern void OWINIT(); + +uint8_t owid[8]={0x1D, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x5C};/**/ +uint8_t config_info[16]={0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + + + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; + + +volatile uint8_t wdcounter; + + + + +typedef union { + volatile uint8_t bytes[45]; + struct { + uint16_t addr; + uint8_t status; + uint8_t scratch[32];//3 + uint32_t counter; //35 + uint32_t zero; //39 + uint16_t crc; //43 + }; +} counterpack_t; +counterpack_t pack; + +volatile uint8_t lastcps; +typedef union { + uint32_t c32[4]; + uint8_t c8[16]; +} counters_t; + +volatile counters_t counters; + +volatile uint8_t istat; + +#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) +#define PCINT_VECTOR PCINT0_vect +#define PIN_REG PINB +#define PIN_DDR DDRB +#define PIN_CH2 (1< - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.C - {26106a5a-6618-4774-943f-65c46ddb610b} - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS2423 - DS2423 - DS2423 - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800024445 - Atmel-ICE - - debugWIRE - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - OWDS2423.S - - - compile - - - + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + {26106a5a-6618-4774-943f-65c46ddb610b} + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS2423 + DS2423 + DS2423 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800024445 + Atmel-ICE + + debugWIRE + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + OWDS2423.S + + + compile + + + \ No newline at end of file diff --git a/DS2423_BMP280/DS2423_BMP280.atsln b/DS2423_BMP280/DS2423_BMP280.atsln index 3b8bc1f..9946f3c 100644 --- a/DS2423_BMP280/DS2423_BMP280.atsln +++ b/DS2423_BMP280/DS2423_BMP280.atsln @@ -1,20 +1,20 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Atmel Studio Solution File, Format Version 11.00 -Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2423_BMP280", "DS2423_BMP280.cproj", "{26106A5A-6618-4774-943F-65C46DDB610B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|AVR = Debug|AVR - Release|AVR = Release|AVR - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.ActiveCfg = Debug|AVR - {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.Build.0 = Debug|AVR - {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.ActiveCfg = Release|AVR - {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.Build.0 = Release|AVR - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Atmel Studio Solution File, Format Version 11.00 +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2423_BMP280", "DS2423_BMP280.cproj", "{26106A5A-6618-4774-943F-65C46DDB610B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.ActiveCfg = Debug|AVR + {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.Build.0 = Debug|AVR + {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.ActiveCfg = Release|AVR + {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/DS2423_BMP280/DS2423_BMP280.c b/DS2423_BMP280/DS2423_BMP280.c index 8ec5432..8f0596e 100644 --- a/DS2423_BMP280/DS2423_BMP280.c +++ b/DS2423_BMP280/DS2423_BMP280.c @@ -1,164 +1,164 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define _4_COUNTERS_ -#define _EEPROM_SAVE_ -//#define _CPULLUP_ - -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/BMP280.h" - - - -extern void OWINIT(); -extern void EXTERN_SLEEP(); - -uint8_t owid[8]={0x1D, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x5C};/**/ -uint8_t config_info[16]={0x09,0x0D,0x09,0x0D,0x01,0x08,0x02,0x08,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - - - -extern volatile uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; - - -volatile uint8_t wdcounter; - -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) -ISR(WATCHDOG_vect) { -#else -ISR(WDT_vect) { -#endif - wdcounter++; - //if (reset_indicator==1) reset_indicator++; - //else if (reset_indicator==2) mode=0; -} - - -typedef union { - volatile uint8_t bytes[45]; - struct { - uint16_t addr; - uint8_t status; - uint8_t scratch[32];//3 - uint32_t counter; //35 - uint32_t zero; //39 - uint16_t crc; //43 - }; -} counterpack_t; -counterpack_t pack; - -volatile uint8_t lastcps; -typedef union { - uint32_t c32[4]; - uint8_t c8[16]; -} counters_t; - -volatile counters_t counters; - -volatile uint8_t istat; - - -volatile uint8_t wdcounter; - -int main(void){ - PRR|=(1<2) { - bmp280ConvertInt(&t,&P,1); - while (mode!=0) ; - cli(); - counters.c32[3]=P; - counters.c32[2]=t; - sei(); - - wdcounter=0; - } - - if (((TIMSK0 & (1< +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common/I2C/BMP280.h" + + + +extern void OWINIT(); +extern void EXTERN_SLEEP(); + +uint8_t owid[8]={0x1D, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x5C};/**/ +uint8_t config_info[16]={0x09,0x0D,0x09,0x0D,0x01,0x08,0x02,0x08,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + + + +extern volatile uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; + + +volatile uint8_t wdcounter; + +#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) +ISR(WATCHDOG_vect) { +#else +ISR(WDT_vect) { +#endif + wdcounter++; + //if (reset_indicator==1) reset_indicator++; + //else if (reset_indicator==2) mode=0; +} + + +typedef union { + volatile uint8_t bytes[45]; + struct { + uint16_t addr; + uint8_t status; + uint8_t scratch[32];//3 + uint32_t counter; //35 + uint32_t zero; //39 + uint16_t crc; //43 + }; +} counterpack_t; +counterpack_t pack; + +volatile uint8_t lastcps; +typedef union { + uint32_t c32[4]; + uint8_t c8[16]; +} counters_t; + +volatile counters_t counters; + +volatile uint8_t istat; + + +volatile uint8_t wdcounter; + +int main(void){ + PRR|=(1<2) { + bmp280ConvertInt(&t,&P,1); + while (mode!=0) ; + cli(); + counters.c32[3]=P; + counters.c32[2]=t; + sei(); + + wdcounter=0; + } + + if (((TIMSK0 & (1< - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.C - {26106a5a-6618-4774-943f-65c46ddb610b} - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS2423_BMP280 - DS2423_BMP280 - DS2423_BMP280 - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800024445 - Atmel-ICE - - debugWIRE - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - BMP280.c - - - compile - USI_TWI_Master.c - - - compile - OWDS2423.S - - - compile - - - + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + {26106a5a-6618-4774-943f-65c46ddb610b} + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS2423_BMP280 + DS2423_BMP280 + DS2423_BMP280 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800024445 + Atmel-ICE + + debugWIRE + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + BMP280.c + + + compile + USI_TWI_Master.c + + + compile + OWDS2423.S + + + compile + + + \ No newline at end of file diff --git a/DS2438_DHT22/.gitignore b/DS2438_DHT22/.gitignore index 6142108..68af380 100644 --- a/DS2438_DHT22/.gitignore +++ b/DS2438_DHT22/.gitignore @@ -1,3 +1,3 @@ -/Debug/ -/Release/ -*.atsuo +/Debug/ +/Release/ +*.atsuo diff --git a/DS2438_DHT22/DS2438_DHT22 - Kopie.c b/DS2438_DHT22/DS2438_DHT22 - Kopie.c index bbd175c..769482e 100644 --- a/DS2438_DHT22/DS2438_DHT22 - Kopie.c +++ b/DS2438_DHT22/DS2438_DHT22 - Kopie.c @@ -1,444 +1,444 @@ -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -#define F_CPU 8000000UL -#define FP_CALC -#include -#include -#include -#include -#include - -extern void OWINIT(); - - -uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0xDD, 0xDD, 0x05, 0xCE};/**/ -uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; - -volatile uint8_t wdcounter; - - -typedef union { -#if defined(__AVR_ATtiny25__) - volatile uint8_t bytes[16]; -#else - volatile uint8_t bytes[64]; -#endif - struct { - uint8_t status; //1 - int16_t temp; //2 - uint16_t voltage; //4 - uint16_t current; //6 - uint8_t threshold; //8 - - uint8_t page1[8]; //9 -#if defined(__AVR_ATtiny25__) -#else - uint8_t page2[8]; //17 - uint8_t page3[8]; //25 - uint8_t page4[8]; //33 - uint8_t page5[8]; //41 - uint8_t page6[8]; //49 - uint8_t page7[8]; //57 - //uint8_t crc; //65 -#endif - }; -} pack_t; -volatile pack_t pack; - -#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - -#define DDR_SENSOR DDRB -#define PORT_SENSOR PORTB -#define PIN_SENSOR PINB -#define SENSOR PB4 -#endif - -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) -#define DDR_SENSOR DDRA -#define PORT_SENSOR PORTA -#define PIN_SENSOR PINA -#define SENSOR PINA2 -#endif - - - -#define SENSOR_sda_out DDR_SENSOR |= (1 << SENSOR) -#define SENSOR_sda_in DDR_SENSOR &= ~(1 << SENSOR);PORT_SENSOR |= (1 << SENSOR) // release sda => hi in consequence of pullup -#define SENSOR_sda_low PORT_SENSOR &= ~(1 << SENSOR) -#define SENSOR_is_hi PIN_SENSOR & (1 << SENSOR) -#define SENSOR_is_low !(PIN_SENSOR & (1 << SENSOR)) - -volatile int16_t am2302_temp; -volatile uint16_t am2302_hum; - - -uint8_t am_wait(uint8_t _time,uint8_t _signal){ - TCNT1=0; - while(TCNT1==0); - if (_signal) - while((SENSOR_is_hi)&&(TCNT1<_time)) {} - else - while((SENSOR_is_low)&&(TCNT1<_time)) {} - - if (TCNT1>=_time) {return 1;} - return 0; -} - -volatile uint8_t am2302_mode=0; -volatile uint8_t timeout=0; - - - -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) -ISR(WATCHDOG_vect) { -#else -ISR(WDT_vect) { -#endif - sleep_disable(); // Disable Sleep on Wakeup - am2302_mode++; - if (reset_indicator==1) reset_indicator++; - else if (reset_indicator==2) mode=0; -/* if (timeout==2) { - DIS_TIMER; - EN_OWINT; - mode=OWM_SLEEP; - } - timeout++;*/ - sleep_enable(); // Enable Sleep Mode - -} - -int testSW() { - uint8_t r; - DDRB&=~(1< bit=1 else bit=0 - sensor_byte |= 1; - if (am_wait(45,1)) return 6;// 30us - 75us = 45us - } - } - sensor_data[i] = sensor_byte; - } - - // checksum - if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4]) - { - // debug output - //printf("%b %b %b %b %b %b" CR, sensor_data[0], sensor_data[1], sensor_data[2], sensor_data[3], sensor_data[4], ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff )); - PORTB&=~(1< bit=1 else bit=0 - sensor_byte |= 1; - if (am_wait(45,1)) return 6;// 30us - 75us = 45us - } - } - sensor_data[i] = sensor_byte; - } - - // checksum - if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4]) - { - // debug output - //printf("%b %b %b %b %b %b" CR, sensor_data[0], sensor_data[1], sensor_data[2], sensor_data[3], sensor_data[4], ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff )); - PORTB&=~(1<31) pn=1; -#endif - } - SENSOFF - am2302_mode=3; - } - if (am2302_mode>=8) { - am2302_mode=0; - SENSON - } -#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - if (((TIMSK & (1< +#include +#include +#include +#include + +extern void OWINIT(); + + +uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0xDD, 0xDD, 0x05, 0xCE};/**/ +uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; + +volatile uint8_t wdcounter; + + +typedef union { +#if defined(__AVR_ATtiny25__) + volatile uint8_t bytes[16]; +#else + volatile uint8_t bytes[64]; +#endif + struct { + uint8_t status; //1 + int16_t temp; //2 + uint16_t voltage; //4 + uint16_t current; //6 + uint8_t threshold; //8 + + uint8_t page1[8]; //9 +#if defined(__AVR_ATtiny25__) +#else + uint8_t page2[8]; //17 + uint8_t page3[8]; //25 + uint8_t page4[8]; //33 + uint8_t page5[8]; //41 + uint8_t page6[8]; //49 + uint8_t page7[8]; //57 + //uint8_t crc; //65 +#endif + }; +} pack_t; +volatile pack_t pack; + +#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) + +#define DDR_SENSOR DDRB +#define PORT_SENSOR PORTB +#define PIN_SENSOR PINB +#define SENSOR PB4 +#endif + +#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) +#define DDR_SENSOR DDRA +#define PORT_SENSOR PORTA +#define PIN_SENSOR PINA +#define SENSOR PINA2 +#endif + + + +#define SENSOR_sda_out DDR_SENSOR |= (1 << SENSOR) +#define SENSOR_sda_in DDR_SENSOR &= ~(1 << SENSOR);PORT_SENSOR |= (1 << SENSOR) // release sda => hi in consequence of pullup +#define SENSOR_sda_low PORT_SENSOR &= ~(1 << SENSOR) +#define SENSOR_is_hi PIN_SENSOR & (1 << SENSOR) +#define SENSOR_is_low !(PIN_SENSOR & (1 << SENSOR)) + +volatile int16_t am2302_temp; +volatile uint16_t am2302_hum; + + +uint8_t am_wait(uint8_t _time,uint8_t _signal){ + TCNT1=0; + while(TCNT1==0); + if (_signal) + while((SENSOR_is_hi)&&(TCNT1<_time)) {} + else + while((SENSOR_is_low)&&(TCNT1<_time)) {} + + if (TCNT1>=_time) {return 1;} + return 0; +} + +volatile uint8_t am2302_mode=0; +volatile uint8_t timeout=0; + + + +#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) +ISR(WATCHDOG_vect) { +#else +ISR(WDT_vect) { +#endif + sleep_disable(); // Disable Sleep on Wakeup + am2302_mode++; + if (reset_indicator==1) reset_indicator++; + else if (reset_indicator==2) mode=0; +/* if (timeout==2) { + DIS_TIMER; + EN_OWINT; + mode=OWM_SLEEP; + } + timeout++;*/ + sleep_enable(); // Enable Sleep Mode + +} + +int testSW() { + uint8_t r; + DDRB&=~(1< bit=1 else bit=0 + sensor_byte |= 1; + if (am_wait(45,1)) return 6;// 30us - 75us = 45us + } + } + sensor_data[i] = sensor_byte; + } + + // checksum + if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4]) + { + // debug output + //printf("%b %b %b %b %b %b" CR, sensor_data[0], sensor_data[1], sensor_data[2], sensor_data[3], sensor_data[4], ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff )); + PORTB&=~(1< bit=1 else bit=0 + sensor_byte |= 1; + if (am_wait(45,1)) return 6;// 30us - 75us = 45us + } + } + sensor_data[i] = sensor_byte; + } + + // checksum + if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4]) + { + // debug output + //printf("%b %b %b %b %b %b" CR, sensor_data[0], sensor_data[1], sensor_data[2], sensor_data[3], sensor_data[4], ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff )); + PORTB&=~(1<31) pn=1; +#endif + } + SENSOFF + am2302_mode=3; + } + if (am2302_mode>=8) { + am2302_mode=0; + SENSON + } +#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) + if (((TIMSK & (1< -#include -#include -#include -#include -#include - - -extern void OWINIT(); -extern void EXTERN_SLEEP(); - -uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0xDD, 0xDD, 0x05, 0xCE};/**/ -uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - - - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; - -volatile uint8_t wdcounter; - - -typedef union { - - volatile uint8_t bytes[64]; - struct { - uint8_t status; //1 - int16_t temp; //2 - uint16_t voltage; //4 - uint16_t current; //6 - uint8_t threshold; //8 - - uint8_t page1[8]; //9 - uint8_t page2[8]; //17 - uint8_t page3[8]; //25 - uint8_t page4[8]; //33 - uint8_t page5[8]; //41 - uint8_t page6[8]; //49 - uint8_t page7[8]; //57 - //uint8_t crc; //65 - }; -} pack_t; -volatile pack_t pack; - - -#define DDR_SENSOR DDRA -#define PORT_SENSOR PORTA -#define PIN_SENSOR PINA -#define SENSOR PINA2 - -#define SENSOR_sda_out DDR_SENSOR |= (1 << SENSOR) -#define SENSOR_sda_in DDR_SENSOR &= ~(1 << SENSOR);PORT_SENSOR |= (1 << SENSOR) // release sda => hi in consequence of pullup -#define SENSOR_sda_low PORT_SENSOR &= ~(1 << SENSOR) -#define SENSOR_is_hi PIN_SENSOR & (1 << SENSOR) -#define SENSOR_is_low !(PIN_SENSOR & (1 << SENSOR)) - -volatile int16_t am2302_temp; -volatile uint16_t am2302_hum; - - -uint8_t am_wait(uint8_t _time,uint8_t _signal){ - TCNT1=0; - while(TCNT1==0); - if (_signal) - while((SENSOR_is_hi)&&(TCNT1<_time)) {} - else - while((SENSOR_is_low)&&(TCNT1<_time)) {} - - if (TCNT1>=_time) {return 1;} - return 0; -} - -volatile uint8_t am2302_mode=0; -volatile uint8_t timeout=0; - - - - - - -uint8_t userRegister[1]; -int16_t sRH,sT; -volatile double temperatureC,humidityRH; -volatile double l; - -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) -ISR(WATCHDOG_vect) { - #else -ISR(WDT_vect) { - #endif - wdcounter++; - if (reset_indicator==1) reset_indicator++; - else if (reset_indicator==2) mode=0; -} - -int testSW(void) { - uint8_t r; - DDRB&=~(1< bit=1 else bit=0 - sensor_byte |= 1; - if (am_wait(45,1)) return 6;// 30us - 75us = 45us - } - } - sensor_data[i] = sensor_byte; - } - - // checksum - if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4]) - { - PORTB&=~(1< 5V also all *5 - config_info[5]=7; - } - else { - - lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]); - config_info[5]=12; - } - lam2302_temp=lam2302_temp*25.6; - rSREG=SREG; - cli(); - am2302_hum=lam2302_hum; - am2302_temp=lam2302_temp; - SREG=rSREG; - return 0; -} - - - - - - - - - int main(void){ - PRR|=(1<2) { - wdcounter=0; - SENSON - } - gcontrol=0; - } - if (wdcounter==2) { - err=am2302(); - if (err!=0) { - pack.page3[pn]=err; - pn=pn+1;if (pn>31) pn=1; - } - SENSOFF - wdcounter=3; - } - if (wdcounter>=16) { - wdcounter=0; - SENSON - } - - - - if (((TIMSK0 & (1< +#include +#include +#include +#include +#include + + +extern void OWINIT(); +extern void EXTERN_SLEEP(); + +uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0xDD, 0xDD, 0x05, 0xCE};/**/ +uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + + + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; + +volatile uint8_t wdcounter; + + +typedef union { + + volatile uint8_t bytes[64]; + struct { + uint8_t status; //1 + int16_t temp; //2 + uint16_t voltage; //4 + uint16_t current; //6 + uint8_t threshold; //8 + + uint8_t page1[8]; //9 + uint8_t page2[8]; //17 + uint8_t page3[8]; //25 + uint8_t page4[8]; //33 + uint8_t page5[8]; //41 + uint8_t page6[8]; //49 + uint8_t page7[8]; //57 + //uint8_t crc; //65 + }; +} pack_t; +volatile pack_t pack; + + +#define DDR_SENSOR DDRA +#define PORT_SENSOR PORTA +#define PIN_SENSOR PINA +#define SENSOR PINA2 + +#define SENSOR_sda_out DDR_SENSOR |= (1 << SENSOR) +#define SENSOR_sda_in DDR_SENSOR &= ~(1 << SENSOR);PORT_SENSOR |= (1 << SENSOR) // release sda => hi in consequence of pullup +#define SENSOR_sda_low PORT_SENSOR &= ~(1 << SENSOR) +#define SENSOR_is_hi PIN_SENSOR & (1 << SENSOR) +#define SENSOR_is_low !(PIN_SENSOR & (1 << SENSOR)) + +volatile int16_t am2302_temp; +volatile uint16_t am2302_hum; + + +uint8_t am_wait(uint8_t _time,uint8_t _signal){ + TCNT1=0; + while(TCNT1==0); + if (_signal) + while((SENSOR_is_hi)&&(TCNT1<_time)) {} + else + while((SENSOR_is_low)&&(TCNT1<_time)) {} + + if (TCNT1>=_time) {return 1;} + return 0; +} + +volatile uint8_t am2302_mode=0; +volatile uint8_t timeout=0; + + + + + + +uint8_t userRegister[1]; +int16_t sRH,sT; +volatile double temperatureC,humidityRH; +volatile double l; + +#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) +ISR(WATCHDOG_vect) { + #else +ISR(WDT_vect) { + #endif + wdcounter++; + if (reset_indicator==1) reset_indicator++; + else if (reset_indicator==2) mode=0; +} + +int testSW(void) { + uint8_t r; + DDRB&=~(1< bit=1 else bit=0 + sensor_byte |= 1; + if (am_wait(45,1)) return 6;// 30us - 75us = 45us + } + } + sensor_data[i] = sensor_byte; + } + + // checksum + if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4]) + { + PORTB&=~(1< 5V also all *5 + config_info[5]=7; + } + else { + + lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]); + config_info[5]=12; + } + lam2302_temp=lam2302_temp*25.6; + rSREG=SREG; + cli(); + am2302_hum=lam2302_hum; + am2302_temp=lam2302_temp; + SREG=rSREG; + return 0; +} + + + + + + + + + int main(void){ + PRR|=(1<2) { + wdcounter=0; + SENSON + } + gcontrol=0; + } + if (wdcounter==2) { + err=am2302(); + if (err!=0) { + pack.page3[pn]=err; + pn=pn+1;if (pn>31) pn=1; + } + SENSOFF + wdcounter=3; + } + if (wdcounter>=16) { + wdcounter=0; + SENSON + } + + + + if (((TIMSK0 & (1< - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.C - dce6c7e3-ee26-4d79-826b-08594b9ad897 - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS2438_DHT22 - DS2438_DHT22 - DS2438_DHT22 - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - J41800000789 - 0x1E930C - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800000789 - Atmel-ICE - - debugWIRE - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - NDEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize for size (-Os) - True - True - True - - - libm - - - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - OWDS2438.S - - - compile - - - + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + dce6c7e3-ee26-4d79-826b-08594b9ad897 + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS2438_DHT22 + DS2438_DHT22 + DS2438_DHT22 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + J41800000789 + 0x1E930C + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000789 + Atmel-ICE + + debugWIRE + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + OWDS2438.S + + + compile + + + \ No newline at end of file diff --git a/DS2438_DHT22/OWDS2438.S b/DS2438_DHT22/OWDS2438.S index 35bc463..a7d92fa 100644 --- a/DS2438_DHT22/OWDS2438.S +++ b/DS2438_DHT22/OWDS2438.S @@ -1,187 +1,187 @@ -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define _CHANGEABLE_ID_ -//#define _DIS_FLASH_ -#define _ZERO_POLLING_ -//#define _DB_ - -#include "../common/OWConfig.s" -#include "../common/OWCRC8.s" - -#if defined(__AVR_ATtiny25__) -.extern pack,16 -#else -.extern pack,64 -#endif -.extern am2302_temp,2 -.extern am2302_hum,2 -.comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad) - - -.macro CHIP_INIT -.endm - -; Ab hier Geraeteabhaenging -#define OW_READ_SCRATCHPAD_ADR OW_FIRST_COMMAND+0 -#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+1 -#define OW_WRITE_SCRATCHPAD_ADR OW_FIRST_COMMAND+2 -#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+3 - - - -.macro COMMAND_TABLE - rjmp h_readscratchpad_adr - rjmp h_readscratchpad - rjmp h_writescratchpad_adr - rjmp h_writescratchpad -.endm - -#include "../common/OWRomFunctions.s" -#include "../common/OWTimerInterrupt.s" - - -;--------------------------------------------------- -; READ COMMAND and start operation -;--------------------------------------------------- - - -h_readcommand: - clr r_bytep -#ifndef _DIS_FLASH_ - FLASH_COMMANDS ; muss zu erst sein.... -#endif - cset 0xBE,OW_READ_SCRATCHPAD_ADR - cset 0x4E,OW_WRITE_SCRATCHPAD_ADR - cjmp 0x44,hrc_set_convertT - cjmp 0xB4,hrc_set_convertV - FW_CONFIG_INFO -#ifdef _CHANGEABLE_ID_ - CHANGE_ID_COMMANDS -#endif - rjmp handle_end_sleep - - -hrc_set_convertT: - ldi r_temp,1 - sts gcontrol,r_temp - lds r_temp,am2302_temp - sts pack+1,r_temp - lds r_temp,am2302_temp+1 - sts pack+2,r_temp - rjmp handle_end_sleep -hrc_set_convertV: - ldi r_temp,2 - sts gcontrol,r_temp - lds r_temp,pack - sbrs r_temp,3 - rjmp hrc_set_convertVV - ldi r_temp,0xF4 - sts pack+3,r_temp - ldi r_temp,0x01 - sts pack+4,r_temp - rjmp hrc_set_convertend -hrc_set_convertVV: - lds r_temp,am2302_hum - sts pack+3,r_temp - lds r_temp,am2302_hum+1 - sts pack+4,r_temp -hrc_set_convertend: - rjmp handle_end_sleep - - - -;--------------------------------------------------- -; READ SCRATCHPAD -;--------------------------------------------------- - -h_readscratchpad_adr: - lsl r_rwbyte - lsl r_rwbyte - lsl r_rwbyte -#if defined(__AVR_ATtiny25__) - andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen -#endif - sts block,r_rwbyte - ldi r_sendflag,1 - ldi r_mode,OW_READ_SCRATCHPAD - CRCInit2 -h_readscratchpad: - cpi r_bytep,8 - breq h_readscratchpad_crc - cpi r_bytep,9 - breq h_readscratchpad_all - lds r_temp,block - add r_temp,r_bytep - configZ pack,r_temp - ld r_rwbyte,Z - rjmp handle_end_inc -h_readscratchpad_crc: - lds r_rwbyte,crc - rjmp handle_end_inc -h_readscratchpad_all: - rjmp handle_end_sleep - - - - -;--------------------------------------------------- -; WRITE SCRATCHPAD -;--------------------------------------------------- -h_writescratchpad_adr: - lsl r_rwbyte - lsl r_rwbyte - lsl r_rwbyte -#if defined(__AVR_ATtiny25__) - andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen -#endif - sts block,r_rwbyte - ldi r_mode,OW_WRITE_SCRATCHPAD - ldi r_bcount,1 - rjmp handle_end -h_writescratchpad: - cpi r_bytep,8 - breq h_writescratchpad_all - lds r_temp,block - add r_temp,r_bytep - configZ pack,r_temp - st Z,r_rwbyte - rjmp handle_end_inc -h_writescratchpad_all: - rjmp handle_end_sleep - - - - - -#include "../common/OWPinInterrupt.s" +// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the +// distribution. +// * All advertising materials mentioning features or use of this +// software must display the following acknowledgement: This product +// includes software developed by tm3d.de and its contributors. +// * Neither the name of tm3d.de nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#define _CHANGEABLE_ID_ +//#define _DIS_FLASH_ +#define _ZERO_POLLING_ +//#define _DB_ + +#include "../common/OWConfig.s" +#include "../common/OWCRC8.s" + +#if defined(__AVR_ATtiny25__) +.extern pack,16 +#else +.extern pack,64 +#endif +.extern am2302_temp,2 +.extern am2302_hum,2 +.comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad) + + +.macro CHIP_INIT +.endm + +; Ab hier Geraeteabhaenging +#define OW_READ_SCRATCHPAD_ADR OW_FIRST_COMMAND+0 +#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+1 +#define OW_WRITE_SCRATCHPAD_ADR OW_FIRST_COMMAND+2 +#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+3 + + + +.macro COMMAND_TABLE + rjmp h_readscratchpad_adr + rjmp h_readscratchpad + rjmp h_writescratchpad_adr + rjmp h_writescratchpad +.endm + +#include "../common/OWRomFunctions.s" +#include "../common/OWTimerInterrupt.s" + + +;--------------------------------------------------- +; READ COMMAND and start operation +;--------------------------------------------------- + + +h_readcommand: + clr r_bytep +#ifndef _DIS_FLASH_ + FLASH_COMMANDS ; muss zu erst sein.... +#endif + cset 0xBE,OW_READ_SCRATCHPAD_ADR + cset 0x4E,OW_WRITE_SCRATCHPAD_ADR + cjmp 0x44,hrc_set_convertT + cjmp 0xB4,hrc_set_convertV + FW_CONFIG_INFO +#ifdef _CHANGEABLE_ID_ + CHANGE_ID_COMMANDS +#endif + rjmp handle_end_sleep + + +hrc_set_convertT: + ldi r_temp,1 + sts gcontrol,r_temp + lds r_temp,am2302_temp + sts pack+1,r_temp + lds r_temp,am2302_temp+1 + sts pack+2,r_temp + rjmp handle_end_sleep +hrc_set_convertV: + ldi r_temp,2 + sts gcontrol,r_temp + lds r_temp,pack + sbrs r_temp,3 + rjmp hrc_set_convertVV + ldi r_temp,0xF4 + sts pack+3,r_temp + ldi r_temp,0x01 + sts pack+4,r_temp + rjmp hrc_set_convertend +hrc_set_convertVV: + lds r_temp,am2302_hum + sts pack+3,r_temp + lds r_temp,am2302_hum+1 + sts pack+4,r_temp +hrc_set_convertend: + rjmp handle_end_sleep + + + +;--------------------------------------------------- +; READ SCRATCHPAD +;--------------------------------------------------- + +h_readscratchpad_adr: + lsl r_rwbyte + lsl r_rwbyte + lsl r_rwbyte +#if defined(__AVR_ATtiny25__) + andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen +#endif + sts block,r_rwbyte + ldi r_sendflag,1 + ldi r_mode,OW_READ_SCRATCHPAD + CRCInit2 +h_readscratchpad: + cpi r_bytep,8 + breq h_readscratchpad_crc + cpi r_bytep,9 + breq h_readscratchpad_all + lds r_temp,block + add r_temp,r_bytep + configZ pack,r_temp + ld r_rwbyte,Z + rjmp handle_end_inc +h_readscratchpad_crc: + lds r_rwbyte,crc + rjmp handle_end_inc +h_readscratchpad_all: + rjmp handle_end_sleep + + + + +;--------------------------------------------------- +; WRITE SCRATCHPAD +;--------------------------------------------------- +h_writescratchpad_adr: + lsl r_rwbyte + lsl r_rwbyte + lsl r_rwbyte +#if defined(__AVR_ATtiny25__) + andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen +#endif + sts block,r_rwbyte + ldi r_mode,OW_WRITE_SCRATCHPAD + ldi r_bcount,1 + rjmp handle_end +h_writescratchpad: + cpi r_bytep,8 + breq h_writescratchpad_all + lds r_temp,block + add r_temp,r_bytep + configZ pack,r_temp + st Z,r_rwbyte + rjmp handle_end_inc +h_writescratchpad_all: + rjmp handle_end_sleep + + + + + +#include "../common/OWPinInterrupt.s" .end \ No newline at end of file diff --git a/DS2438_HIH9121/DS2438_9121.atsln b/DS2438_HIH9121/DS2438_9121.atsln index 453b0e3..467ae24 100644 --- a/DS2438_HIH9121/DS2438_9121.atsln +++ b/DS2438_HIH9121/DS2438_9121.atsln @@ -1,22 +1,22 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Atmel Studio Solution File, Format Version 11.00 -VisualStudioVersion = 14.0.23107.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2438_HIH9121", "DS2438_HIH9121.cproj", "{91468D4F-8AE2-4C59-8A35-549C49E00934}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|AVR = Debug|AVR - Release|AVR = Release|AVR - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.ActiveCfg = Debug|AVR - {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.Build.0 = Debug|AVR - {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.ActiveCfg = Release|AVR - {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.Build.0 = Release|AVR - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Atmel Studio Solution File, Format Version 11.00 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2438_HIH9121", "DS2438_HIH9121.cproj", "{91468D4F-8AE2-4C59-8A35-549C49E00934}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.ActiveCfg = Debug|AVR + {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.Build.0 = Debug|AVR + {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.ActiveCfg = Release|AVR + {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/DS2438_HIH9121/DS2438_HIH9121.c b/DS2438_HIH9121/DS2438_HIH9121.c index a7e115c..6c59d8c 100644 --- a/DS2438_HIH9121/DS2438_HIH9121.c +++ b/DS2438_HIH9121/DS2438_HIH9121.c @@ -1,227 +1,227 @@ -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/MAX44009.h" -#include "../common/I2C/SHT2x.h" - -extern void OWINIT(); -extern void EXTERN_SLEEP(); - -uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0x00, 0x00, 0x05, 0x16};/**/ -uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; -//uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x08, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; - -volatile uint8_t wdcounter; - - -typedef union { - - volatile uint8_t bytes[64]; - struct { - uint8_t status; //1 - int16_t temp; //2 - uint16_t voltage; //4 - uint16_t current; //6 - uint8_t threshold; //8 - - uint8_t page1[8]; //9 - uint8_t page2[8]; //17 - uint8_t page3[8]; //25 - uint8_t page4[8]; //33 - uint8_t page5[8]; //41 - uint8_t page6[8]; //49 - uint8_t page7[8]; //57 - //uint8_t crc; //65 - }; -} pack_t; -volatile pack_t pack; - - - -volatile int16_t am2302_temp; -volatile uint16_t am2302_hum; - -uint8_t userRegister[1]; -int16_t sRH,sT; -volatile double temperatureC,humidityRH; -volatile double l; - -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) -ISR(WATCHDOG_vect) { -#else -ISR(WDT_vect) { -#endif - wdcounter++; - if (reset_indicator==1) reset_indicator++; - else if (reset_indicator==2) mode=0; - - -} - -int testSW(void) { - uint8_t r; - DDRB&=~(1<>2; - - I2c_StopCondition(); - temperatureC=res1/16382.0*160.0-40.0; - humidityRH=res/16382.0*100.0; - //temperatureC = SHT2x_CalcTemperatureC(sT); - //humidityRH = SHT2x_CalcRH(sRH); - - sei(); - - while(1) { - if (gcontrol) { - wdcounter=3; - gcontrol=0; - } - if (wdcounter>2) { - I2c_StartCondition(); - I2c_WriteByte (0b01001110); - I2c_StopCondition(); - _delay_us(100); - I2c_StartCondition(); - I2c_WriteByte (0b01001111); - _delay_us(80); - res=((int16_t)(I2c_ReadByte(ACK))&0x3F)<<8; - res|=I2c_ReadByte(ACK); - res1=((int16_t)(I2c_ReadByte(ACK)))<<6; - res1|=I2c_ReadByte(NO_ACK)>>2; - - I2c_StopCondition(); - temperatureC=res1/16382.0*1650.0-400.0; - humidityRH=res/16382.0*1000.0; - - if (testSW()) { - am2302_hum= humidityRH*10.0; - am2302_temp=temperatureC*25.6; - //am2302_temp=am2302_temp-45; - config_info[5]=8; - - }else{ - - double hhum=(1.0546-0.000216*temperatureC)*(humidityRH); - //am2302_hum=0.318*hhum +76.0; - am2302_hum=0.31*hhum +80; - am2302_temp=temperatureC*25.6; - //am2302_temp=am2302_temp-45; - config_info[5]=7; - } - //PORTB&=~(1< +#include +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common/I2C/MAX44009.h" +#include "../common/I2C/SHT2x.h" + +extern void OWINIT(); +extern void EXTERN_SLEEP(); + +uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0x00, 0x00, 0x05, 0x16};/**/ +uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; +//uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x08, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; + +volatile uint8_t wdcounter; + + +typedef union { + + volatile uint8_t bytes[64]; + struct { + uint8_t status; //1 + int16_t temp; //2 + uint16_t voltage; //4 + uint16_t current; //6 + uint8_t threshold; //8 + + uint8_t page1[8]; //9 + uint8_t page2[8]; //17 + uint8_t page3[8]; //25 + uint8_t page4[8]; //33 + uint8_t page5[8]; //41 + uint8_t page6[8]; //49 + uint8_t page7[8]; //57 + //uint8_t crc; //65 + }; +} pack_t; +volatile pack_t pack; + + + +volatile int16_t am2302_temp; +volatile uint16_t am2302_hum; + +uint8_t userRegister[1]; +int16_t sRH,sT; +volatile double temperatureC,humidityRH; +volatile double l; + +#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) +ISR(WATCHDOG_vect) { +#else +ISR(WDT_vect) { +#endif + wdcounter++; + if (reset_indicator==1) reset_indicator++; + else if (reset_indicator==2) mode=0; + + +} + +int testSW(void) { + uint8_t r; + DDRB&=~(1<>2; + + I2c_StopCondition(); + temperatureC=res1/16382.0*160.0-40.0; + humidityRH=res/16382.0*100.0; + //temperatureC = SHT2x_CalcTemperatureC(sT); + //humidityRH = SHT2x_CalcRH(sRH); + + sei(); + + while(1) { + if (gcontrol) { + wdcounter=3; + gcontrol=0; + } + if (wdcounter>2) { + I2c_StartCondition(); + I2c_WriteByte (0b01001110); + I2c_StopCondition(); + _delay_us(100); + I2c_StartCondition(); + I2c_WriteByte (0b01001111); + _delay_us(80); + res=((int16_t)(I2c_ReadByte(ACK))&0x3F)<<8; + res|=I2c_ReadByte(ACK); + res1=((int16_t)(I2c_ReadByte(ACK)))<<6; + res1|=I2c_ReadByte(NO_ACK)>>2; + + I2c_StopCondition(); + temperatureC=res1/16382.0*1650.0-400.0; + humidityRH=res/16382.0*1000.0; + + if (testSW()) { + am2302_hum= humidityRH*10.0; + am2302_temp=temperatureC*25.6; + //am2302_temp=am2302_temp-45; + config_info[5]=8; + + }else{ + + double hhum=(1.0546-0.000216*temperatureC)*(humidityRH); + //am2302_hum=0.318*hhum +76.0; + am2302_hum=0.31*hhum +80; + am2302_temp=temperatureC*25.6; + //am2302_temp=am2302_temp-45; + config_info[5]=7; + } + //PORTB&=~(1< - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.C - {91468d4f-8ae2-4c59-8a35-549c49e00934} - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS2438_SHT2X - DS2438_HIH9121 - DS2438_SHT2X - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800000779 - Atmel-ICE - - debugWIRE - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - USI_TWI_Master.c - - - compile - OWDS2438.S - - - compile - - - + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + {91468d4f-8ae2-4c59-8a35-549c49e00934} + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS2438_SHT2X + DS2438_HIH9121 + DS2438_SHT2X + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000779 + Atmel-ICE + + debugWIRE + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + USI_TWI_Master.c + + + compile + OWDS2438.S + + + compile + + + \ No newline at end of file diff --git a/DS2438_SHT2X/DS2438_SHT2X.atsln b/DS2438_SHT2X/DS2438_SHT2X.atsln index 1a91fb0..9a19423 100644 --- a/DS2438_SHT2X/DS2438_SHT2X.atsln +++ b/DS2438_SHT2X/DS2438_SHT2X.atsln @@ -1,20 +1,20 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Atmel Studio Solution File, Format Version 11.00 -Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2438_SHT2X", "DS2438_SHT2X.cproj", "{91468D4F-8AE2-4C59-8A35-549C49E00934}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|AVR = Debug|AVR - Release|AVR = Release|AVR - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.ActiveCfg = Debug|AVR - {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.Build.0 = Debug|AVR - {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.ActiveCfg = Release|AVR - {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.Build.0 = Release|AVR - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Atmel Studio Solution File, Format Version 11.00 +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2438_SHT2X", "DS2438_SHT2X.cproj", "{91468D4F-8AE2-4C59-8A35-549C49E00934}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.ActiveCfg = Debug|AVR + {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.Build.0 = Debug|AVR + {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.ActiveCfg = Release|AVR + {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/DS2438_SHT2X/DS2438_SHT2X.c b/DS2438_SHT2X/DS2438_SHT2X.c index dddca10..0da9838 100644 --- a/DS2438_SHT2X/DS2438_SHT2X.c +++ b/DS2438_SHT2X/DS2438_SHT2X.c @@ -1,210 +1,210 @@ -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/MAX44009.h" -#include "../common/I2C/SHT2x.h" - -extern void OWINIT(); -extern void EXTERN_SLEEP(); - -uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0x00, 0x00, 0x05, 0x16};/**/ -uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; -//uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x08, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; - -volatile uint8_t wdcounter=5; - - -typedef union { - - volatile uint8_t bytes[64]; - struct { - uint8_t status; //1 - int16_t temp; //2 - uint16_t voltage; //4 - uint16_t current; //6 - uint8_t threshold; //8 - - uint8_t page1[8]; //9 - uint8_t page2[8]; //17 - uint8_t page3[8]; //25 - uint8_t page4[8]; //33 - uint8_t page5[8]; //41 - uint8_t page6[8]; //49 - uint8_t page7[8]; //57 - //uint8_t crc; //65 - }; -} pack_t; -volatile pack_t pack; - - - -volatile int16_t am2302_temp; -volatile uint16_t am2302_hum; - -uint8_t userRegister[1]; -int16_t sRH,sT; -volatile double temperatureC,humidityRH; -volatile double l; - -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) -ISR(WATCHDOG_vect) { -#else -ISR(WDT_vect) { -#endif - wdcounter++; - if (reset_indicator==1) reset_indicator++; - else if (reset_indicator==2) mode=0; - - -} - -int testSW(void) { - uint8_t r; - DDRB&=~(1<2) { - //PORTB|=(1< +#include +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common/I2C/MAX44009.h" +#include "../common/I2C/SHT2x.h" + +extern void OWINIT(); +extern void EXTERN_SLEEP(); + +uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0x00, 0x00, 0x05, 0x16};/**/ +uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; +//uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x08, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; + +volatile uint8_t wdcounter=5; + + +typedef union { + + volatile uint8_t bytes[64]; + struct { + uint8_t status; //1 + int16_t temp; //2 + uint16_t voltage; //4 + uint16_t current; //6 + uint8_t threshold; //8 + + uint8_t page1[8]; //9 + uint8_t page2[8]; //17 + uint8_t page3[8]; //25 + uint8_t page4[8]; //33 + uint8_t page5[8]; //41 + uint8_t page6[8]; //49 + uint8_t page7[8]; //57 + //uint8_t crc; //65 + }; +} pack_t; +volatile pack_t pack; + + + +volatile int16_t am2302_temp; +volatile uint16_t am2302_hum; + +uint8_t userRegister[1]; +int16_t sRH,sT; +volatile double temperatureC,humidityRH; +volatile double l; + +#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) +ISR(WATCHDOG_vect) { +#else +ISR(WDT_vect) { +#endif + wdcounter++; + if (reset_indicator==1) reset_indicator++; + else if (reset_indicator==2) mode=0; + + +} + +int testSW(void) { + uint8_t r; + DDRB&=~(1<2) { + //PORTB|=(1< - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.C - {91468d4f-8ae2-4c59-8a35-549c49e00934} - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS2438_SHT2X - DS2438_SHT2X - DS2438_SHT2X - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800000779 - Atmel-ICE - - debugWIRE - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - SHT2x.c - - - compile - USI_TWI_Master.c - - - compile - OWDS2438.S - - - compile - - - + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + {91468d4f-8ae2-4c59-8a35-549c49e00934} + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS2438_SHT2X + DS2438_SHT2X + DS2438_SHT2X + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000779 + Atmel-ICE + + debugWIRE + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + SHT2x.c + + + compile + USI_TWI_Master.c + + + compile + OWDS2438.S + + + compile + + + \ No newline at end of file diff --git a/DS2450/DS2450.atsln b/DS2450/DS2450.atsln index 848bac3..09276c9 100644 --- a/DS2450/DS2450.atsln +++ b/DS2450/DS2450.atsln @@ -1,22 +1,22 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Atmel Studio Solution File, Format Version 11.00 -VisualStudioVersion = 14.0.23107.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2450", "DS2450.cproj", "{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 + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Atmel Studio Solution File, Format Version 11.00 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2450", "DS2450.cproj", "{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/DS2450/DS2450.c b/DS2450/DS2450.c index 3567ab2..cf4e588 100644 --- a/DS2450/DS2450.c +++ b/DS2450/DS2450.c @@ -1,244 +1,244 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include - -extern void OWINIT(); -extern void EXTERN_SLEEP(); - -uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/ -uint8_t config_info[16]={0x06,0x09,0x06,0x09,0x06,0x09,0x06,0x09,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - -#if (owid>128) -#error "Variable not correct" -#endif - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; - - -typedef union { - volatile uint8_t bytes[0x20]; - struct { - //Page0 - uint16_t A; //0 - uint16_t B; //2 - uint16_t C; //4 - uint16_t D; //6 - //Page1 - uint8_t CSA1; - uint8_t CSA2; - uint8_t CSB1; - uint8_t CSB2; - uint8_t CSC1; - uint8_t CSC2; - uint8_t CSD1; - uint8_t CSD2; - //Page2 - uint8_t LA; - uint8_t HA; - uint8_t LB; - uint8_t HB; - uint8_t LC; - uint8_t HC; - uint8_t LD; - uint8_t HD; - //Page3 - uint8_t FC1; - uint8_t FC2; - uint8_t FC3; - uint8_t FC4; - uint8_t VCCP; - uint8_t FC5; - uint8_t FC6; - uint8_t FC7; - uint8_t convc1; - uint8_t convc2; - - - }; -} pack_t; -volatile pack_t pack; - - - - - - -int main(void){ - pack.A=0; - pack.B=0; - pack.C=0; - pack.D=0; - pack.CSA1=0x08; - pack.CSA2=0x8C; - pack.CSB1=0x08; - pack.CSB2=0x8C; - pack.CSC1=0x08; - pack.CSC2=0x8C; - pack.CSD1=0x08; - pack.CSD2=0x8C; - pack.HA=0xFF; - pack.LA=0x00; - pack.HB=0xFF; - pack.LB=0x00; - pack.HC=0xFF; - pack.LC=0x00; - pack.HD=0xFF; - pack.LD=0x00; - pack.VCCP=0; - OWINIT(); - - MCUCR &=~(1<pack.HA) {alarmflag=1;pack.CSA2|=0x20;} - if (pack.CSA2&0x04) //AEL - if (pack.bytes[1]pack.HB) {alarmflag=1;pack.CSB2|=0x20;} - if (pack.CSB2&0x04) //AEL - if (pack.bytes[1]pack.HC) {alarmflag=1;pack.CSC2|=0x20;} - if (pack.CSC2&0x04) //AEL - if (pack.bytes[1]pack.HD) {alarmflag=1;pack.CSD2|=0x20;} - if (pack.CSD2&0x04) //AEL - if (pack.bytes[1] +#include +#include +#include +#include +#include + +extern void OWINIT(); +extern void EXTERN_SLEEP(); + +uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/ +uint8_t config_info[16]={0x06,0x09,0x06,0x09,0x06,0x09,0x06,0x09,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +#if (owid>128) +#error "Variable not correct" +#endif + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; + + +typedef union { + volatile uint8_t bytes[0x20]; + struct { + //Page0 + uint16_t A; //0 + uint16_t B; //2 + uint16_t C; //4 + uint16_t D; //6 + //Page1 + uint8_t CSA1; + uint8_t CSA2; + uint8_t CSB1; + uint8_t CSB2; + uint8_t CSC1; + uint8_t CSC2; + uint8_t CSD1; + uint8_t CSD2; + //Page2 + uint8_t LA; + uint8_t HA; + uint8_t LB; + uint8_t HB; + uint8_t LC; + uint8_t HC; + uint8_t LD; + uint8_t HD; + //Page3 + uint8_t FC1; + uint8_t FC2; + uint8_t FC3; + uint8_t FC4; + uint8_t VCCP; + uint8_t FC5; + uint8_t FC6; + uint8_t FC7; + uint8_t convc1; + uint8_t convc2; + + + }; +} pack_t; +volatile pack_t pack; + + + + + + +int main(void){ + pack.A=0; + pack.B=0; + pack.C=0; + pack.D=0; + pack.CSA1=0x08; + pack.CSA2=0x8C; + pack.CSB1=0x08; + pack.CSB2=0x8C; + pack.CSC1=0x08; + pack.CSC2=0x8C; + pack.CSD1=0x08; + pack.CSD2=0x8C; + pack.HA=0xFF; + pack.LA=0x00; + pack.HB=0xFF; + pack.LB=0x00; + pack.HC=0xFF; + pack.LC=0x00; + pack.HD=0xFF; + pack.LD=0x00; + pack.VCCP=0; + OWINIT(); + + MCUCR &=~(1<pack.HA) {alarmflag=1;pack.CSA2|=0x20;} + if (pack.CSA2&0x04) //AEL + if (pack.bytes[1]pack.HB) {alarmflag=1;pack.CSB2|=0x20;} + if (pack.CSB2&0x04) //AEL + if (pack.bytes[1]pack.HC) {alarmflag=1;pack.CSC2|=0x20;} + if (pack.CSC2&0x04) //AEL + if (pack.bytes[1]pack.HD) {alarmflag=1;pack.CSD2|=0x20;} + if (pack.CSD2&0x04) //AEL + if (pack.bytes[1] - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.C - dce6c7e3-ee26-4d79-826b-08594b9ad897 - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS2450 - DS2450 - DS2450 - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - NDEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize for size (-Os) - True - True - True - - - libm - - - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - - - compile - - - + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + dce6c7e3-ee26-4d79-826b-08594b9ad897 + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS2450 + DS2450 + DS2450 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + + + compile + + + \ No newline at end of file diff --git a/DS2450/OWDS2450.S b/DS2450/OWDS2450.S index aec56b7..1d81abd 100644 --- a/DS2450/OWDS2450.S +++ b/DS2450/OWDS2450.S @@ -1,247 +1,247 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define _CHANGEABLE_ID_ -#define _ZERO_POLLING_ - -#include "../common/OWConfig.s" -#include "../common/OWCRC16.s" - -.extern pack,8 -.comm addr,1 ;zweites Adressbyte ist unnoetig (Warum auch immer fuer 32 Byte 16 Bit Adressen verwendet werden....) -.comm crcsave,1 ; zwischenspeicherspeicher fuer crc nur zweites byte.... -//.extern am2302_temp,2 - - - -.macro CHIP_INIT -.endm - -.macro COMMAND_TABLE - rjmp h_readmemoryaddr - rjmp h_readmemory - rjmp h_readmemorycrc1 - rjmp h_readmemorycrc2 - rjmp h_writememoryaddr - rjmp h_writememory - rjmp h_writememorycrc1 - rjmp h_writememorycrc2 - rjmp h_writememoryreadback - rjmp h_convert - rjmp h_convertcrc1 - rjmp h_convertcrc2 - rjmp h_convert_conv -.endm - -#include "../common/OWRomFunctions.s" -#include "../common/OWTimerInterrupt.s" - - - -; Ab hier Geraeteabhaenging -#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+0 -#define OW_READ_MEMORY OW_FIRST_COMMAND+1 -#define OW_READ_MEMORY_CRC1 OW_FIRST_COMMAND+2 -#define OW_READ_MEMORY_CRC2 OW_FIRST_COMMAND+3 -#define OW_WRITE_MEMORY_ADDR OW_FIRST_COMMAND+4 -#define OW_WRITE_MEMORY OW_FIRST_COMMAND+5 -#define OW_WRITE_MEMORY_CRC1 OW_FIRST_COMMAND+6 -#define OW_WRITE_MEMORY_CRC2 OW_FIRST_COMMAND+7 -#define OW_WRITE_MEMORY_READBACK OW_FIRST_COMMAND+8 -#define OW_CONVERT OW_FIRST_COMMAND+9 -#define OW_CONVERT_CRC1 OW_FIRST_COMMAND+10 -#define OW_CONVERT_CRC2 OW_FIRST_COMMAND+11 -#define OW_CONVERT_CONV OW_FIRST_COMMAND+12 - -;--------------------------------------------------- -; READ COMMAND and start operation -;--------------------------------------------------- - - -h_readcommand: - clr r_bytep -#ifndef _DIS_FLASH_ - FLASH_COMMANDS ; muss zu erst sein.... -#endif - cset 0xAA,OW_READ_MEMORY_ADDR - cset 0x55,OW_WRITE_MEMORY_ADDR - cset 0x3C,OW_CONVERT - FW_CONFIG_INFO -#ifdef _CHANGEABLE_ID_ - CHANGE_ID_COMMANDS -#endif - ldi r_mode,OW_SLEEP - rjmp handle_end - - -h_readmemoryaddr: - cpi r_bytep,0 ;erstes Adressbyte ? - brne h_readmemory_addr_byte1 ;nein dann weiter - andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen - sts addr,r_rwbyte ;speichern des ersten bytes - rjmp handle_end_inc -h_readmemory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert! - ldi r_mode,OW_READ_MEMORY ;weiter zu read Memory - ;;ldi r_bcount,1 ;ist unten - ldi r_sendflag,1 ;jetzt sendet der Slave zum Master - clr r_bytep - rjmp h_readmemory2 -h_readmemory: - lds r_bytep,addr - inc r_bytep - sts addr,r_bytep - andi r_bytep,0x07 - breq h_readmemory_init_crc -h_readmemory2: - lds r_bytep,addr - ;andi r_bytep,0x1F ist oben - configZ pack,r_bytep - ld r_rwbyte,Z - ;ldi r_bcount,1 - rjmp handle_end ;sendet das Byte und geht zu h_readmemory -h_readmemory_init_crc:; init erstes CRC byte - lds r_rwbyte,crc - com r_rwbyte - lds r_temp,crc+1 - com r_temp - sts crcsave,r_temp - ldi r_mode,OW_READ_MEMORY_CRC1 - ;ldi r_bcount,1 - rjmp handle_end -h_readmemory_end: - ldi r_mode,OW_SLEEP - clr r_sendflag - rjmp handle_end -h_readmemorycrc1:;init zweites CRC Byte - lds r_rwbyte,crcsave - ;ldi r_bcount,1 - ldi r_mode,OW_READ_MEMORY_CRC2 - rjmp handle_end -h_readmemorycrc2:;weiteres senden..... nach zweitem Byte - lds r_temp,addr - andi r_temp,0xE0 - brne h_readmemory_end; ende des speichers - ldi r_mode,OW_READ_MEMORY - CRCInit1 ;Start with new CRC - rjmp h_readmemory2 - -h_writememoryaddr: - cpi r_bytep,0 ;erstes Adressbyte ? - brne h_writememory_addr_byte1 ;nein dann weiter - andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen - sts addr,r_rwbyte ;speichern des ersten bytes - inc r_bytep - ;ldi r_bcount,1 - rjmp handle_end -h_writememory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert! - ldi r_mode,OW_WRITE_MEMORY ;weiter zu read Memory - ;ldi r_bcount,1 ;; _________________________________________________in handle_end integrieren..... - lds r_bytep,addr - rjmp handle_end ;read Memory Byte -h_writememory: - lds r_bytep,addr - configZ pack,r_bytep - st Z,r_rwbyte - ;ldi r_bcount,1 - ldi r_mode,OW_WRITE_MEMORY_CRC1 - ldi r_sendflag,1 ;jetzt sendet der Slave zum Master - lds r_rwbyte,crc - com r_rwbyte - lds r_temp,crc+1 - com r_temp - sts crcsave,r_temp - rjmp handle_end -h_writememorycrc1: - lds r_rwbyte,crcsave - ;ldi r_bcount,1 - ldi r_mode,OW_WRITE_MEMORY_CRC2 - rjmp handle_end -h_writememorycrc2: - lds r_temp,addr - configZ pack,r_temp - ld r_rwbyte,Z - ;ldi r_bcount,1 - ldi r_mode,OW_WRITE_MEMORY_READBACK - rjmp handle_end -h_writememoryreadback: - ldi r_temp,0x00 - sts crc+1,r_temp - lds r_temp,addr - inc r_temp - sts addr,r_temp - sts crc,r_temp - ldi r_sendflag,0 - ;ldi r_bcount,1 - ldi r_mode,OW_WRITE_MEMORY - rjmp handle_end - -h_convert: - cpi r_bytep,0 ;erstes Adressbyte ? - brne h_convert_byte1 ;nein dann weiter - inc r_bytep - sts pack+0x20,r_rwbyte - ;ldi r_bcount,1 - rjmp handle_end -h_convert_byte1: ;zweies byte glesen go crc# - sts pack+0x21,r_rwbyte - lds r_rwbyte,crc - com r_rwbyte - lds r_temp,crc+1 - com r_temp - sts crcsave,r_temp - ldi r_mode,OW_CONVERT_CRC1 - ;ldi r_bcount,1 - ldi r_sendflag,1 - rjmp handle_end -h_convertcrc1: - lds r_rwbyte,crcsave - ;ldi r_bcount,1 - ldi r_mode,OW_CONVERT_CRC2 - rjmp handle_end -h_convertcrc2: - ldi r_temp,1 - sts gcontrol,r_temp - ;ldi r_bcount,1 - ldi r_mode,OW_CONVERT_CONV - ;clr r_sendflag - ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling -h_convert_conv: - ldi r_bcount,0 - ldi r_rwbyte,0 - rjmp handle_end_no_bcount - - - - -#include "../common/OWPinInterrupt.s" + +// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the +// distribution. +// * All advertising materials mentioning features or use of this +// software must display the following acknowledgement: This product +// includes software developed by tm3d.de and its contributors. +// * Neither the name of tm3d.de nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#define _CHANGEABLE_ID_ +#define _ZERO_POLLING_ + +#include "../common/OWConfig.s" +#include "../common/OWCRC16.s" + +.extern pack,8 +.comm addr,1 ;zweites Adressbyte ist unnoetig (Warum auch immer fuer 32 Byte 16 Bit Adressen verwendet werden....) +.comm crcsave,1 ; zwischenspeicherspeicher fuer crc nur zweites byte.... +//.extern am2302_temp,2 + + + +.macro CHIP_INIT +.endm + +.macro COMMAND_TABLE + rjmp h_readmemoryaddr + rjmp h_readmemory + rjmp h_readmemorycrc1 + rjmp h_readmemorycrc2 + rjmp h_writememoryaddr + rjmp h_writememory + rjmp h_writememorycrc1 + rjmp h_writememorycrc2 + rjmp h_writememoryreadback + rjmp h_convert + rjmp h_convertcrc1 + rjmp h_convertcrc2 + rjmp h_convert_conv +.endm + +#include "../common/OWRomFunctions.s" +#include "../common/OWTimerInterrupt.s" + + + +; Ab hier Geraeteabhaenging +#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+0 +#define OW_READ_MEMORY OW_FIRST_COMMAND+1 +#define OW_READ_MEMORY_CRC1 OW_FIRST_COMMAND+2 +#define OW_READ_MEMORY_CRC2 OW_FIRST_COMMAND+3 +#define OW_WRITE_MEMORY_ADDR OW_FIRST_COMMAND+4 +#define OW_WRITE_MEMORY OW_FIRST_COMMAND+5 +#define OW_WRITE_MEMORY_CRC1 OW_FIRST_COMMAND+6 +#define OW_WRITE_MEMORY_CRC2 OW_FIRST_COMMAND+7 +#define OW_WRITE_MEMORY_READBACK OW_FIRST_COMMAND+8 +#define OW_CONVERT OW_FIRST_COMMAND+9 +#define OW_CONVERT_CRC1 OW_FIRST_COMMAND+10 +#define OW_CONVERT_CRC2 OW_FIRST_COMMAND+11 +#define OW_CONVERT_CONV OW_FIRST_COMMAND+12 + +;--------------------------------------------------- +; READ COMMAND and start operation +;--------------------------------------------------- + + +h_readcommand: + clr r_bytep +#ifndef _DIS_FLASH_ + FLASH_COMMANDS ; muss zu erst sein.... +#endif + cset 0xAA,OW_READ_MEMORY_ADDR + cset 0x55,OW_WRITE_MEMORY_ADDR + cset 0x3C,OW_CONVERT + FW_CONFIG_INFO +#ifdef _CHANGEABLE_ID_ + CHANGE_ID_COMMANDS +#endif + ldi r_mode,OW_SLEEP + rjmp handle_end + + +h_readmemoryaddr: + cpi r_bytep,0 ;erstes Adressbyte ? + brne h_readmemory_addr_byte1 ;nein dann weiter + andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen + sts addr,r_rwbyte ;speichern des ersten bytes + rjmp handle_end_inc +h_readmemory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert! + ldi r_mode,OW_READ_MEMORY ;weiter zu read Memory + ;;ldi r_bcount,1 ;ist unten + ldi r_sendflag,1 ;jetzt sendet der Slave zum Master + clr r_bytep + rjmp h_readmemory2 +h_readmemory: + lds r_bytep,addr + inc r_bytep + sts addr,r_bytep + andi r_bytep,0x07 + breq h_readmemory_init_crc +h_readmemory2: + lds r_bytep,addr + ;andi r_bytep,0x1F ist oben + configZ pack,r_bytep + ld r_rwbyte,Z + ;ldi r_bcount,1 + rjmp handle_end ;sendet das Byte und geht zu h_readmemory +h_readmemory_init_crc:; init erstes CRC byte + lds r_rwbyte,crc + com r_rwbyte + lds r_temp,crc+1 + com r_temp + sts crcsave,r_temp + ldi r_mode,OW_READ_MEMORY_CRC1 + ;ldi r_bcount,1 + rjmp handle_end +h_readmemory_end: + ldi r_mode,OW_SLEEP + clr r_sendflag + rjmp handle_end +h_readmemorycrc1:;init zweites CRC Byte + lds r_rwbyte,crcsave + ;ldi r_bcount,1 + ldi r_mode,OW_READ_MEMORY_CRC2 + rjmp handle_end +h_readmemorycrc2:;weiteres senden..... nach zweitem Byte + lds r_temp,addr + andi r_temp,0xE0 + brne h_readmemory_end; ende des speichers + ldi r_mode,OW_READ_MEMORY + CRCInit1 ;Start with new CRC + rjmp h_readmemory2 + +h_writememoryaddr: + cpi r_bytep,0 ;erstes Adressbyte ? + brne h_writememory_addr_byte1 ;nein dann weiter + andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen + sts addr,r_rwbyte ;speichern des ersten bytes + inc r_bytep + ;ldi r_bcount,1 + rjmp handle_end +h_writememory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert! + ldi r_mode,OW_WRITE_MEMORY ;weiter zu read Memory + ;ldi r_bcount,1 ;; _________________________________________________in handle_end integrieren..... + lds r_bytep,addr + rjmp handle_end ;read Memory Byte +h_writememory: + lds r_bytep,addr + configZ pack,r_bytep + st Z,r_rwbyte + ;ldi r_bcount,1 + ldi r_mode,OW_WRITE_MEMORY_CRC1 + ldi r_sendflag,1 ;jetzt sendet der Slave zum Master + lds r_rwbyte,crc + com r_rwbyte + lds r_temp,crc+1 + com r_temp + sts crcsave,r_temp + rjmp handle_end +h_writememorycrc1: + lds r_rwbyte,crcsave + ;ldi r_bcount,1 + ldi r_mode,OW_WRITE_MEMORY_CRC2 + rjmp handle_end +h_writememorycrc2: + lds r_temp,addr + configZ pack,r_temp + ld r_rwbyte,Z + ;ldi r_bcount,1 + ldi r_mode,OW_WRITE_MEMORY_READBACK + rjmp handle_end +h_writememoryreadback: + ldi r_temp,0x00 + sts crc+1,r_temp + lds r_temp,addr + inc r_temp + sts addr,r_temp + sts crc,r_temp + ldi r_sendflag,0 + ;ldi r_bcount,1 + ldi r_mode,OW_WRITE_MEMORY + rjmp handle_end + +h_convert: + cpi r_bytep,0 ;erstes Adressbyte ? + brne h_convert_byte1 ;nein dann weiter + inc r_bytep + sts pack+0x20,r_rwbyte + ;ldi r_bcount,1 + rjmp handle_end +h_convert_byte1: ;zweies byte glesen go crc# + sts pack+0x21,r_rwbyte + lds r_rwbyte,crc + com r_rwbyte + lds r_temp,crc+1 + com r_temp + sts crcsave,r_temp + ldi r_mode,OW_CONVERT_CRC1 + ;ldi r_bcount,1 + ldi r_sendflag,1 + rjmp handle_end +h_convertcrc1: + lds r_rwbyte,crcsave + ;ldi r_bcount,1 + ldi r_mode,OW_CONVERT_CRC2 + rjmp handle_end +h_convertcrc2: + ldi r_temp,1 + sts gcontrol,r_temp + ;ldi r_bcount,1 + ldi r_mode,OW_CONVERT_CONV + ;clr r_sendflag + ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling +h_convert_conv: + ldi r_bcount,0 + ldi r_rwbyte,0 + rjmp handle_end_no_bcount + + + + +#include "../common/OWPinInterrupt.s" .end \ No newline at end of file diff --git a/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.atsln b/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.atsln index ec60614..37ab426 100644 --- a/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.atsln +++ b/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.atsln @@ -1,22 +1,22 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Atmel Studio Solution File, Format Version 11.00 -VisualStudioVersion = 14.0.23107.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2450_SHT2X_BMP280_MAX44009", "DS2450_SHT2X_BMP280_MAX44009.cproj", "{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 + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Atmel Studio Solution File, Format Version 11.00 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2450_SHT2X_BMP280_MAX44009", "DS2450_SHT2X_BMP280_MAX44009.cproj", "{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/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.c b/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.c index 3e01956..73cca74 100644 --- a/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.c +++ b/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.c @@ -1,318 +1,318 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/SHT2x.h" -#include "../common/I2C/BMP280.h" -#include "../common/I2C/MAX44009.h" -extern void OWINIT(); -extern void EXTERN_SLEEP(); - -uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/ -uint8_t config_info[16]={0x01,14,0x04,0x08, 0x03,15, 0x02,16,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - -#if (owid>128) -#error "Variable not correct" -#endif - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; -volatile uint8_t wdcounter=10; - - -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) -ISR(WATCHDOG_vect) { -#else -ISR(WDT_vect) { -#endif - wdcounter++; - if (reset_indicator==1) reset_indicator++; - else if (reset_indicator==2) mode=0; -} - -typedef union { - volatile uint8_t bytes[0x20]; - struct { - //Page0 - uint16_t A; //0 - uint16_t B; //2 - uint16_t C; //4 - uint16_t D; //6 - //Page1 - uint8_t CSA1; - uint8_t CSA2; - uint8_t CSB1; - uint8_t CSB2; - uint8_t CSC1; - uint8_t CSC2; - uint8_t CSD1; - uint8_t CSD2; - //Page2 - uint8_t LA; - uint8_t HA; - uint8_t LB; - uint8_t HB; - uint8_t LC; - uint8_t HC; - uint8_t LD; - uint8_t HD; - //Page3 - uint8_t FC1; - uint8_t FC2; - uint8_t FC3; - uint8_t FC4; - uint8_t VCCP; - uint8_t FC5; - uint8_t FC6; - uint8_t FC7; - uint8_t convc1; - uint8_t convc2; - - - }; -} pack_t; -volatile pack_t pack; - - - -volatile int16_t am2302_temp; -volatile uint16_t am2302_hum; - - -uint8_t userRegister[1]; -int16_t sRH,sT; -volatile double temperatureC,humidityRH; -volatile double l; -uint32_t P; -int32_t t; -uint8_t max_adr=0; - - - -int main(void){ - pack.A=0; - pack.B=0; - pack.C=0; - pack.D=0; - pack.CSA1=0x08; - pack.CSA2=0x8C; - pack.CSB1=0x08; - pack.CSB2=0x8C; - pack.CSC1=0x08; - pack.CSC2=0x8C; - pack.CSD1=0x08; - pack.CSD2=0x8C; - pack.HA=0xFF; - pack.LA=0x00; - pack.HB=0xFF; - pack.LB=0x00; - pack.HC=0xFF; - pack.LC=0x00; - pack.HD=0xFF; - pack.LD=0x00; - pack.VCCP=0; - PORTB=0xFF-(1<3) { - SHT2x_MeasurePoll(HUMIDITY, &sRH); - // --- measure temperature with "Polling Mode" (no hold master) --- - SHT2x_MeasurePoll(TEMP, &sT); - //-- calculate humidity and temperature -- - temperatureC = SHT2x_CalcTemperatureC(sT); - humidityRH = SHT2x_CalcRH(sRH); - bmp280ConvertInt(&t,&P,1); - l=MAX44009getlux(max_adr); - if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045 - //double l=1000; - l=(log(l)*1000)+32767.0; - wdcounter=0; - } - - - - - - - if (gcontrol) { - //PORTB|=(1<pack.HA) {alarmflag=1;pack.CSA2|=0x20;} - if (pack.CSA2&0x04) //AEL - if (pack.bytes[1]pack.HB) {alarmflag=1;pack.CSB2|=0x20;} - if (pack.CSB2&0x04) //AEL - if (pack.bytes[1]pack.HC) {alarmflag=1;pack.CSC2|=0x20;} - if (pack.CSC2&0x04) //AEL - if (pack.bytes[1]pack.HD) {alarmflag=1;pack.CSD2|=0x20;} - if (pack.CSD2&0x04) //AEL - if (pack.bytes[1] +#include +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common/I2C/SHT2x.h" +#include "../common/I2C/BMP280.h" +#include "../common/I2C/MAX44009.h" +extern void OWINIT(); +extern void EXTERN_SLEEP(); + +uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/ +uint8_t config_info[16]={0x01,14,0x04,0x08, 0x03,15, 0x02,16,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +#if (owid>128) +#error "Variable not correct" +#endif + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; +volatile uint8_t wdcounter=10; + + +#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) +ISR(WATCHDOG_vect) { +#else +ISR(WDT_vect) { +#endif + wdcounter++; + if (reset_indicator==1) reset_indicator++; + else if (reset_indicator==2) mode=0; +} + +typedef union { + volatile uint8_t bytes[0x20]; + struct { + //Page0 + uint16_t A; //0 + uint16_t B; //2 + uint16_t C; //4 + uint16_t D; //6 + //Page1 + uint8_t CSA1; + uint8_t CSA2; + uint8_t CSB1; + uint8_t CSB2; + uint8_t CSC1; + uint8_t CSC2; + uint8_t CSD1; + uint8_t CSD2; + //Page2 + uint8_t LA; + uint8_t HA; + uint8_t LB; + uint8_t HB; + uint8_t LC; + uint8_t HC; + uint8_t LD; + uint8_t HD; + //Page3 + uint8_t FC1; + uint8_t FC2; + uint8_t FC3; + uint8_t FC4; + uint8_t VCCP; + uint8_t FC5; + uint8_t FC6; + uint8_t FC7; + uint8_t convc1; + uint8_t convc2; + + + }; +} pack_t; +volatile pack_t pack; + + + +volatile int16_t am2302_temp; +volatile uint16_t am2302_hum; + + +uint8_t userRegister[1]; +int16_t sRH,sT; +volatile double temperatureC,humidityRH; +volatile double l; +uint32_t P; +int32_t t; +uint8_t max_adr=0; + + + +int main(void){ + pack.A=0; + pack.B=0; + pack.C=0; + pack.D=0; + pack.CSA1=0x08; + pack.CSA2=0x8C; + pack.CSB1=0x08; + pack.CSB2=0x8C; + pack.CSC1=0x08; + pack.CSC2=0x8C; + pack.CSD1=0x08; + pack.CSD2=0x8C; + pack.HA=0xFF; + pack.LA=0x00; + pack.HB=0xFF; + pack.LB=0x00; + pack.HC=0xFF; + pack.LC=0x00; + pack.HD=0xFF; + pack.LD=0x00; + pack.VCCP=0; + PORTB=0xFF-(1<3) { + SHT2x_MeasurePoll(HUMIDITY, &sRH); + // --- measure temperature with "Polling Mode" (no hold master) --- + SHT2x_MeasurePoll(TEMP, &sT); + //-- calculate humidity and temperature -- + temperatureC = SHT2x_CalcTemperatureC(sT); + humidityRH = SHT2x_CalcRH(sRH); + bmp280ConvertInt(&t,&P,1); + l=MAX44009getlux(max_adr); + if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045 + //double l=1000; + l=(log(l)*1000)+32767.0; + wdcounter=0; + } + + + + + + + if (gcontrol) { + //PORTB|=(1<pack.HA) {alarmflag=1;pack.CSA2|=0x20;} + if (pack.CSA2&0x04) //AEL + if (pack.bytes[1]pack.HB) {alarmflag=1;pack.CSB2|=0x20;} + if (pack.CSB2&0x04) //AEL + if (pack.bytes[1]pack.HC) {alarmflag=1;pack.CSC2|=0x20;} + if (pack.CSC2&0x04) //AEL + if (pack.bytes[1]pack.HD) {alarmflag=1;pack.CSD2|=0x20;} + if (pack.CSD2&0x04) //AEL + if (pack.bytes[1] - - - 2.0 - 7.0 - com.Atmel.AVRGCC8.C - dce6c7e3-ee26-4d79-826b-08594b9ad897 - ATtiny84A - none - Executable - C - $(MSBuildProjectName) - .elf - $(MSBuildProjectDirectory)\$(Configuration) - DS2450 - DS2450_SHT2X_BMP280_MAX44009 - DS2450 - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - J41800000779 - 0x1E930C - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800000779 - Atmel-ICE - - debugWIRE - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - NDEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize for size (-Os) - True - True - True - - - libm - - - - - - - - - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - - - - - - compile - BMP280.c - - - compile - MAX44009.c - - - compile - SHT2x.c - - - compile - TSL256x.c - - - compile - USI_TWI_Master.c - - - compile - - - compile - - - + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + dce6c7e3-ee26-4d79-826b-08594b9ad897 + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS2450 + DS2450_SHT2X_BMP280_MAX44009 + DS2450 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + J41800000779 + 0x1E930C + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000779 + Atmel-ICE + + debugWIRE + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + BMP280.c + + + compile + MAX44009.c + + + compile + SHT2x.c + + + compile + TSL256x.c + + + compile + USI_TWI_Master.c + + + compile + + + compile + + + \ No newline at end of file diff --git a/DS2450_SHT2X_BMP280_MAX44009/OWDS2450.S b/DS2450_SHT2X_BMP280_MAX44009/OWDS2450.S index aec56b7..1d81abd 100644 --- a/DS2450_SHT2X_BMP280_MAX44009/OWDS2450.S +++ b/DS2450_SHT2X_BMP280_MAX44009/OWDS2450.S @@ -1,247 +1,247 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define _CHANGEABLE_ID_ -#define _ZERO_POLLING_ - -#include "../common/OWConfig.s" -#include "../common/OWCRC16.s" - -.extern pack,8 -.comm addr,1 ;zweites Adressbyte ist unnoetig (Warum auch immer fuer 32 Byte 16 Bit Adressen verwendet werden....) -.comm crcsave,1 ; zwischenspeicherspeicher fuer crc nur zweites byte.... -//.extern am2302_temp,2 - - - -.macro CHIP_INIT -.endm - -.macro COMMAND_TABLE - rjmp h_readmemoryaddr - rjmp h_readmemory - rjmp h_readmemorycrc1 - rjmp h_readmemorycrc2 - rjmp h_writememoryaddr - rjmp h_writememory - rjmp h_writememorycrc1 - rjmp h_writememorycrc2 - rjmp h_writememoryreadback - rjmp h_convert - rjmp h_convertcrc1 - rjmp h_convertcrc2 - rjmp h_convert_conv -.endm - -#include "../common/OWRomFunctions.s" -#include "../common/OWTimerInterrupt.s" - - - -; Ab hier Geraeteabhaenging -#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+0 -#define OW_READ_MEMORY OW_FIRST_COMMAND+1 -#define OW_READ_MEMORY_CRC1 OW_FIRST_COMMAND+2 -#define OW_READ_MEMORY_CRC2 OW_FIRST_COMMAND+3 -#define OW_WRITE_MEMORY_ADDR OW_FIRST_COMMAND+4 -#define OW_WRITE_MEMORY OW_FIRST_COMMAND+5 -#define OW_WRITE_MEMORY_CRC1 OW_FIRST_COMMAND+6 -#define OW_WRITE_MEMORY_CRC2 OW_FIRST_COMMAND+7 -#define OW_WRITE_MEMORY_READBACK OW_FIRST_COMMAND+8 -#define OW_CONVERT OW_FIRST_COMMAND+9 -#define OW_CONVERT_CRC1 OW_FIRST_COMMAND+10 -#define OW_CONVERT_CRC2 OW_FIRST_COMMAND+11 -#define OW_CONVERT_CONV OW_FIRST_COMMAND+12 - -;--------------------------------------------------- -; READ COMMAND and start operation -;--------------------------------------------------- - - -h_readcommand: - clr r_bytep -#ifndef _DIS_FLASH_ - FLASH_COMMANDS ; muss zu erst sein.... -#endif - cset 0xAA,OW_READ_MEMORY_ADDR - cset 0x55,OW_WRITE_MEMORY_ADDR - cset 0x3C,OW_CONVERT - FW_CONFIG_INFO -#ifdef _CHANGEABLE_ID_ - CHANGE_ID_COMMANDS -#endif - ldi r_mode,OW_SLEEP - rjmp handle_end - - -h_readmemoryaddr: - cpi r_bytep,0 ;erstes Adressbyte ? - brne h_readmemory_addr_byte1 ;nein dann weiter - andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen - sts addr,r_rwbyte ;speichern des ersten bytes - rjmp handle_end_inc -h_readmemory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert! - ldi r_mode,OW_READ_MEMORY ;weiter zu read Memory - ;;ldi r_bcount,1 ;ist unten - ldi r_sendflag,1 ;jetzt sendet der Slave zum Master - clr r_bytep - rjmp h_readmemory2 -h_readmemory: - lds r_bytep,addr - inc r_bytep - sts addr,r_bytep - andi r_bytep,0x07 - breq h_readmemory_init_crc -h_readmemory2: - lds r_bytep,addr - ;andi r_bytep,0x1F ist oben - configZ pack,r_bytep - ld r_rwbyte,Z - ;ldi r_bcount,1 - rjmp handle_end ;sendet das Byte und geht zu h_readmemory -h_readmemory_init_crc:; init erstes CRC byte - lds r_rwbyte,crc - com r_rwbyte - lds r_temp,crc+1 - com r_temp - sts crcsave,r_temp - ldi r_mode,OW_READ_MEMORY_CRC1 - ;ldi r_bcount,1 - rjmp handle_end -h_readmemory_end: - ldi r_mode,OW_SLEEP - clr r_sendflag - rjmp handle_end -h_readmemorycrc1:;init zweites CRC Byte - lds r_rwbyte,crcsave - ;ldi r_bcount,1 - ldi r_mode,OW_READ_MEMORY_CRC2 - rjmp handle_end -h_readmemorycrc2:;weiteres senden..... nach zweitem Byte - lds r_temp,addr - andi r_temp,0xE0 - brne h_readmemory_end; ende des speichers - ldi r_mode,OW_READ_MEMORY - CRCInit1 ;Start with new CRC - rjmp h_readmemory2 - -h_writememoryaddr: - cpi r_bytep,0 ;erstes Adressbyte ? - brne h_writememory_addr_byte1 ;nein dann weiter - andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen - sts addr,r_rwbyte ;speichern des ersten bytes - inc r_bytep - ;ldi r_bcount,1 - rjmp handle_end -h_writememory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert! - ldi r_mode,OW_WRITE_MEMORY ;weiter zu read Memory - ;ldi r_bcount,1 ;; _________________________________________________in handle_end integrieren..... - lds r_bytep,addr - rjmp handle_end ;read Memory Byte -h_writememory: - lds r_bytep,addr - configZ pack,r_bytep - st Z,r_rwbyte - ;ldi r_bcount,1 - ldi r_mode,OW_WRITE_MEMORY_CRC1 - ldi r_sendflag,1 ;jetzt sendet der Slave zum Master - lds r_rwbyte,crc - com r_rwbyte - lds r_temp,crc+1 - com r_temp - sts crcsave,r_temp - rjmp handle_end -h_writememorycrc1: - lds r_rwbyte,crcsave - ;ldi r_bcount,1 - ldi r_mode,OW_WRITE_MEMORY_CRC2 - rjmp handle_end -h_writememorycrc2: - lds r_temp,addr - configZ pack,r_temp - ld r_rwbyte,Z - ;ldi r_bcount,1 - ldi r_mode,OW_WRITE_MEMORY_READBACK - rjmp handle_end -h_writememoryreadback: - ldi r_temp,0x00 - sts crc+1,r_temp - lds r_temp,addr - inc r_temp - sts addr,r_temp - sts crc,r_temp - ldi r_sendflag,0 - ;ldi r_bcount,1 - ldi r_mode,OW_WRITE_MEMORY - rjmp handle_end - -h_convert: - cpi r_bytep,0 ;erstes Adressbyte ? - brne h_convert_byte1 ;nein dann weiter - inc r_bytep - sts pack+0x20,r_rwbyte - ;ldi r_bcount,1 - rjmp handle_end -h_convert_byte1: ;zweies byte glesen go crc# - sts pack+0x21,r_rwbyte - lds r_rwbyte,crc - com r_rwbyte - lds r_temp,crc+1 - com r_temp - sts crcsave,r_temp - ldi r_mode,OW_CONVERT_CRC1 - ;ldi r_bcount,1 - ldi r_sendflag,1 - rjmp handle_end -h_convertcrc1: - lds r_rwbyte,crcsave - ;ldi r_bcount,1 - ldi r_mode,OW_CONVERT_CRC2 - rjmp handle_end -h_convertcrc2: - ldi r_temp,1 - sts gcontrol,r_temp - ;ldi r_bcount,1 - ldi r_mode,OW_CONVERT_CONV - ;clr r_sendflag - ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling -h_convert_conv: - ldi r_bcount,0 - ldi r_rwbyte,0 - rjmp handle_end_no_bcount - - - - -#include "../common/OWPinInterrupt.s" + +// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the +// distribution. +// * All advertising materials mentioning features or use of this +// software must display the following acknowledgement: This product +// includes software developed by tm3d.de and its contributors. +// * Neither the name of tm3d.de nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#define _CHANGEABLE_ID_ +#define _ZERO_POLLING_ + +#include "../common/OWConfig.s" +#include "../common/OWCRC16.s" + +.extern pack,8 +.comm addr,1 ;zweites Adressbyte ist unnoetig (Warum auch immer fuer 32 Byte 16 Bit Adressen verwendet werden....) +.comm crcsave,1 ; zwischenspeicherspeicher fuer crc nur zweites byte.... +//.extern am2302_temp,2 + + + +.macro CHIP_INIT +.endm + +.macro COMMAND_TABLE + rjmp h_readmemoryaddr + rjmp h_readmemory + rjmp h_readmemorycrc1 + rjmp h_readmemorycrc2 + rjmp h_writememoryaddr + rjmp h_writememory + rjmp h_writememorycrc1 + rjmp h_writememorycrc2 + rjmp h_writememoryreadback + rjmp h_convert + rjmp h_convertcrc1 + rjmp h_convertcrc2 + rjmp h_convert_conv +.endm + +#include "../common/OWRomFunctions.s" +#include "../common/OWTimerInterrupt.s" + + + +; Ab hier Geraeteabhaenging +#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+0 +#define OW_READ_MEMORY OW_FIRST_COMMAND+1 +#define OW_READ_MEMORY_CRC1 OW_FIRST_COMMAND+2 +#define OW_READ_MEMORY_CRC2 OW_FIRST_COMMAND+3 +#define OW_WRITE_MEMORY_ADDR OW_FIRST_COMMAND+4 +#define OW_WRITE_MEMORY OW_FIRST_COMMAND+5 +#define OW_WRITE_MEMORY_CRC1 OW_FIRST_COMMAND+6 +#define OW_WRITE_MEMORY_CRC2 OW_FIRST_COMMAND+7 +#define OW_WRITE_MEMORY_READBACK OW_FIRST_COMMAND+8 +#define OW_CONVERT OW_FIRST_COMMAND+9 +#define OW_CONVERT_CRC1 OW_FIRST_COMMAND+10 +#define OW_CONVERT_CRC2 OW_FIRST_COMMAND+11 +#define OW_CONVERT_CONV OW_FIRST_COMMAND+12 + +;--------------------------------------------------- +; READ COMMAND and start operation +;--------------------------------------------------- + + +h_readcommand: + clr r_bytep +#ifndef _DIS_FLASH_ + FLASH_COMMANDS ; muss zu erst sein.... +#endif + cset 0xAA,OW_READ_MEMORY_ADDR + cset 0x55,OW_WRITE_MEMORY_ADDR + cset 0x3C,OW_CONVERT + FW_CONFIG_INFO +#ifdef _CHANGEABLE_ID_ + CHANGE_ID_COMMANDS +#endif + ldi r_mode,OW_SLEEP + rjmp handle_end + + +h_readmemoryaddr: + cpi r_bytep,0 ;erstes Adressbyte ? + brne h_readmemory_addr_byte1 ;nein dann weiter + andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen + sts addr,r_rwbyte ;speichern des ersten bytes + rjmp handle_end_inc +h_readmemory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert! + ldi r_mode,OW_READ_MEMORY ;weiter zu read Memory + ;;ldi r_bcount,1 ;ist unten + ldi r_sendflag,1 ;jetzt sendet der Slave zum Master + clr r_bytep + rjmp h_readmemory2 +h_readmemory: + lds r_bytep,addr + inc r_bytep + sts addr,r_bytep + andi r_bytep,0x07 + breq h_readmemory_init_crc +h_readmemory2: + lds r_bytep,addr + ;andi r_bytep,0x1F ist oben + configZ pack,r_bytep + ld r_rwbyte,Z + ;ldi r_bcount,1 + rjmp handle_end ;sendet das Byte und geht zu h_readmemory +h_readmemory_init_crc:; init erstes CRC byte + lds r_rwbyte,crc + com r_rwbyte + lds r_temp,crc+1 + com r_temp + sts crcsave,r_temp + ldi r_mode,OW_READ_MEMORY_CRC1 + ;ldi r_bcount,1 + rjmp handle_end +h_readmemory_end: + ldi r_mode,OW_SLEEP + clr r_sendflag + rjmp handle_end +h_readmemorycrc1:;init zweites CRC Byte + lds r_rwbyte,crcsave + ;ldi r_bcount,1 + ldi r_mode,OW_READ_MEMORY_CRC2 + rjmp handle_end +h_readmemorycrc2:;weiteres senden..... nach zweitem Byte + lds r_temp,addr + andi r_temp,0xE0 + brne h_readmemory_end; ende des speichers + ldi r_mode,OW_READ_MEMORY + CRCInit1 ;Start with new CRC + rjmp h_readmemory2 + +h_writememoryaddr: + cpi r_bytep,0 ;erstes Adressbyte ? + brne h_writememory_addr_byte1 ;nein dann weiter + andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen + sts addr,r_rwbyte ;speichern des ersten bytes + inc r_bytep + ;ldi r_bcount,1 + rjmp handle_end +h_writememory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert! + ldi r_mode,OW_WRITE_MEMORY ;weiter zu read Memory + ;ldi r_bcount,1 ;; _________________________________________________in handle_end integrieren..... + lds r_bytep,addr + rjmp handle_end ;read Memory Byte +h_writememory: + lds r_bytep,addr + configZ pack,r_bytep + st Z,r_rwbyte + ;ldi r_bcount,1 + ldi r_mode,OW_WRITE_MEMORY_CRC1 + ldi r_sendflag,1 ;jetzt sendet der Slave zum Master + lds r_rwbyte,crc + com r_rwbyte + lds r_temp,crc+1 + com r_temp + sts crcsave,r_temp + rjmp handle_end +h_writememorycrc1: + lds r_rwbyte,crcsave + ;ldi r_bcount,1 + ldi r_mode,OW_WRITE_MEMORY_CRC2 + rjmp handle_end +h_writememorycrc2: + lds r_temp,addr + configZ pack,r_temp + ld r_rwbyte,Z + ;ldi r_bcount,1 + ldi r_mode,OW_WRITE_MEMORY_READBACK + rjmp handle_end +h_writememoryreadback: + ldi r_temp,0x00 + sts crc+1,r_temp + lds r_temp,addr + inc r_temp + sts addr,r_temp + sts crc,r_temp + ldi r_sendflag,0 + ;ldi r_bcount,1 + ldi r_mode,OW_WRITE_MEMORY + rjmp handle_end + +h_convert: + cpi r_bytep,0 ;erstes Adressbyte ? + brne h_convert_byte1 ;nein dann weiter + inc r_bytep + sts pack+0x20,r_rwbyte + ;ldi r_bcount,1 + rjmp handle_end +h_convert_byte1: ;zweies byte glesen go crc# + sts pack+0x21,r_rwbyte + lds r_rwbyte,crc + com r_rwbyte + lds r_temp,crc+1 + com r_temp + sts crcsave,r_temp + ldi r_mode,OW_CONVERT_CRC1 + ;ldi r_bcount,1 + ldi r_sendflag,1 + rjmp handle_end +h_convertcrc1: + lds r_rwbyte,crcsave + ;ldi r_bcount,1 + ldi r_mode,OW_CONVERT_CRC2 + rjmp handle_end +h_convertcrc2: + ldi r_temp,1 + sts gcontrol,r_temp + ;ldi r_bcount,1 + ldi r_mode,OW_CONVERT_CONV + ;clr r_sendflag + ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling +h_convert_conv: + ldi r_bcount,0 + ldi r_rwbyte,0 + rjmp handle_end_no_bcount + + + + +#include "../common/OWPinInterrupt.s" .end \ No newline at end of file diff --git a/common/I2C/BMP280.c b/common/I2C/BMP280.c index 3fdc81d..27adba5 100644 --- a/common/I2C/BMP280.c +++ b/common/I2C/BMP280.c @@ -1,158 +1,158 @@ -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include "USI_TWI_Master.h" - -uint16_t dig_T1; -int16_t dig_T2; -int16_t dig_T3; -uint16_t dig_P1; -int16_t dig_P2; -int16_t dig_P3; -int16_t dig_P4; -int16_t dig_P5; -int16_t dig_P6; -int16_t dig_P7; -int16_t dig_P8; -int16_t dig_P9; - - - - -short bmp280ReadShort(unsigned char address) -{ - char msb, lsb; - short data; - I2c_StartCondition(); - I2c_WriteByte(0xEC); - I2c_WriteByte(address); - I2c_StopCondition(); - I2c_StartCondition(); - I2c_WriteByte(0xED); - lsb=I2c_ReadByte(ACK); - msb=I2c_ReadByte(NO_ACK); - I2c_StopCondition(); - - - - data = msb << 8; - data |= lsb; - - return data; -} - -void bmp280Init(void) { - dig_T1=bmp280ReadShort(0x88); - dig_T2=bmp280ReadShort(0x8A); - dig_T3=bmp280ReadShort(0x8C); - dig_P1=bmp280ReadShort(0x8E); - dig_P2=bmp280ReadShort(0x90); - dig_P3=bmp280ReadShort(0x92); - dig_P4=bmp280ReadShort(0x94); - dig_P5=bmp280ReadShort(0x96); - dig_P6=bmp280ReadShort(0x98); - dig_P7=bmp280ReadShort(0x9A); - dig_P8=bmp280ReadShort(0x9C); - dig_P9=bmp280ReadShort(0x9E); - I2c_StartCondition(); - I2c_WriteByte(0xEC); - I2c_WriteByte(0xF4); - I2c_WriteByte(0b01010111); //2x Temp over 16x Press over Normal mode - I2c_WriteByte(0b11100000); //4s time / no IIfilter - I2c_StopCondition(); - - -} -int32_t bmp280ReadTemp(void) { - uint8_t msb, lsb,xlsb; - volatile int32_t data; - I2c_StartCondition(); - I2c_WriteByte(0xEC); - I2c_WriteByte(0xFA); - I2c_StopCondition(); - I2c_StartCondition(); - I2c_WriteByte(0xED); - msb=I2c_ReadByte(ACK); - lsb=I2c_ReadByte(ACK); - xlsb=I2c_ReadByte(NO_ACK); - I2c_StopCondition(); - - data = (int32_t)msb << 12; - data |= (int16_t)lsb<<4; - data|=xlsb>>4; - - return data; - - -} -int32_t bmp280ReadPressure(uint8_t oss) { - uint8_t msb, lsb,xlsb; - volatile int32_t data; - I2c_StartCondition(); - I2c_WriteByte(0xEC); - I2c_WriteByte(0xF7); - I2c_StopCondition(); - I2c_StartCondition(); - I2c_WriteByte(0xED); - msb=I2c_ReadByte(ACK); - lsb=I2c_ReadByte(ACK); - xlsb=I2c_ReadByte(NO_ACK); - I2c_StopCondition(); - - data = (int32_t)msb << 12; - data |= (int16_t)lsb<<4; - data|=xlsb>>4; - - return data; - - -} -void bmp280ConvertInt(int32_t * temperature,uint32_t *pressure,uint8_t oss) { - int32_t var1,var2,T,t_fine; - - - int32_t adc_T=bmp280ReadTemp(); - var1 = ((((adc_T>>3) - ((int32_t)dig_T1<<1))) * ((int32_t)dig_T2)) >> 11; - var2 = ((((((adc_T>>4) - ((int32_t)dig_T1)) * ((adc_T>>4) - (int32_t)dig_T1))) >> 12) *((int32_t)dig_T3)) >> 14; - t_fine = var1 + var2; - T = (t_fine * 5 + 128) >> 8; - *temperature=T; - int32_t adc_P= bmp280ReadPressure(oss); - uint32_t p; - var1 = (((int32_t)t_fine)>>1) - (int32_t)64000; - var2 = (((var1>>2) * (var1>>2)) >> 11 ) * ((int32_t)dig_P6); - var2 = var2 + ((var1*((int32_t)dig_P5))<<1); - var2 = (var2>>2)+(((int32_t)dig_P4)<<16); - var1 = (((dig_P3 * (((var1>>2) * (var1>>2)) >> 13 )) >> 3) + ((((int32_t)dig_P2) * var1)>>1))>>18; - var1 =((((32768+var1))*((int32_t)dig_P1))>>15); - if (var1 == 0) { - return ; // avoid exception caused by division by zero - } - p = (((uint32_t)(((int32_t)1048576)-adc_P)-(var2>>12)))*3125; - if (p < 0x80000000){ - p = (p << 1) / ((uint32_t)var1); - }else{ - p = (p / (uint32_t)var1) * 2; - } - var1 = (((int32_t)dig_P9) * ((int32_t)(((p>>3) * (p>>3))>>13)))>>12; - var2 = (((int32_t)(p>>2)) * ((int32_t)dig_P8))>>13; - p = (uint32_t)((int32_t)p + ((var1 + var2 + dig_P7) >> 4)); - *pressure=p; - -} -void bmp280Convert(double * temperature, double * pressure,uint8_t oss) { - - uint32_t p; - int32_t T; - bmp280ConvertInt(&T,&p,oss); - *temperature=T/100.0; - *pressure=p/100.0; -} - - - - - +#define F_CPU 8000000UL +#include +#include +#include +#include +#include +#include "USI_TWI_Master.h" + +uint16_t dig_T1; +int16_t dig_T2; +int16_t dig_T3; +uint16_t dig_P1; +int16_t dig_P2; +int16_t dig_P3; +int16_t dig_P4; +int16_t dig_P5; +int16_t dig_P6; +int16_t dig_P7; +int16_t dig_P8; +int16_t dig_P9; + + + + +short bmp280ReadShort(unsigned char address) +{ + char msb, lsb; + short data; + I2c_StartCondition(); + I2c_WriteByte(0xEC); + I2c_WriteByte(address); + I2c_StopCondition(); + I2c_StartCondition(); + I2c_WriteByte(0xED); + lsb=I2c_ReadByte(ACK); + msb=I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + + + + data = msb << 8; + data |= lsb; + + return data; +} + +void bmp280Init(void) { + dig_T1=bmp280ReadShort(0x88); + dig_T2=bmp280ReadShort(0x8A); + dig_T3=bmp280ReadShort(0x8C); + dig_P1=bmp280ReadShort(0x8E); + dig_P2=bmp280ReadShort(0x90); + dig_P3=bmp280ReadShort(0x92); + dig_P4=bmp280ReadShort(0x94); + dig_P5=bmp280ReadShort(0x96); + dig_P6=bmp280ReadShort(0x98); + dig_P7=bmp280ReadShort(0x9A); + dig_P8=bmp280ReadShort(0x9C); + dig_P9=bmp280ReadShort(0x9E); + I2c_StartCondition(); + I2c_WriteByte(0xEC); + I2c_WriteByte(0xF4); + I2c_WriteByte(0b01010111); //2x Temp over 16x Press over Normal mode + I2c_WriteByte(0b11100000); //4s time / no IIfilter + I2c_StopCondition(); + + +} +int32_t bmp280ReadTemp(void) { + uint8_t msb, lsb,xlsb; + volatile int32_t data; + I2c_StartCondition(); + I2c_WriteByte(0xEC); + I2c_WriteByte(0xFA); + I2c_StopCondition(); + I2c_StartCondition(); + I2c_WriteByte(0xED); + msb=I2c_ReadByte(ACK); + lsb=I2c_ReadByte(ACK); + xlsb=I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + + data = (int32_t)msb << 12; + data |= (int16_t)lsb<<4; + data|=xlsb>>4; + + return data; + + +} +int32_t bmp280ReadPressure(uint8_t oss) { + uint8_t msb, lsb,xlsb; + volatile int32_t data; + I2c_StartCondition(); + I2c_WriteByte(0xEC); + I2c_WriteByte(0xF7); + I2c_StopCondition(); + I2c_StartCondition(); + I2c_WriteByte(0xED); + msb=I2c_ReadByte(ACK); + lsb=I2c_ReadByte(ACK); + xlsb=I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + + data = (int32_t)msb << 12; + data |= (int16_t)lsb<<4; + data|=xlsb>>4; + + return data; + + +} +void bmp280ConvertInt(int32_t * temperature,uint32_t *pressure,uint8_t oss) { + int32_t var1,var2,T,t_fine; + + + int32_t adc_T=bmp280ReadTemp(); + var1 = ((((adc_T>>3) - ((int32_t)dig_T1<<1))) * ((int32_t)dig_T2)) >> 11; + var2 = ((((((adc_T>>4) - ((int32_t)dig_T1)) * ((adc_T>>4) - (int32_t)dig_T1))) >> 12) *((int32_t)dig_T3)) >> 14; + t_fine = var1 + var2; + T = (t_fine * 5 + 128) >> 8; + *temperature=T; + int32_t adc_P= bmp280ReadPressure(oss); + uint32_t p; + var1 = (((int32_t)t_fine)>>1) - (int32_t)64000; + var2 = (((var1>>2) * (var1>>2)) >> 11 ) * ((int32_t)dig_P6); + var2 = var2 + ((var1*((int32_t)dig_P5))<<1); + var2 = (var2>>2)+(((int32_t)dig_P4)<<16); + var1 = (((dig_P3 * (((var1>>2) * (var1>>2)) >> 13 )) >> 3) + ((((int32_t)dig_P2) * var1)>>1))>>18; + var1 =((((32768+var1))*((int32_t)dig_P1))>>15); + if (var1 == 0) { + return ; // avoid exception caused by division by zero + } + p = (((uint32_t)(((int32_t)1048576)-adc_P)-(var2>>12)))*3125; + if (p < 0x80000000){ + p = (p << 1) / ((uint32_t)var1); + }else{ + p = (p / (uint32_t)var1) * 2; + } + var1 = (((int32_t)dig_P9) * ((int32_t)(((p>>3) * (p>>3))>>13)))>>12; + var2 = (((int32_t)(p>>2)) * ((int32_t)dig_P8))>>13; + p = (uint32_t)((int32_t)p + ((var1 + var2 + dig_P7) >> 4)); + *pressure=p; + +} +void bmp280Convert(double * temperature, double * pressure,uint8_t oss) { + + uint32_t p; + int32_t T; + bmp280ConvertInt(&T,&p,oss); + *temperature=T/100.0; + *pressure=p/100.0; +} + + + + + diff --git a/common/I2C/BMP280.h b/common/I2C/BMP280.h index 0fab3c5..8ea7059 100644 --- a/common/I2C/BMP280.h +++ b/common/I2C/BMP280.h @@ -1,13 +1,13 @@ -#ifndef BMP280_H -#define BMP280_H - - - -void bmp280Init(void); -int32_t bmp280ReadTemp(void); -int32_t bmp280ReadPressure(uint8_t oss); -void bmp280Convert(double * temperature, double * pressure,uint8_t oss); -void bmp280ConvertInt(int32_t * temperature,uint32_t *pressure,uint8_t oss); - - +#ifndef BMP280_H +#define BMP280_H + + + +void bmp280Init(void); +int32_t bmp280ReadTemp(void); +int32_t bmp280ReadPressure(uint8_t oss); +void bmp280Convert(double * temperature, double * pressure,uint8_t oss); +void bmp280ConvertInt(int32_t * temperature,uint32_t *pressure,uint8_t oss); + + #endif \ No newline at end of file diff --git a/common/I2C/MAX1164x.c b/common/I2C/MAX1164x.c index 8160ac2..404d82d 100644 --- a/common/I2C/MAX1164x.c +++ b/common/I2C/MAX1164x.c @@ -1,55 +1,55 @@ -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include "USI_TWI_Master.h" -#include "MAX1164x.h" - -void MAX1164x_init(){ - - -} -void MAX1164x_config(uint8_t setup,uint8_t config){ - I2c_StartCondition(); - I2c_WriteByte (0b01101100); - I2c_WriteByte (setup|0x80); - I2c_WriteByte (config); - I2c_StopCondition(); - -} -int16_t MAX1164x_read() { - uint16_t res; - I2c_StartCondition(); - I2c_WriteByte (0b01101101); - //DDR_USI&=~(1< +#include +#include +#include +#include +#include "USI_TWI_Master.h" +#include "MAX1164x.h" + +void MAX1164x_init(){ + + +} +void MAX1164x_config(uint8_t setup,uint8_t config){ + I2c_StartCondition(); + I2c_WriteByte (0b01101100); + I2c_WriteByte (setup|0x80); + I2c_WriteByte (config); + I2c_StopCondition(); + +} +int16_t MAX1164x_read(void) { + uint16_t res; + I2c_StartCondition(); + I2c_WriteByte (0b01101101); + //DDR_USI&=~(1< - -#include - - -#include "USI_TWI_Master.h" -#include "MAX44009.h" - -uint8_t checkMAX44009(uint8_t nr) { - volatile uint8_t b1; - nr=(nr<<1)&0x02f; - - I2c_StartCondition(); - I2c_WriteByte(0b10010100|nr); - I2c_WriteByte(0x03); - I2c_StartCondition(); - I2c_WriteByte (0b10010101|nr); - b1 =I2c_ReadByte(NO_ACK); - I2c_StopCondition(); - return b1!=0xFF; - -} - - -double MAX44009getlux(uint8_t nr) { - volatile uint8_t b1,b2; - nr=(nr<<1)&0x02f; - - I2c_StartCondition(); - I2c_WriteByte(0b10010100|nr); - I2c_WriteByte(0x03); - I2c_StartCondition(); - I2c_WriteByte (0b10010101|nr); - b1 =I2c_ReadByte(NO_ACK); - I2c_StopCondition(); - I2c_StartCondition(); - I2c_WriteByte(0b10010100|nr); - I2c_WriteByte(0x04); - I2c_StartCondition(); - I2c_WriteByte (0b10010101|nr); - b2 =I2c_ReadByte(NO_ACK); - I2c_StopCondition(); - uint8_t exponent = (b1 & 0xF0) >> 4;// upper four bits of high byte register - uint8_t mantissa = (b1 & 0x0F) << 4;// lower four bits of high byte register = - // upper four bits of mantissa - mantissa += b2 & 0x0F; // lower four bits of low byte register = - // lower four bits of mantissa - - return (double)mantissa * (double)(1 << (uint16_t)exponent) * 0.045; - - - -} +// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the +// distribution. +// * All advertising materials mentioning features or use of this +// software must display the following acknowledgement: This product +// includes software developed by tm3d.de and its contributors. +// * Neither the name of tm3d.de nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#define F_CPU 8000000UL +#include + +#include + + +#include "USI_TWI_Master.h" +#include "MAX44009.h" + +uint8_t checkMAX44009(uint8_t nr) { + volatile uint8_t b1; + nr=(nr<<1)&0x02f; + + I2c_StartCondition(); + I2c_WriteByte(0b10010100|nr); + I2c_WriteByte(0x03); + I2c_StartCondition(); + I2c_WriteByte (0b10010101|nr); + b1 =I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + return b1!=0xFF; + +} + + +double MAX44009getlux(uint8_t nr) { + volatile uint8_t b1,b2; + nr=(nr<<1)&0x02f; + + I2c_StartCondition(); + I2c_WriteByte(0b10010100|nr); + I2c_WriteByte(0x03); + I2c_StartCondition(); + I2c_WriteByte (0b10010101|nr); + b1 =I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + I2c_StartCondition(); + I2c_WriteByte(0b10010100|nr); + I2c_WriteByte(0x04); + I2c_StartCondition(); + I2c_WriteByte (0b10010101|nr); + b2 =I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + uint8_t exponent = (b1 & 0xF0) >> 4;// upper four bits of high byte register + uint8_t mantissa = (b1 & 0x0F) << 4;// lower four bits of high byte register = + // upper four bits of mantissa + mantissa += b2 & 0x0F; // lower four bits of low byte register = + // lower four bits of mantissa + + return (double)mantissa * (double)(1 << (uint16_t)exponent) * 0.045; + + + +} diff --git a/common/I2C/MAX44009.h b/common/I2C/MAX44009.h index 366a236..a49b98f 100644 --- a/common/I2C/MAX44009.h +++ b/common/I2C/MAX44009.h @@ -1,38 +1,38 @@ -#ifndef MAX44009_H -#define MAX44009_H -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -double MAX44009getlux(uint8_t nr); -uint8_t checkMAX44009(uint8_t nr); - +#ifndef MAX44009_H +#define MAX44009_H +// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the +// distribution. +// * All advertising materials mentioning features or use of this +// software must display the following acknowledgement: This product +// includes software developed by tm3d.de and its contributors. +// * Neither the name of tm3d.de nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +double MAX44009getlux(uint8_t nr); +uint8_t checkMAX44009(uint8_t nr); + #endif \ No newline at end of file diff --git a/common/I2C/SHT2x.c b/common/I2C/SHT2x.c index effe916..ae9f352 100644 --- a/common/I2C/SHT2x.c +++ b/common/I2C/SHT2x.c @@ -1,216 +1,216 @@ -//============================================================================== -// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland -//============================================================================== -// Project : SHT2x Sample Code (V1.2) -// File : SHT2x.c -// Author : MST -// Controller: NEC V850/SG3 (uPD70F3740) -// Compiler : IAR compiler for V850 (3.50A) -// Brief : Sensor layer. Functions for sensor access -//============================================================================== -//---------- Includes ---------------------------------------------------------- -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include "USI_TWI_Master.h" -#include "SHT2x.h" - -const uint16_t POLYNOMIAL = 0x131; //P(x)=x^8+x^5+x^4+1 = 100110001 - - -//============================================================================== -uint8_t SHT2x_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum) -//============================================================================== -{ - uint8_t crc = 0; - uint8_t byteCtr; - //calculates 8-Bit checksum with given polynomial - for (byteCtr = 0; byteCtr < nbrOfBytes; ++byteCtr) - { crc ^= (data[byteCtr]); - for (uint8_t bit = 8; bit > 0; --bit) - { if (crc & 0x80) crc = (crc << 1) ^ POLYNOMIAL; - else crc = (crc << 1); - } - } - if (crc != checksum) return CHECKSUM_ERROR; - else return 0; -} -//=========================================================================== -uint8_t SHT2x_ReadUserRegister(uint8_t *pRegisterValue) -//=========================================================================== -{ - uint8_t checksum; //variable for checksum byte - uint8_t error=0; //variable for error code - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); - error |= I2c_WriteByte (USER_REG_R); - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_R); - *pRegisterValue = I2c_ReadByte(ACK); - checksum=I2c_ReadByte(NO_ACK); - error |= SHT2x_CheckCrc (pRegisterValue,1,checksum); - I2c_StopCondition(); - return error; -} -//=========================================================================== -uint8_t SHT2x_WriteUserRegister(uint8_t *pRegisterValue) -//=========================================================================== -{ - uint8_t error=0; //variable for error code - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); - error |= I2c_WriteByte (USER_REG_W); - error |= I2c_WriteByte (*pRegisterValue); - I2c_StopCondition(); - return error; -} -//=========================================================================== -uint8_t SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand) -//=========================================================================== -{ - uint8_t checksum; //checksum - uint8_t data[2]; //data array for checksum verification - uint8_t error=0; //error variable - uint16_t i; //counting variable - //-- write I2C sensor address and command -- - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr - switch(eSHT2xMeasureType) - { case HUMIDITY: error |= I2c_WriteByte (TRIG_RH_MEASUREMENT_HM); break; - case TEMP : error |= I2c_WriteByte (TRIG_T_MEASUREMENT_HM); break; - //default: assert(0); - } - //-- wait until hold master is released -- - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_R); - //SCL=HIGH; // set SCL I/O port as input - DDR_USI&=~(1<>8) & 0xFF; - *pMeasurand|=0xFF & (data[1] = I2c_ReadByte(ACK)); -// pMeasurand->s16.u8H = data[0] = I2c_ReadByte(ACK); -// pMeasurand->s16.u8L = data[1] = I2c_ReadByte(ACK); - - checksum=I2c_ReadByte(NO_ACK); - //-- verify checksum -- - error |= SHT2x_CheckCrc (data,2,checksum); - I2c_StopCondition(); - return error; -} -//=========================================================================== -uint8_t SHT2x_MeasurePoll(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand) -//=========================================================================== -{ - uint8_t checksum; //checksum - uint8_t data[2]; //data array for checksum verification - uint8_t error=0; //error variable - uint16_t i=0; //counting variable - //-- write I2C sensor address and command -- - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr - switch(eSHT2xMeasureType) - { case HUMIDITY: error |= I2c_WriteByte (TRIG_RH_MEASUREMENT_POLL); break; - case TEMP : error |= I2c_WriteByte (TRIG_T_MEASUREMENT_POLL); break; - //default: assert(0); - } - //-- poll every 10ms for measurement ready. Timeout after 20 retries (200ms)-- - do - { I2c_StartCondition(); - _delay_ms(200); //delay 10ms - if(i++ >= 20) break; - } while(I2c_WriteByte (I2C_ADR_R) == ACK_ERROR); - if (i>=20) error |= TIME_OUT_ERROR; - //-- read two data bytes and one checksum byte -- - data[0]=I2c_ReadByte(ACK); - data[1]=I2c_ReadByte(ACK); - *pMeasurand=(data[0]<<8)|data[1]; - -// pMeasurand->s16.u8H = data[0] = I2c_ReadByte(ACK); -// pMeasurand->s16.u8L = data[1] = I2c_ReadByte(ACK); - checksum=I2c_ReadByte(NO_ACK); - //-- verify checksum -- - error |= SHT2x_CheckCrc (data,2,checksum); - I2c_StopCondition(); - return error; -} -//=========================================================================== -uint8_t SHT2x_SoftReset() -//=========================================================================== -{ - uint8_t error=0; //error variable - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr - error |= I2c_WriteByte (SOFT_RESET); // Command - I2c_StopCondition(); - _delay_ms(15); // wait till sensor has restarted - return error; -} -//============================================================================== -float SHT2x_CalcRH(uint16_t u16sRH) -//============================================================================== -{ - double humidityRH; // variable for result - u16sRH &= ~0x0003; // clear bits [1..0] (status bits) - //-- calculate relative humidity [%RH] -- - humidityRH = -6.0 + 125.0/65536 * (double)u16sRH; // RH= -6 + 125 * SRH/2^16 - return humidityRH; -} -//============================================================================== -float SHT2x_CalcTemperatureC(uint16_t u16sT) -//============================================================================== -{ - double temperatureC; // variable for result - u16sT &= ~0x0003; // clear bits [1..0] (status bits) - //-- calculate temperature [°C] -- - temperatureC= -46.85 + 175.72/65536 *(double)u16sT; //T= -46.85 + 175.72 * ST/2^16 - return temperatureC; -} -//============================================================================== -uint8_t SHT2x_GetSerialNumber(uint8_t u8SerialNumber[]) -//============================================================================== -{ - uint8_t error=0; //error variable - //Read from memory location 1 - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); //I2C address - error |= I2c_WriteByte (0xFA); //Command for readout on-chip memory - error |= I2c_WriteByte (0x0F); //on-chip memory address - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_R); //I2C address - u8SerialNumber[5] = I2c_ReadByte(ACK); //Read SNB_3 - I2c_ReadByte(ACK); //Read CRC SNB_3 (CRC is not analyzed) - u8SerialNumber[4] = I2c_ReadByte(ACK); //Read SNB_2 - I2c_ReadByte(ACK); //Read CRC SNB_2 (CRC is not analyzed) - u8SerialNumber[3] = I2c_ReadByte(ACK); //Read SNB_1 - I2c_ReadByte(ACK); //Read CRC SNB_1 (CRC is not analyzed) - u8SerialNumber[2] = I2c_ReadByte(ACK); //Read SNB_0 - I2c_ReadByte(NO_ACK); //Read CRC SNB_0 (CRC is not analyzed) - I2c_StopCondition(); - //Read from memory location 2 - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); //I2C address - error |= I2c_WriteByte (0xFC); //Command for readout on-chip memory - error |= I2c_WriteByte (0xC9); //on-chip memory address - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_R); //I2C address - u8SerialNumber[1] = I2c_ReadByte(ACK); //Read SNC_1 - u8SerialNumber[0] = I2c_ReadByte(ACK); //Read SNC_0 - I2c_ReadByte(ACK); //Read CRC SNC0/1 (CRC is not analyzed) - u8SerialNumber[7] = I2c_ReadByte(ACK); //Read SNA_1 - u8SerialNumber[6] = I2c_ReadByte(ACK); //Read SNA_0 - I2c_ReadByte(NO_ACK); //Read CRC SNA0/1 (CRC is not analyzed) - I2c_StopCondition(); - return error; -} \ No newline at end of file +//============================================================================== +// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland +//============================================================================== +// Project : SHT2x Sample Code (V1.2) +// File : SHT2x.c +// Author : MST +// Controller: NEC V850/SG3 (uPD70F3740) +// Compiler : IAR compiler for V850 (3.50A) +// Brief : Sensor layer. Functions for sensor access +//============================================================================== +//---------- Includes ---------------------------------------------------------- +#define F_CPU 8000000UL +#include +#include +#include +#include +#include +#include "USI_TWI_Master.h" +#include "SHT2x.h" + +const uint16_t POLYNOMIAL = 0x131; //P(x)=x^8+x^5+x^4+1 = 100110001 + + +//============================================================================== +uint8_t SHT2x_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum) +//============================================================================== +{ + uint8_t crc = 0; + uint8_t byteCtr; + //calculates 8-Bit checksum with given polynomial + for (byteCtr = 0; byteCtr < nbrOfBytes; ++byteCtr) + { crc ^= (data[byteCtr]); + for (uint8_t bit = 8; bit > 0; --bit) + { if (crc & 0x80) crc = (crc << 1) ^ POLYNOMIAL; + else crc = (crc << 1); + } + } + if (crc != checksum) return CHECKSUM_ERROR; + else return 0; +} +//=========================================================================== +uint8_t SHT2x_ReadUserRegister(uint8_t *pRegisterValue) +//=========================================================================== +{ + uint8_t checksum; //variable for checksum byte + uint8_t error=0; //variable for error code + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); + error |= I2c_WriteByte (USER_REG_R); + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_R); + *pRegisterValue = I2c_ReadByte(ACK); + checksum=I2c_ReadByte(NO_ACK); + error |= SHT2x_CheckCrc (pRegisterValue,1,checksum); + I2c_StopCondition(); + return error; +} +//=========================================================================== +uint8_t SHT2x_WriteUserRegister(uint8_t *pRegisterValue) +//=========================================================================== +{ + uint8_t error=0; //variable for error code + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); + error |= I2c_WriteByte (USER_REG_W); + error |= I2c_WriteByte (*pRegisterValue); + I2c_StopCondition(); + return error; +} +//=========================================================================== +uint8_t SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand) +//=========================================================================== +{ + uint8_t checksum; //checksum + uint8_t data[2]; //data array for checksum verification + uint8_t error=0; //error variable + uint16_t i; //counting variable + //-- write I2C sensor address and command -- + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr + switch(eSHT2xMeasureType) + { case HUMIDITY: error |= I2c_WriteByte (TRIG_RH_MEASUREMENT_HM); break; + case TEMP : error |= I2c_WriteByte (TRIG_T_MEASUREMENT_HM); break; + //default: assert(0); + } + //-- wait until hold master is released -- + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_R); + //SCL=HIGH; // set SCL I/O port as input + DDR_USI&=~(1<>8) & 0xFF; + *pMeasurand|=0xFF & (data[1] = I2c_ReadByte(ACK)); +// pMeasurand->s16.u8H = data[0] = I2c_ReadByte(ACK); +// pMeasurand->s16.u8L = data[1] = I2c_ReadByte(ACK); + + checksum=I2c_ReadByte(NO_ACK); + //-- verify checksum -- + error |= SHT2x_CheckCrc (data,2,checksum); + I2c_StopCondition(); + return error; +} +//=========================================================================== +uint8_t SHT2x_MeasurePoll(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand) +//=========================================================================== +{ + uint8_t checksum; //checksum + uint8_t data[2]; //data array for checksum verification + uint8_t error=0; //error variable + uint16_t i=0; //counting variable + //-- write I2C sensor address and command -- + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr + switch(eSHT2xMeasureType) + { case HUMIDITY: error |= I2c_WriteByte (TRIG_RH_MEASUREMENT_POLL); break; + case TEMP : error |= I2c_WriteByte (TRIG_T_MEASUREMENT_POLL); break; + //default: assert(0); + } + //-- poll every 10ms for measurement ready. Timeout after 20 retries (200ms)-- + do + { I2c_StartCondition(); + _delay_ms(200); //delay 10ms + if(i++ >= 20) break; + } while(I2c_WriteByte (I2C_ADR_R) == ACK_ERROR); + if (i>=20) error |= TIME_OUT_ERROR; + //-- read two data bytes and one checksum byte -- + data[0]=I2c_ReadByte(ACK); + data[1]=I2c_ReadByte(ACK); + *pMeasurand=(data[0]<<8)|data[1]; + +// pMeasurand->s16.u8H = data[0] = I2c_ReadByte(ACK); +// pMeasurand->s16.u8L = data[1] = I2c_ReadByte(ACK); + checksum=I2c_ReadByte(NO_ACK); + //-- verify checksum -- + error |= SHT2x_CheckCrc (data,2,checksum); + I2c_StopCondition(); + return error; +} +//=========================================================================== +uint8_t SHT2x_SoftReset(void) +//=========================================================================== +{ + uint8_t error=0; //error variable + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr + error |= I2c_WriteByte (SOFT_RESET); // Command + I2c_StopCondition(); + _delay_ms(15); // wait till sensor has restarted + return error; +} +//============================================================================== +float SHT2x_CalcRH(uint16_t u16sRH) +//============================================================================== +{ + double humidityRH; // variable for result + u16sRH &= ~0x0003; // clear bits [1..0] (status bits) + //-- calculate relative humidity [%RH] -- + humidityRH = -6.0 + 125.0/65536 * (double)u16sRH; // RH= -6 + 125 * SRH/2^16 + return humidityRH; +} +//============================================================================== +float SHT2x_CalcTemperatureC(uint16_t u16sT) +//============================================================================== +{ + double temperatureC; // variable for result + u16sT &= ~0x0003; // clear bits [1..0] (status bits) + //-- calculate temperature [°C] -- + temperatureC= -46.85 + 175.72/65536 *(double)u16sT; //T= -46.85 + 175.72 * ST/2^16 + return temperatureC; +} +//============================================================================== +uint8_t SHT2x_GetSerialNumber(uint8_t u8SerialNumber[]) +//============================================================================== +{ + uint8_t error=0; //error variable + //Read from memory location 1 + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); //I2C address + error |= I2c_WriteByte (0xFA); //Command for readout on-chip memory + error |= I2c_WriteByte (0x0F); //on-chip memory address + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_R); //I2C address + u8SerialNumber[5] = I2c_ReadByte(ACK); //Read SNB_3 + I2c_ReadByte(ACK); //Read CRC SNB_3 (CRC is not analyzed) + u8SerialNumber[4] = I2c_ReadByte(ACK); //Read SNB_2 + I2c_ReadByte(ACK); //Read CRC SNB_2 (CRC is not analyzed) + u8SerialNumber[3] = I2c_ReadByte(ACK); //Read SNB_1 + I2c_ReadByte(ACK); //Read CRC SNB_1 (CRC is not analyzed) + u8SerialNumber[2] = I2c_ReadByte(ACK); //Read SNB_0 + I2c_ReadByte(NO_ACK); //Read CRC SNB_0 (CRC is not analyzed) + I2c_StopCondition(); + //Read from memory location 2 + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); //I2C address + error |= I2c_WriteByte (0xFC); //Command for readout on-chip memory + error |= I2c_WriteByte (0xC9); //on-chip memory address + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_R); //I2C address + u8SerialNumber[1] = I2c_ReadByte(ACK); //Read SNC_1 + u8SerialNumber[0] = I2c_ReadByte(ACK); //Read SNC_0 + I2c_ReadByte(ACK); //Read CRC SNC0/1 (CRC is not analyzed) + u8SerialNumber[7] = I2c_ReadByte(ACK); //Read SNA_1 + u8SerialNumber[6] = I2c_ReadByte(ACK); //Read SNA_0 + I2c_ReadByte(NO_ACK); //Read CRC SNA0/1 (CRC is not analyzed) + I2c_StopCondition(); + return error; +} diff --git a/common/I2C/SHT2x.h b/common/I2C/SHT2x.h index e734a9e..5f97f83 100644 --- a/common/I2C/SHT2x.h +++ b/common/I2C/SHT2x.h @@ -1,134 +1,134 @@ -#ifndef SHT2x_H -#define SHT2x_H -//============================================================================== -// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland -//============================================================================== -// Project : SHT2x Sample Code (V1.2) -// File : SHT2x.h -// Author : MST -// Controller: NEC V850/SG3 (uPD70F3740) -// Compiler : IAR compiler for V850 (3.50A) -// Brief : Sensor layer. Definitions of commands and registers, -// functions for sensor access -//============================================================================== - - -//---------- Defines ----------------------------------------------------------- -// CRC -#define CHECKSUM_ERROR 1 -#define TIME_OUT_ERROR 2 -#define ACK_ERROR 4 - - -// sensor command -typedef enum{ - TRIG_T_MEASUREMENT_HM = 0xE3, // command trig. temp meas. hold master - TRIG_RH_MEASUREMENT_HM = 0xE5, // command trig. humidity meas. hold master - TRIG_T_MEASUREMENT_POLL = 0xF3, // command trig. temp meas. no hold master - TRIG_RH_MEASUREMENT_POLL = 0xF5, // command trig. humidity meas. no hold master - USER_REG_W = 0xE6, // command writing user register - USER_REG_R = 0xE7, // command reading user register - SOFT_RESET = 0xFE // command soft reset -}etSHT2xCommand; -typedef enum { - SHT2x_RES_12_14BIT = 0x00, // RH=12bit, T=14bit - SHT2x_RES_8_12BIT = 0x01, // RH= 8bit, T=12bit - SHT2x_RES_10_13BIT = 0x80, // RH=10bit, T=13bit - SHT2x_RES_11_11BIT = 0x81, // RH=11bit, T=11bit - SHT2x_RES_MASK = 0x81 // Mask for res. bits (7,0) in user reg. -} etSHT2xResolution; -typedef enum { - SHT2x_EOB_ON = 0x40, // end of battery - SHT2x_EOB_MASK = 0x40, // Mask for EOB bit(6) in user reg. -} etSHT2xEob; -typedef enum { - SHT2x_HEATER_ON = 0x04, // heater on - SHT2x_HEATER_OFF = 0x00, // heater off - SHT2x_HEATER_MASK = 0x04, // Mask for Heater bit(2) in user reg. -} etSHT2xHeater; -// measurement signal selection -typedef enum{ - HUMIDITY, - TEMP -}etSHT2xMeasureType; -typedef enum{ - I2C_ADR_W = 128, // sensor I2C address + write bit - I2C_ADR_R = 129 // sensor I2C address + read bit -}etI2cHeader; -//============================================================================== -uint8_t SHT2x_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum); -//============================================================================== -// calculates checksum for n bytes of data and compares it with expected -// checksum -// input: data[] checksum is built based on this data -// nbrOfBytes checksum is built for n bytes of data -// checksum expected checksum -// return: error: CHECKSUM_ERROR = checksum does not match -// 0 = checksum matches -//============================================================================== -uint8_t SHT2x_ReadUserRegister(uint8_t *pRegisterValue); -//============================================================================== -// reads the SHT2x user register (8bit) -// input : - -// output: *pRegisterValue -// return: error -//============================================================================== -uint8_t SHT2x_WriteUserRegister(uint8_t *pRegisterValue); -//============================================================================== -//Sample Code SHT21 -//www.sensirion.com Version 1.2 – February 2010 4/14 -// writes the SHT2x user register (8bit) -// input : *pRegisterValue -// output: - -// return: error -//============================================================================== -uint8_t SHT2x_MeasurePoll(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand); -//============================================================================== -// measures humidity or temperature. This function polls every 10ms until -// measurement is ready. -// input: eSHT2xMeasureType -// output: *pMeasurand: humidity / temperature as raw value -// return: error -// note: timing for timeout may be changed -//============================================================================== -uint8_t SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand); -//============================================================================== -// measures humidity or temperature. This function waits for a hold master until -// measurement is ready or a timeout occurred. -// input: eSHT2xMeasureType -// output: *pMeasurand: humidity / temperature as raw value -// return: error -// note: timing for timeout may be changed -//============================================================================== -uint8_t SHT2x_SoftReset(); -//============================================================================== -// performs a reset -// input: - -// output: - -// return: error -//============================================================================== -float SHT2x_CalcRH(uint16_t u16sRH); -//============================================================================== -// calculates the relative humidity -// input: sRH: humidity raw value (16bit scaled) -// return: pHumidity relative humidity [%RH] -//============================================================================== -float SHT2x_CalcTemperatureC(uint16_t u16sT); -//============================================================================== -// calculates temperature -// input: sT: temperature raw value (16bit scaled) -// return: temperature [°C] -//============================================================================== -uint8_t SHT2x_GetSerialNumber(uint8_t u8SerialNumber[]); -//============================================================================== -// gets serial number of SHT2x according application note "How To -// Read-Out the Serial Number" -// note: readout of this function is not CRC checked -// -// input: - -// output: u8SerialNumber: Array of 8 bytes (64Bits) -// MSB LSB -// u8SerialNumber[7] u8SerialNumber[0] -// SNA_1 SNA_0 SNB_3 SNB_2 SNB_1 SNB_0 SNC_1 SNC_0 -// return: error -#endif \ No newline at end of file +#ifndef SHT2x_H +#define SHT2x_H +//============================================================================== +// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland +//============================================================================== +// Project : SHT2x Sample Code (V1.2) +// File : SHT2x.h +// Author : MST +// Controller: NEC V850/SG3 (uPD70F3740) +// Compiler : IAR compiler for V850 (3.50A) +// Brief : Sensor layer. Definitions of commands and registers, +// functions for sensor access +//============================================================================== + + +//---------- Defines ----------------------------------------------------------- +// CRC +#define CHECKSUM_ERROR 1 +#define TIME_OUT_ERROR 2 +#define ACK_ERROR 4 + + +// sensor command +typedef enum{ + TRIG_T_MEASUREMENT_HM = 0xE3, // command trig. temp meas. hold master + TRIG_RH_MEASUREMENT_HM = 0xE5, // command trig. humidity meas. hold master + TRIG_T_MEASUREMENT_POLL = 0xF3, // command trig. temp meas. no hold master + TRIG_RH_MEASUREMENT_POLL = 0xF5, // command trig. humidity meas. no hold master + USER_REG_W = 0xE6, // command writing user register + USER_REG_R = 0xE7, // command reading user register + SOFT_RESET = 0xFE // command soft reset +}etSHT2xCommand; +typedef enum { + SHT2x_RES_12_14BIT = 0x00, // RH=12bit, T=14bit + SHT2x_RES_8_12BIT = 0x01, // RH= 8bit, T=12bit + SHT2x_RES_10_13BIT = 0x80, // RH=10bit, T=13bit + SHT2x_RES_11_11BIT = 0x81, // RH=11bit, T=11bit + SHT2x_RES_MASK = 0x81 // Mask for res. bits (7,0) in user reg. +} etSHT2xResolution; +typedef enum { + SHT2x_EOB_ON = 0x40, // end of battery + SHT2x_EOB_MASK = 0x40, // Mask for EOB bit(6) in user reg. +} etSHT2xEob; +typedef enum { + SHT2x_HEATER_ON = 0x04, // heater on + SHT2x_HEATER_OFF = 0x00, // heater off + SHT2x_HEATER_MASK = 0x04, // Mask for Heater bit(2) in user reg. +} etSHT2xHeater; +// measurement signal selection +typedef enum{ + HUMIDITY, + TEMP +}etSHT2xMeasureType; +typedef enum{ + I2C_ADR_W = 128, // sensor I2C address + write bit + I2C_ADR_R = 129 // sensor I2C address + read bit +}etI2cHeader; +//============================================================================== +uint8_t SHT2x_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum); +//============================================================================== +// calculates checksum for n bytes of data and compares it with expected +// checksum +// input: data[] checksum is built based on this data +// nbrOfBytes checksum is built for n bytes of data +// checksum expected checksum +// return: error: CHECKSUM_ERROR = checksum does not match +// 0 = checksum matches +//============================================================================== +uint8_t SHT2x_ReadUserRegister(uint8_t *pRegisterValue); +//============================================================================== +// reads the SHT2x user register (8bit) +// input : - +// output: *pRegisterValue +// return: error +//============================================================================== +uint8_t SHT2x_WriteUserRegister(uint8_t *pRegisterValue); +//============================================================================== +//Sample Code SHT21 +//www.sensirion.com Version 1.2 – February 2010 4/14 +// writes the SHT2x user register (8bit) +// input : *pRegisterValue +// output: - +// return: error +//============================================================================== +uint8_t SHT2x_MeasurePoll(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand); +//============================================================================== +// measures humidity or temperature. This function polls every 10ms until +// measurement is ready. +// input: eSHT2xMeasureType +// output: *pMeasurand: humidity / temperature as raw value +// return: error +// note: timing for timeout may be changed +//============================================================================== +uint8_t SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand); +//============================================================================== +// measures humidity or temperature. This function waits for a hold master until +// measurement is ready or a timeout occurred. +// input: eSHT2xMeasureType +// output: *pMeasurand: humidity / temperature as raw value +// return: error +// note: timing for timeout may be changed +//============================================================================== +uint8_t SHT2x_SoftReset(void); +//============================================================================== +// performs a reset +// input: - +// output: - +// return: error +//============================================================================== +float SHT2x_CalcRH(uint16_t u16sRH); +//============================================================================== +// calculates the relative humidity +// input: sRH: humidity raw value (16bit scaled) +// return: pHumidity relative humidity [%RH] +//============================================================================== +float SHT2x_CalcTemperatureC(uint16_t u16sT); +//============================================================================== +// calculates temperature +// input: sT: temperature raw value (16bit scaled) +// return: temperature [°C] +//============================================================================== +uint8_t SHT2x_GetSerialNumber(uint8_t u8SerialNumber[]); +//============================================================================== +// gets serial number of SHT2x according application note "How To +// Read-Out the Serial Number" +// note: readout of this function is not CRC checked +// +// input: - +// output: u8SerialNumber: Array of 8 bytes (64Bits) +// MSB LSB +// u8SerialNumber[7] u8SerialNumber[0] +// SNA_1 SNA_0 SNB_3 SNB_2 SNB_1 SNB_0 SNC_1 SNC_0 +// return: error +#endif diff --git a/common/I2C/TSL256x.c b/common/I2C/TSL256x.c index 140dd86..d32ab0f 100644 --- a/common/I2C/TSL256x.c +++ b/common/I2C/TSL256x.c @@ -1,146 +1,146 @@ -#define F_CPU 8000000UL -#include -#include -#include -#include -#include -#include "USI_TWI_Master.h" - -void TSL256x_init() { - I2c_StartCondition(); - I2c_WriteByte(0b01010010); // 0x0101001 1001001 0111001 - I2c_WriteByte(0x80); - I2c_WriteByte(0x03); - I2c_StopCondition(); - I2c_StartCondition(); - I2c_WriteByte(0b01010010); // 0x0101001 1001001 0111001 - I2c_WriteByte(0x81); - I2c_WriteByte(0x12); - I2c_StopCondition(); - _delay_ms(500); -} - -void TSL256x_setup(uint8_t conf) { - I2c_StartCondition(); - I2c_WriteByte(0b01010010); // 0x0101001 1001001 0111001 - I2c_WriteByte(0x81); - I2c_WriteByte(conf); - I2c_StopCondition(); -} - -uint16_t TSL256x_Ch(uint8_t ch){ - uint16_t res; - I2c_StartCondition(); - I2c_WriteByte(0b01010010); // 0x0101001 1001001 0111001 - //I2c_WriteByte(0xAD); - I2c_WriteByte(0xAC+(ch<<1)); - I2c_StopCondition(); - I2c_StartCondition(); - I2c_WriteByte(0b01010011); - res=I2c_ReadByte(ACK); - res|=((uint16_t)I2c_ReadByte(NO_ACK))<<8; - I2c_StopCondition(); - return res; -} - -#define LUX_SCALE 14 // scale by 2^14 -#define RATIO_SCALE 9 // scale ratio by 2^9 -//??????????????????????????????????????????????????? -// Integration time scaling factors -//??????????????????????????????????????????????????? -#define CH_SCALE 10 // scale channel values by 2^10 -#define CHSCALE_TINT0 0x7517 // 322/11 * 2^CH_SCALE -#define CHSCALE_TINT1 0x0fe7 // 322/81 * 2^CH_SCALE - -#define K1T 0x0040 // 0.125 * 2^RATIO_SCALE -#define B1T 0x01f2 // 0.0304 * 2^LUX_SCALE -#define M1T 0x01be // 0.0272 * 2^LUX_SCALE -#define K2T 0x0080 // 0.250 * 2^RATIO_SCALE -#define B2T 0x0214 // 0.0325 * 2^LUX_SCALE -#define M2T 0x02d1 // 0.0440 * 2^LUX_SCALE -#define K3T 0x00c0 // 0.375 * 2^RATIO_SCALE -#define B3T 0x023f // 0.0351 * 2^LUX_SCALE -#define M3T 0x037b // 0.0544 * 2^LUX_SCALE -#define K4T 0x0100 // 0.50 * 2^RATIO_SCALE -#define B4T 0x0270 // 0.0381 * 2^LUX_SCALE -#define M4T 0x03fe // 0.0624 * 2^LUX_SCALE -#define K5T 0x0138 // 0.61 * 2^RATIO_SCALE -#define B5T 0x016f // 0.0224 * 2^LUX_SCALE -#define M5T 0x01fc // 0.0310 * 2^LUX_SCALE -#define K6T 0x019a // 0.80 * 2^RATIO_SCALE -#define B6T 0x00d2 // 0.0128 * 2^LUX_SCALE -#define M6T 0x00fb // 0.0153 * 2^LUX_SCALE -#define K7T 0x029a // 1.3 * 2^RATIO_SCALE -#define B7T 0x0018 // 0.00146 * 2^LUX_SCALE -#define M7T 0x0012 // 0.00112 * 2^LUX_SCALE -#define K8T 0x029a // 1.3 * 2^RATIO_SCALE -#define B8T 0x0000 // 0.000 * 2^LUX_SCALE -#define M8T 0x0000 // 0.000 * 2^LUX_SCALE - -uint32_t CalculateLux(uint8_t iGain, uint8_t tInt, uint16_t ch0, uint16_t ch1) -{ - //???????????????????????????????????????????????????????????????????????? - // first, scale the channel values depending on the gain and integration time - // 16X, 402mS is nominal. - // scale if integration time is NOT 402 msec - uint32_t chScale; - uint32_t channel1; - uint32_t channel0; - switch (tInt) - { - case 0: // 13.7 msec - chScale = CHSCALE_TINT0; - break; - case 1: // 101 msec - chScale = CHSCALE_TINT1; - break; - default: // assume no scaling - chScale = (1 << CH_SCALE); - break; - } - // scale if gain is NOT 16X - if (!iGain) chScale = chScale << 4; // scale 1X to 16X - // scale the channel values - channel0 = (ch0 * chScale) >> CH_SCALE; - channel1 = (ch1 * chScale) >> CH_SCALE; - //???????????????????????????????????????????????????????????????????????? - // find the ratio of the channel values (Channel1/Channel0) - // protect against divide by zero - uint32_t ratio1 = 0; - if (channel0 != 0) ratio1 = (channel1 << (RATIO_SCALE+1)) / channel0; - // round the ratio value - uint32_t ratio = (ratio1 + 1) >> 1; - // is ratio <= eachBreak ? - uint16_t b, m; - if ((ratio >= 0) && (ratio <= K1T)) - {b=B1T; m=M1T;} - else if (ratio <= K2T) - {b=B2T; m=M2T;} - else if (ratio <= K3T) - {b=B3T; m=M3T;} - else if (ratio <= K4T) - {b=B4T; m=M4T;} - else if (ratio <= K5T) - {b=B5T; m=M5T;} - else if (ratio <= K6T) - {b=B6T; m=M6T;} - else if (ratio <= K7T) - {b=B7T; m=M7T;} - else if (ratio > K8T) - {b=B8T; m=M8T;} - uint32_t temp; - temp = ((channel0 * b) - (channel1 * m)); - // do not allow negative lux value - if (temp < 0) temp = 0; - // round lsb (2^(LUX_SCALE?1)) - temp += (1 << (LUX_SCALE-1)); - // strip off fractional portion - uint32_t lux = temp ;//>> LUX_SCALE; - return(lux); -} - - - - - - +#define F_CPU 8000000UL +#include +#include +#include +#include +#include +#include "USI_TWI_Master.h" + +void TSL256x_init() { + I2c_StartCondition(); + I2c_WriteByte(0b01010010); // 0x0101001 1001001 0111001 + I2c_WriteByte(0x80); + I2c_WriteByte(0x03); + I2c_StopCondition(); + I2c_StartCondition(); + I2c_WriteByte(0b01010010); // 0x0101001 1001001 0111001 + I2c_WriteByte(0x81); + I2c_WriteByte(0x12); + I2c_StopCondition(); + _delay_ms(500); +} + +void TSL256x_setup(uint8_t conf) { + I2c_StartCondition(); + I2c_WriteByte(0b01010010); // 0x0101001 1001001 0111001 + I2c_WriteByte(0x81); + I2c_WriteByte(conf); + I2c_StopCondition(); +} + +uint16_t TSL256x_Ch(uint8_t ch){ + uint16_t res; + I2c_StartCondition(); + I2c_WriteByte(0b01010010); // 0x0101001 1001001 0111001 + //I2c_WriteByte(0xAD); + I2c_WriteByte(0xAC+(ch<<1)); + I2c_StopCondition(); + I2c_StartCondition(); + I2c_WriteByte(0b01010011); + res=I2c_ReadByte(ACK); + res|=((uint16_t)I2c_ReadByte(NO_ACK))<<8; + I2c_StopCondition(); + return res; +} + +#define LUX_SCALE 14 // scale by 2^14 +#define RATIO_SCALE 9 // scale ratio by 2^9 +//??????????????????????????????????????????????????? +// Integration time scaling factors +//??????????????????????????????????????????????????? +#define CH_SCALE 10 // scale channel values by 2^10 +#define CHSCALE_TINT0 0x7517 // 322/11 * 2^CH_SCALE +#define CHSCALE_TINT1 0x0fe7 // 322/81 * 2^CH_SCALE + +#define K1T 0x0040 // 0.125 * 2^RATIO_SCALE +#define B1T 0x01f2 // 0.0304 * 2^LUX_SCALE +#define M1T 0x01be // 0.0272 * 2^LUX_SCALE +#define K2T 0x0080 // 0.250 * 2^RATIO_SCALE +#define B2T 0x0214 // 0.0325 * 2^LUX_SCALE +#define M2T 0x02d1 // 0.0440 * 2^LUX_SCALE +#define K3T 0x00c0 // 0.375 * 2^RATIO_SCALE +#define B3T 0x023f // 0.0351 * 2^LUX_SCALE +#define M3T 0x037b // 0.0544 * 2^LUX_SCALE +#define K4T 0x0100 // 0.50 * 2^RATIO_SCALE +#define B4T 0x0270 // 0.0381 * 2^LUX_SCALE +#define M4T 0x03fe // 0.0624 * 2^LUX_SCALE +#define K5T 0x0138 // 0.61 * 2^RATIO_SCALE +#define B5T 0x016f // 0.0224 * 2^LUX_SCALE +#define M5T 0x01fc // 0.0310 * 2^LUX_SCALE +#define K6T 0x019a // 0.80 * 2^RATIO_SCALE +#define B6T 0x00d2 // 0.0128 * 2^LUX_SCALE +#define M6T 0x00fb // 0.0153 * 2^LUX_SCALE +#define K7T 0x029a // 1.3 * 2^RATIO_SCALE +#define B7T 0x0018 // 0.00146 * 2^LUX_SCALE +#define M7T 0x0012 // 0.00112 * 2^LUX_SCALE +#define K8T 0x029a // 1.3 * 2^RATIO_SCALE +#define B8T 0x0000 // 0.000 * 2^LUX_SCALE +#define M8T 0x0000 // 0.000 * 2^LUX_SCALE + +uint32_t CalculateLux(uint8_t iGain, uint8_t tInt, uint16_t ch0, uint16_t ch1) +{ + //???????????????????????????????????????????????????????????????????????? + // first, scale the channel values depending on the gain and integration time + // 16X, 402mS is nominal. + // scale if integration time is NOT 402 msec + uint32_t chScale; + uint32_t channel1; + uint32_t channel0; + switch (tInt) + { + case 0: // 13.7 msec + chScale = CHSCALE_TINT0; + break; + case 1: // 101 msec + chScale = CHSCALE_TINT1; + break; + default: // assume no scaling + chScale = (1 << CH_SCALE); + break; + } + // scale if gain is NOT 16X + if (!iGain) chScale = chScale << 4; // scale 1X to 16X + // scale the channel values + channel0 = (ch0 * chScale) >> CH_SCALE; + channel1 = (ch1 * chScale) >> CH_SCALE; + //???????????????????????????????????????????????????????????????????????? + // find the ratio of the channel values (Channel1/Channel0) + // protect against divide by zero + uint32_t ratio1 = 0; + if (channel0 != 0) ratio1 = (channel1 << (RATIO_SCALE+1)) / channel0; + // round the ratio value + uint32_t ratio = (ratio1 + 1) >> 1; + // is ratio <= eachBreak ? + uint16_t b, m; + if ((ratio >= 0) && (ratio <= K1T)) + {b=B1T; m=M1T;} + else if (ratio <= K2T) + {b=B2T; m=M2T;} + else if (ratio <= K3T) + {b=B3T; m=M3T;} + else if (ratio <= K4T) + {b=B4T; m=M4T;} + else if (ratio <= K5T) + {b=B5T; m=M5T;} + else if (ratio <= K6T) + {b=B6T; m=M6T;} + else if (ratio <= K7T) + {b=B7T; m=M7T;} + else if (ratio > K8T) + {b=B8T; m=M8T;} + uint32_t temp; + temp = ((channel0 * b) - (channel1 * m)); + // do not allow negative lux value + if (temp < 0) temp = 0; + // round lsb (2^(LUX_SCALE?1)) + temp += (1 << (LUX_SCALE-1)); + // strip off fractional portion + uint32_t lux = temp ;//>> LUX_SCALE; + return(lux); +} + + + + + + diff --git a/common/I2C/TSL256x.h b/common/I2C/TSL256x.h index 16f7b06..9f1756e 100644 --- a/common/I2C/TSL256x.h +++ b/common/I2C/TSL256x.h @@ -1,17 +1,17 @@ -#ifndef TSL256x_H -#define TSL256x_H - -#define TSL_GAIN16 0x10 -#define TSL_GAIN1 0x00 -#define TSL_INT_TIME1 0x00 -#define TSL_INT_TIME2 0x01 -#define TSL_INT_TIME3 0x02 - -void TSL256x_init(); -void TSL256x_setup(uint8_t conf); -uint16_t TSL256x_Ch(uint8_t ch); - uint32_t CalculateLux(unsigned int iGain, unsigned int tInt, unsigned int ch0, unsigned int ch1); - -uint16_t TSL256x_Lux(); - -#endif +#ifndef TSL256x_H +#define TSL256x_H + +#define TSL_GAIN16 0x10 +#define TSL_GAIN1 0x00 +#define TSL_INT_TIME1 0x00 +#define TSL_INT_TIME2 0x01 +#define TSL_INT_TIME3 0x02 + +void TSL256x_init(); +void TSL256x_setup(uint8_t conf); +uint16_t TSL256x_Ch(uint8_t ch); + uint32_t CalculateLux(unsigned int iGain, unsigned int tInt, unsigned int ch0, unsigned int ch1); + +uint16_t TSL256x_Lux(); + +#endif diff --git a/common/I2C/USI_TWI_Master.c b/common/I2C/USI_TWI_Master.c index 5e6dea8..d5f2596 100644 --- a/common/I2C/USI_TWI_Master.c +++ b/common/I2C/USI_TWI_Master.c @@ -1,322 +1,322 @@ -/***************************************************************************** -* -* Atmel Corporation -* -* File : USI_TWI_Master.c -* Compiler : AVRGCC Toolchain version 3.4.2 -* Revision : $Revision: 992 $ -* Date : $Date: 2013-11-07 $ -* Updated by : $Author: Atmel $ -* -* Support mail : avr@atmel.com -* -* Supported devices : All device with USI module can be used. -* The example is written for the ATmega169, ATtiny26 and ATtiny2313 -* -* AppNote : AVR310 - Using the USI module as a TWI Master -* -* Description : This is an implementation of an TWI master using -* the USI module as basis. The implementation assumes the AVR to -* be the only TWI master in the system and can therefore not be -* used in a multi-master system. -* Usage : Initialize the USI module by calling the USI_TWI_Master_Initialise() -* function. Hence messages/data are transceived on the bus using -* the USI_TWI_Transceive() function. The transceive function -* returns a status byte, which can be used to evaluate the -* success of the transmission. -* -****************************************************************************/ -#define F_CPU 8000000UL -#include -#include "USI_TWI_Master.h" -#include - -unsigned char USI_TWI_Master_Transfer( unsigned char ); -unsigned char USI_TWI_Master_Stop( void ); - -union USI_TWI_state -{ - unsigned char errorState; // Can reuse the TWI_state for error states due to that it will not be need if there exists an error. - struct - { - unsigned char addressMode : 1; - unsigned char masterWriteDataMode : 1; - unsigned char unused : 6; - }; -} USI_TWI_state; - -/*--------------------------------------------------------------- - USI TWI single master initialization function ----------------------------------------------------------------*/ -void USI_TWI_Master_Initialise( void ) -{ - PORT_USI |= (1< (unsigned char*)RAMEND) // Test if address is outside SRAM space - { - USI_TWI_state.errorState = USI_TWI_DATA_OUT_OF_BOUND; - return (FALSE); - } - if(msgSize <= 1) // Test if the transmission buffer is empty - { - USI_TWI_state.errorState = USI_TWI_NO_DATA; - return (FALSE); - } -#endif - -#ifdef NOISE_TESTING // Test if any unexpected conditions have arrived prior to this execution. - if( USISR & (1< +#include "USI_TWI_Master.h" +#include + +unsigned char USI_TWI_Master_Transfer( unsigned char ); +unsigned char USI_TWI_Master_Stop( void ); + +union USI_TWI_state +{ + unsigned char errorState; // Can reuse the TWI_state for error states due to that it will not be need if there exists an error. + struct + { + unsigned char addressMode : 1; + unsigned char masterWriteDataMode : 1; + unsigned char unused : 6; + }; +} USI_TWI_state; + +/*--------------------------------------------------------------- + USI TWI single master initialization function +---------------------------------------------------------------*/ +void USI_TWI_Master_Initialise( void ) +{ + PORT_USI |= (1< (unsigned char*)RAMEND) // Test if address is outside SRAM space + { + USI_TWI_state.errorState = USI_TWI_DATA_OUT_OF_BOUND; + return (FALSE); + } + if(msgSize <= 1) // Test if the transmission buffer is empty + { + USI_TWI_state.errorState = USI_TWI_NO_DATA; + return (FALSE); + } +#endif + +#ifdef NOISE_TESTING // Test if any unexpected conditions have arrived prior to this execution. + if( USISR & (1< -//********** Defines **********// - -// Defines controlling timing limits -#define TWI_FAST_MODE - -#define SYS_CLK 8000.0 // [kHz] - -#ifdef TWI_FAST_MODE // TWI FAST mode timing limits. SCL = 100-400kHz - #define T2_TWI ((SYS_CLK *1300) /1000000) +1 // >1,3us - #define T4_TWI ((SYS_CLK * 600) /1000000) +1 // >0,6us - -#else // TWI STANDARD mode timing limits. SCL <= 100kHz - #define T2_TWI ((SYS_CLK *4700) /1000000) +1 // >4,7us - #define T4_TWI ((SYS_CLK *4000) /1000000) +1 // >4,0us -#endif - -// Defines controling code generating -//#define PARAM_VERIFICATION -//#define NOISE_TESTING -//#define SIGNAL_VERIFY - -//USI_TWI messages and flags and bit masks -//#define SUCCESS 7 -//#define MSG 0 -/**************************************************************************** - Bit and byte definitions -****************************************************************************/ -#define TWI_READ_BIT 0 // Bit position for R/W bit in "address byte". -#define TWI_ADR_BITS 1 // Bit position for LSB of the slave address bits in the init byte. -#define TWI_NACK_BIT 0 // Bit position for (N)ACK bit. - -#define USI_TWI_NO_DATA 0x00 // Transmission buffer is empty -#define USI_TWI_DATA_OUT_OF_BOUND 0x01 // Transmission buffer is outside SRAM space -#define USI_TWI_UE_START_CON 0x02 // Unexpected Start Condition -#define USI_TWI_UE_STOP_CON 0x03 // Unexpected Stop Condition -#define USI_TWI_UE_DATA_COL 0x04 // Unexpected Data Collision (arbitration) -#define USI_TWI_NO_ACK_ON_DATA 0x05 // The slave did not acknowledge all data -#define USI_TWI_NO_ACK_ON_ADDRESS 0x06 // The slave did not acknowledge the address -#define USI_TWI_MISSING_START_CON 0x07 // Generated Start Condition not detected on bus -#define USI_TWI_MISSING_STOP_CON 0x08 // Generated Stop Condition not detected on bus - -// Device dependant defines - -#if defined(__AVR_AT90Mega169__) | defined(__AVR_ATmega169PA__) | \ - defined(__AVR_AT90Mega165__) | defined(__AVR_ATmega165__) | \ - defined(__AVR_ATmega325__) | defined(__AVR_ATmega3250__) | \ - defined(__AVR_ATmega645__) | defined(__AVR_ATmega6450__) | \ - defined(__AVR_ATmega329__) | defined(__AVR_ATmega3290__) | \ - defined(__AVR_ATmega649__) | defined(__AVR_ATmega6490__) - #define DDR_USI DDRE - #define PORT_USI PORTE - #define PIN_USI PINE - #define PORT_USI_SDA PORTE5 - #define PORT_USI_SCL PORTE4 - #define PIN_USI_SDA PINE5 - #define PIN_USI_SCL PINE4 -#endif - -#if defined(__AVR_ATtiny25__) | defined(__AVR_ATtiny45__) | defined(__AVR_ATtiny85__) | \ - defined(__AVR_AT90Tiny26__) | defined(__AVR_ATtiny26__) - #define DDR_USI DDRB - #define PORT_USI PORTB - #define PIN_USI PINB - #define PORT_USI_SDA PORTB0 - #define PORT_USI_SCL PORTB2 - #define PIN_USI_SDA PINB0 - #define PIN_USI_SCL PINB2 -#endif - -#if defined(__AVR_AT90Tiny2313__) | defined(__AVR_ATtiny2313__) - #define DDR_USI DDRB - #define PORT_USI PORTB - #define PIN_USI PINB - #define PORT_USI_SDA PORTB5 - #define PORT_USI_SCL PORTB7 - #define PIN_USI_SDA PINB5 - #define PIN_USI_SCL PINB7 -#endif - -#if defined(__AVR_ATtiny84__) | defined(__AVR_ATtiny84A__) -#define DDR_USI DDRA -#define PORT_USI PORTA -#define PIN_USI PINA -#define PORT_USI_SDA PORTA6 -#define PORT_USI_SCL PORTA4 -#define PIN_USI_SDA PINA6 -#define PIN_USI_SCL PINA4 -#endif - -// General defines -#define TRUE 1 -#define FALSE 0 - -#define ACK (1< +//********** Defines **********// + +// Defines controlling timing limits +#define TWI_FAST_MODE + +#define SYS_CLK 8000.0 // [kHz] + +#ifdef TWI_FAST_MODE // TWI FAST mode timing limits. SCL = 100-400kHz + #define T2_TWI ((SYS_CLK *1300) /1000000) +1 // >1,3us + #define T4_TWI ((SYS_CLK * 600) /1000000) +1 // >0,6us + +#else // TWI STANDARD mode timing limits. SCL <= 100kHz + #define T2_TWI ((SYS_CLK *4700) /1000000) +1 // >4,7us + #define T4_TWI ((SYS_CLK *4000) /1000000) +1 // >4,0us +#endif + +// Defines controling code generating +//#define PARAM_VERIFICATION +//#define NOISE_TESTING +//#define SIGNAL_VERIFY + +//USI_TWI messages and flags and bit masks +//#define SUCCESS 7 +//#define MSG 0 +/**************************************************************************** + Bit and byte definitions +****************************************************************************/ +#define TWI_READ_BIT 0 // Bit position for R/W bit in "address byte". +#define TWI_ADR_BITS 1 // Bit position for LSB of the slave address bits in the init byte. +#define TWI_NACK_BIT 0 // Bit position for (N)ACK bit. + +#define USI_TWI_NO_DATA 0x00 // Transmission buffer is empty +#define USI_TWI_DATA_OUT_OF_BOUND 0x01 // Transmission buffer is outside SRAM space +#define USI_TWI_UE_START_CON 0x02 // Unexpected Start Condition +#define USI_TWI_UE_STOP_CON 0x03 // Unexpected Stop Condition +#define USI_TWI_UE_DATA_COL 0x04 // Unexpected Data Collision (arbitration) +#define USI_TWI_NO_ACK_ON_DATA 0x05 // The slave did not acknowledge all data +#define USI_TWI_NO_ACK_ON_ADDRESS 0x06 // The slave did not acknowledge the address +#define USI_TWI_MISSING_START_CON 0x07 // Generated Start Condition not detected on bus +#define USI_TWI_MISSING_STOP_CON 0x08 // Generated Stop Condition not detected on bus + +// Device dependant defines + +#if defined(__AVR_AT90Mega169__) | defined(__AVR_ATmega169PA__) | \ + defined(__AVR_AT90Mega165__) | defined(__AVR_ATmega165__) | \ + defined(__AVR_ATmega325__) | defined(__AVR_ATmega3250__) | \ + defined(__AVR_ATmega645__) | defined(__AVR_ATmega6450__) | \ + defined(__AVR_ATmega329__) | defined(__AVR_ATmega3290__) | \ + defined(__AVR_ATmega649__) | defined(__AVR_ATmega6490__) + #define DDR_USI DDRE + #define PORT_USI PORTE + #define PIN_USI PINE + #define PORT_USI_SDA PORTE5 + #define PORT_USI_SCL PORTE4 + #define PIN_USI_SDA PINE5 + #define PIN_USI_SCL PINE4 +#endif + +#if defined(__AVR_ATtiny25__) | defined(__AVR_ATtiny45__) | defined(__AVR_ATtiny85__) | \ + defined(__AVR_AT90Tiny26__) | defined(__AVR_ATtiny26__) + #define DDR_USI DDRB + #define PORT_USI PORTB + #define PIN_USI PINB + #define PORT_USI_SDA PORTB0 + #define PORT_USI_SCL PORTB2 + #define PIN_USI_SDA PINB0 + #define PIN_USI_SCL PINB2 +#endif + +#if defined(__AVR_AT90Tiny2313__) | defined(__AVR_ATtiny2313__) + #define DDR_USI DDRB + #define PORT_USI PORTB + #define PIN_USI PINB + #define PORT_USI_SDA PORTB5 + #define PORT_USI_SCL PORTB7 + #define PIN_USI_SDA PINB5 + #define PIN_USI_SCL PINB7 +#endif + +#if defined(__AVR_ATtiny84__) | defined(__AVR_ATtiny84A__) +#define DDR_USI DDRA +#define PORT_USI PORTA +#define PIN_USI PINA +#define PORT_USI_SDA PORTA6 +#define PORT_USI_SCL PORTA4 +#define PIN_USI_SDA PINA6 +#define PIN_USI_SCL PINA4 +#endif + +// General defines +#define TRUE 1 +#define FALSE 0 + +#define ACK (1< - -#define r_temp 16 -#define r_rwbyte 17 -#define r_temp2 18 -#define r_bcount 19 -#define r_mode 20 -#define r_sendflag 21 -#define r_bytep 22 -#define r_crc 23 - -#define r_idm1 25 -#define r_idm2 24 -#define r_idn1 15 -#define r_idn2 14 - -#define xl 26 -#define xh 27 -#define yl 28 -#define yh 29 -#define zl 30 -#define zh 31 - -.extern owid,8 -.extern config_info,16 - -.comm mode,1 ; Aktueller Zustand nach dem die Unterprogramme aufgerufen werden -.comm srbyte,1 ; aktuelles Byte fuer Searchrom -.comm bytep,1 ; pointer fuer Zugriffe auf owid usw -.comm bcount,1 ;bit counter, bit wird durchgeschoben -.comm rwbyte,1 ; alktuelles byte beim Senden oder Empfangen -.comm sendflag,1; sendfalg= 1 -> Senden sonst Empfangen -.comm gcontrol,1 ;im Test -.comm reset_indicator,1 ; zeigt an wenn ein Reset empfangen wurde (Fuer das C Programm) -.comm alarmflag,1 -#ifndef _DIS_FLASH_ -.comm flashmarker,1 -#endif - -.macro configZ m,offs - ldi zl,lo8(\m) - ; daten im gleichen 256 Segment -//#if (((handle_stable>>1)&0xFF00)!= (m&0xFF00)) - ldi zh,hi8(\m) -//#endif - add zl,\offs -//#if ((pack&0x00FF)>(0xC0)) - clr r_temp - adc zh,r_temp -//#endif - -.endm - - -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) -#include "../common/OWSet_ATTINYX4.s" -#endif - -#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) -#include "../common/OWSet_ATTINYX5.s" -#endif - + +// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the +// distribution. +// * All advertising materials mentioning features or use of this +// software must display the following acknowledgement: This product +// includes software developed by tm3d.de and its contributors. +// * Neither the name of tm3d.de nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +#include + +#define r_temp 16 +#define r_rwbyte 17 +#define r_temp2 18 +#define r_bcount 19 +#define r_mode 20 +#define r_sendflag 21 +#define r_bytep 22 +#define r_crc 23 + +#define r_idm1 25 +#define r_idm2 24 +#define r_idn1 15 +#define r_idn2 14 + +#define xl 26 +#define xh 27 +#define yl 28 +#define yh 29 +#define zl 30 +#define zh 31 + +.extern owid,8 +.extern config_info,16 + +.comm mode,1 ; Aktueller Zustand nach dem die Unterprogramme aufgerufen werden +.comm srbyte,1 ; aktuelles Byte fuer Searchrom +.comm bytep,1 ; pointer fuer Zugriffe auf owid usw +.comm bcount,1 ;bit counter, bit wird durchgeschoben +.comm rwbyte,1 ; alktuelles byte beim Senden oder Empfangen +.comm sendflag,1; sendfalg= 1 -> Senden sonst Empfangen +.comm gcontrol,1 ;im Test +.comm reset_indicator,1 ; zeigt an wenn ein Reset empfangen wurde (Fuer das C Programm) +.comm alarmflag,1 +#ifndef _DIS_FLASH_ +.comm flashmarker,1 +#endif + +.macro configZ m,offs + ldi zl,lo8(\m) + ; daten im gleichen 256 Segment +//#if (((handle_stable>>1)&0xFF00)!= (m&0xFF00)) + ldi zh,hi8(\m) +//#endif + add zl,\offs +//#if ((pack&0x00FF)>(0xC0)) + clr r_temp + adc zh,r_temp +//#endif + +.endm + + +#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) +#include "../common/OWSet_ATTINYX4.s" +#endif + +#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) +#include "../common/OWSet_ATTINYX5.s" +#endif + diff --git a/common/OWDS18B20.S b/common/OWDS18B20.S index 07e4980..e9ef6d3 100644 --- a/common/OWDS18B20.S +++ b/common/OWDS18B20.S @@ -1,217 +1,217 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define _CHANGEABLE_ID_ -#define _ZERO_POLLING_ - -#include "../common/OWConfig.s" -#include "../common/OWCRC8.s" - -.extern pack,8 - -//.extern am2302_temp,2 - - - -.macro CHIP_INIT -Init_EEPROM_read: - sbic _SFR_IO_ADDR(EECR), EEPE - rjmp Init_EEPROM_read - ldi r_temp,0 - out _SFR_IO_ADDR(EEARH), r_temp - ldi r_temp,2 - out _SFR_IO_ADDR(EEARL), r_temp - sbi _SFR_IO_ADDR(EECR), EERE - in r_temp,_SFR_IO_ADDR(EEDR) - sbrs r_temp,7 - rcall hrc_recall_eeprom_func -.endm - -.macro COMMAND_TABLE - rjmp h_readscratchpad - rjmp h_writescratchpad - rjmp h_convert_run -.endm - -#include "../common/OWRomFunctions.s" -#include "../common/OWTimerInterrupt.s" - - - -; Ab hier Geraeteabhaenging -#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+0 -#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+1 -#define OW_CONVERT_RUN OW_FIRST_COMMAND+2 - - -;--------------------------------------------------- -; READ COMMAND and start operation -;--------------------------------------------------- - - -h_readcommand: - clr r_bytep -#ifndef _DIS_FLASH_ - FLASH_COMMANDS ; muss zu erst sein.... -#endif - cjmp 0xBE,hrc_set_readscratchpad - cjmp 0x4E,hrc_set_writescratchpad - cjmp 0x44,hrc_set_convertT - cjmp 0x48,hrc_copy_scratchpad - cjmp 0xB8,hrc_recall_eeprom - FW_CONFIG_INFO -#ifdef _CHANGEABLE_ID_ - CHANGE_ID_COMMANDS -#endif - //ldi r_mode,OW_SLEEP - rjmp handle_end_sleep - -hrc_set_readscratchpad: - ldi r_mode,OW_READ_SCRATCHPAD - ldi r_sendflag,1 - CRCInit2 - rjmp h_readscratchpad - -hrc_set_writescratchpad: - ldi r_mode,OW_WRITE_SCRATCHPAD - ldi r_bytep,2 ;start to write in 2 - rjmp handle_end - -hrc_recall_eeprom: - rcall hrc_recall_eeprom_func - rjmp handle_end - - - -hrc_set_convertT: - ldi r_temp,1 - sts gcontrol,r_temp - ldi r_mode,OW_CONVERT_RUN - ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling -h_convert_run: - ldi r_bcount,0 - ldi r_rwbyte,0 - rjmp handle_end_no_bcount - -hrc_copy_scratchpad: - ldi r_bytep,2 - configZ pack,r_bytep - clr r_bytep -hrc_copy_scratchpad_EEPROM_write: - sbic _SFR_IO_ADDR(EECR), EEPE - rjmp hrc_copy_scratchpad_EEPROM_write - ldi r_temp, (0<VOC use different + st Z,r_rwbyte + rjmp handle_end_sleep + +;***************************************************************************************************************************************************************************************** +;***************************************************************************************************************************************************************************************** +;***************************************************************************************************************************************************************************************** +;***************************************************************************************************************************************************************************************** +;***************************************************************************************************************************************************************************************** + + + + + +h_readcommand2: + clr r_bytep +#ifndef _DIS_FLASH_ + FLASH_COMMANDS ; muss zu erst sein.... +#endif + cset 0xBE,OW_READ_SCRATCHPAD_ADR2 + cset 0x4E,OW_WRITE_SCRATCHPAD_ADR2 + cjmp 0x44,hrc_set_convertT2 + cjmp 0xB4,hrc_set_convertV2 + FW_CONFIG_INFO2 + //cljmp 0x85,hrc_fw_configinfo2 +#ifdef _CHANGEABLE_ID_ + CHANGE_ID_COMMANDS +#endif + rjmp handle_end_sleep + + +hrc_set_convertT2: + ldi r_temp,2 + sts gcontrol,r_temp + lds r_temp,am2302_temp + sts pack2+1,r_temp + lds r_temp,am2302_temp+1 + sts pack2+2,r_temp + rjmp handle_end_sleep +hrc_set_convertV2: + lds r_temp,pack2 + sbrs r_temp,3 + rjmp hrc_set_convertVV2 + ldi r_temp,0xF4 + sts pack2+3,r_temp + ldi r_temp,0x01 + sts pack2+4,r_temp + rjmp hrc_set_convertend2 +hrc_set_convertVV2: + ldi r_temp,3 + sts gcontrol,r_temp + lds r_temp,am2302_hum + sts pack2+3,r_temp + lds r_temp,am2302_hum+1 + sts pack2+4,r_temp +hrc_set_convertend2: + rjmp handle_end_sleep + + + +;--------------------------------------------------- +; READ SCRATCHPAD +;--------------------------------------------------- + +h_readscratchpad_adr2: + lsl r_rwbyte + lsl r_rwbyte + lsl r_rwbyte +#if defined(__AVR_ATtiny25__) + andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen +#endif + sts block,r_rwbyte + ldi r_sendflag,1 + ldi r_mode,OW_READ_SCRATCHPAD2 + CRCInit2 +h_readscratchpad2: + cpi r_bytep,8 + breq h_readscratchpad_crc2 + cpi r_bytep,9 + breq h_readscratchpad_all2 + lds r_temp,block + add r_temp,r_bytep + configZ pack2,r_temp + ld r_rwbyte,Z + rjmp handle_end_inc +h_readscratchpad_crc2: + lds r_rwbyte,crc + rjmp handle_end_inc +h_readscratchpad_all2: + rjmp handle_end_sleep + + + + +;--------------------------------------------------- +; WRITE SCRATCHPAD +;--------------------------------------------------- +h_writescratchpad_adr2: + lsl r_rwbyte + lsl r_rwbyte + lsl r_rwbyte +#if defined(__AVR_ATtiny25__) + andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen +#endif + sts block,r_rwbyte + ldi r_mode,OW_WRITE_SCRATCHPAD2 + ldi r_bcount,1 + rjmp handle_end +h_writescratchpad2: + cpi r_bytep,8 + breq h_writescratchpad_all2 + lds r_temp,block + add r_temp,r_bytep + configZ pack2,r_temp + st Z,r_rwbyte + rjmp handle_end_inc +h_writescratchpad_all2: + rjmp handle_end_sleep + + + + + + + + + +#include "../common/OWPinInterrupt.s" +.end diff --git a/common/OWDS2423.S b/common/OWDS2423.S index 05df87d..0fb23d8 100644 --- a/common/OWDS2423.S +++ b/common/OWDS2423.S @@ -1,339 +1,339 @@ - -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -#define _CHANGEABLE_ID_ -#define _ZERO_POLLING_ -#include "../common/OWConfig.s" -#include "../common/OWCRC16.s" - -.extern pack,45 -.extern counters,8 - -.macro CHIP_INIT -.endm - -.macro COMMAND_TABLE - rjmp h_writescratchpad - rjmp h_writescratchpad_crc - rjmp h_readscratchpad - rjmp h_copyscratchpad - rjmp h_readmemory_addr - rjmp h_readmemory - rjmp h_readmemorycounter_addr - rjmp h_readmemorycounter - rjmp h_readmemorycounter_ex -.endm - -#include "../common/OWRomFunctions.s" -#include "../common/OWTimerInterrupt.s" - - - -; Ab hier Geraeteabhaenging -#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+0 -#define OW_WRITE_SCRATCHPAD_CRC OW_FIRST_COMMAND+1 -#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+2 -#define OW_COPY_SCRATCHPAD OW_FIRST_COMMAND+3 -#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+4 -#define OW_READ_MEMORY OW_FIRST_COMMAND+5 -#define OW_READ_MEMORYCOUNTER_ADDR OW_FIRST_COMMAND+6 -#define OW_READ_MEMORYCOUNTER OW_FIRST_COMMAND+7 -#define OW_READ_MEMORYCOUNTER_EX OW_FIRST_COMMAND+8 - -;--------------------------------------------------- -; READ COMMAND and start operation -;--------------------------------------------------- - - -h_readcommand: - clr r_bytep -#ifndef _DIS_FLASH_ - FLASH_COMMANDS ; muss zu erst sein.... -#endif - cset 0x0F,OW_WRITE_SCRATCHPAD - cjmp 0xAA,hrc_set_readscratchpad - cset 0x5A,OW_COPY_SCRATCHPAD - cset 0xF0,OW_READ_MEMORY_ADDR - cset 0xA5,OW_READ_MEMORYCOUNTER_ADDR - FW_CONFIG_INFO -#ifdef _CHANGEABLE_ID_ - CHANGE_ID_COMMANDS -#endif - ldi r_mode,OW_SLEEP - rjmp handle_end - -hrc_set_readscratchpad: - ldi r_mode,OW_READ_SCRATCHPAD - ldi r_sendflag,1 - rjmp h_readscratchpad - -h_writescratchpad: - configZ pack,r_bytep - inc r_bytep - st Z,r_rwbyte - cpi r_bytep,2 - breq h_writescratchpad_block - brsh h_writescratchpad_set_eoffset ;;33 - rjmp handle_end ;handle_end zu weit entfernt fuer br... -h_writescratchpad_set_eoffset: - cpi r_bytep,35 - breq h_writescratchpad_setcrc - mov r_temp,r_bytep - subi r_temp,4 - sts pack+2,r_temp ;AA und PF cleared - rjmp handle_end -;Start writeing to 32 Byte Block ; skip status byte -h_writescratchpad_block: - lds r_temp,pack ; Adresse low byte - andi r_temp,0x1F ;32 byte - add r_bytep,r_temp ;Zur angegebenen Startadresse springen - ;ori r_temp,0x20 ; Set PF flag - sts pack+2,r_temp ;E4:E0 vorher setzen - ; Byte 3 ueberspringen - rjmp handle_end_inc - -h_writescratchpad_setcrc: - ;copy crc to pack - lds r_temp,crc - com r_temp - sts pack+43,r_temp - lds r_temp,crc+1 - com r_temp ; invertieren , komischer name..... - sts pack+44,r_temp - ldi r_mode,OW_WRITE_SCRATCHPAD_CRC - ldi r_sendflag,1 - ldi r_bytep,43 -h_writescratchpad_crc: - cpi r_bytep,45 - breq h_writescratchpad_crc_end - configZ pack,r_bytep - ld r_rwbyte,Z - rjmp handle_end_inc -h_writescratchpad_crc_end: - rjmp handle_end_sleep - - -h_readscratchpad: - cpi r_bytep,35 - breq h_readscratchpad_end - cpi r_bytep,3 - brne h_readscratchpad_read_byte -h_readscratchpad_set_offset: - lds r_temp,pack - andi r_temp,0x1F - ldi r_temp2,3 - add r_temp,r_temp2 - mov r_bytep,r_temp -h_readscratchpad_read_byte: - configZ pack,r_bytep - ld r_rwbyte,Z - rjmp handle_end_inc -h_readscratchpad_end: - rjmp handle_end_sleep - - - -h_copyscratchpad: - cpi r_bytep,3 - brsh h_copyscratchpad_ok - configZ pack,r_bytep - inc r_bytep - ld r_temp,Z - cp r_temp,r_rwbyte - brne h_copyscratchpad_nok - cpi r_bytep,3 - breq h_copyscratchpad_ok - ldi r_bcount,1 - rjmp handle_end -h_copyscratchpad_ok: - ldi r_rwbyte,0xAA - ldi r_sendflag,1 - rjmp handle_end -h_copyscratchpad_nok: - lds r_temp,pack+3 - andi r_temp,~0x80 - sts pack+3,r_temp - rjmp handle_end_sleep - - -h_readmemory_addr: - cpi r_bytep,0 - brne h_readmrmory_addr_byte1 - sts pack,r_rwbyte - rjmp handle_end_inc -h_readmrmory_addr_byte1: - sts pack+1,r_rwbyte - ldi r_mode,OW_READ_MEMORY - ldi r_sendflag,1 - clr r_bytep - rjmp h_readmemory2 -h_readmemory: - lds r_bytep,pack - lds r_temp2,pack+1 - inc r_bytep - clr r_temp - adc r_temp2,r_temp - sbrc r_temp2,1 - rjmp h_readmemory_end - sts pack+1,r_temp - sts pack,r_bytep -h_readmemory2: - lds r_bytep,pack - andi r_bytep,0x1F - configZ pack+3,r_bytep - ld r_rwbyte,Z - rjmp handle_end -h_readmemory_end: - rjmp handle_end_sleep - - - - - - - - -h_readmemorycounter_addr: - cpi r_bytep,0 - brne h_readmrmorycounter_addr_byte1 - sts pack,r_rwbyte - inc r_bytep - ;ldi r_bcount,1 - rjmp handle_end -h_readmrmorycounter_addr_byte1: - sts pack+1,r_rwbyte - ldi r_mode,OW_READ_MEMORYCOUNTER - ;ldi r_bcount,1 - ldi r_sendflag,1 - clr r_bytep - rjmp h_readmemorycounter2 -h_readmemorycounter: - lds r_bytep,pack - lds r_temp2,pack+1 - ldi r_temp,1 ;inc leider kein c flag - add r_bytep,r_temp - clr r_temp - adc r_temp2,r_temp - mov r_temp,r_bytep - andi r_temp,0x1F - breq h_readmemorycounter_next - sts pack+1,r_temp2 - sts pack,r_bytep -h_readmemorycounter2: ;Lesen von dem worauf die erstenzwei bytes zeigen - lds r_bytep,pack - andi r_bytep,0x1F - configZ pack+3,r_bytep - ld r_rwbyte,Z - ;ldi r_bcount,1 - rjmp handle_end -//h_readmemorycounter_end: -// ldi r_mode,OW_SLEEP -// clr r_sendflag -// rjmp handle_end -h_readmemorycounter_next: ; rest lesen - ldi r_mode,OW_READ_MEMORYCOUNTER_EX - ldi r_bytep,34 - lds r_temp2,pack - lds r_temp,pack+1 - //lsr r_temp - //ror r_temp2 - - lsl r_temp2 - rol r_temp - cpi r_temp,3 - brne h_readmemorycounter_cFF - andi r_temp2,0xC0 - swap r_temp2 - - ;cpi r_temp,0xE0 - - configZ counters,r_temp2 - ld r_temp,Z+ - sts pack+35,r_temp - ld r_temp,Z+ - sts pack+36,r_temp - ld r_temp,Z+ - sts pack+37,r_temp - ld r_temp,Z+ - sts pack+38,r_temp - rjmp h_readmemorycounter_ex -h_readmemorycounter_cFF: - ldi r_temp,0xFF - sts pack+35,r_temp - sts pack+36,r_temp - sts pack+37,r_temp - sts pack+38,r_temp - -h_readmemorycounter_ex: - inc r_bytep - cpi r_bytep,45 - breq h_readmemorycounter_ex_end - cpi r_bytep,43 - brne h_readmemorycounter_ex2 - lds r_temp,crc - com r_temp - sts pack+43,r_temp - lds r_temp,crc+1 - com r_temp - sts pack+44,r_temp -h_readmemorycounter_ex2: - ;ldi r_bcount,1 - configZ pack,r_bytep - ld r_rwbyte,Z - rjmp handle_end -h_readmemorycounter_ex_end: - lds r_bytep,pack - lds r_temp2,pack+1 - ldi r_temp,1 ;inc leider kein c flag - add r_bytep,r_temp - clr r_temp - adc r_temp2,r_temp - sbrc r_temp2,1 ;am ene von allem - rjmp h_readmemorycounter_ex_sleep - CRCInit1 - ldi r_mode,OW_READ_MEMORYCOUNTER - sts pack+1,r_temp2 - sts pack,r_bytep - rjmp h_readmemorycounter2 -h_readmemorycounter_ex_sleep: - ldi r_mode,OW_SLEEP - clr r_sendflag - rjmp handle_end - - - - - -#include "../common/OWPinInterrupt.s" + +// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the +// distribution. +// * All advertising materials mentioning features or use of this +// software must display the following acknowledgement: This product +// includes software developed by tm3d.de and its contributors. +// * Neither the name of tm3d.de nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +#define _CHANGEABLE_ID_ +#define _ZERO_POLLING_ +#include "../common/OWConfig.s" +#include "../common/OWCRC16.s" + +.extern pack,45 +.extern counters,8 + +.macro CHIP_INIT +.endm + +.macro COMMAND_TABLE + rjmp h_writescratchpad + rjmp h_writescratchpad_crc + rjmp h_readscratchpad + rjmp h_copyscratchpad + rjmp h_readmemory_addr + rjmp h_readmemory + rjmp h_readmemorycounter_addr + rjmp h_readmemorycounter + rjmp h_readmemorycounter_ex +.endm + +#include "../common/OWRomFunctions.s" +#include "../common/OWTimerInterrupt.s" + + + +; Ab hier Geraeteabhaenging +#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+0 +#define OW_WRITE_SCRATCHPAD_CRC OW_FIRST_COMMAND+1 +#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+2 +#define OW_COPY_SCRATCHPAD OW_FIRST_COMMAND+3 +#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+4 +#define OW_READ_MEMORY OW_FIRST_COMMAND+5 +#define OW_READ_MEMORYCOUNTER_ADDR OW_FIRST_COMMAND+6 +#define OW_READ_MEMORYCOUNTER OW_FIRST_COMMAND+7 +#define OW_READ_MEMORYCOUNTER_EX OW_FIRST_COMMAND+8 + +;--------------------------------------------------- +; READ COMMAND and start operation +;--------------------------------------------------- + + +h_readcommand: + clr r_bytep +#ifndef _DIS_FLASH_ + FLASH_COMMANDS ; muss zu erst sein.... +#endif + cset 0x0F,OW_WRITE_SCRATCHPAD + cjmp 0xAA,hrc_set_readscratchpad + cset 0x5A,OW_COPY_SCRATCHPAD + cset 0xF0,OW_READ_MEMORY_ADDR + cset 0xA5,OW_READ_MEMORYCOUNTER_ADDR + FW_CONFIG_INFO +#ifdef _CHANGEABLE_ID_ + CHANGE_ID_COMMANDS +#endif + ldi r_mode,OW_SLEEP + rjmp handle_end + +hrc_set_readscratchpad: + ldi r_mode,OW_READ_SCRATCHPAD + ldi r_sendflag,1 + rjmp h_readscratchpad + +h_writescratchpad: + configZ pack,r_bytep + inc r_bytep + st Z,r_rwbyte + cpi r_bytep,2 + breq h_writescratchpad_block + brsh h_writescratchpad_set_eoffset ;;33 + rjmp handle_end ;handle_end zu weit entfernt fuer br... +h_writescratchpad_set_eoffset: + cpi r_bytep,35 + breq h_writescratchpad_setcrc + mov r_temp,r_bytep + subi r_temp,4 + sts pack+2,r_temp ;AA und PF cleared + rjmp handle_end +;Start writeing to 32 Byte Block ; skip status byte +h_writescratchpad_block: + lds r_temp,pack ; Adresse low byte + andi r_temp,0x1F ;32 byte + add r_bytep,r_temp ;Zur angegebenen Startadresse springen + ;ori r_temp,0x20 ; Set PF flag + sts pack+2,r_temp ;E4:E0 vorher setzen + ; Byte 3 ueberspringen + rjmp handle_end_inc + +h_writescratchpad_setcrc: + ;copy crc to pack + lds r_temp,crc + com r_temp + sts pack+43,r_temp + lds r_temp,crc+1 + com r_temp ; invertieren , komischer name..... + sts pack+44,r_temp + ldi r_mode,OW_WRITE_SCRATCHPAD_CRC + ldi r_sendflag,1 + ldi r_bytep,43 +h_writescratchpad_crc: + cpi r_bytep,45 + breq h_writescratchpad_crc_end + configZ pack,r_bytep + ld r_rwbyte,Z + rjmp handle_end_inc +h_writescratchpad_crc_end: + rjmp handle_end_sleep + + +h_readscratchpad: + cpi r_bytep,35 + breq h_readscratchpad_end + cpi r_bytep,3 + brne h_readscratchpad_read_byte +h_readscratchpad_set_offset: + lds r_temp,pack + andi r_temp,0x1F + ldi r_temp2,3 + add r_temp,r_temp2 + mov r_bytep,r_temp +h_readscratchpad_read_byte: + configZ pack,r_bytep + ld r_rwbyte,Z + rjmp handle_end_inc +h_readscratchpad_end: + rjmp handle_end_sleep + + + +h_copyscratchpad: + cpi r_bytep,3 + brsh h_copyscratchpad_ok + configZ pack,r_bytep + inc r_bytep + ld r_temp,Z + cp r_temp,r_rwbyte + brne h_copyscratchpad_nok + cpi r_bytep,3 + breq h_copyscratchpad_ok + ldi r_bcount,1 + rjmp handle_end +h_copyscratchpad_ok: + ldi r_rwbyte,0xAA + ldi r_sendflag,1 + rjmp handle_end +h_copyscratchpad_nok: + lds r_temp,pack+3 + andi r_temp,~0x80 + sts pack+3,r_temp + rjmp handle_end_sleep + + +h_readmemory_addr: + cpi r_bytep,0 + brne h_readmrmory_addr_byte1 + sts pack,r_rwbyte + rjmp handle_end_inc +h_readmrmory_addr_byte1: + sts pack+1,r_rwbyte + ldi r_mode,OW_READ_MEMORY + ldi r_sendflag,1 + clr r_bytep + rjmp h_readmemory2 +h_readmemory: + lds r_bytep,pack + lds r_temp2,pack+1 + inc r_bytep + clr r_temp + adc r_temp2,r_temp + sbrc r_temp2,1 + rjmp h_readmemory_end + sts pack+1,r_temp + sts pack,r_bytep +h_readmemory2: + lds r_bytep,pack + andi r_bytep,0x1F + configZ pack+3,r_bytep + ld r_rwbyte,Z + rjmp handle_end +h_readmemory_end: + rjmp handle_end_sleep + + + + + + + + +h_readmemorycounter_addr: + cpi r_bytep,0 + brne h_readmrmorycounter_addr_byte1 + sts pack,r_rwbyte + inc r_bytep + ;ldi r_bcount,1 + rjmp handle_end +h_readmrmorycounter_addr_byte1: + sts pack+1,r_rwbyte + ldi r_mode,OW_READ_MEMORYCOUNTER + ;ldi r_bcount,1 + ldi r_sendflag,1 + clr r_bytep + rjmp h_readmemorycounter2 +h_readmemorycounter: + lds r_bytep,pack + lds r_temp2,pack+1 + ldi r_temp,1 ;inc leider kein c flag + add r_bytep,r_temp + clr r_temp + adc r_temp2,r_temp + mov r_temp,r_bytep + andi r_temp,0x1F + breq h_readmemorycounter_next + sts pack+1,r_temp2 + sts pack,r_bytep +h_readmemorycounter2: ;Lesen von dem worauf die erstenzwei bytes zeigen + lds r_bytep,pack + andi r_bytep,0x1F + configZ pack+3,r_bytep + ld r_rwbyte,Z + ;ldi r_bcount,1 + rjmp handle_end +//h_readmemorycounter_end: +// ldi r_mode,OW_SLEEP +// clr r_sendflag +// rjmp handle_end +h_readmemorycounter_next: ; rest lesen + ldi r_mode,OW_READ_MEMORYCOUNTER_EX + ldi r_bytep,34 + lds r_temp2,pack + lds r_temp,pack+1 + //lsr r_temp + //ror r_temp2 + + lsl r_temp2 + rol r_temp + cpi r_temp,3 + brne h_readmemorycounter_cFF + andi r_temp2,0xC0 + swap r_temp2 + + ;cpi r_temp,0xE0 + + configZ counters,r_temp2 + ld r_temp,Z+ + sts pack+35,r_temp + ld r_temp,Z+ + sts pack+36,r_temp + ld r_temp,Z+ + sts pack+37,r_temp + ld r_temp,Z+ + sts pack+38,r_temp + rjmp h_readmemorycounter_ex +h_readmemorycounter_cFF: + ldi r_temp,0xFF + sts pack+35,r_temp + sts pack+36,r_temp + sts pack+37,r_temp + sts pack+38,r_temp + +h_readmemorycounter_ex: + inc r_bytep + cpi r_bytep,45 + breq h_readmemorycounter_ex_end + cpi r_bytep,43 + brne h_readmemorycounter_ex2 + lds r_temp,crc + com r_temp + sts pack+43,r_temp + lds r_temp,crc+1 + com r_temp + sts pack+44,r_temp +h_readmemorycounter_ex2: + ;ldi r_bcount,1 + configZ pack,r_bytep + ld r_rwbyte,Z + rjmp handle_end +h_readmemorycounter_ex_end: + lds r_bytep,pack + lds r_temp2,pack+1 + ldi r_temp,1 ;inc leider kein c flag + add r_bytep,r_temp + clr r_temp + adc r_temp2,r_temp + sbrc r_temp2,1 ;am ene von allem + rjmp h_readmemorycounter_ex_sleep + CRCInit1 + ldi r_mode,OW_READ_MEMORYCOUNTER + sts pack+1,r_temp2 + sts pack,r_bytep + rjmp h_readmemorycounter2 +h_readmemorycounter_ex_sleep: + ldi r_mode,OW_SLEEP + clr r_sendflag + rjmp handle_end + + + + + +#include "../common/OWPinInterrupt.s" .end \ No newline at end of file diff --git a/common/OWDS2438.S b/common/OWDS2438.S index 35bc463..a7d92fa 100644 --- a/common/OWDS2438.S +++ b/common/OWDS2438.S @@ -1,187 +1,187 @@ -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#define _CHANGEABLE_ID_ -//#define _DIS_FLASH_ -#define _ZERO_POLLING_ -//#define _DB_ - -#include "../common/OWConfig.s" -#include "../common/OWCRC8.s" - -#if defined(__AVR_ATtiny25__) -.extern pack,16 -#else -.extern pack,64 -#endif -.extern am2302_temp,2 -.extern am2302_hum,2 -.comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad) - - -.macro CHIP_INIT -.endm - -; Ab hier Geraeteabhaenging -#define OW_READ_SCRATCHPAD_ADR OW_FIRST_COMMAND+0 -#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+1 -#define OW_WRITE_SCRATCHPAD_ADR OW_FIRST_COMMAND+2 -#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+3 - - - -.macro COMMAND_TABLE - rjmp h_readscratchpad_adr - rjmp h_readscratchpad - rjmp h_writescratchpad_adr - rjmp h_writescratchpad -.endm - -#include "../common/OWRomFunctions.s" -#include "../common/OWTimerInterrupt.s" - - -;--------------------------------------------------- -; READ COMMAND and start operation -;--------------------------------------------------- - - -h_readcommand: - clr r_bytep -#ifndef _DIS_FLASH_ - FLASH_COMMANDS ; muss zu erst sein.... -#endif - cset 0xBE,OW_READ_SCRATCHPAD_ADR - cset 0x4E,OW_WRITE_SCRATCHPAD_ADR - cjmp 0x44,hrc_set_convertT - cjmp 0xB4,hrc_set_convertV - FW_CONFIG_INFO -#ifdef _CHANGEABLE_ID_ - CHANGE_ID_COMMANDS -#endif - rjmp handle_end_sleep - - -hrc_set_convertT: - ldi r_temp,1 - sts gcontrol,r_temp - lds r_temp,am2302_temp - sts pack+1,r_temp - lds r_temp,am2302_temp+1 - sts pack+2,r_temp - rjmp handle_end_sleep -hrc_set_convertV: - ldi r_temp,2 - sts gcontrol,r_temp - lds r_temp,pack - sbrs r_temp,3 - rjmp hrc_set_convertVV - ldi r_temp,0xF4 - sts pack+3,r_temp - ldi r_temp,0x01 - sts pack+4,r_temp - rjmp hrc_set_convertend -hrc_set_convertVV: - lds r_temp,am2302_hum - sts pack+3,r_temp - lds r_temp,am2302_hum+1 - sts pack+4,r_temp -hrc_set_convertend: - rjmp handle_end_sleep - - - -;--------------------------------------------------- -; READ SCRATCHPAD -;--------------------------------------------------- - -h_readscratchpad_adr: - lsl r_rwbyte - lsl r_rwbyte - lsl r_rwbyte -#if defined(__AVR_ATtiny25__) - andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen -#endif - sts block,r_rwbyte - ldi r_sendflag,1 - ldi r_mode,OW_READ_SCRATCHPAD - CRCInit2 -h_readscratchpad: - cpi r_bytep,8 - breq h_readscratchpad_crc - cpi r_bytep,9 - breq h_readscratchpad_all - lds r_temp,block - add r_temp,r_bytep - configZ pack,r_temp - ld r_rwbyte,Z - rjmp handle_end_inc -h_readscratchpad_crc: - lds r_rwbyte,crc - rjmp handle_end_inc -h_readscratchpad_all: - rjmp handle_end_sleep - - - - -;--------------------------------------------------- -; WRITE SCRATCHPAD -;--------------------------------------------------- -h_writescratchpad_adr: - lsl r_rwbyte - lsl r_rwbyte - lsl r_rwbyte -#if defined(__AVR_ATtiny25__) - andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen -#endif - sts block,r_rwbyte - ldi r_mode,OW_WRITE_SCRATCHPAD - ldi r_bcount,1 - rjmp handle_end -h_writescratchpad: - cpi r_bytep,8 - breq h_writescratchpad_all - lds r_temp,block - add r_temp,r_bytep - configZ pack,r_temp - st Z,r_rwbyte - rjmp handle_end_inc -h_writescratchpad_all: - rjmp handle_end_sleep - - - - - -#include "../common/OWPinInterrupt.s" +// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the +// distribution. +// * All advertising materials mentioning features or use of this +// software must display the following acknowledgement: This product +// includes software developed by tm3d.de and its contributors. +// * Neither the name of tm3d.de nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#define _CHANGEABLE_ID_ +//#define _DIS_FLASH_ +#define _ZERO_POLLING_ +//#define _DB_ + +#include "../common/OWConfig.s" +#include "../common/OWCRC8.s" + +#if defined(__AVR_ATtiny25__) +.extern pack,16 +#else +.extern pack,64 +#endif +.extern am2302_temp,2 +.extern am2302_hum,2 +.comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad) + + +.macro CHIP_INIT +.endm + +; Ab hier Geraeteabhaenging +#define OW_READ_SCRATCHPAD_ADR OW_FIRST_COMMAND+0 +#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+1 +#define OW_WRITE_SCRATCHPAD_ADR OW_FIRST_COMMAND+2 +#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+3 + + + +.macro COMMAND_TABLE + rjmp h_readscratchpad_adr + rjmp h_readscratchpad + rjmp h_writescratchpad_adr + rjmp h_writescratchpad +.endm + +#include "../common/OWRomFunctions.s" +#include "../common/OWTimerInterrupt.s" + + +;--------------------------------------------------- +; READ COMMAND and start operation +;--------------------------------------------------- + + +h_readcommand: + clr r_bytep +#ifndef _DIS_FLASH_ + FLASH_COMMANDS ; muss zu erst sein.... +#endif + cset 0xBE,OW_READ_SCRATCHPAD_ADR + cset 0x4E,OW_WRITE_SCRATCHPAD_ADR + cjmp 0x44,hrc_set_convertT + cjmp 0xB4,hrc_set_convertV + FW_CONFIG_INFO +#ifdef _CHANGEABLE_ID_ + CHANGE_ID_COMMANDS +#endif + rjmp handle_end_sleep + + +hrc_set_convertT: + ldi r_temp,1 + sts gcontrol,r_temp + lds r_temp,am2302_temp + sts pack+1,r_temp + lds r_temp,am2302_temp+1 + sts pack+2,r_temp + rjmp handle_end_sleep +hrc_set_convertV: + ldi r_temp,2 + sts gcontrol,r_temp + lds r_temp,pack + sbrs r_temp,3 + rjmp hrc_set_convertVV + ldi r_temp,0xF4 + sts pack+3,r_temp + ldi r_temp,0x01 + sts pack+4,r_temp + rjmp hrc_set_convertend +hrc_set_convertVV: + lds r_temp,am2302_hum + sts pack+3,r_temp + lds r_temp,am2302_hum+1 + sts pack+4,r_temp +hrc_set_convertend: + rjmp handle_end_sleep + + + +;--------------------------------------------------- +; READ SCRATCHPAD +;--------------------------------------------------- + +h_readscratchpad_adr: + lsl r_rwbyte + lsl r_rwbyte + lsl r_rwbyte +#if defined(__AVR_ATtiny25__) + andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen +#endif + sts block,r_rwbyte + ldi r_sendflag,1 + ldi r_mode,OW_READ_SCRATCHPAD + CRCInit2 +h_readscratchpad: + cpi r_bytep,8 + breq h_readscratchpad_crc + cpi r_bytep,9 + breq h_readscratchpad_all + lds r_temp,block + add r_temp,r_bytep + configZ pack,r_temp + ld r_rwbyte,Z + rjmp handle_end_inc +h_readscratchpad_crc: + lds r_rwbyte,crc + rjmp handle_end_inc +h_readscratchpad_all: + rjmp handle_end_sleep + + + + +;--------------------------------------------------- +; WRITE SCRATCHPAD +;--------------------------------------------------- +h_writescratchpad_adr: + lsl r_rwbyte + lsl r_rwbyte + lsl r_rwbyte +#if defined(__AVR_ATtiny25__) + andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen +#endif + sts block,r_rwbyte + ldi r_mode,OW_WRITE_SCRATCHPAD + ldi r_bcount,1 + rjmp handle_end +h_writescratchpad: + cpi r_bytep,8 + breq h_writescratchpad_all + lds r_temp,block + add r_temp,r_bytep + configZ pack,r_temp + st Z,r_rwbyte + rjmp handle_end_inc +h_writescratchpad_all: + rjmp handle_end_sleep + + + + + +#include "../common/OWPinInterrupt.s" .end \ No newline at end of file diff --git a/common/OWPinInterrupt.s b/common/OWPinInterrupt.s index 72aef80..df8952d 100644 --- a/common/OWPinInterrupt.s +++ b/common/OWPinInterrupt.s @@ -1,201 +1,201 @@ -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -.global PIN_INTERRIPT -PIN_INTERRIPT: - ;leitung auf Low ziehen - TESTZEROMARKER ; ueberspringe wenn zeromarker=0 ;sbic und cbi/sbi andern SREG nicht - sbi OW_DDR,OW_PINN - push r_temp2 //; wichtig: Benutzte Register und das - in r_temp2,_SFR_IO_ADDR(SREG) //; Status-Register (SREG) sichern! - ;Zeromarker loeschen - RESETZEROMARKER - ;Weitere Register sichern - push r_temp2 - push r_temp - sdb - ; Wegen Power Down Mode Widerherstellen der fallenden Flanke und disable von POWER DONW - SET_FALLING_RESET_SLEEP - push r_bcount - push r_rwbyte - push r_sendflag - ;schauen ob noch ein Bit in der Pipeline - lds r_bcount,bcount - lds r_rwbyte,rwbyte - lds r_sendflag,sendflag -int_internal_start: - ;Timer zuruecksetzen - ldi r_temp,~OWT_MIN_RESET - out TCNT_REG,r_temp - EN_TIM_INT - tst r_sendflag - breq receive_bit ; sendflag=0 Slave empfaengt - -send_bit: ; bit senden - ;nachstes bit vorbereiten - tst r_bcount - brne send_bit_no_handle ;noch bits da - rcall handle_byte ; neues Byte muss bearbeitet werden - tst r_sendflag - breq send_bit_low_loop ; Nach dem Gelesen byte koennte gesendet werden muessen.... -send_bit_no_handle: ;noch bits da - ldi r_temp2,0 ; fuer die CRC berechnung in CRCS - ror r_rwbyte - brcs send_bit_no_low - SETZEROMARKER - ldi r_temp2,1 ;WICHTIG fuer CRC berechnung -send_bit_no_low: ;ueberspringen von r_wzero=1 wenn leitung nicht auf 0 gezogen wird - CRCS - ;naechstes byte .... - lsl r_bcount - sbis OW_DDR,OW_PINN - rjmp iend ;abkuerzung wenn leitung nicht low -send_bit_low_loop: - in r_temp,TCNT_REG - cpi r_temp,(~OWT_MIN_RESET)+OWT_WRITE ;aller zwei us zaehlt der timer - brlo send_bit_low_loop ;wenn kleiner - cbi OW_DDR,OW_PINN ;Leitung auf hochohmig - rjmp iend - -receive_bit: ;or reset - ;beim lesen zuerst zeit bis zum lesen abwarten - ;(9us nach den 6 us vom low impuls) - in r_temp,TCNT_REG - cpi r_temp,(~OWT_MIN_RESET)+OWT_READ ;aller zwei us zaehlt der timer - brlo receive_bit ;wenn kleiner - lsr r_rwbyte - ldi r_temp2,1 ;fuer CRC Berechnung - sbis OW_PIN,OW_PINN - rjmp receive_bit_crc - ori r_rwbyte,0x80 - ldi r_temp2,0 ;fuer CRC Berechnung -receive_bit_crc: - CRCR - lsl r_bcount - brne recive_bit_no_handle ;bcount nicht 0 - ;naechstes byte .... - rcall handle_byte - tst r_sendflag - brne send_bit ; Nach dem Gelesen byte koennte gesendet werden muessen.... -recive_bit_no_handle: -iend: -#ifdef _ZERO_POLLING_ - ;--------------------------------------- Polling for set low... for 4us low impuls of DS2490 - TESTZEROMARKER ; ueberspringe wenn zeromarker=0 - rjmp zeropolling - rjmp no_zerromaker -zeropolling: - sbrc r_sendflag,1 ; sendflag bit 1 -> switch off zeropolling in software eg for asking convert is donne (DS2450, DS18B20 and others) - rjmp no_zerromaker -zeropolling_h_loop: - sbic OW_PIN,OW_PINN ;warten bis leitung wieder h - rjmp zeropolling_wait ;leitung ist low ->Schleie - in r_temp,TCNT_REG - cpi r_temp,(~OWT_MIN_RESET)+OWT_ZP_WAIT_LOW_TO;aller zwei us zaehlt der timer - brsh zeropolling_timeout ;Timeout Reset? - rjmp zeropolling_h_loop -zeropolling_wait: - sbis OW_PIN,OW_PINN ;warten bis leitung wieder l - rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe - in r_temp,TCNT_REG - cpi r_temp,(~OWT_MIN_RESET)+OWT_ZP_WAIT_HIGH_TO ;aller zwei us zaehlt der timer - sbis OW_PIN,OW_PINN ;noch eine Abfrage, da sonst schleife zu lang (sbis aendert keine flags) - rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe - brlo zeropolling_wait - rjmp zeropolling_timeout -zeropolling_low_imp: - sbi OW_DDR,OW_PINN - RESETZEROMARKER - rjmp int_internal_start - -zeropolling_timeout: - //in r_temp,TCNT_REG - //clr r_sendflag - //RESETZEROMARKER - -no_zerromaker: -#endif - CLEAR_INTERRUPT_FLAG ; wichtig falls inzwischen wider ein Interrupt aufgelaufen ist - sts sendflag,r_sendflag - sts bcount,r_bcount - sts rwbyte,r_rwbyte - pop r_sendflag - pop r_rwbyte - pop r_bcount - pop r_temp - cdb - cbi OW_DDR,OW_PINN ;vorsichtsmassname Nicht dauerhaft auf low - pop r_temp2 //; die benutzten Register wiederherstellen - out _SFR_IO_ADDR(SREG),r_temp2 - pop r_temp2 - reti - - - - -handle_byte: - push zl - push zh - push r_mode - push r_bytep - //cdb - lds r_mode,mode - lds r_bytep,bytep - - - ldi zl,lo8(pm(handle_stable)) - ldi zh,hi8(pm(handle_stable)) - add zl,r_mode -#if ((handle_stable&0xFE00)!=(handle_stable_end&0xFE00)) - ldi r_temp,0 - adc zh,r_temp -#endif - ijmp -handle_end_sleep: - clr r_bcount - ldi r_mode,OW_SLEEP - clr r_sendflag - rjmp handle_end_no_bcount -handle_end_inc: - inc r_bytep -handle_end: - ldi r_bcount,1 -handle_end_no_bcount: - sts mode,r_mode - sts bytep,r_bytep - //sdb - pop r_bytep - pop r_mode - pop zh - pop zl - ret +// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the +// distribution. +// * All advertising materials mentioning features or use of this +// software must display the following acknowledgement: This product +// includes software developed by tm3d.de and its contributors. +// * Neither the name of tm3d.de nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +.global PIN_INTERRIPT +PIN_INTERRIPT: + ;leitung auf Low ziehen + TESTZEROMARKER ; ueberspringe wenn zeromarker=0 ;sbic und cbi/sbi andern SREG nicht + sbi OW_DDR,OW_PINN + push r_temp2 //; wichtig: Benutzte Register und das + in r_temp2,_SFR_IO_ADDR(SREG) //; Status-Register (SREG) sichern! + ;Zeromarker loeschen + RESETZEROMARKER + ;Weitere Register sichern + push r_temp2 + push r_temp + sdb + ; Wegen Power Down Mode Widerherstellen der fallenden Flanke und disable von POWER DONW + SET_FALLING_RESET_SLEEP + push r_bcount + push r_rwbyte + push r_sendflag + ;schauen ob noch ein Bit in der Pipeline + lds r_bcount,bcount + lds r_rwbyte,rwbyte + lds r_sendflag,sendflag +int_internal_start: + ;Timer zuruecksetzen + ldi r_temp,~OWT_MIN_RESET + out TCNT_REG,r_temp + EN_TIM_INT + tst r_sendflag + breq receive_bit ; sendflag=0 Slave empfaengt + +send_bit: ; bit senden + ;nachstes bit vorbereiten + tst r_bcount + brne send_bit_no_handle ;noch bits da + rcall handle_byte ; neues Byte muss bearbeitet werden + tst r_sendflag + breq send_bit_low_loop ; Nach dem Gelesen byte koennte gesendet werden muessen.... +send_bit_no_handle: ;noch bits da + ldi r_temp2,0 ; fuer die CRC berechnung in CRCS + ror r_rwbyte + brcs send_bit_no_low + SETZEROMARKER + ldi r_temp2,1 ;WICHTIG fuer CRC berechnung +send_bit_no_low: ;ueberspringen von r_wzero=1 wenn leitung nicht auf 0 gezogen wird + CRCS + ;naechstes byte .... + lsl r_bcount + sbis OW_DDR,OW_PINN + rjmp iend ;abkuerzung wenn leitung nicht low +send_bit_low_loop: + in r_temp,TCNT_REG + cpi r_temp,(~OWT_MIN_RESET)+OWT_WRITE ;aller zwei us zaehlt der timer + brlo send_bit_low_loop ;wenn kleiner + cbi OW_DDR,OW_PINN ;Leitung auf hochohmig + rjmp iend + +receive_bit: ;or reset + ;beim lesen zuerst zeit bis zum lesen abwarten + ;(9us nach den 6 us vom low impuls) + in r_temp,TCNT_REG + cpi r_temp,(~OWT_MIN_RESET)+OWT_READ ;aller zwei us zaehlt der timer + brlo receive_bit ;wenn kleiner + lsr r_rwbyte + ldi r_temp2,1 ;fuer CRC Berechnung + sbis OW_PIN,OW_PINN + rjmp receive_bit_crc + ori r_rwbyte,0x80 + ldi r_temp2,0 ;fuer CRC Berechnung +receive_bit_crc: + CRCR + lsl r_bcount + brne recive_bit_no_handle ;bcount nicht 0 + ;naechstes byte .... + rcall handle_byte + tst r_sendflag + brne send_bit ; Nach dem Gelesen byte koennte gesendet werden muessen.... +recive_bit_no_handle: +iend: +#ifdef _ZERO_POLLING_ + ;--------------------------------------- Polling for set low... for 4us low impuls of DS2490 + TESTZEROMARKER ; ueberspringe wenn zeromarker=0 + rjmp zeropolling + rjmp no_zerromaker +zeropolling: + sbrc r_sendflag,1 ; sendflag bit 1 -> switch off zeropolling in software eg for asking convert is donne (DS2450, DS18B20 and others) + rjmp no_zerromaker +zeropolling_h_loop: + sbic OW_PIN,OW_PINN ;warten bis leitung wieder h + rjmp zeropolling_wait ;leitung ist low ->Schleie + in r_temp,TCNT_REG + cpi r_temp,(~OWT_MIN_RESET)+OWT_ZP_WAIT_LOW_TO;aller zwei us zaehlt der timer + brsh zeropolling_timeout ;Timeout Reset? + rjmp zeropolling_h_loop +zeropolling_wait: + sbis OW_PIN,OW_PINN ;warten bis leitung wieder l + rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe + in r_temp,TCNT_REG + cpi r_temp,(~OWT_MIN_RESET)+OWT_ZP_WAIT_HIGH_TO ;aller zwei us zaehlt der timer + sbis OW_PIN,OW_PINN ;noch eine Abfrage, da sonst schleife zu lang (sbis aendert keine flags) + rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe + brlo zeropolling_wait + rjmp zeropolling_timeout +zeropolling_low_imp: + sbi OW_DDR,OW_PINN + RESETZEROMARKER + rjmp int_internal_start + +zeropolling_timeout: + //in r_temp,TCNT_REG + //clr r_sendflag + //RESETZEROMARKER + +no_zerromaker: +#endif + CLEAR_INTERRUPT_FLAG ; wichtig falls inzwischen wider ein Interrupt aufgelaufen ist + sts sendflag,r_sendflag + sts bcount,r_bcount + sts rwbyte,r_rwbyte + pop r_sendflag + pop r_rwbyte + pop r_bcount + pop r_temp + cdb + cbi OW_DDR,OW_PINN ;vorsichtsmassname Nicht dauerhaft auf low + pop r_temp2 //; die benutzten Register wiederherstellen + out _SFR_IO_ADDR(SREG),r_temp2 + pop r_temp2 + reti + + + + +handle_byte: + push zl + push zh + push r_mode + push r_bytep + //cdb + lds r_mode,mode + lds r_bytep,bytep + + + ldi zl,lo8(pm(handle_stable)) + ldi zh,hi8(pm(handle_stable)) + add zl,r_mode +#if ((handle_stable&0xFE00)!=(handle_stable_end&0xFE00)) + ldi r_temp,0 + adc zh,r_temp +#endif + ijmp +handle_end_sleep: + clr r_bcount + ldi r_mode,OW_SLEEP + clr r_sendflag + rjmp handle_end_no_bcount +handle_end_inc: + inc r_bytep +handle_end: + ldi r_bcount,1 +handle_end_no_bcount: + sts mode,r_mode + sts bytep,r_bytep + //sdb + pop r_bytep + pop r_mode + pop zh + pop zl + ret diff --git a/common/OWRomFunctions.s b/common/OWRomFunctions.s index e889416..e5c007b 100644 --- a/common/OWRomFunctions.s +++ b/common/OWRomFunctions.s @@ -1,493 +1,493 @@ -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// * All advertising materials mentioning features or use of this -// software must display the following acknowledgement: This product -// includes software developed by tm3d.de and its contributors. -// * Neither the name of tm3d.de nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - - -.macro cjmp val,addr - cpi r_rwbyte,\val - breq \addr -.endm -.macro cljmp val,addr; Weiter sprung, wenn das ziel zu weit entfernt fuer brxx - cpi r_rwbyte,\val - brne 1f - rjmp \addr -1: -.endm - -.macro cset val,mod ;Nur der Mode wird gesetzt. Abkuerzung da oft nur das noch bleibt - cpi r_rwbyte,\val - brne 1f - ldi r_mode,\mod - rjmp handle_end -1: -.endm - - - - -#define OW_SLEEP 0 -#define OW_READ_ROM_COMMAND 1 -#define OW_MATCHROM 2 -#define OW_SEARCHROMS 3 ;next send two bit -#define OW_SEARCHROMR 4 ; next resive master answer -#define OW_READROM 5 -#define OW_READ_COMMAND 6 -#define OW_FWCONFIGINFO 7 - - -#ifdef _CHANGEABLE_ID_ -#define OW_WRITE_NEWID 8 -#define OW_READ_NEWID 9 -#define OW_SET_NEWID 10 -#define OW_FIRST_COMMAND 11 -.comm newid,8 - - -.macro CHANGE_ID_COMMANDS - cset 0x75,OW_WRITE_NEWID - cljmp 0xA7,hrc_set_readid - cljmp 0x79,hrc_set_setid -.endm - - -#else -#define OW_FIRST_COMMAND 8 -#endif - -#ifndef _DIS_FLASH_ -; test auf run flasher command 0x88 in h_readcommand -.macro FLASH_COMMANDS - cpi r_rwbyte,0x88 - brne 1f - rjmp hrc_jmp_flasher -1: ldi r_temp,0 ;Anderes Kommando flashmarker zuruecksetzen... - sts flashmarker,r_temp -.endm -#endif - -.macro FW_CONFIG_INFO - cljmp 0x85,hrc_fw_configinfo -.endm - - -#ifdef _CHANGEABLE_ID_ -; lesen der ID aus dem EEPROM beim Start -read_EEPROM_ID: - push r_bytep - push r_rwbyte//r_temp2 and Z is not in gnu C save area - ldi r_temp2,lo8(E2END) - ldi zh,hi8(E2END) - subi r_temp2,7 - out _SFR_IO_ADDR(EEARH), zh - ldi r_bytep,0 - ldi zl,lo8(owid) - ldi zh,hi8(owid) -read_EEPROM_ID_loop: - sbic _SFR_IO_ADDR(EECR), EEPE - rjmp read_EEPROM_ID_loop - out _SFR_IO_ADDR(EEARL),r_temp2 - sbi _SFR_IO_ADDR(EECR), EERE - in r_rwbyte,_SFR_IO_ADDR(EEDR) - cpi r_rwbyte,0xFF - breq read_EEPROM_ID_end - st Z+,r_rwbyte - inc r_bytep - inc r_temp2 - cpi r_bytep,8 - brne read_EEPROM_ID_loop -read_EEPROM_ID_end: - pop r_rwbyte - pop r_bytep - ret -#endif - - - - - - -handle_stable: - rjmp handle_end_no_bcount // sleep eventuell reset, nichts tun und auf Timeout warten - rjmp h_readromcommand - rjmp h_matchrom - rjmp h_searchroms - rjmp h_searchromr - rjmp h_readrom - rjmp h_readcommand - rjmp h_fwconfiginfo -#ifdef _CHANGEABLE_ID_ - rjmp h_writeid - rjmp h_readid - rjmp h_setid -#endif - COMMAND_TABLE - - - -h_readromcommand: - clr r_bytep - cset 0x55,OW_MATCHROM - cjmp 0xF0,hrc_set_searchrom - cjmp 0xCC,hrc_start_read_command ;skip rom - cjmp 0x33,hrc_set_read_rom - cjmp 0xEC,hrc_set_alarm_search - - rjmp handle_end_sleep - -#ifndef _DIS_FLASH_ -;sprung zum flasher -hrc_jmp_flasher: - lds r_temp,flashmarker - cpi r_temp,2 - brne hrc_jmp_flasher_inc - ldi r_temp,0xC0 - push r_temp - ldi r_temp,0x0E - push r_temp - ret ; Direkter Sprung zum Bootloader -hrc_jmp_flasher_inc: - inc r_temp - sts flashmarker,r_temp - rjmp handle_end_sleep -#endif - - -hrc_set_searchrom: - lds r_rwbyte,owid ;erstes Byte lesen - rjmp h_searchrom_next_bit - -hrc_start_read_command: ;Skip rom und Matchrom ok... - ldi r_mode,OW_READ_COMMAND - CRCInit1 - rjmp handle_end - -hrc_set_read_rom: - ldi r_mode,OW_READROM - ldi r_sendflag,1 - rjmp h_readrom - -hrc_set_alarm_search: - lds r_temp,alarmflag - tst r_temp - brne hrc_set_searchrom ;alarm flag nicht 0 also gehe zu searchrom - ; sonst tue nichts - rjmp handle_end_sleep - - -hrc_fw_configinfo: - ldi r_mode,OW_FWCONFIGINFO - ldi r_sendflag,1 - CRCInit2 - rjmp h_fwconfiginfo - - -;--------------------------------------------------- -; MATCH ROM -;--------------------------------------------------- - - -h_matchrom: - configZ owid,r_bytep - ld r_temp,Z - cp r_temp,r_rwbyte - breq hmr_next_byte - rjmp handle_end_sleep - -hmr_next_byte: - cpi r_bytep,7 - breq hrc_start_read_command ;Starten von Read Command - rjmp handle_end_inc - - - -;--------------------------------------------------- -; SEARCH ROM -;--------------------------------------------------- - - -h_searchrom_next_bit: ;Setup next Bit of ID - sts srbyte,r_rwbyte ;erstes Byte speichern von der Aufrufenden Ebene - mov r_temp2,r_rwbyte - com r_rwbyte ; negieren - ror r_temp2 ; erstes unnegiertes bit in Carry - rol r_rwbyte ;und dann als erstes bit in r_rwbyte - ldi r_sendflag,1 - ldi r_bcount,0x40 ; zwei bits sensden dann zu Searchromr - ldi r_mode,OW_SEARCHROMR - rjmp handle_end_no_bcount - - - -h_searchroms: ; Modus Send zwei bit - clr r_temp - sbrc r_rwbyte,7 ; bit gesetz (1 empfangen) - ldi r_temp,1 - lds r_bcount,srbyte ;r_bcount wird am ende gesetzt - eor r_temp,r_bcount - sbrs r_temp,0 - rjmp h_searchroms_next ; Vergleich des letzen gelesenen bits mit der id - ;Ungleich.... - ;goto sleep - ;clr r_sendflag - ; ist ja auf lesen - rjmp handle_end_sleep -h_searchroms_next: ; Setup next bit - inc r_bytep ; zaehler der Bits erhoehen - sbrc r_bytep,6 ; 64 bit erreicht - rjmp h_searchrom_end_ok ;alles ok auf Command warten - mov r_temp,r_bytep - andi r_temp,0x07 - brne h_searchroms_next_bit ; bit zwischen 0 und 8 - mov r_bcount,r_bytep ; next Byte lesen - lsr r_bcount - lsr r_bcount - lsr r_bcount - - configZ owid,r_bcount - ld r_rwbyte,Z - sts srbyte,r_rwbyte - rjmp h_searchrom_next_bit - -h_searchroms_next_bit: ;next Bit lesen - ;sts srbytep,r_bcount - lds r_rwbyte,srbyte - lsr r_rwbyte ;aktuelles byte weiterschieben r_rwbyte hier zweckefrei verwendet - rjmp h_searchrom_next_bit ;algemeine routine zum vorbereiten -h_searchrom_end_ok: - clr r_sendflag - rjmp hrc_start_read_command - -h_searchromr: - clr r_sendflag - ldi r_mode,OW_SEARCHROMS - ldi r_bcount,0 - rjmp handle_end_no_bcount - - -;--------------------------------------------------- -; READ ROM -;--------------------------------------------------- - -h_readrom: - cpi r_bytep,8 - breq h_readrom_all - configZ owid,r_bytep - ld r_rwbyte,Z - rjmp handle_end_inc -h_readrom_all: - rjmp handle_end_sleep - - -;--------------------------------------------------- -; FW_CONFIG_INFO -;--------------------------------------------------- - -h_fwconfiginfo: - cpi r_bytep,16 - breq h_fwconfiginfo_crc -#ifdef _CRC8_ - cpi r_bytep,17 - breq h_fwconfiginfo_all -#elif defined _CRC16_ - cpi r_bytep,17 - breq h_fwconfiginfo_crc2 - cpi r_bytep,18 - breq h_fwconfiginfo_all -#else - cpi r_bytep,16 - breq h_fwconfiginfo_all -#warning No CRC known code implemented -#endif - configZ config_info,r_bytep - ld r_rwbyte,Z - rjmp handle_end_inc -h_fwconfiginfo_crc: - lds r_rwbyte,crc - rjmp handle_end_inc -h_fwconfiginfo_crc2: - lds r_rwbyte,crc+1 - rjmp handle_end_inc -h_fwconfiginfo_all: - rjmp handle_end_sleep - - -;--------------------------------------------------- -; CHANGE ROM FUNCTIONS -;--------------------------------------------------- - - -#ifdef _CHANGEABLE_ID_ - -h_writeid: - configZ newid,r_bytep - st Z,r_rwbyte - cpi r_bytep,7 - breq h_writeid_all - rjmp handle_end_inc -h_writeid_all: - rjmp handle_end_sleep - - -hrc_set_readid: - ldi r_mode,OW_READ_NEWID - ldi r_sendflag,1 -h_readid: - cpi r_bytep,8 - breq h_readid_all - configZ newid,r_bytep - ld r_rwbyte,Z - rjmp handle_end_inc -h_readid_all: - clr r_sendflag - rjmp handle_end_sleep - -hrc_set_setid: - ldi r_mode,OW_SET_NEWID - ;ldi r_bytep,1 ;start to write in 2 - rjmp handle_end_inc ;set r_bytep to 1!!! - -h_setid: - configZ owid,r_bytep - ld r_temp,Z - cp r_rwbyte,r_temp - brne h_setid_bad_code_all - cpi r_bytep,1 - breq h_setid_set2 - cpi r_bytep,5 - breq h_setid_set3 - cpi r_bytep,6 - breq h_setid_copy_id - rjmp h_setid_bad_code_all ;sollte eigentlich nicht passieren -h_setid_set2: - ldi r_temp,3 - add r_bytep,r_temp -h_setid_set3: - inc r_bytep - rjmp handle_end -h_setid_copy_id: - ldi r_temp2,lo8(E2END) - ldi zh,hi8(E2END) - ldi r_temp,7 - sub r_temp2,r_temp - ;ldi r_temp,0 ;kommt nicht vor das ein E2ROM genau n*256+(0 bis 7) byte gross ist - ;sbc zh - out _SFR_IO_ADDR(EEARH),zh - ldi zl,lo8(newid) - ldi zh,hi8(newid) - ldi r_bytep,0 -h_setid_EEPROM_write: - sbic _SFR_IO_ADDR(EECR), EEPE - rjmp h_setid_EEPROM_write - ldi r_temp, (0< -#include - - - -//const uint8_t cor[] PROGMEM= {0, 3, 6, 10, 13, 17, 20, 24, 27, 30, 34, 37, 41, 44, 47, 51, 54, 58, 61, 64, 68, 71, 75, 78, 81, 85, 88, 91, 95, 98, 101, 105, 108, 111, 115, 118, 121, 125, 128, 131, 135, 138, 141, 144, 148, 151, 154, 158, 161, 164, 167, 171, 174, 177, 180, 184, 187, 190, 193, 197, 200, 203, 206, 209, 213, 216, 219, 222, 225, 229, 232, 235, 238, 241, 245, 248, 251, 254, 255, 255}; - -#define a 7.5 -#define b 237.3 - -inline double SDDD(double t,double x) { - //volatile double p=((a*t/(b+t)-(a*t+a*x)/(b+t+x)))*2000.0; - //return ((p*3.3)/3000.0)+1; - //return ((3.5*((a*t/(b+t)-(a*t+a*x)/(b+t+x)))*2000.0)/3000.0+1); - return 1 - (2.33333 *a* b* x)/((b + t)* (b + t + x)); -} - -double calibr_hum(double temp,double tempdiv,double hum) { - double r=hum*(SDDD(temp,tempdiv)*(tempdiv/(temp+273.15)+1)); - if (r>100) return 100.0; - return r; +#include "calibr.h" +#include +#include + + + +//const uint8_t cor[] PROGMEM= {0, 3, 6, 10, 13, 17, 20, 24, 27, 30, 34, 37, 41, 44, 47, 51, 54, 58, 61, 64, 68, 71, 75, 78, 81, 85, 88, 91, 95, 98, 101, 105, 108, 111, 115, 118, 121, 125, 128, 131, 135, 138, 141, 144, 148, 151, 154, 158, 161, 164, 167, 171, 174, 177, 180, 184, 187, 190, 193, 197, 200, 203, 206, 209, 213, 216, 219, 222, 225, 229, 232, 235, 238, 241, 245, 248, 251, 254, 255, 255}; + +#define a 7.5 +#define b 237.3 + +inline double SDDD(double t,double x) { + //volatile double p=((a*t/(b+t)-(a*t+a*x)/(b+t+x)))*2000.0; + //return ((p*3.3)/3000.0)+1; + //return ((3.5*((a*t/(b+t)-(a*t+a*x)/(b+t+x)))*2000.0)/3000.0+1); + return 1 - (2.33333 *a* b* x)/((b + t)* (b + t + x)); +} + +double calibr_hum(double temp,double tempdiv,double hum) { + double r=hum*(SDDD(temp,tempdiv)*(tempdiv/(temp+273.15)+1)); + if (r>100) return 100.0; + return r; } \ No newline at end of file diff --git a/common/calibr.h b/common/calibr.h index a6bd4fe..2ba627c 100644 --- a/common/calibr.h +++ b/common/calibr.h @@ -1,9 +1,9 @@ -#ifndef CALIBR_H -#define CALIBR_H - - - -double calibr_hum(double temp,double tempdiv,double hum); - - +#ifndef CALIBR_H +#define CALIBR_H + + + +double calibr_hum(double temp,double tempdiv,double hum); + + #endif \ No newline at end of file diff --git a/programmer/flash/flashp 2.7.bat b/programmer/flash/flashp 2.7.bat index 323f30d..8699f70 100644 --- a/programmer/flash/flashp 2.7.bat +++ b/programmer/flash/flashp 2.7.bat @@ -1,2 +1,2 @@ -avrdude -c usbasp -p t84 -U lfuse:w:0xE2:m -U hfuse:w:0xDD:m -U efuse:w:0xFE:m -avrdude -c usbasp -p t84 -e -U flash:w:"../programmer/Release/programmer.hex" +avrdude -c usbasp -p t84 -U lfuse:w:0xE2:m -U hfuse:w:0xDD:m -U efuse:w:0xFE:m +avrdude -c usbasp -p t84 -e -U flash:w:"../programmer/Release/programmer.hex" diff --git a/programmer/flash/flashp.bat b/programmer/flash/flashp.bat index 5159495..86322ed 100644 --- a/programmer/flash/flashp.bat +++ b/programmer/flash/flashp.bat @@ -1,2 +1,2 @@ -avrdude -c usbasp -p t84 -U lfuse:w:0xE2:m -U hfuse:w:0xDE:m -U efuse:w:0xFE:m -avrdude -c usbasp -p t84 -e -U flash:w:"../programmer/Release/programmer.hex" +avrdude -c usbasp -p t84 -U lfuse:w:0xE2:m -U hfuse:w:0xDE:m -U efuse:w:0xFE:m +avrdude -c usbasp -p t84 -e -U flash:w:"../programmer/Release/programmer.hex" diff --git a/programmer/programmer.atsln b/programmer/programmer.atsln index bf34f1d..5b2bfd6 100644 --- a/programmer/programmer.atsln +++ b/programmer/programmer.atsln @@ -1,20 +1,20 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Atmel Studio Solution File, Format Version 11.00 -Project("{18226A42-8477-4023-8AD2-40C49DA407C9}") = "programmer", "programmer\programmer.asmproj", "{73DCF55E-6410-4DEA-8872-EE17F76DD05A}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|AVR = Debug|AVR - Release|AVR = Release|AVR - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Debug|AVR.ActiveCfg = Debug|AVR - {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Debug|AVR.Build.0 = Debug|AVR - {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Release|AVR.ActiveCfg = Release|AVR - {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Release|AVR.Build.0 = Release|AVR - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Atmel Studio Solution File, Format Version 11.00 +Project("{18226A42-8477-4023-8AD2-40C49DA407C9}") = "programmer", "programmer\programmer.asmproj", "{73DCF55E-6410-4DEA-8872-EE17F76DD05A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Debug|AVR.ActiveCfg = Debug|AVR + {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Debug|AVR.Build.0 = Debug|AVR + {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Release|AVR.ActiveCfg = Release|AVR + {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/programmer/programmer/programmer.asm b/programmer/programmer/programmer.asm index d047da0..cccdd18 100644 --- a/programmer/programmer/programmer.asm +++ b/programmer/programmer/programmer.asm @@ -1,489 +1,489 @@ -.def srbyte = r12 ;byty for search rom algorithm -.def writelow = r13; marker for send low -.def zero =r14; always zero -.def smode=r15; if 1 then send -.def temp = r16 ; -.def temp2 = r17; -.def mode = r18 ; -.def bitp = r19 ; bit counter ... shift... -.def rwbyte = r21; -.def param = r22; -.def bytep = r23 ;byte counter -#define spmcrval param - - -.equ OWM_READ_ROM_COMMAND=0 ; 0 wegen schnellen test ist dieser wert 0! Daturch wird die Sprungdabelle nicht verwendet -.equ OWM_SLEEP=1 ; Warten auf Reset -.equ OWM_MATCH_ROM=2 -.equ OWM_SEARCH_ROM_S=3 ;send bit -.equ OWM_SEARCH_ROM_R=4 ;resive master -.equ OWM_READ_COMMAND=5 -.equ OWM_WRITE_SCRATCHPAD=6 -.equ OWM_READ_SCRATCHPAD=7 -.equ OWM_PROGRAMM_PAGE=8 -.equ OWM_RECALL_FLASH=9 - - -.equ OW_DDR = DDRB -.equ OW_PIN = PORTB2 -.equ OW_PORT = PORTB -.equ OW_PINN = PINB - -;.equ SRAM_START = 0x60 - -.macro set_clock - ldi temp,0x80; - out CLKPR,temp - ldi temp,@0 - out CLKPR,temp -.endmacro - -.macro owwl - sbic OW_PINN,OW_PIN - rjmp pc-1 -.endmacro - -.macro owwh - sbis OW_PINN,OW_PIN - rjmp pc-1 -.endmacro - - - - - ;--------------------------------------------------- -; START of PROG -;--------------------------------------------------- - - -.CSEG -.ORG 0x000 -jreset: - rjmp start ; Reset-Vector - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - - -.ORG 0x0EC0 - -start: - cli - ldi temp,0 - mov zero,temp - set_clock 0x00 ;8mhz - ldi mode,OWM_SLEEP - ldi temp,(1< - - - 2.0 - 7.0 - com.Atmel.AVRAssembler - {73dcf55e-6410-4dea-8872-ee17f76dd05a} - none - ATtiny84A - $(MSBuildProjectName) - .obj - $(MSBuildProjectDirectory)\$(Configuration) - ASSEMBLY - programmer - programmer - programmer - $(MSBuildProjectDirectory)\programmer.asm - Native - true - false - true - true - 0x20000000 - - true - exception_table - 2 - 1 - - - - - - - - - - - - - com.atmel.avrdbg.tool.atmelice - - - - 100000 - 0 - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800000779 - Atmel-ICE - - debugWIRE - - J41800000779 - 0x1E930C - - - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc - - - tn84adef.inc - - - Executable - - - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc - - - tn84adef.inc - - - - - - Code - - - + + + + 2.0 + 7.0 + com.Atmel.AVRAssembler + {73dcf55e-6410-4dea-8872-ee17f76dd05a} + none + ATtiny84A + $(MSBuildProjectName) + .obj + $(MSBuildProjectDirectory)\$(Configuration) + ASSEMBLY + programmer + programmer + programmer + $(MSBuildProjectDirectory)\programmer.asm + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + 100000 + 0 + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000779 + Atmel-ICE + + debugWIRE + + J41800000779 + 0x1E930C + + + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc + + + tn84adef.inc + + + Executable + + + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc + + + tn84adef.inc + + + + + + Code + + + \ No newline at end of file diff --git a/programmer/programmer/programmer_4mhz.asm b/programmer/programmer/programmer_4mhz.asm index 9af0938..b08cc96 100644 --- a/programmer/programmer/programmer_4mhz.asm +++ b/programmer/programmer/programmer_4mhz.asm @@ -1,490 +1,490 @@ -.def srbyte = r12 ;byty for search rom algorithm -.def writelow = r13; marker for send low -.def zero =r14; always zero -.def smode=r15; if 1 then send -.def temp = r16 ; -.def temp2 = r17; -.def mode = r18 ; -.def bitp = r19 ; bit counter ... shift... -.def rwbyte = r21; -.def param = r22; -.def bytep = r23 ;byte counter -#define spmcrval param - - -.equ OWM_READ_ROM_COMMAND=0 ; 0 wegen schnellen test ist dieser wert 0! Daturch wird die Sprungdabelle nicht verwendet -.equ OWM_SLEEP=1 ; Warten auf Reset -.equ OWM_MATCH_ROM=2 -.equ OWM_SEARCH_ROM_S=3 ;send bit -.equ OWM_SEARCH_ROM_R=4 ;resive master -.equ OWM_READ_COMMAND=5 -.equ OWM_WRITE_SCRATCHPAD=6 -.equ OWM_READ_SCRATCHPAD=7 -.equ OWM_PROGRAMM_PAGE=8 -.equ OWM_RECALL_FLASH=9 - - -.equ OW_DDR = DDRB -.equ OW_PIN = PORTB2 -.equ OW_PORT = PORTB -.equ OW_PINN = PINB - -;.equ SRAM_START = 0x60 - -.macro set_clock - ldi temp,0x80; - out CLKPR,temp - ldi temp,@0 - out CLKPR,temp -.endmacro - -.macro owwl - sbic OW_PINN,OW_PIN - rjmp pc-1 -.endmacro - -.macro owwh - sbis OW_PINN,OW_PIN - rjmp pc-1 -.endmacro - - - - - ;--------------------------------------------------- -; START of PROG -;--------------------------------------------------- - - -.CSEG -.ORG 0x000 -jreset: - rjmp start ; Reset-Vector - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - reti ; - - -.ORG 0x0EC0 - -start: - cli - ldi temp,0 - mov zero,temp - set_clock 0x01 ;4mhz - ldi mode,OWM_SLEEP - ldi temp,(1<= 0 -#a = 7.6, b = 240.7 fuer T < 0 ueber Wasser (Taupunkt) -#a = 9.5, b = 265.5 fuer T < 0 ueber Eis (Frostpunkt) - -Rs = 8314.3 #J/(kmol*K) (universelle Gaskonstante) -mw = 18.016 #kg/kmol (Molekulargewicht des Wasserdampfes) -#AF = absolute Feuchte in g Wasserdampf pro m3 Luft - -#Formeln: - -# SDD(T) = 6.1078 * 10^((a*T)/(b+T)) -# DD(r,T) = r/100 * SDD(T) -# r(T,TD) = 100 * SDD(TD) / SDD(T) -# TD(r,T) = b*v/(a-v) mit v(r,T) = log10(DD(r,T)/6.1078) -# AF(r,TK) = 10^5 * mw/R* * DD(r,T)/TK; AF(TD,TK) = 10^5 * mw/R* * SDD(TD)/TK - - -a=7.5 -b=237.3 - -#a=r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000 -#r=a*100/(SDD(T)/(T+273.15)*mw/Rs*10000) - -def SDD(T): - return 6.1078 * 10**((a*T)/(b+T)) - -#def DD(r,T): -# return r/100 * SDD(T) - -#def _r(T,TD): -# return 100 * SDD(TD) / SDD(T) - -#def _v(r,T): -# return math.log10(DD(r,T)/6.1078) - -#def TD(r,T): -# return b*v/(a-_v(r,T)) - - -#def AF(r,T): -# return 10000 * mw/Rs * DD(r,T)/(T+273.15) #; AF(TD,TK) = 10^5 * mw/R* * SDD(TD)/TK - -def AF1(r,T): - return r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000 - -def RF1(a,T): - return a*100/(SDD(T)/(T+273.15)*mw/Rs*10000) -#print(0.5*SDD(20)/(20+273.15)*mw/Rs*10000) -d=[] -for i in range(11): - s="" - r=[] - for j in range(6): - r.append((i*10)-RF1(AF1(i*10,j*10),j*10+0.5)) - s=s+"%0.2f\t" % (r[len(r)-1]) - print(s) - d.append(r) - -for i in range(11): - s="" - for j in range(5): - s=s+"%0.4f\t" % (d[i][j]-d[i][j+1]) - print(s) - +import math +#Bezeichnungen: +#r = relative Luftfeuchte +#T = Temperatur in C +#TK = Temperatur in Kelvin (TK = T + 273.15) +#TD = Taupunkttemperatur in C +#DD = Dampfdruck in hPa +#SDD = Saettigungsdampfdruck in hPa + +#Parameter: +#a = 7.5, b = 237.3 fuer T >= 0 +#a = 7.6, b = 240.7 fuer T < 0 ueber Wasser (Taupunkt) +#a = 9.5, b = 265.5 fuer T < 0 ueber Eis (Frostpunkt) + +Rs = 8314.3 #J/(kmol*K) (universelle Gaskonstante) +mw = 18.016 #kg/kmol (Molekulargewicht des Wasserdampfes) +#AF = absolute Feuchte in g Wasserdampf pro m3 Luft + +#Formeln: + +# SDD(T) = 6.1078 * 10^((a*T)/(b+T)) +# DD(r,T) = r/100 * SDD(T) +# r(T,TD) = 100 * SDD(TD) / SDD(T) +# TD(r,T) = b*v/(a-v) mit v(r,T) = log10(DD(r,T)/6.1078) +# AF(r,TK) = 10^5 * mw/R* * DD(r,T)/TK; AF(TD,TK) = 10^5 * mw/R* * SDD(TD)/TK + + +a=7.5 +b=237.3 + +#a=r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000 +#r=a*100/(SDD(T)/(T+273.15)*mw/Rs*10000) + +def SDD(T): + return 6.1078 * 10**((a*T)/(b+T)) + +#def DD(r,T): +# return r/100 * SDD(T) + +#def _r(T,TD): +# return 100 * SDD(TD) / SDD(T) + +#def _v(r,T): +# return math.log10(DD(r,T)/6.1078) + +#def TD(r,T): +# return b*v/(a-_v(r,T)) + + +#def AF(r,T): +# return 10000 * mw/Rs * DD(r,T)/(T+273.15) #; AF(TD,TK) = 10^5 * mw/R* * SDD(TD)/TK + +def AF1(r,T): + return r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000 + +def RF1(a,T): + return a*100/(SDD(T)/(T+273.15)*mw/Rs*10000) +#print(0.5*SDD(20)/(20+273.15)*mw/Rs*10000) +d=[] +for i in range(11): + s="" + r=[] + for j in range(6): + r.append((i*10)-RF1(AF1(i*10,j*10),j*10+0.5)) + s=s+"%0.2f\t" % (r[len(r)-1]) + print(s) + d.append(r) + +for i in range(11): + s="" + for j in range(5): + s=s+"%0.4f\t" % (d[i][j]-d[i][j+1]) + print(s) + diff --git a/stest/find.py b/stest/find.py index 5c28895..415ffe3 100644 --- a/stest/find.py +++ b/stest/find.py @@ -1,292 +1,292 @@ -import sys -import os -import os.path -import subprocess -import io -import time -import math -import shutil - -toolstr="/home/muto/owtools/src/owtools USB1 DC " -devdict={} -devwholist=[] -f=open("DEVLIST.txt","r") -for l in f.readlines(): - ls=l.split(" ") - if (len(ls)>1): - devdict[ls[0]]=l.replace("\n","") - devwholist.append(ls[0]) -f.close() - -def id2string(id): - s="" - for i in range(8): - s=s+"%02X" %(id[7-i]) - return s - -def string2id(s): - for i in range(8): - bl=[] - i2=14-i*2; - bl.append(int(s[i2:i2+2],16)) - return bl - - -def calculateValues(code, V, vn): - if code==1: - return V[vn] / 16.0; - elif code==2: - return V[vn]/1.6; - elif code==3: - return V[vn]*0.2 + 700; - elif code==4: - return math.exp(V[vn] / 160.0); - elif code==5: - return V[vn]*62.5 + 55000; - elif code==6: - return V[vn] / 256.0; - elif code==7: - if V[1]!=0: - return ((float(V[2]) / float(V[1]) - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0); - else: - return 0 - elif code==8: - return V[vn] / 100.0; - elif code==9: - return V[vn] / 65535.0*5.1; - elif code==10: - return V[vn] / 65535.0*2.55; - elif code==11: - return V[vn] / 65535.0*1.1; - elif code==12: - return V[vn] / 10.0; - elif code==13: - return V[vn]; - elif code==14: - return (V[vn] - 32767.0) / 100.0; - elif code==15: - return math.exp((V[vn]-32767.0)/1000.0); - elif code==16: - return V[vn]/32.0; - else: - return 0; - -def getName(code ): - if code==1: - return ["Temperatur","C"] - if code==2: - return ["Druck","hPa"] - if code==3: - return ["Beleuchtungsstaerke","lux"] - if code==4: - return ["Luftfeuchte","%%"] - if code==5: - return ["Konstante",""] - if code==6: - return ["Spannung","V"] - if code==7: - return ["Strom","mA"] - if code==8: - return ["VOC","ppm"] - if code==9: - return ["Counter",""] - return [] - - -def owCom(dev,send,rcount): - cmd=toolstr+id2string(dev) - #for i in range(8): - # cmd=cmd+"%02X" %(dev[7-i]) - cmd=cmd+" " - for b in send: - cmd=cmd+"%02X" % (b) - for i in range(rcount): - cmd=cmd+"FF" - #print(cmd.split(' ')); - p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE) - p.wait() - s=p.stdout.read().decode("utf-8") - l=s.split("\n"); - #print(l[2]) - bl=[] - for i in range(int(len(l[2])/2)): - i2=i*2; - bl.append(int(l[2][i2:i2+2],16)) - return bl - -def owComStr(dev,sendstr): - cmd=toolstr+id2string(dev) - #for i in range(8): - # cmd=cmd+"%02X" %(dev[7-i]) - cmd=cmd+" "+sendstr - p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE) - p.wait() - s=p.stdout.read().decode("utf-8") - #print(s); - ll=s.split("\n"); - bll=[] - for l in ll[2:]: - bl=[] - for i in range(int(len(l)/2)): - i2=i*2; - bl.append(int(l[i2:i2+2],16)) - bll.append(bl) - return bll - -def getValues(dev,voc): - pl=[] - #print(id2string(dev[0]),voc) - if dev[0][0]==0x26: - vnok=1 - rc=0 - while (vnok): - sbl=owComStr(dev[0],"4E000F_RB4_R_P7044_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF") - #print(sbl) - sb=sbl[4] - VDD=(sb[5]+sb[6]*256) - sb=sbl[8] - VAD=(sb[5]+sb[6]*256) - Temp=(sb[3]+sb[4]*256) - if (sb[4] & 0x80): - Temp-=0x10000 - curr=sb[7]+sb[8]*256 - if (sb[8] & 0x80): - curr-=0x10000 - vals=[Temp,VDD,VAD,curr] - formellist=[6,8,7,8] - if dev[1][0]!=0xFF: - formellist=[] - for i in range(4): - if (dev[1][i*2+1])!=0: - formellist.append(dev[1][i*2+1]) - else: - break - cvals=[] - for i in range(len(formellist)): - cvals.append(calculateValues(formellist[i],vals,i)) - if (cvals[2]<=110): - vnok=0 - else: - rc=rc+1 - if (rc==3): - vnok=0 - cvals[2]=100 - if voc!=0: - #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2 - sb=sbl[9] - R0=(sb[2]+sb[3]*256)/100.0 - VS=(sb[4]+sb[5]*256)/10000.0 - Corr=(sb[7]+sb[8]*256)/1000.0 - cmode=sb[6] - RS=(3/VS-1)*30 - RSR0=(RS/R0) - VOC1=RSR0*Corr - VOC2=RSR0/Corr - cvals.append(R0) - cvals.append(VS) - cvals.append(Corr) - cvals.append(cmode) - cvals.append(RS) - cvals.append(RSR0) - cvals.append(VOC1) - cvals.append(VOC2) - return cvals - if dev[0][0]==0x28: - sbl=owComStr(dev[0],"44_R_PFF_PFF_PFF_PFFBEFFFFFFFFFFFFFFFFFF") - Temp=sbl[1][1]+sbl[1][2]*256 - if (sbl[1][2] & 0x80): - Temp=-(Temp&0x7FFF) - if dev[1][0]!=0xFF: - return [calculateValues(dev[1][1],[Temp],0)] - else: - return [calculateValues(1,[Temp],0)] - return [] - - -def owList(): - cmd=toolstr[0:-3] - print(cmd) - p = subprocess.Popen(["./owtools","USB1"], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE) - p.wait() - s=p.stdout.read() - l=s.split("\n") - #print(l); - l=l[1:-1] - devlist=[] - ic=0 - for d in l: - dev=[] - bl=[] - for i in range(8): - i2=14-i*2; - bl.append(int(d[i2:i2+2],16)) - dev.append(bl) - #print(bl) - config=owCom(bl,[0x85],18) - #print(config) - if (config[1]==0xFF): - if (bl[0]==0x26): - config=[0,1,6,6,8,4,7,7,8,0] - if (bl[0]==0x28): - config=[0,1,1,0,0,0,0,0,0,0] - dev.append(config[1:]) - bls=id2string(bl) - cs="%i: " %(ic) - ic=ic+1 - cs=cs+bls+": " - if bls in devdict: - cs=cs+devdict[bls].split(",")[0].split(" ")[1]+" " - for i in range(4): - c=config[i*2+1] - if (c==0xFF): - cs=cs+"Noconfig " - if (bl[0]==0x26): - config=[0,1,6,6,8,4,7,7,8,0] - if (bl[0]==0x28): - config=[0,1,1,0,0,0,0,0,0,0] - break - if (c==0): - break - cs=cs+getName(c)[0]+" " - voc=0 - if bls in devdict: - if "VOC" in devdict[bls]: - voc=1 - l=getValues([bl,config[1:]],voc) - for v in l: - cs=cs+" %0.2f " %(v) - print(cs) - ddev=0 - vm=0 - if config[1]==0x08: - vm=1 - #print("Test_configs") - i=0 - for dv in devlist: - #print("c",dv[1][9:16]) - #print("d",bl[0:7]) - if dv[1][9:16]==bl[0:7]: - print("Double Device") - ddev=1 - dv.append(dev[0]) - dv.append(dev[1]) - #if vm==1: - #voc_marker[i]=2 - i=i+1 - if ddev==0: - devlist.append(dev) - #voc_marker.append(vm) - #print("devlist",devlist) - return devlist - -dl=owList() -#for d in dl: -# print(d) - -#while (1): -# for d in dl: -# ds=id2string(d[0]) -# print(ds) - - +import sys +import os +import os.path +import subprocess +import io +import time +import math +import shutil + +toolstr="/home/muto/owtools/src/owtools USB1 DC " +devdict={} +devwholist=[] +f=open("DEVLIST.txt","r") +for l in f.readlines(): + ls=l.split(" ") + if (len(ls)>1): + devdict[ls[0]]=l.replace("\n","") + devwholist.append(ls[0]) +f.close() + +def id2string(id): + s="" + for i in range(8): + s=s+"%02X" %(id[7-i]) + return s + +def string2id(s): + for i in range(8): + bl=[] + i2=14-i*2; + bl.append(int(s[i2:i2+2],16)) + return bl + + +def calculateValues(code, V, vn): + if code==1: + return V[vn] / 16.0; + elif code==2: + return V[vn]/1.6; + elif code==3: + return V[vn]*0.2 + 700; + elif code==4: + return math.exp(V[vn] / 160.0); + elif code==5: + return V[vn]*62.5 + 55000; + elif code==6: + return V[vn] / 256.0; + elif code==7: + if V[1]!=0: + return ((float(V[2]) / float(V[1]) - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0); + else: + return 0 + elif code==8: + return V[vn] / 100.0; + elif code==9: + return V[vn] / 65535.0*5.1; + elif code==10: + return V[vn] / 65535.0*2.55; + elif code==11: + return V[vn] / 65535.0*1.1; + elif code==12: + return V[vn] / 10.0; + elif code==13: + return V[vn]; + elif code==14: + return (V[vn] - 32767.0) / 100.0; + elif code==15: + return math.exp((V[vn]-32767.0)/1000.0); + elif code==16: + return V[vn]/32.0; + else: + return 0; + +def getName(code ): + if code==1: + return ["Temperatur","C"] + if code==2: + return ["Druck","hPa"] + if code==3: + return ["Beleuchtungsstaerke","lux"] + if code==4: + return ["Luftfeuchte","%%"] + if code==5: + return ["Konstante",""] + if code==6: + return ["Spannung","V"] + if code==7: + return ["Strom","mA"] + if code==8: + return ["VOC","ppm"] + if code==9: + return ["Counter",""] + return [] + + +def owCom(dev,send,rcount): + cmd=toolstr+id2string(dev) + #for i in range(8): + # cmd=cmd+"%02X" %(dev[7-i]) + cmd=cmd+" " + for b in send: + cmd=cmd+"%02X" % (b) + for i in range(rcount): + cmd=cmd+"FF" + #print(cmd.split(' ')); + p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE) + p.wait() + s=p.stdout.read().decode("utf-8") + l=s.split("\n"); + #print(l[2]) + bl=[] + for i in range(int(len(l[2])/2)): + i2=i*2; + bl.append(int(l[2][i2:i2+2],16)) + return bl + +def owComStr(dev,sendstr): + cmd=toolstr+id2string(dev) + #for i in range(8): + # cmd=cmd+"%02X" %(dev[7-i]) + cmd=cmd+" "+sendstr + p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE) + p.wait() + s=p.stdout.read().decode("utf-8") + #print(s); + ll=s.split("\n"); + bll=[] + for l in ll[2:]: + bl=[] + for i in range(int(len(l)/2)): + i2=i*2; + bl.append(int(l[i2:i2+2],16)) + bll.append(bl) + return bll + +def getValues(dev,voc): + pl=[] + #print(id2string(dev[0]),voc) + if dev[0][0]==0x26: + vnok=1 + rc=0 + while (vnok): + sbl=owComStr(dev[0],"4E000F_RB4_R_P7044_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF") + #print(sbl) + sb=sbl[4] + VDD=(sb[5]+sb[6]*256) + sb=sbl[8] + VAD=(sb[5]+sb[6]*256) + Temp=(sb[3]+sb[4]*256) + if (sb[4] & 0x80): + Temp-=0x10000 + curr=sb[7]+sb[8]*256 + if (sb[8] & 0x80): + curr-=0x10000 + vals=[Temp,VDD,VAD,curr] + formellist=[6,8,7,8] + if dev[1][0]!=0xFF: + formellist=[] + for i in range(4): + if (dev[1][i*2+1])!=0: + formellist.append(dev[1][i*2+1]) + else: + break + cvals=[] + for i in range(len(formellist)): + cvals.append(calculateValues(formellist[i],vals,i)) + if (cvals[2]<=110): + vnok=0 + else: + rc=rc+1 + if (rc==3): + vnok=0 + cvals[2]=100 + if voc!=0: + #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2 + sb=sbl[9] + R0=(sb[2]+sb[3]*256)/100.0 + VS=(sb[4]+sb[5]*256)/10000.0 + Corr=(sb[7]+sb[8]*256)/1000.0 + cmode=sb[6] + RS=(3/VS-1)*30 + RSR0=(RS/R0) + VOC1=RSR0*Corr + VOC2=RSR0/Corr + cvals.append(R0) + cvals.append(VS) + cvals.append(Corr) + cvals.append(cmode) + cvals.append(RS) + cvals.append(RSR0) + cvals.append(VOC1) + cvals.append(VOC2) + return cvals + if dev[0][0]==0x28: + sbl=owComStr(dev[0],"44_R_PFF_PFF_PFF_PFFBEFFFFFFFFFFFFFFFFFF") + Temp=sbl[1][1]+sbl[1][2]*256 + if (sbl[1][2] & 0x80): + Temp=-(Temp&0x7FFF) + if dev[1][0]!=0xFF: + return [calculateValues(dev[1][1],[Temp],0)] + else: + return [calculateValues(1,[Temp],0)] + return [] + + +def owList(): + cmd=toolstr[0:-3] + print(cmd) + p = subprocess.Popen(["./owtools","USB1"], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE) + p.wait() + s=p.stdout.read() + l=s.split("\n") + #print(l); + l=l[1:-1] + devlist=[] + ic=0 + for d in l: + dev=[] + bl=[] + for i in range(8): + i2=14-i*2; + bl.append(int(d[i2:i2+2],16)) + dev.append(bl) + #print(bl) + config=owCom(bl,[0x85],18) + #print(config) + if (config[1]==0xFF): + if (bl[0]==0x26): + config=[0,1,6,6,8,4,7,7,8,0] + if (bl[0]==0x28): + config=[0,1,1,0,0,0,0,0,0,0] + dev.append(config[1:]) + bls=id2string(bl) + cs="%i: " %(ic) + ic=ic+1 + cs=cs+bls+": " + if bls in devdict: + cs=cs+devdict[bls].split(",")[0].split(" ")[1]+" " + for i in range(4): + c=config[i*2+1] + if (c==0xFF): + cs=cs+"Noconfig " + if (bl[0]==0x26): + config=[0,1,6,6,8,4,7,7,8,0] + if (bl[0]==0x28): + config=[0,1,1,0,0,0,0,0,0,0] + break + if (c==0): + break + cs=cs+getName(c)[0]+" " + voc=0 + if bls in devdict: + if "VOC" in devdict[bls]: + voc=1 + l=getValues([bl,config[1:]],voc) + for v in l: + cs=cs+" %0.2f " %(v) + print(cs) + ddev=0 + vm=0 + if config[1]==0x08: + vm=1 + #print("Test_configs") + i=0 + for dv in devlist: + #print("c",dv[1][9:16]) + #print("d",bl[0:7]) + if dv[1][9:16]==bl[0:7]: + print("Double Device") + ddev=1 + dv.append(dev[0]) + dv.append(dev[1]) + #if vm==1: + #voc_marker[i]=2 + i=i+1 + if ddev==0: + devlist.append(dev) + #voc_marker.append(vm) + #print("devlist",devlist) + return devlist + +dl=owList() +#for d in dl: +# print(d) + +#while (1): +# for d in dl: +# ds=id2string(d[0]) +# print(ds) + + \ No newline at end of file diff --git a/stest/log_all1.py b/stest/log_all1.py index 323d6fa..70b3e17 100644 --- a/stest/log_all1.py +++ b/stest/log_all1.py @@ -1,341 +1,341 @@ -import sys -import os -import os.path -import subprocess -import io -import time -import datetime -import math -import shutil - -toolstr="/home/muto/owtools/src/owtools USB1 DC " -devdict={} -devwholist=[] -f=open("DEVLIST.txt","r") -for l in f.readlines(): - ls=l.split(" ") - if (len(ls)>1): - devdict[ls[0]]=l.replace("\n","") - devwholist.append(ls[0]) -f.close() - -def id2string(id): - s="" - for i in range(8): - s=s+"%02X" %(id[7-i]) - return s - -def string2id(s): - for i in range(8): - bl=[] - i2=14-i*2; - bl.append(int(s[i2:i2+2],16)) - return bl - - -def calculateValues(code, V, vn): - if code==1: - return V[vn] / 16.0; - elif code==2: - return V[vn]/1.6; - elif code==3: - return V[vn]*0.2 + 700; - elif code==4: - return math.exp(V[vn] / 160.0); - elif code==5: - return V[vn]*62.5 + 55000; - elif code==6: - return V[vn] / 256.0; - elif code==7: - if V[1]!=0: - return ((float(V[2]) / float(V[1]) - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0); - else: - return 0 - elif code==8: - return V[vn] / 100.0; - elif code==9: - return V[vn] / 65535.0*5.1; - elif code==10: - return V[vn] / 65535.0*2.55; - elif code==11: - return V[vn] / 65535.0*1.1; - elif code==12: - return V[vn] / 10.0; - elif code==13: - return V[vn]; - elif code==14: - return (V[vn] - 32767.0) / 100.0; - elif code==15: - return math.exp((V[vn]-32767.0)/1000.0); - elif code==16: - return V[vn]/32.0; - else: - return 0; - -def getName(code ): - if code==1: - return ["Temperatur","C"] - if code==2: - return ["Druck","hPa"] - if code==3: - return ["Beleuchtungsstaerke","lux"] - if code==4: - return ["Luftfeuchte","%%"] - if code==5: - return ["Konstante",""] - if code==6: - return ["Spannung","V"] - if code==7: - return ["Strom","mA"] - if code==8: - return ["VOC","ppm"] - if code==9: - return ["Counter",""] - return [] - - -def owCom(dev,send,rcount): - cmd=toolstr+id2string(dev) - #for i in range(8): - # cmd=cmd+"%02X" %(dev[7-i]) - cmd=cmd+" " - for b in send: - cmd=cmd+"%02X" % (b) - for i in range(rcount): - cmd=cmd+"FF" - #print(cmd.split(' ')); - p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE) - p.wait() - s=p.stdout.read().decode("utf-8") - l=s.split("\n"); - #print(l[2]) - bl=[] - for i in range(int(len(l[2])/2)): - i2=i*2; - bl.append(int(l[2][i2:i2+2],16)) - return bl - -def owComStr(dev,sendstr): - cmd=toolstr+id2string(dev) - #for i in range(8): - # cmd=cmd+"%02X" %(dev[7-i]) - cmd=cmd+" "+sendstr - p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE) - p.wait() - s=p.stdout.read().decode("utf-8") - #print(s); - ll=s.split("\n"); - bll=[] - for l in ll[2:]: - bl=[] - for i in range(int(len(l)/2)): - i2=i*2; - bl.append(int(l[i2:i2+2],16)) - bll.append(bl) - return bll - -def getValues(dev,voc): - pl=[] - #print(id2string(dev[0]),voc) - if dev[0][0]==0x26: - vnok=1 - rc=0 - while (vnok): - sbl=owComStr(dev[0],"4E000F_RB4_R_P7044_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF") - #print(sbl) - sb=sbl[4] - VDD=(sb[5]+sb[6]*256) - sb=sbl[8] - VAD=(sb[5]+sb[6]*256) - Temp=(sb[3]+sb[4]*256) - if (sb[4] & 0x80): - Temp-=0x10000 - curr=sb[7]+sb[8]*256 - if (sb[8] & 0x80): - curr-=0x10000 - vals=[Temp,VDD,VAD,curr] - formellist=[6,8,7,8] - if dev[1][0]!=0xFF: - formellist=[] - for i in range(4): - if (dev[1][i*2+1])!=0: - formellist.append(dev[1][i*2+1]) - else: - break - cvals=[] - for i in range(len(formellist)): - cvals.append(calculateValues(formellist[i],vals,i)) - if (cvals[2]<=110): - vnok=0 - else: - rc=rc+1 - if (rc==3): - vnok=0 - cvals[2]=100 - if voc!=0: - #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2 - sb=sbl[9] - R0=(sb[2]+sb[3]*256)/100.0 - VS=(sb[4]+sb[5]*256)/10000.0 - Corr=(sb[7]+sb[8]*256)/1000.0 - cmode=sb[6] - RS=(3/VS-1)*30 - RSR0=(RS/R0) - VOC1=RSR0*Corr - VOC2=RSR0/Corr - cvals.append(R0) - cvals.append(VS) - cvals.append(Corr) - cvals.append(cmode) - cvals.append(RS) - cvals.append(RSR0) - cvals.append(VOC1) - cvals.append(VOC2) - return cvals - if dev[0][0]==0x28: - sbl=owComStr(dev[0],"44_R_PFF_PFF_PFF_PFFBEFFFFFFFFFFFFFFFFFF") - Temp=sbl[1][1]+sbl[1][2]*256 - if (sbl[1][2] & 0x80): - Temp=-(Temp&0x7FFF) - if dev[1][0]!=0xFF: - return [calculateValues(dev[1][1],[Temp],0)] - else: - return [calculateValues(1,[Temp],0)] - return [] - - -def owList(): - cmd=toolstr[0:-3] - print(cmd) - p = subprocess.Popen(["./owtools","USB1"], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE) - p.wait() - s=p.stdout.read() - l=s.split("\n") - #print(l); - l=l[1:-1] - devlist=[] - ic=0 - for d in l: - dev=[] - bl=[] - for i in range(8): - i2=14-i*2; - bl.append(int(d[i2:i2+2],16)) - dev.append(bl) - #print(bl) - config=owCom(bl,[0x85],18) - #print(config) - if (config[1]==0xFF): - if (bl[0]==0x26): - config=[0,1,6,6,8,4,7,7,8,0] - if (bl[0]==0x28): - config=[0,1,1,0,0,0,0,0,0,0] - dev.append(config[1:]) - bls=id2string(bl) - cs="%i: " %(ic) - ic=ic+1 - cs=cs+bls+": " - if bls in devdict: - cs=cs+devdict[bls].split(",")[0].split(" ")[1]+" " - for i in range(4): - c=config[i*2+1] - if (c==0xFF): - cs=cs+"Noconfig " - config=[0,0,0,0,0,0,0,0,0,0] - break - if (c==0): - break - cs=cs+getName(c)[0]+" " - #voc=0 - #if bls in devdict: - # if "VOC" in devdict[bls]: - # voc=1 - #l=getValues([bl,config[1:]],voc) - #for v in l: - # cs=cs+" %0.2f " %(v) - print(cs) - ddev=0 - vm=0 - if config[1]==0x08: - vm=1 - #print("Test_configs") - i=0 - for dv in devlist: - #print("c",dv[1][9:16]) - #print("d",bl[0:7]) - if dv[1][9:16]==bl[0:7]: - print("Double Device") - ddev=1 - dv.append(dev[0]) - dv.append(dev[1]) - #if vm==1: - #voc_marker[i]=2 - i=i+1 - #if ddev==0: - devlist.append(dev) - #voc_marker.append(vm) - #print("devlist",devlist) - return devlist - -dl=owList() -#for d in dl: -# print(d) - -while (1): - lt = time.localtime() - vline=time.strftime("%d#%m#%Y %H:%M:%S\t", lt) - n = datetime.datetime.now() - unix_timestamp = time.mktime(n.timetuple())# works if Python >= 3.3 - for d in dl: - ds=id2string(d[0]) - bezeichnung="not in List" - if ds in devdict: - bezeichnung=devdict[ds].split(",")[0].split(" ")[1]+" " - vnames=[] - for i in range(4): - c=d[1][i*2] - if (c==0): - break - name=getName(c) - if name!=[]: - vnames.append(name[0]) - voc=0 - if "VOC" in bezeichnung: - voc=1 - vnames.append("R0") - vnames.append("VS") - vnames.append("Corr") - vnames.append("cmode") - vnames.append("RS") - vnames.append("RSR0") - vnames.append("VOC1") - vnames.append("VOC2") - #print(ds) - l=getValues([d[0],d[1]],voc) - s=vline+"%i" %(unix_timestamp) - for i in range(len(l)): - print("%s %s: %0.2f " %(bezeichnung,vnames[i],l[i])) - s=s+"\t%0.4f" % (l[i]) - fname="log_%s.ow1" %(ds) - writeheader=1 - if os.path.exists(fname): - writeheader=0 - f=open(fname,"a") - if writeheader==1: - sh="time\tunixtime" - for i in range(len(l)): - sh=sh+"\t%s" % (vnames[i]) - f.write(sh+"\n") - f.write(s.replace(".",",").replace("#",".")+"\n") - f.close() - #execfile("separate1.py") - os.system("python separate1.py") - print("--------------------") - n = datetime.datetime.now() - unix_timestamp1 = time.mktime(n.timetuple())# works if Python >= 3.3 - d=unix_timestamp1-unix_timestamp - print (d) - print("--------------------") - time.sleep(120-d) - +import sys +import os +import os.path +import subprocess +import io +import time +import datetime +import math +import shutil + +toolstr="/home/muto/owtools/src/owtools USB1 DC " +devdict={} +devwholist=[] +f=open("DEVLIST.txt","r") +for l in f.readlines(): + ls=l.split(" ") + if (len(ls)>1): + devdict[ls[0]]=l.replace("\n","") + devwholist.append(ls[0]) +f.close() + +def id2string(id): + s="" + for i in range(8): + s=s+"%02X" %(id[7-i]) + return s + +def string2id(s): + for i in range(8): + bl=[] + i2=14-i*2; + bl.append(int(s[i2:i2+2],16)) + return bl + + +def calculateValues(code, V, vn): + if code==1: + return V[vn] / 16.0; + elif code==2: + return V[vn]/1.6; + elif code==3: + return V[vn]*0.2 + 700; + elif code==4: + return math.exp(V[vn] / 160.0); + elif code==5: + return V[vn]*62.5 + 55000; + elif code==6: + return V[vn] / 256.0; + elif code==7: + if V[1]!=0: + return ((float(V[2]) / float(V[1]) - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0); + else: + return 0 + elif code==8: + return V[vn] / 100.0; + elif code==9: + return V[vn] / 65535.0*5.1; + elif code==10: + return V[vn] / 65535.0*2.55; + elif code==11: + return V[vn] / 65535.0*1.1; + elif code==12: + return V[vn] / 10.0; + elif code==13: + return V[vn]; + elif code==14: + return (V[vn] - 32767.0) / 100.0; + elif code==15: + return math.exp((V[vn]-32767.0)/1000.0); + elif code==16: + return V[vn]/32.0; + else: + return 0; + +def getName(code ): + if code==1: + return ["Temperatur","C"] + if code==2: + return ["Druck","hPa"] + if code==3: + return ["Beleuchtungsstaerke","lux"] + if code==4: + return ["Luftfeuchte","%%"] + if code==5: + return ["Konstante",""] + if code==6: + return ["Spannung","V"] + if code==7: + return ["Strom","mA"] + if code==8: + return ["VOC","ppm"] + if code==9: + return ["Counter",""] + return [] + + +def owCom(dev,send,rcount): + cmd=toolstr+id2string(dev) + #for i in range(8): + # cmd=cmd+"%02X" %(dev[7-i]) + cmd=cmd+" " + for b in send: + cmd=cmd+"%02X" % (b) + for i in range(rcount): + cmd=cmd+"FF" + #print(cmd.split(' ')); + p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE) + p.wait() + s=p.stdout.read().decode("utf-8") + l=s.split("\n"); + #print(l[2]) + bl=[] + for i in range(int(len(l[2])/2)): + i2=i*2; + bl.append(int(l[2][i2:i2+2],16)) + return bl + +def owComStr(dev,sendstr): + cmd=toolstr+id2string(dev) + #for i in range(8): + # cmd=cmd+"%02X" %(dev[7-i]) + cmd=cmd+" "+sendstr + p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE) + p.wait() + s=p.stdout.read().decode("utf-8") + #print(s); + ll=s.split("\n"); + bll=[] + for l in ll[2:]: + bl=[] + for i in range(int(len(l)/2)): + i2=i*2; + bl.append(int(l[i2:i2+2],16)) + bll.append(bl) + return bll + +def getValues(dev,voc): + pl=[] + #print(id2string(dev[0]),voc) + if dev[0][0]==0x26: + vnok=1 + rc=0 + while (vnok): + sbl=owComStr(dev[0],"4E000F_RB4_R_P7044_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF") + #print(sbl) + sb=sbl[4] + VDD=(sb[5]+sb[6]*256) + sb=sbl[8] + VAD=(sb[5]+sb[6]*256) + Temp=(sb[3]+sb[4]*256) + if (sb[4] & 0x80): + Temp-=0x10000 + curr=sb[7]+sb[8]*256 + if (sb[8] & 0x80): + curr-=0x10000 + vals=[Temp,VDD,VAD,curr] + formellist=[6,8,7,8] + if dev[1][0]!=0xFF: + formellist=[] + for i in range(4): + if (dev[1][i*2+1])!=0: + formellist.append(dev[1][i*2+1]) + else: + break + cvals=[] + for i in range(len(formellist)): + cvals.append(calculateValues(formellist[i],vals,i)) + if (cvals[2]<=110): + vnok=0 + else: + rc=rc+1 + if (rc==3): + vnok=0 + cvals[2]=100 + if voc!=0: + #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2 + sb=sbl[9] + R0=(sb[2]+sb[3]*256)/100.0 + VS=(sb[4]+sb[5]*256)/10000.0 + Corr=(sb[7]+sb[8]*256)/1000.0 + cmode=sb[6] + RS=(3/VS-1)*30 + RSR0=(RS/R0) + VOC1=RSR0*Corr + VOC2=RSR0/Corr + cvals.append(R0) + cvals.append(VS) + cvals.append(Corr) + cvals.append(cmode) + cvals.append(RS) + cvals.append(RSR0) + cvals.append(VOC1) + cvals.append(VOC2) + return cvals + if dev[0][0]==0x28: + sbl=owComStr(dev[0],"44_R_PFF_PFF_PFF_PFFBEFFFFFFFFFFFFFFFFFF") + Temp=sbl[1][1]+sbl[1][2]*256 + if (sbl[1][2] & 0x80): + Temp=-(Temp&0x7FFF) + if dev[1][0]!=0xFF: + return [calculateValues(dev[1][1],[Temp],0)] + else: + return [calculateValues(1,[Temp],0)] + return [] + + +def owList(): + cmd=toolstr[0:-3] + print(cmd) + p = subprocess.Popen(["./owtools","USB1"], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE) + p.wait() + s=p.stdout.read() + l=s.split("\n") + #print(l); + l=l[1:-1] + devlist=[] + ic=0 + for d in l: + dev=[] + bl=[] + for i in range(8): + i2=14-i*2; + bl.append(int(d[i2:i2+2],16)) + dev.append(bl) + #print(bl) + config=owCom(bl,[0x85],18) + #print(config) + if (config[1]==0xFF): + if (bl[0]==0x26): + config=[0,1,6,6,8,4,7,7,8,0] + if (bl[0]==0x28): + config=[0,1,1,0,0,0,0,0,0,0] + dev.append(config[1:]) + bls=id2string(bl) + cs="%i: " %(ic) + ic=ic+1 + cs=cs+bls+": " + if bls in devdict: + cs=cs+devdict[bls].split(",")[0].split(" ")[1]+" " + for i in range(4): + c=config[i*2+1] + if (c==0xFF): + cs=cs+"Noconfig " + config=[0,0,0,0,0,0,0,0,0,0] + break + if (c==0): + break + cs=cs+getName(c)[0]+" " + #voc=0 + #if bls in devdict: + # if "VOC" in devdict[bls]: + # voc=1 + #l=getValues([bl,config[1:]],voc) + #for v in l: + # cs=cs+" %0.2f " %(v) + print(cs) + ddev=0 + vm=0 + if config[1]==0x08: + vm=1 + #print("Test_configs") + i=0 + for dv in devlist: + #print("c",dv[1][9:16]) + #print("d",bl[0:7]) + if dv[1][9:16]==bl[0:7]: + print("Double Device") + ddev=1 + dv.append(dev[0]) + dv.append(dev[1]) + #if vm==1: + #voc_marker[i]=2 + i=i+1 + #if ddev==0: + devlist.append(dev) + #voc_marker.append(vm) + #print("devlist",devlist) + return devlist + +dl=owList() +#for d in dl: +# print(d) + +while (1): + lt = time.localtime() + vline=time.strftime("%d#%m#%Y %H:%M:%S\t", lt) + n = datetime.datetime.now() + unix_timestamp = time.mktime(n.timetuple())# works if Python >= 3.3 + for d in dl: + ds=id2string(d[0]) + bezeichnung="not in List" + if ds in devdict: + bezeichnung=devdict[ds].split(",")[0].split(" ")[1]+" " + vnames=[] + for i in range(4): + c=d[1][i*2] + if (c==0): + break + name=getName(c) + if name!=[]: + vnames.append(name[0]) + voc=0 + if "VOC" in bezeichnung: + voc=1 + vnames.append("R0") + vnames.append("VS") + vnames.append("Corr") + vnames.append("cmode") + vnames.append("RS") + vnames.append("RSR0") + vnames.append("VOC1") + vnames.append("VOC2") + #print(ds) + l=getValues([d[0],d[1]],voc) + s=vline+"%i" %(unix_timestamp) + for i in range(len(l)): + print("%s %s: %0.2f " %(bezeichnung,vnames[i],l[i])) + s=s+"\t%0.4f" % (l[i]) + fname="log_%s.ow1" %(ds) + writeheader=1 + if os.path.exists(fname): + writeheader=0 + f=open(fname,"a") + if writeheader==1: + sh="time\tunixtime" + for i in range(len(l)): + sh=sh+"\t%s" % (vnames[i]) + f.write(sh+"\n") + f.write(s.replace(".",",").replace("#",".")+"\n") + f.close() + #execfile("separate1.py") + os.system("python separate1.py") + print("--------------------") + n = datetime.datetime.now() + unix_timestamp1 = time.mktime(n.timetuple())# works if Python >= 3.3 + d=unix_timestamp1-unix_timestamp + print (d) + print("--------------------") + time.sleep(120-d) + \ No newline at end of file diff --git a/stest/separate1.py b/stest/separate1.py index bffda77..b1c2871 100644 --- a/stest/separate1.py +++ b/stest/separate1.py @@ -1,103 +1,103 @@ -import sys -import os -import os.path -import subprocess -import io -import time -import math -import shutil -import datetime - - -#Parameter: -#a = 7.5, b = 237.3 fuer T >= 0 -#a = 7.6, b = 240.7 fuer T < 0 ueber Wasser (Taupunkt) -#a = 9.5, b = 265.5 fuer T < 0 ueber Eis (Frostpunkt) -a=7.5 -b=237.3 -Rs = 8314.3 #J/(kmol*K) (universelle Gaskonstante) -mw = 18.016 #kg/kmol (Molekulargewicht des Wasserdampfes) - -def SDD(T): - return 6.1078 * 10**((a*T)/(b+T)) - -def AF1(r,T): - return r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000 - -def RF1(a,T): - return a*100/(SDD(T)/(T+273.15)*mw/Rs*10000) -#print(0.5*SDD(20)/(20+273.15)*mw/Rs*10000) - -def rdiff(r1,t1,t2): - return (r1)-RF1(AF1(r1,t1),t2) - - -def calcDerivation(Name,Valuetype,Value,T): - return [0.5,0.5] - - -devdict={} -devwholist=[] -f=open("DEVLIST.txt","r") -for l in f.readlines(): - ls=l.split(" ") - if (len(ls)>1): - devdict[ls[0]]=l.replace("\n","").split(",")[0].split(" ")[1] - devwholist.append(ls[0]) -f.close() - -sel_list=["Temperatur","Luftfeuchte","Beleuchtungsstaerke","R0","VOC","RS","Corr"] -data=[] -for s in sel_list: - data.append(["Time"]) - -for ds in devwholist: #fuer Jedes Geraet in DEVLIST.txt - fname="log_%s.ow1" %(ds) #Sind Daten da? - if os.path.exists(fname): - f=open(fname,"r") #Lesen - lines=f.readlines() - ti=lines[0][:-1].split("\t") #Ueberschriften aufteilen - i=0 - if ("Temperatur" in ti): - tempindex=ti.index("Temperatur") - for t in ti: #fuer jedes Element in der Ueberschrift - if t in sel_list: #schauen ob es Uebernommen werden soll - p=sel_list.index(t) #schaue nach Nummer in der Datenbank - data[p][0]=data[p][0]+","+ds+" "+devdict[ds] #hinzufuegen der Ueberschrift in der Tabelle - if len(data[p])==1: #erstes Element, Time einfuegen und neue zeile anlegen - for l in lines[1:]: - l=l[:-1] - ll=l.split("\t") - la=ll[0].split(" ") - lb=la[0].split(".") - ts=lb[2]+"/"+lb[1]+"/"+lb[0]+" "+la[1] - data[p].append(ts) - j=1; - for l in lines[1:]: - #print(ll) - l=l[:-1] #\n wegmachen - ll=l.split("\t") #telen - fl=float(ll[i].replace(",",".")) - if "VOC" in devdict[ds] or "Lum" in devdict[ds]: - if (t=="Temperatur"): - ltemp=fl - fl=fl-1 - if (t=="Luftfeuchte"): - ltemp=float(ll[tempindex].replace(",",".")) - fl=fl-rdiff(fl,ltemp,ltemp-1) - data[p][j]=data[p][j]+",%0.2f" % (fl) - j=j+1 - i=i+1 - f.close() - - -#print data - -for i in range(len(sel_list)): - f=open("/var/www/html/"+sel_list[i]+".csv","w") - for l in data[i]: - f.write(l+"\n") - f.close() - - - +import sys +import os +import os.path +import subprocess +import io +import time +import math +import shutil +import datetime + + +#Parameter: +#a = 7.5, b = 237.3 fuer T >= 0 +#a = 7.6, b = 240.7 fuer T < 0 ueber Wasser (Taupunkt) +#a = 9.5, b = 265.5 fuer T < 0 ueber Eis (Frostpunkt) +a=7.5 +b=237.3 +Rs = 8314.3 #J/(kmol*K) (universelle Gaskonstante) +mw = 18.016 #kg/kmol (Molekulargewicht des Wasserdampfes) + +def SDD(T): + return 6.1078 * 10**((a*T)/(b+T)) + +def AF1(r,T): + return r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000 + +def RF1(a,T): + return a*100/(SDD(T)/(T+273.15)*mw/Rs*10000) +#print(0.5*SDD(20)/(20+273.15)*mw/Rs*10000) + +def rdiff(r1,t1,t2): + return (r1)-RF1(AF1(r1,t1),t2) + + +def calcDerivation(Name,Valuetype,Value,T): + return [0.5,0.5] + + +devdict={} +devwholist=[] +f=open("DEVLIST.txt","r") +for l in f.readlines(): + ls=l.split(" ") + if (len(ls)>1): + devdict[ls[0]]=l.replace("\n","").split(",")[0].split(" ")[1] + devwholist.append(ls[0]) +f.close() + +sel_list=["Temperatur","Luftfeuchte","Beleuchtungsstaerke","R0","VOC","RS","Corr"] +data=[] +for s in sel_list: + data.append(["Time"]) + +for ds in devwholist: #fuer Jedes Geraet in DEVLIST.txt + fname="log_%s.ow1" %(ds) #Sind Daten da? + if os.path.exists(fname): + f=open(fname,"r") #Lesen + lines=f.readlines() + ti=lines[0][:-1].split("\t") #Ueberschriften aufteilen + i=0 + if ("Temperatur" in ti): + tempindex=ti.index("Temperatur") + for t in ti: #fuer jedes Element in der Ueberschrift + if t in sel_list: #schauen ob es Uebernommen werden soll + p=sel_list.index(t) #schaue nach Nummer in der Datenbank + data[p][0]=data[p][0]+","+ds+" "+devdict[ds] #hinzufuegen der Ueberschrift in der Tabelle + if len(data[p])==1: #erstes Element, Time einfuegen und neue zeile anlegen + for l in lines[1:]: + l=l[:-1] + ll=l.split("\t") + la=ll[0].split(" ") + lb=la[0].split(".") + ts=lb[2]+"/"+lb[1]+"/"+lb[0]+" "+la[1] + data[p].append(ts) + j=1; + for l in lines[1:]: + #print(ll) + l=l[:-1] #\n wegmachen + ll=l.split("\t") #telen + fl=float(ll[i].replace(",",".")) + if "VOC" in devdict[ds] or "Lum" in devdict[ds]: + if (t=="Temperatur"): + ltemp=fl + fl=fl-1 + if (t=="Luftfeuchte"): + ltemp=float(ll[tempindex].replace(",",".")) + fl=fl-rdiff(fl,ltemp,ltemp-1) + data[p][j]=data[p][j]+",%0.2f" % (fl) + j=j+1 + i=i+1 + f.close() + + +#print data + +for i in range(len(sel_list)): + f=open("/var/www/html/"+sel_list[i]+".csv","w") + for l in data[i]: + f.write(l+"\n") + f.close() + + + diff --git a/tools_cmd/owtools.sdf b/tools_cmd/owtools.sdf index 16df8ea5f90ae1e077dc6a575a780bb1e358f1f4..367c2e9b537d9edf5fbff5ad65964d7b1e48c8d9 100644 GIT binary patch delta 1889 zcmXBN2bj+V9LMqB|8V>xcgKm4JG1PwN6L|v8Oh2xJK3UC;?DSV_PC0&M@K}bv$7S+ zehX#q5h|s<`=sylyq?eZc|PCg`6ef4L?v6eYQ-tP2A-TV!^J~&)|NjOsxVjl3kGdsXUCLjn19E2)rW_! zN8XF|kz=D39ZHXmhz{=vABt_9H8I$g8IJ!YDm@`0K0GgeVB?4&J}8wIPS_eMmbo{f zc9fDL(vz|z#hh7|+CCIS2RZM34T6%HF^PAgL>7@%WD}7hyT~EJ;y#g6#)@%byqF*) zUKgoiqL?Hmiz#BNm?ox+8DgfGCDOzj;!W|Em@Vdrx5YbRu9zq0iv?n#SR@vUC1R;q zCf*h4V!2o$-V-auD)GKpE!Kz+M21)^J`|Z^omek6h>c>C_(*IPTf|neO>7rC#7?nG zd@Mc@yTu-{S9~fy6Z^z|aX=gths0rVL?Die&&4ruT$~VJh%d!SaY~#PXT(`?PMjAP z#6@vQTozZvRdG#R7dOOL;-x~7k9-E;z#k5_*wiSeigro-^Cx| zPw|)dTl_PL&@@68VOcDzWwS`jZaFM$_gPNMW%pZdi?V2ou{@U7VlAINVEL_pJ!l23 zkQKIvtcb-~ycM-#R@_QhNh@U!+ap%m%2-(|XXUMeRkQ@FWR4vdebGuG%%bZa3^JyJ@#VYq%Xs_!rP$u+RVi delta 1960 zcmXBM36#xs7{>Acz3$AIQD!DG)(~Znv6dxcYhxHqmP#2SlrkcF+$J7Nve!k)J}t_w z3E8)7`Pxf6656zA-yZdz-{(Bu4xF=X?;9 z?iK_!lp8lA_4JZan`h2C9E$hBu!UkBhsBjD*qs~K zI61#gxI%J+aN_0cNLJ7@&213G7G8=BC>Xu9Q(m%i!udIca*|HApIkfBC)cDEB;_XT zC|WiW1ktL|pl}en@+0b(F(Djm4JQSWAa-GNLUt&KH5-$#LlhDb5hvnBf+#E!MUp5Y zt`b*^q9R$Oh*WWnC?<-FYefl>CQ6D@qO>R@%8GL0I#FI!5EaGsqLQdAZV)$$Dx#{W zCaQ}XqNb=NZW6Uc9g!~Tih82HXdoJjM&f31i)bvGh^C^MxK%V48KQ+~DO!ovqK&vs z+%E1AcZ$12ThUHriuR&|$PyjJ-6C7uBRYxBqKoJ%?iKfm`$aeLfOt@J7dfJb=qVl& zy+m*Eu;?TDihkk|@u=u89utp?0U}on6iDvuVu@HP^2ICSRq>j5T`UuCh&RP@u|ljAtHf%tMywU<#9N|3ye-y?4Pv8s zM{E+C#TKzuY!lnX4zW}061&A7@vhh__KE%CfH)}L6Nd!ius9-)ieuuqI3Z4o_r(X| zl=x75Bt90Oh)>05;&X9YoDpZm7vh}wQk)kT#6|Iy_*#4;z7^kzOX7R+gZNSWBrc1e z#V_Jl@tgQv{2~4ne~G`vKa&VeA!K1IWD$$AcuTOtmS{;<#ICZdt*9kiily2$R?Ldq zwN}E?tfZB)(pJXGS~@lqtgrR6N9rrI={ZZmAA z&9dk11&i5in`3kBMSIES*~>QH7T7{tWQ%QyEwy}m#a^}7>~&jaZ`hl*+*a61TV<bX%lRr)=U>;d!1@3H diff --git a/tools_cmd/owtools.sln b/tools_cmd/owtools.sln index 50196c8..a00b8e7 100644 --- a/tools_cmd/owtools.sln +++ b/tools_cmd/owtools.sln @@ -1,22 +1,22 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30501.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rwOW", "rwOW\rwOW.vcxproj", "{5D2435E4-D963-4533-AC3B-C4E0F2C251DB}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Debug|Win32.ActiveCfg = Debug|Win32 - {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Debug|Win32.Build.0 = Debug|Win32 - {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Release|Win32.ActiveCfg = Release|Win32 - {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30501.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rwOW", "rwOW\rwOW.vcxproj", "{5D2435E4-D963-4533-AC3B-C4E0F2C251DB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Debug|Win32.ActiveCfg = Debug|Win32 + {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Debug|Win32.Build.0 = Debug|Win32 + {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Release|Win32.ActiveCfg = Release|Win32 + {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/tools_cmd/rwOW/crcutil.c b/tools_cmd/rwOW/crcutil.c index 7ae13cb..cf1bef8 100644 --- a/tools_cmd/rwOW/crcutil.c +++ b/tools_cmd/rwOW/crcutil.c @@ -1,119 +1,119 @@ -//--------------------------------------------------------------------------- -// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES -// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// Except as contained in this notice, the name of Dallas Semiconductor -// shall not be used except as stated in the Dallas Semiconductor -// Branding Policy. -//-------------------------------------------------------------------------- -// -// crcutil.c - Keeps track of the CRC for 16 and 8 bit operations -// version 2.00 - -// Include files -#include "ownet.h" - -// Local global variables -ushort utilcrc16[MAX_PORTNUM]; -uchar utilcrc8[MAX_PORTNUM]; -static short oddparity[16] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 }; -static uchar dscrc_table[] = { - 0, 94,188,226, 97, 63,221,131,194,156,126, 32,163,253, 31, 65, - 157,195, 33,127,252,162, 64, 30, 95, 1,227,189, 62, 96,130,220, - 35,125,159,193, 66, 28,254,160,225,191, 93, 3,128,222, 60, 98, - 190,224, 2, 92,223,129, 99, 61,124, 34,192,158, 29, 67,161,255, - 70, 24,250,164, 39,121,155,197,132,218, 56,102,229,187, 89, 7, - 219,133,103, 57,186,228, 6, 88, 25, 71,165,251,120, 38,196,154, - 101, 59,217,135, 4, 90,184,230,167,249, 27, 69,198,152,122, 36, - 248,166, 68, 26,153,199, 37,123, 58,100,134,216, 91, 5,231,185, - 140,210, 48,110,237,179, 81, 15, 78, 16,242,172, 47,113,147,205, - 17, 79,173,243,112, 46,204,146,211,141,111, 49,178,236, 14, 80, - 175,241, 19, 77,206,144,114, 44,109, 51,209,143, 12, 82,176,238, - 50,108,142,208, 83, 13,239,177,240,174, 76, 18,145,207, 45,115, - 202,148,118, 40,171,245, 23, 73, 8, 86,180,234,105, 55,213,139, - 87, 9,235,181, 54,104,138,212,149,203, 41,119,244,170, 72, 22, - 233,183, 85, 11,136,214, 52,106, 43,117,151,201, 74, 20,246,168, - 116, 42,200,150, 21, 75,169,247,182,232, 10, 84,215,137,107, 53}; - -//-------------------------------------------------------------------------- -// Reset crc16 to the value passed in -// -// 'reset' - data to set crc16 to. -// -void setcrc16(int portnum, ushort reset) -{ - utilcrc16[portnum&0x0FF] = reset; - return; -} - -//-------------------------------------------------------------------------- -// Reset crc8 to the value passed in -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// 'reset' - data to set crc8 to -// -void setcrc8(int portnum, uchar reset) -{ - utilcrc8[portnum&0x0FF] = reset; - return; -} - -//-------------------------------------------------------------------------- -// Calculate a new CRC16 from the input data short. Return the current -// CRC16 and also update the global variable CRC16. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// 'data' - data to perform a CRC16 on -// -// Returns: the current CRC16 -// -ushort docrc16(int portnum, ushort cdata) -{ - cdata = (cdata ^ (utilcrc16[portnum&0x0FF] & 0xff)) & 0xff; - utilcrc16[portnum&0x0FF] >>= 8; - - if (oddparity[cdata & 0xf] ^ oddparity[cdata >> 4]) - utilcrc16[portnum&0x0FF] ^= 0xc001; - - cdata <<= 6; - utilcrc16[portnum&0x0FF] ^= cdata; - cdata <<= 1; - utilcrc16[portnum&0x0FF] ^= cdata; - - return utilcrc16[portnum&0x0FF]; -} - -//-------------------------------------------------------------------------- -// Update the Dallas Semiconductor One Wire CRC (utilcrc8) from the global -// variable utilcrc8 and the argument. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// 'x' - data byte to calculate the 8 bit crc from -// -// Returns: the updated utilcrc8. -// -uchar docrc8(int portnum, uchar x) -{ - utilcrc8[portnum&0x0FF] = dscrc_table[utilcrc8[portnum&0x0FF] ^ x]; - return utilcrc8[portnum&0x0FF]; -} +//--------------------------------------------------------------------------- +// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name of Dallas Semiconductor +// shall not be used except as stated in the Dallas Semiconductor +// Branding Policy. +//-------------------------------------------------------------------------- +// +// crcutil.c - Keeps track of the CRC for 16 and 8 bit operations +// version 2.00 + +// Include files +#include "ownet.h" + +// Local global variables +ushort utilcrc16[MAX_PORTNUM]; +uchar utilcrc8[MAX_PORTNUM]; +static short oddparity[16] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 }; +static uchar dscrc_table[] = { + 0, 94,188,226, 97, 63,221,131,194,156,126, 32,163,253, 31, 65, + 157,195, 33,127,252,162, 64, 30, 95, 1,227,189, 62, 96,130,220, + 35,125,159,193, 66, 28,254,160,225,191, 93, 3,128,222, 60, 98, + 190,224, 2, 92,223,129, 99, 61,124, 34,192,158, 29, 67,161,255, + 70, 24,250,164, 39,121,155,197,132,218, 56,102,229,187, 89, 7, + 219,133,103, 57,186,228, 6, 88, 25, 71,165,251,120, 38,196,154, + 101, 59,217,135, 4, 90,184,230,167,249, 27, 69,198,152,122, 36, + 248,166, 68, 26,153,199, 37,123, 58,100,134,216, 91, 5,231,185, + 140,210, 48,110,237,179, 81, 15, 78, 16,242,172, 47,113,147,205, + 17, 79,173,243,112, 46,204,146,211,141,111, 49,178,236, 14, 80, + 175,241, 19, 77,206,144,114, 44,109, 51,209,143, 12, 82,176,238, + 50,108,142,208, 83, 13,239,177,240,174, 76, 18,145,207, 45,115, + 202,148,118, 40,171,245, 23, 73, 8, 86,180,234,105, 55,213,139, + 87, 9,235,181, 54,104,138,212,149,203, 41,119,244,170, 72, 22, + 233,183, 85, 11,136,214, 52,106, 43,117,151,201, 74, 20,246,168, + 116, 42,200,150, 21, 75,169,247,182,232, 10, 84,215,137,107, 53}; + +//-------------------------------------------------------------------------- +// Reset crc16 to the value passed in +// +// 'reset' - data to set crc16 to. +// +void setcrc16(int portnum, ushort reset) +{ + utilcrc16[portnum&0x0FF] = reset; + return; +} + +//-------------------------------------------------------------------------- +// Reset crc8 to the value passed in +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// 'reset' - data to set crc8 to +// +void setcrc8(int portnum, uchar reset) +{ + utilcrc8[portnum&0x0FF] = reset; + return; +} + +//-------------------------------------------------------------------------- +// Calculate a new CRC16 from the input data short. Return the current +// CRC16 and also update the global variable CRC16. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// 'data' - data to perform a CRC16 on +// +// Returns: the current CRC16 +// +ushort docrc16(int portnum, ushort cdata) +{ + cdata = (cdata ^ (utilcrc16[portnum&0x0FF] & 0xff)) & 0xff; + utilcrc16[portnum&0x0FF] >>= 8; + + if (oddparity[cdata & 0xf] ^ oddparity[cdata >> 4]) + utilcrc16[portnum&0x0FF] ^= 0xc001; + + cdata <<= 6; + utilcrc16[portnum&0x0FF] ^= cdata; + cdata <<= 1; + utilcrc16[portnum&0x0FF] ^= cdata; + + return utilcrc16[portnum&0x0FF]; +} + +//-------------------------------------------------------------------------- +// Update the Dallas Semiconductor One Wire CRC (utilcrc8) from the global +// variable utilcrc8 and the argument. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// 'x' - data byte to calculate the 8 bit crc from +// +// Returns: the updated utilcrc8. +// +uchar docrc8(int portnum, uchar x) +{ + utilcrc8[portnum&0x0FF] = dscrc_table[utilcrc8[portnum&0x0FF] ^ x]; + return utilcrc8[portnum&0x0FF]; +} diff --git a/tools_cmd/rwOW/ibtmexcw.h b/tools_cmd/rwOW/ibtmexcw.h index 6c1bfbe..8729c7c 100644 --- a/tools_cmd/rwOW/ibtmexcw.h +++ b/tools_cmd/rwOW/ibtmexcw.h @@ -1,234 +1,234 @@ -/*--------------------------------------------------------------------------- -* Copyright © 1992-2008 Maxim Integrated Products, All Rights Reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL MAXIM INTEGRATED PRODUCTS BE LIABLE FOR ANY CLAIM, DAMAGES -* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -* OTHER DEALINGS IN THE SOFTWARE. -* -* Except as contained in this notice, the name of Maxim Integrated Products -* shall not be used except as stated in the Maxim Integrated Products -* Branding Policy. -*--------------------------------------------------------------------------- -* Version 4.01 -*/ - -/* includes */ -#include -#include -#include -#include -#ifndef _WIN32_WCE -#include -#include -#include -#include -#include -#include -#endif - -/* type defs */ -typedef unsigned char uchar; -typedef unsigned short ushort; -typedef unsigned long ulong; - -/* typedef structure sent back by TMEX routines */ -typedef struct -{ -uchar name[4]; -uchar extension; -uchar startpage; -uchar numpages; -uchar attrib; -uchar bitmap[32]; -} FileEntry; - -/* structure to hold directory path */ -typedef struct -{ -uchar NumEntries; /* number of entries in path 0-10 */ -char Ref; /* reference character '\' or '.' */ -char Entries[10][4]; /* sub-directory entry names */ -} DirectoryPath; - -/* Holds info of each object in the Directory list */ -struct DirNumInfo -{ -unsigned char Name[4]; -unsigned char Extension; -char Attrib; -}; - -/* structure to hold exportable device parameters by family code (3.11) */ -typedef struct -{ -short features[32]; -char dscrptn[255]; -} Specification; - - -/* Error codes from TMEX functions */ -#define NO_DEVICE -1 -#define WRONG_TYPE -2 -#define FILE_READ_ERR -3 -#define BUFFER_TOO_SMALL -4 -#define HANDLE_NOT_AVAIL -5 -#define FILE_NOT_FOUND -6 -#define REPEAT_FILE -7 -#define HANDLE_NOT_USED -8 -#define FILE_WRITE_ONLY -9 -#define OUT_OF_SPACE -10 -#define FILE_WRITE_ERR -11 -#define TMFILE_READ_ONLY -12 -#define FUNC_NOT_SUP -13 -#define BAD_FILENAME -14 -#define CANT_DEL_READ_ONLY -15 -#define HANDLE_NOT_EXIST -16 -#define ONE_WIRE_PORT_ERROR -17 -#define INVALID_DIRECTORY -18 -#define DIRECTORY_NOT_EMPTY -19 -#define UNABLE_TO_CREATE_DIR -20 -#define NO_PROGRAM_JOB -21 -#define PROGRAM_WRITE_PROTECT -22 -#define NON_PROGRAM_PARTS -23 -#define ADDFILE_TERMINATED -24 -#define TIMEOUT -25 -#define INVALID_ARGUMENT -26 -#define BAD_ACK -27 -#define INVALID_SESSION -200 -#define NO_BASDRV_FOUND -201 - -/* Basic physical level error codes */ -#define BPORT_NOT_INITIALIZED -1 -#define BPORT_NOT_EXIST -2 -#define BNO_SUCH_FUNCTION -3 - -/* Transport level error codes */ -#define TERROR_READ_WRITE -4 -#define TBUFFER_TOO_SMALL -5 -#define TDEVICE_TOO_SMALL -6 -#define TNO_DEVICE -7 -#define TBLOCK_TOO_BIG -8 -#define TWRONG_TYPE -9 -#define TPAGE_REDIRECTED -10 -#define TPROGRAM_NOT_POSSIBLE -11 -#define BCOM_FAILURE -12 -#define BCOM_EVENT -13 - -/* for TMOneWireLevel */ -#define LEVEL_NORMAL 0 -#define LEVEL_STRONG_PULLUP 1 -#define LEVEL_BREAK 2 -#define LEVEL_PROGRAM 3 -#define PRIMED_NONE 0 -#define PRIMED_BIT 1 -#define PRIMED_BYTE 2 -#define LEVEL_READ 1 -#define LEVEL_SET 0 - -/* misc */ -#define GENERAL_FAIL -2 -#define BAD_ARGUMENT 50 -#define NO_DRIVERS 51 -#define KEY_ABORT 52 -#define OUT_MEMORY 53 -#define NORMAL_EXIT 0 - -#define TRUE 1 -#define FALSE 0 -#define DIR_READ 1 -#define DIR_SET 0 -#define DIR_REMOVE 1 -#define DIR_MAKE 0 - -/* for specification */ -#define NOMEM 0 -#define NVRAM 1 -#define EPROM1 2 -#define EPROM2 3 -#define EPROM3 4 -#define EEPROM1 5 -#define MNVRAM 6 -#define EEPROM2 7 -#define NVRAM2 8 -#define NVRAM3 9 -#define FTR_REG_PAGES 0 -#define FTR_REG_LEN 1 -#define FTR_STAT_PAGES 2 -#define FTR_STAT_LEN 3 -#define FTR_MAX_COM 4 -#define FTR_MEM_TYPE 5 - -// session -extern long __fastcall TMExtendedStartSession(short, short, void far *); -extern short __fastcall TMValidSession(long); -extern short __fastcall TMEndSession(long); -extern short __fastcall Get_Version(char far *); -// file_operations -extern short __fastcall TMFirstFile(long, void far *, FileEntry far *); -extern short __fastcall TMNextFile(long, void far *, FileEntry far *); -extern short __fastcall TMOpenFile(long, void far *, FileEntry far *); -extern short __fastcall TMCreateFile(long, void far *, short far *, FileEntry far *); -extern short __fastcall TMCloseFile(long, void far *, short); -extern short __fastcall TMReadFile(long, void far *, short, uchar far *, short); -extern short __fastcall TMWriteFile(long, void far *, short, uchar far *, short); -extern short __fastcall TMDeleteFile(long, void far *, FileEntry far *); -extern short __fastcall TMFormat(long, void far *); -extern short __fastcall TMAttribute(long, void far *, short, FileEntry far *); -extern short __fastcall TMReNameFile(long, void far *, short, FileEntry far *); -extern short __fastcall TMChangeDirectory(long, void far *, short, DirectoryPath far *); -extern short __fastcall TMDirectoryMR(long, void far *, short, FileEntry far *); -extern short __fastcall TMCreateProgramJob(long, void far *); -extern short __fastcall TMDoProgramJob(long, void far *); -extern short __fastcall TMWriteAddFile(long, void far *, short, short, short, uchar far *, short); -extern short __fastcall TMTerminateAddFile(long, void far *, FileEntry far *); -extern short __fastcall TMGetFamilySpec(long, void far *, Specification *); -// transport -extern short __fastcall TMReadPacket(long, void far *, short, uchar far *, short); -extern short __fastcall TMWritePacket(long, void far *, short, uchar far *, short); -extern short __fastcall TMBlockIO(long, uchar far *, short); -extern short __fastcall TMExtendedReadPage(long, void far *, short, uchar far *, short); -extern short __fastcall TMProgramByte(long, void far *, short, short, short, short far *, short); -extern short __fastcall TMProgramBlock(long, void far *, uchar far *, short, short, short far *); /* (3.11) */ -extern long __fastcall TMCRC(short, uchar far *, ushort, short); -// network -extern short __fastcall TMSkipFamily(long, void far *); -extern short __fastcall TMFamilySearchSetup(long, void far *, short); -extern short __fastcall TMFirst(long, void far *); -extern short __fastcall TMNext(long, void far *); -extern short __fastcall TMAccess(long, void far *); -extern short __fastcall TMOverAccess(long, void far *); -extern short __fastcall TMStrongAccess(long, void far *); -extern short __fastcall TMStrongAlarmAccess(long, void far *); -extern short __fastcall TMRom(long, void far *, short far *); -extern short __fastcall TMFirstAlarm(long, void far *); -extern short __fastcall TMNextAlarm(long, void far *); -extern short __fastcall TMAutoOverDrive(long, void far *, short); -extern short __fastcall TMSearch(short, short, short, short); -// hardware_specific -extern short __fastcall TMSetup(long); -extern short __fastcall TMTouchByte(long, short); -extern short __fastcall TMTouchReset(long); -extern short __fastcall TMTouchBit(long, short); -extern short __fastcall TMClose(long); -extern short __fastcall TMProgramPulse(long); -extern short __fastcall TMOneWireCom(long, short, short); -extern short __fastcall TMOneWireLevel(long, short, short, short); -extern short __fastcall TMGetTypeVersion(short,char far *); -extern short __fastcall TMBlockStream(long, uchar far *, short); -extern short __fastcall TMGetAdapterSpec(long, Specification far *); -extern short __fastcall TMReadDefaultPort(short far *, short far *); - +/*--------------------------------------------------------------------------- +* Copyright © 1992-2008 Maxim Integrated Products, All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED PRODUCTS BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated Products +* shall not be used except as stated in the Maxim Integrated Products +* Branding Policy. +*--------------------------------------------------------------------------- +* Version 4.01 +*/ + +/* includes */ +#include +#include +#include +#include +#ifndef _WIN32_WCE +#include +#include +#include +#include +#include +#include +#endif + +/* type defs */ +typedef unsigned char uchar; +typedef unsigned short ushort; +typedef unsigned long ulong; + +/* typedef structure sent back by TMEX routines */ +typedef struct +{ +uchar name[4]; +uchar extension; +uchar startpage; +uchar numpages; +uchar attrib; +uchar bitmap[32]; +} FileEntry; + +/* structure to hold directory path */ +typedef struct +{ +uchar NumEntries; /* number of entries in path 0-10 */ +char Ref; /* reference character '\' or '.' */ +char Entries[10][4]; /* sub-directory entry names */ +} DirectoryPath; + +/* Holds info of each object in the Directory list */ +struct DirNumInfo +{ +unsigned char Name[4]; +unsigned char Extension; +char Attrib; +}; + +/* structure to hold exportable device parameters by family code (3.11) */ +typedef struct +{ +short features[32]; +char dscrptn[255]; +} Specification; + + +/* Error codes from TMEX functions */ +#define NO_DEVICE -1 +#define WRONG_TYPE -2 +#define FILE_READ_ERR -3 +#define BUFFER_TOO_SMALL -4 +#define HANDLE_NOT_AVAIL -5 +#define FILE_NOT_FOUND -6 +#define REPEAT_FILE -7 +#define HANDLE_NOT_USED -8 +#define FILE_WRITE_ONLY -9 +#define OUT_OF_SPACE -10 +#define FILE_WRITE_ERR -11 +#define TMFILE_READ_ONLY -12 +#define FUNC_NOT_SUP -13 +#define BAD_FILENAME -14 +#define CANT_DEL_READ_ONLY -15 +#define HANDLE_NOT_EXIST -16 +#define ONE_WIRE_PORT_ERROR -17 +#define INVALID_DIRECTORY -18 +#define DIRECTORY_NOT_EMPTY -19 +#define UNABLE_TO_CREATE_DIR -20 +#define NO_PROGRAM_JOB -21 +#define PROGRAM_WRITE_PROTECT -22 +#define NON_PROGRAM_PARTS -23 +#define ADDFILE_TERMINATED -24 +#define TIMEOUT -25 +#define INVALID_ARGUMENT -26 +#define BAD_ACK -27 +#define INVALID_SESSION -200 +#define NO_BASDRV_FOUND -201 + +/* Basic physical level error codes */ +#define BPORT_NOT_INITIALIZED -1 +#define BPORT_NOT_EXIST -2 +#define BNO_SUCH_FUNCTION -3 + +/* Transport level error codes */ +#define TERROR_READ_WRITE -4 +#define TBUFFER_TOO_SMALL -5 +#define TDEVICE_TOO_SMALL -6 +#define TNO_DEVICE -7 +#define TBLOCK_TOO_BIG -8 +#define TWRONG_TYPE -9 +#define TPAGE_REDIRECTED -10 +#define TPROGRAM_NOT_POSSIBLE -11 +#define BCOM_FAILURE -12 +#define BCOM_EVENT -13 + +/* for TMOneWireLevel */ +#define LEVEL_NORMAL 0 +#define LEVEL_STRONG_PULLUP 1 +#define LEVEL_BREAK 2 +#define LEVEL_PROGRAM 3 +#define PRIMED_NONE 0 +#define PRIMED_BIT 1 +#define PRIMED_BYTE 2 +#define LEVEL_READ 1 +#define LEVEL_SET 0 + +/* misc */ +#define GENERAL_FAIL -2 +#define BAD_ARGUMENT 50 +#define NO_DRIVERS 51 +#define KEY_ABORT 52 +#define OUT_MEMORY 53 +#define NORMAL_EXIT 0 + +#define TRUE 1 +#define FALSE 0 +#define DIR_READ 1 +#define DIR_SET 0 +#define DIR_REMOVE 1 +#define DIR_MAKE 0 + +/* for specification */ +#define NOMEM 0 +#define NVRAM 1 +#define EPROM1 2 +#define EPROM2 3 +#define EPROM3 4 +#define EEPROM1 5 +#define MNVRAM 6 +#define EEPROM2 7 +#define NVRAM2 8 +#define NVRAM3 9 +#define FTR_REG_PAGES 0 +#define FTR_REG_LEN 1 +#define FTR_STAT_PAGES 2 +#define FTR_STAT_LEN 3 +#define FTR_MAX_COM 4 +#define FTR_MEM_TYPE 5 + +// session +extern long __fastcall TMExtendedStartSession(short, short, void far *); +extern short __fastcall TMValidSession(long); +extern short __fastcall TMEndSession(long); +extern short __fastcall Get_Version(char far *); +// file_operations +extern short __fastcall TMFirstFile(long, void far *, FileEntry far *); +extern short __fastcall TMNextFile(long, void far *, FileEntry far *); +extern short __fastcall TMOpenFile(long, void far *, FileEntry far *); +extern short __fastcall TMCreateFile(long, void far *, short far *, FileEntry far *); +extern short __fastcall TMCloseFile(long, void far *, short); +extern short __fastcall TMReadFile(long, void far *, short, uchar far *, short); +extern short __fastcall TMWriteFile(long, void far *, short, uchar far *, short); +extern short __fastcall TMDeleteFile(long, void far *, FileEntry far *); +extern short __fastcall TMFormat(long, void far *); +extern short __fastcall TMAttribute(long, void far *, short, FileEntry far *); +extern short __fastcall TMReNameFile(long, void far *, short, FileEntry far *); +extern short __fastcall TMChangeDirectory(long, void far *, short, DirectoryPath far *); +extern short __fastcall TMDirectoryMR(long, void far *, short, FileEntry far *); +extern short __fastcall TMCreateProgramJob(long, void far *); +extern short __fastcall TMDoProgramJob(long, void far *); +extern short __fastcall TMWriteAddFile(long, void far *, short, short, short, uchar far *, short); +extern short __fastcall TMTerminateAddFile(long, void far *, FileEntry far *); +extern short __fastcall TMGetFamilySpec(long, void far *, Specification *); +// transport +extern short __fastcall TMReadPacket(long, void far *, short, uchar far *, short); +extern short __fastcall TMWritePacket(long, void far *, short, uchar far *, short); +extern short __fastcall TMBlockIO(long, uchar far *, short); +extern short __fastcall TMExtendedReadPage(long, void far *, short, uchar far *, short); +extern short __fastcall TMProgramByte(long, void far *, short, short, short, short far *, short); +extern short __fastcall TMProgramBlock(long, void far *, uchar far *, short, short, short far *); /* (3.11) */ +extern long __fastcall TMCRC(short, uchar far *, ushort, short); +// network +extern short __fastcall TMSkipFamily(long, void far *); +extern short __fastcall TMFamilySearchSetup(long, void far *, short); +extern short __fastcall TMFirst(long, void far *); +extern short __fastcall TMNext(long, void far *); +extern short __fastcall TMAccess(long, void far *); +extern short __fastcall TMOverAccess(long, void far *); +extern short __fastcall TMStrongAccess(long, void far *); +extern short __fastcall TMStrongAlarmAccess(long, void far *); +extern short __fastcall TMRom(long, void far *, short far *); +extern short __fastcall TMFirstAlarm(long, void far *); +extern short __fastcall TMNextAlarm(long, void far *); +extern short __fastcall TMAutoOverDrive(long, void far *, short); +extern short __fastcall TMSearch(short, short, short, short); +// hardware_specific +extern short __fastcall TMSetup(long); +extern short __fastcall TMTouchByte(long, short); +extern short __fastcall TMTouchReset(long); +extern short __fastcall TMTouchBit(long, short); +extern short __fastcall TMClose(long); +extern short __fastcall TMProgramPulse(long); +extern short __fastcall TMOneWireCom(long, short, short); +extern short __fastcall TMOneWireLevel(long, short, short, short); +extern short __fastcall TMGetTypeVersion(short,char far *); +extern short __fastcall TMBlockStream(long, uchar far *, short); +extern short __fastcall TMGetAdapterSpec(long, Specification far *); +extern short __fastcall TMReadDefaultPort(short far *, short far *); + diff --git a/tools_cmd/rwOW/main.cpp b/tools_cmd/rwOW/main.cpp index 184ffd7..fa6df19 100644 --- a/tools_cmd/rwOW/main.cpp +++ b/tools_cmd/rwOW/main.cpp @@ -1,391 +1,391 @@ -#define _CRT_SECURE_NO_WARNINGS 1 -extern "C" { -#include "ownet.h" -} -#include -#include -#include - -FILE *fio; -char s[100], fname[254]; - - -SMALLINT ReadDS2430(int portnum, uchar SerialNum[8]) { - uchar rt = FALSE; - uchar send_block[145]; - uchar send_cnt = 0, i; - int address; - char s[100]; - FILE *f; - sprintf(s, "%02X%02X%02X%02X%02X%02X%02X%02X.bin", SerialNum[7], SerialNum[6], SerialNum[5], SerialNum[4], SerialNum[3], SerialNum[2], SerialNum[1], SerialNum[0]); - fprintf(fio, ">14\n"); - send_cnt = 0; - printf("Read Data MEM \n"); - if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } - send_block[send_cnt++] = 0xF0; - send_block[send_cnt++] = 0x00; - for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF; - if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } - for (i = 2; i TEST DS2433 \n"); - fprintf(fio, ">23\n"); - - send_cnt = 0; - printf("\nRead MEM ALL \n"); - if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } - send_block[send_cnt++] = 0xF0; - send_block[send_cnt++] = 0x00; - send_block[send_cnt++] = 0x00; - for (j = 0; j<16; j++) { - for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF; - if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } - for (i = j?0:3; i < send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); } - send_cnt = 0; - printf("\n"); - fprintf(fio, "\n"); - } - -} - - -int findDev(uchar code) { - int find = 0; - fio = fopen(fname, "r"); - while (!feof(fio)) { - s[0] = fgetc(fio); - if (s[0] == '>') { - s[0] = fgetc(fio); - s[1] = fgetc(fio); - s[2] = 0; - uchar w = strtol(s, NULL, 16); - if (code ==w) return 1; - } - } - fclose(fio); - return 0; -} - - - -SMALLINT WriteDS2433(int portnum, uchar SerialNum[8]) { - uchar rt = FALSE; - uchar send_block[145]; - uchar send_cnt = 0, i, j; - int address; - send_cnt = 0; - printf("-----> TEST DS2433 \n"); - if (findDev(0x23)) { - for (j = 0; j < 16; j++) { - for (i = 0; i < 32; i++) { - fscanf(fio, "%02X", &send_block[i + 3]); - } - if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } - send_block[0] = 0x0F; - send_block[1] = j << 5; - send_block[2] = j >> 3; - if (!owBlock(portnum, FALSE, send_block, 32 + 3)) { printf("ERROR RUN COMMAND \n"); return 1; } - if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } - send_cnt = 0; - send_block[send_cnt++] = 0xAA; - for (i = 0; i < 32 + 3; i++) send_block[send_cnt++] = 0xFF; - if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } - for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); } - if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } - send_cnt = 0; - send_block[send_cnt++] = 0x55; - send_cnt += 3; - if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } - msDelay(100); - printf("\n"); - } - - } - fclose(fio); - return 0; - - -} - - -SMALLINT WriteDS2430(int portnum, uchar SerialNum[8]) { - uchar rt = FALSE; - uchar send_block[145]; - uchar send_cnt = 0, i, j; - int address; - send_cnt = 0; - printf("-----> TEST DS2430 \n"); - if (findDev(0x14)) { - for (i = 0; i < 32; i++) { - fscanf(fio, "%02X", &send_block[i + 2]); - } - if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } - send_block[0] = 0x0F; - send_block[1] = 0; - if (!owBlock(portnum, FALSE, send_block, 32 + 2)) { printf("ERROR RUN COMMAND \n"); return 1; } - if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } - send_cnt = 0; - send_block[send_cnt++] = 0xAA; - send_block[send_cnt++] = 0x00; - for (i = 0; i < 32 + 2; i++) send_block[send_cnt++] = 0xFF; - if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } - for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); } - if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } - send_cnt = 0; - send_block[send_cnt++] = 0x55; - send_block[send_cnt++] = 0xA5; - if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } - msDelay(100); - printf("\n"); - } - fclose(fio); - -} -/* -SMALLINT WriteDS2430(int portnum, uchar SerialNum[8], const char *fname) { - uchar rt = FALSE; - uchar send_block[145]; - uchar send_cnt = 0, i; - int address; - uchar readbl[64]; - FILE *f; - f = fopen(fname, "rb"); - fread(readbl, 1, 32 + 16, f); - fclose(f); - ResetDS2430(portnum, SerialNum); - msDelay(1000); - send_cnt = 0; - if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } - send_block[send_cnt++] = 0x0F; - send_block[send_cnt++] = 0x00; - for (i = 0; i<32; i++) send_block[send_cnt++] = readbl[i + 8]; - if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } - send_cnt = 0; - if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } - send_block[send_cnt++] = 0xAA; - send_block[send_cnt++] = 0x00; - for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF; - if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } - for (i = 0; i= '0') && (s[i] <= '9')) { - b += s[i] - '0'; - } else - if ((s[i] >= 'A') && (s[i] <= 'F')) { - b += s[i] - 'A'+10; - } else - if ((s[i] >= 'a') && (s[i] <= 'f')) { - b += s[i] - 'a'+10; - } - - } - return b; -} - -void strcpys(char *s, const char* d,bool up) { - if (strlen(d) > 7990) { - strncpy(s, d, 7990); - s[200] = 0; - } - else strcpy(s, d); - if (up) { - for (int i = 0; i= 'a') && (s[i] <= 'z')) - s[i] += 'A' - 'a'; - } -} - -int main(int argc, char *argv[]) { - uchar SNum[8]; - int rslt, cnt, i; - uchar send_block[256]; - uchar send_cnt = 0; - int portnum; - char adapter[20]; - int found = 0; - int rw = 0; - int err = 0; - char s[8000]; - int adt = 0; - int mod = 0; - if (argc >= 2) { - strcpys(s, argv[1],true); - - - if (strncmp(s,"USB",3)==0) {adt = 6;} - if (strncmp(s, "COM", 3) == 0) { adt = 5; } - if (adt != 0) { - strcpy(s, argv[1] + 3); - sprintf(adapter, "{%s,%i}\0",s,adt); - printf("Open Port %s\n", argv[1]); - if ((portnum = owAcquireEx(adapter)) < 0) { - printf("ERROR \n", adt); - } - else mod = 1; - - } - if ((argc == 2) && (mod == 1)) mod = 2; - if (argc > 2) { - strcpys(s, argv[2],true); - if (strncmp(s, "DC", 2) == 0) { - if (argc > 3) { - if (strlen(argv[3])>=16) - for (int i = 0; i < 16; i += 2) { - SNum[7 - (i / 2)] = conf2(argv[3] + i); - - } - printf("Select: %02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]); - mod = 3; - } - - } - } - if ((mod == 3) && (argc>4)) { - strcpys(s, argv[4], true); - mod = 4; - } - - } - - if (mod == 2) { - rslt = owFirst(portnum, TRUE, FALSE); - cnt = 0; - while (rslt) { - cnt++; - owSerialNum(portnum, &SNum[0], TRUE); - printf("%02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]); - // fprintf(ft,"%02X%02X%02X%02X%02X%02X%02X%02X\n",SNum[7],SNum[6],SNum[5],SNum[4],SNum[3],SNum[2],SNum[1],SNum[0]); -/* switch (SNum[0]) { - - - case 0x14: { - //TestDS2430(portnum,&SNum[0]); - //scanf("%i",&i); - //ResetDS2430(portnum,&SNum[0]); - //uchar id[]={0x14,0xF5 ,0xEA ,0x24 ,0x06 ,0x00 ,0x00 ,0x5E}; - //SetIDDS2430(portnum,&SNum[0],id); - if (rw) WriteDS2430(portnum, &SNum[0]); else ReadDS2430(portnum, &SNum[0]); - //WriteDS2430(portnum,&SNum[0],"5E00000624EAF514.bin"); - break; - } - case 0x23: { - //TestDS2433(portnum,&SNum[0]); - //TestDS2433_reset(portnum,&SNum[0]); - //scanf("%i",&i); - if (rw) WriteDS2433(portnum, &SNum[0]); else ReadDS2433(portnum, &SNum[0]); - break; - } - }*/ - rslt = owNext(portnum, TRUE, FALSE); - } - } - if (mod == 4) { - owSerialNum(portnum, SNum, FALSE); - strcat(s, "_R"); - int len = strlen(s); - int i = 0; - while (i < len) { - if (s[i] == '_') { - if (s[i + 1] == 'R') { - if (owAccess(portnum)) { - if (owBlock(portnum, FALSE, send_block, send_cnt)) { - for (int j = 0; j < send_cnt; j++) { - printf("%02X", send_block[j]); - } - printf("\n"); - } - else printf("ERROR RESET\n"); - } - else printf("ERROR SEND\n"); - send_cnt = 0; - } - if (s[i + 1] == 'P') { - if (i + 2 < len) { - i += 2; - msDelay(conf2(s + i)); - - } - } - } - else { - send_block[send_cnt++] = conf2(s + i); - } - i += 2; - - - } - } - if (mod>0) owRelease(portnum); - - return 0; +#define _CRT_SECURE_NO_WARNINGS 1 +extern "C" { +#include "ownet.h" +} +#include +#include +#include + +FILE *fio; +char s[100], fname[254]; + + +SMALLINT ReadDS2430(int portnum, uchar SerialNum[8]) { + uchar rt = FALSE; + uchar send_block[145]; + uchar send_cnt = 0, i; + int address; + char s[100]; + FILE *f; + sprintf(s, "%02X%02X%02X%02X%02X%02X%02X%02X.bin", SerialNum[7], SerialNum[6], SerialNum[5], SerialNum[4], SerialNum[3], SerialNum[2], SerialNum[1], SerialNum[0]); + fprintf(fio, ">14\n"); + send_cnt = 0; + printf("Read Data MEM \n"); + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_block[send_cnt++] = 0xF0; + send_block[send_cnt++] = 0x00; + for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + for (i = 2; i TEST DS2433 \n"); + fprintf(fio, ">23\n"); + + send_cnt = 0; + printf("\nRead MEM ALL \n"); + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_block[send_cnt++] = 0xF0; + send_block[send_cnt++] = 0x00; + send_block[send_cnt++] = 0x00; + for (j = 0; j<16; j++) { + for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + for (i = j?0:3; i < send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); } + send_cnt = 0; + printf("\n"); + fprintf(fio, "\n"); + } + +} + + +int findDev(uchar code) { + int find = 0; + fio = fopen(fname, "r"); + while (!feof(fio)) { + s[0] = fgetc(fio); + if (s[0] == '>') { + s[0] = fgetc(fio); + s[1] = fgetc(fio); + s[2] = 0; + uchar w = strtol(s, NULL, 16); + if (code ==w) return 1; + } + } + fclose(fio); + return 0; +} + + + +SMALLINT WriteDS2433(int portnum, uchar SerialNum[8]) { + uchar rt = FALSE; + uchar send_block[145]; + uchar send_cnt = 0, i, j; + int address; + send_cnt = 0; + printf("-----> TEST DS2433 \n"); + if (findDev(0x23)) { + for (j = 0; j < 16; j++) { + for (i = 0; i < 32; i++) { + fscanf(fio, "%02X", &send_block[i + 3]); + } + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_block[0] = 0x0F; + send_block[1] = j << 5; + send_block[2] = j >> 3; + if (!owBlock(portnum, FALSE, send_block, 32 + 3)) { printf("ERROR RUN COMMAND \n"); return 1; } + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_cnt = 0; + send_block[send_cnt++] = 0xAA; + for (i = 0; i < 32 + 3; i++) send_block[send_cnt++] = 0xFF; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); } + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_cnt = 0; + send_block[send_cnt++] = 0x55; + send_cnt += 3; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + msDelay(100); + printf("\n"); + } + + } + fclose(fio); + return 0; + + +} + + +SMALLINT WriteDS2430(int portnum, uchar SerialNum[8]) { + uchar rt = FALSE; + uchar send_block[145]; + uchar send_cnt = 0, i, j; + int address; + send_cnt = 0; + printf("-----> TEST DS2430 \n"); + if (findDev(0x14)) { + for (i = 0; i < 32; i++) { + fscanf(fio, "%02X", &send_block[i + 2]); + } + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_block[0] = 0x0F; + send_block[1] = 0; + if (!owBlock(portnum, FALSE, send_block, 32 + 2)) { printf("ERROR RUN COMMAND \n"); return 1; } + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_cnt = 0; + send_block[send_cnt++] = 0xAA; + send_block[send_cnt++] = 0x00; + for (i = 0; i < 32 + 2; i++) send_block[send_cnt++] = 0xFF; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); } + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_cnt = 0; + send_block[send_cnt++] = 0x55; + send_block[send_cnt++] = 0xA5; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + msDelay(100); + printf("\n"); + } + fclose(fio); + +} +/* +SMALLINT WriteDS2430(int portnum, uchar SerialNum[8], const char *fname) { + uchar rt = FALSE; + uchar send_block[145]; + uchar send_cnt = 0, i; + int address; + uchar readbl[64]; + FILE *f; + f = fopen(fname, "rb"); + fread(readbl, 1, 32 + 16, f); + fclose(f); + ResetDS2430(portnum, SerialNum); + msDelay(1000); + send_cnt = 0; + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_block[send_cnt++] = 0x0F; + send_block[send_cnt++] = 0x00; + for (i = 0; i<32; i++) send_block[send_cnt++] = readbl[i + 8]; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + send_cnt = 0; + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_block[send_cnt++] = 0xAA; + send_block[send_cnt++] = 0x00; + for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + for (i = 0; i= '0') && (s[i] <= '9')) { + b += s[i] - '0'; + } else + if ((s[i] >= 'A') && (s[i] <= 'F')) { + b += s[i] - 'A'+10; + } else + if ((s[i] >= 'a') && (s[i] <= 'f')) { + b += s[i] - 'a'+10; + } + + } + return b; +} + +void strcpys(char *s, const char* d,bool up) { + if (strlen(d) > 7990) { + strncpy(s, d, 7990); + s[200] = 0; + } + else strcpy(s, d); + if (up) { + for (int i = 0; i= 'a') && (s[i] <= 'z')) + s[i] += 'A' - 'a'; + } +} + +int main(int argc, char *argv[]) { + uchar SNum[8]; + int rslt, cnt, i; + uchar send_block[256]; + uchar send_cnt = 0; + int portnum; + char adapter[20]; + int found = 0; + int rw = 0; + int err = 0; + char s[8000]; + int adt = 0; + int mod = 0; + if (argc >= 2) { + strcpys(s, argv[1],true); + + + if (strncmp(s,"USB",3)==0) {adt = 6;} + if (strncmp(s, "COM", 3) == 0) { adt = 5; } + if (adt != 0) { + strcpy(s, argv[1] + 3); + sprintf(adapter, "{%s,%i}\0",s,adt); + printf("Open Port %s\n", argv[1]); + if ((portnum = owAcquireEx(adapter)) < 0) { + printf("ERROR \n", adt); + } + else mod = 1; + + } + if ((argc == 2) && (mod == 1)) mod = 2; + if (argc > 2) { + strcpys(s, argv[2],true); + if (strncmp(s, "DC", 2) == 0) { + if (argc > 3) { + if (strlen(argv[3])>=16) + for (int i = 0; i < 16; i += 2) { + SNum[7 - (i / 2)] = conf2(argv[3] + i); + + } + printf("Select: %02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]); + mod = 3; + } + + } + } + if ((mod == 3) && (argc>4)) { + strcpys(s, argv[4], true); + mod = 4; + } + + } + + if (mod == 2) { + rslt = owFirst(portnum, TRUE, FALSE); + cnt = 0; + while (rslt) { + cnt++; + owSerialNum(portnum, &SNum[0], TRUE); + printf("%02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]); + // fprintf(ft,"%02X%02X%02X%02X%02X%02X%02X%02X\n",SNum[7],SNum[6],SNum[5],SNum[4],SNum[3],SNum[2],SNum[1],SNum[0]); +/* switch (SNum[0]) { + + + case 0x14: { + //TestDS2430(portnum,&SNum[0]); + //scanf("%i",&i); + //ResetDS2430(portnum,&SNum[0]); + //uchar id[]={0x14,0xF5 ,0xEA ,0x24 ,0x06 ,0x00 ,0x00 ,0x5E}; + //SetIDDS2430(portnum,&SNum[0],id); + if (rw) WriteDS2430(portnum, &SNum[0]); else ReadDS2430(portnum, &SNum[0]); + //WriteDS2430(portnum,&SNum[0],"5E00000624EAF514.bin"); + break; + } + case 0x23: { + //TestDS2433(portnum,&SNum[0]); + //TestDS2433_reset(portnum,&SNum[0]); + //scanf("%i",&i); + if (rw) WriteDS2433(portnum, &SNum[0]); else ReadDS2433(portnum, &SNum[0]); + break; + } + }*/ + rslt = owNext(portnum, TRUE, FALSE); + } + } + if (mod == 4) { + owSerialNum(portnum, SNum, FALSE); + strcat(s, "_R"); + int len = strlen(s); + int i = 0; + while (i < len) { + if (s[i] == '_') { + if (s[i + 1] == 'R') { + if (owAccess(portnum)) { + if (owBlock(portnum, FALSE, send_block, send_cnt)) { + for (int j = 0; j < send_cnt; j++) { + printf("%02X", send_block[j]); + } + printf("\n"); + } + else printf("ERROR RESET\n"); + } + else printf("ERROR SEND\n"); + send_cnt = 0; + } + if (s[i + 1] == 'P') { + if (i + 2 < len) { + i += 2; + msDelay(conf2(s + i)); + + } + } + } + else { + send_block[send_cnt++] = conf2(s + i); + } + i += 2; + + + } + } + if (mod>0) owRelease(portnum); + + return 0; } \ No newline at end of file diff --git a/tools_cmd/rwOW/owerr.c b/tools_cmd/rwOW/owerr.c index e26a97a..76c5176 100644 --- a/tools_cmd/rwOW/owerr.c +++ b/tools_cmd/rwOW/owerr.c @@ -1,348 +1,348 @@ -//--------------------------------------------------------------------------- -// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES -// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// Except as contained in this notice, the name of Dallas Semiconductor -// shall not be used except as stated in the Dallas Semiconductor -// Branding Policy. -//--------------------------------------------------------------------------- -// -// owerr.c - Library functions for error handling with 1-Wire library -// -// Version: 1.00 -// - -#include -#ifndef _WIN32_WCE -#include -#endif -#ifdef _WIN64 -#include -#endif -#include "ownet.h" - -#ifndef SIZE_OWERROR_STACK - #ifdef SMALL_MEMORY_TARGET - //for small memory, only hole 1 error - #define SIZE_OWERROR_STACK 1 - #else - #define SIZE_OWERROR_STACK 10 - #endif -#endif - -//--------------------------------------------------------------------------- -// Variables -//--------------------------------------------------------------------------- - -// Error Struct for holding error information. -// In DEBUG, this will also hold the line number and filename. -typedef struct -{ - int owErrorNum; -#ifdef DEBUG - int lineno; - char *filename; -#endif -} owErrorStruct; - -// Ring-buffer used for stack. -// In case of overflow, deepest error is over-written. -static owErrorStruct owErrorStack[SIZE_OWERROR_STACK]; - -// Stack pointer to top-most error. -static int owErrorPointer = 0; - - -//--------------------------------------------------------------------------- -// Functions Definitions -//--------------------------------------------------------------------------- -int owGetErrorNum(void); -void owClearError(void); -int owHasErrors(void); -#ifdef DEBUG - void owRaiseError(int,int,char*); -#else - void owRaiseError(int); -#endif -#ifndef SMALL_MEMORY_TARGET - void owPrintErrorMsg(FILE *); - void owPrintErrorMsgStd(); - char *owGetErrorMsg(int); -#endif - - -//-------------------------------------------------------------------------- -// The 'owGetErroNum' returns the error code of the top-most error on the -// error stack. NOTE: This function has the side effect of popping the -// current error off the stack. All successive calls to 'owGetErrorNum' -// will further clear the error stack. -// -// For list of error codes, see 'ownet.h' -// -// Returns: int : The error code of the top-most error on the stack -// -int owGetErrorNum(void) -{ - int i = owErrorStack[ owErrorPointer ].owErrorNum; - owErrorStack[ owErrorPointer ].owErrorNum = 0; - if(!owErrorPointer) - owErrorPointer = SIZE_OWERROR_STACK - 1; - else - owErrorPointer = (owErrorPointer - 1); - return i; -} - -//-------------------------------------------------------------------------- -// The 'owClearError' clears all the errors. -// -void owClearError(void) -{ - owErrorStack[ owErrorPointer ].owErrorNum = 0; -} - -//-------------------------------------------------------------------------- -// The 'owHasErrors' is a boolean test function which tests whether or not -// a valid error is waiting on the stack. -// -// Returns: TRUE (1) : When there are errors on the stack. -// FALSE (0): When stack's errors are set to 0, or NO_ERROR_SET. -// -int owHasErrors(void) -{ - if(owErrorStack[ owErrorPointer ].owErrorNum) - return 1; //TRUE - else - return 0; //FALSE -} - -#ifdef DEBUG - //-------------------------------------------------------------------------- - // The 'owRaiseError' is the method for raising an error onto the error - // stack. - // - // Arguments: int err - the error code you wish to raise. - // int lineno - DEBUG only - the line number where it was raised - // char* filename - DEBUG only - the file name where it occured. - // - void owRaiseError(int err, int lineno, char* filename) - { - owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK; - owErrorStack[ owErrorPointer ].owErrorNum = err; - owErrorStack[ owErrorPointer ].lineno = lineno; - owErrorStack[ owErrorPointer ].filename = filename; - } -#else - //-------------------------------------------------------------------------- - // The 'owRaiseError' is the method for raising an error onto the error - // stack. - // - // Arguments: int err - the error code you wish to raise. - // - void owRaiseError(int err) - { - owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK; - owErrorStack[ owErrorPointer ].owErrorNum = err; - } -#endif - - -// SMALL_MEMORY_TARGET - embedded microcontrollers, where these -// messaging functions might not make any sense. -#ifndef SMALL_MEMORY_TARGET - //Array of meaningful error messages to associate with codes. - //Not used on targets with low memory (i.e. PIC). - static char *owErrorMsg[125] = - { - /*000*/ "No Error Was Set", - /*001*/ "No Devices found on 1-Wire Network", - /*002*/ "1-Wire Net Reset Failed", - /*003*/ "Search ROM Error: Couldn't locate next device on 1-Wire", - /*004*/ "Access Failed: Could not select device", - /*005*/ "DS2480B Adapter Not Detected", - /*006*/ "DS2480B: Wrong Baud", - /*007*/ "DS2480B: Bad Response", - /*008*/ "Open COM Failed", - /*009*/ "Write COM Failed", - /*010*/ "Read COM Failed", - /*011*/ "Data Block Too Large", - /*012*/ "Block Transfer failed", - /*013*/ "Program Pulse Failed", - /*014*/ "Program Byte Failed", - /*015*/ "Write Byte Failed", - /*016*/ "Read Byte Failed", - /*017*/ "Write Verify Failed", - /*018*/ "Read Verify Failed", - /*019*/ "Write Scratchpad Failed", - /*020*/ "Copy Scratchpad Failed", - /*021*/ "Incorrect CRC Length", - /*022*/ "CRC Failed", - /*023*/ "Failed to acquire a necessary system resource", - /*024*/ "Failed to initialize system resource", - /*025*/ "Data too long to fit on specified device.", - /*026*/ "Read exceeds memory bank end.", - /*027*/ "Write exceeds memory bank end.", - /*028*/ "Device select failed", - /*029*/ "Read Scratch Pad verify failed.", - /*030*/ "Copy scratchpad complete not found", - /*031*/ "Erase scratchpad complete not found", - /*032*/ "Address read back from scrachpad was incorrect", - /*033*/ "Read page with extra-info not supported by this memory bank", - /*034*/ "Read page packet with extra-info not supported by this memory bank", - /*035*/ "Length of packet requested exceeds page size", - /*036*/ "Invalid length in packet", - /*037*/ "Program pulse required but not available", - /*038*/ "Trying to access a read-only memory bank", - /*039*/ "Current bank is not general purpose memory", - /*040*/ "Read back from write compare is incorrect, page may be locked", - /*041*/ "Invalid page number for this memory bank", - /*042*/ "Read page with CRC not supported by this memory bank", - /*043*/ "Read page with CRC and extra-info not supported by this memory bank", - /*044*/ "Read back from write incorrect, could not lock page", - /*045*/ "Read back from write incorrect, could not lock redirect byte", - /*046*/ "The read of the status was not completed.", - /*047*/ "Page redirection not supported by this memory bank", - /*048*/ "Lock Page redirection not supported by this memory bank", - /*049*/ "Read back byte on EPROM programming did not match.", - /*050*/ "Can not write to a page that is locked.", - /*051*/ "Can not lock a redirected page that has already been locked.", - /*052*/ "Trying to redirect a locked redirected page.", - /*053*/ "Trying to lock a page that is already locked.", - /*054*/ "Trying to write to a memory bank that is write protected.", - /*055*/ "Error due to not matching MAC.", - /*056*/ "Memory Bank is write protected.", - /*057*/ "Secret is write protected, can not Load First Secret.", - /*058*/ "Error in Reading Scratchpad after Computing Next Secret.", - /*059*/ "Load Error from Loading First Secret.", - /*060*/ "Power delivery required but not available", - /*061*/ "Not a valid file name.", - /*062*/ "Unable to Create a Directory in this part.", - /*063*/ "That file already exists.", - /*064*/ "The directory is not empty.", - /*065*/ "The wrong type of part for this operation.", - /*066*/ "The max len for this file is too small.", - /*067*/ "This is not a write once bank.", - /*068*/ "The file can not be found.", - /*069*/ "There is not enough space available.", - /*070*/ "There is not a page to match that bit in the bitmap.", - /*071*/ "There are no jobs for EPROM parts.", - /*072*/ "Function not supported to modify attributes.", - /*073*/ "Handle is not in use.", - /*074*/ "Tring to read a write only file.", - /*075*/ "There is no handle available for use.", - /*076*/ "The directory provided is an invalid directory.", - /*077*/ "Handle does not exist.", - /*078*/ "Serial Number did not match with current job.", - /*079*/ "Can not program EPROM because a non-EPROM part on the network.", - /*080*/ "Write protect redirection byte is set.", - /*081*/ "There is an inappropriate directory length.", - /*082*/ "The file has already been terminated.", - /*083*/ "Failed to read memory page of iButton part.", - /*084*/ "Failed to match scratchpad of iButton part.", - /*085*/ "Failed to erase scratchpad of iButton part.", - /*086*/ "Failed to read scratchpad of iButton part.", - /*087*/ "Failed to execute SHA function on SHA iButton.", - /*088*/ "SHA iButton did not return a status completion byte.", - /*089*/ "Write data page failed.", - /*090*/ "Copy secret into secret memory pages failed.", - /*091*/ "Bind unique secret to iButton failed.", - /*092*/ "Could not install secret into user token.", - /*093*/ "Transaction Incomplete: signature did not match.", - /*094*/ "Transaction Incomplete: could not sign service data.", - /*095*/ "User token did not provide a valid authentication response.", - /*096*/ "Failed to answer a challenge on the user token.", - /*097*/ "Failed to create a challenge on the coprocessor.", - /*098*/ "Transaction Incomplete: service data was not valid.", - /*099*/ "Transaction Incomplete: service data was not updated.", - /*100*/ "Unrecoverable, catastrophic service failure occured.", - /*101*/ "Load First Secret from scratchpad data failed.", - /*102*/ "Failed to match signature of user's service data.", - /*103*/ "Subkey out of range for the DS1991.", - /*104*/ "Block ID out of range for the DS1991", - /*105*/ "Password is enabled", - /*106*/ "Password is invalid", - /*107*/ "This memory bank has no read only password", - /*108*/ "This memory bank has no read/write password", - /*109*/ "1-Wire is shorted", - /*110*/ "Error communicating with 1-Wire adapter", - /*111*/ "CopyScratchpad failed: Ending Offset must go to end of page", - /*112*/ "WriteScratchpad failed: Ending Offset must go to end of page", - /*113*/ "Mission can not be stopped while one is not in progress", - /*114*/ "Error stopping the mission", - /*115*/ "Port number is outside (0,MAX_PORTNUM) interval", - /*116*/ "Level of the 1-Wire was not changed", - /*117*/ "Both the Read Only and Read Write Passwords must be set", - /*118*/ "Failure to change latch state." - /*119*/ "Could not open usb port through libusb", - /*120*/ "Libusb DS2490 port already opened", - /*121*/ "Failed to set libusb configuration", - /*122*/ "Failed to claim libusb interface", - /*123*/ "Failed to set libusb altinterface", - /*124*/ "No adapter found at this port number" - }; - - char *owGetErrorMsg(int err) - { - return owErrorMsg[err]; - } - -#ifndef __C51__ - //-------------------------------------------------------------------------- - // The 'owPrintErrorMsg' is the method for printing an error from the stack. - // The destination for the print is specified by the argument, fileno, which - // can be stderr, stdout, or a log file. In non-debug mode, the output is - // of the form: - // Error num: Error msg - // - // In debug-mode, the output is of the form: - // Error num: filename line#: Error msg - // - // NOTE: This function has the side-effect of popping the error off the stack. - // - // Arguments: FILE*: the destination for printing. - // - void owPrintErrorMsg(FILE *filenum) - { - #ifdef DEBUG - int l = owErrorStack[ owErrorPointer ].lineno; - char *f = owErrorStack[ owErrorPointer ].filename; - int err = owGetErrorNum(); - fprintf(filenum,"Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]); - #else - int err = owGetErrorNum(); - fprintf(filenum,"Error %d: %s\r\n",err,owErrorMsg[err]); - #endif - } -#endif //__C51__ - - // Same as above, except uses default printf output - void owPrintErrorMsgStd() - { - #ifdef DEBUG - int l = owErrorStack[ owErrorPointer ].lineno; - char *f = owErrorStack[ owErrorPointer ].filename; - int err = owGetErrorNum(); - printf("Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]); - #else - int err = owGetErrorNum(); - printf("Error %d: %s\r\n",err,owErrorMsg[err]); - #endif - } -#endif - +//--------------------------------------------------------------------------- +// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name of Dallas Semiconductor +// shall not be used except as stated in the Dallas Semiconductor +// Branding Policy. +//--------------------------------------------------------------------------- +// +// owerr.c - Library functions for error handling with 1-Wire library +// +// Version: 1.00 +// + +#include +#ifndef _WIN32_WCE +#include +#endif +#ifdef _WIN64 +#include +#endif +#include "ownet.h" + +#ifndef SIZE_OWERROR_STACK + #ifdef SMALL_MEMORY_TARGET + //for small memory, only hole 1 error + #define SIZE_OWERROR_STACK 1 + #else + #define SIZE_OWERROR_STACK 10 + #endif +#endif + +//--------------------------------------------------------------------------- +// Variables +//--------------------------------------------------------------------------- + +// Error Struct for holding error information. +// In DEBUG, this will also hold the line number and filename. +typedef struct +{ + int owErrorNum; +#ifdef DEBUG + int lineno; + char *filename; +#endif +} owErrorStruct; + +// Ring-buffer used for stack. +// In case of overflow, deepest error is over-written. +static owErrorStruct owErrorStack[SIZE_OWERROR_STACK]; + +// Stack pointer to top-most error. +static int owErrorPointer = 0; + + +//--------------------------------------------------------------------------- +// Functions Definitions +//--------------------------------------------------------------------------- +int owGetErrorNum(void); +void owClearError(void); +int owHasErrors(void); +#ifdef DEBUG + void owRaiseError(int,int,char*); +#else + void owRaiseError(int); +#endif +#ifndef SMALL_MEMORY_TARGET + void owPrintErrorMsg(FILE *); + void owPrintErrorMsgStd(); + char *owGetErrorMsg(int); +#endif + + +//-------------------------------------------------------------------------- +// The 'owGetErroNum' returns the error code of the top-most error on the +// error stack. NOTE: This function has the side effect of popping the +// current error off the stack. All successive calls to 'owGetErrorNum' +// will further clear the error stack. +// +// For list of error codes, see 'ownet.h' +// +// Returns: int : The error code of the top-most error on the stack +// +int owGetErrorNum(void) +{ + int i = owErrorStack[ owErrorPointer ].owErrorNum; + owErrorStack[ owErrorPointer ].owErrorNum = 0; + if(!owErrorPointer) + owErrorPointer = SIZE_OWERROR_STACK - 1; + else + owErrorPointer = (owErrorPointer - 1); + return i; +} + +//-------------------------------------------------------------------------- +// The 'owClearError' clears all the errors. +// +void owClearError(void) +{ + owErrorStack[ owErrorPointer ].owErrorNum = 0; +} + +//-------------------------------------------------------------------------- +// The 'owHasErrors' is a boolean test function which tests whether or not +// a valid error is waiting on the stack. +// +// Returns: TRUE (1) : When there are errors on the stack. +// FALSE (0): When stack's errors are set to 0, or NO_ERROR_SET. +// +int owHasErrors(void) +{ + if(owErrorStack[ owErrorPointer ].owErrorNum) + return 1; //TRUE + else + return 0; //FALSE +} + +#ifdef DEBUG + //-------------------------------------------------------------------------- + // The 'owRaiseError' is the method for raising an error onto the error + // stack. + // + // Arguments: int err - the error code you wish to raise. + // int lineno - DEBUG only - the line number where it was raised + // char* filename - DEBUG only - the file name where it occured. + // + void owRaiseError(int err, int lineno, char* filename) + { + owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK; + owErrorStack[ owErrorPointer ].owErrorNum = err; + owErrorStack[ owErrorPointer ].lineno = lineno; + owErrorStack[ owErrorPointer ].filename = filename; + } +#else + //-------------------------------------------------------------------------- + // The 'owRaiseError' is the method for raising an error onto the error + // stack. + // + // Arguments: int err - the error code you wish to raise. + // + void owRaiseError(int err) + { + owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK; + owErrorStack[ owErrorPointer ].owErrorNum = err; + } +#endif + + +// SMALL_MEMORY_TARGET - embedded microcontrollers, where these +// messaging functions might not make any sense. +#ifndef SMALL_MEMORY_TARGET + //Array of meaningful error messages to associate with codes. + //Not used on targets with low memory (i.e. PIC). + static char *owErrorMsg[125] = + { + /*000*/ "No Error Was Set", + /*001*/ "No Devices found on 1-Wire Network", + /*002*/ "1-Wire Net Reset Failed", + /*003*/ "Search ROM Error: Couldn't locate next device on 1-Wire", + /*004*/ "Access Failed: Could not select device", + /*005*/ "DS2480B Adapter Not Detected", + /*006*/ "DS2480B: Wrong Baud", + /*007*/ "DS2480B: Bad Response", + /*008*/ "Open COM Failed", + /*009*/ "Write COM Failed", + /*010*/ "Read COM Failed", + /*011*/ "Data Block Too Large", + /*012*/ "Block Transfer failed", + /*013*/ "Program Pulse Failed", + /*014*/ "Program Byte Failed", + /*015*/ "Write Byte Failed", + /*016*/ "Read Byte Failed", + /*017*/ "Write Verify Failed", + /*018*/ "Read Verify Failed", + /*019*/ "Write Scratchpad Failed", + /*020*/ "Copy Scratchpad Failed", + /*021*/ "Incorrect CRC Length", + /*022*/ "CRC Failed", + /*023*/ "Failed to acquire a necessary system resource", + /*024*/ "Failed to initialize system resource", + /*025*/ "Data too long to fit on specified device.", + /*026*/ "Read exceeds memory bank end.", + /*027*/ "Write exceeds memory bank end.", + /*028*/ "Device select failed", + /*029*/ "Read Scratch Pad verify failed.", + /*030*/ "Copy scratchpad complete not found", + /*031*/ "Erase scratchpad complete not found", + /*032*/ "Address read back from scrachpad was incorrect", + /*033*/ "Read page with extra-info not supported by this memory bank", + /*034*/ "Read page packet with extra-info not supported by this memory bank", + /*035*/ "Length of packet requested exceeds page size", + /*036*/ "Invalid length in packet", + /*037*/ "Program pulse required but not available", + /*038*/ "Trying to access a read-only memory bank", + /*039*/ "Current bank is not general purpose memory", + /*040*/ "Read back from write compare is incorrect, page may be locked", + /*041*/ "Invalid page number for this memory bank", + /*042*/ "Read page with CRC not supported by this memory bank", + /*043*/ "Read page with CRC and extra-info not supported by this memory bank", + /*044*/ "Read back from write incorrect, could not lock page", + /*045*/ "Read back from write incorrect, could not lock redirect byte", + /*046*/ "The read of the status was not completed.", + /*047*/ "Page redirection not supported by this memory bank", + /*048*/ "Lock Page redirection not supported by this memory bank", + /*049*/ "Read back byte on EPROM programming did not match.", + /*050*/ "Can not write to a page that is locked.", + /*051*/ "Can not lock a redirected page that has already been locked.", + /*052*/ "Trying to redirect a locked redirected page.", + /*053*/ "Trying to lock a page that is already locked.", + /*054*/ "Trying to write to a memory bank that is write protected.", + /*055*/ "Error due to not matching MAC.", + /*056*/ "Memory Bank is write protected.", + /*057*/ "Secret is write protected, can not Load First Secret.", + /*058*/ "Error in Reading Scratchpad after Computing Next Secret.", + /*059*/ "Load Error from Loading First Secret.", + /*060*/ "Power delivery required but not available", + /*061*/ "Not a valid file name.", + /*062*/ "Unable to Create a Directory in this part.", + /*063*/ "That file already exists.", + /*064*/ "The directory is not empty.", + /*065*/ "The wrong type of part for this operation.", + /*066*/ "The max len for this file is too small.", + /*067*/ "This is not a write once bank.", + /*068*/ "The file can not be found.", + /*069*/ "There is not enough space available.", + /*070*/ "There is not a page to match that bit in the bitmap.", + /*071*/ "There are no jobs for EPROM parts.", + /*072*/ "Function not supported to modify attributes.", + /*073*/ "Handle is not in use.", + /*074*/ "Tring to read a write only file.", + /*075*/ "There is no handle available for use.", + /*076*/ "The directory provided is an invalid directory.", + /*077*/ "Handle does not exist.", + /*078*/ "Serial Number did not match with current job.", + /*079*/ "Can not program EPROM because a non-EPROM part on the network.", + /*080*/ "Write protect redirection byte is set.", + /*081*/ "There is an inappropriate directory length.", + /*082*/ "The file has already been terminated.", + /*083*/ "Failed to read memory page of iButton part.", + /*084*/ "Failed to match scratchpad of iButton part.", + /*085*/ "Failed to erase scratchpad of iButton part.", + /*086*/ "Failed to read scratchpad of iButton part.", + /*087*/ "Failed to execute SHA function on SHA iButton.", + /*088*/ "SHA iButton did not return a status completion byte.", + /*089*/ "Write data page failed.", + /*090*/ "Copy secret into secret memory pages failed.", + /*091*/ "Bind unique secret to iButton failed.", + /*092*/ "Could not install secret into user token.", + /*093*/ "Transaction Incomplete: signature did not match.", + /*094*/ "Transaction Incomplete: could not sign service data.", + /*095*/ "User token did not provide a valid authentication response.", + /*096*/ "Failed to answer a challenge on the user token.", + /*097*/ "Failed to create a challenge on the coprocessor.", + /*098*/ "Transaction Incomplete: service data was not valid.", + /*099*/ "Transaction Incomplete: service data was not updated.", + /*100*/ "Unrecoverable, catastrophic service failure occured.", + /*101*/ "Load First Secret from scratchpad data failed.", + /*102*/ "Failed to match signature of user's service data.", + /*103*/ "Subkey out of range for the DS1991.", + /*104*/ "Block ID out of range for the DS1991", + /*105*/ "Password is enabled", + /*106*/ "Password is invalid", + /*107*/ "This memory bank has no read only password", + /*108*/ "This memory bank has no read/write password", + /*109*/ "1-Wire is shorted", + /*110*/ "Error communicating with 1-Wire adapter", + /*111*/ "CopyScratchpad failed: Ending Offset must go to end of page", + /*112*/ "WriteScratchpad failed: Ending Offset must go to end of page", + /*113*/ "Mission can not be stopped while one is not in progress", + /*114*/ "Error stopping the mission", + /*115*/ "Port number is outside (0,MAX_PORTNUM) interval", + /*116*/ "Level of the 1-Wire was not changed", + /*117*/ "Both the Read Only and Read Write Passwords must be set", + /*118*/ "Failure to change latch state." + /*119*/ "Could not open usb port through libusb", + /*120*/ "Libusb DS2490 port already opened", + /*121*/ "Failed to set libusb configuration", + /*122*/ "Failed to claim libusb interface", + /*123*/ "Failed to set libusb altinterface", + /*124*/ "No adapter found at this port number" + }; + + char *owGetErrorMsg(int err) + { + return owErrorMsg[err]; + } + +#ifndef __C51__ + //-------------------------------------------------------------------------- + // The 'owPrintErrorMsg' is the method for printing an error from the stack. + // The destination for the print is specified by the argument, fileno, which + // can be stderr, stdout, or a log file. In non-debug mode, the output is + // of the form: + // Error num: Error msg + // + // In debug-mode, the output is of the form: + // Error num: filename line#: Error msg + // + // NOTE: This function has the side-effect of popping the error off the stack. + // + // Arguments: FILE*: the destination for printing. + // + void owPrintErrorMsg(FILE *filenum) + { + #ifdef DEBUG + int l = owErrorStack[ owErrorPointer ].lineno; + char *f = owErrorStack[ owErrorPointer ].filename; + int err = owGetErrorNum(); + fprintf(filenum,"Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]); + #else + int err = owGetErrorNum(); + fprintf(filenum,"Error %d: %s\r\n",err,owErrorMsg[err]); + #endif + } +#endif //__C51__ + + // Same as above, except uses default printf output + void owPrintErrorMsgStd() + { + #ifdef DEBUG + int l = owErrorStack[ owErrorPointer ].lineno; + char *f = owErrorStack[ owErrorPointer ].filename; + int err = owGetErrorNum(); + printf("Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]); + #else + int err = owGetErrorNum(); + printf("Error %d: %s\r\n",err,owErrorMsg[err]); + #endif + } +#endif + diff --git a/tools_cmd/rwOW/ownet.h b/tools_cmd/rwOW/ownet.h index a74cd95..7c0c144 100644 --- a/tools_cmd/rwOW/ownet.h +++ b/tools_cmd/rwOW/ownet.h @@ -1,422 +1,422 @@ -//--------------------------------------------------------------------------- -// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES -// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// Except as contained in this notice, the name of Dallas Semiconductor -// shall not be used except as stated in the Dallas Semiconductor -// Branding Policy. -//--------------------------------------------------------------------------- -// -// ownet.h - Include file for 1-Wire Net library -// -// Version: 2.10 -// -// History: 1.02 -> 1.03 Make sure uchar is not defined twice. -// 1.03 -> 2.00 Changed 'MLan' to 'ow'. -// 2.00 -> 2.01 Added error handling. Added circular-include check. -// 2.01 -> 2.10 Added raw memory error handling and SMALLINT -// 2.10 -> 3.00 Added memory bank functionality -// Added file I/O operations -// - -#ifndef OWNET_H -#define OWNET_H - -//--------------------------------------------------------------// -// Common Includes to ownet applications -//--------------------------------------------------------------// -#include - - -//--------------------------------------------------------------// -// Target Specific Information -//--------------------------------------------------------------// -//--------------------------------------------------------------// -// Handhelds (PalmOS, WinCE) -//--------------------------------------------------------------// -#ifdef __MC68K__ - //MC68K is the type of processor in the PILOT - //Metrowerk's CodeWarrior defines this symbol - #include - #ifndef strcmp - #include - #define strcmp StrCompare - #endif - #include -#endif - -#ifdef _WIN32_WCE - //All of our projects had this flag defined by default (_WIN32_WCE), - //but I'm not 100% positive that this is _the_ definitive - //flag to use to identify a WinCE system. - #include "WinCElnk.h" - #ifndef FILE - #define FILE int - extern int sprintf(char *buffer, char *format,...); - extern void fprintf(FILE *fp, char *format,...); - extern void printf(char *format,...); - #endif -#endif - -#if !defined(_WIN32_WCE) && !defined(__MC68K__) - #include -#endif - -#ifdef __C51__ - #define FILE int - #define exit(c) return - typedef unsigned int ushort; - typedef unsigned long ulong; - #define SMALLINT uchar -#endif - -#ifdef __ICCMAXQ__ - #define FILE int - #define stdout 0 - #define stdin 1 - #define stderr 2 - typedef unsigned int ushort; - typedef unsigned long ulong; - #define SMALLINT short - #define main micro_main - #define real_main main - #define SMALL_MEMORY_TARGET -#endif - - -//--------------------------------------------------------------// -// Typedefs -//--------------------------------------------------------------// -#ifndef SMALLINT - // - // purpose of smallint is for compile-time changing of formal - // parameters and return values of functions. For each target - // machine, an integer is alleged to represent the most "simple" - // number representable by that architecture. This should, in - // most cases, produce optimal code for that particular arch. - // BUT... The majority of compilers designed for embedded - // processors actually keep an int at 16 bits, although the - // architecture might only be comfortable with 8 bits. - // The default size of smallint will be the same as that of - // an integer, but this allows for easy overriding of that size. - // - // NOTE: - // In all cases where a smallint is used, it is assumed that - // decreasing the size of this integer to something as low as - // a single byte _will_not_ change the functionality of the - // application. e.g. a loop counter that will iterate through - // several kilobytes of data should not be SMALLINT. The most - // common place you'll see smallint is for boolean return types. - // - #define SMALLINT int -#endif - -// setting max baud -#ifdef _WINDOWS - // 0x02 = PARAMSET_19200 -#define MAX_BAUD 0x02 -#else - // 0x06 = PARMSET_115200 -#define MAX_BAUD 0x06 -#endif - -#ifndef OW_UCHAR - #define OW_UCHAR - typedef unsigned char uchar; - #if !defined(__MINGW32__) && (defined(__CYGWIN__) || defined(__GNUC__)) - typedef unsigned long ulong; - //ushort already defined in sys/types.h - #include - #else - #if defined(_WIN32) || defined(WIN32) || defined(__MC68K__) || defined(_WIN32_WCE) || defined(_DOS) || defined(_WINDOWS) || defined(__MINGW32__) - typedef unsigned short ushort; - typedef unsigned long ulong; - #endif - #endif - #ifdef __sun__ - #include - #endif - #ifdef SDCC - //intent of ushort is 2 bytes unsigned. - //for ds390 in sdcc, an int, not a short, - //is 2 bytes. - typedef unsigned int ushort; - #endif -#endif - -// general defines -#define WRITE_FUNCTION 1 -#define READ_FUNCTION 0 - -// error codes -// todo: investigate these and replace with new Error Handling library -#define READ_ERROR -1 -#define INVALID_DIR -2 -#define NO_FILE -3 -#define WRITE_ERROR -4 -#define WRONG_TYPE -5 -#define FILE_TOO_BIG -6 - -// Misc -#define FALSE 0 -#define TRUE 1 - -#ifndef MAX_PORTNUM - #define MAX_PORTNUM 16 -#endif - -// mode bit flags -#define MODE_NORMAL 0x00 -#define MODE_OVERDRIVE 0x01 -#define MODE_STRONG5 0x02 -#define MODE_PROGRAM 0x04 -#define MODE_BREAK 0x08 - -// Output flags -#define LV_ALWAYS 2 -#define LV_OPTIONAL 1 -#define LV_VERBOSE 0 - -//--------------------------------------------------------------// -// Error handling -//--------------------------------------------------------------// -extern int owGetErrorNum(void); -extern int owHasErrors(void); - -//Clears the stack. -#define OWERROR_CLEAR() while(owHasErrors()) owGetErrorNum(); - -#ifdef DEBUG - //Raises an exception with extra debug info - #define OWERROR(err) owRaiseError(err,__LINE__,__FILE__) - extern void owRaiseError(int,int,char*); - #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err),__LINE__,__FILE__);return (ret);} -#else - //Raises an exception with just the error code - #define OWERROR(err) owRaiseError(err) - extern void owRaiseError(int); - #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err));return (ret);} -#endif - -#ifdef SMALL_MEMORY_TARGET - #define OWERROR_DUMP(fileno) /*no-op*/; -#else - //Prints the stack out to the given file. - #define OWERROR_DUMP(fileno) while(owHasErrors()) owPrintErrorMsg(fileno); - extern void owPrintErrorMsg(FILE *); - extern void owPrintErrorMsgStd(); - extern char *owGetErrorMsg(int); -#endif - -#define OWERROR_NO_ERROR_SET 0 -#define OWERROR_NO_DEVICES_ON_NET 1 -#define OWERROR_RESET_FAILED 2 -#define OWERROR_SEARCH_ERROR 3 -#define OWERROR_ACCESS_FAILED 4 -#define OWERROR_DS2480_NOT_DETECTED 5 -#define OWERROR_DS2480_WRONG_BAUD 6 -#define OWERROR_DS2480_BAD_RESPONSE 7 -#define OWERROR_OPENCOM_FAILED 8 -#define OWERROR_WRITECOM_FAILED 9 -#define OWERROR_READCOM_FAILED 10 -#define OWERROR_BLOCK_TOO_BIG 11 -#define OWERROR_BLOCK_FAILED 12 -#define OWERROR_PROGRAM_PULSE_FAILED 13 -#define OWERROR_PROGRAM_BYTE_FAILED 14 -#define OWERROR_WRITE_BYTE_FAILED 15 -#define OWERROR_READ_BYTE_FAILED 16 -#define OWERROR_WRITE_VERIFY_FAILED 17 -#define OWERROR_READ_VERIFY_FAILED 18 -#define OWERROR_WRITE_SCRATCHPAD_FAILED 19 -#define OWERROR_COPY_SCRATCHPAD_FAILED 20 -#define OWERROR_INCORRECT_CRC_LENGTH 21 -#define OWERROR_CRC_FAILED 22 -#define OWERROR_GET_SYSTEM_RESOURCE_FAILED 23 -#define OWERROR_SYSTEM_RESOURCE_INIT_FAILED 24 -#define OWERROR_DATA_TOO_LONG 25 -#define OWERROR_READ_OUT_OF_RANGE 26 -#define OWERROR_WRITE_OUT_OF_RANGE 27 -#define OWERROR_DEVICE_SELECT_FAIL 28 -#define OWERROR_READ_SCRATCHPAD_VERIFY 29 -#define OWERROR_COPY_SCRATCHPAD_NOT_FOUND 30 -#define OWERROR_ERASE_SCRATCHPAD_NOT_FOUND 31 -#define OWERROR_ADDRESS_READ_BACK_FAILED 32 -#define OWERROR_EXTRA_INFO_NOT_SUPPORTED 33 -#define OWERROR_PG_PACKET_WITHOUT_EXTRA 34 -#define OWERROR_PACKET_LENGTH_EXCEEDS_PAGE 35 -#define OWERROR_INVALID_PACKET_LENGTH 36 -#define OWERROR_NO_PROGRAM_PULSE 37 -#define OWERROR_READ_ONLY 38 -#define OWERROR_NOT_GENERAL_PURPOSE 39 -#define OWERROR_READ_BACK_INCORRECT 40 -#define OWERROR_INVALID_PAGE_NUMBER 41 -#define OWERROR_CRC_NOT_SUPPORTED 42 -#define OWERROR_CRC_EXTRA_INFO_NOT_SUPPORTED 43 -#define OWERROR_READ_BACK_NOT_VALID 44 -#define OWERROR_COULD_NOT_LOCK_REDIRECT 45 -#define OWERROR_READ_STATUS_NOT_COMPLETE 46 -#define OWERROR_PAGE_REDIRECTION_NOT_SUPPORTED 47 -#define OWERROR_LOCK_REDIRECTION_NOT_SUPPORTED 48 -#define OWERROR_READBACK_EPROM_FAILED 49 -#define OWERROR_PAGE_LOCKED 50 -#define OWERROR_LOCKING_REDIRECTED_PAGE_AGAIN 51 -#define OWERROR_REDIRECTED_PAGE 52 -#define OWERROR_PAGE_ALREADY_LOCKED 53 -#define OWERROR_WRITE_PROTECTED 54 -#define OWERROR_NONMATCHING_MAC 55 -#define OWERROR_WRITE_PROTECT 56 -#define OWERROR_WRITE_PROTECT_SECRET 57 -#define OWERROR_COMPUTE_NEXT_SECRET 58 -#define OWERROR_LOAD_FIRST_SECRET 59 -#define OWERROR_POWER_NOT_AVAILABLE 60 -#define OWERROR_XBAD_FILENAME 61 -#define OWERROR_XUNABLE_TO_CREATE_DIR 62 -#define OWERROR_REPEAT_FILE 63 -#define OWERROR_DIRECTORY_NOT_EMPTY 64 -#define OWERROR_WRONG_TYPE 65 -#define OWERROR_BUFFER_TOO_SMALL 66 -#define OWERROR_NOT_WRITE_ONCE 67 -#define OWERROR_FILE_NOT_FOUND 68 -#define OWERROR_OUT_OF_SPACE 69 -#define OWERROR_TOO_LARGE_BITNUM 70 -#define OWERROR_NO_PROGRAM_JOB 71 -#define OWERROR_FUNC_NOT_SUP 72 -#define OWERROR_HANDLE_NOT_USED 73 -#define OWERROR_FILE_WRITE_ONLY 74 -#define OWERROR_HANDLE_NOT_AVAIL 75 -#define OWERROR_INVALID_DIRECTORY 76 -#define OWERROR_HANDLE_NOT_EXIST 77 -#define OWERROR_NONMATCHING_SNUM 78 -#define OWERROR_NON_PROGRAM_PARTS 79 -#define OWERROR_PROGRAM_WRITE_PROTECT 80 -#define OWERROR_FILE_READ_ERR 81 -#define OWERROR_ADDFILE_TERMINATED 82 -#define OWERROR_READ_MEMORY_PAGE_FAILED 83 -#define OWERROR_MATCH_SCRATCHPAD_FAILED 84 -#define OWERROR_ERASE_SCRATCHPAD_FAILED 85 -#define OWERROR_READ_SCRATCHPAD_FAILED 86 -#define OWERROR_SHA_FUNCTION_FAILED 87 -#define OWERROR_NO_COMPLETION_BYTE 88 -#define OWERROR_WRITE_DATA_PAGE_FAILED 89 -#define OWERROR_COPY_SECRET_FAILED 90 -#define OWERROR_BIND_SECRET_FAILED 91 -#define OWERROR_INSTALL_SECRET_FAILED 92 -#define OWERROR_VERIFY_SIG_FAILED 93 -#define OWERROR_SIGN_SERVICE_DATA_FAILED 94 -#define OWERROR_VERIFY_AUTH_RESPONSE_FAILED 95 -#define OWERROR_ANSWER_CHALLENGE_FAILED 96 -#define OWERROR_CREATE_CHALLENGE_FAILED 97 -#define OWERROR_BAD_SERVICE_DATA 98 -#define OWERROR_SERVICE_DATA_NOT_UPDATED 99 -#define OWERROR_CATASTROPHIC_SERVICE_FAILURE 100 -#define OWERROR_LOAD_FIRST_SECRET_FAILED 101 -#define OWERROR_MATCH_SERVICE_SIGNATURE_FAILED 102 -#define OWERROR_KEY_OUT_OF_RANGE 103 -#define OWERROR_BLOCK_ID_OUT_OF_RANGE 104 -#define OWERROR_PASSWORDS_ENABLED 105 -#define OWERROR_PASSWORD_INVALID 106 -#define OWERROR_NO_READ_ONLY_PASSWORD 107 -#define OWERROR_NO_READ_WRITE_PASSWORD 108 -#define OWERROR_OW_SHORTED 109 -#define OWERROR_ADAPTER_ERROR 110 -#define OWERROR_EOP_COPY_SCRATCHPAD_FAILED 111 -#define OWERROR_EOP_WRITE_SCRATCHPAD_FAILED 112 -#define OWERROR_HYGRO_STOP_MISSION_UNNECESSARY 113 -#define OWERROR_HYGRO_STOP_MISSION_ERROR 114 -#define OWERROR_PORTNUM_ERROR 115 -#define OWERROR_LEVEL_FAILED 116 -#define OWERROR_PASSWORD_NOT_SET 117 -#define OWERROR_LATCH_NOT_SET 118 -#define OWERROR_LIBUSB_OPEN_FAILED 119 -#define OWERROR_LIBUSB_DEVICE_ALREADY_OPENED 120 -#define OWERROR_LIBUSB_SET_CONFIGURATION_ERROR 121 -#define OWERROR_LIBUSB_CLAIM_INTERFACE_ERROR 122 -#define OWERROR_LIBUSB_SET_ALTINTERFACE_ERROR 123 -#define OWERROR_LIBUSB_NO_ADAPTER_FOUND 124 - -// One Wire functions defined in ownetu.c -SMALLINT owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only); -SMALLINT owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only); -void owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read); -void owFamilySearchSetup(int portnum, SMALLINT search_family); -void owSkipFamily(int portnum); -SMALLINT owAccess(int portnum); -SMALLINT owVerify(int portnum, SMALLINT alarm_only); -SMALLINT owOverdriveAccess(int portnum); - - -// external One Wire functions defined in owsesu.c - SMALLINT owAcquire(int portnum, char *port_zstr); - int owAcquireEx(char *port_zstr); - void owRelease(int portnum); - -// external One Wire functions defined in findtype.c -// SMALLINT FindDevices(int,uchar FamilySN[][8],SMALLINT,int); - -// external One Wire functions from link layer owllu.c -SMALLINT owTouchReset(int portnum); -SMALLINT owTouchBit(int portnum, SMALLINT sendbit); -SMALLINT owTouchByte(int portnum, SMALLINT sendbyte); -SMALLINT owWriteByte(int portnum, SMALLINT sendbyte); -SMALLINT owReadByte(int portnum); -SMALLINT owSpeed(int portnum, SMALLINT new_speed); -SMALLINT owLevel(int portnum, SMALLINT new_level); -SMALLINT owProgramPulse(int portnum); -SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte); -SMALLINT owReadBytePower(int portnum); -SMALLINT owHasPowerDelivery(int portnum); -SMALLINT owHasProgramPulse(int portnum); -SMALLINT owHasOverDrive(int portnum); -SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse); -// external One Wire global from owllu.c -extern SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE; - -// external One Wire functions from transaction layer in owtrnu.c -SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len); -SMALLINT owReadPacketStd(int portnum, SMALLINT do_access, int start_page, uchar *read_buf); -SMALLINT owWritePacketStd(int portnum, int start_page, uchar *write_buf, - SMALLINT write_len, SMALLINT is_eprom, SMALLINT crc_type); -SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd, - SMALLINT crc_type, SMALLINT do_access); - -// link functions -void msDelay(int len); -long msGettick(void); - -// ioutil.c functions prototypes -int EnterString(char *msg, char *buf, int min, int max); -int EnterNum(char *msg, int numchars, long *value, long min, long max); -int EnterHex(char *msg, int numchars, ulong *value); -int ToHex(char ch); -int getkeystroke(void); -int key_abort(void); -void ExitProg(char *msg, int exit_code); -int getData(uchar *write_buff, int max_len, SMALLINT gethex); -void PrintHex(uchar* buffer, int cnt); -void PrintChars(uchar* buffer, int cnt); -void PrintSerialNum(uchar* buffer); - -// external functions defined in crcutil.c -void setcrc16(int portnum, ushort reset); -ushort docrc16(int portnum, ushort cdata); -void setcrc8(int portnum, uchar reset); -uchar docrc8(int portnum, uchar x); - -#endif //OWNET_H +//--------------------------------------------------------------------------- +// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name of Dallas Semiconductor +// shall not be used except as stated in the Dallas Semiconductor +// Branding Policy. +//--------------------------------------------------------------------------- +// +// ownet.h - Include file for 1-Wire Net library +// +// Version: 2.10 +// +// History: 1.02 -> 1.03 Make sure uchar is not defined twice. +// 1.03 -> 2.00 Changed 'MLan' to 'ow'. +// 2.00 -> 2.01 Added error handling. Added circular-include check. +// 2.01 -> 2.10 Added raw memory error handling and SMALLINT +// 2.10 -> 3.00 Added memory bank functionality +// Added file I/O operations +// + +#ifndef OWNET_H +#define OWNET_H + +//--------------------------------------------------------------// +// Common Includes to ownet applications +//--------------------------------------------------------------// +#include + + +//--------------------------------------------------------------// +// Target Specific Information +//--------------------------------------------------------------// +//--------------------------------------------------------------// +// Handhelds (PalmOS, WinCE) +//--------------------------------------------------------------// +#ifdef __MC68K__ + //MC68K is the type of processor in the PILOT + //Metrowerk's CodeWarrior defines this symbol + #include + #ifndef strcmp + #include + #define strcmp StrCompare + #endif + #include +#endif + +#ifdef _WIN32_WCE + //All of our projects had this flag defined by default (_WIN32_WCE), + //but I'm not 100% positive that this is _the_ definitive + //flag to use to identify a WinCE system. + #include "WinCElnk.h" + #ifndef FILE + #define FILE int + extern int sprintf(char *buffer, char *format,...); + extern void fprintf(FILE *fp, char *format,...); + extern void printf(char *format,...); + #endif +#endif + +#if !defined(_WIN32_WCE) && !defined(__MC68K__) + #include +#endif + +#ifdef __C51__ + #define FILE int + #define exit(c) return + typedef unsigned int ushort; + typedef unsigned long ulong; + #define SMALLINT uchar +#endif + +#ifdef __ICCMAXQ__ + #define FILE int + #define stdout 0 + #define stdin 1 + #define stderr 2 + typedef unsigned int ushort; + typedef unsigned long ulong; + #define SMALLINT short + #define main micro_main + #define real_main main + #define SMALL_MEMORY_TARGET +#endif + + +//--------------------------------------------------------------// +// Typedefs +//--------------------------------------------------------------// +#ifndef SMALLINT + // + // purpose of smallint is for compile-time changing of formal + // parameters and return values of functions. For each target + // machine, an integer is alleged to represent the most "simple" + // number representable by that architecture. This should, in + // most cases, produce optimal code for that particular arch. + // BUT... The majority of compilers designed for embedded + // processors actually keep an int at 16 bits, although the + // architecture might only be comfortable with 8 bits. + // The default size of smallint will be the same as that of + // an integer, but this allows for easy overriding of that size. + // + // NOTE: + // In all cases where a smallint is used, it is assumed that + // decreasing the size of this integer to something as low as + // a single byte _will_not_ change the functionality of the + // application. e.g. a loop counter that will iterate through + // several kilobytes of data should not be SMALLINT. The most + // common place you'll see smallint is for boolean return types. + // + #define SMALLINT int +#endif + +// setting max baud +#ifdef _WINDOWS + // 0x02 = PARAMSET_19200 +#define MAX_BAUD 0x02 +#else + // 0x06 = PARMSET_115200 +#define MAX_BAUD 0x06 +#endif + +#ifndef OW_UCHAR + #define OW_UCHAR + typedef unsigned char uchar; + #if !defined(__MINGW32__) && (defined(__CYGWIN__) || defined(__GNUC__)) + typedef unsigned long ulong; + //ushort already defined in sys/types.h + #include + #else + #if defined(_WIN32) || defined(WIN32) || defined(__MC68K__) || defined(_WIN32_WCE) || defined(_DOS) || defined(_WINDOWS) || defined(__MINGW32__) + typedef unsigned short ushort; + typedef unsigned long ulong; + #endif + #endif + #ifdef __sun__ + #include + #endif + #ifdef SDCC + //intent of ushort is 2 bytes unsigned. + //for ds390 in sdcc, an int, not a short, + //is 2 bytes. + typedef unsigned int ushort; + #endif +#endif + +// general defines +#define WRITE_FUNCTION 1 +#define READ_FUNCTION 0 + +// error codes +// todo: investigate these and replace with new Error Handling library +#define READ_ERROR -1 +#define INVALID_DIR -2 +#define NO_FILE -3 +#define WRITE_ERROR -4 +#define WRONG_TYPE -5 +#define FILE_TOO_BIG -6 + +// Misc +#define FALSE 0 +#define TRUE 1 + +#ifndef MAX_PORTNUM + #define MAX_PORTNUM 16 +#endif + +// mode bit flags +#define MODE_NORMAL 0x00 +#define MODE_OVERDRIVE 0x01 +#define MODE_STRONG5 0x02 +#define MODE_PROGRAM 0x04 +#define MODE_BREAK 0x08 + +// Output flags +#define LV_ALWAYS 2 +#define LV_OPTIONAL 1 +#define LV_VERBOSE 0 + +//--------------------------------------------------------------// +// Error handling +//--------------------------------------------------------------// +extern int owGetErrorNum(void); +extern int owHasErrors(void); + +//Clears the stack. +#define OWERROR_CLEAR() while(owHasErrors()) owGetErrorNum(); + +#ifdef DEBUG + //Raises an exception with extra debug info + #define OWERROR(err) owRaiseError(err,__LINE__,__FILE__) + extern void owRaiseError(int,int,char*); + #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err),__LINE__,__FILE__);return (ret);} +#else + //Raises an exception with just the error code + #define OWERROR(err) owRaiseError(err) + extern void owRaiseError(int); + #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err));return (ret);} +#endif + +#ifdef SMALL_MEMORY_TARGET + #define OWERROR_DUMP(fileno) /*no-op*/; +#else + //Prints the stack out to the given file. + #define OWERROR_DUMP(fileno) while(owHasErrors()) owPrintErrorMsg(fileno); + extern void owPrintErrorMsg(FILE *); + extern void owPrintErrorMsgStd(); + extern char *owGetErrorMsg(int); +#endif + +#define OWERROR_NO_ERROR_SET 0 +#define OWERROR_NO_DEVICES_ON_NET 1 +#define OWERROR_RESET_FAILED 2 +#define OWERROR_SEARCH_ERROR 3 +#define OWERROR_ACCESS_FAILED 4 +#define OWERROR_DS2480_NOT_DETECTED 5 +#define OWERROR_DS2480_WRONG_BAUD 6 +#define OWERROR_DS2480_BAD_RESPONSE 7 +#define OWERROR_OPENCOM_FAILED 8 +#define OWERROR_WRITECOM_FAILED 9 +#define OWERROR_READCOM_FAILED 10 +#define OWERROR_BLOCK_TOO_BIG 11 +#define OWERROR_BLOCK_FAILED 12 +#define OWERROR_PROGRAM_PULSE_FAILED 13 +#define OWERROR_PROGRAM_BYTE_FAILED 14 +#define OWERROR_WRITE_BYTE_FAILED 15 +#define OWERROR_READ_BYTE_FAILED 16 +#define OWERROR_WRITE_VERIFY_FAILED 17 +#define OWERROR_READ_VERIFY_FAILED 18 +#define OWERROR_WRITE_SCRATCHPAD_FAILED 19 +#define OWERROR_COPY_SCRATCHPAD_FAILED 20 +#define OWERROR_INCORRECT_CRC_LENGTH 21 +#define OWERROR_CRC_FAILED 22 +#define OWERROR_GET_SYSTEM_RESOURCE_FAILED 23 +#define OWERROR_SYSTEM_RESOURCE_INIT_FAILED 24 +#define OWERROR_DATA_TOO_LONG 25 +#define OWERROR_READ_OUT_OF_RANGE 26 +#define OWERROR_WRITE_OUT_OF_RANGE 27 +#define OWERROR_DEVICE_SELECT_FAIL 28 +#define OWERROR_READ_SCRATCHPAD_VERIFY 29 +#define OWERROR_COPY_SCRATCHPAD_NOT_FOUND 30 +#define OWERROR_ERASE_SCRATCHPAD_NOT_FOUND 31 +#define OWERROR_ADDRESS_READ_BACK_FAILED 32 +#define OWERROR_EXTRA_INFO_NOT_SUPPORTED 33 +#define OWERROR_PG_PACKET_WITHOUT_EXTRA 34 +#define OWERROR_PACKET_LENGTH_EXCEEDS_PAGE 35 +#define OWERROR_INVALID_PACKET_LENGTH 36 +#define OWERROR_NO_PROGRAM_PULSE 37 +#define OWERROR_READ_ONLY 38 +#define OWERROR_NOT_GENERAL_PURPOSE 39 +#define OWERROR_READ_BACK_INCORRECT 40 +#define OWERROR_INVALID_PAGE_NUMBER 41 +#define OWERROR_CRC_NOT_SUPPORTED 42 +#define OWERROR_CRC_EXTRA_INFO_NOT_SUPPORTED 43 +#define OWERROR_READ_BACK_NOT_VALID 44 +#define OWERROR_COULD_NOT_LOCK_REDIRECT 45 +#define OWERROR_READ_STATUS_NOT_COMPLETE 46 +#define OWERROR_PAGE_REDIRECTION_NOT_SUPPORTED 47 +#define OWERROR_LOCK_REDIRECTION_NOT_SUPPORTED 48 +#define OWERROR_READBACK_EPROM_FAILED 49 +#define OWERROR_PAGE_LOCKED 50 +#define OWERROR_LOCKING_REDIRECTED_PAGE_AGAIN 51 +#define OWERROR_REDIRECTED_PAGE 52 +#define OWERROR_PAGE_ALREADY_LOCKED 53 +#define OWERROR_WRITE_PROTECTED 54 +#define OWERROR_NONMATCHING_MAC 55 +#define OWERROR_WRITE_PROTECT 56 +#define OWERROR_WRITE_PROTECT_SECRET 57 +#define OWERROR_COMPUTE_NEXT_SECRET 58 +#define OWERROR_LOAD_FIRST_SECRET 59 +#define OWERROR_POWER_NOT_AVAILABLE 60 +#define OWERROR_XBAD_FILENAME 61 +#define OWERROR_XUNABLE_TO_CREATE_DIR 62 +#define OWERROR_REPEAT_FILE 63 +#define OWERROR_DIRECTORY_NOT_EMPTY 64 +#define OWERROR_WRONG_TYPE 65 +#define OWERROR_BUFFER_TOO_SMALL 66 +#define OWERROR_NOT_WRITE_ONCE 67 +#define OWERROR_FILE_NOT_FOUND 68 +#define OWERROR_OUT_OF_SPACE 69 +#define OWERROR_TOO_LARGE_BITNUM 70 +#define OWERROR_NO_PROGRAM_JOB 71 +#define OWERROR_FUNC_NOT_SUP 72 +#define OWERROR_HANDLE_NOT_USED 73 +#define OWERROR_FILE_WRITE_ONLY 74 +#define OWERROR_HANDLE_NOT_AVAIL 75 +#define OWERROR_INVALID_DIRECTORY 76 +#define OWERROR_HANDLE_NOT_EXIST 77 +#define OWERROR_NONMATCHING_SNUM 78 +#define OWERROR_NON_PROGRAM_PARTS 79 +#define OWERROR_PROGRAM_WRITE_PROTECT 80 +#define OWERROR_FILE_READ_ERR 81 +#define OWERROR_ADDFILE_TERMINATED 82 +#define OWERROR_READ_MEMORY_PAGE_FAILED 83 +#define OWERROR_MATCH_SCRATCHPAD_FAILED 84 +#define OWERROR_ERASE_SCRATCHPAD_FAILED 85 +#define OWERROR_READ_SCRATCHPAD_FAILED 86 +#define OWERROR_SHA_FUNCTION_FAILED 87 +#define OWERROR_NO_COMPLETION_BYTE 88 +#define OWERROR_WRITE_DATA_PAGE_FAILED 89 +#define OWERROR_COPY_SECRET_FAILED 90 +#define OWERROR_BIND_SECRET_FAILED 91 +#define OWERROR_INSTALL_SECRET_FAILED 92 +#define OWERROR_VERIFY_SIG_FAILED 93 +#define OWERROR_SIGN_SERVICE_DATA_FAILED 94 +#define OWERROR_VERIFY_AUTH_RESPONSE_FAILED 95 +#define OWERROR_ANSWER_CHALLENGE_FAILED 96 +#define OWERROR_CREATE_CHALLENGE_FAILED 97 +#define OWERROR_BAD_SERVICE_DATA 98 +#define OWERROR_SERVICE_DATA_NOT_UPDATED 99 +#define OWERROR_CATASTROPHIC_SERVICE_FAILURE 100 +#define OWERROR_LOAD_FIRST_SECRET_FAILED 101 +#define OWERROR_MATCH_SERVICE_SIGNATURE_FAILED 102 +#define OWERROR_KEY_OUT_OF_RANGE 103 +#define OWERROR_BLOCK_ID_OUT_OF_RANGE 104 +#define OWERROR_PASSWORDS_ENABLED 105 +#define OWERROR_PASSWORD_INVALID 106 +#define OWERROR_NO_READ_ONLY_PASSWORD 107 +#define OWERROR_NO_READ_WRITE_PASSWORD 108 +#define OWERROR_OW_SHORTED 109 +#define OWERROR_ADAPTER_ERROR 110 +#define OWERROR_EOP_COPY_SCRATCHPAD_FAILED 111 +#define OWERROR_EOP_WRITE_SCRATCHPAD_FAILED 112 +#define OWERROR_HYGRO_STOP_MISSION_UNNECESSARY 113 +#define OWERROR_HYGRO_STOP_MISSION_ERROR 114 +#define OWERROR_PORTNUM_ERROR 115 +#define OWERROR_LEVEL_FAILED 116 +#define OWERROR_PASSWORD_NOT_SET 117 +#define OWERROR_LATCH_NOT_SET 118 +#define OWERROR_LIBUSB_OPEN_FAILED 119 +#define OWERROR_LIBUSB_DEVICE_ALREADY_OPENED 120 +#define OWERROR_LIBUSB_SET_CONFIGURATION_ERROR 121 +#define OWERROR_LIBUSB_CLAIM_INTERFACE_ERROR 122 +#define OWERROR_LIBUSB_SET_ALTINTERFACE_ERROR 123 +#define OWERROR_LIBUSB_NO_ADAPTER_FOUND 124 + +// One Wire functions defined in ownetu.c +SMALLINT owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only); +SMALLINT owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only); +void owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read); +void owFamilySearchSetup(int portnum, SMALLINT search_family); +void owSkipFamily(int portnum); +SMALLINT owAccess(int portnum); +SMALLINT owVerify(int portnum, SMALLINT alarm_only); +SMALLINT owOverdriveAccess(int portnum); + + +// external One Wire functions defined in owsesu.c + SMALLINT owAcquire(int portnum, char *port_zstr); + int owAcquireEx(char *port_zstr); + void owRelease(int portnum); + +// external One Wire functions defined in findtype.c +// SMALLINT FindDevices(int,uchar FamilySN[][8],SMALLINT,int); + +// external One Wire functions from link layer owllu.c +SMALLINT owTouchReset(int portnum); +SMALLINT owTouchBit(int portnum, SMALLINT sendbit); +SMALLINT owTouchByte(int portnum, SMALLINT sendbyte); +SMALLINT owWriteByte(int portnum, SMALLINT sendbyte); +SMALLINT owReadByte(int portnum); +SMALLINT owSpeed(int portnum, SMALLINT new_speed); +SMALLINT owLevel(int portnum, SMALLINT new_level); +SMALLINT owProgramPulse(int portnum); +SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte); +SMALLINT owReadBytePower(int portnum); +SMALLINT owHasPowerDelivery(int portnum); +SMALLINT owHasProgramPulse(int portnum); +SMALLINT owHasOverDrive(int portnum); +SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse); +// external One Wire global from owllu.c +extern SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE; + +// external One Wire functions from transaction layer in owtrnu.c +SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len); +SMALLINT owReadPacketStd(int portnum, SMALLINT do_access, int start_page, uchar *read_buf); +SMALLINT owWritePacketStd(int portnum, int start_page, uchar *write_buf, + SMALLINT write_len, SMALLINT is_eprom, SMALLINT crc_type); +SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd, + SMALLINT crc_type, SMALLINT do_access); + +// link functions +void msDelay(int len); +long msGettick(void); + +// ioutil.c functions prototypes +int EnterString(char *msg, char *buf, int min, int max); +int EnterNum(char *msg, int numchars, long *value, long min, long max); +int EnterHex(char *msg, int numchars, ulong *value); +int ToHex(char ch); +int getkeystroke(void); +int key_abort(void); +void ExitProg(char *msg, int exit_code); +int getData(uchar *write_buff, int max_len, SMALLINT gethex); +void PrintHex(uchar* buffer, int cnt); +void PrintChars(uchar* buffer, int cnt); +void PrintSerialNum(uchar* buffer); + +// external functions defined in crcutil.c +void setcrc16(int portnum, ushort reset); +ushort docrc16(int portnum, ushort cdata); +void setcrc8(int portnum, uchar reset); +uchar docrc8(int portnum, uchar x); + +#endif //OWNET_H diff --git a/tools_cmd/rwOW/tmexlnk.c b/tools_cmd/rwOW/tmexlnk.c index 7555714..7fa329a 100644 --- a/tools_cmd/rwOW/tmexlnk.c +++ b/tools_cmd/rwOW/tmexlnk.c @@ -1,368 +1,368 @@ -//--------------------------------------------------------------------------- -// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES -// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// Except as contained in this notice, the name of Dallas Semiconductor -// shall not be used except as stated in the Dallas Semiconductor -// Branding Policy. -//--------------------------------------------------------------------------- -// -// TMEXLnk.C - Link module to call on TMEX low-level functions to -// excersize the general 1-Wire Net functions. -// (Requires TMEX 3.11 or newer) -// -// Version: 3.00 -// -// History: 1.00 -> 1.01 Return values in owLevel corrected. -// Added function msDelay. -// 1.02 -> 1.03 Add msGettick, always return owLevel success -// to hide adapters (DS9097E) that do not have -// power delivery capabilities. -// 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for -// multiple ports. -// 2.10 -> 3.00 Added owReadBitPower and owWriteBytePower - -#include "ownet.h" -#include - -// external TMEX variables -extern long SessionHandle[MAX_PORTNUM]; -extern uchar StateBuffer[MAX_PORTNUM][5120]; -extern short far pascal TMTouchByte(long, short); -extern short far pascal TMTouchReset(long); -extern short far pascal TMTouchBit(long, short); -extern short far pascal TMProgramPulse(long); -extern short far pascal TMOneWireCom(long, short, short); -extern short far pascal TMOneWireLevel(long, short, short, short); - -// globals -SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE = FALSE; // for compatibility purposes - -//-------------------------------------------------------------------------- -// Reset all of the devices on the 1-Wire Net and return the result. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// -// Returns: TRUE(1): presense pulse(s) detected, device(s) reset -// FALSE(0): no presense pulses detected -// -SMALLINT owTouchReset(int portnum) -{ - int result; - - // Assume valid Session - result = TMTouchReset(SessionHandle[portnum]); - - // success if the normal or alarm presence - if ((result == 1) || (result == 2)) - return TRUE; - else - return FALSE; -} - - -//-------------------------------------------------------------------------- -// Send 1 bit of communication to the 1-Wire Net and return the -// result 1 bit read from the 1-Wire Net. The parameter 'sendbit' -// least significant bit is used and the least significant bit -// of the result is the return bit. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// 'sendbit' - the least significant bit is the bit to send -// -// Returns: 0: 0 bit read from sendbit -// 1: 1 bit read from sendbit -// -SMALLINT owTouchBit(int portnum, SMALLINT sendbit) -{ - // Assume valid Session - return TMTouchBit(SessionHandle[portnum],(short)sendbit); -} - -//-------------------------------------------------------------------------- -// Send 8 bits of communication to the 1-Wire Net and verify that the -// 8 bits read from the 1-Wire Net is the same (write operation). -// The parameter 'sendbyte' least significant 8 bits are used. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// 'sendbyte' - 8 bits to send (least significant byte) -// -// Returns: TRUE: bytes written and echo was the same -// FALSE: echo was not the same -// -SMALLINT owTouchByte(int portnum, SMALLINT sendbyte) -{ - // Assume valid Session - return TMTouchByte(SessionHandle[portnum],(short)sendbyte); -} - -//-------------------------------------------------------------------------- -// Send 8 bits of communication to the MicroLAN and verify that the -// 8 bits read from the MicroLAN is the same (write operation). -// The parameter 'sendbyte' least significant 8 bits are used. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// 'sendbyte' - 8 bits to send (least significant byte) -// -// Returns: TRUE: bytes written and echo was the same -// FALSE: echo was not the same -// -SMALLINT owWriteByte(int portnum, SMALLINT sendbyte) -{ - return (owTouchByte(portnum,sendbyte) == sendbyte) ? TRUE : FALSE; -} - -//-------------------------------------------------------------------------- -// Send 8 bits of read communication to the 1-Wire Net and and return the -// result 8 bits read from the 1-Wire Net. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// -// Returns: TRUE: 8 bytes read from 1-Wire Net -// FALSE: the 8 bytes were not read -// -SMALLINT owReadByte(int portnum) -{ - return owTouchByte(portnum,0xFF); -} - -//-------------------------------------------------------------------------- -// Set the 1-Wire Net communucation speed. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// 'new_speed' - new speed defined as -// MODE_NORMAL 0x00 -// MODE_OVERDRIVE 0x01 -// -// Returns: current 1-Wire Net speed -// -SMALLINT owSpeed(int portnum, SMALLINT new_speed) -{ - return TMOneWireCom(SessionHandle[portnum],0,(short)new_speed); -} - -//-------------------------------------------------------------------------- -// Set the 1-Wire Net line level. The values for new_level are -// as follows: -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// 'new_level' - new level defined as -// MODE_NORMAL 0x00 -// MODE_STRONG5 0x02 -// MODE_PROGRAM 0x04 -// MODE_BREAK 0x08 (not supported) -// -// Returns: current 1-Wire Net level -// -SMALLINT owLevel(int portnum, SMALLINT new_level) -{ - int rslt; - int docheck = FALSE; - - // check for DS2480 bug - if (((SessionHandle[portnum] & 0x0F0) == 0x050) && - (TMOneWireLevel(SessionHandle[portnum],1,0,0) == 1)) - docheck = TRUE; - - switch (new_level) - { - case MODE_NORMAL: - rslt = TMOneWireLevel(SessionHandle[portnum],0,0,0); - // test code for DS2480 bug - if (docheck) - TMTouchBit(SessionHandle[portnum],1); - break; - case MODE_STRONG5: - rslt = TMOneWireLevel(SessionHandle[portnum],0,1,0); - break; - case MODE_PROGRAM: - rslt = TMOneWireLevel(SessionHandle[portnum],0,3,0); - break; - case MODE_BREAK: - rslt = TMOneWireLevel(SessionHandle[portnum],0,2,0); - break; - default: - rslt = 0; - } - - // Assume TMEX can do it so always return NewLevel - return new_level; -} - -//-------------------------------------------------------------------------- -// This procedure creates a fixed 480 microseconds 12 volt pulse -// on the 1-Wire Net for programming EPROM iButtons. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// -// Returns: TRUE successful -// FALSE program voltage not available -// -SMALLINT owProgramPulse(int portnum) -{ - return TMProgramPulse(SessionHandle[portnum]); -} - -//-------------------------------------------------------------------------- -// Description: -// Delay for at least 'len' ms -// -void msDelay(int len) -{ - Sleep(len); -} - -//-------------------------------------------------------------------------- -// Get the current millisecond tick count. Does not have to represent -// an actual time, it just needs to be an incrementing timer. -// -long msGettick(void) -{ - return GetTickCount(); -} - -//-------------------------------------------------------------------------- -// Send 8 bits of communication to the 1-Wire Net and verify that the -// 8 bits read from the 1-Wire Net is the same (write operation). -// The parameter 'sendbyte' least significant 8 bits are used. After the -// 8 bits are sent change the level of the 1-Wire net. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to -// OpenCOM to indicate the port number. -// 'sendbyte' - 8 bits to send (least significant byte) -// -// Returns: TRUE: bytes written and echo was the same -// FALSE: echo was not the same -// -SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte) -{ - // prime for power delivery after byte - TMOneWireLevel(SessionHandle[portnum],0,1,2); - - // send the byte and start strong pullup - if(TMTouchByte(SessionHandle[portnum],(short)sendbyte) != sendbyte) - { - TMOneWireLevel(SessionHandle[portnum],0,0,0); - return FALSE; - } - - return TRUE; -} - -//-------------------------------------------------------------------------- -// Read 8 bits of communication to the 1-Wire Net and verify that the -// 8 bits read from the 1-Wire Net is the same (write operation). -// The parameter 'sendbyte' least significant 8 bits are used. After the -// 8 bits are read change the level of the 1-Wire net. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to -// OpenCOM to indicate the port number. -// 'sendbyte' - 8 bits to send (least significant byte) -// -// Returns: TRUE: bytes written and echo was the same -// FALSE: echo was not the same -// -SMALLINT owReadBytePower(int portnum) -{ - SMALLINT sendbyte = 0xFF; - - // prime for power delivery after byte - TMOneWireLevel(SessionHandle[portnum],0,1,2); - - // send the byte and start strong pullup - return TMTouchByte(SessionHandle[portnum],(short)sendbyte); -} - -//-------------------------------------------------------------------------- -// Send 1 bit of communication to the 1-Wire Net and verify that the -// response matches the 'applyPowerResponse' bit and apply power delivery -// to the 1-Wire net. Note that some implementations may apply the power -// first and then turn it off if the response is incorrect. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to -// OpenCOM to indicate the port number. -// 'applyPowerResponse' - 1 bit response to check, if correct then start -// power delivery -// -// Returns: TRUE: bit written and response correct, strong pullup now on -// FALSE: response incorrect -// -SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse) -{ - // prime for power delivery after bit - TMOneWireLevel(SessionHandle[portnum],0,1,1); - - // send the byte and start strong pullup - if(TMTouchBit(SessionHandle[portnum],0x01) != applyPowerResponse) - { - TMOneWireLevel(SessionHandle[portnum],0,0,0); - return FALSE; - } - - return TRUE; -} - -//-------------------------------------------------------------------------- -// This procedure indicates wether the adapter can deliver power. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to -// OpenCOM to indicate the port number. -// -// Returns: TRUE because all userial adapters have over drive. -// -SMALLINT owHasPowerDelivery(int portnum) -{ - return TRUE; -} - -//-------------------------------------------------------------------------- -// This procedure indicates wether the adapter can deliver power. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to -// OpenCOM to indicate the port number. -// -// Returns: TRUE because all userial adapters have over drive. -// -SMALLINT owHasOverDrive(int portnum) -{ - return TRUE; -} - -//-------------------------------------------------------------------------- -// This procedure creates a fixed 480 microseconds 12 volt pulse -// on the 1-Wire Net for programming EPROM iButtons. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to -// OpenCOM to indicate the port number. -// -// Returns: TRUE program volatage available -// FALSE program voltage not available -SMALLINT owHasProgramPulse(int portnum) -{ - return TMProgramPulse(SessionHandle[portnum]); +//--------------------------------------------------------------------------- +// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name of Dallas Semiconductor +// shall not be used except as stated in the Dallas Semiconductor +// Branding Policy. +//--------------------------------------------------------------------------- +// +// TMEXLnk.C - Link module to call on TMEX low-level functions to +// excersize the general 1-Wire Net functions. +// (Requires TMEX 3.11 or newer) +// +// Version: 3.00 +// +// History: 1.00 -> 1.01 Return values in owLevel corrected. +// Added function msDelay. +// 1.02 -> 1.03 Add msGettick, always return owLevel success +// to hide adapters (DS9097E) that do not have +// power delivery capabilities. +// 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for +// multiple ports. +// 2.10 -> 3.00 Added owReadBitPower and owWriteBytePower + +#include "ownet.h" +#include + +// external TMEX variables +extern long SessionHandle[MAX_PORTNUM]; +extern uchar StateBuffer[MAX_PORTNUM][5120]; +extern short far pascal TMTouchByte(long, short); +extern short far pascal TMTouchReset(long); +extern short far pascal TMTouchBit(long, short); +extern short far pascal TMProgramPulse(long); +extern short far pascal TMOneWireCom(long, short, short); +extern short far pascal TMOneWireLevel(long, short, short, short); + +// globals +SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE = FALSE; // for compatibility purposes + +//-------------------------------------------------------------------------- +// Reset all of the devices on the 1-Wire Net and return the result. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// +// Returns: TRUE(1): presense pulse(s) detected, device(s) reset +// FALSE(0): no presense pulses detected +// +SMALLINT owTouchReset(int portnum) +{ + int result; + + // Assume valid Session + result = TMTouchReset(SessionHandle[portnum]); + + // success if the normal or alarm presence + if ((result == 1) || (result == 2)) + return TRUE; + else + return FALSE; +} + + +//-------------------------------------------------------------------------- +// Send 1 bit of communication to the 1-Wire Net and return the +// result 1 bit read from the 1-Wire Net. The parameter 'sendbit' +// least significant bit is used and the least significant bit +// of the result is the return bit. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// 'sendbit' - the least significant bit is the bit to send +// +// Returns: 0: 0 bit read from sendbit +// 1: 1 bit read from sendbit +// +SMALLINT owTouchBit(int portnum, SMALLINT sendbit) +{ + // Assume valid Session + return TMTouchBit(SessionHandle[portnum],(short)sendbit); +} + +//-------------------------------------------------------------------------- +// Send 8 bits of communication to the 1-Wire Net and verify that the +// 8 bits read from the 1-Wire Net is the same (write operation). +// The parameter 'sendbyte' least significant 8 bits are used. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// 'sendbyte' - 8 bits to send (least significant byte) +// +// Returns: TRUE: bytes written and echo was the same +// FALSE: echo was not the same +// +SMALLINT owTouchByte(int portnum, SMALLINT sendbyte) +{ + // Assume valid Session + return TMTouchByte(SessionHandle[portnum],(short)sendbyte); +} + +//-------------------------------------------------------------------------- +// Send 8 bits of communication to the MicroLAN and verify that the +// 8 bits read from the MicroLAN is the same (write operation). +// The parameter 'sendbyte' least significant 8 bits are used. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// 'sendbyte' - 8 bits to send (least significant byte) +// +// Returns: TRUE: bytes written and echo was the same +// FALSE: echo was not the same +// +SMALLINT owWriteByte(int portnum, SMALLINT sendbyte) +{ + return (owTouchByte(portnum,sendbyte) == sendbyte) ? TRUE : FALSE; +} + +//-------------------------------------------------------------------------- +// Send 8 bits of read communication to the 1-Wire Net and and return the +// result 8 bits read from the 1-Wire Net. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// +// Returns: TRUE: 8 bytes read from 1-Wire Net +// FALSE: the 8 bytes were not read +// +SMALLINT owReadByte(int portnum) +{ + return owTouchByte(portnum,0xFF); +} + +//-------------------------------------------------------------------------- +// Set the 1-Wire Net communucation speed. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// 'new_speed' - new speed defined as +// MODE_NORMAL 0x00 +// MODE_OVERDRIVE 0x01 +// +// Returns: current 1-Wire Net speed +// +SMALLINT owSpeed(int portnum, SMALLINT new_speed) +{ + return TMOneWireCom(SessionHandle[portnum],0,(short)new_speed); +} + +//-------------------------------------------------------------------------- +// Set the 1-Wire Net line level. The values for new_level are +// as follows: +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// 'new_level' - new level defined as +// MODE_NORMAL 0x00 +// MODE_STRONG5 0x02 +// MODE_PROGRAM 0x04 +// MODE_BREAK 0x08 (not supported) +// +// Returns: current 1-Wire Net level +// +SMALLINT owLevel(int portnum, SMALLINT new_level) +{ + int rslt; + int docheck = FALSE; + + // check for DS2480 bug + if (((SessionHandle[portnum] & 0x0F0) == 0x050) && + (TMOneWireLevel(SessionHandle[portnum],1,0,0) == 1)) + docheck = TRUE; + + switch (new_level) + { + case MODE_NORMAL: + rslt = TMOneWireLevel(SessionHandle[portnum],0,0,0); + // test code for DS2480 bug + if (docheck) + TMTouchBit(SessionHandle[portnum],1); + break; + case MODE_STRONG5: + rslt = TMOneWireLevel(SessionHandle[portnum],0,1,0); + break; + case MODE_PROGRAM: + rslt = TMOneWireLevel(SessionHandle[portnum],0,3,0); + break; + case MODE_BREAK: + rslt = TMOneWireLevel(SessionHandle[portnum],0,2,0); + break; + default: + rslt = 0; + } + + // Assume TMEX can do it so always return NewLevel + return new_level; +} + +//-------------------------------------------------------------------------- +// This procedure creates a fixed 480 microseconds 12 volt pulse +// on the 1-Wire Net for programming EPROM iButtons. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// +// Returns: TRUE successful +// FALSE program voltage not available +// +SMALLINT owProgramPulse(int portnum) +{ + return TMProgramPulse(SessionHandle[portnum]); +} + +//-------------------------------------------------------------------------- +// Description: +// Delay for at least 'len' ms +// +void msDelay(int len) +{ + Sleep(len); +} + +//-------------------------------------------------------------------------- +// Get the current millisecond tick count. Does not have to represent +// an actual time, it just needs to be an incrementing timer. +// +long msGettick(void) +{ + return GetTickCount(); +} + +//-------------------------------------------------------------------------- +// Send 8 bits of communication to the 1-Wire Net and verify that the +// 8 bits read from the 1-Wire Net is the same (write operation). +// The parameter 'sendbyte' least significant 8 bits are used. After the +// 8 bits are sent change the level of the 1-Wire net. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to +// OpenCOM to indicate the port number. +// 'sendbyte' - 8 bits to send (least significant byte) +// +// Returns: TRUE: bytes written and echo was the same +// FALSE: echo was not the same +// +SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte) +{ + // prime for power delivery after byte + TMOneWireLevel(SessionHandle[portnum],0,1,2); + + // send the byte and start strong pullup + if(TMTouchByte(SessionHandle[portnum],(short)sendbyte) != sendbyte) + { + TMOneWireLevel(SessionHandle[portnum],0,0,0); + return FALSE; + } + + return TRUE; +} + +//-------------------------------------------------------------------------- +// Read 8 bits of communication to the 1-Wire Net and verify that the +// 8 bits read from the 1-Wire Net is the same (write operation). +// The parameter 'sendbyte' least significant 8 bits are used. After the +// 8 bits are read change the level of the 1-Wire net. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to +// OpenCOM to indicate the port number. +// 'sendbyte' - 8 bits to send (least significant byte) +// +// Returns: TRUE: bytes written and echo was the same +// FALSE: echo was not the same +// +SMALLINT owReadBytePower(int portnum) +{ + SMALLINT sendbyte = 0xFF; + + // prime for power delivery after byte + TMOneWireLevel(SessionHandle[portnum],0,1,2); + + // send the byte and start strong pullup + return TMTouchByte(SessionHandle[portnum],(short)sendbyte); +} + +//-------------------------------------------------------------------------- +// Send 1 bit of communication to the 1-Wire Net and verify that the +// response matches the 'applyPowerResponse' bit and apply power delivery +// to the 1-Wire net. Note that some implementations may apply the power +// first and then turn it off if the response is incorrect. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to +// OpenCOM to indicate the port number. +// 'applyPowerResponse' - 1 bit response to check, if correct then start +// power delivery +// +// Returns: TRUE: bit written and response correct, strong pullup now on +// FALSE: response incorrect +// +SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse) +{ + // prime for power delivery after bit + TMOneWireLevel(SessionHandle[portnum],0,1,1); + + // send the byte and start strong pullup + if(TMTouchBit(SessionHandle[portnum],0x01) != applyPowerResponse) + { + TMOneWireLevel(SessionHandle[portnum],0,0,0); + return FALSE; + } + + return TRUE; +} + +//-------------------------------------------------------------------------- +// This procedure indicates wether the adapter can deliver power. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to +// OpenCOM to indicate the port number. +// +// Returns: TRUE because all userial adapters have over drive. +// +SMALLINT owHasPowerDelivery(int portnum) +{ + return TRUE; +} + +//-------------------------------------------------------------------------- +// This procedure indicates wether the adapter can deliver power. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to +// OpenCOM to indicate the port number. +// +// Returns: TRUE because all userial adapters have over drive. +// +SMALLINT owHasOverDrive(int portnum) +{ + return TRUE; +} + +//-------------------------------------------------------------------------- +// This procedure creates a fixed 480 microseconds 12 volt pulse +// on the 1-Wire Net for programming EPROM iButtons. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to +// OpenCOM to indicate the port number. +// +// Returns: TRUE program volatage available +// FALSE program voltage not available +SMALLINT owHasProgramPulse(int portnum) +{ + return TMProgramPulse(SessionHandle[portnum]); } \ No newline at end of file diff --git a/tools_cmd/rwOW/tmexnet.c b/tools_cmd/rwOW/tmexnet.c index 5f328c7..3f9b77d 100644 --- a/tools_cmd/rwOW/tmexnet.c +++ b/tools_cmd/rwOW/tmexnet.c @@ -1,249 +1,249 @@ -//--------------------------------------------------------------------------- -// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES -// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// Except as contained in this notice, the name of Dallas Semiconductor -// shall not be used except as stated in the Dallas Semiconductor -// Branding Policy. -//--------------------------------------------------------------------------- -// -// tmexnet.C - Wrapper class to hook 1-Wire Public Domain API to TMEX API -// for network functions. -// -// Version: 3.00 -// -// - -#include "ownet.h" -#include - -uchar StateBuffer[MAX_PORTNUM][5120]; - -// external TMEX variables -extern long SessionHandle[MAX_PORTNUM]; -extern short far pascal TMSearch(long session_handle, void *start_buffer, - short ResetSearch, short PerformReset, - short SrchCmd); -extern short pascal TMFirst(long, void *); -extern short pascal TMNext(long, void *); -extern short pascal TMAccess(long, void *); -extern short pascal TMStrongAccess(long, void *); -extern short pascal TMStrongAlarmAccess(long, void *); -extern short pascal TMOverAccess(long, void *); -extern short pascal TMRom(long, void *, short *); -extern short pascal TMFirstAlarm(long, void *); -extern short pascal TMNextAlarm(long, void *); -extern short pascal TMFamilySearchSetup(long, void *, short); -extern short pascal TMSkipFamily(long, void *); -extern short pascal TMAutoOverDrive(long, void *, short); - - -//-------------------------------------------------------------------------- -// The 'owFirst' finds the first device on the 1-Wire Net This function -// contains one parameter 'alarm_only'. When -// 'alarm_only' is TRUE (1) the find alarm command 0xEC is -// sent instead of the normal search command 0xF0. -// Using the find alarm command 0xEC will limit the search to only -// 1-Wire devices that are in an 'alarm' state. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// 'do_reset' - TRUE (1) perform reset before search, FALSE (0) do not -// perform reset before search. -// 'alarm_only' - TRUE (1) the find alarm command 0xEC is -// sent instead of the normal search command 0xF0 -// -// Returns: TRUE (1) : when a 1-Wire device was found and it's -// Serial Number placed in the global SerialNum[portnum] -// FALSE (0): There are no devices on the 1-Wire Net. -// -SMALLINT owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only) -{ - return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 1, - (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1); -} - -//-------------------------------------------------------------------------- -// The 'owNext' function does a general search. This function -// continues from the previos search state. The search state -// can be reset by using the 'owFirst' function. -// This function contains one parameter 'alarm_only'. -// When 'alarm_only' is TRUE (1) the find alarm command -// 0xEC is sent instead of the normal search command 0xF0. -// Using the find alarm command 0xEC will limit the search to only -// 1-Wire devices that are in an 'alarm' state. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// 'do_reset' - TRUE (1) perform reset before search, FALSE (0) do not -// perform reset before search. -// 'alarm_only' - TRUE (1) the find alarm command 0xEC is -// sent instead of the normal search command 0xF0 -// -// Returns: TRUE (1) : when a 1-Wire device was found and it's -// Serial Number placed in the global SerialNum[portnum] -// FALSE (0): when no new device was found. Either the -// last search was the last device or there -// are no devices on the 1-Wire Net. -// -SMALLINT owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only) -{ - return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 0, - (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1); -} - -//-------------------------------------------------------------------------- -// The 'owSerialNum' function either reads or sets the SerialNum buffer -// that is used in the search functions 'owFirst' and 'owNext'. -// This function contains two parameters, 'serialnum_buf' is a pointer -// to a buffer provided by the caller. 'serialnum_buf' should point to -// an array of 8 unsigned chars. The second parameter is a flag called -// 'do_read' that is TRUE (1) if the operation is to read and FALSE -// (0) if the operation is to set the internal SerialNum buffer from -// the data in the provided buffer. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// 'serialnum_buf' - buffer to that contains the serial number to set -// when do_read = FALSE (0) and buffer to get the serial -// number when do_read = TRUE (1). -// 'do_read' - flag to indicate reading (1) or setting (0) the current -// serial number. -// -void owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read) -{ - short ROM[8],i; - - // check if reading or writing - if (do_read) - { - ROM[0] = 0; - } - else - { - for (i = 0; i < 8; i++) - ROM[i] = serialnum_buf[i]; - } - - // call TMEX to read or set the current device - TMRom(SessionHandle[portnum], StateBuffer[portnum], ROM); - - // place in 'serialnum_buf' - if (do_read) - { - for (i = 0; i < 8; i++) - serialnum_buf[i] = (uchar)ROM[i]; - } -} - -//-------------------------------------------------------------------------- -// Setup the search algorithm to find a certain family of devices -// the next time a search function is called 'owNext'. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to -// OpenCOM to indicate the port number. -// 'search_family' - family code type to set the search algorithm to find -// next. -// -void owFamilySearchSetup(int portnum, SMALLINT search_family) -{ - TMFamilySearchSetup(SessionHandle[portnum], StateBuffer[portnum], - (short)search_family); -} - -//-------------------------------------------------------------------------- -// Set the current search state to skip the current family code. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// -void owSkipFamily(int portnum) -{ - TMSkipFamily(SessionHandle[portnum], StateBuffer[portnum]); -} - -//-------------------------------------------------------------------------- -// The 'owAccess' function resets the 1-Wire and sends a MATCH Serial -// Number command followed by the current SerialNum code. After this -// function is complete the 1-Wire device is ready to accept device-specific -// commands. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// -// Returns: TRUE (1) : reset indicates present and device is ready -// for commands. -// FALSE (0): reset does not indicate presence or echos 'writes' -// are not correct. -// -SMALLINT owAccess(int portnum) -{ - return (TMAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1); -} - -//---------------------------------------------------------------------- -// The function 'owVerify' verifies that the current device -// is in contact with the 1-Wire Net. -// Using the find alarm command 0xEC will verify that the device -// is in contact with the 1-Wire Net and is in an 'alarm' state. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// 'alarm_only' - TRUE (1) the find alarm command 0xEC -// is sent instead of the normal search -// command 0xF0. -// -// Returns: TRUE (1) : when the 1-Wire device was verified -// to be on the 1-Wire Net -// with alarm_only == FALSE -// or verified to be on the 1-Wire Net -// AND in an alarm state when -// alarm_only == TRUE. -// FALSE (0): the 1-Wire device was not on the -// 1-Wire Net or if alarm_only -// == TRUE, the device may be on the -// 1-Wire Net but in a non-alarm state. -// -SMALLINT owVerify(int portnum, SMALLINT alarm_only) -{ - if (alarm_only) - return (TMStrongAlarmAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1); - else - return (TMStrongAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1); -} - -//---------------------------------------------------------------------- -// Perform a overdrive MATCH command to select the 1-Wire device with -// the address in the ID data register. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// -// Returns: TRUE: If the device is present on the 1-Wire Net and -// can do overdrive then the device is selected. -// FALSE: Device is not present or not capable of overdrive. -// -// *Note: This function could be converted to send DS2480 -// commands in one packet. -// -SMALLINT owOverdriveAccess(int portnum) -{ - return (TMOverAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1); -} +//--------------------------------------------------------------------------- +// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name of Dallas Semiconductor +// shall not be used except as stated in the Dallas Semiconductor +// Branding Policy. +//--------------------------------------------------------------------------- +// +// tmexnet.C - Wrapper class to hook 1-Wire Public Domain API to TMEX API +// for network functions. +// +// Version: 3.00 +// +// + +#include "ownet.h" +#include + +uchar StateBuffer[MAX_PORTNUM][5120]; + +// external TMEX variables +extern long SessionHandle[MAX_PORTNUM]; +extern short far pascal TMSearch(long session_handle, void *start_buffer, + short ResetSearch, short PerformReset, + short SrchCmd); +extern short pascal TMFirst(long, void *); +extern short pascal TMNext(long, void *); +extern short pascal TMAccess(long, void *); +extern short pascal TMStrongAccess(long, void *); +extern short pascal TMStrongAlarmAccess(long, void *); +extern short pascal TMOverAccess(long, void *); +extern short pascal TMRom(long, void *, short *); +extern short pascal TMFirstAlarm(long, void *); +extern short pascal TMNextAlarm(long, void *); +extern short pascal TMFamilySearchSetup(long, void *, short); +extern short pascal TMSkipFamily(long, void *); +extern short pascal TMAutoOverDrive(long, void *, short); + + +//-------------------------------------------------------------------------- +// The 'owFirst' finds the first device on the 1-Wire Net This function +// contains one parameter 'alarm_only'. When +// 'alarm_only' is TRUE (1) the find alarm command 0xEC is +// sent instead of the normal search command 0xF0. +// Using the find alarm command 0xEC will limit the search to only +// 1-Wire devices that are in an 'alarm' state. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// 'do_reset' - TRUE (1) perform reset before search, FALSE (0) do not +// perform reset before search. +// 'alarm_only' - TRUE (1) the find alarm command 0xEC is +// sent instead of the normal search command 0xF0 +// +// Returns: TRUE (1) : when a 1-Wire device was found and it's +// Serial Number placed in the global SerialNum[portnum] +// FALSE (0): There are no devices on the 1-Wire Net. +// +SMALLINT owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only) +{ + return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 1, + (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1); +} + +//-------------------------------------------------------------------------- +// The 'owNext' function does a general search. This function +// continues from the previos search state. The search state +// can be reset by using the 'owFirst' function. +// This function contains one parameter 'alarm_only'. +// When 'alarm_only' is TRUE (1) the find alarm command +// 0xEC is sent instead of the normal search command 0xF0. +// Using the find alarm command 0xEC will limit the search to only +// 1-Wire devices that are in an 'alarm' state. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// 'do_reset' - TRUE (1) perform reset before search, FALSE (0) do not +// perform reset before search. +// 'alarm_only' - TRUE (1) the find alarm command 0xEC is +// sent instead of the normal search command 0xF0 +// +// Returns: TRUE (1) : when a 1-Wire device was found and it's +// Serial Number placed in the global SerialNum[portnum] +// FALSE (0): when no new device was found. Either the +// last search was the last device or there +// are no devices on the 1-Wire Net. +// +SMALLINT owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only) +{ + return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 0, + (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1); +} + +//-------------------------------------------------------------------------- +// The 'owSerialNum' function either reads or sets the SerialNum buffer +// that is used in the search functions 'owFirst' and 'owNext'. +// This function contains two parameters, 'serialnum_buf' is a pointer +// to a buffer provided by the caller. 'serialnum_buf' should point to +// an array of 8 unsigned chars. The second parameter is a flag called +// 'do_read' that is TRUE (1) if the operation is to read and FALSE +// (0) if the operation is to set the internal SerialNum buffer from +// the data in the provided buffer. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// 'serialnum_buf' - buffer to that contains the serial number to set +// when do_read = FALSE (0) and buffer to get the serial +// number when do_read = TRUE (1). +// 'do_read' - flag to indicate reading (1) or setting (0) the current +// serial number. +// +void owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read) +{ + short ROM[8],i; + + // check if reading or writing + if (do_read) + { + ROM[0] = 0; + } + else + { + for (i = 0; i < 8; i++) + ROM[i] = serialnum_buf[i]; + } + + // call TMEX to read or set the current device + TMRom(SessionHandle[portnum], StateBuffer[portnum], ROM); + + // place in 'serialnum_buf' + if (do_read) + { + for (i = 0; i < 8; i++) + serialnum_buf[i] = (uchar)ROM[i]; + } +} + +//-------------------------------------------------------------------------- +// Setup the search algorithm to find a certain family of devices +// the next time a search function is called 'owNext'. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to +// OpenCOM to indicate the port number. +// 'search_family' - family code type to set the search algorithm to find +// next. +// +void owFamilySearchSetup(int portnum, SMALLINT search_family) +{ + TMFamilySearchSetup(SessionHandle[portnum], StateBuffer[portnum], + (short)search_family); +} + +//-------------------------------------------------------------------------- +// Set the current search state to skip the current family code. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// +void owSkipFamily(int portnum) +{ + TMSkipFamily(SessionHandle[portnum], StateBuffer[portnum]); +} + +//-------------------------------------------------------------------------- +// The 'owAccess' function resets the 1-Wire and sends a MATCH Serial +// Number command followed by the current SerialNum code. After this +// function is complete the 1-Wire device is ready to accept device-specific +// commands. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// +// Returns: TRUE (1) : reset indicates present and device is ready +// for commands. +// FALSE (0): reset does not indicate presence or echos 'writes' +// are not correct. +// +SMALLINT owAccess(int portnum) +{ + return (TMAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1); +} + +//---------------------------------------------------------------------- +// The function 'owVerify' verifies that the current device +// is in contact with the 1-Wire Net. +// Using the find alarm command 0xEC will verify that the device +// is in contact with the 1-Wire Net and is in an 'alarm' state. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// 'alarm_only' - TRUE (1) the find alarm command 0xEC +// is sent instead of the normal search +// command 0xF0. +// +// Returns: TRUE (1) : when the 1-Wire device was verified +// to be on the 1-Wire Net +// with alarm_only == FALSE +// or verified to be on the 1-Wire Net +// AND in an alarm state when +// alarm_only == TRUE. +// FALSE (0): the 1-Wire device was not on the +// 1-Wire Net or if alarm_only +// == TRUE, the device may be on the +// 1-Wire Net but in a non-alarm state. +// +SMALLINT owVerify(int portnum, SMALLINT alarm_only) +{ + if (alarm_only) + return (TMStrongAlarmAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1); + else + return (TMStrongAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1); +} + +//---------------------------------------------------------------------- +// Perform a overdrive MATCH command to select the 1-Wire device with +// the address in the ID data register. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// +// Returns: TRUE: If the device is present on the 1-Wire Net and +// can do overdrive then the device is selected. +// FALSE: Device is not present or not capable of overdrive. +// +// *Note: This function could be converted to send DS2480 +// commands in one packet. +// +SMALLINT owOverdriveAccess(int portnum) +{ + return (TMOverAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1); +} diff --git a/tools_cmd/rwOW/tmexses.c b/tools_cmd/rwOW/tmexses.c index 793d650..fea8798 100644 --- a/tools_cmd/rwOW/tmexses.c +++ b/tools_cmd/rwOW/tmexses.c @@ -1,212 +1,212 @@ -//--------------------------------------------------------------------------- -// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES -// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// Except as contained in this notice, the name of Dallas Semiconductor -// shall not be used except as stated in the Dallas Semiconductor -// Branding Policy. -//--------------------------------------------------------------------------- -// -// owsestmx.c - Acquire and release a Session on the 1-Wire Net using TMEX. -// (Requires TMEX 3.11 or newer) -// -// Version: 2.01 -// -// History: 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for -// multiple ports. -// 2.00 -> 2.01 Added support for owError library. -// - -#include -#include -#include "ownet.h" - -// external function prototypes -extern long far pascal TMExtendedStartSession(short, short, void far *); -extern short far pascal TMEndSession(long); -extern short far pascal TMClose(long); -extern short far pascal TMSetup(long); -extern short far pascal TMReadDefaultPort(short far *, short far *); - -short PortNum=1,PortType=2; -long SessionHandle[MAX_PORTNUM]; -SMALLINT handle_init = FALSE; - -//--------------------------------------------------------------------------- -// Attempt to acquire a 1-Wire net using a com port and a DS2480 based -// adapter. -// -// 'port_zstr' - zero terminated port name. For this platform -// use format {port number, port type}. -// -// Returns: port number and -1 if not successful in setting up the port. -// -int owAcquireEx(char *port_zstr) -{ - int portnum; - int string_counter, counter, i, lenmax; - char portnum_str[15]; - char porttype_str[15]; - void *tmex_options = NULL; - - if(!handle_init) - { - for(i=0; i 12) - lenmax = 12; - string_counter = 1; - counter = 0; - do - { - portnum_str[counter] = port_zstr[string_counter]; - - counter++; - string_counter++; - } - while((port_zstr[string_counter] != ',') && (string_counter <= lenmax)); - - portnum_str[counter] = '\0'; - - string_counter++; - counter = 0; - - do - { - porttype_str[counter] = port_zstr[string_counter]; - - counter++; - string_counter++; - } - while((port_zstr[string_counter] != '}') && (string_counter <= lenmax)); - - porttype_str[counter] = '\0'; - - PortNum = atoi(portnum_str); - PortType = atoi(porttype_str); - } - - // open a session - SessionHandle[portnum] = TMExtendedStartSession(PortNum,PortType,tmex_options); - - // check the session handle - if (SessionHandle[portnum] <= 0) - { - OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED); - SessionHandle[portnum] = 0; - return -1; - } - - // setup the port - if (TMSetup(SessionHandle[portnum]) != 1) - { - TMClose(SessionHandle[portnum]); - TMEndSession(SessionHandle[portnum]); - OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED); - SessionHandle[portnum] = 0; - return -1; - } - - return portnum; -} - -//--------------------------------------------------------------------------- -// Attempt to acquire a 1-Wire net using a com port and a DS2480 based -// adapter. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// 'port_zstr' - zero terminated port name. For this platform -// use format COMX where X is the port number. -// -// Returns: TRUE - success, COM port opened -// -SMALLINT owAcquire(int portnum, char *port_zstr) -{ - int i; - - if(!handle_init) - { - for(i=0; i=0 && !SessionHandle[portnum], - OWERROR_PORTNUM_ERROR, FALSE ); - - // read the default PortNum and PortType - TMReadDefaultPort(&PortNum,&PortType); - - // convert the string in port_zstr to be the port number - PortNum = atoi(port_zstr); - - // open a session - SessionHandle[portnum] = TMExtendedStartSession(PortNum,PortType,NULL); - - // check the session handle - if (SessionHandle[portnum] <= 0) - { - OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED); - SessionHandle[portnum] = 0; - return FALSE; - } - - // setup the port - if (TMSetup(SessionHandle[portnum]) != 1) - { - TMClose(SessionHandle[portnum]); - TMEndSession(SessionHandle[portnum]); - OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED); - SessionHandle[portnum] = 0; - return FALSE; - } - - return TRUE; -} - -//--------------------------------------------------------------------------- -// Release the previously acquired a 1-Wire net. -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// -void owRelease(int portnum) -{ - TMClose(SessionHandle[portnum]); - TMEndSession(SessionHandle[portnum]); - SessionHandle[portnum] = 0; -} - +//--------------------------------------------------------------------------- +// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name of Dallas Semiconductor +// shall not be used except as stated in the Dallas Semiconductor +// Branding Policy. +//--------------------------------------------------------------------------- +// +// owsestmx.c - Acquire and release a Session on the 1-Wire Net using TMEX. +// (Requires TMEX 3.11 or newer) +// +// Version: 2.01 +// +// History: 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for +// multiple ports. +// 2.00 -> 2.01 Added support for owError library. +// + +#include +#include +#include "ownet.h" + +// external function prototypes +extern long far pascal TMExtendedStartSession(short, short, void far *); +extern short far pascal TMEndSession(long); +extern short far pascal TMClose(long); +extern short far pascal TMSetup(long); +extern short far pascal TMReadDefaultPort(short far *, short far *); + +short PortNum=1,PortType=2; +long SessionHandle[MAX_PORTNUM]; +SMALLINT handle_init = FALSE; + +//--------------------------------------------------------------------------- +// Attempt to acquire a 1-Wire net using a com port and a DS2480 based +// adapter. +// +// 'port_zstr' - zero terminated port name. For this platform +// use format {port number, port type}. +// +// Returns: port number and -1 if not successful in setting up the port. +// +int owAcquireEx(char *port_zstr) +{ + int portnum; + int string_counter, counter, i, lenmax; + char portnum_str[15]; + char porttype_str[15]; + void *tmex_options = NULL; + + if(!handle_init) + { + for(i=0; i 12) + lenmax = 12; + string_counter = 1; + counter = 0; + do + { + portnum_str[counter] = port_zstr[string_counter]; + + counter++; + string_counter++; + } + while((port_zstr[string_counter] != ',') && (string_counter <= lenmax)); + + portnum_str[counter] = '\0'; + + string_counter++; + counter = 0; + + do + { + porttype_str[counter] = port_zstr[string_counter]; + + counter++; + string_counter++; + } + while((port_zstr[string_counter] != '}') && (string_counter <= lenmax)); + + porttype_str[counter] = '\0'; + + PortNum = atoi(portnum_str); + PortType = atoi(porttype_str); + } + + // open a session + SessionHandle[portnum] = TMExtendedStartSession(PortNum,PortType,tmex_options); + + // check the session handle + if (SessionHandle[portnum] <= 0) + { + OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED); + SessionHandle[portnum] = 0; + return -1; + } + + // setup the port + if (TMSetup(SessionHandle[portnum]) != 1) + { + TMClose(SessionHandle[portnum]); + TMEndSession(SessionHandle[portnum]); + OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED); + SessionHandle[portnum] = 0; + return -1; + } + + return portnum; +} + +//--------------------------------------------------------------------------- +// Attempt to acquire a 1-Wire net using a com port and a DS2480 based +// adapter. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// 'port_zstr' - zero terminated port name. For this platform +// use format COMX where X is the port number. +// +// Returns: TRUE - success, COM port opened +// +SMALLINT owAcquire(int portnum, char *port_zstr) +{ + int i; + + if(!handle_init) + { + for(i=0; i=0 && !SessionHandle[portnum], + OWERROR_PORTNUM_ERROR, FALSE ); + + // read the default PortNum and PortType + TMReadDefaultPort(&PortNum,&PortType); + + // convert the string in port_zstr to be the port number + PortNum = atoi(port_zstr); + + // open a session + SessionHandle[portnum] = TMExtendedStartSession(PortNum,PortType,NULL); + + // check the session handle + if (SessionHandle[portnum] <= 0) + { + OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED); + SessionHandle[portnum] = 0; + return FALSE; + } + + // setup the port + if (TMSetup(SessionHandle[portnum]) != 1) + { + TMClose(SessionHandle[portnum]); + TMEndSession(SessionHandle[portnum]); + OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED); + SessionHandle[portnum] = 0; + return FALSE; + } + + return TRUE; +} + +//--------------------------------------------------------------------------- +// Release the previously acquired a 1-Wire net. +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// +void owRelease(int portnum) +{ + TMClose(SessionHandle[portnum]); + TMEndSession(SessionHandle[portnum]); + SessionHandle[portnum] = 0; +} + diff --git a/tools_cmd/rwOW/tmextran.c b/tools_cmd/rwOW/tmextran.c index 31d2cf7..4a4b926 100644 --- a/tools_cmd/rwOW/tmextran.c +++ b/tools_cmd/rwOW/tmextran.c @@ -1,199 +1,199 @@ -//--------------------------------------------------------------------------- -// Copyright (C) 1999 Dallas Semiconductor Corporation, All Rights Reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES -// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// Except as contained in this notice, the name of Dallas Semiconductor -// shall not be used except as stated in the Dallas Semiconductor -// Branding Policy. -//--------------------------------------------------------------------------- -// -// tmexnet.C - Wrapper class to hook 1-Wire Public Domain API to TMEX API -// for transport functions. -// -// Version: 3.00 -// - -#include "ownet.h" -#include - -// external TMEX variables -extern long SessionHandle[MAX_PORTNUM]; -extern short far pascal TMBlockIO(long, uchar *, short); -extern short far pascal TMBlockStream(long, uchar *, short); - -//-------------------------------------------------------------------------- -// The 'owBlock' transfers a block of data to and from the -// 1-Wire Net with an optional reset at the begining of communication. -// The result is returned in the same buffer. -// -// 'do_reset' - cause a owTouchReset to occure at the begining of -// communication TRUE(1) or not FALSE(0) -// 'tran_buf' - pointer to a block of unsigned -// chars of length 'TranferLength' that will be sent -// to the 1-Wire Net -// 'tran_len' - length in bytes to transfer -// Supported devices: all -// -// Returns: TRUE (1) : The optional reset returned a valid -// presence (do_reset == TRUE) or there -// was no reset required. -// FALSE (0): The reset did not return a valid prsence -// (do_reset == TRUE). -// -// The maximum tran_len is 64 -// -SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len) -{ - short rslt; - - // check for a block too big - if (tran_len > 192) - { - OWERROR(OWERROR_BLOCK_TOO_BIG); - return FALSE; - } - - // check if need to do a owTouchReset first - if (do_reset) - rslt = TMBlockIO(SessionHandle[portnum], tran_buf, (short)tran_len); - else - rslt = TMBlockStream(SessionHandle[portnum], tran_buf, (short)tran_len); - - return (rslt == tran_len); -} - -//-------------------------------------------------------------------------- -// Write a byte to an EPROM 1-Wire device. -// -// Supported devices: crc_type=0(CRC8) -// DS1982 -// crc_type=1(CRC16) -// DS1985, DS1986, DS2407 -// -// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to -// indicate the symbolic port number. -// 'write_byte' - byte to program -// 'addr' - address of byte to program -// 'write_cmd' - command used to write (0x0F reg mem, 0x55 status) -// 'crc_type' - CRC used (0 CRC8, 1 CRC16) -// 'do_access' - Flag to access device for each byte -// (0 skip access, 1 do the access) -// WARNING, only use do_access=0 if programing the NEXT -// byte immediatly after the previous byte. -// -// Returns: >=0 success, this is the resulting byte from the program -// effort -// -1 error, device not connected or program pulse voltage -// not available -// -SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd, - SMALLINT crc_type, SMALLINT do_access) -{ - ushort lastcrc16; - uchar lastcrc8; - - // optionally access the device - if (do_access) - { - if (!owAccess(portnum)) - { - OWERROR(OWERROR_ACCESS_FAILED); - return -1; - } - - // send the write command - if (!owWriteByte(portnum,write_cmd)) - { - OWERROR(OWERROR_WRITE_BYTE_FAILED); - return -1; - } - - // send the address - if (!owWriteByte(portnum,addr & 0xFF) || !owWriteByte(portnum,addr >> 8)) - { - OWERROR(OWERROR_WRITE_BYTE_FAILED); - return -1; - } - } - - // send the data to write - if (!owWriteByte(portnum,write_byte)) - { - OWERROR(OWERROR_WRITE_BYTE_FAILED); - return -1; - } - - // read the CRC - if (crc_type == 0) - { - // calculate CRC8 - if (do_access) - { - setcrc8(portnum,0); - docrc8(portnum,(uchar)write_cmd); - docrc8(portnum,(uchar)(addr & 0xFF)); - docrc8(portnum,(uchar)(addr >> 8)); - } - else - setcrc8(portnum,(uchar)(addr & 0xFF)); - - docrc8(portnum,(uchar)write_byte); - // read and calculate the read crc - lastcrc8 = docrc8(portnum,(uchar)owReadByte(portnum)); - // crc should now be 0x00 - if (lastcrc8 != 0) - { - OWERROR(OWERROR_CRC_FAILED); - return -1; - } - } - else - { - // CRC16 - if (do_access) - { - setcrc16(portnum,0); - docrc16(portnum,(ushort)write_cmd); - docrc16(portnum,(ushort)(addr & 0xFF)); - docrc16(portnum,(ushort)(addr >> 8)); - } - else - setcrc16(portnum,(ushort)addr); - docrc16(portnum,(ushort)write_byte); - // read and calculate the read crc - docrc16(portnum,(ushort)owReadByte(portnum)); - lastcrc16 = docrc16(portnum,(ushort)owReadByte(portnum)); - // crc should now be 0xB001 - if (lastcrc16 != 0xB001) - return -1; - } - - // send the program pulse - if (!owProgramPulse(portnum)) - { - OWERROR(OWERROR_PROGRAM_PULSE_FAILED); - return -1; - } - - // read back and return the resulting byte - return owReadByte(portnum); -} - - +//--------------------------------------------------------------------------- +// Copyright (C) 1999 Dallas Semiconductor Corporation, All Rights Reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name of Dallas Semiconductor +// shall not be used except as stated in the Dallas Semiconductor +// Branding Policy. +//--------------------------------------------------------------------------- +// +// tmexnet.C - Wrapper class to hook 1-Wire Public Domain API to TMEX API +// for transport functions. +// +// Version: 3.00 +// + +#include "ownet.h" +#include + +// external TMEX variables +extern long SessionHandle[MAX_PORTNUM]; +extern short far pascal TMBlockIO(long, uchar *, short); +extern short far pascal TMBlockStream(long, uchar *, short); + +//-------------------------------------------------------------------------- +// The 'owBlock' transfers a block of data to and from the +// 1-Wire Net with an optional reset at the begining of communication. +// The result is returned in the same buffer. +// +// 'do_reset' - cause a owTouchReset to occure at the begining of +// communication TRUE(1) or not FALSE(0) +// 'tran_buf' - pointer to a block of unsigned +// chars of length 'TranferLength' that will be sent +// to the 1-Wire Net +// 'tran_len' - length in bytes to transfer +// Supported devices: all +// +// Returns: TRUE (1) : The optional reset returned a valid +// presence (do_reset == TRUE) or there +// was no reset required. +// FALSE (0): The reset did not return a valid prsence +// (do_reset == TRUE). +// +// The maximum tran_len is 64 +// +SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len) +{ + short rslt; + + // check for a block too big + if (tran_len > 192) + { + OWERROR(OWERROR_BLOCK_TOO_BIG); + return FALSE; + } + + // check if need to do a owTouchReset first + if (do_reset) + rslt = TMBlockIO(SessionHandle[portnum], tran_buf, (short)tran_len); + else + rslt = TMBlockStream(SessionHandle[portnum], tran_buf, (short)tran_len); + + return (rslt == tran_len); +} + +//-------------------------------------------------------------------------- +// Write a byte to an EPROM 1-Wire device. +// +// Supported devices: crc_type=0(CRC8) +// DS1982 +// crc_type=1(CRC16) +// DS1985, DS1986, DS2407 +// +// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to +// indicate the symbolic port number. +// 'write_byte' - byte to program +// 'addr' - address of byte to program +// 'write_cmd' - command used to write (0x0F reg mem, 0x55 status) +// 'crc_type' - CRC used (0 CRC8, 1 CRC16) +// 'do_access' - Flag to access device for each byte +// (0 skip access, 1 do the access) +// WARNING, only use do_access=0 if programing the NEXT +// byte immediatly after the previous byte. +// +// Returns: >=0 success, this is the resulting byte from the program +// effort +// -1 error, device not connected or program pulse voltage +// not available +// +SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd, + SMALLINT crc_type, SMALLINT do_access) +{ + ushort lastcrc16; + uchar lastcrc8; + + // optionally access the device + if (do_access) + { + if (!owAccess(portnum)) + { + OWERROR(OWERROR_ACCESS_FAILED); + return -1; + } + + // send the write command + if (!owWriteByte(portnum,write_cmd)) + { + OWERROR(OWERROR_WRITE_BYTE_FAILED); + return -1; + } + + // send the address + if (!owWriteByte(portnum,addr & 0xFF) || !owWriteByte(portnum,addr >> 8)) + { + OWERROR(OWERROR_WRITE_BYTE_FAILED); + return -1; + } + } + + // send the data to write + if (!owWriteByte(portnum,write_byte)) + { + OWERROR(OWERROR_WRITE_BYTE_FAILED); + return -1; + } + + // read the CRC + if (crc_type == 0) + { + // calculate CRC8 + if (do_access) + { + setcrc8(portnum,0); + docrc8(portnum,(uchar)write_cmd); + docrc8(portnum,(uchar)(addr & 0xFF)); + docrc8(portnum,(uchar)(addr >> 8)); + } + else + setcrc8(portnum,(uchar)(addr & 0xFF)); + + docrc8(portnum,(uchar)write_byte); + // read and calculate the read crc + lastcrc8 = docrc8(portnum,(uchar)owReadByte(portnum)); + // crc should now be 0x00 + if (lastcrc8 != 0) + { + OWERROR(OWERROR_CRC_FAILED); + return -1; + } + } + else + { + // CRC16 + if (do_access) + { + setcrc16(portnum,0); + docrc16(portnum,(ushort)write_cmd); + docrc16(portnum,(ushort)(addr & 0xFF)); + docrc16(portnum,(ushort)(addr >> 8)); + } + else + setcrc16(portnum,(ushort)addr); + docrc16(portnum,(ushort)write_byte); + // read and calculate the read crc + docrc16(portnum,(ushort)owReadByte(portnum)); + lastcrc16 = docrc16(portnum,(ushort)owReadByte(portnum)); + // crc should now be 0xB001 + if (lastcrc16 != 0xB001) + return -1; + } + + // send the program pulse + if (!owProgramPulse(portnum)) + { + OWERROR(OWERROR_PROGRAM_PULSE_FAILED); + return -1; + } + + // read back and return the resulting byte + return owReadByte(portnum); +} + + -- 2.34.1