From a18d5969bd1582a6bc4623cdd0ee3d19b74d8627 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 5 Sep 2010 14:07:01 -0300 Subject: [PATCH] Next part of board bringup: reset and power cycling. - atusd/ERRATA: one more problem: the transistor footprint is wrong - atusd/tools/lib/atusd.c (atusd_cycle, atusd_reset): added power cycling and hardware reset - atusd/tools/lib/atusd.h: be nice and make a header file - atusd/tools/try.c: be nice and use header files (caught a bug as well) --- atusd/ERRATA | 3 +++ atusd/tools/lib/atusd.c | 52 ++++++++++++++++++++++++++++++++++++++++- atusd/tools/lib/atusd.h | 7 ++++++ atusd/tools/try.c | 10 ++++++-- 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 atusd/tools/lib/atusd.h diff --git a/atusd/ERRATA b/atusd/ERRATA index 88ec06a..9bb63d2 100644 --- a/atusd/ERRATA +++ b/atusd/ERRATA @@ -3,3 +3,6 @@ - added wire connecting uSD-side ground plane to ground plane at outer edge, to improve CLK signal return. (Probably unnecessary, too.) + +- the footprint of the transistor (Q1) is reversed :-( It works after + converting the chip from SOT to PLCC. diff --git a/atusd/tools/lib/atusd.c b/atusd/tools/lib/atusd.c index 210d6a0..96bed59 100644 --- a/atusd/tools/lib/atusd.c +++ b/atusd/tools/lib/atusd.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -102,7 +103,7 @@ struct atusd_dsc *atusd_open(void) void atusd_close(struct atusd_dsc *dsc) { - /* stop the MMC clock */ + /* stop the MMC bus clock */ MSC_STRPCL = 1; /* cut the power */ @@ -111,3 +112,52 @@ void atusd_close(struct atusd_dsc *dsc) /* make all MMC pins inputs */ PDDIRC = MxSx | CLK | SCLK | SLP_TR | IRQ | nSEL; } + + +void atusd_cycle(struct atusd_dsc *dsc) +{ + /* stop the MMC bus clock */ + MSC_STRPCL = 1; + + /* drive all outputs low (including the MMC bus clock) */ + PDDATC = MxSx | CLK | SCLK | SLP_TR | nSEL; + + /* make the MMC bus clock a regular output */ + PDFUNC = CLK; + + /* cut the power */ + PDDATS = VDD_OFF; + + /* Power drains within about 20 ms. Wait 100 ms to be sure. */ + usleep(100*1000); + + /* drive nSS high */ + PDDATS = nSEL; + + /* supply power */ + PDDATS = VDD_OFF; + + /* return the bus clock output to the MMC controller */ + PDFUNS = CLK; + + /* start MMC clock output */ + MSC_STRPCL = 2; +} + + +void atusd_reset(struct atusd_dsc *dsc) +{ + /* activate reset */ + PDDATS = SLP_TR; + PDDATC = nSEL; + + /* + * Data sheet says 625 ns, programmer's guide says 6 us. Whom do we + * trust ? + */ + usleep(6); + + /* release reset */ + PDDATS = nSEL; + PDDATC = SLP_TR; +} diff --git a/atusd/tools/lib/atusd.h b/atusd/tools/lib/atusd.h new file mode 100644 index 0000000..8304df6 --- /dev/null +++ b/atusd/tools/lib/atusd.h @@ -0,0 +1,7 @@ +struct atusd_dsc; + + +struct atusd_dsc *atusd_open(void); +void atusd_close(struct atusd_dsc *dsc); +void atusd_cycle(struct atusd_dsc *dsc); +void atusd_reset(struct atusd_dsc *dsc); diff --git a/atusd/tools/try.c b/atusd/tools/try.c index d982fbe..4f28e1a 100644 --- a/atusd/tools/try.c +++ b/atusd/tools/try.c @@ -1,4 +1,7 @@ -struct atusd_dsc; +#include +#include + +#include "lib/atusd.h" int main(void) @@ -7,7 +10,10 @@ int main(void) char tmp; dsc = atusd_open(); - read(1, tmp, 1); + read(1, &tmp, 1); +fprintf(stderr, "cycling\n"); + atusd_cycle(dsc); + read(1, &tmp, 1); atusd_close(dsc); return 0;