-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatmelwebserver.asm
6703 lines (6483 loc) · 160 KB
/
atmelwebserver.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;CodeVisionAVR C Compiler V1.23.8d Standard
;(C) Copyright 1998-2003 HP InfoTech s.r.l.
;http://www.hpinfotech.ro
;e-mail:[email protected]
;Chip type : ATmega32
;Program type : Application
;Clock frequency : 16.000000 MHz
;Memory model : Small
;Optimize for : Size
;(s)printf features : int
;(s)scanf features : int, width
;External SRAM size : 0
;Data Stack size : 512
;Promote char to int : No
;char is unsigned : Yes
;8 bit enums : No
;Enhanced core instructions : On
;Automatic register allocation : On
;Use AVR Studio Terminal I/O : No
.LISTMAC
.EQU UDRE=0x5
.EQU RXC=0x7
.EQU USR=0xB
.EQU UDR=0xC
.EQU EERE=0x0
.EQU EEWE=0x1
.EQU EEMWE=0x2
.EQU SPSR=0xE
.EQU SPDR=0xF
.EQU EECR=0x1C
.EQU EEDR=0x1D
.EQU EEARL=0x1E
.EQU EEARH=0x1F
.EQU WDTCR=0x21
.EQU MCUCR=0x35
.EQU GICR=0x3B
.EQU SPL=0x3D
.EQU SPH=0x3E
.EQU SREG=0x3F
.DEF R0X0=R0
.DEF R0X1=R1
.DEF R0X2=R2
.DEF R0X3=R3
.DEF R0X4=R4
.DEF R0X5=R5
.DEF R0X6=R6
.DEF R0X7=R7
.DEF R0X8=R8
.DEF R0X9=R9
.DEF R0XA=R10
.DEF R0XB=R11
.DEF R0XC=R12
.DEF R0XD=R13
.DEF R0XE=R14
.DEF R0XF=R15
.DEF R0X10=R16
.DEF R0X11=R17
.DEF R0X12=R18
.DEF R0X13=R19
.DEF R0X14=R20
.DEF R0X15=R21
.DEF R0X16=R22
.DEF R0X17=R23
.DEF R0X18=R24
.DEF R0X19=R25
.DEF R0X1A=R26
.DEF R0X1B=R27
.DEF R0X1C=R28
.DEF R0X1D=R29
.DEF R0X1E=R30
.DEF R0X1F=R31
.EQU __se_bit=0x80
.EQU __sm_mask=0x30
.EQU __sm_powerdown=0x20
.MACRO __CPD1N
CPI R30,LOW(@0)
LDI R26,HIGH(@0)
CPC R31,R26
LDI R26,BYTE3(@0)
CPC R22,R26
LDI R26,BYTE4(@0)
CPC R23,R26
.ENDM
.MACRO __CPD2N
CPI R26,LOW(@0)
LDI R30,HIGH(@0)
CPC R27,R30
LDI R30,BYTE3(@0)
CPC R24,R30
LDI R30,BYTE4(@0)
CPC R25,R30
.ENDM
.MACRO __CPWRR
CP R@0,R@2
CPC R@1,R@3
.ENDM
.MACRO __CPWRN
CPI R@0,LOW(@2)
LDI R30,HIGH(@2)
CPC R@1,R30
.ENDM
.MACRO __ADDD1N
SUBI R30,LOW(-@0)
SBCI R31,HIGH(-@0)
SBCI R22,BYTE3(-@0)
SBCI R23,BYTE4(-@0)
.ENDM
.MACRO __ADDD2N
SUBI R26,LOW(-@0)
SBCI R27,HIGH(-@0)
SBCI R24,BYTE3(-@0)
SBCI R25,BYTE4(-@0)
.ENDM
.MACRO __SUBD1N
SUBI R30,LOW(@0)
SBCI R31,HIGH(@0)
SBCI R22,BYTE3(@0)
SBCI R23,BYTE4(@0)
.ENDM
.MACRO __SUBD2N
SUBI R26,LOW(@0)
SBCI R27,HIGH(@0)
SBCI R24,BYTE3(@0)
SBCI R25,BYTE4(@0)
.ENDM
.MACRO __ANDD1N
ANDI R30,LOW(@0)
ANDI R31,HIGH(@0)
ANDI R22,BYTE3(@0)
ANDI R23,BYTE4(@0)
.ENDM
.MACRO __ORD1N
ORI R30,LOW(@0)
ORI R31,HIGH(@0)
ORI R22,BYTE3(@0)
ORI R23,BYTE4(@0)
.ENDM
.MACRO __DELAY_USB
LDI R24,LOW(@0)
__DELAY_USB_LOOP:
DEC R24
BRNE __DELAY_USB_LOOP
.ENDM
.MACRO __DELAY_USW
LDI R24,LOW(@0)
LDI R25,HIGH(@0)
__DELAY_USW_LOOP:
SBIW R24,1
BRNE __DELAY_USW_LOOP
.ENDM
.MACRO __CLRD1S
CLR R30
STD Y+@0,R30
STD Y+@0+1,R30
STD Y+@0+2,R30
STD Y+@0+3,R30
.ENDM
.MACRO __GETD1S
LDD R30,Y+@0
LDD R31,Y+@0+1
LDD R22,Y+@0+2
LDD R23,Y+@0+3
.ENDM
.MACRO __PUTD1S
STD Y+@0,R30
STD Y+@0+1,R31
STD Y+@0+2,R22
STD Y+@0+3,R23
.ENDM
.MACRO __POINTB1MN
LDI R30,LOW(@0+@1)
.ENDM
.MACRO __POINTW1MN
LDI R30,LOW(@0+@1)
LDI R31,HIGH(@0+@1)
.ENDM
.MACRO __POINTW1FN
LDI R30,LOW(2*@0+@1)
LDI R31,HIGH(2*@0+@1)
.ENDM
.MACRO __POINTB2MN
LDI R26,LOW(@0+@1)
.ENDM
.MACRO __POINTW2MN
LDI R26,LOW(@0+@1)
LDI R27,HIGH(@0+@1)
.ENDM
.MACRO __GETD1N
LDI R30,LOW(@0)
LDI R31,HIGH(@0)
LDI R22,BYTE3(@0)
LDI R23,BYTE4(@0)
.ENDM
.MACRO __GETD2N
LDI R26,LOW(@0)
LDI R27,HIGH(@0)
LDI R24,BYTE3(@0)
LDI R25,BYTE4(@0)
.ENDM
.MACRO __GETD2S
LDD R26,Y+@0
LDD R27,Y+@0+1
LDD R24,Y+@0+2
LDD R25,Y+@0+3
.ENDM
.MACRO __GETB1MN
LDS R30,@0+@1
.ENDM
.MACRO __GETW1MN
LDS R30,@0+@1
LDS R31,@0+@1+1
.ENDM
.MACRO __GETD1MN
LDS R30,@0+@1
LDS R31,@0+@1+1
LDS R22,@0+@1+2
LDS R23,@0+@1+3
.ENDM
.MACRO __GETBRMN
LDS R@2,@0+@1
.ENDM
.MACRO __GETWRMN
LDS R@2,@0+@1
LDS R@3,@0+@1+1
.ENDM
.MACRO __GETB2MN
LDS R26,@0+@1
.ENDM
.MACRO __GETW2MN
LDS R26,@0+@1
LDS R27,@0+@1+1
.ENDM
.MACRO __GETD2MN
LDS R26,@0+@1
LDS R27,@0+@1+1
LDS R24,@0+@1+2
LDS R25,@0+@1+3
.ENDM
.MACRO __PUTB1MN
STS @0+@1,R30
.ENDM
.MACRO __PUTW1MN
STS @0+@1,R30
STS @0+@1+1,R31
.ENDM
.MACRO __PUTD1MN
STS @0+@1,R30
STS @0+@1+1,R31
STS @0+@1+2,R22
STS @0+@1+3,R23
.ENDM
.MACRO __PUTBMRN
STS @0+@1,R@2
.ENDM
.MACRO __PUTWMRN
STS @0+@1,R@2
STS @0+@1+1,R@3
.ENDM
.MACRO __GETW1R
MOV R30,R@0
MOV R31,R@1
.ENDM
.MACRO __GETW2R
MOV R26,R@0
MOV R27,R@1
.ENDM
.MACRO __GETWRN
LDI R@0,LOW(@2)
LDI R@1,HIGH(@2)
.ENDM
.MACRO __PUTW1R
MOV R@0,R30
MOV R@1,R31
.ENDM
.MACRO __PUTW2R
MOV R@0,R26
MOV R@1,R27
.ENDM
.MACRO __ADDWRN
SUBI R@0,LOW(-@2)
SBCI R@1,HIGH(-@2)
.ENDM
.MACRO __ADDWRR
ADD R@0,R@2
ADC R@1,R@3
.ENDM
.MACRO __SUBWRN
SUBI R@0,LOW(@2)
SBCI R@1,HIGH(@2)
.ENDM
.MACRO __SUBWRR
SUB R@0,R@2
SBC R@1,R@3
.ENDM
.MACRO __ANDWRN
ANDI R@0,LOW(@2)
ANDI R@1,HIGH(@2)
.ENDM
.MACRO __ANDWRR
AND R@0,R@2
AND R@1,R@3
.ENDM
.MACRO __ORWRN
ORI R@0,LOW(@2)
ORI R@1,HIGH(@2)
.ENDM
.MACRO __ORWRR
OR R@0,R@2
OR R@1,R@3
.ENDM
.MACRO __EORWRR
EOR R@0,R@2
EOR R@1,R@3
.ENDM
.MACRO __GETWRS
LDD R@0,Y+@2
LDD R@1,Y+@2+1
.ENDM
.MACRO __PUTWSR
STD Y+@2,R@0
STD Y+@2+1,R@1
.ENDM
.MACRO __MOVEWRR
MOV R@0,R@2
MOV R@1,R@3
.ENDM
.MACRO __INWR
IN R@0,@2
IN R@1,@2+1
.ENDM
.MACRO __OUTWR
OUT @2+1,R@1
OUT @2,R@0
.ENDM
.MACRO __CALL1MN
LDS R30,@0+@1
LDS R31,@0+@1+1
ICALL
.ENDM
.MACRO __NBST
BST R@0,@1
IN R30,SREG
LDI R31,0x40
EOR R30,R31
OUT SREG,R30
.ENDM
.MACRO __PUTB1SN
LDD R26,Y+@0
LDD R27,Y+@0+1
SUBI R26,LOW(-@1)
SBCI R27,HIGH(-@1)
ST X,R30
.ENDM
.MACRO __PUTW1SN
LDD R26,Y+@0
LDD R27,Y+@0+1
SUBI R26,LOW(-@1)
SBCI R27,HIGH(-@1)
ST X+,R30
ST X,R31
.ENDM
.MACRO __PUTD1SN
LDD R26,Y+@0
LDD R27,Y+@0+1
SUBI R26,LOW(-@1)
SBCI R27,HIGH(-@1)
CALL __PUTDP1
.ENDM
.MACRO __PUTB1SNS
LDD R26,Y+@0
LDD R27,Y+@0+1
ADIW R26,@1
ST X,R30
.ENDM
.MACRO __PUTW1SNS
LDD R26,Y+@0
LDD R27,Y+@0+1
ADIW R26,@1
ST X+,R30
ST X,R31
.ENDM
.MACRO __PUTD1SNS
LDD R26,Y+@0
LDD R27,Y+@0+1
ADIW R26,@1
CALL __PUTDP1
.ENDM
.MACRO __PUTB1PMN
LDS R26,@0
LDS R27,@0+1
SUBI R26,LOW(-@1)
SBCI R27,HIGH(-@1)
ST X,R30
.ENDM
.MACRO __PUTW1PMN
LDS R26,@0
LDS R27,@0+1
SUBI R26,LOW(-@1)
SBCI R27,HIGH(-@1)
ST X+,R30
ST X,R31
.ENDM
.MACRO __PUTD1PMN
LDS R26,@0
LDS R27,@0+1
SUBI R26,LOW(-@1)
SBCI R27,HIGH(-@1)
CALL __PUTDP1
.ENDM
.MACRO __PUTB1PMNS
LDS R26,@0
LDS R27,@0+1
ADIW R26,@1
ST X,R30
.ENDM
.MACRO __PUTW1PMNS
LDS R26,@0
LDS R27,@0+1
ADIW R26,@1
ST X+,R30
ST X,R31
.ENDM
.MACRO __PUTD1PMNS
LDS R26,@0
LDS R27,@0+1
ADIW R26,@1
CALL __PUTDP1
.ENDM
.MACRO __GETB1SX
MOVW R30,R28
SUBI R30,LOW(-@0)
SBCI R31,HIGH(-@0)
LD R30,Z
.ENDM
.MACRO __GETW1SX
MOVW R30,R28
SUBI R30,LOW(-@0)
SBCI R31,HIGH(-@0)
LD R0,Z+
LD R31,Z
MOV R30,R0
.ENDM
.MACRO __GETD1SX
MOVW R30,R28
SUBI R30,LOW(-@0)
SBCI R31,HIGH(-@0)
LD R0,Z+
LD R1,Z+
LD R22,Z+
LD R23,Z
MOVW R30,R0
.ENDM
.MACRO __GETB2SX
MOVW R26,R28
SUBI R26,LOW(-@0)
SBCI R27,HIGH(-@0)
LD R26,X
.ENDM
.MACRO __GETW2SX
MOVW R26,R28
SUBI R26,LOW(-@0)
SBCI R27,HIGH(-@0)
LD R0,X+
LD R27,X
MOV R26,R0
.ENDM
.MACRO __GETD2SX
MOVW R26,R28
SUBI R26,LOW(-@0)
SBCI R27,HIGH(-@0)
LD R0,X+
LD R1,X+
LD R24,X+
LD R25,X
MOVW R26,R0
.ENDM
.MACRO __GETBRSX
MOVW R30,R28
SUBI R30,LOW(-@1)
SBCI R31,HIGH(-@1)
LD R@0,Z
.ENDM
.MACRO __GETWRSX
MOVW R30,R28
SUBI R30,LOW(-@2)
SBCI R31,HIGH(-@2)
LD R@0,Z+
LD R@1,Z
.ENDM
.MACRO __LSLW8SX
MOVW R30,R28
SUBI R30,LOW(-@0)
SBCI R31,HIGH(-@0)
LD R31,Z
CLR R30
.ENDM
.MACRO __PUTB1SX
MOVW R26,R28
SUBI R26,LOW(-@0)
SBCI R27,HIGH(-@0)
ST X,R30
.ENDM
.MACRO __PUTW1SX
MOVW R26,R28
SUBI R26,LOW(-@0)
SBCI R27,HIGH(-@0)
ST X+,R30
ST X,R31
.ENDM
.MACRO __PUTD1SX
MOVW R26,R28
SUBI R26,LOW(-@0)
SBCI R27,HIGH(-@0)
ST X+,R30
ST X+,R31
ST X+,R22
ST X,R23
.ENDM
.MACRO __CLRW1SX
MOVW R30,R28
SUBI R30,LOW(-@0)
SBCI R31,HIGH(-@0)
CLR R0
ST Z+,R0
ST Z,R0
.ENDM
.MACRO __CLRD1SX
MOVW R30,R28
SUBI R30,LOW(-@0)
SBCI R31,HIGH(-@0)
CLR R0
ST Z+,R0
ST Z+,R0
ST Z+,R0
ST Z,R0
.ENDM
.MACRO __PUTB2SX
MOVW R30,R28
SUBI R30,LOW(-@0)
SBCI R31,HIGH(-@0)
ST Z,R26
.ENDM
.MACRO __PUTW2SX
MOVW R30,R28
SUBI R30,LOW(-@0)
SBCI R31,HIGH(-@0)
ST Z+,R26
ST Z,R27
.ENDM
.MACRO __PUTBSRX
MOVW R30,R28
SUBI R30,LOW(-@0)
SBCI R31,HIGH(-@0)
ST Z,R@1
.ENDM
.MACRO __PUTWSRX
MOVW R30,R28
SUBI R30,LOW(-@2)
SBCI R31,HIGH(-@2)
ST Z+,R@0
ST Z,R@1
.ENDM
.MACRO __PUTB1SNX
MOVW R26,R28
SUBI R26,LOW(-@0)
SBCI R27,HIGH(-@0)
LD R0,X+
LD R27,X
MOV R26,R0
SUBI R26,LOW(-@1)
SBCI R27,HIGH(-@1)
ST X,R30
.ENDM
.MACRO __PUTW1SNX
MOVW R26,R28
SUBI R26,LOW(-@0)
SBCI R27,HIGH(-@0)
LD R0,X+
LD R27,X
MOV R26,R0
SUBI R26,LOW(-@1)
SBCI R27,HIGH(-@1)
ST X+,R30
ST X,R31
.ENDM
.MACRO __PUTD1SNX
MOVW R26,R28
SUBI R26,LOW(-@0)
SBCI R27,HIGH(-@0)
LD R0,X+
LD R27,X
MOV R26,R0
SUBI R26,LOW(-@1)
SBCI R27,HIGH(-@1)
ST X+,R30
ST X+,R31
ST X+,R22
ST X,R23
.ENDM
.MACRO __MULBRR
MULS R@0,R@1
MOV R30,R0
.ENDM
.MACRO __MULBRRU
MUL R@0,R@1
MOV R30,R0
.ENDM
.CSEG
.ORG 0
.INCLUDE "atmelwebserver.vec"
.INCLUDE "atmelwebserver.inc"
__RESET:
CLI
CLR R30
OUT EECR,R30
;INTERRUPT VECTORS ARE PLACED
;AT THE START OF FLASH
LDI R31,1
OUT GICR,R31
OUT GICR,R30
OUT MCUCR,R30
;DISABLE WATCHDOG
LDI R31,0x18
OUT WDTCR,R31
LDI R31,0x10
OUT WDTCR,R31
;CLEAR R2-R14
LDI R24,13
LDI R26,2
CLR R27
__CLEAR_REG:
ST X+,R30
DEC R24
BRNE __CLEAR_REG
;CLEAR SRAM
LDI R24,LOW(0x800)
LDI R25,HIGH(0x800)
LDI R26,0x60
__CLEAR_SRAM:
ST X+,R30
SBIW R24,1
BRNE __CLEAR_SRAM
;GLOBAL VARIABLES INITIALIZATION
LDI R30,LOW(__GLOBAL_INI_TBL*2)
LDI R31,HIGH(__GLOBAL_INI_TBL*2)
__GLOBAL_INI_NEXT:
LPM R0,Z+
LPM R1,Z+
MOVW R22,R30
MOVW R30,R0
SBIW R30,0
BREQ __GLOBAL_INI_END
LPM R26,Z+
LPM R27,Z+
LPM R24,Z+
LPM R25,Z+
__GLOBAL_INI_LOOP:
LPM R0,Z+
ST X+,R0
SBIW R24,1
BRNE __GLOBAL_INI_LOOP
MOVW R30,R22
RJMP __GLOBAL_INI_NEXT
__GLOBAL_INI_END:
;STACK POINTER INITIALIZATION
LDI R30,LOW(0x85F)
OUT SPL,R30
LDI R30,HIGH(0x85F)
OUT SPH,R30
;DATA STACK POINTER INITIALIZATION
LDI R28,LOW(0x260)
LDI R29,HIGH(0x260)
JMP _main
.ESEG
.ORG 0
.DB 0 ; FIRST EEPROM LOCATION NOT USED, SEE ATMEL ERRATA SHEETS
.DSEG
.ORG 0x260
; 1 /*Project: AVR Web Server
; 2 by: Eric Mesa and Richard West
; 3 based upon version 0.93 beta
; 4 by: Jeremy
; 5
; 6 **********************************************************************
; 7 * DESCRIPTION
; 8 **********************************************************************
; 9 This project is a webserver running on an Atmel Mega32. It supports
; 10 ping, dhcp,
; 11
; 12 **********************************************************************
; 13 * CHANGELOG
; 14 ***********************************************************************
; 15 Current working version 0.96
; 16
; 17 Version 0.96 - The Compliance Wars - 13 Apr 2005
; 18 The goal of version 0.96 is to shore up compliance
; 19 issues with the original code. It is already
; 20 functional with all broswers, but we want to
; 21 allow error checking, better HTML parsing, and
; 22 generally a heckuva lot more compliant versions
; 23 of the code.
; 24
; 25 1) Added HTTP errors if the wrong page is asked for
; 26 2) Fixed TCP_data variable because Jeremy had been
; 27 pointing into the options and padding area
; 28 3) Added favicon.ico to be compliant with requests for
; 29 page icons - lack of the icon had prevented it from following links
; 30 (at least in Firefox)
; 31 **********************************************************************
; 32
; 33 **********************************************************************
; 34 Version 0.95 - The Modular Version - 13 Apr 2005
; 35 The goal of version 0.95 is to modularize the functions
; 36 by moving them over to their own library and header files.
; 37 This enables a code that is much easier to read as well
; 38 as easier to maintain. This, and the subsquent optimization
; 39 of the code, is our greatest change to the code
; 40
; 41 1) Moved arp-related functions over to their own library/header files
; 42 2) Moved icmp-related functions over to their own library/header files
; 43 3) Moved udp-related functions over to their own library/header files
; 44 4) Moved dhcp-related functions over to their own library/header files
; 45 5) Moved tcp-related functions over to their own library/header files
; 46 6) Moved ack-related functions over to their own library/header files
; 47 7) Moved tcp_send-related functions over to their own library/header
; 48 files
; 49 8) Moved nic communication-related functions over to their own
; 50 library/header files
; 51 9) Moved ring buffer related functions over to their own library/header f
; 52 iles
; 53 10) Moved packet echoing related functions over to their own library/
; 54 header files
; 55 11) Moved ring related functions over to their own library/header files
; 56 12) Moved IP address related functions over to their own library/header
; 57 files
; 58 13) Moved Checksum related functions over to their own library/header
; 59 files
; 60 14) Moved RTL8019AS initialization related functions over to their own
; 61 library/header files
; 62
; 63 Also, changed HTTP to HTTP1.0 from 1.1 to allow the code to be
; 64 retrieved multiple times. Prior to this the server could only be
; 65 connected to once per hard reset.
; 66 **********************************************************************
; 67
; 68 **********************************************************************
; 69 Version 0.94.1 9 Apr 2005
; 70 1) Eliminated minor redundancies (eg x++ instead of x=x+1)
; 71
; 72
; 73 Version 0.94 9 Apr 2005
; 74 1) Fixed browser compatibility problems by correctly padding the html
; 75 header. This involved adding 12 spaces at the front and a \r\n at the
; 76 end
; 77 **********************************************************************
; 78
; 79 **********************************************************************
; 80 Version 0.93.1 6 April 2005
; 81 1) Fixed typoes in copying from PDF
; 82
; 83
; 84 Version 0.93 4 March 2004
; 85 1) Added Checksum for incoming TCP packets (fixed)
; 86 2) Added TCP data sending function (only sends 1 packet at a time Window
; 87 functionality should be done)
; 88 3)Increased packet size from 96 - 300 (since we can have 576 max
; 89 packet length)
; 90 4)Added HTTP functions and HTTP sample
; 91 5)Added DHCP functionality
; 92 6)Need to tweak the TCP_close() functionality
; 93 7) Note: The webbrowesers use the RST fucntion whenever it is closed.
; 94 Don't think will need the TCP_close()
; 95 *****TESTING*****
; 96 6) DHCP WORKING!
; 97 7) IMCP working!!
; 98 7) HTTP up!!
; 99 8) TCP resend lost data working (tested)
; 100 8) (fixed) didn't do the setting of packets properly only set the 1st
; 101 byte must do all bytes
; 102 **********************************************************************
; 103 */
; 104
; 105 //**********************************************************************
; 106 //*
; 107 //* END OF CHANGELOG, BEGIN CODE
; 108 //*
; 109 //**********************************************************************
; 110
; 111 //*******************************************
; 112 //* PORT MAP
; 113 //*******************************************
; 114 //PORT C = rtldata - data bus RCTL8019 and AVR
; 115 // 0 SD0
; 116 // 1 SD1
; 117 // 2 SD2
; 118 // 3 SD3
; 119 // 4 SD4
; 120 // 5 SD5
; 121 // 6 SD6
; 122 // 7 SD7
; 123 // PORT B
; 124 // 0 SA0
; 125 // 1 SA1
; 126 // 2 SA2
; 127 // 3 SA3
; 128 // 4 SA4
; 129 // 5
; 130 // 6
; 131 // 7 make this the rst_pin
; 132 // PORT A
; 133 // temperature sensor port
; 134
; 135 //PORT D
; 136 //0 RXD
; 137 //1 TXD
; 138 //2 INT0 --> for EEPROM only
; 139 // 3 EESK
; 140 //4 EEDI
; 141 //5 EEDO
; 142 //6 ior_pin
; 143 //7 iow_pin
; 144
; 145 #include<mega32.h>
; 146 #include<string.h>
; 147 #include<stdio.h>
; 148 #include<delay.h>
; 149 #include<stdlib.h>
; 150
; 151 #define ISO_G 0x47
; 152 #define ISO_E 0x45
; 153 #define ISO_T 0x54
; 154 #define ISO_slash 0x2f
; 155 #define ISO_c 0x63
; 156 #define ISO_g 0x67
; 157 #define ISO_i 0x69
; 158 #define ISO_space 0x20
; 159 #define ISO_nl 0x0a
; 160 #define ISO_cr 0x0d
; 161 #define ISO_a 0x61
; 162 #define ISO_t 0x74
; 163 #define ISO_hash 0x23
; 164 #define ISO_period 0x2e
; 165
; 166 //define the connection structure for a single TCP socket (multiple connections)
; 167 unsigned int page_size;
; 168
; 169 //**********************************************************************
; 170 //* Stored Web Pages
; 171 //**********************************************************************
; 172
; 173 flash unsigned char *index = "HTTP/1.0 200 OK\r\nServer: KickAss Server\r\nContent-type: text/html\r\n\r\n<html><head><meta HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\"><title>index</title><link rel=\"shortcut icon\" href=\"/favicon.ico\" type=\"image/x-icon\" ></head><body><h1>Atmel Mega32 Webserver</h1><br /><a href=\"about.html\">by Eric Mesa and Richard West</a></h1><br>based on source code by Jeremy Tan<br><h2>Sound Bite</h2><br>Our project is a fully web-standards compliant webserver running on an Atmel Mega32.<h2>Summary</h2>Using code from graduate student Jeremy Tzeming Tan, we improved upon his webserver source code by making it more fully compliant with Internet Standards. Additionally, we modularized his code for easer maintenance, documentation, and implementation.<a href=\"index2.html\">next</a></body></html>\r\n\r\n";
_index:
.BYTE 0x2
; 174 flash unsigned char *index2 = "HTTP/1.0 200 OK\r\nServer: KickAss Server\r\nContent-type: text/html\r\n\r\n<html><head><meta HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\"><title>index2</title><link rel=\"shortcut icon\" href=\"/favicon.ico\" type=\"image/x-icon\" ></head><body>By splitting up the code, instead of keeping all 2000 lines in one file, someone who wishes to maintain a specific function wouldn't have to hunt for it throughout the file. Documentation of each of the files is made easier by splitting them up because a lot more documentation can exist at the toip of each of the files. FInally, we have , therefore, built up a library of Internet protocols. Someone else may take our library files and implement only those protocols which are important to that specific project instead of having to implement a full-blown webserver.</body></html>\r\n\r\n";
_index2:
.BYTE 0x2
; 175
; 176 flash unsigned char *about = "HTTP/1.0 200 OK\r\nServer: KickAss Server\r\nContent-type: text/html\r\n\r\n<html><head><meta HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\"><title>about</title><link rel=\"shortcut icon\" href=\"/favicon.ico\" type=\"image/x-icon\" ></head><body>Eric and Richard, also known as the Kings of Atmel, have taken some time out of their busy schedule to work on this little project.<br /><a href=\"index.html\">index</a></body></html>\r\n\r\n";
_about:
.BYTE 0x2
; 177 // favicon is parsed and sent correctly, but it always appears as a white icon.
; 178 // it is a legitimate ico file since none of the browsers complain when it is received
; 179 flash unsigned char favicon[256+71-10] = {'H','T','T','P','/','1','.','0',' ','2','0','0',' ','O','K','\r','\n','S','e','r','v','e','r',':',' ','K','i','c','k','A','s','s',' ','S','e','r','v','e','r','\r','\n','C','o','n','t','e','n','t','-','t','y','p','e',':',' ','i','m','a','g','e','/','x','-','i','c','o','n','\r','\n','\r','\n',
.CSEG
; 180 0x00,0x00,0x01,0x00,0x01,0x00,0x10,0x10,0x02,0x00,0x01,0x00,0x01,0x00,0xb0,0x00,
; 181 0x00,0x00,0x16,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x20,0x00,
; 182 0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
; 183 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6b,0x3C,
; 184 0x6A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
; 185 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
; 186 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
; 187 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
; 188 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
; 189 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
; 190 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
; 191 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
; 192 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
; 193 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
; 194 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
; 195 0x00,0x00,0x00,0x00,0x00,0x00};
; 196
; 197 flash unsigned char *error400 = "HTTP/1.0 400 Bad Request\r\nServer: KickAss Server\r\nContent-type: text/html\r\n\r\n<html><head><meta HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\"><title>error400</title></head><body>Error400: Opps, you broke it (Bad Request).</body></html>\r\n\r\n";
.DSEG
_error400:
.BYTE 0x2
; 198 flash unsigned char *error404 = "HTTP/1.0 404 Not Found\r\nServer: KickAss Server\r\nContent-type: text/html\r\n\r\n<html><head><meta HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\"><title>error404</title></head><body>Error404: Opps, you broke it (Not Found).</body></html>\r\n\r\n";
_error404:
.BYTE 0x2