/[H8]/trunk/docs/Microchip TCP_IP stack v4.02/TCPIP Stack/Tick.c
ViewVC logotype

Annotation of /trunk/docs/Microchip TCP_IP stack v4.02/TCPIP Stack/Tick.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 53 - (hide annotations) (download)
Fri Apr 27 06:32:59 2007 UTC (17 years, 2 months ago) by torben
File MIME type: text/plain
File size: 5569 byte(s)


1 hedin 15 /*********************************************************************
2     *
3     * Tick Manager for Loose Timekeeping
4     *
5     *********************************************************************
6     * FileName: Tick.c
7     * Dependencies: stackTSK.h
8     * Tick.h
9     * Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F
10     * Complier: Microchip C18 v3.02 or higher
11     * Microchip C30 v2.01 or higher
12     * Company: Microchip Technology, Inc.
13     *
14     * Software License Agreement
15     *
16     * Copyright © 2002-2007 Microchip Technology Inc. All rights
17     * reserved.
18     *
19     * Microchip licenses to you the right to use, modify, copy, and
20     * distribute:
21     * (i) the Software when embedded on a Microchip microcontroller or
22     * digital signal controller product (“Device”) which is
23     * integrated into Licensee’s product; or
24     * (ii) ONLY the Software driver source files ENC28J60.c and
25     * ENC28J60.h ported to a non-Microchip device used in
26     * conjunction with a Microchip ethernet controller for the
27     * sole purpose of interfacing with the ethernet controller.
28     *
29     * You should refer to the license agreement accompanying this
30     * Software for additional information regarding your rights and
31     * obligations.
32     *
33     * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT
34     * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
35     * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
36     * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
37     * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
38     * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
39     * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
40     * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
41     * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
42     * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
43     * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
44     *
45     *
46     * Author Date Comment
47     *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48     * Nilesh Rajbharti 6/28/01 Original (Rev 1.0)
49     * Nilesh Rajbharti 2/9/02 Cleanup
50     * Nilesh Rajbharti 5/22/02 Rev 2.0 (See version.log for detail)
51     ********************************************************************/
52     #define __TICK_C
53    
54     #include "TCPIP Stack/TCPIP.h"
55    
56     static volatile TICK TickCount = 0;
57    
58    
59     /*********************************************************************
60     * Function: void TickInit(void)
61     *
62     * PreCondition: None
63     *
64     * Input: None
65     *
66     * Output: Tick manager is initialized.
67     *
68     * Side Effects: None
69     *
70     * Overview: Initializes Timer0 as a tick counter.
71     *
72     * Note: None
73     ********************************************************************/
74     #define PERIOD ((WORD)((INSTR_FREQ+32+TICKS_PER_SECOND/2)/64/TICKS_PER_SECOND))
75     #define TICK_LOAD ((WORD)((-(INSTR_FREQ+2+TICKS_PER_SECOND/2)/4/TICKS_PER_SECOND)+4))
76     void TickInit(void)
77     {
78     #ifdef __C30__
79     // Set up timer1 to wake up by timeout
80     // 1:64 prescale
81     T1CONbits.TCKPS = 2;
82     // Base
83     PR1 = (WORD)PERIOD;
84     // Clear counter
85     TMR1 = 0;
86     // Enable timer interrupt
87     IFS0bits.T1IF = 0;
88     IEC0bits.T1IE = 1;
89     // Start timer
90     T1CONbits.TON = 1;
91     #else
92     // Initialize the time
93     TMR0H = (TICK_LOAD & 0xFF00)>>8;
94     TMR0L = TICK_LOAD & 0xFF;
95    
96     // Set up the timer interrupt
97     INTCON2bits.TMR0IP = 0; // Low priority
98     INTCONbits.TMR0IF = 0;
99     INTCONbits.TMR0IE = 1; // Enable interrupt
100    
101     // Timer0 on, 16-bit, internal timer, 4:1 prescalar
102     T0CON = 0x81;
103     #endif
104     }
105    
106    
107     /*********************************************************************
108     * Function: TICK TickGet(void)
109     *
110     * PreCondition: None
111     *
112     * Input: None
113     *
114     * Output: Current tick value is given
115     * 1 tick represents approximately 10ms
116     *
117     * Side Effects: None
118     *
119     * Overview: None
120     *
121     * Note: None
122     ********************************************************************/
123     TICK TickGet(void)
124     {
125     return TickCount;
126     }
127    
128    
129     /*********************************************************************
130     * Function: void TickUpdate(void)
131     *
132     * PreCondition: None
133     *
134     * Input: None
135     *
136     * Output: None
137     *
138     * Side Effects: None
139     *
140     * Overview: Internal Tick and Seconds count are updated.
141     *
142     * Note: None
143     ********************************************************************/
144     #ifdef __18CXX
145     void TickUpdate(void)
146     {
147     WORD_VAL TMR0Val;
148    
149     if(INTCONbits.TMR0IF)
150     {
151     TMR0Val.v[0] = TMR0L;
152     TMR0Val.v[1] = TMR0H;
153     TMR0Val.Val += (WORD)TICK_LOAD;
154     TMR0H = TMR0Val.v[1];
155     TMR0L = TMR0Val.v[0];
156    
157     TickCount++;
158    
159     INTCONbits.TMR0IF = 0;
160     }
161     }
162    
163     #else
164     /*********************************************************************
165     * Function: void _ISR _T1Interrupt(void)
166     *
167     * PreCondition: None
168     *
169     * Input: None
170     *
171     * Output: TickCount variable is updated
172     *
173     * Side Effects: None
174     *
175     * Overview: None
176     *
177     * Note: None
178     ********************************************************************/
179     #if __C30_VERSION__ >= 300
180     void _ISR __attribute__((__no_auto_psv__)) _T1Interrupt(void)
181     #else
182     void _ISR _T1Interrupt(void)
183     #endif
184     {
185     TickCount++;
186     // Reset interrupt flag
187     IFS0bits.T1IF = 0;
188     return;
189     }
190     #endif

  ViewVC Help
Powered by ViewVC 1.1.20