⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ntp.lis

📁 AVR单片机系统开发经典实例部分源程序
💻 LIS
📖 第 1 页 / 共 3 页
字号:
                        .module ntp.c
                        .area text(rom, con, rel)
 0000                   .dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ntp.c
 0000                   .dbfunc e NTP_RequestSNTP _NTP_RequestSNTP fc
 0000                   .dbstruct 0 48 TNTP
 0000                   .dbfield 0 mode c
 0000                   .dbfield 1 stratum c
 0000                   .dbfield 2 poll c
 0000                   .dbfield 3 Precision c
 0000                   .dbfield 4 RootDelay l
 0000                   .dbfield 8 RootDisperson l
 0000                   .dbfield 12 RefID l
 0000                   .dbfield 16 Ref1 l
 0000                   .dbfield 20 Ref2 l
 0000                   .dbfield 24 Org1 l
 0000                   .dbfield 28 Org2 l
 0000                   .dbfield 32 Rcv1 l
 0000                   .dbfield 36 Rcv2 l
 0000                   .dbfield 40 Xmit1 l
 0000                   .dbfield 44 Xmit2 l
 0000                   .dbend
 0000           ;            NTP -> R20,R21
 0000           ;             IP -> y+6
                        .even
 0000           _NTP_RequestSNTP::
 0000 0E940000          xcall push_arg4
 0004 0E940000          xcall push_gset1
 0008 2497              sbiw R28,4
 000A                   .dbline -1
 000A                   .dbline 66
 000A           ; 
 000A           ; /*
 000A           ;  * Copyright (C) 2003-2004 by Clive Moss All rights reserved.
 000A           ;  *
 000A           ;  * Help & Contributions from D.J.Armstrong
 000A           ; 
 000A           ;  * Redistribution and use in source and binary forms, with or without
 000A           ;  * modification, are permitted provided that the following conditions
 000A           ;  * are met:
 000A           ;  *
 000A           ;  * 1. Redistributions of source code must retain the above copyright
 000A           ;  *    notice, this list of conditions and the following disclaimer.
 000A           ;  * 2. Redistributions in binary form must reproduce the above copyright
 000A           ;  *    notice, this list of conditions and the following disclaimer in the
 000A           ;  *    documentation and/or other materials provided with the distribution.
 000A           ;  * 3. Neither the name of the copyright holders nor the names of
 000A           ;  *    contributors may be used to endorse or promote products derived
 000A           ;  *    from this software without specific prior written permission.
 000A           ;  *
 000A           ;  * THIS SOFTWARE IS PROVIDED BY CLIVE MOSS 'AS IS' AND ANY EXPRESS OR
 000A           ;  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 000A           ;  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 000A           ;  * ARE DISCLAIMED.
 000A           ;  * IN NO EVENT SHALL CLIVE MOSS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 000A           ;  * INDIRECT, INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 000A           ;  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 000A           ;  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 000A           ;  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 000A           ;  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
 000A           ;  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 000A           ;  * SUCH DAMAGE.
 000A           ;  */
 000A           ; 
 000A           ; //#ifdef CPU_eZ8
 000A           ; //    #pragma stkck                                                                   // enable stack checking
 000A           ; //#endif
 000A           ; 
 000A           ; #include <string.h>
 000A           ; #include <stdio.h>
 000A           ; //#include <math.h>
 000A           ; 
 000A           ; #include "common.h"
 000A           ; #include "ppp.h"
 000A           ; #include "ip.h"
 000A           ; #include "udp.h"
 000A           ; #include "ntp.h"
 000A           ; 
 000A           ; #define HoursPerDay           24
 000A           ; #define MinsPerDay            (HoursPerDay * 60)
 000A           ; #define SecsPerDay            (MinsPerDay * 60)
 000A           ; #define MSecsPerDay           (SecsPerDay * 1000)
 000A           ; 
 000A           ; #ifdef CPU_eZ8
 000A           ; volatile near u16                     NTP_Timer;
 000A           ; volatile near T_IP_Addr               NTP_IP;
 000A           ; #endif
 000A           ; #ifdef CPU_ATmega128
 000A           ; volatile u16                          NTP_Timer;
 000A           ; volatile T_IP_Addr                    NTP_IP;
 000A           ; #endif
 000A           ; 
 000A           ; //*********************************************************************************************************************
 000A           ; // request the date & time using SNTP
 000A           ; 
 000A           ; bool NTP_RequestSNTP(u32 IP)
 000A           ; {
 000A                   .dbline 69
 000A           ;       T_NTP   *NTP;
 000A           ; 
 000A           ;       if (!UDP_StartPacket(IP, 123, 123)) return false;                                                                       //
 000A 8BE7              ldi R24,123
 000C 90E0              ldi R25,0
 000E 9B83              std y+3,R25
 0010 8A83              std y+2,R24
 0012 9983              std y+1,R25
 0014 8883              std y+0,R24
 0016 FE01              movw R30,R28
 0018 0681              ldd R16,z+6
 001A 1781              ldd R17,z+7
 001C 2085              ldd R18,z+8
 001E 3185              ldd R19,z+9
 0020 0E940000          xcall _UDP_StartPacket
 0024 0023              tst R16
 0026 11F4              brne L2
 0028                   .dbline 69
 0028 0027              clr R16
 002A 31C0              xjmp L1
 002C           L2:
 002C                   .dbline 71
 002C           ;                                                                                                                                                                               //
 002C           ;       NTP = (T_NTP*)(MainBuffer + MainBufferWr_Tx);                                                                           //
 002C 80E0              ldi R24,<_MainBuffer
 002E 90E0              ldi R25,>_MainBuffer
 0030 40910000          lds R20,_MainBufferWr_Tx
 0034 50910100          lds R21,_MainBufferWr_Tx+1
 0038 480F              add R20,R24
 003A 591F              adc R21,R25
 003C                   .dbline 72
 003C           ;       memset(NTP, 0, sizeof(T_NTP));                                                                                                          //
 003C 80E3              ldi R24,48
 003E 90E0              ldi R25,0
 0040 9983              std y+1,R25
 0042 8883              std y+0,R24
 0044 2227              clr R18
 0046 3327              clr R19
 0048 8A01              movw R16,R20
 004A 0E940000          xcall _memset
 004E                   .dbline 73
 004E           ;       NTP->mode = 0x1b;                                                                                                                                       //
 004E 8BE1              ldi R24,27
 0050 FA01              movw R30,R20
 0052 8083              std z+0,R24
 0054                   .dbline 74
 0054           ;       MainBufferWr_Tx += sizeof(T_NTP);                                                                                                       // update index
 0054 80910000          lds R24,_MainBufferWr_Tx
 0058 90910100          lds R25,_MainBufferWr_Tx+1
 005C C096              adiw R24,48
 005E 90930100          sts _MainBufferWr_Tx+1,R25
 0062 80930000          sts _MainBufferWr_Tx,R24
 0066                   .dbline 76
 0066           ;                                                                                                                                                                               //
 0066           ;       u16_Put(&NTP_Timer, 0);                                                                                                                         // reset the timer
 0066 2227              clr R18
 0068 3327              clr R19
 006A 00E0              ldi R16,<_NTP_Timer
 006C 10E0              ldi R17,>_NTP_Timer
 006E 0E940000          xcall _u16_Put
 0072                   .dbline 77
 0072           ;       u32_Put(&NTP_IP.ip32, IP);                                                                                                                      // remember the ip we are getting the ntp from
 0072 FE01              movw R30,R28
 0074 2680              ldd R2,z+6
 0076 3780              ldd R3,z+7
 0078 4084              ldd R4,z+8
 007A 5184              ldd R5,z+9
 007C 4882              std y+0,R4
 007E 5982              std y+1,R5
 0080 9101              movw R18,R2
 0082 00E0              ldi R16,<_NTP_IP
 0084 10E0              ldi R17,>_NTP_IP
 0086 0E940000          xcall _u32_Put
 008A                   .dbline 79
 008A           ;                                                                                                                                                                               //
 008A           ;       return UDP_EndPacket();                                                                                                                         //
 008A 0E940000          xcall _UDP_EndPacket
 008E                   .dbline -2
 008E           L1:
 008E 2496              adiw R28,4
 0090 0E940000          xcall pop_gset1
 0094 2496              adiw R28,4
 0096                   .dbline 0 ; func end
 0096 0895              ret
 0098                   .dbsym r NTP 20 pS[TNTP]
 0098                   .dbsym l IP 6 l
 0098                   .dbend
 0098                   .dbfunc e NTP_DecodeSNTP _NTP_DecodeSNTP fV
 0098           ;            sec -> R14,R15
 0098           ;            min -> R12,R13
 0098           ;           hour -> R10,R11
 0098           ;            lag -> y+12
 0098           ;             dw -> y+8
 0098           ;            NTP -> R10,R11
 0098           ;             IP -> y+24
                        .even
 0098           _NTP_DecodeSNTP::
 0098 0E940000          xcall push_arg4
 009C 0E940000          xcall push_gset5
 00A0 2E97              sbiw R28,14
 00A2 AC8C              ldd R10,y+28
 00A4 BD8C              ldd R11,y+29
 00A6                   .dbline -1
 00A6                   .dbline 86
 00A6           ; }
 00A6           ; 
 00A6           ; //*********************************************************************************************************************
 00A6           ; // decode an SNTP reply (UDP packet on port 123 normally)
 00A6           ; 
 00A6           ; void NTP_DecodeSNTP(u32 IP, T_NTP *NTP)
 00A6           ; {
 00A6                   .dbline 92
 00A6           ; //    TDateTime               FNTPTime;
 00A6           ; //    double                  Nsec, Nfrac;
 00A6           ;       u32                             dw;
 00A6           ;       u16                             hour, min, sec, lag;
 00A6           ; 
 00A6           ;       if (!NTP) return;                                                               //
 00A6 AA20              tst R10
 00A8 19F4              brne L5
 00AA BB20              tst R11

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -