コード例 #1
0
ファイル: synch.c プロジェクト: Joel397/Ongoing_work_files
void
_cyg_scheduler_lock(char *file, int line)
{
    cyg_scheduler_lock();
    do_sched_event(__FUNCTION__, file, line, SPLX_TRACE_DATA());
}
コード例 #2
0
ファイル: network_support.c プロジェクト: EPiCS/reconos_v2
//
// Initialize network interface[s] using BOOTP/DHCP
//
void
init_all_network_interfaces(void)
{
    static volatile int in_init_all_network_interfaces = 0;
#ifdef CYGPKG_IO_PCMCIA
    cyg_netdevtab_entry_t *t;
#endif // CYGPKG_IO_PCMCIA
#ifdef CYGOPT_NET_IPV6_ROUTING_THREAD
    int rs_wait = 40;
#endif

    cyg_scheduler_lock();
    while ( in_init_all_network_interfaces ) {
        // Another thread is doing this...
        cyg_scheduler_unlock();
        cyg_thread_delay( 10 );
        cyg_scheduler_lock();
    }
    in_init_all_network_interfaces = 1;
    cyg_scheduler_unlock();

#ifdef CYGHWR_NET_DRIVER_ETH0
    if ( ! eth0_up ) { // Make this call idempotent
#ifdef CYGPKG_IO_PCMCIA
        if ((t = eth_drv_netdev("eth0")) != (cyg_netdevtab_entry_t *)NULL) {
            int tries = 0;
            while (t->status != CYG_NETDEVTAB_STATUS_AVAIL) {
                if (tries == 0) {
                    diag_printf("... Waiting for PCMCIA device 'eth0'\n");
                } 
                if (++tries == 5) {
                    diag_printf("... Giving up on PCMCIA device 'eth0'\n");
                    goto bail_eth0;
                }
                cyg_thread_delay(100);
            }
        }
#endif // CYGPKG_IO_PCMCIA
#ifdef CYGHWR_NET_DRIVER_ETH0_BOOTP
        // Perform a complete initialization, using BOOTP/DHCP
        eth0_up = true;
#ifdef CYGHWR_NET_DRIVER_ETH0_DHCP
        eth0_dhcpstate = 0; // Says that initialization is external to dhcp
        if (do_dhcp(eth0_name, &eth0_bootp_data, &eth0_dhcpstate, &eth0_lease)) 
#else
#ifdef CYGPKG_NET_DHCP
        eth0_dhcpstate = DHCPSTATE_BOOTP_FALLBACK;
        // so the dhcp machine does no harm if called
#endif
        if (do_bootp(eth0_name, &eth0_bootp_data)) 
#endif
        {
#ifdef CYGHWR_NET_DRIVER_ETH0_BOOTP_SHOW
            show_bootp(eth0_name, &eth0_bootp_data);
#endif
        } else {
            diag_printf("BOOTP/DHCP failed on eth0\n");
            eth0_up = false;
        }
#elif defined(CYGHWR_NET_DRIVER_ETH0_ADDRS_IP)
        eth0_up = true;
        build_bootp_record(&eth0_bootp_data,
                           eth0_name,
                           string(CYGHWR_NET_DRIVER_ETH0_ADDRS_IP),
                           string(CYGHWR_NET_DRIVER_ETH0_ADDRS_NETMASK),
                           string(CYGHWR_NET_DRIVER_ETH0_ADDRS_BROADCAST),
                           string(CYGHWR_NET_DRIVER_ETH0_ADDRS_GATEWAY),
                           string(CYGHWR_NET_DRIVER_ETH0_ADDRS_SERVER));
        show_bootp(eth0_name, &eth0_bootp_data);
#endif
#ifdef CYGPKG_IO_PCMCIA
    bail_eth0:
#endif
    }
#endif // CYGHWR_NET_DRIVER_ETH0
#ifdef CYGHWR_NET_DRIVER_ETH1
    if ( ! eth1_up ) { // Make this call idempotent
#ifdef CYGPKG_IO_PCMCIA
        if ((t = eth_drv_netdev("eth1")) != (cyg_netdevtab_entry_t *)NULL) {
            int tries = 0;
            while (t->status != CYG_NETDEVTAB_STATUS_AVAIL) {
                if (tries == 0) {
                    diag_printf("... Waiting for PCMCIA device 'eth1'\n");
                } 
                if (++tries == 5) {
                    diag_printf("... Giving up on PCMCIA device 'eth1'\n");
                    goto bail_eth1;
                }
                cyg_thread_delay(100);
            }
        }
#endif // CYGPKG_IO_PCMCIA
#ifdef CYGHWR_NET_DRIVER_ETH1_BOOTP
        // Perform a complete initialization, using BOOTP/DHCP
        eth1_up = true;
#ifdef CYGHWR_NET_DRIVER_ETH1_DHCP
        eth1_dhcpstate = 0; // Says that initialization is external to dhcp
        if (do_dhcp(eth1_name, &eth1_bootp_data, &eth1_dhcpstate, &eth1_lease)) 
#else
#ifdef CYGPKG_NET_DHCP
        eth1_dhcpstate = DHCPSTATE_BOOTP_FALLBACK;
        // so the dhcp machine does no harm if called
#endif
        if (do_bootp(eth1_name, &eth1_bootp_data))
#endif
        {
#ifdef CYGHWR_NET_DRIVER_ETH1_BOOTP_SHOW
            show_bootp(eth1_name, &eth1_bootp_data);
#endif
        } else {
            diag_printf("BOOTP/DHCP failed on eth1\n");
            eth1_up = false;
        }
#elif defined(CYGHWR_NET_DRIVER_ETH1_ADDRS_IP)
        eth1_up = true;
        build_bootp_record(&eth1_bootp_data,
                           eth1_name,
                           string(CYGHWR_NET_DRIVER_ETH1_ADDRS_IP),
                           string(CYGHWR_NET_DRIVER_ETH1_ADDRS_NETMASK),
                           string(CYGHWR_NET_DRIVER_ETH1_ADDRS_BROADCAST),
                           string(CYGHWR_NET_DRIVER_ETH1_ADDRS_GATEWAY),
                           string(CYGHWR_NET_DRIVER_ETH1_ADDRS_SERVER));
        show_bootp(eth1_name, &eth1_bootp_data);
#endif
#ifdef CYGPKG_IO_PCMCIA
    bail_eth1:
#endif
    }
#endif // CYGHWR_NET_DRIVER_ETH1
#ifdef CYGHWR_NET_DRIVER_ETH0
#ifndef CYGHWR_NET_DRIVER_ETH0_MANUAL
    if (eth0_up) {
        if (!init_net(eth0_name, &eth0_bootp_data)) {
            diag_printf("Network initialization failed for eth0\n");
            eth0_up = false;
        }
#ifdef CYGHWR_NET_DRIVER_ETH0_IPV6_PREFIX
        if (!init_net_IPv6(eth0_name, &eth0_bootp_data, 
                           string(CYGHWR_NET_DRIVER_ETH0_IPV6_PREFIX))) {
            diag_printf("Static IPv6 network initialization failed for eth0\n");
            eth0_up = false;  // ???
        }
#endif
    }
#endif
#endif
#ifdef CYGHWR_NET_DRIVER_ETH1
#ifndef CYGHWR_NET_DRIVER_ETH1_MANUAL
    if (eth1_up) {
        if (!init_net(eth1_name, &eth1_bootp_data)) {
            diag_printf("Network initialization failed for eth1\n");
            eth1_up = false;
        }
#ifdef CYGHWR_NET_DRIVER_ETH1_IPV6_PREFIX
        if (!init_net_IPv6(eth1_name, &eth1_bootp_data, 
                           string(CYGHWR_NET_DRIVER_ETH1_IPV6_PREFIX))) {
            diag_printf("Static IPv6 network initialization failed for eth1\n");
            eth1_up = false; // ???
        }
#endif
    }
#endif
#endif

#ifdef CYGPKG_NET_NLOOP
#if 0 < CYGPKG_NET_NLOOP
    {
        static int loop_init = 0;
        int i;
        if ( 0 == loop_init++ )
            for ( i = 0; i < CYGPKG_NET_NLOOP; i++ )
                init_loopback_interface( i );
    }
#endif
#endif

#ifdef CYGOPT_NET_DHCP_DHCP_THREAD
    dhcp_start_dhcp_mgt_thread();
#endif

#ifdef CYGOPT_NET_IPV6_ROUTING_THREAD
    ipv6_start_routing_thread();

    // Wait for router solicit process to happen.
    while (rs_wait-- && !cyg_net_get_ipv6_advrouter(NULL)) {
      cyg_thread_delay(10);
    }
    if (rs_wait == 0 ) {
      diag_printf("No router solicit received\n");
    } else {
      // Give Duplicate Address Detection time to work
      cyg_thread_delay(200);
    }
#endif

#ifdef CYGDAT_NS_DNS_DEFAULT_SERVER
      cyg_dns_res_start(string(CYGDAT_NS_DNS_DEFAULT_SERVER));
#endif

#ifdef CYGDAT_NS_DNS_DOMAINNAME_NAME
#define _NAME string(CYGDAT_NS_DNS_DOMAINNAME_NAME)
    {
      const char buf[] = _NAME;
      int len = strlen(_NAME);
      
      setdomainname(buf,len);
    }
#endif
    // Open the monitor to other threads.
    in_init_all_network_interfaces = 0;

}
コード例 #3
0
ファイル: synch.c プロジェクト: Joel397/Ongoing_work_files
// ------------------------------------------------------------------------
// Wait for an event with timeout
//   tsleep(event, priority, state, timeout)
//     event - the thing to wait for
//     priority - unused
//     state    - a descriptive message
//     timeout  - max time (in ticks) to wait
//   returns:
//     0         - event was "signalled"
//     ETIMEDOUT - timeout occurred
//     EINTR     - thread broken out of sleep
//
int       
cyg_tsleep(void *chan, int pri, char *wmesg, int timo)
{
    int i, res = 0;
    struct wakeup_event *ev;    
    cyg_tick_count_t sleep_time;
    cyg_handle_t self = cyg_thread_self();
    int old_splflags = 0; // no flags held

    cyg_scheduler_lock();

    // Safely find a free slot:
    for (i = 0, ev = wakeup_list;  i < CYGPKG_NET_NUM_WAKEUP_EVENTS;  i++, ev++) {
        if (ev->chan == 0) {
            ev->chan = chan;
            break;
        }
    }
    CYG_ASSERT( i <  CYGPKG_NET_NUM_WAKEUP_EVENTS, "no sleep slots" );
    CYG_ASSERT( 1 == cyg_scheduler_read_lock(),
                "Tsleep - called with scheduler locked" );
    // Defensive:
    if ( i >= CYGPKG_NET_NUM_WAKEUP_EVENTS ) {
        cyg_scheduler_unlock();
        return ETIMEDOUT;
    }

    // If we are the owner, then we must release the mutex when
    // we wait.
    if ( self == splx_thread ) {
        old_splflags = spl_state; // Keep them for restoration
        CYG_ASSERT( spl_state, "spl_state not set" );
        // Also want to assert that the mutex is locked...
        CYG_ASSERT( splx_mutex.locked, "Splx mutex not locked" );
        CYG_ASSERT( (cyg_handle_t)splx_mutex.owner == self, "Splx mutex not mine" );
        splx_thread = 0;
        spl_state = 0;
        cyg_mutex_unlock( &splx_mutex );
    }

    // Re-initialize the semaphore - it might have counted up arbitrarily
    // in the time between a prior sleeper being signalled and them
    // actually running.
    cyg_semaphore_init(&ev->sem, 0);    

    // This part actually does the wait:
    // As of the new kernel, we can do this without unlocking the scheduler
    if (timo) {
        sleep_time = cyg_current_time() + timo;
        if (!cyg_semaphore_timed_wait(&ev->sem, sleep_time)) {
            if( cyg_current_time() >= sleep_time )
                res = ETIMEDOUT;
            else
                res = EINTR;
        }
    } else {
        if (!cyg_semaphore_wait(&ev->sem) ) {
            res = EINTR;
        }
    }

    ev->chan = 0;  // Free the slot - the wakeup call cannot do this.
    
    if ( old_splflags ) { // restore to previous state
        // As of the new kernel, we can do this with the scheduler locked
        cyg_mutex_lock( &splx_mutex ); // this might wait
        CYG_ASSERT( 0 == splx_thread, "Splx thread set in tsleep" );
        CYG_ASSERT( 0 == spl_state, "spl_state set in tsleep" );
        splx_thread = self; // got it now...
        spl_state = old_splflags;
    }

    cyg_scheduler_unlock();
    return res;
}
コード例 #4
0
ファイル: client1017.c プロジェクト: ntuDerekWang/uIP_on_eCos
void mainfunc(cyg_addrword_t data)
{
/******************** lock the Scheduler ************************/
      cyg_scheduler_lock();
/****************************************************************/
    printf("Hello, eCos mainfunc!\n");
    
    ds2411_id[0] = 0x00;
    ds2411_id[1] = 0x12;
    ds2411_id[2] = 0x75;
    ds2411_id[3] = 0x00;
    ds2411_id[4] = 0x0c;
    ds2411_id[5] = 0x59;
  //ds2411_id[6] = 0x57;
  //ds2411_id[7] = 0x3d;
    ds2411_id[6] = 0x10;
    ds2411_id[7] = 0x17;
    ds2411_id[2] &= 0xfe;
/*
    ds2411_id[0] = 0x02;
    ds2411_id[1] = 0x00;
    ds2411_id[2] = 0x00;
    ds2411_id[3] = 0x00;
    ds2411_id[4] = 0x00;
    ds2411_id[5] = 0x00;
  //ds2411_id[6] = 0x57;
  //ds2411_id[7] = 0x3d;
    ds2411_id[6] = 0x00;
    ds2411_id[7] = 0x00;
*/

     
  /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
#ifdef IEEE_802154_MAC_ADDRESS
  {
    uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
    memcpy(ds2411_id, ieee, sizeof(uip_lladdr.addr));
    ds2411_id[7] = node_id & 0xff;
  }
#endif
     random_init(5);

     set_rime_addr();
     NETSTACK_RADIO.init(); 
     
 
  {
    cyg_uint8 longaddr[8];
    cyg_uint16 shortaddr;
    
    shortaddr = (rimeaddr_node_addr.u8[0] << 8) +
    rimeaddr_node_addr.u8[1];
    memset(longaddr, 0, sizeof(longaddr));
    rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_node_addr);
    printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
           longaddr[0], longaddr[1], longaddr[2], longaddr[3],
           longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
    
    uz2400_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
  }
  uz2400_set_channel(RF_CHANNEL);///////////////////////////////////////////
 
 
 #if WITH_UIP6
  memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); 
  /* Setup nullmac-like MAC for 802.15.4 */
