1 /* $Id: arcofi.c,v 1.14.2.3 2004/01/13 14:31:24 keil Exp $
3 * Ansteuerung ARCOFI 2165
6 * Copyright by Karsten Keil <keil@isdn4linux.de>
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
18 #define ARCOFI_TIMER_VALUE 20
21 add_arcofi_timer(struct IsdnCardState *cs) {
22 if (test_and_set_bit(FLG_ARCOFI_TIMER, &cs->HW_Flags)) {
23 del_timer(&cs->dc.isac.arcofitimer);
25 init_timer(&cs->dc.isac.arcofitimer);
26 cs->dc.isac.arcofitimer.expires = jiffies + ((ARCOFI_TIMER_VALUE * HZ)/1000);
27 add_timer(&cs->dc.isac.arcofitimer);
31 send_arcofi(struct IsdnCardState *cs) {
35 cs->dc.isac.mon_txp = 0;
36 cs->dc.isac.mon_txc = cs->dc.isac.arcofi_list->len;
37 memcpy(cs->dc.isac.mon_tx, cs->dc.isac.arcofi_list->msg, cs->dc.isac.mon_txc);
38 switch(cs->dc.isac.arcofi_bc) {
40 case 1: cs->dc.isac.mon_tx[1] |= 0x40;
44 cs->dc.isac.mocr &= 0x0f;
45 cs->dc.isac.mocr |= 0xa0;
46 cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
47 val = cs->readisac(cs, ISAC_MOSR);
48 cs->writeisac(cs, ISAC_MOX1, cs->dc.isac.mon_tx[cs->dc.isac.mon_txp++]);
49 cs->dc.isac.mocr |= 0x10;
50 cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
54 arcofi_fsm(struct IsdnCardState *cs, int event, void *data) {
55 if (cs->debug & L1_DEB_MONITOR) {
56 debugl1(cs, "arcofi state %d event %d", cs->dc.isac.arcofi_state, event);
58 if (event == ARCOFI_TIMEOUT) {
59 cs->dc.isac.arcofi_state = ARCOFI_NOP;
60 test_and_set_bit(FLG_ARCOFI_ERROR, &cs->HW_Flags);
61 wake_up(&cs->dc.isac.arcofi_wait);
64 switch (cs->dc.isac.arcofi_state) {
66 if (event == ARCOFI_START) {
67 cs->dc.isac.arcofi_list = data;
68 cs->dc.isac.arcofi_state = ARCOFI_TRANSMIT;
73 if (event == ARCOFI_TX_END) {
74 if (cs->dc.isac.arcofi_list->receive) {
76 cs->dc.isac.arcofi_state = ARCOFI_RECEIVE;
78 if (cs->dc.isac.arcofi_list->next) {
79 cs->dc.isac.arcofi_list =
80 cs->dc.isac.arcofi_list->next;
83 if (test_and_clear_bit(FLG_ARCOFI_TIMER, &cs->HW_Flags)) {
84 del_timer(&cs->dc.isac.arcofitimer);
86 cs->dc.isac.arcofi_state = ARCOFI_NOP;
87 wake_up(&cs->dc.isac.arcofi_wait);
93 if (event == ARCOFI_RX_END) {
94 if (cs->dc.isac.arcofi_list->next) {
95 cs->dc.isac.arcofi_list =
96 cs->dc.isac.arcofi_list->next;
97 cs->dc.isac.arcofi_state = ARCOFI_TRANSMIT;
100 if (test_and_clear_bit(FLG_ARCOFI_TIMER, &cs->HW_Flags)) {
101 del_timer(&cs->dc.isac.arcofitimer);
103 cs->dc.isac.arcofi_state = ARCOFI_NOP;
104 wake_up(&cs->dc.isac.arcofi_wait);
109 debugl1(cs, "Arcofi unknown state %x", cs->dc.isac.arcofi_state);
116 arcofi_timer(struct IsdnCardState *cs) {
117 arcofi_fsm(cs, ARCOFI_TIMEOUT, NULL);
121 clear_arcofi(struct IsdnCardState *cs) {
122 if (test_and_clear_bit(FLG_ARCOFI_TIMER, &cs->HW_Flags)) {
123 del_timer(&cs->dc.isac.arcofitimer);
128 init_arcofi(struct IsdnCardState *cs) {
129 cs->dc.isac.arcofitimer.function = (void *) arcofi_timer;
130 cs->dc.isac.arcofitimer.data = (long) cs;
131 init_timer(&cs->dc.isac.arcofitimer);
132 init_waitqueue_head(&cs->dc.isac.arcofi_wait);
133 test_and_set_bit(HW_ARCOFI, &cs->HW_Flags);