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

📄 simple_socket_server.h

📁 lan911的vhdl源代码
💻 H
字号:
/******************************************************************************* Copyright ? 2004 Altera Corporation, San Jose, California, USA.             ** All rights reserved. All use of this software and documentation is          ** subject to the License Agreement located at the end of this file below.     ********************************************************************************                                                                             ** Author - S. O'Reilly                                                        ** Date - July 4, 2004                                                         ** Module - simple_socket_server.h                                             **                                                                             ** Based on Telnet example by JRK and lwIP & HTTP server ports by PRR          *******************************************************************************//*  * Simple Socket Server (SSS) example.  *  * Please refer to the Nios II lwIP Tutorial documentation for details on this  * software example, as well as details on how to configure the lwIP TCP/IP  * networking stack and MicroC/OS-II Real-Time Operating System.  The Nios II * lwIP Tutorial, along with the rest of the Nios II documentation is published  * on the Altera web-site.  See:  * Start Menu -> Programs -> Nios II Development Kit -> Nios II Documentation. * In particular, chapter 9 of the Nios II Software Developer's Handbook  * describes Ethernet & LightWeight IP. *  * Software Design Methodology Note: *  * The naming convention used in the Simple Socket Server Tutorial employs * capitalized software module references as prefixes to variables to identify * public resources for each software module, while lower-case  * variables with underscores indicate a private resource used strictly  * internally to a software module. *  * The software modules are named and have capitalized variable identifiers as * follows: *  * SSS      Simple Socket Server software module   * LED      Light Emitting Diode Management software module * NETUTILS Network Utilities software module *  * LWIP     Light Weight INternet Protocol RTOS software component * OS       Micrium MicroC/OS-II Real-Time Operating System software component */ #ifndef __SIMPLE_SOCKET_SERVER_H__#define __SIMPLE_SOCKET_SERVER_H__#ifndef LWIP  #error The Simple Socket Server lwIP Tutorial requires the   #error Lightweight Internet Protocol (lwIP) IP Software Component#endif#ifndef __ucosii__  #error This Simple Socket Server lwIP Tutorial requires   #error the MicroC/OS-II Intellectual Property Software Component.#endif/* * Task Prototypes: *  *    LEDManagementTask() - Manages the LEDs on the Nios Development Board,  * driven by commands received via a MicroC/OS-II queue, SSSLEDCommmandQ. *  *    SSSSimpleSocketServerTask() - Manages the socket server connection and  * calls relevant subroutines to manage the socket connection. *  *    LED7SegLightshowTask() blinks the 7-segment LEDs with a random pattern.  * The pattern stops and starts in response to LEDManagementTask's posting and  * pending to the MicroC/OS-II semaphore named SSSLEDLightshowSem. *  *    SSSInitialTask() instantiates all of the MicroC/OS-II resources. *  *    NETUTILSDHCPTimeoutTask() is useful in development for assigning a static  * IP address only after a DHCP timeout period has expired.  This task should  * not be used in a deployed system, which should be designed to use either a  * static IP address or employ a way to quickly obtain an IP address for fast  * embedded application startup. */void LEDManagementTask();void LED7SegLightshowTask();void SSSSimpleSocketServerTask();void SSSInitialTask();void NETUTILSDHCPTimeoutTask();/* *  Task Priorities: *  *  MicroC/OS-II only allows one task (thread) per priority number.    */#define LED_MANAGEMENT_TASK_PRIORITY            7#define LED_7SEG_LIGHTSHOW_TASK_PRIORITY        18#define SSS_SIMPLE_SOCKET_SERVER_TASK_PRIORITY  10#define SSS_INITIAL_TASK_PRIORITY               1#define NETUTILS_DHCP_TIMEOUT_TASK_PRIORITY     2/* * LWIP_RX_ETHER_TASK_PRIORITY sets the priority for an lwIP task launched in  * lwip_devices_init, called lwip_dev_rx.   * This lwIP task acts as the bottom half of a UNIX style driver. * When an ethernet packet is received, the ethernet receive interrupt handler * clears the bit and puts a message on the Q for this task. The high priority  * lwip_dev_rx task is responsible for reading  * in packets and dispatching them to the lwIP main TCP/IP networking stack  * task. */#define LWIP_RX_ETHER_TASK_PRIORITY         3/*  * lwIP main TCP/IP networking stack task, launched by lwip_stack_init.  */#define LWIP_TCPIP_TASK_PRIORITY                6/* * Time we wait for DHCP to assign an IP address before settling on a static * address (default is 120 seconds). */#define DHCP_TIMEOUT ((120 * 1000)/100)/*  * The IP, gateway, and subnet mask address below are used as a last resort if  * if no network settings can be found, and DHCP (if enabled) fails. You can * edit these as a quick-and-dirty way of changing network settings if desired. *  * Default fall-back address: *           IP: 10.0.0.51 *      Gateway: 10.0.0.255 *  Subnet Mask: 255.255.255.0 */#define IPADDR0   192#define IPADDR1   168#define IPADDR2   1#define IPADDR3   88#define GWADDR0   192#define GWADDR1   168#define GWADDR2   1#define GWADDR3   255#define MSKADDR0  255#define MSKADDR1  255#define MSKADDR2  255#define MSKADDR3  0/* * IP Port(s) for our application(s) */#define SSS_PORT 30/* Definition of Task Stacks for tasks not using lwIP */#define   TASK_STACKSIZE       1024extern OS_STK    SSSInitialTaskStk[TASK_STACKSIZE];extern OS_STK    LEDManagementTaskStk[TASK_STACKSIZE];extern OS_STK    LED7SegLightshowTaskStk[TASK_STACKSIZE];/*  * Nios Development Boards are programmed on the production line with a unique * MAC address & network settings in the last sector of flash memory. *  * Stratix II based Nios Development Boards have 16 megabytes of flash memory,  * so the last flash sector is located starting at offset 0x00FF0000 from  * the flash base.  For Stratix II, the flash base address is 0x02000000, as * defined in system.h.  So the LAST_FLASH_SECTOR physical address is 0x02FF0000. *  * For Stratix and Cyclone based Nios Development Boards, which have 8 megabytes  * of flash memory, the last flash sector is located at offset address 0x7F0000  * from a flash memory base address of 0 as defined in system.h. So the  * LAST_FLASH_SECTOR address is 0x007F0000 for Stratix and Cyclone based Nios  * Development Boards. *  * LAST_FLASH_SECTOR is used in the get_mac_addr() function defined in  * network_utilities.c */ /* Stratix II based Nios and DSP Development Board */#if defined(ALTERA_NIOS_DEV_BOARD_STRATIX_2S60_ES) ||\    defined(ALTERA_NIOS_DEV_BOARD_STRATIX_2S60)    || \    defined(ALTERA_DSP_DEV_BOARD_STRATIX_2S60_ES) ||\    defined(ALTERA_NIOS_DEV_BOARD_CYCLONE_2C35)#define LAST_SECTOR_OFFSET  0x001F0000#endif/* Stratix and Cyclone based Nios Development Board */#if defined(ALTERA_NIOS_EVAL_BOARD_CYCLONE_1C12) ||\    defined(ALTERA_NIOS_DEV_BOARD_STRATIX_1S10) ||\    defined(ALTERA_NIOS_DEV_BOARD_STRATIX_1S10_ES) ||\    defined(ALTERA_NIOS_DEV_BOARD_STRATIX_1S40)    #define LAST_SECTOR_OFFSET  0x001F0000#endif/* All Nios Development Boards */#define LAST_FLASH_SECTOR FLASH_BASE + LAST_SECTOR_OFFSET/*  * Defined commands for the sss server to interpret */#define CMD_LEDS_BIT_0_TOGGLE   '0'#define CMD_LEDS_BIT_1_TOGGLE   '1'#define CMD_LEDS_BIT_2_TOGGLE   '2'#define CMD_LEDS_BIT_3_TOGGLE   '3'#define CMD_LEDS_BIT_4_TOGGLE   '4'#define CMD_LEDS_BIT_5_TOGGLE   '5'#define CMD_LEDS_BIT_6_TOGGLE   '6'#define CMD_LEDS_BIT_7_TOGGLE   '7'#define CMD_LEDS_LIGHTSHOW      'S'#define CMD_QUIT                'Q'  /*  * Bit Masks for LED Toggles  */#define BIT_0 0x1#define BIT_1 0x2#define BIT_2 0x4#define BIT_3 0x8#define BIT_4 0x10#define BIT_5 0x20#define BIT_6 0x40#define BIT_7 0x80/*  * TX & RX buffer sizes for all socket sends & receives in our sss app */#define SSS_RX_BUF_SIZE  1500#define SSS_TX_BUF_SIZE  1500/*  * Here we structure to manage sss communication for a single connection */typedef struct SSS_SOCKET{  enum { READY, COMPLETE, CLOSE } state;   int       fd;  int       close;  INT8U     rx_buffer[SSS_RX_BUF_SIZE];  INT8U     *rx_rd_pos; /* position we've read up to */  INT8U     *rx_wr_pos; /* position we've written up to */} SSSConn;/* * Handles to our MicroC/OS-II resources. All of the resources beginning with  * "SSS" are declared eclared in file "simple_socket_server.c". *//* * Handle to our MicroC/OS-II Command Queue for sending commands received  * on the TCP-IP socket from the SSSSimpleSocketServerTask to the LEDTask. */extern OS_EVENT *SSSLEDCommandQ;/* * Handle to our MicroC/OS-II LED Event Flag.  Each flag corresponds to one of * the LEDs on the Nios Development board, D0 - D7.  */extern OS_FLAG_GRP *SSSLEDEventFlag;/* * Handle to our MicroC/OS-II LED Lightshow Semaphore. The semaphore is checked  * by the SSSLEDLightshowTask each time it updates 7 segment LED displays,  * U8 and U9.  The LEDTask grabs the semaphore away from the lightshow task to * toggle the lightshow off, and gives up the semaphore to turn the lightshow * back on.  The LEDTask does this in response to the CMD_LEDS_LIGHTSHOW * command sent from the SSSSimpleSocketServerTask when user sends the toggle  * lightshow command over the TCPIP socket. */extern OS_EVENT *SSSLEDLightshowSem;/* * Handle to our MicroC/OS-II LED IP address Semaphore.  The semaphore is posted * when an IP address has been set, either using a static value, or in response  * to a reply from a DHCP server.  An application can pend on this semaphore in  * order to wait for a valid IP address before opening sockets, if desired. */ extern OS_EVENT *SSSAttainedIPAddressSem;#endif /* __SIMPLE_SOCKET_SERVER_H__ *//*******************************************************************************                                                                             ** License Agreement                                                           **                                                                             ** Copyright (c) 2004 Altera Corporation, San Jose, California, USA.           ** All rights reserved.                                                        **                                                                             ** Permission is hereby granted, free of charge, to any person obtaining a     ** copy of this software and associated documentation files (the "Software"),  ** to deal in the Software without restriction, including without limitation   ** the rights to use, copy, modify, merge, publish, distribute, sublicense,    ** and/or sell copies of the Software, and to permit persons to whom the       ** Software is furnished to do so, subject to the following conditions:        **                                                                             ** The above copyright notice and this permission notice shall be included in  ** all copies or substantial portions of the Software.                         **                                                                             ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     ** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         ** DEALINGS IN THE SOFTWARE.                                                   **                                                                             ** This agreement shall be governed in all respects by the laws of the State   ** of California and by the laws of the United States of America.              ** Altera does not recommend, suggest or require that this reference design    ** file be used in conjunction or combination with any other product.          *******************************************************************************/

⌨️ 快捷键说明

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