aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbarthess <barthess@yandex.ru>2016-05-31 00:04:19 +0300
committerbarthess <barthess@yandex.ru>2016-05-31 00:04:19 +0300
commitb10e42340675dfb915be881b45053aeccf1dcbe4 (patch)
tree513acfeb99700d71100b9b9b10b5d2e996d1c872
parent0fb26389ea53d4e2a4b0587886e6970f8c5ad102 (diff)
downloadChibiOS-Contrib-b10e42340675dfb915be881b45053aeccf1dcbe4.tar.gz
ChibiOS-Contrib-b10e42340675dfb915be881b45053aeccf1dcbe4.tar.bz2
ChibiOS-Contrib-b10e42340675dfb915be881b45053aeccf1dcbe4.zip
1-wire improvements.
1) Functions reading bit from PAL now return ioline_t type. 2) Functions that handle acquired buffer with acquired bits now use uint8_t type because it corresponds to buffer type. 3) Cryptic bit shifting in bit storage functions replaced by dividion operations because all modern compilers perfectly optimise such operations.
-rw-r--r--os/hal/include/hal_onewire.h4
-rw-r--r--os/hal/src/hal_onewire.c20
-rw-r--r--testhal/STM32/STM32F0xx/onewire/search_rom_synth.c16
-rw-r--r--testhal/STM32/STM32F1xx/onewire/search_rom_synth.c16
-rw-r--r--testhal/STM32/STM32F4xx/onewire/search_rom_synth.c16
5 files changed, 36 insertions, 36 deletions
diff --git a/os/hal/include/hal_onewire.h b/os/hal/include/hal_onewire.h
index 2d27f48..9fb5be2 100644
--- a/os/hal/include/hal_onewire.h
+++ b/os/hal/include/hal_onewire.h
@@ -342,8 +342,8 @@ extern "C" {
uint8_t *result, size_t max_rom_cnt);
#endif /* ONEWIRE_USE_SEARCH_ROM */
#if ONEWIRE_SYNTH_SEARCH_TEST
- void _synth_ow_write_bit(onewireDriver *owp, uint8_t bit);
- uint_fast8_t _synth_ow_read_bit(void);
+ void _synth_ow_write_bit(onewireDriver *owp, ioline_t bit);
+ ioline_t _synth_ow_read_bit(void);
void synthSearchRomTest(onewireDriver *owp);
#endif /* ONEWIRE_SYNTH_SEARCH_TEST */
#ifdef __cplusplus
diff --git a/os/hal/src/hal_onewire.c b/os/hal/src/hal_onewire.c
index 85f0fdc..61a1e6c 100644
--- a/os/hal/src/hal_onewire.c
+++ b/os/hal/src/hal_onewire.c
@@ -58,6 +58,7 @@ on every timer overflow event.
#if (HAL_USE_ONEWIRE == TRUE) || defined(__DOXYGEN__)
#include <string.h>
+#include <limits.h>
/*===========================================================================*/
/* Driver local definitions. */
@@ -172,7 +173,7 @@ static void ow_bus_active(onewireDriver *owp) {
* @brief Function performing read of single bit.
* @note It must be callable from any context.
*/
-static uint_fast8_t ow_read_bit(onewireDriver *owp) {
+static ioline_t ow_read_bit(onewireDriver *owp) {
#if ONEWIRE_SYNTH_SEARCH_TEST
(void)owp;
return _synth_ow_read_bit();
@@ -221,7 +222,7 @@ static void pwm_search_rom_cb(PWMDriver *pwmp) {
*
* @notapi
*/
-static void ow_write_bit_I(onewireDriver *owp, uint_fast8_t bit) {
+static void ow_write_bit_I(onewireDriver *owp, ioline_t bit) {
#if ONEWIRE_SYNTH_SEARCH_TEST
_synth_ow_write_bit(owp, bit);
#else
@@ -348,12 +349,11 @@ static void ow_write_bit_cb(PWMDriver *pwmp, onewireDriver *owp) {
* @param[in] sr pointer to the @p onewire_search_rom_t helper structure
* @param[in] bit discovered bit to be stored in helper structure
*/
-static void store_bit(onewire_search_rom_t *sr, uint_fast8_t bit) {
+static void store_bit(onewire_search_rom_t *sr, uint8_t bit) {
size_t rb = sr->reg.rombit;
- /* / 8 % 8 */
- sr->retbuf[rb >> 3] |= bit << (rb & 7);
+ sr->retbuf[rb / CHAR_BIT] |= bit << (rb % CHAR_BIT);
sr->reg.rombit++;
}
@@ -365,9 +365,9 @@ static void store_bit(onewire_search_rom_t *sr, uint_fast8_t bit) {
* 'search ROM' helper structure
* @param[in] bit number of bit [0..63]
*/
-static uint_fast8_t extract_path_bit(const uint8_t *path, uint_fast8_t bit) {
- /* / 8 % 8 */
- return (path[bit >> 3] >> (bit & 7)) & 1;
+static uint8_t extract_path_bit(const uint8_t *path, uint8_t bit) {
+
+ return (path[bit / CHAR_BIT] >> (bit % CHAR_BIT)) & 1;
}
/**
@@ -377,9 +377,9 @@ static uint_fast8_t extract_path_bit(const uint8_t *path, uint_fast8_t bit) {
*
* @param[in,out] sr pointer to the @p onewire_search_rom_t helper structure
*/
-static uint_fast8_t collision_handler(onewire_search_rom_t *sr) {
+static uint8_t collision_handler(onewire_search_rom_t *sr) {
- uint_fast8_t bit;
+ uint8_t bit;
switch(sr->reg.search_iter) {
case ONEWIRE_SEARCH_ROM_NEXT:
diff --git a/testhal/STM32/STM32F0xx/onewire/search_rom_synth.c b/testhal/STM32/STM32F0xx/onewire/search_rom_synth.c
index 98f097d..cd2528f 100644
--- a/testhal/STM32/STM32F0xx/onewire/search_rom_synth.c
+++ b/testhal/STM32/STM32F0xx/onewire/search_rom_synth.c
@@ -41,7 +41,7 @@ typedef struct {
OWSynthDevice devices[SYNTH_DEVICES_MAX];
size_t dev_present;
bool complement_bit;
- uint_fast8_t rom_bit;
+ ioline_t rom_bit;
} OWSynthBus;
/*
@@ -86,12 +86,12 @@ static uint64_t detected_devices[SYNTH_DEVICES_MAX];
/**
*
*/
-void _synth_ow_write_bit(onewireDriver *owp, uint8_t bit) {
+void _synth_ow_write_bit(onewireDriver *owp, ioline_t bit) {
(void)owp;
size_t i;
for (i=0; i<SYNTH_DEVICES_MAX; i++) {
- if (((synth_bus.devices[i].id >> synth_bus.rom_bit) & 1) != bit) {
+ if (((synth_bus.devices[i].id >> synth_bus.rom_bit) & 1U) != bit) {
synth_bus.devices[i].active = false;
}
}
@@ -101,16 +101,16 @@ void _synth_ow_write_bit(onewireDriver *owp, uint8_t bit) {
/**
*
*/
-uint_fast8_t _synth_ow_read_bit(void) {
- uint_fast8_t ret = 0xFF;
+ioline_t _synth_ow_read_bit(void) {
+ ioline_t ret = 0xFF;
size_t i;
- uint_fast8_t bit;
+ ioline_t bit;
for (i=0; i<SYNTH_DEVICES_MAX; i++) {
if (synth_bus.devices[i].active){
- bit = (synth_bus.devices[i].id >> synth_bus.rom_bit) & 1;
+ bit = (synth_bus.devices[i].id >> synth_bus.rom_bit) & 1U;
if (synth_bus.complement_bit){
- bit ^= 1;
+ bit ^= 1U;
}
if (0xFF == ret)
ret = bit;
diff --git a/testhal/STM32/STM32F1xx/onewire/search_rom_synth.c b/testhal/STM32/STM32F1xx/onewire/search_rom_synth.c
index 98f097d..cd2528f 100644
--- a/testhal/STM32/STM32F1xx/onewire/search_rom_synth.c
+++ b/testhal/STM32/STM32F1xx/onewire/search_rom_synth.c
@@ -41,7 +41,7 @@ typedef struct {
OWSynthDevice devices[SYNTH_DEVICES_MAX];
size_t dev_present;
bool complement_bit;
- uint_fast8_t rom_bit;
+ ioline_t rom_bit;
} OWSynthBus;
/*
@@ -86,12 +86,12 @@ static uint64_t detected_devices[SYNTH_DEVICES_MAX];
/**
*
*/
-void _synth_ow_write_bit(onewireDriver *owp, uint8_t bit) {
+void _synth_ow_write_bit(onewireDriver *owp, ioline_t bit) {
(void)owp;
size_t i;
for (i=0; i<SYNTH_DEVICES_MAX; i++) {
- if (((synth_bus.devices[i].id >> synth_bus.rom_bit) & 1) != bit) {
+ if (((synth_bus.devices[i].id >> synth_bus.rom_bit) & 1U) != bit) {
synth_bus.devices[i].active = false;
}
}
@@ -101,16 +101,16 @@ void _synth_ow_write_bit(onewireDriver *owp, uint8_t bit) {
/**
*
*/
-uint_fast8_t _synth_ow_read_bit(void) {
- uint_fast8_t ret = 0xFF;
+ioline_t _synth_ow_read_bit(void) {
+ ioline_t ret = 0xFF;
size_t i;
- uint_fast8_t bit;
+ ioline_t bit;
for (i=0; i<SYNTH_DEVICES_MAX; i++) {
if (synth_bus.devices[i].active){
- bit = (synth_bus.devices[i].id >> synth_bus.rom_bit) & 1;
+ bit = (synth_bus.devices[i].id >> synth_bus.rom_bit) & 1U;
if (synth_bus.complement_bit){
- bit ^= 1;
+ bit ^= 1U;
}
if (0xFF == ret)
ret = bit;
diff --git a/testhal/STM32/STM32F4xx/onewire/search_rom_synth.c b/testhal/STM32/STM32F4xx/onewire/search_rom_synth.c
index 98f097d..cd2528f 100644
--- a/testhal/STM32/STM32F4xx/onewire/search_rom_synth.c
+++ b/testhal/STM32/STM32F4xx/onewire/search_rom_synth.c
@@ -41,7 +41,7 @@ typedef struct {
OWSynthDevice devices[SYNTH_DEVICES_MAX];
size_t dev_present;
bool complement_bit;
- uint_fast8_t rom_bit;
+ ioline_t rom_bit;
} OWSynthBus;
/*
@@ -86,12 +86,12 @@ static uint64_t detected_devices[SYNTH_DEVICES_MAX];
/**
*
*/
-void _synth_ow_write_bit(onewireDriver *owp, uint8_t bit) {
+void _synth_ow_write_bit(onewireDriver *owp, ioline_t bit) {
(void)owp;
size_t i;
for (i=0; i<SYNTH_DEVICES_MAX; i++) {
- if (((synth_bus.devices[i].id >> synth_bus.rom_bit) & 1) != bit) {
+ if (((synth_bus.devices[i].id >> synth_bus.rom_bit) & 1U) != bit) {
synth_bus.devices[i].active = false;
}
}
@@ -101,16 +101,16 @@ void _synth_ow_write_bit(onewireDriver *owp, uint8_t bit) {
/**
*
*/
-uint_fast8_t _synth_ow_read_bit(void) {
- uint_fast8_t ret = 0xFF;
+ioline_t _synth_ow_read_bit(void) {
+ ioline_t ret = 0xFF;
size_t i;
- uint_fast8_t bit;
+ ioline_t bit;
for (i=0; i<SYNTH_DEVICES_MAX; i++) {
if (synth_bus.devices[i].active){
- bit = (synth_bus.devices[i].id >> synth_bus.rom_bit) & 1;
+ bit = (synth_bus.devices[i].id >> synth_bus.rom_bit) & 1U;
if (synth_bus.complement_bit){
- bit ^= 1;
+ bit ^= 1U;
}
if (0xFF == ret)
ret = bit;