日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]  TCP/IP Stack  使用pic18f97j60開發(fā)過多個(gè)項(xiàng)目,項(xiàng)目中都使用了Microchip免費(fèi)提供的TCP/IP Stack實(shí)現(xiàn)遠(yuǎn)程控制。但是每次更新程序,都需要將pic18f97j60目標(biāo)板取回來重新燒錄,很不方便。既然可以實(shí)現(xiàn)遠(yuǎn)程控制,

  TCP/IP Stack

  使用pic18f97j60開發(fā)過多個(gè)項(xiàng)目,項(xiàng)目中都使用了Microchip免費(fèi)提供的TCP/IP Stack實(shí)現(xiàn)遠(yuǎn)程控制。但是每次更新程序,都需要將pic18f97j60目標(biāo)板取回來重新燒錄,很不方便。既然可以實(shí)現(xiàn)遠(yuǎn)程控制,為什么不實(shí)現(xiàn)遠(yuǎn)程更新呢?這就是我的ethernet bootloader的由來。Microchip的TCP/IP Stack功能很強(qiáng)大,我決定只用它的UDP模塊來實(shí)現(xiàn)。為了實(shí)現(xiàn)遠(yuǎn)程更新,我需要寫pic18f97j60單片機(jī)端UDP協(xié)議的ethernet bootloader程序--我將其命名為PhnBoot_v1.0; 同時(shí)還需要寫PC端與bootloader交互的UDP通信程序--我將其命名為PhnLoader_v1.0。我還定義了PhnBoot_v1.0和PhnLoader_v1.0之間傳輸數(shù)據(jù)的通信協(xié)定。

  通信協(xié)定

  單片機(jī)端PhnBoot_v1.0和PC端PhnLoader_v1.0之間的通信數(shù)據(jù)包采用以下協(xié)定

...

  定義如下:

STX - Start of packet indicator
ETX - End of packet indicator
LEN - The length of true data
DATA - General data 16 bytes, only first LEN of datas are true
CMD - Base command
ADDR - Address up to 24 bits ( ADDRL , ADDRH , ADDRH)

  具體有以下Base command:

RD-VER: 0x00 -- Read Version Information (最終版本刪除了此命令)
RD_MEM: 0x01 -- Read Program Memory (最終版本刪除了此命令)
ER_MEM: 0x03 -- Erase Program Memory
WR_MEM: 0x02 -- Write Program Memory
WR_CFG: 0x04 -- Write Configuration Registers

  PhnLoader_v1.0 功能

  定義好了通訊協(xié)定, 接著就按照協(xié)定去實(shí)現(xiàn)PhnLoader_v1.0。 PhnLoader_v1.0的具體功能包括選擇IP地址,端口和協(xié)議類型,目前只支持UDP協(xié)議, 創(chuàng)建UDP服務(wù)器,加載應(yīng)用程序Hex文件,Parse 應(yīng)用程序的Hex文件,一行一行解讀Hex文件,一旦收到更新請(qǐng)求,立刻按照通訊協(xié)定采用UDP協(xié)議發(fā)送Hex記錄到單片機(jī),接收單片機(jī)發(fā)送回來的Response,發(fā)送完畢后斷開UDP通信,發(fā)送期間出現(xiàn)問題就立馬結(jié)束發(fā)送。

  PhnLoader_v1.0 主要代碼段

  PhnLoader_v1.0是用C#實(shí)現(xiàn)的,是我在利用空余時(shí)間自學(xué)C#后寫的,上面提到的功能都實(shí)現(xiàn)了。


