This repository has been archived by the owner on Jan 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uart_s.c
951 lines (838 loc) · 33.9 KB
/
uart_s.c
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
// $Id: uart_s.c,v 1.18 2004-06-07 12:32:14 peter Exp $
#include <msp430x14x.h>
#include <string.h>
//â¨¯ë ¯¥à¥¬¥ëå
#include "type_def.h"
#include "global.h"
#include "uart_s.h"
// "inline" äãªæ¨¨ ¤«ï 149 ¯à®æ¥áá®à
#include "m149.h"
// ¬®¤ã«ì ¤«ï à ¡®âë á ¯ ª¥â ¬¨
#include "uart_p.h"
#define STEND_N 2
extern u16 temp_hold;
extern u16 timer_sum_sleep;
extern u16 timer_sum_int;
extern u16 timer_hold;
extern u16 timer_sum;
extern u16 sleep;
extern u16 timer_sum_display;
extern u16 timer_sum_serial;
extern u16 timer_sum_adc;
extern u16 timer_sum_stat;
extern u16 why_job;
u16 stop_transmit;
u16 analog_on;
u16 temperature;
u16 stop_adc;
u16 send_correction_temperature;
extern u16 chanel_convert;
extern unsigned int current_level;
extern unsigned int what_doing;
unsigned int to_level;
extern unsigned int valve_hold;
extern u16 stat_buf[STAT_FIFO_RCV_LEN*SIZE_STAT];
extern unsigned int stat_rcv_fifo_start; /* stat receive buffer start index */
extern volatile unsigned int stat_rcv_fifo_end; /* stat receive buffer end index */
extern u16 stat1_buf[STAT1_FIFO_RCV_LEN*SIZE_STAT1];
extern unsigned int stat1_rcv_fifo_start; /* stat receive buffer start index */
extern volatile unsigned int stat1_rcv_fifo_end; /* stat receive buffer end index */
#ifdef DEBUG_SERIAL
extern u16 packet_in_fifo;
extern u16 packet_in_fifo_max;
extern u16 fifo_trn_depth;
extern u16 packet_fifo_full;
extern u16 fifo_trn_depth_max;
extern u16 error_uart_depth;
extern u16 error_send_serial;
extern u16 length_sended_2_fifo;
extern u16 length_sended_2_fifo_max;
extern u16 length_sended_2_fifo_min;
extern u16 error_packets_crc;
#endif //DEBUG_SERIAL
extern u16 current_rec_packet;
extern u16 rec_length;
extern u16 received_packed;
//extern unsigned int results0[ADC_FIFO_RCV_LEN*SIZE_OF_ADC_DUMP];
//extern unsigned int results1[ADC_FIFO_RCV_LEN*SIZE_OF_ADC_DUMP];
//extern unsigned int results2[ADC_FIFO_RCV_LEN*SIZE_OF_ADC_DUMP];
//extern unsigned int results3[ADC_FIFO_RCV_LEN*SIZE_OF_ADC_DUMP];
//extern unsigned int results4[ADC_FIFO_RCV_LEN*SIZE_OF_ADC_DUMP];
//extern unsigned int results5[ADC_FIFO_RCV_LEN*SIZE_OF_ADC_DUMP];
//extern unsigned int results6[ADC_FIFO_RCV_LEN*SIZE_OF_ADC_DUMP];
extern unsigned int one_count0[ADC_FIFO_RCV_LEN*SIZE_OF_ADC_DUMP];
extern unsigned int one_count1[ADC_FIFO_RCV_LEN*SIZE_OF_ADC_DUMP];
extern unsigned int multi_count0[NUM_MULTICHANNEL][ADC_FIFO_RCV_LEN];
extern unsigned int multi_count1[NUM_MULTICHANNEL][ADC_FIFO_RCV_LEN];
extern unsigned int results[ADC_FIFO_RCV_LEN];
extern u16 dac[NUM_CHANEL];
extern u16 chanel;
/*
®¡¬¥ ᪮à®á⨠115200
Š®«¨ç¥á⢮ ‡ 票¥
¡ ©â
_____
X ¤ ë¥ ¯ ª¥â
á«ã¦¥¡ë¥ ¤ ë¥ ¯ ª¥â :
1 ¯®à浪®¢ë© ®¬¥à ¯ ª¥â
( ¥á«¨ ⨯ ¯ ª¥â 0x01 - â® íâ® ®¬¥à ¯®¤â¢¥à¦¤ ¥¬®£® ¯ ª¥â )
1 ⨯ ¯ ª¥â
1 ¤«¨ ¯ ª¥â (¡¥§ ¬ àª¥à ª®æ ¯ ª¥â = X+5)
2 CRC16 (áâ à訩 ¡ ©â ¨¤¥â ¯¥à¢ë¬, ¯®â®¬ ¬« ¤è¨©)
CRC16 - áç¨â ¥âáï ¬ áᨢ ¤ ëå á ç « ¯ ª¥â ¤ ëå
¤® ¯®«ï ¨¤ã騬 ¯¥à¥¤ ¯®«¥¬ CRC16 (¤«¨ ¯ ª¥â ) ¢ª«îç¨â¥«ì®
¯®á«¥ í⮣® ¯®«ãç¥ ï CRC § ®á¨âáï ¢ á«¥¤ãî饬 ¯®à浪¥:
áâ à訩 ¡ ©â, ¬« ¤è¨© ¡ ©â
1 x7E - ¬ àª¥à ¯ ª¥â
‚ 楫ïå £¨¡ª®á⨠(à áè¨à¥¨ï) ¤«¨ë ¯ ª¥â ¤ ëå «î¡®£® ⨯
¯à®£à ¬¬ãî ॠ«¨§ æ¨î à §¡®à ᮤ¥à¦¨¬®£® ¯ ª¥â (¤ ëå ¯ ª¥â )
¦¥« â¥«ì® ¤¥« âì ®â "£®«®¢ë" ¯ ª¥â ,
á«ã¦¥¡ëå § £®«®¢ª®¢ - ®â 墮áâ ¯ ª¥â (¬ àª¥à ª®æ )
¯à¨ ¯¥à¥¤ ç¥ ¯® ª «ã ¢¥áì ¯ ª¥â (¤ ë¥ ¯ ª¥â +á«ã¦¥¡ë¥ á
㦥 ¯®¤áç¨â 묨 ¯®«ï¬¨ ¨ CRC, § ¨áª«î票¥¬ ¬ àª¥à ª®æ
¯ ª¥â 0x7E) «¨§¨àã¥âáï «¨ç¨¥ ¡ ©â á ª®¤ ¬¨
0x7D (ESCAPE)
0x7E (EOF)
â ª¨¥ ¡ ©âë § ¬¥ïîâáï ¯®á«¥¤®¢ ⥫ì®áâì ¨§ ¤¢ãå ¡ ©â
0x7D,¨áå®¤ë¥ ¤ ë¥ XOR 0x40
â® ¥áâì
¡ë«® áâ «®
0x7D 0x7D 0x3D
0x7E 0x7D 0x3E
¯à¨¥¬®© áâ®à®¥:
¯®â®ª «¨§¨àã¥âáï ¯®áâ㯫¥¨¥ ¡ ©â
0x7D (ESCAPE). ਠ¯®«ã票¨ ¤ ®£® § 票ï á ¬ ª®¤ í⮣®
¡ ©â ¢ «¨§¥ ¥ ãç ¢áâ¢ã¥â, ¤ § 票¥ á«¥¤ãî饣® ¡ ©â
¥®¡å®¤¨¬® ¯à®¢¥á⨠®¯¥à æ¨î XOR 0x40. ®«ãç¥ë¥ ¤ ë¥
¯®á«¥ ¤ ®© ®¯¥à 樨 ¥ ïîâáï á«ã¦¥¡ë¬¨ ª®¤ ¬¨ (EOF ¨«¨
ESCAPE), ïîâáï ®¡ëª®¢¥ë¬ ᮤ¥à¦¨¬ë¬ ¯ ª¥â .
¯à¨ ¯®«ã票¨ ª®¤ 0x7E (EOF) ¥®¡å®¤¨¬® ¯®¤áç¨â âì CRC
¢á¥å ¯à¨ïâëå ¤ ëå ¯¥à¥¤ í⨬ ª®¤®¬ (¨áª«îç ï á ¬ ᨬ¢®« EOF)
¯à¨ १ã«ìâ¨àãî饬 § 票¨ CRC = 0 ª®â஫ì ï á㬬 áç¨â ¥âáï
ᮢ¯ ¢è¥©. „®¯®«¨â¥«ìë¬ ª®â஫¥¬ 楫®áâ®á⨠¯ ª¥â
¬®¦¥â á«ã¦¨âì ᮢ¯ ¤¥¨¥ ª®«¨ç¥á⢠ॠ«ì® ¯à¨ïâëå ¤ ëå
á® § 票¥¬ 㪠§ ë¬ ¢ á«ã¦¥¡®¬ ¯®«¥ ¯ ª¥â "¤«¨ ".
’¨¯
¯ ª¥â
0x01 ¯ ª¥â ¯®¤â¢¥à¦¤¥¨ï.
¯®¤â¢¥à¦¤ ¥âáï ¯à¨¥¬ ¯ ª¥â á 㪠§ ë¬ ¯®à浪®¢ë¬ ®¬¥à®¬
_________________________________________________________________
0x02 ¯ ª¥â á¨åந§ 樨 ¢à¥¬¥¨
‚ ¯ ª¥â¥ ¯¥à¥¤ ¥âáï ” § ¬®¬¥â ¯¥à¥¤ ç¨ ¯®
¯®á«¥¤®¢ ⥫쮬㠯®àâã
¯ ª¥â ¥ âॡã¥â ¯®¤â¢¥à¦¤¥¨ï ¨ ¨¤¥â ¡¥§ ¯®à浪®¢®£® ®¬¥à
_________________________________________________________________
0x03 ¯ ª¥â ¤ ëå Šƒ
_________________________________________________________________
0x05 ¯ ª¥â ¤ ëå áâ â¨á⨪¨
_________________________________________________________________
0x06 ¯ ª¥â ¤ ëå áâ â¨á⨪¨ 1
_________________________________________________________________
0x07 ¯ ª¥â ¤ ëå á ¤¢ãå ª «®¢
ᮤ¥à¦ ¨¥ ¯ ª¥â :
(0) á«®¢® - § 票¥ ®¯®à®£® ª «
(1) á«®¢® - § 票¥ ®¯®à®£® ª « (á«¥¤ãî饥 ¯® ¢à¥¬¥¨)
.....
(7) á«®¢® - § 票¥ ®¯®à®£® ª « (á«¥¤ãî饥 ¯® ¢à¥¬¥¨)
(8) á«®¢® - § 票¥ ¨áá«¥¤ã¥¬®£® ª «
(9) á«®¢® - § 票¥ ¨áá«¥¤ã¥¬®£® ª « (á«¥¤ãî饥 ¯® ¢à¥¬¥¨)
.....
(15) á«®¢® - § 票¥ ¨áá«¥¤ã¥¬®£® ª « (á«¥¤ãî饥 ¯® ¢à¥¬¥¨)
1 ¡ ©â - § १¥à¢¨à®¢ ®
®¡é¥¥ ª®«¨ç¥á⢮ ¤ ëå 16*2+1=33 ¡ ©â
_________________________________________________________________
0x08 ¯ ª¥â ¤ ëå ãáâ ®¢ª¨ ª « –€
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¤¢ ¡ ©â - § 票¥ ¤«ï –€
¡ ©â - ®¬¥à ª « –€
®¡é¥¥ ª®«¨ç¥á⢮ ¤ ëå 2+1=3 ¡ ©â
_________________________________________________________________
0x09 ¯ ª¥â ¤ ëå ãáâ ®¢ª¨ ª « €–
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¡ ©â - ®¬¥à ª « ¤«ï ¯à¥®¡à §®¢ ¨ï
¢ ª®â®à®¬ - SXMM MAAM
S - 0 - ®á®¢®©, 1 - १¥à¢ë©
X - 0 - ०¨¬ ¢ë¢®¤ ¢á¥å ®âáç¥â®¢ ®¯®à®£® ¨
¨áá«¥¤ã¥¬®£® ª « (¯ ª¥â 0x07)
1 - ०¨¬ ¢ë¢®¤ á㬬 àëå § 票©
A - § 票¥ ª « €– (PRESS_1 - PRESS_4)
M - § 票¥ ¤«ï MUX (A0-A3)
_________________________________________________________________
0x0A ¯ ª¥â ¤ ëå á ª «®¢ (¯à®á㬬¨à®¢ ë¥)
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¡ ©â - ª®«¨ç¥á⢮ ¢ë¢®¤¨¬ëå ª «®¢ (N)
¡ ©â - ®¬¥à ¯¥à¢®£® ª «
á«®¢® - § 票¥ ®¯®à®£® ª « ᮠᬥ饨¥¬ 0
á«®¢® - § 票¥ ¨áá«¥¤ã¥¬®£® ª « ᮠᬥ饨¥¬ 0
á«®¢® - § 票¥ ®¯®à®£® ª « ᮠᬥ饨¥¬ 1
á«®¢® - § 票¥ ¨áá«¥¤ã¥¬®£® ª « ᮠᬥ饨¥¬ 1
.....
á«®¢® - § 票¥ ®¯®à®£® ª « ᮠᬥ饨¥¬ (N-1)
á«®¢® - § 票¥ ¨áá«¥¤ã¥¬®£® ª « ᮠᬥ饨¥¬ (N-1)
á«®¢® - § 票¥ ⥬¯¥à âãàë (á㬬¨à®¢ ë¥ 16 ®âáç¥â®¢)
1 ¡ ©â - § १¥à¢¨à®¢ ®
®¡é¥¥ ª®«¨ç¥á⢮ ¤ ëå 2+N*2+1 ¡ ©â
_________________________________________________________________
0x0B § ªàëâì ª« ¯
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¥â
_________________________________________________________________
0x0‘ ®âªàëâì ª« ¯
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¥â
_________________________________________________________________
0x0D á¯ãáâ¨âì ¤ ¢«¥¨¥ ¤® âॡ㥬®© ¢¥«¨ç¨ë
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¢ ¯ ª¥â¥ á«®¢® (+1 ¡ ©â reserved) - ¡á®«î⮥
§ 票¥ ¤® ª®â®à®£® ¥®¡å®¤¨¬® ®¯ãáâ¨âìáï ¨ § ªàëâì ª« ¯
12 ¡¨â ⥪ã饣® ®¯®à®£® (®á®¢®£® ¨«¨ १¥à¢®£®)
ª «
®¡é¥¥ ª®«¨ç¥á⢮ ¤ ëå 3 ¡ ©â
_________________________________________________________________
0x0E ª ç âì ¤ ¢«¥¨¥ ¤® 㪠§ ®© ¢¥«¨ç¨ë
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¢ ¯ ª¥â¥ á«®¢® (+1 ¡ ©â reserved) - ¡á®«î⮥
§ 票¥ ¤® ª®â®à®£® ¥®¡å®¤¨¬® ª ç âì ¤ ¢«¥¨¥
¯à¥¤¢ à¨â¥«ì® ¥®¡å®¤¨¬® ¤ âì ª®¬¬ ¤ã
§ ªàëâì ª« ¯
®¡é¥¥ ª®«¨ç¥á⢮ ¤ ëå 3 ¡ ©â
_________________________________________________________________
0x0F ¢ëª«îç¨âì ª®¬¯à¥áá®à. „ ï ª®¬ ¤ ¯à¥ªà é ¥â
¤¥©á⢨¥ ¯ ª¥â 0x0E
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¥â
_________________________________________________________________
0x10 ãáâ ®¢ª ¨â¥à¢ « â ©¬ ãâ (ᥪ) ¢ â¥ç¥¨¨
ª®â®à®£® ¯ëâ âìáï ª ç âì ¤ ¢«¥¨¥ ¤® âॡ㥬®£®
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¢ ¯ ª¥â¥ 1 ¡ ©â, ¯® 㬮«ç ¨î 30.
® ¨áâ¥ç¥¨¨ í⮣® ¢à¥¬¥¨ ¢ëáë« ¥âáï á«ã¦¥¡ë© ¯ ª¥â
0x11
®¡é¥¥ ª®«¨ç¥á⢮ ¤ ëå 1 ¡ ©â
_________________________________________________________________
0x11 á«ã¦¥¡ë© ¯ ª¥â ᨣ «¨§¨àãî騩 ® ¨áâ¥ç¥¨¨
â ©¬ ãâ ª 窨
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¥â
_________________________________________________________________
0x12 ãáâ ®¢ª ¨â¥à¢ « â ©¬ ãâ (ᥪ) ¢ â¥ç¥¨¨
ª®â®à®£® ¯ëâ âìáï ®¯ãáâ¨âì ¤ ¢«¥¨¥ ¤® âॡ㥬®£®
(¯® 㬮«ç ¨î 5)
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¢ ¯ ª¥â¥ 1 ¡ ©â
®¡é¥¥ ª®«¨ç¥á⢮ ¤ ëå 1 ¡ ©â
® ¨áâ¥ç¥¨¨ í⮣® ¢à¥¬¥¨ ¢ëáë« ¥âáï á«ã¦¥¡ë© ¯ ª¥â
0x14
_________________________________________________________________
0x14 á«ã¦¥¡ë© ¯ ª¥â ᨣ «¨§¨àãî騩 ® ¨áâ¥ç¥¨¨
â ©¬ ãâ á¯ãáª
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¥â
_________________________________________________________________
0x15 ãáâ ®¢ª ¤ ¢«¥¨ï ¯à¨ ¤®á⨦¥¨¨ ª®â®à®£®
¢â®¬ â¨ç¥áª¨ ¢ë¯®«ï¥âáï 0x0F 0x0‘
¨ ¢ëáë« ¥âáï á«ã¦¥¡ë© ¯ ª¥â 0x16
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¢ ¯ ª¥â¥ á«®¢® (+1 ¡ ©â reserved) - ¡á®«î⮥
¯à¥¤¥«ì®¥ § 票¥ ¤ ¢«¥¨ï
®¡é¥¥ ª®«¨ç¥á⢮ ¤ ëå 3 ¡ ©â
_________________________________________________________________
0x16 á«ã¦¥¡ë© ¯ ª¥â ᨣ «¨§¨àãî騩 ® ¯à¥¢ë襨¨
§ ¤ ®£® ãà®¢ï ¤ ¢«¥¨ï ( ¢ à¨©ë© ã஢¥ì)
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¥â
_________________________________________________________________
0x18 “áâ ®¢¨âì ¡¨âë ã¯à ¢«¥¨ï ०¨¬®¬
ᮤ¥à¦ ¨¥ ¯ ª¥â :
¢ ¯ ª¥â¥ 1 ¡ ©â
0 ¡¨â - ¢ª«î票¥ ¯à殮¨ï ¤ â稪 å
1 ¡¨â - ¢ª«î票¥ ¯à殮¨ï «®£®¢®© ç áâ¨
2 ¡¨â - ¢ëª«î票¥ ¯à¥®¡à §®¢ ¨ï €–
3 ¡¨â - ¢ª«î票¥ ¯à¥®¡à §®¢ ¨ï €–
4 ¡¨â - ¢ëª«î票¥ UART
5 ¡¨â - ¢ª«î票¥ UART
6 ¡¨â - ¢ëª«î票¥ ⥬¯¥à âãàë
7 ¡¨â - ¢ª«î票¥ ⥬¯¥à âãàë
®¡é¥¥ ª®«¨ç¥á⢮ ¤ ëå 1 ¡ ©â
_________________________________________________________________
0x19 „ ë¥ â¥¬¯¥à âãàë
ᮤ¥à¦ ¨¥ ¯ ª¥â :
2 ¡ ©â - ¨§¬¥à¥®¥ § 票¥
_________________________________________________________________
0x1A „ ë¥ ª®à४樨 ⥬¯¥à âãàë (à § ¢ ᥪã¤ã)
ᮤ¥à¦ ¨¥ ¯ ª¥â :
2 ¡ ©â - ª«®
2 ¡ ©â - ᬥ饨¥
2 ¡ ©â - § 票¥ €– (¯¥à¢ ï â®çª )
2 ¡ ©â - § 票¥ ⥬¯¥à âãàë 㬮¦¥®¥ 100 (¯¥à¢ ï â®çª )
2 ¡ ©â - § 票¥ €– (¢â®à ï â®çª )
2 ¡ ©â - § 票¥ ⥬¯¥à âãàë 㬮¦¥®¥ 100 (¢â®à ï â®çª )
*/
#define CRCPACKET 2 //ᬥ饨¥ (á ª®æ ) ¯®«®¦¥¨ï ¢ ¯ ª¥â¥ CRC
#define LENPACKET 3 //ᬥ饨¥ (á ª®æ ) ¯®«®¦¥¨ï ¢ ¯ ª¥â¥ ¤«¨ë ¯ ª¥â
#define TYPEPACKET 4 //ᬥ饨¥ (á ª®æ ) ¯®«®¦¥¨ï ¢ ¯ ª¥â¥ ⨯ ¯ ª¥â
#define NUMPACKET 5 //ᬥ饨¥ (á ª®æ ) ¯®«®¦¥¨ï ¢ ¯ ª¥â¥ ®¬¥à ¯ ª¥â
#define CHANNEL_TO_SET 6 //§ 票¥ ®¬¥à ª « €– ¢ 9-®¬ ¯ ª¥â¥
#define NUM_OF_CHANNEL_DAC 6 //§ 票¥ ®¬¥à ª « –€ ¢ 8-®¬ ¯ ª¥â¥
#define VALVE_OF_CHANNEL_DAC 8 //§ 票¥ ¤«ï –€ ¢ 8-®¬ ¯ ª¥â¥
#define LEVEL_SET 8 //§ 票¥ ¤ ëå ¢ 3-å ¡ ©â®¢®¬ ¯ ª¥â¥
#define REGIM_JOB 6 //ãáâ ®¢ª ०¨¬®¢ à ¡®âë
extern volatile unsigned int asp_trn_fifo_start; /* serial transmit buffer start index */
extern unsigned int asp_trn_fifo_end; /* serial transmit flash buffer end index */
extern u16 asp_trn_fifo_buf[SERIAL_FIFO_TRN_LEN]; /* storage for serial transmit buffer */
//unsigned int asp_rcv_fifo_start; /* serial receive buffer start index */
//volatile unsigned int asp_rcv_fifo_end; /* serial receive flash buffer end index */
//u8 asp_rcv_fifo_buf[SERIAL_FIFO_RCV_LEN]; /* storage for receive transmit buffer */
#define FREEPLACE 0 //᢮¡®¤ë© ¯ ª¥â
#define PACKBUSY 1 //§ ïâë© ¯®¤ ®¡à ¡®âªã
#define NOTSENDED 2 //¥®â¯à ¢«¥ë© ¯ ª¥â
#define WAIT_ACK 3 //®¦¨¤ î騩 ¯®¤â¢¥à¦¤¥¨ï
#define PACKREC 4 //¯à¨ïâë© ¯ ª¥â
extern struct que queue[MAXQUE];
extern u8 packets[MAXQUE*MAXPACKETLEN];
extern u8 counts_packet; //¯®à浪®¢ë© ®¬¥à ¯ ª¥â
//®â¯à ¢«ï¥¬ ¯ ª¥â á® áâ â¨á⨪®©
u16 put_packet_type5(void){
int n;
//int x;
int crc;
int shift_fifo;
//u16* t_p;
//u16* t_s;
//§ å¢ âë¢ ¥¬ ᢮¡®¤ë© ¯ ª¥â
disable_int_no_interrupt();
n=hold_packet();
enable_int_no_interrupt();
if (n==MAXQUE) {
#ifdef DEBUG_SERIAL
packet_fifo_full++;
#endif //DEBUG_SERIAL
return 0; //᢮¡®¤ëå ¯ ª¥â®¢ ¥â
}
#ifdef DEBUG_SERIAL
packet_in_fifo++;
if (packet_in_fifo_max<packet_in_fifo) packet_in_fifo_max=packet_in_fifo;
#endif //DEBUG_SERIAL
shift_fifo=(n+1)*MAXPACKETLEN;
//ª®¯¨à㥬 â㤠¤ ë¥ ¤«ï ¯ ª¥â
// t_p=(u16*)&packets[shift_fifo-DATA5PACKET];
// t_s=(u16*)&stat_buf[(stat_rcv_fifo_start & (STAT_FIFO_RCV_LEN-1))*SIZE_STAT];
// for(x=0;x<SIZE_STAT;x++)
// *t_p++=*t_s++;
memcpy(&packets[shift_fifo-DATA5PACKET],&stat_buf[(stat_rcv_fifo_start & (STAT_FIFO_RCV_LEN-1))*SIZE_STAT],SIZE_STAT*2);
stat_rcv_fifo_start++;
//¯®¬¥é ¥¬ ¢ ¯ ª¥â ¥£® ¤«¨ã (¡¥§ § ¢¥àè î饣® EOFPACKET)
packets[shift_fifo-LENPACKET]=DATA5PACKET;
//¯®¬¥é ¥¬ (¨ 㢥«¨ç¨¢ ¥¬) ¯®à浪®¢ë© ®¬¥à ¯ ª¥â
packets[shift_fifo-NUMPACKET]=counts_packet;
queue[n].numeric=counts_packet++;
//㪠§ë¢ ¥¬ ⨯ ¯ ª¥â
packets[shift_fifo-TYPEPACKET]=0x05;
//¯®¤áç¨âë¢ ¥¬ ¨ ¯®¬¥é ¥¬ CRC ¯ ª¥â
crc=crc16(&packets[shift_fifo-DATA5PACKET],DATA5PACKET-2);
packets[shift_fifo-CRCPACKET]=crc>>8;
packets[shift_fifo-CRCPACKET+1]=crc;
//¢ á¯à ¢®ç®¬ ¬ áᨢ¥ 㪠§ë¢ ¥¬ ¤«¨ã ¯ ª¥â
queue[n].len=DATA5PACKET;
queue[n].busy=NOTSENDED;
return 1;
}
u16 put_packet_type6(void){
int n;
//int x;
int crc;
int shift_fifo;
//§ å¢ âë¢ ¥¬ ᢮¡®¤ë© ¯ ª¥â
disable_int_no_interrupt();
n=hold_packet();
enable_int_no_interrupt();
if (n==MAXQUE) {
#ifdef DEBUG_SERIAL
packet_fifo_full++;
#endif //DEBUG_SERIAL
return 0; //᢮¡®¤ëå ¯ ª¥â®¢ ¥â
}
#ifdef DEBUG_SERIAL
packet_in_fifo++;
if (packet_in_fifo_max<packet_in_fifo) packet_in_fifo_max=packet_in_fifo;
#endif //DEBUG_SERIAL
shift_fifo=(n+1)*MAXPACKETLEN;
//ª®¯¨à㥬 â㤠¤ ë¥ ¤«ï ¯ ª¥â
memcpy(&packets[shift_fifo-DATA6PACKET],&stat1_buf[(stat1_rcv_fifo_start & (STAT1_FIFO_RCV_LEN-1))*SIZE_STAT1],SIZE_STAT1*2);
stat1_rcv_fifo_start++;
//¯®¬¥é ¥¬ ¢ ¯ ª¥â ¥£® ¤«¨ã (¡¥§ § ¢¥àè î饣® EOFPACKET)
packets[shift_fifo-LENPACKET]=DATA6PACKET;
//¯®¬¥é ¥¬ (¨ 㢥«¨ç¨¢ ¥¬) ¯®à浪®¢ë© ®¬¥à ¯ ª¥â
packets[shift_fifo-NUMPACKET]=counts_packet;
queue[n].numeric=counts_packet++;
//㪠§ë¢ ¥¬ ⨯ ¯ ª¥â
packets[shift_fifo-TYPEPACKET]=0x06;
//¯®¤áç¨âë¢ ¥¬ ¨ ¯®¬¥é ¥¬ CRC ¯ ª¥â
crc=crc16(&packets[shift_fifo-DATA6PACKET],DATA6PACKET-2);
packets[shift_fifo-CRCPACKET]=crc>>8;
packets[shift_fifo-CRCPACKET+1]=crc;
//¢ á¯à ¢®ç®¬ ¬ áᨢ¥ 㪠§ë¢ ¥¬ ¤«¨ã ¯ ª¥â
queue[n].len=DATA6PACKET;
queue[n].busy=NOTSENDED;
return 1;
}
u8 put_packet_type4(void){
int n;
int crc;
int shift_fifo;
//§ å¢ âë¢ ¥¬ ᢮¡®¤ë© ¯ ª¥â
disable_int_no_interrupt();
n=hold_packet();
enable_int_no_interrupt();
if (n==MAXQUE) {
#ifdef DEBUG_SERIAL
packet_fifo_full++;
#endif //DEBUG_SERIAL
return 0; //᢮¡®¤ëå ¯ ª¥â®¢ ¥â
}
#ifdef DEBUG_SERIAL
packet_in_fifo++;
if (packet_in_fifo_max<packet_in_fifo) packet_in_fifo_max=packet_in_fifo;
#endif //DEBUG_SERIAL
shift_fifo=(n+1)*MAXPACKETLEN;
packets[shift_fifo-11]='0';
packets[shift_fifo-10]='9';
packets[shift_fifo-9]='8';
packets[shift_fifo-8]='7';
packets[shift_fifo-7]='6';
packets[shift_fifo-6]='5';
packets[shift_fifo-5]='4';
packets[shift_fifo-4]='3';
packets[shift_fifo-3]='2';
packets[shift_fifo-TYPEPACKET]=0x04;
crc=crc16(&packets[shift_fifo-13],11);
packets[shift_fifo-CRCPACKET]=crc>>8;
packets[shift_fifo-CRCPACKET+1]=crc;
queue[n].len=13;
queue[n].busy=NOTSENDED;
return 1;
}
u8 put_packet_type7(u16 info){
int n;
int crc;
int shift_fifo;
u16* t_p;
//u8* t_r;
//§ å¢ âë¢ ¥¬ ᢮¡®¤ë© ¯ ª¥â
disable_int_no_interrupt();
n=hold_packet();
enable_int_no_interrupt();
if (n==MAXQUE) {
#ifdef DEBUG_SERIAL
packet_fifo_full++;
#endif //DEBUG_SERIAL
return 0; //᢮¡®¤ëå ¯ ª¥â®¢ ¥â
}
#ifdef DEBUG_SERIAL
packet_in_fifo++;
if (packet_in_fifo_max<packet_in_fifo) packet_in_fifo_max=packet_in_fifo;
#endif //DEBUG_SERIAL
shift_fifo=(n+1)*MAXPACKETLEN;
//ª®¯¨à㥬 â㤠¤ ë¥ ¤«ï ¯ ª¥â
t_p=(u16*)&packets[shift_fifo-DATA7PACKET];
memcpy(t_p,&one_count0[info*SIZE_OF_ADC_DUMP],SIZE_OF_ADC_DUMP*2);
memcpy(t_p+SIZE_OF_ADC_DUMP,&one_count1[info*SIZE_OF_ADC_DUMP],SIZE_OF_ADC_DUMP*2);
packets[shift_fifo-DATA7PACKET+4*SIZE_OF_ADC_DUMP]=results[info];
//¯®¬¥é ¥¬ ¢ ¯ ª¥â ¥£® ¤«¨ã (¡¥§ § ¢¥àè î饣® EOFPACKET)
packets[shift_fifo-LENPACKET]=DATA7PACKET;
//¯®¬¥é ¥¬ (¨ 㢥«¨ç¨¢ ¥¬) ¯®à浪®¢ë© ®¬¥à ¯ ª¥â
packets[shift_fifo-NUMPACKET]=counts_packet;
queue[n].numeric=counts_packet++;
//㪠§ë¢ ¥¬ ⨯ ¯ ª¥â
packets[shift_fifo-TYPEPACKET]=0x07;
//¯®¤áç¨âë¢ ¥¬ ¨ ¯®¬¥é ¥¬ CRC ¯ ª¥â
crc=crc16(&packets[shift_fifo-DATA7PACKET],DATA7PACKET-2);
packets[shift_fifo-CRCPACKET]=crc>>8;
packets[shift_fifo-CRCPACKET+1]=crc;
//¢ á¯à ¢®ç®¬ ¬ áᨢ¥ 㪠§ë¢ ¥¬ ¤«¨ã ¯ ª¥â
queue[n].len=DATA7PACKET;
queue[n].busy=NOTSENDED;
return 1;
}
u8 put_packet_typeA(u16 info){
int z;
int n;
int crc;
int shift_fifo;
u16* t_p;
//§ å¢ âë¢ ¥¬ ᢮¡®¤ë© ¯ ª¥â
disable_int_no_interrupt();
n=hold_packet();
enable_int_no_interrupt();
if (n==MAXQUE) {
#ifdef DEBUG_SERIAL
packet_fifo_full++;
#endif //DEBUG_SERIAL
return 0; //᢮¡®¤ëå ¯ ª¥â®¢ ¥â
}
#ifdef DEBUG_SERIAL
packet_in_fifo++;
if (packet_in_fifo_max<packet_in_fifo) packet_in_fifo_max=packet_in_fifo;
#endif //DEBUG_SERIAL
shift_fifo=(n+1)*MAXPACKETLEN;
//ª®¯¨à㥬 â㤠¤ ë¥ ¤«ï ¯ ª¥â
t_p=(u16*)&packets[shift_fifo-DATAxAPACKET];
*t_p++=((results[info]&0xFF)<<8)|NUM_MULTICHANNEL;//ª®«¨ç¥á⢮ ¢ë¢®¤¨¬ëå ª «®¢
for (z=0;z<NUM_MULTICHANNEL;z++){
*t_p++=multi_count0[z][info];
*t_p++=multi_count1[z][info];
}
// *t_p++=multi_count0[NUM_MULTICHANNEL][info]+multi_count1[NUM_MULTICHANNEL][info]; //⥬¯¥à âãà
//¯®¬¥é ¥¬ ¢ ¯ ª¥â ¥£® ¤«¨ã (¡¥§ § ¢¥àè î饣® EOFPACKET)
packets[shift_fifo-LENPACKET]=DATAxAPACKET;
//¯®¬¥é ¥¬ (¨ 㢥«¨ç¨¢ ¥¬) ¯®à浪®¢ë© ®¬¥à ¯ ª¥â
packets[shift_fifo-NUMPACKET]=counts_packet;
queue[n].numeric=counts_packet++;
//㪠§ë¢ ¥¬ ⨯ ¯ ª¥â
packets[shift_fifo-TYPEPACKET]=0x0A;
//¯®¤áç¨âë¢ ¥¬ ¨ ¯®¬¥é ¥¬ CRC ¯ ª¥â
crc=crc16(&packets[shift_fifo-DATAxAPACKET],DATAxAPACKET-2);
packets[shift_fifo-CRCPACKET]=crc>>8;
packets[shift_fifo-CRCPACKET+1]=crc;
//¢ á¯à ¢®ç®¬ ¬ áᨢ¥ 㪠§ë¢ ¥¬ ¤«¨ã ¯ ª¥â
queue[n].len=DATAxAPACKET;
queue[n].busy=NOTSENDED;
return 1;
}
u8 put_packet_type19(u16 info){
//int z;
int n;
int crc;
int shift_fifo;
u16* t_p;
//§ å¢ âë¢ ¥¬ ᢮¡®¤ë© ¯ ª¥â
disable_int_no_interrupt();
n=hold_packet();
enable_int_no_interrupt();
if (n==MAXQUE) {
#ifdef DEBUG_SERIAL
packet_fifo_full++;
#endif //DEBUG_SERIAL
return 0; //᢮¡®¤ëå ¯ ª¥â®¢ ¥â
}
#ifdef DEBUG_SERIAL
packet_in_fifo++;
if (packet_in_fifo_max<packet_in_fifo) packet_in_fifo_max=packet_in_fifo;
#endif //DEBUG_SERIAL
shift_fifo=(n+1)*MAXPACKETLEN;
//ª®¯¨à㥬 â㤠¤ ë¥ ¤«ï ¯ ª¥â
t_p=(u16*)&packets[shift_fifo-DATA19PACKET];
*t_p++=multi_count0[0][info];//⥬¯¥à âãà
//¯®¬¥é ¥¬ ¢ ¯ ª¥â ¥£® ¤«¨ã (¡¥§ § ¢¥àè î饣® EOFPACKET)
packets[shift_fifo-LENPACKET]=DATA19PACKET;
//¯®¬¥é ¥¬ (¨ 㢥«¨ç¨¢ ¥¬) ¯®à浪®¢ë© ®¬¥à ¯ ª¥â
packets[shift_fifo-NUMPACKET]=counts_packet;
queue[n].numeric=counts_packet++;
//㪠§ë¢ ¥¬ ⨯ ¯ ª¥â
packets[shift_fifo-TYPEPACKET]=0x19;
//¯®¤áç¨âë¢ ¥¬ ¨ ¯®¬¥é ¥¬ CRC ¯ ª¥â
crc=crc16(&packets[shift_fifo-DATA19PACKET],DATA19PACKET-2);
packets[shift_fifo-CRCPACKET]=crc>>8;
packets[shift_fifo-CRCPACKET+1]=crc;
//¢ á¯à ¢®ç®¬ ¬ áᨢ¥ 㪠§ë¢ ¥¬ ¤«¨ã ¯ ª¥â
queue[n].len=DATA19PACKET;
queue[n].busy=NOTSENDED;
return 1;
}
u8 put_packet_type1A(void){
u16* t_p;
int n;
int crc;
int shift_fifo;
//§ å¢ âë¢ ¥¬ ᢮¡®¤ë© ¯ ª¥â
disable_int_no_interrupt();
n=hold_packet();
enable_int_no_interrupt();
if (n==MAXQUE) {
#ifdef DEBUG_SERIAL
packet_fifo_full++;
#endif //DEBUG_SERIAL
return 0; //᢮¡®¤ëå ¯ ª¥â®¢ ¥â
}
#ifdef DEBUG_SERIAL
packet_in_fifo++;
if (packet_in_fifo_max<packet_in_fifo) packet_in_fifo_max=packet_in_fifo;
#endif //DEBUG_SERIAL
shift_fifo=(n+1)*MAXPACKETLEN;
//ª®¯¨à㥬 â㤠¤ ë¥ ¤«ï ¯ ª¥â
t_p=(u16*)&packets[shift_fifo-DATA1APACKET];
#if STEND_N == 1
*t_p++=41294; // ª«®
*t_p++=42148; //ᬥ饨¥
*t_p++=43344; //§ 票¥ €– (¯¥à¢ ï â®çª )
*t_p++=2266; //§ 票¥ ⥬¯¥à âãàë 㬮¦¥®¥ 100 (¯¥à¢ ï â®çª )
*t_p++=43680; //§ 票¥ €– (¢â®à ï â®çª )
*t_p++=4460; //§ 票¥ ⥬¯¥à âãàë 㬮¦¥®¥ 100 (¢â®à ï â®çª )
*t_p++=0x04A4; //®¬¥à á⥤ A4040003
*t_p++=0x0100; // A - á⥤, 04 - £®¤, 0003 - ®¬¥à
warning!!!
#elif STEND_N == 2
*t_p++=41294; // ª«®
*t_p++=42148; //ᬥ饨¥
*t_p++=43344; //§ 票¥ €– (¯¥à¢ ï â®çª )
*t_p++=2266; //§ 票¥ ⥬¯¥à âãàë 㬮¦¥®¥ 100 (¯¥à¢ ï â®çª )
*t_p++=43680; //§ 票¥ €– (¢â®à ï â®çª )
*t_p++=4460; //§ 票¥ ⥬¯¥à âãàë 㬮¦¥®¥ 100 (¢â®à ï â®çª )
*t_p++=0x04A4; //®¬¥à á⥤ A4040003
*t_p++=0x0200; // A - á⥤, 04 - £®¤, 0003 - ®¬¥à
#elif STEND_N == 3
*t_p++=0; // ª«®
*t_p++=0; //ᬥ饨¥
*t_p++=0; //§ 票¥ €– (¯¥à¢ ï â®çª )
*t_p++=0; //§ 票¥ ⥬¯¥à âãàë 㬮¦¥®¥ 100 (¯¥à¢ ï â®çª )
*t_p++=0; //§ 票¥ €– (¢â®à ï â®çª )
*t_p++=0; //§ 票¥ ⥬¯¥à âãàë 㬮¦¥®¥ 100 (¢â®à ï â®çª )
*t_p++=0x04A4; //®¬¥à á⥤ A4040003
*t_p++=0x0300; // A - á⥤, 04 - £®¤, 0003 - ®¬¥à
#else
warning!!!
#endif
//¯®¬¥é ¥¬ ¢ ¯ ª¥â ¥£® ¤«¨ã (¡¥§ § ¢¥àè î饣® EOFPACKET)
packets[shift_fifo-LENPACKET]=DATA1APACKET;
//¯®¬¥é ¥¬ (¨ 㢥«¨ç¨¢ ¥¬) ¯®à浪®¢ë© ®¬¥à ¯ ª¥â
packets[shift_fifo-NUMPACKET]=counts_packet;
queue[n].numeric=counts_packet++;
//㪠§ë¢ ¥¬ ⨯ ¯ ª¥â
packets[shift_fifo-TYPEPACKET]=0x1A;
//¯®¤áç¨âë¢ ¥¬ ¨ ¯®¬¥é ¥¬ CRC ¯ ª¥â
crc=crc16(&packets[shift_fifo-DATA1APACKET],DATA1APACKET-2);
packets[shift_fifo-CRCPACKET]=crc>>8;
packets[shift_fifo-CRCPACKET+1]=crc;
//¢ á¯à ¢®ç®¬ ¬ áᨢ¥ 㪠§ë¢ ¥¬ ¤«¨ã ¯ ª¥â
queue[n].len=DATA1APACKET;
queue[n].busy=NOTSENDED;
send_correction_temperature=0;
return 1;
}
u8 buffer[SIZE_N_LOADER];
void work_with_serial_rec(void){
int x;
int crc;
u16 shift_fifo;
u16 address;
for (x=0;x<MAXQUE;x++){
if (queue[x].busy==PACKREC){
received_packed--;
//¯®¤áç¨â âì CRC
shift_fifo=x*MAXPACKETLEN+queue[x].len;
if (crc16(&packets[x*MAXPACKETLEN],queue[x].len)==0){ //árc ᮢ¯ « ?
switch(packets[shift_fifo-TYPEPACKET]){
case 0x08:
dac[packets[shift_fifo-NUM_OF_CHANNEL_DAC]&((NUM_CHANEL>>1)-1)]=packets[shift_fifo-VALVE_OF_CHANNEL_DAC]+(packets[shift_fifo-VALVE_OF_CHANNEL_DAC+1]<<8);
break;
case 0x09:
chanel=packets[shift_fifo-CHANNEL_TO_SET];
break;
case 0x0B: //§ ªàëâì ª« ¯
close_valve();
break;
case 0x0C: //®âªàëâì ª« ¯
open_valve();
break;
case 0x0D: //á¯ãáâ¨âì ¤ ¢«¥¨¥ ¤® âॡ㥬®© ¢¥«¨ç¨ë
// ᮤ¥à¦ ¨¥ ¯ ª¥â :
// ¢ ¯ ª¥â¥ á«®¢® (+1 ¡ ©â reserved) - ¡á®«î⮥
// § 票¥ ¤® ª®â®à®£® ¥®¡å®¤¨¬® ®¯ãáâ¨âìáï ¨ § ªàëâì ª« ¯
// 12 ¡¨â ⥪ã饣® ®¯®à®£® (®á®¢®£® ¨«¨ १¥à¢®£®)
// ª «
// ®¡é¥¥ ª®«¨ç¥á⢮ ¤ ëå 3 ¡ ©â
what_doing=NO_JOB;
to_level=packets[shift_fifo-LEVEL_SET]+(packets[shift_fifo-LEVEL_SET+1]<<8);
to_level&=0xFFF;
open_valve();
off_pump();
what_doing=LEVEL_DOWN;
break;
case 0x0E: // ª ç âì ¤ ¢«¥¨¥ ¤® 㪠§ ®© ¢¥«¨ç¨ë
// ᮤ¥à¦ ¨¥ ¯ ª¥â :
// ¢ ¯ ª¥â¥ á«®¢® (+1 ¡ ©â reserved) - ¡á®«î⮥
// § 票¥ ¤® ª®â®à®£® ¥®¡å®¤¨¬® ª ç âì ¤ ¢«¥¨¥
// ¯à¥¤¢ à¨â¥«ì® ¥®¡å®¤¨¬® ¤ âì ª®¬¬ ¤ã
// § ªàëâì ª« ¯
// ®¡é¥¥ ª®«¨ç¥á⢮ ¤ ëå 3 ¡ ©â
what_doing=NO_JOB;
to_level=packets[shift_fifo-LEVEL_SET]+(packets[shift_fifo-LEVEL_SET+1]<<8);
to_level&=0xFFF;
close_valve();
on_pump();
what_doing=LEVEL_UP;
break;
case 0x0F: //¢ëª«îç¨âì ª®¬¯à¥áá®à. „ ï ª®¬ ¤ ¯à¥ªà é ¥â
break;
case 0x15: //ãáâ ®¢ª ¤ ¢«¥¨ï ¯à¨ ¤®á⨦¥¨¨ ª®â®à®£®
break;
case 0x18: //ãáâ ®¢¨âì ०¨¬ë à ¡®âë
if (packets[shift_fifo-REGIM_JOB]&0x01) // ¯à殮¨ï ¤ â稪 å
P4OUT&=~BIT6;
else
P4OUT|=BIT6;
if (packets[shift_fifo-REGIM_JOB]&0x02) // ¯à殮¨ï «®£®¢®© ç áâ¨
{
P1OUT&=~BIT0;
analog_on=1;
P2OUT|=BIT0+BIT1+BIT3; //¢ª«îç ¥¬ –€
P5SEL |= 0x70; // MCLK, SMCLK,ACLK ¢ë¢®¤
}
else{
P5SEL&= ~0x70; // MCLK, SMCLK,ACLK ¢ëª«îç ¥¬ ¢ë¢®¤
P2OUT&=~(BIT0+BIT1+BIT3);
P3OUT&=~(BIT0+BIT1+BIT2+BIT3);
analog_on=0;
P1OUT|=BIT0;
}
if ((stop_adc==0) && packets[shift_fifo-REGIM_JOB]&0x04){ //¢ëª«îç¨âì €–
disable_int_no_interrupt();
chanel_convert&=~0x40; //¢ëª«îç ¥¬ ¯ ª¥âë© à¥¦¨¬
off_adc();
stop_adc=1;
enable_int_no_interrupt();
}
if ((stop_adc==1) && packets[shift_fifo-REGIM_JOB]&0x08){ //¢ª«îç¨âì €–
disable_int_no_interrupt();
init_adc();
stop_adc=0;
enable_int_no_interrupt();
}
if (packets[shift_fifo-REGIM_JOB]&0x10){ //¢ëª«îç¨âì UART
disable_int_no_interrupt();
P3SEL &= ~BIT4; // ¢ëª«îç ¥¬ ¢ ®«ì ¯¥à¥¤ çã USART0
stop_transmit=1;
// P3DIR = 0xFF; // All P3.x outputs
// P3OUT = 0; // All P3.x reset
enable_int_no_interrupt();
}
if (packets[shift_fifo-REGIM_JOB]&0x20){ //¢ª«îç¨âì UART
disable_int_no_interrupt();
P3SEL |= BIT4; // ¢ª«îç ¥¬ ¢ ®«ì ¯¥à¥¤ çã USART0
stop_transmit=0;
// P3DIR = 0xFF; // All P3.x outputs
// P3OUT = 0; // All P3.x reset
enable_int_no_interrupt();
}
if ( (temperature==1) && packets[shift_fifo-REGIM_JOB]&0x40){ //¢ëª«îç¨âì ⥬¯¥à âãàã
disable_int_no_interrupt();
temperature=0;
if (stop_adc==0) { //¥á«¨ €– ¥ ®áâ ®¢«¥
set_adc(chanel_convert,1);
ADC12CTL0 |= ADC12SC; // Start conversion
}
enable_int_no_interrupt();
}
if ((stop_adc==0) && (temperature==0) && packets[shift_fifo-REGIM_JOB]&0x80){ //¢ª«îç¨âì ⥬¯¥à âãàã
disable_int_no_interrupt();
temperature=1;
send_correction_temperature=10000;
set_adc_temperature();
ADC12CTL0 |= ADC12SC; // Start conversion
enable_int_no_interrupt();
}
break;
case 0x1B:
address=packets[shift_fifo-ADDRESS_PACK1B]+(packets[shift_fifo-ADDRESS_PACK1B+1]<<8);
memcpy(&buffer[0],&packets[shift_fifo-ADDRESS_PACK1B_DATA],SIZE_N_LOADER);
break;
}
//®â¯à ¢¨âì ¯®¤â¢¥à¦¤¥¨¥, ¥á«¨ íâ® ¥ 0x01 ⨯ ¯ ª¥â
if (packets[shift_fifo-TYPEPACKET]!=0x01){
shift_fifo=(x+1)*MAXPACKETLEN;
//¯®¬¥é ¥¬ ¯®à浪®¢ë© ®¬¥à ¯ ª¥â ¤«ï ¯®¤â¢¥à¦¤¥¨ï
packets[shift_fifo-NUMPACKET]=packets[x*MAXPACKETLEN+queue[x].len-NUMPACKET];
packets[shift_fifo-LENPACKET]=NUMPACKET; //¤«¨ ¯®¤â¢¥à¦¤ î饣® ¯ ª¥â
//㪠§ë¢ ¥¬ ⨯ ¯ ª¥â
packets[shift_fifo-TYPEPACKET]=0x01; //¯®¤â¢¥à¦¤ î騩 ¯ ª¥â
//¯®¤áç¨âë¢ ¥¬ ¨ ¯®¬¥é ¥¬ CRC ¯ ª¥â
crc=crc16(&packets[shift_fifo-NUMPACKET],NUMPACKET-2);
packets[shift_fifo-CRCPACKET]=crc>>8;
packets[shift_fifo-CRCPACKET+1]=crc;
//¢ á¯à ¢®ç®¬ ¬ áᨢ¥ 㪠§ë¢ ¥¬ ¤«¨ã ¯ ª¥â
queue[x].len=NUMPACKET;
#ifdef DEBUG_SERIAL
packet_in_fifo++;
if (packet_in_fifo_max<packet_in_fifo) packet_in_fifo_max=packet_in_fifo;
#endif //DEBUG_SERIAL
queue[x].busy=NOTSENDED;
}
else{ // íâ® ¯ ª¥â 0x01 ⨯ , ¯®¤â¢¥à¦¤ î騩
queue[x].busy=FREEPLACE;
}
}
else{ // crc ¥ ᮢ¯ «
queue[x].busy=FREEPLACE;
error_packets_crc++;
}
}
}
}
//u8 test[4]={'0','1','2','3'};
extern u16 last_sended_packet;
//¨¨æ¨ «¨§ æ¨ï serial port 0
void init_uart0(void){
}
//¨¨æ¨ «¨§ æ¨ï serial port 1
void init_uart(void){
int x;
#ifdef CABLE
UCTL1 = CHAR; // 8-bit character
UTCTL1 = SSEL1; // UCLK = SMCLK
// UBR01 = 0x45; // 8Mhz/115200 - 69.44
// UBR11 = 0x00; //
// UMCTL1 = 0x2C; // modulation
UBR01 = 0x80; //7.372.800/19200 = 384 (0x180)
UBR11 = 0x01; //
UMCTL1 = 0x00; // no modulation
UBR01 = 0x40; //7.372.800/115200 = 64 (0x40)
UBR11 = 0x00; //
UMCTL1 = 0x00; // no modulation
// UBR01 = 0xC0; //7.372.800/38400 = 192 (0xC0)
// UBR11 = 0x00; //
// UMCTL1 = 0x00; // no modulation
ME2 |= UTXE1 + URXE1; // Enable USART1 TXD/RXD
IE2 |= URXIE1; // Enable USART1 RX+TX interrupt
//+ UTXIE1;
for (x=0;x<MAXQUE;x++) queue[x].busy=FREEPLACE;
last_sended_packet=MAXQUE;
#ifdef DEBUG_SERIAL
fifo_trn_depth_max=0;
fifo_trn_depth=0;
packet_in_fifo=0;
packet_fifo_full=0;
error_packets_crc=0;
#endif
#endif //CABLE
#ifdef STEND
UCTL0 = CHAR; // 8-bit character
UTCTL0 = SSEL1; // UCLK = SMCLK
// UBR00 = 0x45; // 8Mhz/115200 - 69.44
// UBR10 = 0x00; //
// UMCTL0 = 0x2C; // modulation
// UBR00 = 0x80; //7.372.800/19200 = 384 (0x180)
// UBR10 = 0x01; //
// UMCTL0 = 0x00; // no modulation
UBR00 = 0x40; //7.372.800/115200 = 64 (0x40)
UBR10 = 0x00; //
UMCTL0 = 0x00; // no modulation
ME1 |= UTXE0 + URXE0; // Enable USART1 TXD/RXD
IE1 |= URXIE0; // Enable USART1 RX+TX interrupt
//+ UTXIE0;
for (x=0;x<MAXQUE;x++) queue[x].busy=FREEPLACE;
last_sended_packet=MAXQUE;
current_rec_packet=0;
stop_transmit=0;
rec_length=0;
queue[0].busy=PACKBUSY;
#ifdef DEBUG_SERIAL
fifo_trn_depth_max=0;
fifo_trn_depth=0;
packet_in_fifo=0;
packet_fifo_full=0;
error_packets_crc=0;
#endif
received_packed=0;
#endif //STEND
dac[0]=0x7FF;
}