?? main.c
字號:
///
// Copyright (c) 2003, Wolver Wang, MinShan Inc. R&D Center
// wolver@minshan-inc.com
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. All advertising materials mentioning features or use of this software
// must display the following acknowledgement:
// This product includes software developed by Wolver Wang.
// 4. The name of the author may not be used to endorse or promote
// products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
///
///
// Copyright (c) 2003, Wolver Wang, MinShan Inc. R&D Center
// wolver@minshan-inc.com
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. All advertising materials mentioning features or use of this software
// must display the following acknowledgement:
// This product includes software developed by Wolver Wang.
// 4. The name of the author may not be used to endorse or promote
// products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
///
///
// 版權 2003, 王衛無,四川綿陽岷山集團有限公司--研究開發中心
// wolver@minshan-inc.com
// 保留一切權利
//
// 如果符合以下條件,則無論是以原代碼或非原代碼代碼形式,且不論是否修改,
// 再分發和使用本軟件都是被允許的。
// 1. 原代碼的再分發必須保留上述的版權聲明、本條件說明和以下免責聲明。
// 2. 非原代碼形式的再分發,必須在證明文件和(或)其它一同提供的材料中重新
// 作上述的版權聲明、本條件說明和以下免責聲明。
// 3. 一切提及本軟件和使用的廣告材料必須顯示以下致謝:
// 本產品包含王衛無(四川綿陽岷山集團有限公司--研究開發中心)開發的軟件。
// 4. 如果沒有預先得到特定的書面許可,不能用作者的名字來宣傳推廣基于本軟件得到
// 的產品。
//
// 免責聲明:
// 本軟件是由某某作者提供,如果出現以下情況,作者都不承擔任何責任。
// 1. 因作者的說明以及任何明確的或暗示的保證(包括但不限于表達某種商業性和適合某一
// 特定目的暗示性保證)而產生的損失。
// 2. 無論在何種情況下,對使用本軟件造成的任何直接的、間接的、偶然的、特定的、可預
// 見性的和連帶產生的損失(包括但不限于獲取產品和服務、作用喪失、數據遺失、利益損
// 失或商業干預),無論這些損失是怎樣造成的,并且是以何種方式闡釋責任。
// 3. 任何因使用本軟件而相關的合同、嚴格賠償責任和侵權行為(包含:疏忽或其它)的損失,
// 甚至即便是可能的此類已經明示或暗示的損失。
///
#include "system.h"
#include "tcpip.h"
#include "drivers.h"
// 定義應用:1 表示開啟功能,0 表示關閉功能
#define cTCP_RS232 1 // TCP <-> RS232 的應用,只用于服務模式
#define cTCP_ADAC 1 // TCP <-> Audio, 主要用于服務,也可以用于客戶。要求高帶寬: > 912Kbit
// 分配本地用戶自定義服務模式應用TCP端口號,不能與知名端口相同!如:23, 80
// 注意:對不同的TCP事件使用不同的本地端口號,有助于快速查找TCP事件而不需要判斷IP是否相同!
// 這樣做能使本地快速響應。
#define cTCP_ListenPort_TEST 0x1000 // 4096
#if cTCP_RS232 == 1
#define cTCP_ListenPort_RS232 0x2000 // 8192
#endif
#if cTCP_ADAC == 0
#define cTCP_ListenPort_ADAC 0x3000 // 12288
#endif
// 客戶應用模式的本地TCP端口號。不能與知名端口相同!如:23, 80
// 注意:對不同的TCP事件使用不同的本地端口號(包括:本地偵聽端口),有助于快速查找TCP事件而
// 不需要判斷IP是否相同!這樣做能使本地快速響應。
#if (cTCP_ADAC == 1) && (TCP_ACTIVE_OPEN == 1)
#define cTCP_ActivePort_ADAC 0x3001 // 12289
#endif
// 分配系統應用臨時緩沖區(按 wrod 存儲)
UINT16 guwAppBuf[cAppSizeMax];
//--------------------------------------------------------------------------------------
main(){
#if TCP_ACTIVE_OPEN == 1
UINT16 temp[2];
#endif
// 1. Hardware initialize: SPCE061A
SP_IO_INIT();
// 2. Open and Enable Hardware interrupt 2Hz and Clear WatchDog!
SP_OpenTime2();
// 3. Hardware initialize: RTL8019AS
RTL8019AS_RESET();
RTL8019AS_INIT();
// 4. vIP4 TCP/IP initialize
msip_Init();
// 5. We listen test port
msip_Listen(cTCP_ListenPort_TEST); // 用于偵聽來自鏈路測試的TCP包
#if cTCP_RS232 == 1
SP_UART_INIT(C_UART_Baud_115200); // Hardware initialize: UART of SPCE061A
msip_Listen(cTCP_ListenPort_RS232); // 用于偵聽來自RS232的TCP包
#endif
#if cTCP_ADAC == 1
// SP_ADAC_INIT(cSample_4096); // Open ADAC
// SP_ADAC_INIT(cSample_8192); // Open ADAC
// SP_ADAC_INIT(cSample_16384); // Open ADAC
// SP_ADAC_INIT(cSample_32768); // Open ADAC
// SP_CLOSE_FIQ(); // 關閉FIQ中斷,同時也禁止了ADAC
msip_Listen(cTCP_ListenPort_ADAC); // 用于偵聽來自遠端的Audio的TCP包
#endif
#if (cTCP_ADAC == 1) && (TCP_ACTIVE_OPEN == 1)
// for test audio, wo active link remote: 192.168.0.60
temp[0] = ((192<<8)|168);
temp[1] = ((0<<8)|30);
msip_Connect(cTCP_ActivePort_ADAC, temp, cTCP_ListenPort_ADAC);
#endif
// 6. We do TCP/IP Check Loop
loop:
// 接收新的以太包,并處理
if ((guwEthLen = ether_Receive()) != 0){
switch (cptEthHdrBuf->EthType){
case cEthType_Arp:
msip_Arp_In();
break;
case cEthType_Ip:
msip_Input();
}
}
// ARP表老化處理
if (guwMsg_Route & cM_ARP_TIME){
msip_Arp_Time();
}
// TCP事件輪詢
if (guwMsg_Route & cM_TCP_PERIODIC){
msip_Periodic();
}
goto loop;
}
// SUB-SUB-SUB-SUB-SUB-SUB-SUB-SUB-SUB-SUB-SUB-SUB-SUB-SUB-SUB-SUB-SUB-SUB-SUB-SUB-SUB
//--------------------------------------------------------------------------------------
//
// |--------------| |-----|----------|------| |------|--------|
// |工業設備|RS232| <---> |RS232|核心嵌入板|TCP/IP| <---> |TCP/IP|普通PC機|
// |--------------| |-----|----------|------| |------|--------|
//
//-------------------------------------------------------------------------------------
void userapp(){
switch (gptConn->LocalPort){
#if cTCP_RS232 == 1
case cTCP_ListenPort_RS232:
goto link_rs232;
#endif
#if cTCP_ADAC == 1 // ADAC 工作時:由于雙向通訊,所以Listen和Active處理是一樣的!
case cTCP_ListenPort_ADAC:
goto link_adac_listen;
#endif
#if (cTCP_ADAC == 1) && (TCP_ACTIVE_OPEN == 1) // ADAC 工作時:由于雙向通訊,所以Listen和Active處理是一樣的!
case cTCP_ActivePort_ADAC:
goto link_adac_active;
#endif
case cTCP_ListenPort_TEST:
goto test_net;
default:
return;
}
#if cTCP_RS232 == 1
link_rs232: // 與RS232透明傳輸通訊:本系統的一個應用。
// 以下事件的過慮判斷并不按照事件發生的順序,是因為有些事件通常只會發生一次,
// 從而在大多數其它經常發生的事件狀態下,減少對那些事件的過濾判斷,以提高速度!!!
if (msip_Poll() || msip_Acked()){ // 如果RS232有數據要發送,就轉發TCP數據段!
if (guwUartRxLen > 0) { // 根據guwUartRxLen判斷是否轉發RS232數據
MEMCPY(guwUartRxLen, guwUartRxBuf, cpTcpData);
guwEthLen = guwUartRxLen;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -