Exemple #1
0
// implementation
static int CommandReset(_CMDIO_DEV_NODE* pCmdIO, int argc, char** argv)
{
    const void* cmdIoParam = pCmdIO->cmdIoParam;
    (*pCmdIO->pCmdApi->msg)(cmdIoParam, LINE_TERM " *** System Reboot ***\r\n" );
    SYS_Reboot();
    return 0;
}
Exemple #2
0
/*********************************************************************
 * Function:        void RebootTask(NET_CONFIG* pConfig)
 *
 * PreCondition:    Stack is initialized()
 *
 * Input:           pConfig   - interface 
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Checks for incomming traffic on port 69.  
 *					Resets the PIC if a 'R' is received.
 *
 * Note:            This module is primarily for use with the 
 *					Ethernet bootloader.  By resetting, the Ethernet 
 *					bootloader can take control for a second and let
 *					a firmware upgrade take place.
 ********************************************************************/
void RebootTask(NET_CONFIG* pConfig)
{
	struct
	{
		uint8_t vMACAddress[6];
		uint32_t dwIPAddress;
		uint16_t wChecksum;
	} BootloaderAddress;
    int netIx;

    netIx = _TCPIPStackNetIx(pConfig);

	
	if(MySocket[netIx] == INVALID_UDP_SOCKET)
    {
        MySocket[netIx] = UDPOpen(0,UDP_OPEN_SERVER,REBOOT_PORT,INVALID_UDP_PORT);

        if(MySocket[netIx] == INVALID_UDP_SOCKET)
        {
            return;
        }
        UDPSocketSetNet(MySocket[netIx], pConfig);
    }

	// Do nothing if no data is waiting
	if(!UDPIsGetReady(MySocket[netIx]))
		return;
    
	#if defined(REBOOT_SAME_SUBNET_ONLY)
		// Respond only to name requests sent to us from nodes on the same subnet
     	if((remoteNode.IPAddr.Val & pConfig->MyMask.Val) != (pConfig->MyIPAddr.Val & pConfig->MyMask.Val))
		{
			UDPDiscard(pConfig);
			return;
		}
	#endif

	// Get our MAC address, IP address, and compute a checksum of them 
	memcpy((void*)&BootloaderAddress.vMACAddress[0], (void*)&pConfig->MyMACAddr.v[0], sizeof(pConfig->MyMACAddr));
	BootloaderAddress.dwIPAddress = pConfig->MyIPAddr.Val;
	BootloaderAddress.wChecksum = CalcIPChecksum((uint8_t*)&BootloaderAddress, sizeof(BootloaderAddress) - sizeof(BootloaderAddress.wChecksum));
	
	// To enter the bootloader, we reset the system
	SYS_OUT_MESSAGE("Bootloader Reset");

	SYS_Reboot();
}
Exemple #3
0
INT32 mdr_KfcDrvIoctl(struct inode *inode, struct file *file, UINT32 cmd, unsigned long arg)
{
    READ_WRITE_REG32_T regBuf;
	KERNEL_FUNC_CALL_T kernel_func_call; 

	switch (cmd)
	{
        case KFC_NOTICE_FEED_DOG:
            //lock
            //user_notice_feeddog = 1;
            //unlock
            SYS_ResetWatchdog();
            break;

		case KFC_NOTICE_SYS_REBOOT:
			SYS_Reboot();
			break;
		case KFC_READ_REG8:	//read fpga reg8
            copy_from_user(&regBuf, (void*)arg, sizeof(READ_WRITE_REG32_T));
            regBuf.value = mdr_com_readb(regBuf.addr);
            copy_to_user((void*)arg, &regBuf, sizeof(READ_WRITE_REG32_T));
			break;
		case KFC_WRITE_REG8://write fpga reg8
            copy_from_user(&regBuf, (void*)arg, sizeof(READ_WRITE_REG32_T));
            mdr_com_writeb(regBuf.value, regBuf.addr);
			break;
		case KFC_READ_REG32:	//read reg32
            copy_from_user(&regBuf, (void*)arg, sizeof(READ_WRITE_REG32_T));
            regBuf.value = mdr_com_readl(regBuf.addr);
            copy_to_user((void*)arg, &regBuf, sizeof(READ_WRITE_REG32_T));
			break;
		case KFC_WRITE_REG32://write reg32
            copy_from_user(&regBuf, (void*)arg, sizeof(READ_WRITE_REG32_T));
            mdr_com_writel(regBuf.value, regBuf.addr);
            break;
		case KFC_CALL_KERNEL_FUNCTION://call kernel function
		{			
			UINT32 para[5]; 
			UINT8 *string[5]; 
			INT32 i = 0;

			for (i = 0; i < 5; i++)
			{
			    para[i] = 0;
				string[i] = NULL;
			}

            copy_from_user(&kernel_func_call, (void*)arg, sizeof(KERNEL_FUNC_CALL_T));
			
			kernel_symbol_entry = (void(*)
				(UINT32, UINT32, UINT32, 
			UINT32, UINT32 ))kernel_func_call.symbol_addr;

			Mdr_ComPrint("entry(%08x)\n", (UINT32)kernel_symbol_entry );
			i = 0;
			while (kernel_func_call.para_count > i)
			{
				if (kernel_func_call.func_para[i].type == FUNC_PARA_TYPE_STRING)		
				{//for string
					Mdr_ComPrint("string para[%d]\n", i);
					string[i] = kmalloc(kernel_func_call.func_para[i].length+1, GFP_KERNEL);
					memset(string[i], 0, kernel_func_call.func_para[i].length+1);
					Mdr_ComPrint("string value(%x), len(%d)\n", 
						kernel_func_call.func_para[i].value,
						kernel_func_call.func_para[i].length);
					copy_from_user((void*)string[i], 
						(void *)kernel_func_call.func_para[i].value , 
						kernel_func_call.func_para[i].length );
					Mdr_ComPrint(" string after copy: [%s] \n", string[i]);

					para[i] = (UINT32)(&(string[i][1]));//delete first '#'
					Mdr_ComPrint(" %s \n", (UINT8*)para[i]);
				}
				else
				{
					para[i] = kernel_func_call.func_para[i].value;
					Mdr_ComPrint("INT32 para[%d], %08x\n", i, para[i]);
				}
				
				i ++;
			}
	
 			(*kernel_symbol_entry)(para[0], para[1], para[2], para[3], para[4]);
	
			Mdr_ComPrint("call function ok \n");
			for (i = 0; i < 5; i++)
			{
				if (string[i] != NULL)
				{
					kfree(string[i]);	
				}
			}
			Mdr_ComPrint("return from ioctl \n");

			break;
		}
		default:
			break;
	}
	return 0;
}
Exemple #4
0
//
// Main application entry point.
//
int main(void)
{

#if defined(APP_USE_IPERF)
    static uint8_t iperfOk = 0;
#endif
    static SYS_TICK startTick = 0;
    static IP_ADDR dwLastIP[sizeof (TCPIP_HOSTS_CONFIGURATION) / sizeof (*TCPIP_HOSTS_CONFIGURATION)];
    uint8_t i;


    // perform system initialization
    if(!SYS_Initialize())
    {
        return 0;
    }

    SYS_CONSOLE_MESSAGE("\r\n\n\n --- Unified TCPIP Demo Starts! --- \r\n");

    SYS_OUT_MESSAGE("TCPStack " TCPIP_STACK_VERSION "  ""                ");

    #if defined(TCPIP_STACK_USE_MPFS) || defined(TCPIP_STACK_USE_MPFS2)
	MPFSInit();
	#endif

    // Initiates board setup process if button is depressed 
	// on startup
    if(BUTTON0_IO == 0u)
    {
        #if defined(TCPIP_STACK_USE_STORAGE)  && (defined(SPIFLASH_CS_TRIS) || defined(EEPROM_CS_TRIS))
		// Invalidate the EEPROM contents if BUTTON0 is held down for more than 4 seconds
		SYS_TICK StartTime = SYS_TICK_Get();
		LED_PUT(0x00);
				
		while(BUTTON0_IO == 0u)
		{
			if(SYS_TICK_Get() - StartTime > 4*SYS_TICK_TicksPerSecondGet())
			{
                TCPIP_STORAGE_HANDLE hStorage;
                
                // just in case we execute this before the stack is initialized
                TCPIP_STORAGE_Init(0);
                hStorage = TCPIP_STORAGE_Open(0, false);   // no refresh actually needed
                if(hStorage)
                {
                    TCPIP_STORAGE_Erase(hStorage);
                    SYS_CONSOLE_MESSAGE("\r\n\r\nBUTTON0 held for more than 4 seconds.  Default settings restored.\r\n\r\n");
                    TCPIP_STORAGE_Close(hStorage);
                }
                else
                {
                    SYS_ERROR(SYS_ERROR_WARN, "\r\n\r\nCould not restore the default settings!!!.\r\n\r\n");
                }
                TCPIP_STORAGE_DeInit(0);
                
				LED_PUT(0x0F);
                // wait 4.5 seconds here then reset
				while((SYS_TICK_Get() - StartTime) <= (9*SYS_TICK_TicksPerSecondGet()/2));
				LED_PUT(0x00);
				while(BUTTON0_IO == 0u);
				SYS_Reboot();
				break;
			}
		}
        #endif  // defined(TCPIP_STACK_USE_STORAGE)  && (defined(SPIFLASH_CS_TRIS) || defined(EEPROM_CS_TRIS))
    }

    // Initialize the TCPIP stack
    if(!TCPIP_STACK_Init(TCPIP_HOSTS_CONFIGURATION, sizeof(TCPIP_HOSTS_CONFIGURATION)/sizeof(*TCPIP_HOSTS_CONFIGURATION),
                       TCPIP_STACK_MODULE_CONFIG_TBL, sizeof(TCPIP_STACK_MODULE_CONFIG_TBL)/sizeof(*TCPIP_STACK_MODULE_CONFIG_TBL) ))
    {
        return 0;
    }
#if defined(TCPIP_STACK_USE_TELNET_SERVER)
    TelnetRegisterCallback(ProcessIO);
#endif  // defined(TCPIP_STACK_USE_TELNET_SERVER)

#if defined (TCPIP_STACK_USE_IPV6)
    TCPIP_ICMPV6_RegisterCallback (ICMPv6Callback);
#endif

#if defined(TCPIP_STACK_USE_ICMP_CLIENT) || defined(TCPIP_STACK_USE_ICMP_SERVER)
    ICMPRegisterCallback (PingProcessIPv4);
#endif


#if defined(TCPIP_STACK_USE_EVENT_NOTIFICATION)
    TCPIP_NET_HANDLE hWiFi = TCPIP_STACK_NetHandle("MRF24W");
    if(hWiFi)
    {
        TCPIP_STACK_SetNotifyEvents(hWiFi, TCPIP_EV_RX_ALL|TCPIP_EV_TX_ALL|TCPIP_EV_RXTX_ERRORS);
        TCPIP_STACK_SetNotifyHandler(hWiFi, StackNotification, 0);
    }
#endif  // defined(TCPIP_STACK_USE_EVENT_NOTIFICATION)


#if defined(APP_USE_IPERF)
    IperfConsoleInit();
    iperfOk = IperfAppInit(TCPIP_HOSTS_CONFIGURATION[0].interface);
#endif

	// Now that all items are initialized, begin the co-operative
	// multitasking loop.  This infinite loop will continuously 
	// execute all stack-related tasks, as well as your own
	// application's functions.  Custom functions should be added
	// at the end of this loop.
    // Note that this is a "co-operative mult-tasking" mechanism
    // where every task performs its tasks (whether all in one shot
    // or part of it) and returns so that other tasks can do their
    // job.
    // If a task needs very long time to do its job, it must be broken
    // down into smaller pieces so that other tasks can have CPU time.
    while(1)
    {
        // Blink LED0 (right most one) every second.
        if(SYS_TICK_Get() - startTick >= SYS_TICK_TicksPerSecondGet()/2ul)
        {
            startTick = SYS_TICK_Get();
            LED0_IO ^= 1;
        }

        // This task performs normal stack task including checking
        // for incoming packet, type of packet and calling
        // appropriate stack entity to process it.
        TCPIP_STACK_Task();


		// Process application specific tasks here.
		// For this demo app, this will include the Generic TCP 
		// client and servers, and the SNMP, Ping, and SNMP Trap
		// demos.  Following that, we will process any IO from
		// the inputs on the board itself.
		// Any custom modules or processing you need to do should
		// go here.
		#if defined(TCPIP_STACK_USE_GENERIC_TCP_CLIENT_EXAMPLE)
		GenericTCPClient();
		#endif
		
		#if defined(TCPIP_STACK_USE_GENERIC_TCP_SERVER_EXAMPLE)
		GenericTCPServer();
		#endif
		
		#if defined(TCPIP_STACK_USE_SMTP_CLIENT)
		SMTPDemo();
		#endif
		
		#if defined(TCPIP_STACK_USE_ICMP_CLIENT) || defined (TCPIP_STACK_USE_ICMP_SERVER) || defined (TCPIP_STACK_USE_IPV6)
        // use ping on the default interface
		PingDemoTask();
		#endif
		
		#if defined(TCPIP_STACK_USE_SNMP_SERVER) && !defined(SNMP_TRAP_DISABLED)
		//User should use one of the following SNMP demo
		// This routine demonstrates V1 or V2 trap formats with one variable binding.
		SNMPTrapDemo();
		
		#if defined(SNMP_STACK_USE_V2_TRAP) || defined(SNMP_V1_V2_TRAP_WITH_SNMPV3)
		//This routine provides V2 format notifications with multiple (3) variable bindings
		//User should modify this routine to send v2 trap format notifications with the required varbinds.
		//SNMPV2TrapDemo();
		#endif 
		if(gSendTrapFlag)
			SNMPSendTrap();
		#endif
		
		#if defined(TCPIP_STACK_USE_BERKELEY_API)
		BerkeleyTCPClientDemo();
		BerkeleyTCPServerDemo();
		BerkeleyUDPClientDemo(0);
		#endif


#if defined(APP_USE_IPERF)
        IperfConsoleProcess();
        if (iperfOk) IperfAppCall();    // Only running in case of init succeed
        IperfConsoleProcessEpilogue();
#endif

        // If the local IP address has changed (ex: due to DHCP lease change)
        // write the new IP address to the console display, UART, and Announce
        // service
        // We use the default interface
        for (i = 0; i < sizeof(TCPIP_HOSTS_CONFIGURATION)/sizeof(*TCPIP_HOSTS_CONFIGURATION); i++)
        {	
            TCPIP_NET_HANDLE netH = TCPIP_STACK_NetHandle(TCPIP_HOSTS_CONFIGURATION[i].interface);
			if((uint32_t)dwLastIP[i].Val != TCPIP_STACK_NetAddress(netH))
			{
				dwLastIP[i].Val = TCPIP_STACK_NetAddress(netH);
				
				SYS_CONSOLE_MESSAGE(TCPIP_HOSTS_CONFIGURATION[i].interface);
				SYS_CONSOLE_MESSAGE(" new IP Address: ");
			
				DisplayIPValue(dwLastIP[i]);
			
				SYS_CONSOLE_MESSAGE("\r\n");
			
            }
        }

#if defined(TCPIP_STACK_USE_EVENT_NOTIFICATION)
        if(stackNotifyCnt)
        {
            stackNotifyCnt = 0;
            ProcessNotification(stackNotifyHandle);
        }
#endif  // defined(TCPIP_STACK_USE_EVENT_NOTIFICATION)
	}
}