static void dchild6( DREC *pdr, CHILD *pc )
{
    int rc;

    // Get the lock to synchronize with parent
    SemPend( hDSem6, SEM_FOREVER );
    SemPost( hDSem6 );

    // This function returns "1" if the socket is still open,
    // and "0" is the socket has been closed.
    rc = pdr->pCb( pc->s,  pdr->Argument );

    // Close the socket if we need to
    // We do this before we get the lock so if the socket
    // uses LINGER, we don't hold everyone up
    if( rc && pc->closeSock )
        fdClose( pc->s );

    // Get our lock
    SemPend( hDSem6, SEM_FOREVER );

    // Close the socket session (if open)
    if( pc->hTask )
        fdCloseSession( pc->hTask );

    // Remove our record from the DREC
    if( pc->pNext )
        pc->pNext->pPrev = pc->pPrev;
    if( !pc->pPrev )
        pdr->pC = pc->pNext;
    else
        pc->pPrev->pNext = pc->pNext;
    pdr->TasksSpawned--;

    // Free our record
    mmFree( pc );

    // Kick the parent thread
    if( hDTask6 )
        fdSelectAbort( hDTask6 );

    // Release the lock
    SemPost( hDSem6 );

    TaskExit();
}
static void daemon6()
{
    int                   i,closeSock;
    struct sockaddr_in6   sin1;
    SOCKET                tsock;
    CHILD*                pc;

    // Enter our lock
    SemPend( hDSem6, SEM_FOREVER );

    for(;;)
    {
        //
        // Create any socket that needs to be created
        //
        for( i=0; i<DAEMON_MAXRECORD; i++ )
        {
            if( drec6[i].Type && drec6[i].s == INVALID_SOCKET )
            {
                // Create UDP or TCP as needed
                if( drec6[i].Type == SOCK_DGRAM )
                    drec6[i].s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
                else
                    drec6[i].s = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);

                // If the socket was created, bind it
                if( drec6[i].s != INVALID_SOCKET )
                {
                    // Bind to the specified Server port
                    bzero( &sin1, sizeof(struct sockaddr_in) );
                    sin1.sin6_family     = AF_INET6;
                    memcpy((void *)&sin1.sin6_addr,(void *)&drec6[i].LocalAddress, sizeof(struct in6_addr));
                    sin1.sin6_port       = htons(drec6[i].LocalPort);

                    if( bind( drec6[i].s,(struct sockaddr *)&sin1, sizeof(sin1) ) < 0 )
                    {
                        fdClose( drec6[i].s );
                        drec6[i].s = INVALID_SOCKET;
                    }
                }

                // If the socket is bound and TCP, start listening
                if( drec6[i].s != INVALID_SOCKET && drec6[i].Type != SOCK_DGRAM )
                {
                    if( listen( drec6[i].s, drec6[i].MaxSpawn ) < 0 )
                    {
                        fdClose( drec6[i].s );
                        drec6[i].s = INVALID_SOCKET;
                    }
                }
            }

            // Update the fdPoll array
            pollitem6[i].fd = drec6[i].s;
            if( drec6[i].Type && drec6[i].TasksSpawned < drec6[i].MaxSpawn )
                pollitem6[i].eventsRequested = POLLIN;
            else
                pollitem6[i].eventsRequested = 0;
        }

        // Leave our lock
        SemPost( hDSem6 );

        // Poll with a timeout of 10 second - to try and catch
        // synchronization error
        if( fdPoll( pollitem6, DAEMON_MAXRECORD, 10000 ) == SOCKET_ERROR )
            break;

        // Enter our lock
        SemPend( hDSem6, SEM_FOREVER );

        //
        // Spawn tasks for any active sockets
        //
        for( i=0; i<DAEMON_MAXRECORD; i++ )
        {
            // If no poll results or the drec6 has been freed, skip it
            if( !pollitem6[i].eventsDetected || !drec6[i].Type )
                continue;

            // If the socket is invalid, close it
            if( pollitem6[i].eventsDetected & POLLNVAL )
            {
                fdClose( drec6[i].s);
                drec6[i].s = INVALID_SOCKET;
                continue;
            }

            if( pollitem6[i].eventsDetected & POLLIN )
            {
                if( drec6[i].Type == SOCK_DGRAM )
                {
                    tsock = drec6[i].s;
                    closeSock = 0;
                }
                else
                {
                    tsock = accept( drec6[i].s, 0, 0 );
                    closeSock = 1;
                }

                if( tsock != INVALID_SOCKET )
                {
                    // Create a record to track this task
                    pc = mmAlloc( sizeof(CHILD) );
                    if( !pc )
                        goto spawnComplete;

                    // Create the task
                    pc->hTask = TaskCreate( dchild6, "dchild6",
                                            drec6[i].Priority, drec6[i].StackSize,
                                            (UINT32)&drec6[i], (UINT32)pc, 0);
                    if( !pc->hTask )
                    {
                        mmFree( pc );
                        goto spawnComplete;
                    }

                    // Open a socket session for the child task
                    fdOpenSession( pc->hTask );

                    // Fill in the rest of the child record
                    pc->closeSock = closeSock;
                    pc->s = tsock;

                    // Now we won't close the socket here
                    closeSock = 0;

                    // Link this record onto the DREC
                    drec6[i].TasksSpawned++;
                    pc->pPrev = 0;
                    pc->pNext = drec6[i].pC;
                    drec6[i].pC = pc;
                    if( pc->pNext )
                        pc->pNext->pPrev = pc;

spawnComplete:
                    // If there was an error, we may need to close the socket
                    if( closeSock )
                        fdClose( tsock );
                }
            }
        }
    }

    TaskExit();
}
示例#3
0
int hpdspuaStart (void) {

	   uint32_t coreId;
	   QMSS_CFG_T      qmss_cfg;
	      CPPI_CFG_T      cppi_cfg;
	   /* determine the core number. */
	      coreId = CSL_chipReadReg (CSL_CHIP_DNUM);
	      led_no=coreId;

	      platform_write("num of cores  %d starts twinkling its LED\n", number_of_cores);
	      platform_write("core = %d starts twinkling its LED\n", coreId);
	      //platform_uart_init();
	      //platform_uart_set_baudrate(115200);
//	      write_uart("AAAAAAAA");
	      gpioInit();
	      gpioSetDirection(GPIO_10 ,GPIO_IN);   //DOUTA pin
	      gpioSetDirection(GPIO_3 ,GPIO_OUT);   //CNVST pin
	      gpioSetDirection(GPIO_13 ,GPIO_OUT);  //CS pin
	      gpioSetDirection(GPIO_7 ,GPIO_OUT);  //SCLK

	      //ADDR = 0, VA1 and VB1 are sampled;  ADDR =1, VA2 and VB2 are sampled
	      //Right now VA1 and VB1 are being sampled
	      gpioSetOutput(GPIO_7);   //By default clock high
	      gpioSetOutput(GPIO_3);   // by default conversion pin high
	      gpioSetOutput(GPIO_13);   // BY Default CS pin high

          gpioSetFallingEdgeInterrupt(GPIO_10);
          gpioSetRisingEdgeInterrupt(GPIO_10);
	  	  gpioEnableGlobalInterrupt();

	  	  //Wait for 100us before starting first conversion
	      platform_delay(100);
	      int rc=0;
	      while(1) {
		    if(coreId==0)
		    {



		    	    if (platform_get_coreid() == 0)
		    	    {
		    	        qmss_cfg.master_core        = 1;
		    	    }
		    	    else
		    	    {
		    	        qmss_cfg.master_core        = 0;
		    	    }
		    	    qmss_cfg.max_num_desc       = MAX_NUM_DESC;
		    	    qmss_cfg.desc_size          = MAX_DESC_SIZE;
		    	    qmss_cfg.mem_region         = Qmss_MemRegion_MEMORY_REGION0;
		    	    if (res_mgr_init_qmss (&qmss_cfg) != 0)
		    	    {
		    	        platform_write ("Failed to initialize the QMSS subsystem \n");
		    	        goto main_exit;
		    	    }
		    	    else
		    	    {
		    	        platform_write ("QMSS successfully initialized \n");
		    	    }


		    	    if (platform_get_coreid() == 0)
		    	    {
		    	        cppi_cfg.master_core        = 1;
		    	    }
		    	    else
		    	    {
		    	        cppi_cfg.master_core        = 0;
		    	    }
		    	    cppi_cfg.dma_num            = Cppi_CpDma_PASS_CPDMA;
		    	    cppi_cfg.num_tx_queues      = NUM_PA_TX_QUEUES;
		    	    cppi_cfg.num_rx_channels    = NUM_PA_RX_CHANNELS;
		    	    if (res_mgr_init_cppi (&cppi_cfg) != 0)
		    	    {
		    	        platform_write ("Failed to initialize CPPI subsystem \n");
		    	        goto main_exit;
		    	    }
		    	    else
		    	    {
		    	        platform_write ("CPPI successfully initialized \n");
		    	    }


		    	    if (res_mgr_init_pass()!= 0) {
		    	        platform_write ("Failed to initialize the Packet Accelerator \n");
		    	        goto main_exit;
		    	    }
		    	    else
		    	    {
		    	        platform_write ("PA successfully initialized \n");
		    	    }



		    	    rc = NC_SystemOpen( NC_PRIORITY_HIGH, NC_OPMODE_INTERRUPT );

		    	    if( rc ) {
		    	        platform_write("NC_SystemOpen Failed (%d). Will die in an infinite loop so you need to reset...\n",rc);
		    	        for(;;);
		    	    }

		    	    platform_write("HUA version %s\n", BLM_VERSION);

		    	        hCfg = CfgNew();
		    	    if( !hCfg )
		    	    {
		    	        platform_write("Unable to create a configuration for the IP stack.\n");
		    	        goto main_exit;
		    	    }


		    	    strcpy (HostName, "tidemo-");
		    	    i = strlen(HostName);
		    	    j = strlen(gPlatformInfo.serial_nbr);

		    	    if (j > 0) {
		    	        if (j > 6) {
		    	            memcpy (&HostName[i], &gPlatformInfo.serial_nbr[j-6], 6);
		    	            HostName[i+7] = '\0';
		    	        }
		    	        else {
		    	            memcpy (&HostName[i], gPlatformInfo.serial_nbr, j);
		    	            HostName[i+j+1] = '\0';
		    	        }
		    	    }


		    	    if( strlen( DomainName ) >= CFG_DOMAIN_MAX ||
		    	        strlen( HostName ) >= CFG_HOSTNAME_MAX )
		    	    {
		    	        platform_write("Domain or Host Name too long\n");
		    	        goto main_exit;
		    	    }

		    	    platform_write("Setting hostname to %s \n", HostName);

		    	    platform_write("MAC Address: %02X-%02X-%02X-%02X-%02X-%02X \n",
		    	            gPlatformInfo.emac.efuse_mac_address[0], gPlatformInfo.emac.efuse_mac_address[1],
		    	            gPlatformInfo.emac.efuse_mac_address[2], gPlatformInfo.emac.efuse_mac_address[3],
		    	            gPlatformInfo.emac.efuse_mac_address[4], gPlatformInfo.emac.efuse_mac_address[5]);

		    	    CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,
		    	                 strlen(HostName), (uint8_t *)HostName, 0 );

		    	    if (!platform_get_switch_state(1)) {

		    	        CI_IPNET NA;
		    	        CI_ROUTE RT;
		    	        IPN      IPTmp;
		    	        bzero( &NA, sizeof(NA) );
		    	        NA.IPAddr  = inet_addr(EVMStaticIP);
		    	        NA.IPMask  = inet_addr(LocalIPMask);
		    	        strcpy( NA.Domain, DomainName );


		    	        CfgAddEntry( hCfg, CFGTAG_IPNET, 1, 1, sizeof(CI_IPNET), (uint8_t *)&NA, 0 );

		    	        bzero( &RT, sizeof(RT) );
		    	        RT.IPDestAddr = inet_addr(PCStaticIP);
		    	        RT.IPDestMask = inet_addr(LocalIPMask);
		    	        RT.IPGateAddr = inet_addr(GatewayIP);

		    	        CfgAddEntry( hCfg, CFGTAG_ROUTE, 0, 1, sizeof(CI_ROUTE), (uint8_t *)&RT, 0 );


		    	        platform_write("EVM in StaticIP mode at %s\n",EVMStaticIP);
		    	        platform_write("Set IP address of PC to %s\n", PCStaticIP);
		    	    }




		    	       rc = DBG_WARN;
		    	    CfgAddEntry( hCfg, CFGTAG_OS, CFGITEM_OS_DBGPRINTLEVEL,
		    	                 CFG_ADDMODE_UNIQUE, sizeof(uint), (uint8_t *)&rc, 0 );

		    	       rc = 64000;
		    	    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPTXBUF,
		    	                 CFG_ADDMODE_UNIQUE, sizeof(uint), (uint8_t *)&rc, 0 );

		    	    rc = 64000;
		    	    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXBUF,
		    	                 CFG_ADDMODE_UNIQUE, sizeof(uint), (uint8_t *)&rc, 0 );

		    	    rc = 64000;
		    	    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXLIMIT,
		    	                 CFG_ADDMODE_UNIQUE, sizeof(uint), (uint8_t *)&rc, 0 );

		    	    rc = 8192;
		    	    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKUDPRXLIMIT,
		    	                 CFG_ADDMODE_UNIQUE, sizeof(uint), (uint8_t *)&rc, 0 );


		    	    do
		    	    {
		    	        rc = NC_NetStart( hCfg, NetworkOpen, NetworkClose, NetworkIPAddr );
		    	    } while( rc > 0 );



		    	    platform_write("Done with this utility. Shutting things down\n");





		    	    CfgFree( hCfg );


		    	main_exit:
		    	    platform_write("Exiting the system\n");
		    	    //NC_SystemClose();
		    	    TaskExit();
		    	    return(0);


		    }
		    else
		    {
		    	while(1)
		    	{
		    		platform_write("done processing .exiting core %d \n", coreId);
		    		platform_delay(300000);
		    		break;
		    	}
		    	platform_delay(300000);
		    	break;
		    }
	 }

	 platform_write("done processing .exiting core %d", coreId);

	 platform_delay(3000000);
	 return 0;
}