aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/src
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 /os/hal/src
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.
Diffstat (limited to 'os/hal/src')
-rw-r--r--os/hal/src/hal_onewire.c20
1 files changed, 10 insertions, 10 deletions
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: