1 /* $Id: timer.c,v 1.1.4.1 2001/11/20 14:19:37 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
18 #define __NO_VERSION__
24 extern board *adapter[];
26 extern void flushreadfifo(int);
27 extern int startproc(int);
28 extern int indicate_status(int, int, unsigned long, char *);
29 extern int sendmessage(int, unsigned int, unsigned int, unsigned int,
30 unsigned int, unsigned int, unsigned int, unsigned int *);
34 * Write the proper values into the I/O ports following a reset
36 void setup_ports(int card)
39 outb((adapter[card]->rambase >> 12), adapter[card]->ioport[EXP_BASE]);
42 outb((adapter[card]->interrupt | 0x80),
43 adapter[card]->ioport[IRQ_SELECT]);
47 * Timed function to check the status of a previous reset
48 * Must be very fast as this function runs in the context of
49 * an interrupt handler.
51 * Setup the ioports for the board that were cleared by the reset.
52 * Then, check to see if the signate has been set. Next, set the
53 * signature to a known value and issue a startproc if needed.
55 void check_reset(unsigned long data)
59 int card = (unsigned int) data;
61 pr_debug("%s: check_timer timer called\n", adapter[card]->devicename);
63 /* Setup the io ports */
68 outb(adapter[card]->ioport[adapter[card]->shmem_pgport],
69 (adapter[card]->shmem_magic>>14) | 0x80);
70 sig = (unsigned long) *((unsigned long *)(adapter[card]->rambase + SIG_OFFSET));
72 /* check the signature */
73 if(sig == SIGNATURE) {
76 /* See if we need to do a startproc */
77 if (adapter[card]->StartOnReset)
81 pr_debug("%s: No signature yet, waiting another %d jiffies.\n",
82 adapter[card]->devicename, CHECKRESET_TIME);
83 mod_timer(&adapter[card]->reset_timer, jiffies+CHECKRESET_TIME);
90 * Timed function to check the status of a previous reset
91 * Must be very fast as this function runs in the context of
92 * an interrupt handler.
94 * Send check adapter->phystat to see if the channels are up
95 * If they are, tell ISDN4Linux that the board is up. If not,
96 * tell IADN4Linux that it is up. Always reset the timer to
97 * fire again (endless loop).
99 void check_phystat(unsigned long data)
102 int card = (unsigned int) data;
104 pr_debug("%s: Checking status...\n", adapter[card]->devicename);
106 * check the results of the last PhyStat and change only if
107 * has changed drastically
109 if (adapter[card]->nphystat && !adapter[card]->phystat) { /* All is well */
110 pr_debug("PhyStat transition to RUN\n");
111 pr_info("%s: Switch contacted, transmitter enabled\n",
112 adapter[card]->devicename);
113 indicate_status(card, ISDN_STAT_RUN, 0, NULL);
115 else if (!adapter[card]->nphystat && adapter[card]->phystat) { /* All is not well */
116 pr_debug("PhyStat transition to STOP\n");
117 pr_info("%s: Switch connection lost, transmitter disabled\n",
118 adapter[card]->devicename);
120 indicate_status(card, ISDN_STAT_STOP, 0, NULL);
123 adapter[card]->phystat = adapter[card]->nphystat;
125 /* Reinitialize the timer */
128 mod_timer(&adapter[card]->stat_timer, jiffies+CHECKSTAT_TIME);
129 restore_flags(flags);
131 /* Send a new cePhyStatus message */
132 sendmessage(card, CEPID,ceReqTypePhy,ceReqClass2,
133 ceReqPhyStatus,0,0,NULL);
137 * When in trace mode, this callback is used to swap the working shared
138 * RAM page to the trace page(s) and process all received messages. It
139 * must be called often enough to get all of the messages out of RAM before
141 * Trace messages are \n terminated strings.
142 * We output the messages in 64 byte chunks through readstat. Each chunk
143 * is scanned for a \n followed by a time stamp. If the timerstamp is older
144 * than the current time, scanning stops and the page and offset are recorded
145 * as the starting point the next time the trace timer is called. The final
146 * step is to restore the working page and reset the timer.
148 void trace_timer(unsigned long data)
153 * Disable interrupts and swap the first page