privatevoidbtnDownload_Click(objectsender,EventArgse){btnDownload.Enabled=false;pBarLoading.Visible=false;if(!this.connect()){Debug.WriteLine("Udpserverbuildingunsuccessfully");textBoxStatus.ForeColor=Color.Red;textBoxStatus.AppendText("Udpserverbuildingunsuccessfullyrn");textBoxStatus.ForeColor=Color.Black;btnDownload.Enabled=true;return;}try{loaderReader=newStreamReader(textBoxFile.Text);}catch(Exceptionex){Debug.WriteLine("Error:"+ex.Message);textBoxStatus.ForeColor=Color.Red;textBoxStatus.AppendText("Readhexfileunsuccessfullyrn");textBoxStatus.ForeColor=Color.Black;loaderReader.Close();loaderServer.Close();btnDownload.Enabled=true;return;}loaderFrame=newSerialFrame();DateTimestartTime=DateTime.Now;IPEndPointclientPoint=newIPEndPoint(IPAddress.Any,0);if(!loaderServer.Read(readyMsg,timeSpan)){Debug.WriteLine("Error:Timeoutreceivereadymessagefrombootloader");textBoxStatus.ForeColor=Color.Red;textBoxStatus.AppendText("Timeoutreceivereadymessagefrombootloaderrn");textBoxStatus.ForeColor=Color.Black;loaderServer.Close();loaderReader.Close();btnDownload.Enabled=true;return;}if(!erase()){textBoxStatus.ForeColor=Color.Red;textBoxStatus.AppendText("Eraseunsuccessfullyrn");textBoxStatus.ForeColor=Color.Black;loaderReader.Close();loaderServer.Close();btnDownload.Enabled=true;return;}pBarLoading.Refresh();pBarLoading.Visible=true;pBarLoading.Value=0;pBarLoading.Maximum=loaderLines;pBarLoading.Step=1;stringrecordLine;Address_U=0;boolisNextLineUserID=false;boolisNextLineConfigBits=false;textBoxStatus.AppendText("rnDownloadinghexfile...rn");try{while(loaderReader.Peek()>=0){pBarLoading.PerformStep();recordLine=loaderReader.ReadLine();if(recordLine.Contains(EXTEND_TOKEN)==true){if(recordLine.Contains(USER_ID_TOKEN)==true){isNextLineUserID=true;continue;}elseif(recordLine.Contains(CONFIG_BITS_TOKEN)==true){constintADDR_U_START_INDEX=9;constintADDR_U_LENGTH=4;stringaddrU=recordLine.Substring(ADDR_U_START_INDEX,ADDR_U_LENGTH);Address_U=Convert.ToInt32(addrU,16)<<16;isNextLineConfigBits=true;continue;}else{constintADDR_U_START_INDEX=9;constintADDR_U_LENGTH=4;stringaddrU=recordLine.Substring(ADDR_U_START_INDEX,ADDR_U_LENGTH);Address_U=Convert.ToInt32(addrU,16)<<16;continue;}}elseif(((recordLine.Contains(J_TYPE_CONFIG_BITS_1)==true)||(recordLine.Contains(J_TYPE_CONFIG_BITS_2)==true)||(recordLine.Contains(J_TYPE_CONFIG_BITS_3)==true)||(recordLine.Contains(J_TYPE_CONFIG_BITS_4)==true)||(recordLine.Contains(J_TYPE_CONFIG_BITS_5)==true)||(recordLine.Contains(J_TYPE_CONFIG_BITS_6)==true)||(recordLine.Contains(J_TYPE_CONFIG_BITS_TOKEN_1)==true)||(recordLine.Contains(J_TYPE_CONFIG_BITS_TOKEN_2)==true))&&(Address_U==0x010000)){if(!DownloadConfigLine(recordLine)){Debug.WriteLine("Errorfoundduringconfigurationbitsprogramming");loaderReader.Close();loaderServer.Close();btnDownload.Enabled=true;return;}continue;}elseif(recordLine.Contains(END_OF_HEX_FILE_TOKEN)==true){break;}if(isNextLineUserID){isNextLineUserID=false;//donothing;}elseif(isNextLineConfigBits){if(!DownloadConfigLine(recordLine)){Debug.WriteLine("Errorfoundduringconfigurationbitsprogramming");loaderReader.Close();loaderServer.Close();btnDownload.Enabled=true;return;}isNextLineConfigBits=false;}else{if(!DownloadDataLine(recordLine)){Debug.WriteLine("Errorfoundduringdataprogramming");loaderReader.Close();loaderServer.Close();btnDownload.Enabled=true;return;}}}}catch(Exceptionex){Debug.WriteLine("Error:"+ex.Message);textBoxStatus.ForeColor=Color.Red;textBoxStatus.AppendText("Downloadingfailedrn");textBoxStatus.ForeColor=Color.Black;loaderServer.Close();loaderReader.Close();btnDownload.Enabled=true;return;}textBoxStatus.AppendText("Downloadingcompletedrn");if(!run()){textBoxStatus.ForeColor=Color.Red;textBoxStatus.AppendText("JumptoApplicationunsuccessfullyrn");textBoxStatus.ForeColor=Color.Black;loaderReader.Close();loaderServer.Close();btnDownload.Enabled=true;return;}loaderServer.Close();loaderReader.Close();btnDownload.Enabled=true;}

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

總線-Ethernet與EtherCAT的比較

關(guān)鍵字: ethercat ethernet

    UDP簡(jiǎn)介         UDP 是User Datagram Protocol的簡(jiǎn)稱, 中文名是用戶數(shù)據(jù)報(bào)協(xié)議,是OS

關(guān)鍵字: udp協(xié)議

  UDP協(xié)議也是互聯(lián)網(wǎng)基礎(chǔ)協(xié)議之一。它和TCP一樣同屬于傳輸層當(dāng)中的一個(gè)協(xié)議。   不過UDP協(xié)議是一個(gè)面向無連接的協(xié)議(TCP是向面連接的協(xié)議)。一個(gè)UDP連接的建立,不必象TCP協(xié)

關(guān)鍵字: udp協(xié)議 包格式

  QUdpSocket   QUdpSocket是QAbstractSocket 的子類,它們都繼承了QIODevice。所以可以用QUdpSocket進(jìn)行發(fā)送接收數(shù)據(jù)。它和QTcpS

關(guān)鍵字: qudpsocket udp協(xié)議

  在進(jìn)行UDP協(xié)議的使用中,我們通常會(huì)借助其他語言工具來完成工作。那么今天我們主要介紹一下Java下的UDP協(xié)議的使用。首先我們來了解一下UDP協(xié)議的基本概念。UDP協(xié)議的全稱是用戶數(shù)據(jù)報(bào),在

關(guān)鍵字: udp協(xié)議

  隨著半導(dǎo)體技術(shù)的不斷進(jìn)步(按照摩爾定律),MCU內(nèi)部集成的邏輯功能外設(shè)越來越多,存儲(chǔ)器也越來越大。消費(fèi)者對(duì)于汽車節(jié)能(經(jīng)濟(jì)和法規(guī)對(duì)排放的要求)型、舒適性、互聯(lián)性、安全性(功能安全和信息安全)

關(guān)鍵字: bootloader 汽車電子

1.之所以要實(shí)現(xiàn)一個(gè)專用的bootloader,一是為了更好的移植和自身的升級(jí),二是為了方便操作系統(tǒng)的調(diào)試,當(dāng)然,你完全可以將這部分所要實(shí)現(xiàn)的與操作系統(tǒng)相關(guān)的功能集成到操作

關(guān)鍵字: bootloader 如何實(shí)現(xiàn) 嵌入式開發(fā)
關(guān)閉