1-wire. Added workaround form F1xx MCUs

This commit is contained in:
barthess 2014-12-09 11:31:46 +03:00
parent 97be1351af
commit 99505cdea6
3 changed files with 20 additions and 9 deletions

View File

@ -108,10 +108,10 @@ static const PWMConfig pwm_default_cfg = {
ONEWIRE_RESET_TOTAL_WIDTH, ONEWIRE_RESET_TOTAL_WIDTH,
NULL, NULL,
{ {
{PWM_OUTPUT_DISABLED, NULL}, {PWM_OUTPUT_ACTIVE_LOW, NULL},
{PWM_OUTPUT_DISABLED, NULL}, {PWM_OUTPUT_ACTIVE_LOW, NULL},
{PWM_OUTPUT_DISABLED, NULL}, {PWM_OUTPUT_ACTIVE_LOW, NULL},
{PWM_OUTPUT_DISABLED, NULL} {PWM_OUTPUT_ACTIVE_LOW, NULL}
}, },
0, 0,
0 0
@ -582,6 +582,7 @@ void onewireStart(onewireDriver *owp, const onewireConfig *config) {
#endif #endif
owp->config = config; owp->config = config;
pwmStart(owp->config->pwmd, &pwm_default_cfg);
owp->reg.state = ONEWIRE_READY; owp->reg.state = ONEWIRE_READY;
} }
@ -617,9 +618,11 @@ bool onewireReset(onewireDriver *owp) {
osalDbgAssert(owp->reg.state == ONEWIRE_READY, "Invalid state"); osalDbgAssert(owp->reg.state == ONEWIRE_READY, "Invalid state");
/* short circuit on bus or any other device transmit data */ /* short circuit on bus or any other device transmit data */
if (0 == owp->config->readBitX()) if (PAL_LOW == owp->config->readBitX())
return false; return false;
palSetPad(GPIOC, GPIOC_LED);
pwmd = owp->config->pwmd; pwmd = owp->config->pwmd;
owp->pwmcfg.period = ONEWIRE_RESET_LOW_WIDTH + ONEWIRE_RESET_SAMPLE_WIDTH; 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; owp->pwmcfg.channels[owp->config->sample_channel].mode = PWM_OUTPUT_ACTIVE_LOW;
pwmStart(pwmd, &owp->pwmcfg); 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->master_channel, ONEWIRE_RESET_LOW_WIDTH);
pwmEnableChannel(pwmd, owp->config->sample_channel, ONEWIRE_RESET_SAMPLE_WIDTH); pwmEnableChannel(pwmd, owp->config->sample_channel, ONEWIRE_RESET_SAMPLE_WIDTH);
pwmEnableChannelNotification(pwmd, owp->config->sample_channel); pwmEnableChannelNotification(pwmd, owp->config->sample_channel);
@ -638,11 +642,12 @@ bool onewireReset(onewireDriver *owp) {
osalThreadSuspendS(&owp->thread); osalThreadSuspendS(&owp->thread);
osalSysUnlock(); osalSysUnlock();
palSetPadMode(GPIOB, 8, PAL_MODE_INPUT);
pwmStop(pwmd); pwmStop(pwmd);
/* wait until slave release bus to discriminate short circuit condition */ /* wait until slave release bus to discriminate short circuit condition */
osalThreadSleepMicroseconds(500); 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; owp->pwmcfg.channels[owp->config->sample_channel].mode = PWM_OUTPUT_ACTIVE_LOW;
pwmStart(pwmd, &owp->pwmcfg); 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->master_channel, ONEWIRE_ONE_WIDTH);
pwmEnableChannel(pwmd, owp->config->sample_channel, ONEWIRE_SAMPLE_WIDTH); pwmEnableChannel(pwmd, owp->config->sample_channel, ONEWIRE_SAMPLE_WIDTH);
pwmEnableChannelNotification(pwmd, owp->config->sample_channel); pwmEnableChannelNotification(pwmd, owp->config->sample_channel);
@ -686,6 +692,7 @@ void onewireRead(onewireDriver *owp, uint8_t *rxbuf, size_t rxbytes) {
osalThreadSuspendS(&owp->thread); osalThreadSuspendS(&owp->thread);
osalSysUnlock(); osalSysUnlock();
palSetPadMode(GPIOB, 8, PAL_MODE_INPUT);
pwmStop(pwmd); pwmStop(pwmd);
} }
@ -732,6 +739,7 @@ void onewireWrite(onewireDriver *owp, uint8_t *txbuf,
#endif #endif
pwmStart(pwmd, &owp->pwmcfg); pwmStart(pwmd, &owp->pwmcfg);
palSetPadMode(GPIOB, 8, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
pwmEnablePeriodicNotification(pwmd); pwmEnablePeriodicNotification(pwmd);
osalSysLock(); osalSysLock();
@ -739,6 +747,7 @@ void onewireWrite(onewireDriver *owp, uint8_t *txbuf,
osalSysUnlock(); osalSysUnlock();
pwmDisablePeriodicNotification(pwmd); pwmDisablePeriodicNotification(pwmd);
palSetPadMode(GPIOB, 8, PAL_MODE_INPUT);
pwmStop(pwmd); pwmStop(pwmd);
#if ONEWIRE_USE_STRONG_PULLUP #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].callback = pwm_search_rom_cb;
owp->pwmcfg.channels[owp->config->sample_channel].mode = PWM_OUTPUT_ACTIVE_LOW; owp->pwmcfg.channels[owp->config->sample_channel].mode = PWM_OUTPUT_ACTIVE_LOW;
pwmStart(pwmd, &owp->pwmcfg); 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->master_channel, ONEWIRE_ONE_WIDTH);
pwmEnableChannel(pwmd, owp->config->sample_channel, ONEWIRE_SAMPLE_WIDTH); pwmEnableChannel(pwmd, owp->config->sample_channel, ONEWIRE_SAMPLE_WIDTH);
pwmEnableChannelNotification(pwmd, owp->config->sample_channel); pwmEnableChannelNotification(pwmd, owp->config->sample_channel);
@ -811,6 +821,7 @@ size_t onewireSearchRom(onewireDriver *owp, uint8_t *result,
osalThreadSuspendS(&owp->thread); osalThreadSuspendS(&owp->thread);
osalSysUnlock(); osalSysUnlock();
palSetPadMode(GPIOB, 8, PAL_MODE_INPUT);
pwmStop(pwmd); pwmStop(pwmd);
if (ONEWIRE_SEARCH_ROM_ERROR != owp->search_rom.reg.result) { if (ONEWIRE_SEARCH_ROM_ERROR != owp->search_rom.reg.result) {

View File

@ -5,7 +5,7 @@
# Compiler options here. # Compiler options here.
ifeq ($(USE_OPT),) ifeq ($(USE_OPT),)
USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16 USE_OPT = -O0 -ggdb -fomit-frame-pointer -falign-functions=16
endif endif
# C specific options here (added to USE_OPT). # C specific options here (added to USE_OPT).

View File

@ -40,8 +40,8 @@
#define GPIOB_ONEWIRE 8 #define GPIOB_ONEWIRE 8
#define search_led_off() (palClearPad(GPIOC, GPIOC_LED)) #define search_led_off() (palClearPad(GPIOC, GPIOC_LED))
#define search_led_on() (palSetPad(GPIOC, GPIOC_LED)) #define search_led_on() (palSetPad(GPIOC, GPIOC_LED))
#define ONEWIRE_MASTER_CHANNEL 3 #define ONEWIRE_MASTER_CHANNEL 2
#define ONEWIRE_SAMPLE_CHANNEL 2 #define ONEWIRE_SAMPLE_CHANNEL 3
#else #else
#define GPIOB_ONEWIRE GPIOB_TACHOMETER #define GPIOB_ONEWIRE GPIOB_TACHOMETER
#include "pads.h" #include "pads.h"