1 /* $Id: timer.c,v 1.3.6.1 2001/09/23 22:24:59 kai Exp $
3 * Copyright (C) 1996 SpellCaster Telecommunications Inc.
5 * This software may be used and distributed according to the terms
6 * of the GNU General Public License, incorporated herein by reference.
8 * For more information, please contact gpl-info@spellcast.com or write:
10 * SpellCaster Telecommunications Inc.
11 * 5621 Finch Avenue East, Unit #3
12 * Scarborough, Ontario Canada
15 * +1 (416) 297-6433 Facsimile
23 extern board
*sc_adapter
[];
25 extern void flushreadfifo(int);
26 extern int startproc(int);
27 extern int indicate_status(int, int, unsigned long, char *);
28 extern int sendmessage(int, unsigned int, unsigned int, unsigned int,
29 unsigned int, unsigned int, unsigned int, unsigned int *);
33 * Write the proper values into the I/O ports following a reset
35 void setup_ports(int card
)
38 outb((sc_adapter
[card
]->rambase
>> 12), sc_adapter
[card
]->ioport
[EXP_BASE
]);
41 outb((sc_adapter
[card
]->interrupt
| 0x80),
42 sc_adapter
[card
]->ioport
[IRQ_SELECT
]);
46 * Timed function to check the status of a previous reset
47 * Must be very fast as this function runs in the context of
48 * an interrupt handler.
50 * Setup the ioports for the board that were cleared by the reset.
51 * Then, check to see if the signate has been set. Next, set the
52 * signature to a known value and issue a startproc if needed.
54 void check_reset(unsigned long data
)
58 int card
= (unsigned int) data
;
60 pr_debug("%s: check_timer timer called\n",
61 sc_adapter
[card
]->devicename
);
63 /* Setup the io ports */
66 spin_lock_irqsave(&sc_adapter
[card
]->lock
, flags
);
67 outb(sc_adapter
[card
]->ioport
[sc_adapter
[card
]->shmem_pgport
],
68 (sc_adapter
[card
]->shmem_magic
>>14) | 0x80);
69 sig
= (unsigned long) *((unsigned long *)(sc_adapter
[card
]->rambase
+ SIG_OFFSET
));
71 /* check the signature */
72 if(sig
== SIGNATURE
) {
74 spin_unlock_irqrestore(&sc_adapter
[card
]->lock
, flags
);
75 /* See if we need to do a startproc */
76 if (sc_adapter
[card
]->StartOnReset
)
79 pr_debug("%s: No signature yet, waiting another %d jiffies.\n",
80 sc_adapter
[card
]->devicename
, CHECKRESET_TIME
);
81 mod_timer(&sc_adapter
[card
]->reset_timer
, jiffies
+CHECKRESET_TIME
);
82 spin_unlock_irqrestore(&sc_adapter
[card
]->lock
, flags
);
87 * Timed function to check the status of a previous reset
88 * Must be very fast as this function runs in the context of
89 * an interrupt handler.
91 * Send check sc_adapter->phystat to see if the channels are up
92 * If they are, tell ISDN4Linux that the board is up. If not,
93 * tell IADN4Linux that it is up. Always reset the timer to
94 * fire again (endless loop).
96 void check_phystat(unsigned long data
)
99 int card
= (unsigned int) data
;
101 pr_debug("%s: Checking status...\n", sc_adapter
[card
]->devicename
);
103 * check the results of the last PhyStat and change only if
104 * has changed drastically
106 if (sc_adapter
[card
]->nphystat
&& !sc_adapter
[card
]->phystat
) { /* All is well */
107 pr_debug("PhyStat transition to RUN\n");
108 pr_info("%s: Switch contacted, transmitter enabled\n",
109 sc_adapter
[card
]->devicename
);
110 indicate_status(card
, ISDN_STAT_RUN
, 0, NULL
);
112 else if (!sc_adapter
[card
]->nphystat
&& sc_adapter
[card
]->phystat
) { /* All is not well */
113 pr_debug("PhyStat transition to STOP\n");
114 pr_info("%s: Switch connection lost, transmitter disabled\n",
115 sc_adapter
[card
]->devicename
);
117 indicate_status(card
, ISDN_STAT_STOP
, 0, NULL
);
120 sc_adapter
[card
]->phystat
= sc_adapter
[card
]->nphystat
;
122 /* Reinitialize the timer */
123 spin_lock_irqsave(&sc_adapter
[card
]->lock
, flags
);
124 mod_timer(&sc_adapter
[card
]->stat_timer
, jiffies
+CHECKSTAT_TIME
);
125 spin_unlock_irqrestore(&sc_adapter
[card
]->lock
, flags
);
127 /* Send a new cePhyStatus message */
128 sendmessage(card
, CEPID
,ceReqTypePhy
,ceReqClass2
,
129 ceReqPhyStatus
,0,0,NULL
);
133 * When in trace mode, this callback is used to swap the working shared
134 * RAM page to the trace page(s) and process all received messages. It
135 * must be called often enough to get all of the messages out of RAM before
137 * Trace messages are \n terminated strings.
138 * We output the messages in 64 byte chunks through readstat. Each chunk
139 * is scanned for a \n followed by a time stamp. If the timerstamp is older
140 * than the current time, scanning stops and the page and offset are recorded
141 * as the starting point the next time the trace timer is called. The final
142 * step is to restore the working page and reset the timer.
144 void trace_timer(unsigned long data
)
146 /* not implemented */