aboutsummaryrefslogtreecommitdiffstats
path: root/testhal
diff options
context:
space:
mode:
authorbarthess <barthess@yandex.ru>2016-05-30 23:07:09 +0300
committerbarthess <barthess@yandex.ru>2016-05-30 23:07:09 +0300
commit0fb26389ea53d4e2a4b0587886e6970f8c5ad102 (patch)
treeea0eb271ee122c4863d2195554cbd5ef795fbfc4 /testhal
parentbdb680652cc1f0ad223786b10196b6329127c804 (diff)
downloadChibiOS-Contrib-0fb26389ea53d4e2a4b0587886e6970f8c5ad102.tar.gz
ChibiOS-Contrib-0fb26389ea53d4e2a4b0587886e6970f8c5ad102.tar.bz2
ChibiOS-Contrib-0fb26389ea53d4e2a4b0587886e6970f8c5ad102.zip
1-wire. Data acqusition code in test application rewritten in more safe way
Diffstat (limited to 'testhal')
-rw-r--r--testhal/STM32/STM32F0xx/onewire/onewire_test.c6
-rw-r--r--testhal/STM32/STM32F1xx/onewire/onewire_test.c6
-rw-r--r--testhal/STM32/STM32F4xx/onewire/onewire_test.c6
3 files changed, 9 insertions, 9 deletions
diff --git a/testhal/STM32/STM32F0xx/onewire/onewire_test.c b/testhal/STM32/STM32F0xx/onewire/onewire_test.c
index 719420a..be20dbc 100644
--- a/testhal/STM32/STM32F0xx/onewire/onewire_test.c
+++ b/testhal/STM32/STM32F0xx/onewire/onewire_test.c
@@ -95,6 +95,7 @@ static void strong_pullup_release(void);
static uint8_t testbuf[12];
+/* stores 3 temperature values in millicelsius */
static int32_t temperature[3];
/*
@@ -242,9 +243,8 @@ void onewireTest(void) {
onewireRead(&OWD1, testbuf, 9);
osalDbgCheck(testbuf[8] == onewireCRC(testbuf, 8));
- tmp = 0;
- tmp |= (testbuf[1] << 8) | testbuf[0];
- temperature[i] = (tmp * 625) / 10;
+ memcpy(&tmp, &testbuf, 2);
+ temperature[i] = ((int32_t)tmp * 625) / 10;
}
}
else {
diff --git a/testhal/STM32/STM32F1xx/onewire/onewire_test.c b/testhal/STM32/STM32F1xx/onewire/onewire_test.c
index 719420a..be20dbc 100644
--- a/testhal/STM32/STM32F1xx/onewire/onewire_test.c
+++ b/testhal/STM32/STM32F1xx/onewire/onewire_test.c
@@ -95,6 +95,7 @@ static void strong_pullup_release(void);
static uint8_t testbuf[12];
+/* stores 3 temperature values in millicelsius */
static int32_t temperature[3];
/*
@@ -242,9 +243,8 @@ void onewireTest(void) {
onewireRead(&OWD1, testbuf, 9);
osalDbgCheck(testbuf[8] == onewireCRC(testbuf, 8));
- tmp = 0;
- tmp |= (testbuf[1] << 8) | testbuf[0];
- temperature[i] = (tmp * 625) / 10;
+ memcpy(&tmp, &testbuf, 2);
+ temperature[i] = ((int32_t)tmp * 625) / 10;
}
}
else {
diff --git a/testhal/STM32/STM32F4xx/onewire/onewire_test.c b/testhal/STM32/STM32F4xx/onewire/onewire_test.c
index 719420a..be20dbc 100644
--- a/testhal/STM32/STM32F4xx/onewire/onewire_test.c
+++ b/testhal/STM32/STM32F4xx/onewire/onewire_test.c
@@ -95,6 +95,7 @@ static void strong_pullup_release(void);
static uint8_t testbuf[12];
+/* stores 3 temperature values in millicelsius */
static int32_t temperature[3];
/*
@@ -242,9 +243,8 @@ void onewireTest(void) {
onewireRead(&OWD1, testbuf, 9);
osalDbgCheck(testbuf[8] == onewireCRC(testbuf, 8));
- tmp = 0;
- tmp |= (testbuf[1] << 8) | testbuf[0];
- temperature[i] = (tmp * 625) / 10;
+ memcpy(&tmp, &testbuf, 2);
+ temperature[i] = ((int32_t)tmp * 625) / 10;
}
}
else {