/[H8]/trunk/docs/MCHPStack2.20/Source/Helpers.c
ViewVC logotype

Annotation of /trunk/docs/MCHPStack2.20/Source/Helpers.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (hide annotations) (download)
Tue May 1 08:17:39 2007 UTC (17 years, 2 months ago) by hedin
File MIME type: text/plain
File size: 3777 byte(s)
Removed tcpip stack 4.02 and added tcpip stack 2.20.
1 hedin 62 /*********************************************************************
2     *
3     * Helper Functions for Microchip TCP/IP Stack
4     *
5     *********************************************************************
6     * FileName: Helpers.C
7     * Dependencies: compiler.h
8     * helpers.h
9     * Processor: PIC18
10     * Complier: MCC18 v1.00.50 or higher
11     * HITECH PICC-18 V8.10PL1 or higher
12     * Company: Microchip Technology, Inc.
13     *
14     * Software License Agreement
15     *
16     * The software supplied herewith by Microchip Technology Incorporated
17     * (the “Company”) for its PICmicro® Microcontroller is intended and
18     * supplied to you, the Company’s customer, for use solely and
19     * exclusively on Microchip PICmicro Microcontroller products. The
20     * software is owned by the Company and/or its supplier, and is
21     * protected under applicable copyright laws. All rights are reserved.
22     * Any use in violation of the foregoing restrictions may subject the
23     * user to criminal sanctions under applicable laws, as well as to
24     * civil liability for the breach of the terms and conditions of this
25     * license.
26     *
27     * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
28     * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
29     * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
30     * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
31     * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
32     * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
33     *
34     * HiTech PICC18 Compiler Options excluding device selection:
35     * -FAKELOCAL -G -E -C
36     *
37     *
38     *
39     * Author Date Comment
40     *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41     * Nilesh Rajbharti 5/17/01 Original (Rev 1.0)
42     * Nilesh Rajbharti 2/9/02 Cleanup
43     * Nilesh Rajbharti 6/25/02 Rewritten CalcIPChecksum() to avoid
44     * multi-byte shift operation.
45     ********************************************************************/
46    
47     #include "compiler.h"
48     #include "helpers.h"
49    
50    
51     WORD swaps(WORD v)
52     {
53     WORD_VAL t;
54     BYTE b;
55    
56     t.Val = v;
57     b = t.v[1];
58     t.v[1] = t.v[0];
59     t.v[0] = b;
60    
61     return t.Val;
62     }
63    
64    
65     DWORD swapl(DWORD v)
66     {
67     BYTE b;
68     DWORD myV;
69     DWORD_VAL *myP;
70    
71     myV = v;
72     myP = (DWORD_VAL*)&myV;
73    
74     b = myP->v[3];
75     myP->v[3] = myP->v[0];
76     myP->v[0] = b;
77    
78     b = myP->v[2];
79     myP->v[2] = myP->v[1];
80     myP->v[1] = b;
81    
82     return myV;
83    
84     }
85    
86     WORD CalcIPChecksum(BYTE* buffer, WORD count)
87     {
88     WORD i;
89     WORD *val;
90    
91     union
92     {
93     DWORD Val;
94     struct
95     {
96     WORD_VAL LSB;
97     WORD_VAL MSB;
98     } words;
99     } tempSum, sum;
100    
101     sum.Val = 0;
102    
103     i = count >> 1;
104     val = (WORD *)buffer;
105    
106     while( i-- )
107     sum.Val += *val++;
108    
109     if ( count & 1 )
110     sum.Val += *(BYTE *)val;
111    
112     tempSum.Val = sum.Val;
113    
114     while( (i = tempSum.words.MSB.Val) != 0 )
115     {
116     sum.words.MSB.Val = 0;
117     sum.Val = (DWORD)sum.words.LSB.Val + (DWORD)i;
118     tempSum.Val = sum.Val;
119     }
120    
121     return (~sum.words.LSB.Val);
122     }
123    
124    
125     #if defined(HITECH_C18)
126     char *strupr (char *s)
127     {
128     char c;
129     char *t;
130    
131     t = s;
132     while( (c = *t) )
133     {
134     if ( (c >= 'a' && c <= 'z') )
135     *t -= ('a' - 'A');
136     t++;
137     }
138     return s;
139     }
140     #endif
141    
142    
143     #if defined(HITECH_C18)
144     void *mymemcpy(void * d1, const void * s1, register unsigned char n)
145     {
146    
147     register char * d;
148     register const char * s;
149    
150     s = s1;
151     d = d1;
152     while(n--)
153     *d++ = *s++;
154     return d1;
155     }
156     #endif

  ViewVC Help
Powered by ViewVC 1.1.20