From 73b9a82a0b2310a77d0e7ab720774f9612f6a9f8 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 27 Dec 2014 22:14:20 +0300 Subject: [1-wire] Added testhal for STM32F0xx family --- testhal/STM32/STM32F0xx/onewire/search_rom_synth.c | 370 +++++++++++++++++++++ 1 file changed, 370 insertions(+) create mode 100644 testhal/STM32/STM32F0xx/onewire/search_rom_synth.c (limited to 'testhal/STM32/STM32F0xx/onewire/search_rom_synth.c') diff --git a/testhal/STM32/STM32F0xx/onewire/search_rom_synth.c b/testhal/STM32/STM32F0xx/onewire/search_rom_synth.c new file mode 100644 index 0000000..98f097d --- /dev/null +++ b/testhal/STM32/STM32F0xx/onewire/search_rom_synth.c @@ -0,0 +1,370 @@ +/* + ChibiOS/RT - Copyright (C) 2014 Uladzimir Pylinsky aka barthess + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include + +/* + ****************************************************************************** + * DEFINES + ****************************************************************************** + */ + +/* do not set it more than 64 because of some fill_pattern functions + * will be broken.*/ +#define SYNTH_DEVICES_MAX 64 + +/* + * synthetic device + */ +typedef struct { + bool active; + uint64_t id; +} OWSynthDevice; + +/* + * synthetic bus + */ +typedef struct { + OWSynthDevice devices[SYNTH_DEVICES_MAX]; + size_t dev_present; + bool complement_bit; + uint_fast8_t rom_bit; +} OWSynthBus; + +/* + ****************************************************************************** + * EXTERNS + ****************************************************************************** + */ + +/* + ****************************************************************************** + * PROTOTYPES + ****************************************************************************** + */ + +/* + ****************************************************************************** + * GLOBAL VARIABLES + ****************************************************************************** + */ + +static OWSynthBus synth_bus; + +/* + * local buffer for discovered ROMs + */ +static uint64_t detected_devices[SYNTH_DEVICES_MAX]; + +/* + ****************************************************************************** + ****************************************************************************** + * LOCAL FUNCTIONS + ****************************************************************************** + ****************************************************************************** + */ + +/* + ****************************************************************************** + * EXPORTED FUNCTIONS + ****************************************************************************** + */ + +/** + * + */ +void _synth_ow_write_bit(onewireDriver *owp, uint8_t bit) { + (void)owp; + size_t i; + + for (i=0; i> synth_bus.rom_bit) & 1) != bit) { + synth_bus.devices[i].active = false; + } + } + synth_bus.rom_bit++; +} + +/** + * + */ +uint_fast8_t _synth_ow_read_bit(void) { + uint_fast8_t ret = 0xFF; + size_t i; + uint_fast8_t bit; + + for (i=0; i> synth_bus.rom_bit) & 1; + if (synth_bus.complement_bit){ + bit ^= 1; + } + if (0xFF == ret) + ret = bit; + else + ret &= bit; + } + } + synth_bus.complement_bit = !synth_bus.complement_bit; + return ret; +} + +/** + * + */ +static void synth_reset_pulse(void){ + size_t i; + + for (i=0; isearch_rom); + + do { + /* initialize buffer to store result */ + if (owp->search_rom.reg.devices_found >= max_rom_cnt) + owp->search_rom.retbuf = result + 8*(max_rom_cnt-1); + else + owp->search_rom.retbuf = result + 8*owp->search_rom.reg.devices_found; + memset(owp->search_rom.retbuf, 0, 8); + + /* clean iteration state */ + search_clean_iteration(&owp->search_rom); + + /**/ + synth_reset_pulse(); + synth_bus.rom_bit = 0; + synth_bus.complement_bit = false; + for (i=0; i<64*3 - 1; i++){ + ow_search_rom_cb(NULL, owp); + } + + if (ONEWIRE_SEARCH_ROM_ERROR != owp->search_rom.reg.result) { + /* store cached result for usage in next iteration */ + memcpy(owp->search_rom.prev_path, owp->search_rom.retbuf, 8); + } + } + while (ONEWIRE_SEARCH_ROM_SUCCESS == owp->search_rom.reg.result); + + /**/ + if (ONEWIRE_SEARCH_ROM_ERROR == owp->search_rom.reg.result) + return 0; + else + return owp->search_rom.reg.devices_found; +} + +/** + * + */ +static void fill_pattern_real_devices(void) { + size_t i; + + for (i=0; i> i); + } +} + +/** + * @brief random pattern helper + */ +static bool is_id_uniq(const OWSynthDevice *dev, size_t n, uint64_t id) { + size_t i; + + for (i=0; i