diff options
Diffstat (limited to 'src/tempmodule')
-rw-r--r-- | src/tempmodule/configuration.c | 33 | ||||
-rw-r--r-- | src/tempmodule/configuration.h | 28 | ||||
l--------- | src/tempmodule/datatypes.h | 1 | ||||
-rw-r--r-- | src/tempmodule/indicator.c | 15 | ||||
-rw-r--r-- | src/tempmodule/indicator.h | 3 | ||||
-rw-r--r-- | src/tempmodule/main.ino | 12 | ||||
-rw-r--r-- | src/tempmodule/meson.build | 5 | ||||
-rw-r--r-- | src/tempmodule/volatile_ops.c | 38 | ||||
-rw-r--r-- | src/tempmodule/volatile_ops.h | 36 |
9 files changed, 155 insertions, 16 deletions
diff --git a/src/tempmodule/configuration.c b/src/tempmodule/configuration.c new file mode 100644 index 0000000..76acde8 --- /dev/null +++ b/src/tempmodule/configuration.c @@ -0,0 +1,33 @@ +/* + * Hot Beverage Companion – configuration data + * + * Copyright (C) 2018 Gediminas Jakutis + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* We want the padding data to be detectible in the binary + * so we could find out the boundries of inner workings. + * We also want to detect byte order from the padding. + */ + +#include "datatypes.h" +volatile const struct configuration configuration = {{{ + PADDING_START, + "ssid", /* ssid */ + "password", /* password */ + {3430, 3330, 3230, 3130}, /* calibration */ + PADDING_END +}}}; diff --git a/src/tempmodule/configuration.h b/src/tempmodule/configuration.h new file mode 100644 index 0000000..dfe1264 --- /dev/null +++ b/src/tempmodule/configuration.h @@ -0,0 +1,28 @@ +/* + * Hot Beverage Companion – configuration data + * + * Copyright (C) 2018 Gediminas Jakutis + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef CONFIGURATION_INCLUDED +#define CONFIGURATION_INCLUDED + +#include "datatypes.h" + +extern volatile const struct configuration configuration; + +#endif /* CONFIGURATION_INCLUDED */ diff --git a/src/tempmodule/datatypes.h b/src/tempmodule/datatypes.h new file mode 120000 index 0000000..3a91016 --- /dev/null +++ b/src/tempmodule/datatypes.h @@ -0,0 +1 @@ +../../include/datatypes.h
\ No newline at end of file diff --git a/src/tempmodule/indicator.c b/src/tempmodule/indicator.c index 2968958..16df495 100644 --- a/src/tempmodule/indicator.c +++ b/src/tempmodule/indicator.c @@ -19,6 +19,8 @@ */ #include "indicator.h" +#include "configuration.h" +#include "volatile_ops.h" #define HIGH 1 #define LOW 0 @@ -38,8 +40,9 @@ static const unsigned int greenled = 4; /* D2 */ static const unsigned int blueled = 14; /* D5 */ static void indicator_set_state(unsigned int red, unsigned int green, unsigned int blue); +static void indicator_calibrate(int const * const calibration); -void indicator_init(int temp, unsigned int const * const calibration) +void indicator_init(int temp) { static const int default_calibration[] = {3430, 3330, 3230, 3130}; @@ -49,11 +52,7 @@ void indicator_init(int temp, unsigned int const * const calibration) state.current_temp = temp; - if (calibration) { - indicator_calibrate(calibration); - } else { - indicator_calibrate(default_calibration); - } + indicator_calibrate(configuration.calibration); } @@ -79,9 +78,9 @@ void indicator_update(const int temp, const unsigned int on) } } -void indicator_calibrate(int const * const calibration) +static void indicator_calibrate(int const * const calibration) { - memcpy(state.calibration, calibration, sizeof(state.calibration)); + volatile_memcpy(state.calibration, calibration, sizeof(state.calibration)); indicator_update(state.current_temp, 1); } diff --git a/src/tempmodule/indicator.h b/src/tempmodule/indicator.h index 99f4e1c..23ac87d 100644 --- a/src/tempmodule/indicator.h +++ b/src/tempmodule/indicator.h @@ -25,9 +25,8 @@ extern "C" { #endif -void indicator_init(int temp, unsigned int const * const calibration); +void indicator_init(int temp); void indicator_update(const int temp, const unsigned int on); -void indicator_calibrate(int const * const calibration); #ifdef __cplusplus } diff --git a/src/tempmodule/main.ino b/src/tempmodule/main.ino index 29ebc11..914b3ff 100644 --- a/src/tempmodule/main.ino +++ b/src/tempmodule/main.ino @@ -25,6 +25,8 @@ #include <limits.h> #include "indicator.h" #include "temperature.h" +#include "configuration.h" +#include "volatile_ops.h" #define arrsize(a) (sizeof(a)/sizeof(*a)) @@ -69,7 +71,7 @@ void setup(void) pinMode(thermistorvcc, OUTPUT); digitalWrite(thermistorvcc, LOW); - indicator_init(0, NULL); + indicator_init(0); WiFi.mode(WIFI_OFF); WiFi.forceSleepBegin(); @@ -90,12 +92,15 @@ void setup(void) void loop(void) { - static const char * const ssid = "SSID"; - static const char * const password = "password"; + char ssid[32]; + char password[32]; static unsigned int ticker = 0; short int data[3]; size_t i; + volatile_memcpy(ssid, configuration.ssid, sizeof(configuration.ssid)); + volatile_memcpy(password, configuration.password, sizeof(configuration.ssid)); + udp_init_packet(ip, port); if (wifidesired && !wifistate) { @@ -193,7 +198,6 @@ static void wifi_disconnect(void) wifiled_off(); Udp.stop(); WiFi.disconnect(1); - WiFi.mode(WIFI_OFF); WiFi.forceSleepBegin(); yield(); wifistate = 0; diff --git a/src/tempmodule/meson.build b/src/tempmodule/meson.build index e974884..b2c88b9 100644 --- a/src/tempmodule/meson.build +++ b/src/tempmodule/meson.build @@ -1,3 +1,4 @@ +fw_filename = 'fw.bin' if get_option('fwbuild') espmake = find_program('espmake') @@ -5,9 +6,9 @@ if get_option('fwbuild') fw_filenames = ['main.ino', 'indicator.c', 'temperature.c', 'indicator.h', 'temperature.h'] fw_sources = files(fw_filenames) fw = custom_target('fw', - output : 'fw.bin', + output : fw_filename, input : fw_sources, - command : [espmake, '-C', sourcedir, '&&', 'cp', '/tmp/mkESP/main_d1_mini/main.bin', '@OUTDIR@/fw.bin']) + command : [espmake, '-C', sourcedir, '&&', 'cp', '/tmp/mkESP/main_d1_mini/main.bin', '@OUTDIR@/' + fw_filename], install : true, install_dir : resource_dir) if get_option('fwflash') esptool = find_program('esptool.py') diff --git a/src/tempmodule/volatile_ops.c b/src/tempmodule/volatile_ops.c new file mode 100644 index 0000000..432955a --- /dev/null +++ b/src/tempmodule/volatile_ops.c @@ -0,0 +1,38 @@ +/* + * Hot Beverage Companion – volatile data ops + * + * Copyright (C) 2018 Gediminas Jakutis + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "volatile_ops.h" + +void *volatile_memcpy(void *dest, volatile const void * const src, size_t n) +{ + char *d; + volatile const char *s; + + if (!n) { + return dest; + } + + d = dest; + s = src; + + while (n--) { + d[n] = s[n]; + } +} diff --git a/src/tempmodule/volatile_ops.h b/src/tempmodule/volatile_ops.h new file mode 100644 index 0000000..7a165b9 --- /dev/null +++ b/src/tempmodule/volatile_ops.h @@ -0,0 +1,36 @@ +/* + * Hot Beverage Companion – volatile data ops + * + * Copyright (C) 2018 Gediminas Jakutis + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef VOLATILE_OPS_INCLUDED +#define VOLATILE_OPS_INCLUDED + +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif + +void *volatile_memcpy(void *dest, volatile const void * const src, size_t n); + +#ifdef __cplusplus +} +#endif + +#endif /* VOLATILE_OPS_INCLUDED */ |