diff options
-rw-r--r-- | os/hal/src/onewire.c | 23 | ||||
-rw-r--r-- | testhal/STM32/STM32F1xx/onewire/Makefile | 2 | ||||
-rw-r--r-- | testhal/STM32/STM32F1xx/onewire/onewire_test.c | 4 |
3 files changed, 20 insertions, 9 deletions
diff --git a/os/hal/src/onewire.c b/os/hal/src/onewire.c index f1fb7a8..724ff2f 100644 --- a/os/hal/src/onewire.c +++ b/os/hal/src/onewire.c @@ -108,10 +108,10 @@ static const PWMConfig pwm_default_cfg = { ONEWIRE_RESET_TOTAL_WIDTH, NULL, { - {PWM_OUTPUT_DISABLED, NULL}, - {PWM_OUTPUT_DISABLED, NULL}, - {PWM_OUTPUT_DISABLED, NULL}, - {PWM_OUTPUT_DISABLED, NULL} + {PWM_OUTPUT_ACTIVE_LOW, NULL}, + {PWM_OUTPUT_ACTIVE_LOW, NULL}, + {PWM_OUTPUT_ACTIVE_LOW, NULL}, + {PWM_OUTPUT_ACTIVE_LOW, NULL} }, 0, 0 @@ -582,6 +582,7 @@ void onewireStart(onewireDriver *owp, const onewireConfig *config) { #endif owp->config = config; + pwmStart(owp->config->pwmd, &pwm_default_cfg); owp->reg.state = ONEWIRE_READY; } @@ -617,9 +618,11 @@ bool onewireReset(onewireDriver *owp) { osalDbgAssert(owp->reg.state == ONEWIRE_READY, "Invalid state"); /* short circuit on bus or any other device transmit data */ - if (0 == owp->config->readBitX()) + if (PAL_LOW == owp->config->readBitX()) return false; + palSetPad(GPIOC, GPIOC_LED); + pwmd = owp->config->pwmd; owp->pwmcfg.period = ONEWIRE_RESET_LOW_WIDTH + ONEWIRE_RESET_SAMPLE_WIDTH; @@ -630,6 +633,7 @@ bool onewireReset(onewireDriver *owp) { owp->pwmcfg.channels[owp->config->sample_channel].mode = PWM_OUTPUT_ACTIVE_LOW; pwmStart(pwmd, &owp->pwmcfg); + palSetPadMode(GPIOB, 8, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); pwmEnableChannel(pwmd, owp->config->master_channel, ONEWIRE_RESET_LOW_WIDTH); pwmEnableChannel(pwmd, owp->config->sample_channel, ONEWIRE_RESET_SAMPLE_WIDTH); pwmEnableChannelNotification(pwmd, owp->config->sample_channel); @@ -638,11 +642,12 @@ bool onewireReset(onewireDriver *owp) { osalThreadSuspendS(&owp->thread); osalSysUnlock(); + palSetPadMode(GPIOB, 8, PAL_MODE_INPUT); pwmStop(pwmd); /* wait until slave release bus to discriminate short circuit condition */ osalThreadSleepMicroseconds(500); - return (1 == owp->config->readBitX()) && (true == owp->reg.slave_present); + return (PAL_HIGH == owp->config->readBitX()) && (true == owp->reg.slave_present); } /** @@ -678,6 +683,7 @@ void onewireRead(onewireDriver *owp, uint8_t *rxbuf, size_t rxbytes) { owp->pwmcfg.channels[owp->config->sample_channel].mode = PWM_OUTPUT_ACTIVE_LOW; pwmStart(pwmd, &owp->pwmcfg); + palSetPadMode(GPIOB, 8, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); pwmEnableChannel(pwmd, owp->config->master_channel, ONEWIRE_ONE_WIDTH); pwmEnableChannel(pwmd, owp->config->sample_channel, ONEWIRE_SAMPLE_WIDTH); pwmEnableChannelNotification(pwmd, owp->config->sample_channel); @@ -686,6 +692,7 @@ void onewireRead(onewireDriver *owp, uint8_t *rxbuf, size_t rxbytes) { osalThreadSuspendS(&owp->thread); osalSysUnlock(); + palSetPadMode(GPIOB, 8, PAL_MODE_INPUT); pwmStop(pwmd); } @@ -732,6 +739,7 @@ void onewireWrite(onewireDriver *owp, uint8_t *txbuf, #endif pwmStart(pwmd, &owp->pwmcfg); + palSetPadMode(GPIOB, 8, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); pwmEnablePeriodicNotification(pwmd); osalSysLock(); @@ -739,6 +747,7 @@ void onewireWrite(onewireDriver *owp, uint8_t *txbuf, osalSysUnlock(); pwmDisablePeriodicNotification(pwmd); + palSetPadMode(GPIOB, 8, PAL_MODE_INPUT); pwmStop(pwmd); #if ONEWIRE_USE_STRONG_PULLUP @@ -803,6 +812,7 @@ size_t onewireSearchRom(onewireDriver *owp, uint8_t *result, owp->pwmcfg.channels[owp->config->sample_channel].callback = pwm_search_rom_cb; owp->pwmcfg.channels[owp->config->sample_channel].mode = PWM_OUTPUT_ACTIVE_LOW; pwmStart(pwmd, &owp->pwmcfg); + palSetPadMode(GPIOB, 8, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); pwmEnableChannel(pwmd, owp->config->master_channel, ONEWIRE_ONE_WIDTH); pwmEnableChannel(pwmd, owp->config->sample_channel, ONEWIRE_SAMPLE_WIDTH); pwmEnableChannelNotification(pwmd, owp->config->sample_channel); @@ -811,6 +821,7 @@ size_t onewireSearchRom(onewireDriver *owp, uint8_t *result, osalThreadSuspendS(&owp->thread); osalSysUnlock(); + palSetPadMode(GPIOB, 8, PAL_MODE_INPUT); pwmStop(pwmd); if (ONEWIRE_SEARCH_ROM_ERROR != owp->search_rom.reg.result) { diff --git a/testhal/STM32/STM32F1xx/onewire/Makefile b/testhal/STM32/STM32F1xx/onewire/Makefile index d657cdc..dbaaca5 100644 --- a/testhal/STM32/STM32F1xx/onewire/Makefile +++ b/testhal/STM32/STM32F1xx/onewire/Makefile @@ -5,7 +5,7 @@ # Compiler options here.
ifeq ($(USE_OPT),)
- USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
+ USE_OPT = -O0 -ggdb -fomit-frame-pointer -falign-functions=16
endif
# C specific options here (added to USE_OPT).
diff --git a/testhal/STM32/STM32F1xx/onewire/onewire_test.c b/testhal/STM32/STM32F1xx/onewire/onewire_test.c index 139732d..3ce31dc 100644 --- a/testhal/STM32/STM32F1xx/onewire/onewire_test.c +++ b/testhal/STM32/STM32F1xx/onewire/onewire_test.c @@ -40,8 +40,8 @@ #define GPIOB_ONEWIRE 8 #define search_led_off() (palClearPad(GPIOC, GPIOC_LED)) #define search_led_on() (palSetPad(GPIOC, GPIOC_LED)) -#define ONEWIRE_MASTER_CHANNEL 3 -#define ONEWIRE_SAMPLE_CHANNEL 2 +#define ONEWIRE_MASTER_CHANNEL 2 +#define ONEWIRE_SAMPLE_CHANNEL 3 #else #define GPIOB_ONEWIRE GPIOB_TACHOMETER #include "pads.h" |