/*   sicslowpan_init(sicslowmac_init(&cc2420_driver)); */
/*   printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); */

  /* Setup X-MAC for 802.15.4 */
  queuebuf_init();
  //NETSTACK_RADIO.init();
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

  printf("%s %s, channel check rate %lu Hz, radio channel %u\n",
         NETSTACK_MAC.name, NETSTACK_RDC.name,
         CLOCK_CONF_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                         NETSTACK_RDC.channel_check_interval()),
         RF_CHANNEL); 
//================
  uip_init(); 
  rpl_init(); 
//=============
  printf("Tentative link-local IPv6 address ");
  {
    uip_ds6_addr_t *lladdr=NULL;
    int i;
    lladdr = uip_ds6_get_link_local(-1);
    for(i = 0; i < 7; ++i) {
      printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
             lladdr->ipaddr.u8[i * 2 + 1]);
    }
    printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
  } 

  if(!UIP_CONF_IPV6_RPL) {
    uip_ipaddr_t ipaddr;
    int i;
    uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
    uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
    printf("Tentative global IPv6 address ");
    for(i = 0; i < 7; ++i) {
      printf("%02x%02x:",
             ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
    }
    printf("%02x%02x\n",
           ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
  }


#endif /* WITH_UIP6 */
  
  static cyg_uint32 GLedPinspec; 
  GLedPinspec =  CYGHWR_HAL_STM32_GPIO( C, 6, OUT_50MHZ , OUT_PUSHPULL     );
  volatile static  cyg_uint8 blink=0;  
/******************** unlock the Scheduler ************************/
        cyg_scheduler_unlock();
/****************************************************************/
  
	while(1){  
       /*         
                blink=~blink;
              CYGHWR_HAL_STM32_GPIO_OUT(GLedPinspec,blink); 
               
		cyg_thread_delay(500);
         */
         cyg_thread_yield();       
               
                
       }
}