bsllib: separate modem control line sequencing.

This commit is contained in:
Daniel Beer 2014-04-02 14:48:42 +13:00
parent 4417bf82a7
commit 651d18e121
4 changed files with 104 additions and 55 deletions

View File

@ -149,6 +149,7 @@ OBJ=\
drivers/hal_proto.o \
drivers/v3hil.o \
drivers/fet3.o \
drivers/bsllib.o \
formats/binfile.o \
formats/coff.o \
formats/elf32.o \

70
drivers/bsllib.c Normal file
View File

@ -0,0 +1,70 @@
/* MSPDebug - debugging tool for the eZ430
* Copyright (C) 2009, 2010 Daniel Beer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "util/util.h"
#include "bsllib.h"
int bsllib_seq_do(sport_t fd, const char *seq)
{
int state = 0;
while (*seq && *seq != ':') {
const char c = *(seq++);
switch (c) {
case 'R':
state |= SPORT_MC_RTS;
break;
case 'r':
state &= ~SPORT_MC_RTS;
break;
case 'D':
state |= SPORT_MC_DTR;
break;
case 'd':
state &= ~SPORT_MC_DTR;
break;
case ',':
if (sport_set_modem(fd, state) < 0)
return -1;
delay_ms(50);
break;
}
}
if (sport_set_modem(fd, state) < 0)
return -1;
delay_ms(50);
return 0;
}
const char *bsllib_seq_next(const char *seq)
{
while (*seq && *seq != ':')
seq++;
if (*seq == ':')
seq++;
return seq;
}

30
drivers/bsllib.h Normal file
View File

@ -0,0 +1,30 @@
/* MSPDebug - debugging tool for the eZ430
* Copyright (C) 2009, 2010 Daniel Beer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef BSLLIB_H_
#define BSLLIB_H_
#include "util/sport.h"
/* Execute the given sequence specifier with the modem control lines */
int bsllib_seq_do(sport_t sport, const char *seq);
/* Skip to the next part of a sequence specified */
const char *bsllib_seq_next(const char *seq);
#endif

View File

@ -29,6 +29,7 @@
#include "output.h"
#include "fet_error.h"
#include "sport.h"
#include "bsllib.h"
struct flash_bsl_device {
struct device base;
@ -549,64 +550,11 @@ static int flash_bsl_writemem(device_t dev_base,
return 0;
}
static int do_pattern(sport_t fd, const char *seq)
{
int state = 0;
while (*seq && *seq != ':') {
const char c = *(seq++);
switch (c) {
case 'R':
state |= SPORT_MC_RTS;
break;
case 'r':
state &= ~SPORT_MC_RTS;
break;
case 'D':
state |= SPORT_MC_DTR;
break;
case 'd':
state &= ~SPORT_MC_DTR;
break;
case ',':
if (sport_set_modem(fd, state) < 0)
return -1;
delay_ms(50);
break;
}
}
if (sport_set_modem(fd, state) < 0)
return -1;
delay_ms(50);
return 0;
}
static void exit_via_dtr_rts(struct flash_bsl_device *dev)
{
const char *seq = dev->seq;
while (*seq && *seq != ':')
seq++;
if (*seq == ':')
seq++;
do_pattern(dev->serial_fd, seq);
}
static void flash_bsl_destroy(device_t dev_base)
{
struct flash_bsl_device *dev = (struct flash_bsl_device *)dev_base;
exit_via_dtr_rts(dev);
bsllib_seq_do(dev->serial_fd, bsllib_seq_next(dev->seq));
sport_close(dev->serial_fd);
free(dev);
}
@ -649,7 +597,7 @@ static device_t flash_bsl_open(const struct device_args *args)
dev->long_password = args->flags & DEVICE_FLAG_LONG_PW;
/* enter bootloader */
if (do_pattern(dev->serial_fd, dev->seq) < 0) {
if (bsllib_seq_do(dev->serial_fd, dev->seq) < 0) {
printc_err("BSL entry sequence failed\n");
goto fail;
}