003-m8cutils-parport-por-issp.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. Add a driver for the Parallel Port based PowerOnReset In System Serial Programmer.
  2. ---
  3. prog/Makefile | 2
  4. prog/drv/ppporissp.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++
  5. 2 files changed, 144 insertions(+), 1 deletion(-)
  6. --- m8cutils-22.orig/prog/Makefile
  7. +++ m8cutils-22/prog/Makefile
  8. @@ -8,7 +8,7 @@
  9. include ../Common.make
  10. -DRIVERS=waspic watsp watpp wadsp ecb_at91 dummy
  11. +DRIVERS=waspic watsp watpp wadsp ecb_at91 dummy ppporissp
  12. TESTS=rd errd ercmok ercmf wrrd wrcmok wrcmf wrlkcmok wrlkcmf wrlkrdf wrlkrdz \
  13. secu secf secr secw secfsrw secfsur secfsfw \
  14. secfspu secfspf secfspr secfspw secmir inrom inhex outrom outhex \
  15. --- /dev/null
  16. +++ m8cutils-22/prog/drv/ppporissp.c
  17. @@ -0,0 +1,143 @@
  18. +/*
  19. + * ppporissp.c - Parallel Port based PowerOnReset In System Serial Programmer
  20. + *
  21. + * Copyright (c) 2009 Michael Buesch <m@bues.ch>
  22. + * Derived from wadsp.c Copyright 2006 Werner Almesberger
  23. + * Derived from watpp.c Copyright 2006 Werner Almesberger
  24. + */
  25. +
  26. +#include <stdint.h>
  27. +#include <stdlib.h>
  28. +#include <stdio.h>
  29. +#include <unistd.h>
  30. +
  31. +#include "prog.h"
  32. +#include "pp.h"
  33. +
  34. +/*
  35. + * Programmer connections:
  36. + *
  37. + * Logical
  38. + * 1 0
  39. + * Data 0 (pin 2) SDATA to device SDATA !SDATA
  40. + * Data 1 (pin 3) SCLK to device SCLK !SCLK
  41. + * Data 2 (pin 4) Device power PWR !PWR
  42. + * Status 3 (pin 15) SDATA from device SDATA !SDATA
  43. + */
  44. +
  45. +#define PWR_TARGET(on) ((on) ? (data |= (1 << 2)) : (data &= ~(1 << 2)))
  46. +#define SCLK(on) ((on) ? (data |= (1 << 1)) : (data &= ~(1 << 1)))
  47. +#define SDATA_OUT(on) ((on) ? (data |= (1 << 0)) : (data &= ~(1 << 0)))
  48. +#define SDATA_IN() (!!(pp_read_status() & (1 << 3)))
  49. +#define COMMIT() pp_write_data(data)
  50. +
  51. +static int fd;
  52. +static int inverted;
  53. +static uint8_t data;
  54. +
  55. +
  56. +void delay_hook(int rising);
  57. +void __attribute__((weak)) delay_hook(int rising)
  58. +{
  59. +}
  60. +
  61. +static void ppporissp_send_bit(int bit)
  62. +{
  63. + SDATA_OUT(bit);
  64. + SCLK(1);
  65. + COMMIT();
  66. + delay_hook(1);
  67. + SCLK(0);
  68. + COMMIT();
  69. + delay_hook(0);
  70. +}
  71. +
  72. +static void ppporissp_send_z(void)
  73. +{
  74. + SDATA_OUT(0);
  75. + SCLK(!inverted);
  76. + COMMIT();
  77. + delay_hook(1);
  78. + SCLK(inverted);
  79. + COMMIT();
  80. + delay_hook(0);
  81. +}
  82. +
  83. +static int ppporissp_read_bit(void)
  84. +{
  85. + return SDATA_IN();
  86. +}
  87. +
  88. +static void ppporissp_invert_phase(void)
  89. +{
  90. + inverted = !inverted;
  91. + if (inverted) {
  92. + SCLK(1);
  93. + COMMIT();
  94. + }
  95. +}
  96. +
  97. +static struct prog_bit ppporissp_bit = {
  98. + .send_bit = ppporissp_send_bit,
  99. + .send_z = ppporissp_send_z,
  100. + .read_bit = ppporissp_read_bit,
  101. + .invert_phase = ppporissp_invert_phase,
  102. +};
  103. +
  104. +static void ppporissp_initialize(int power_on)
  105. +{
  106. + struct timeval t0;
  107. +
  108. + printf("Performing power-on-reset...\n");
  109. + PWR_TARGET(1);
  110. + COMMIT();
  111. + start_time(&t0);
  112. + /* This is much safer than usleep. */
  113. + while (delta_time_us(&t0) < T_VDDWAIT);
  114. +}
  115. +
  116. +static int ppporissp_open(const char *dev, int voltage, int power_on,
  117. + const char *args[])
  118. +{
  119. + prog_init(NULL, NULL, NULL, &ppporissp_bit);
  120. +
  121. + if (!power_on) {
  122. + fprintf(stderr, "ppporissp does not support XRES\n");
  123. + return -1;
  124. + }
  125. + if (voltage != 5)
  126. + printf("Warning: Not operating on 5V. Trying anyway...\n");
  127. +
  128. + fd = pp_open(dev, 0);
  129. +
  130. + inverted = 0;
  131. + PWR_TARGET(0);
  132. + SCLK(0);
  133. + SDATA_OUT(0);
  134. + COMMIT();
  135. + /*
  136. + * With the power off, we now wait for capacitors on the board to
  137. + * discharge. Using v(t) = v(0)*exp(-t/RC) and
  138. + * v(0) = 5V, R = 4.7kOhm, t = 100ms, we can discharge up to
  139. + * C = 10uF down to a diode drop of 0.6V.
  140. + */
  141. + printf("Waiting for device to power down...\n");
  142. + sleep(2); /* 2000 ms */
  143. +
  144. + return voltage;
  145. +}
  146. +
  147. +static void ppporissp_close(void)
  148. +{
  149. + SCLK(0);
  150. + PWR_TARGET(0);
  151. + COMMIT();
  152. + pp_close();
  153. +}
  154. +
  155. +struct prog_common ppporissp = {
  156. + .name = "ppporissp",
  157. + .open = ppporissp_open,
  158. + .close = ppporissp_close,
  159. + .initialize = ppporissp_initialize,
  160. +};