arcofi.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* $Id: arcofi.c,v 1.14.2.3 2004/01/13 14:31:24 keil Exp $
  2. *
  3. * Ansteuerung ARCOFI 2165
  4. *
  5. * Author Karsten Keil
  6. * Copyright by Karsten Keil <keil@isdn4linux.de>
  7. *
  8. * This software may be used and distributed according to the terms
  9. * of the GNU General Public License, incorporated herein by reference.
  10. *
  11. */
  12. #include <linux/sched.h>
  13. #include "hisax.h"
  14. #include "isdnl1.h"
  15. #include "isac.h"
  16. #include "arcofi.h"
  17. #define ARCOFI_TIMER_VALUE 20
  18. static void
  19. add_arcofi_timer(struct IsdnCardState *cs) {
  20. if (test_and_set_bit(FLG_ARCOFI_TIMER, &cs->HW_Flags)) {
  21. del_timer(&cs->dc.isac.arcofitimer);
  22. }
  23. init_timer(&cs->dc.isac.arcofitimer);
  24. cs->dc.isac.arcofitimer.expires = jiffies + ((ARCOFI_TIMER_VALUE * HZ)/1000);
  25. add_timer(&cs->dc.isac.arcofitimer);
  26. }
  27. static void
  28. send_arcofi(struct IsdnCardState *cs) {
  29. add_arcofi_timer(cs);
  30. cs->dc.isac.mon_txp = 0;
  31. cs->dc.isac.mon_txc = cs->dc.isac.arcofi_list->len;
  32. memcpy(cs->dc.isac.mon_tx, cs->dc.isac.arcofi_list->msg, cs->dc.isac.mon_txc);
  33. switch(cs->dc.isac.arcofi_bc) {
  34. case 0: break;
  35. case 1: cs->dc.isac.mon_tx[1] |= 0x40;
  36. break;
  37. default: break;
  38. }
  39. cs->dc.isac.mocr &= 0x0f;
  40. cs->dc.isac.mocr |= 0xa0;
  41. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  42. (void) cs->readisac(cs, ISAC_MOSR);
  43. cs->writeisac(cs, ISAC_MOX1, cs->dc.isac.mon_tx[cs->dc.isac.mon_txp++]);
  44. cs->dc.isac.mocr |= 0x10;
  45. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  46. }
  47. int
  48. arcofi_fsm(struct IsdnCardState *cs, int event, void *data) {
  49. if (cs->debug & L1_DEB_MONITOR) {
  50. debugl1(cs, "arcofi state %d event %d", cs->dc.isac.arcofi_state, event);
  51. }
  52. if (event == ARCOFI_TIMEOUT) {
  53. cs->dc.isac.arcofi_state = ARCOFI_NOP;
  54. test_and_set_bit(FLG_ARCOFI_ERROR, &cs->HW_Flags);
  55. wake_up(&cs->dc.isac.arcofi_wait);
  56. return(1);
  57. }
  58. switch (cs->dc.isac.arcofi_state) {
  59. case ARCOFI_NOP:
  60. if (event == ARCOFI_START) {
  61. cs->dc.isac.arcofi_list = data;
  62. cs->dc.isac.arcofi_state = ARCOFI_TRANSMIT;
  63. send_arcofi(cs);
  64. }
  65. break;
  66. case ARCOFI_TRANSMIT:
  67. if (event == ARCOFI_TX_END) {
  68. if (cs->dc.isac.arcofi_list->receive) {
  69. add_arcofi_timer(cs);
  70. cs->dc.isac.arcofi_state = ARCOFI_RECEIVE;
  71. } else {
  72. if (cs->dc.isac.arcofi_list->next) {
  73. cs->dc.isac.arcofi_list =
  74. cs->dc.isac.arcofi_list->next;
  75. send_arcofi(cs);
  76. } else {
  77. if (test_and_clear_bit(FLG_ARCOFI_TIMER, &cs->HW_Flags)) {
  78. del_timer(&cs->dc.isac.arcofitimer);
  79. }
  80. cs->dc.isac.arcofi_state = ARCOFI_NOP;
  81. wake_up(&cs->dc.isac.arcofi_wait);
  82. }
  83. }
  84. }
  85. break;
  86. case ARCOFI_RECEIVE:
  87. if (event == ARCOFI_RX_END) {
  88. if (cs->dc.isac.arcofi_list->next) {
  89. cs->dc.isac.arcofi_list =
  90. cs->dc.isac.arcofi_list->next;
  91. cs->dc.isac.arcofi_state = ARCOFI_TRANSMIT;
  92. send_arcofi(cs);
  93. } else {
  94. if (test_and_clear_bit(FLG_ARCOFI_TIMER, &cs->HW_Flags)) {
  95. del_timer(&cs->dc.isac.arcofitimer);
  96. }
  97. cs->dc.isac.arcofi_state = ARCOFI_NOP;
  98. wake_up(&cs->dc.isac.arcofi_wait);
  99. }
  100. }
  101. break;
  102. default:
  103. debugl1(cs, "Arcofi unknown state %x", cs->dc.isac.arcofi_state);
  104. return(2);
  105. }
  106. return(0);
  107. }
  108. static void
  109. arcofi_timer(struct IsdnCardState *cs) {
  110. arcofi_fsm(cs, ARCOFI_TIMEOUT, NULL);
  111. }
  112. void
  113. clear_arcofi(struct IsdnCardState *cs) {
  114. if (test_and_clear_bit(FLG_ARCOFI_TIMER, &cs->HW_Flags)) {
  115. del_timer(&cs->dc.isac.arcofitimer);
  116. }
  117. }
  118. void
  119. init_arcofi(struct IsdnCardState *cs) {
  120. cs->dc.isac.arcofitimer.function = (void *) arcofi_timer;
  121. cs->dc.isac.arcofitimer.data = (long) cs;
  122. init_timer(&cs->dc.isac.arcofitimer);
  123. init_waitqueue_head(&cs->dc.isac.arcofi_wait);
  124. test_and_set_bit(HW_ARCOFI, &cs->HW_Flags);
  125. }