/****************************************************************************** * Copyright (c) 2006 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. * ******************************************************************************* * * Date - October 24, 2006 * * Module - iniche_init.c * * * * ******************************************************************************/ /****************************************************************************** * NicheStack TCP/IP stack initialization and Operating System Start in main() * for Simple Socket Server (SSS) example. * * This example demonstrates the use of MicroC/OS-II running on NIOS II. * In addition it is to serve as a good starting point for designs using * MicroC/OS-II and Altera NicheStack TCP/IP Stack - NIOS II Edition. * * Please refer to the Altera NicheStack Tutorial documentation for details on * this software example, as well as details on how to configure the NicheStack * TCP/IP networking stack and MicroC/OS-II Real-Time Operating System. */ #include /* MicroC/OS-II definitions */ #include "includes.h" #include "system.h" /* Simple Socket Server definitions */ #include "simple_socket_server.h" #include "alt_error_handler.h" /* Nichestack definitions */ #include "ipport.h" #include "libport.h" #include "osport.h" #include "altera_avalon_tse.h" #include "altera_avalon_uart.h" #include "altera_avalon_uart_regs.h" #include "altera_avalon_pio_regs.h" #include "triple_speed_ethernet_regs.h" #include "altera_avalon_sgdma_regs.h" //extern alt_u8 max_mac_system; /* Definition of TSE system */ extern alt_tse_system_info tse_mac_device[MAXNETS]; /* Definition of task stack for the initial task which will initialize the NicheStack * TCP/IP Stack and then initialize the rest of the Simple Socket Server example tasks. */ OS_STK SSSInitialTaskStk[TASK_STACKSIZE]; /* Declarations for creating a task with TK_NEWTASK. * All tasks which use NicheStack (those that use sockets) must be created this way. * TK_OBJECT macro creates the static task object used by NicheStack during operation. * TK_ENTRY macro corresponds to the entry point, or defined function name, of the task. * inet_taskinfo is the structure used by TK_NEWTASK to create the task. */ TK_OBJECT(to_ssstask); TK_ENTRY(SSSSimpleSocketServerTask); struct inet_taskinfo ssstask = { &to_ssstask, "simple socket server", SSSSimpleSocketServerTask, 4, APP_STACK_SIZE, }; volatile alt_u32 mask_pio_out; void temporisation(long tmp) { long i; for(i=0;i<=(tmp*200000);i++) { } } /* SSSInitialTask will initialize the NicheStack * TCP/IP Stack and then initialize the rest of the Simple Socket Server example * RTOS structures and tasks. */ void SSSInitialTask(void *task_data) { INT8U error_code; /* * Initialize Altera NicheStack TCP/IP Stack - Nios II Edition specific code. * NicheStack is initialized from a task, so that RTOS will have started, and * I/O drivers are available. Two tasks are created: * "Inet main" task with priority 2 * "clock tick" task with priority 3 */ // printf(" avant alt iniche \n\r"); alt_iniche_init(); // printf(" avant net main \n\r"); netmain(); printf(" apres alt iniche et netmain \n\r"); /* Wait for the network stack to be ready before proceeding. * iniche_net_ready indicates that TCP/IP stack is ready, and IP address is obtained. */ while (!iniche_net_ready) TK_SLEEP(1); /* Now that the stack is running, perform the application initialization steps */ /* Application Specific Task Launching Code Block Begin */ printf("\nSimple Socket Server starting up\n"); /* Create the main simple socket server task. */ TK_NEWTASK(&ssstask); /*create os data structures */ SSSCreateOSDataStructs(); /* create the other tasks */ SSSCreateTasks(); /* Application Specific Task Launching Code Block End */ /*This task is deleted because there is no need for it to run again */ error_code = OSTaskDel(OS_PRIO_SELF); alt_uCOSIIErrorHandler(error_code, 0); while (1); /* Correct Program Flow should never get here */ } /* Main creates a single task, SSSInitialTask, and starts task scheduler. */ int main (int argc, char* argv[], char* envp[]) { INT8U error_code; np_tse_mac *pmac; mask_pio_out=0; printf(" prog 27 07 Main \n\r"); //init pio out pour mettre reset_phy à 1 mask_pio_out=mask_pio_out | 0x8; IOWR(PIO_OUT_BASE, 0, mask_pio_out); //hard reset_phy mask_pio_out=mask_pio_out & 0xFFFFFFF7; IOWR(PIO_OUT_BASE, 0,mask_pio_out ); temporisation(9); mask_pio_out=mask_pio_out | 0x8; IOWR(PIO_OUT_BASE, 0,mask_pio_out ); printf(" Hard Reset PHY \n\r"); //soft reset mac pmac=TRIPLE_SPEED_ETHERNET_0_BASE; tse_mac_SwReset(pmac); //set addr mdio IOWR_ALTERA_TSEMAC_MDIO_ADDR0(TRIPLE_SPEED_ETHERNET_0_BASE,0x12); //init (global) max_mac_system (2 matches) // max_mac_system=1; //marvell en gmii marvell_cfg_gmii(pmac); tse_mac_device[0].desc_mem_base=DESCRIPTOR_MEMORY_BASE; tse_mac_device[0].ext_desc_mem=1;//0; tse_mac_device[0].tse_en_maclite=TRIPLE_SPEED_ETHERNET_0_ENABLE_MACLITE; tse_mac_device[0].tse_mac_base=TRIPLE_SPEED_ETHERNET_0_BASE; tse_mac_device[0].tse_maclite_gige=TRIPLE_SPEED_ETHERNET_0_MACLITE_GIGE; tse_mac_device[0].tse_mdio_shared=TRIPLE_SPEED_ETHERNET_0_MDIO_SHARED; tse_mac_device[0].tse_multichannel_mac=TRIPLE_SPEED_ETHERNET_0_IS_MULTICHANNEL_MAC; tse_mac_device[0].tse_num_of_channel=TRIPLE_SPEED_ETHERNET_0_NUMBER_OF_CHANNEL; tse_mac_device[0].tse_number_of_mac_mdio_shared=TRIPLE_SPEED_ETHERNET_0_NUMBER_OF_MAC_MDIO_SHARED; tse_mac_device[0].tse_pcs_ena=TRIPLE_SPEED_ETHERNET_0_PCS; tse_mac_device[0].tse_pcs_sgmii=TRIPLE_SPEED_ETHERNET_0_PCS_SGMII; // tse_mac_device[0].tse_phy_cfg=alt_tse_phy_init;//(pmac); tse_mac_device[0].tse_phy_mdio_address=0x12; tse_mac_device[0].tse_rx_depth=TRIPLE_SPEED_ETHERNET_0_RECEIVE_FIFO_DEPTH; tse_mac_device[0].tse_sgdma_rx=RX_SGDMA_NAME; tse_mac_device[0].tse_sgdma_rx_irq=TX_SGDMA_IRQ; tse_mac_device[0].tse_sgdma_tx=TX_SGDMA_NAME; tse_mac_device[0].tse_shared_fifo_rx_ctrl_base=0; tse_mac_device[0].tse_shared_fifo_rx_depth=0; tse_mac_device[0].tse_shared_fifo_rx_stat_base=0; tse_mac_device[0].tse_shared_fifo_tx_ctrl_base=0; tse_mac_device[0].tse_shared_fifo_tx_depth=0; tse_mac_device[0].tse_shared_fifo_tx_stat_base=0; tse_mac_device[0].tse_tx_depth=TRIPLE_SPEED_ETHERNET_0_TRANSMIT_FIFO_DEPTH; tse_mac_device[0].tse_use_mdio=1; tse_mac_device[0].use_shared_fifo=0;//TRIPLE_SPEED_ETHERNET_0_REGISTER_SHARED; printf(" prog sss \n\r"); /* Clear the RTOS timer */ OSTimeSet(0); /* SSSInitialTask will initialize the NicheStack * TCP/IP Stack and then initialize the rest of the Simple Socket Server example * RTOS structures and tasks. */ error_code = OSTaskCreateExt(SSSInitialTask, NULL, (void *)&SSSInitialTaskStk[TASK_STACKSIZE], SSS_INITIAL_TASK_PRIORITY, SSS_INITIAL_TASK_PRIORITY, SSSInitialTaskStk, TASK_STACKSIZE, NULL, 0); alt_uCOSIIErrorHandler(error_code, 0); /* * As with all MicroC/OS-II designs, once the initial thread(s) and * associated RTOS resources are declared, we start the RTOS. That's it! */ OSStart(); while(1); /* Correct Program Flow never gets here. */ return -1; } /****************************************************************************** * * * License Agreement * * * * Copyright (c) 2006 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. * ******************************************************************************/