Advertisement
uaa

[wip:20140511] uchcom.c diff (worked, 9600bps only!)

uaa
May 10th, 2014
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. --- uchcom.c.bak Fri Nov 15 19:17:39 2013
  2. +++ uchcom.c Sun May 11 06:15:20 2014
  3. @@ -48,9 +48,10 @@
  4. #include <dev/usb/usbdevs.h>
  5. #include <dev/usb/ucomvar.h>
  6.  
  7. +#define UCHCOM_DEBUG
  8. #ifdef UCHCOM_DEBUG
  9. #define DPRINTFN(n, x) do { if (uchcomdebug > (n)) printf x; } while (0)
  10. -int uchcomdebug = 0;
  11. +int uchcomdebug = 3;
  12. #else
  13. #define DPRINTFN(n, x)
  14. #endif
  15. @@ -72,7 +73,7 @@ int uchcomdebug = 0;
  16. #define UCHCOM_REG_STAT2 0x07
  17. #define UCHCOM_REG_BPS_PRE 0x12
  18. #define UCHCOM_REG_BPS_DIV 0x13
  19. -#define UCHCOM_REG_BPS_MOD 0x14
  20. +#define UCHCOM_REG_BPS_MOD 0x2C
  21. #define UCHCOM_REG_BPS_PAD 0x0F
  22. #define UCHCOM_REG_BREAK1 0x05
  23. #define UCHCOM_REG_BREAK2 0x18
  24. @@ -81,9 +82,8 @@ int uchcomdebug = 0;
  25.  
  26. #define UCHCOM_VER_20 0x20
  27.  
  28. -#define UCHCOM_BASE_UNKNOWN 0
  29. -#define UCHCOM_BPS_MOD_BASE 20000000
  30. -#define UCHCOM_BPS_MOD_BASE_OFS 1100
  31. +#define UCHCOM_BAUDBASE_FACTOR 1532620800
  32. +#define UCHCOM_BAUDBASE_DIVMAX 3
  33.  
  34. #define UCHCOM_DTR_MASK 0x20
  35. #define UCHCOM_RTS_MASK 0x40
  36. @@ -142,24 +142,6 @@ struct uchcom_divider
  37. uint8_t dv_mod;
  38. };
  39.  
  40. -struct uchcom_divider_record
  41. -{
  42. - uint32_t dvr_high;
  43. - uint32_t dvr_low;
  44. - uint32_t dvr_base_clock;
  45. - struct uchcom_divider dvr_divider;
  46. -};
  47. -
  48. -static const struct uchcom_divider_record dividers[] =
  49. -{
  50. - { 307200, 307200, UCHCOM_BASE_UNKNOWN, { 7, 0xD9, 0 } },
  51. - { 921600, 921600, UCHCOM_BASE_UNKNOWN, { 7, 0xF3, 0 } },
  52. - { 2999999, 23530, 6000000, { 3, 0, 0 } },
  53. - { 23529, 2942, 750000, { 2, 0, 0 } },
  54. - { 2941, 368, 93750, { 1, 0, 0 } },
  55. - { 367, 1, 11719, { 0, 0, 0 } },
  56. -};
  57. -
  58. void uchcom_get_status(void *, int, u_char *, u_char *);
  59. void uchcom_set(void *, int, int, int);
  60. int uchcom_param(void *, int, struct termios *);
  61. @@ -259,6 +241,7 @@ uchcom_attach(struct device *parent, struct device *se
  62. struct ucom_attach_args uca;
  63. struct usbd_device *dev = uaa->device;
  64. struct uchcom_endpoints endpoints;
  65. + usbd_status err;
  66.  
  67. sc->sc_udev = dev;
  68. sc->sc_dtr = sc->sc_rts = -1;
  69. @@ -300,7 +283,15 @@ uchcom_attach(struct device *parent, struct device *se
  70. uca.methods = &uchcom_methods;
  71. uca.arg = sc;
  72. uca.info = NULL;
  73. -
  74. +
  75. + err = uchcom_setup_comm(sc);
  76. + if (err) {
  77. + printf("%s: setup failed, %s\n", sc->sc_dev.dv_xname,
  78. + usbd_errstr(err));
  79. + usbd_deactivate(sc->sc_udev);
  80. + return;
  81. + }
  82. +
  83. sc->sc_subdev = config_found_sm(self, &uca, ucomprint, ucomsubmatch);
  84.  
  85. return;
  86. @@ -645,39 +636,26 @@ uchcom_set_break(struct uchcom_softc *sc, int onoff)
  87. int
  88. uchcom_calc_divider_settings(struct uchcom_divider *dp, uint32_t rate)
  89. {
  90. - int i;
  91. - const struct uchcom_divider_record *rp;
  92. - uint32_t div, rem, mod;
  93. + uint32_t factor, prescaler;
  94.  
  95. - /* find record */
  96. - for (i=0; i<nitems(dividers); i++) {
  97. - if (dividers[i].dvr_high >= rate &&
  98. - dividers[i].dvr_low <= rate) {
  99. - rp = &dividers[i];
  100. - goto found;
  101. - }
  102. - }
  103. - return -1;
  104. + if (!rate)
  105. + return -1;
  106.  
  107. -found:
  108. - dp->dv_prescaler = rp->dvr_divider.dv_prescaler;
  109. - if (rp->dvr_base_clock == UCHCOM_BASE_UNKNOWN)
  110. - dp->dv_div = rp->dvr_divider.dv_div;
  111. - else {
  112. - div = rp->dvr_base_clock / rate;
  113. - rem = rp->dvr_base_clock % rate;
  114. - if (div==0 || div>=0xFF)
  115. - return -1;
  116. - if ((rem<<1) >= rate)
  117. - div += 1;
  118. - dp->dv_div = (uint8_t)-div;
  119. + factor = UCHCOM_BAUDBASE_FACTOR / rate;
  120. + prescaler = UCHCOM_BAUDBASE_DIVMAX;
  121. +
  122. + while ((factor > 0xfff0) && prescaler) {
  123. + factor >>= 3;
  124. + prescaler--;
  125. }
  126. + if (factor > 0xfff0)
  127. + return -1;
  128.  
  129. - mod = UCHCOM_BPS_MOD_BASE/rate + UCHCOM_BPS_MOD_BASE_OFS;
  130. - mod = mod + mod/2;
  131. + factor = 0x10000 - factor;
  132. + dp->dv_prescaler = prescaler;
  133. + dp->dv_div = (factor & 0xff00) >> 8;
  134. + dp->dv_mod = factor & 0xff;
  135.  
  136. - dp->dv_mod = mod / 0x100;
  137. -
  138. return 0;
  139. }
  140.  
  141. @@ -859,6 +837,10 @@ uchcom_setup_comm(struct uchcom_softc *sc)
  142. if (ret)
  143. return ret;
  144.  
  145. + ret = uchcom_read_status(sc, NULL);
  146. + if (ret)
  147. + return ret;
  148. +
  149. return 0;
  150. }
  151.  
  152. @@ -949,7 +931,7 @@ uchcom_param(void *arg, int portno, struct termios *t)
  153. {
  154. struct uchcom_softc *sc = arg;
  155. int ret;
  156. -
  157. +return 0; // XXX
  158. if (usbd_is_dying(sc->sc_udev))
  159. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement