Beispiel #1
0
static void
thread_prog(cyg_addrword_t data) 
{
    lua_State        *L     = (lua_State *) data;
    lua_ecos_state_t *state = (lua_ecos_state_t *) lua_getuserspace(L);
    int i, n, ref;
   
    // get arguments table size 
    n = luaL_getn(L, 1);

    // push arguments from table 
    for (i = 1; i <= n; i++) 
        lua_rawgeti(L, 1, i);
    lua_remove(L, 1);

    // run program  
    lua_call(L, n, 0);

    ref = state->thread->ref;
    
    // put ourselves into terminated list
    cyg_scheduler_lock();
    {
        state->thread->next = terminated_threads;
        terminated_threads = state->thread;
        state->thread = NULL;
    }
    cyg_scheduler_unlock();

    // unreference the lua thread  
    lua_unref(L, ref);
}
Beispiel #2
0
/*---------------------------------------------------------------------------*/
void
neighbor_info_packet_received(cyg_uint8 rssi)
{
  const rimeaddr_t *src;

  src = packetbuf_addr(PACKETBUF_ADDR_SENDER);
  if(rimeaddr_cmp(src, &rimeaddr_null)) { 
    return;
  }

  PRINTF("neighbor-info: packet received from %x.%x\n",
	src->u8[sizeof(*src) - 2], src->u8[sizeof(*src) - 1]);
/*
 if ( NULL != neighbor_attr_get_data(&etx, src)){ 

        if (rssi > 0)   ///// MODIFIED LATER
             update_etx(src, rssi);
     }
*/
/******************** lock the Scheduler ************************/
      cyg_scheduler_lock();
/****************************************************************/
  add_neighbor(src);
  update_etx(src, rssi);
/******************** unlock the Scheduler ************************/
      cyg_scheduler_unlock();
/****************************************************************/
  
}
Beispiel #3
0
static Cyg_ErrNo 
kbd_read(cyg_io_handle_t handle, 
         void *buffer, 
         cyg_uint32 *len)
{
    unsigned char *ev;
    int tot = *len;
    unsigned char *bp = (unsigned char *)buffer;

    cyg_scheduler_lock();  // Prevent interaction with DSR code
    while (tot >= sizeof(*ev)) {
        if (num_events > 0) {
            ev = &_events[_event_get++];
            if (_event_get == MAX_EVENTS) {
                _event_get = 0;
            }
            memcpy(bp, ev, sizeof(*ev));
            bp += sizeof(*ev);
            tot -= sizeof(*ev);
            num_events--;
        } else {
            break;  // No more events
        }
    }
    cyg_scheduler_unlock(); // Allow DSRs again
    diag_dump_buf(buffer, tot);
    *len -= tot;
    return ENOERR;
}
Beispiel #4
0
void pwr_set_clk_profile(int profile)
{
	int i, ticks;
	int old;
	
	if(profile > sizeof(clk_profile)/sizeof(w99702_clk_t)) return;	
	
	cyg_scheduler_lock();
	//HAL_DISABLE_INTERRUPTS(old);
	sysDisableCache();
	sysInvalidCache();
	sysFlushCache(I_D_CACHE);
	sysEnableCache(CACHE_WRITE_BACK);

	
	//outpw(0x3FFF001C, inpw(0x3FFF001C)|0xC);
	//outpw(0x7FF00108, (inpw(0x7FF00108)&(~3))|0x2);

	pwr_set_clk(&clk_profile[profile]);
	
	


	current_clk_profile = profile;	

	//HAL_RESTORE_INTERRUPTS(old);
	cyg_scheduler_unlock();
	
}
Beispiel #5
0
/*--------------------------------------------------------*/
void udp_client_process(void){
     
/******************** lock the Scheduler ************************/
      cyg_scheduler_lock();
/****************************************************************/
        static struct ctimer backoff_timer;
 
	 PRINTF("UDP client started\n");
	 
         set_global_address();   
	 
	 
	 print_local_addresses();
	 
	  

     client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL);
 

     udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT));
     PRINTF("Created a connection with the server ");
     PRINT6ADDR(&client_conn->ripaddr);
     PRINTF(" local/remote port %u/%u\n",
	UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

     ctimer_set(&backoff_timer,SEND_TIME,send_packet,NULL);
	 
//      PRINTF(" local/remote port %u/%u\n", client_conn->lport, client_conn->rport);
	 
	        void* message = NULL;
                
                 
/******************** unlock the Scheduler ************************/
        cyg_scheduler_unlock();
/****************************************************************/
          while(1){
                    // cyg_thread_yield();

		     message = cyg_mbox_tryget (mbox_out_tcpip_handle);
		     MyEvent_t* msg_local = message ;
			 if (  message != NULL){ 
                              cyg_handle_t* event_handlePtr;
                              event_handlePtr = (cyg_handle_t*) msg_local-> dataPtr;

                              if( cyg_thread_self() == *event_handlePtr){
			 
			                            tcpip_handler();
			                    }
 
 
		
		
                             }
                          cyg_thread_yield();
                     }
}
Beispiel #6
0
static cyg_bool  
ts_select(cyg_io_handle_t handle, 
          cyg_uint32 which, 
          cyg_addrword_t info)
{
    if (which == CYG_FREAD) {
        cyg_scheduler_lock();  // Prevent interaction with DSR code
        if (num_events > 0) {
            cyg_scheduler_unlock();  // Reallow interaction with DSR code
            return true;
        }        
        if (!ts_select_active) {
            ts_select_active = true;
            cyg_selrecord(info, &ts_select_info);
        }
        cyg_scheduler_unlock();  // Reallow interaction with DSR code
    }
    return false;
}
// Allocate a semaphore for a given port number if one is not already
// allocated.
static void sem_alloc(int port) {
  int i;

  CYG_ASSERT(port != 0, "Invalid port number");

  cyg_scheduler_lock(); // Avoid race with other tftpd's
  for (i=0; i < CYGNUM_NET_TFTPD_MULTITHREADED_PORTS; i++) {
    if (tftpd_sems[i].port == port) {
      cyg_scheduler_unlock();
      return;
    }
    if (tftpd_sems[i].port == 0) {
      tftpd_sems[i].port = port;
      cyg_semaphore_init(&tftpd_sems[i].sem,1);
      cyg_scheduler_unlock();
      return ;
    }
  }
  cyg_scheduler_unlock();
  diag_printf("TFTPD: Unable to allocate a semaphore for port %d\n",port);
}
Beispiel #8
0
static Cyg_ErrNo 
ts_read(cyg_io_handle_t handle, 
        void *buffer, 
        cyg_uint32 *len)
{
    struct _event *ev;
    int tot = *len;
    unsigned char *bp = (unsigned char *)buffer;

    cyg_scheduler_lock();  // Prevent interaction with DSR code
    while (tot >= sizeof(struct _event)) {
        if (num_events > 0) {
            ev = &_events[_event_get++];
            if (_event_get == MAX_EVENTS) {
                _event_get = 0;
            }
            // Self calibrate
            if (ev->xPos > xBounds.max) xBounds.max = ev->xPos;
            if (ev->xPos < xBounds.min) xBounds.min = ev->xPos;
            if (ev->yPos > yBounds.max) yBounds.max = ev->yPos;
            if (ev->yPos < yBounds.min) yBounds.min = ev->yPos;
            if ((xBounds.span = xBounds.max - xBounds.min) <= 1) {
                xBounds.span = 1;
            }
            if ((yBounds.span = yBounds.max - yBounds.min) <= 1) {
                yBounds.span = 1;
            }
            // Scale values - done here so these potentially lengthy
            // operations take place outside of interrupt processing
#ifdef DEBUG
            diag_printf("Raw[%d,%d], X[%d,%d,%d], Y[%d,%d,%d]",
                        ev->xPos, ev->yPos,
                        xBounds.max, xBounds.min, xBounds.span,
                        yBounds.max, yBounds.min, yBounds.span);
#endif
            ev->xPos = 640 - (((xBounds.max - ev->xPos) * 640) / xBounds.span);
            ev->yPos = 480 - (((yBounds.max - ev->yPos) * 480) / yBounds.span);
#ifdef DEBUG
            diag_printf(", Cooked[%d,%d]\n",
                        ev->xPos, ev->yPos);
#endif
            memcpy(bp, ev, sizeof(*ev));
            bp += sizeof(*ev);
            tot -= sizeof(*ev);
            num_events--;
        } else {
            break;  // No more events
        }
    }
    cyg_scheduler_unlock(); // Allow DSRs again
    *len -= tot;
    return ENOERR;
}
Beispiel #9
0
//
// Signal an event
void
cyg_wakeup(void *chan)
{
    int i;
    struct wakeup_event *ev;
    cyg_scheduler_lock(); // Ensure scan is safe
    // NB this is broadcast semantics because a sleeper/wakee holds the
    // slot until they exit.  This avoids a race condition whereby the
    // semaphore can get an extra post - and then the slot is freed, so the
    // sem wait returns immediately, AOK, so the slot wasn't freed.
    for (i = 0, ev = wakeup_list;  i < CYGPKG_NET_NUM_WAKEUP_EVENTS;  i++, ev++)
        if (ev->chan == chan)
            cyg_semaphore_post(&ev->sem);

    cyg_scheduler_unlock();
}
Beispiel #10
0
void
lua_ecosfreeterminatedthreads(void)
{
    cyg_scheduler_lock();
    {
        lua_ecos_thread_t *thread = terminated_threads;

        while (thread != NULL && thread->handle != cyg_thread_self())
        {
            cyg_thread_delete(thread->handle);
            terminated_threads = thread->next;
            free(thread->stack);
            free(thread);
            thread = terminated_threads;
        }
    }
    cyg_scheduler_unlock();
}
Beispiel #11
0
bool cyg_recursive_mutex_trylock( cyg_recursive_mutex_t *mx )
{
    bool result=false;
    cyg_scheduler_lock();
    {
        if( cyg_thread_self() == mx->owner ) {
            mx->count++;
            result = true;
        } else {
            result = cyg_mutex_trylock( &mx->mutex );
            if (result == true) {
                mx->count = 1;
                mx->owner = cyg_thread_self();
            }
        }
    }
  cyg_scheduler_unlock();
  return result;
}
Beispiel #12
0
void cyg_recursive_mutex_unlock( cyg_recursive_mutex_t *mx )
{
  cyg_scheduler_lock();
  {
    if( cyg_thread_self() == mx->owner )
      {
	// Only do something if mutex was locked
	if (mx->count >= 1)
	  {
	    mx->count--;
	    if (mx->count == 0)
	      {
		cyg_mutex_unlock( &mx->mutex );
	      }
	  }
	else
	  diag_printf("recursive mutex: not locked\n");
      }
    else
      diag_printf("Error unlocking recursive mutex: you're not the owner!\n");
  }
  cyg_scheduler_unlock();
}
Beispiel #13
0
//------------------------------------------------------------------------------
// FUNCTION
//
//
// DESCRIPTION
//
//  
// PARAMETERS
//
//  
// RETURN
//
//  
//------------------------------------------------------------------------------
char* netarp_get(unsigned int addr, char *outbuf, unsigned short flag)
{
	int i, error;
    struct radix_node_head *rnh;
    struct arp_req req;
	
	memset(&req, 0, sizeof(struct arp_req));
	if(addr && outbuf) {
		req.flg = flag;
		req.dst = addr;
		req.buf = outbuf;
	}
	
    cyg_scheduler_lock();
    for (i = 1; i <= AF_MAX; i++) {
        if ((rnh = rt_tables[i]) != NULL) {
            error = rnh->rnh_walktree(rnh, dump_arp, &req);
        }
    }

    cyg_scheduler_unlock();
	
	return outbuf;
}
int http_put_file(int id, http_upload_content* content, char * file, int len)
{
    int rc, ok=0;
    extern unsigned int flsh_cfg_fwm_off;
    extern unsigned int flsh_cfg_fwm_sz;
	
    if (content == NULL || file == NULL || len <= 0)
    {
        ok = -3;
        goto err_out;
    }
    
    if (0 != cfg_chk_header(id, file))
    {
        int i;
        diag_printf("[CFG] err header id=%d, dump:", id );
        for (i=0; i<8; i++)
            diag_printf("%02x ", file[i]&0xff);
        diag_printf("\n");
        ok = -3;      // file error
        goto err_out;
    }

    switch (id)
    {
    case 1:
        diag_printf("[CFG] FMW sz=%x ,max=%x!\n", len, flsh_cfg_fwm_sz);
        if (len > flsh_cfg_fwm_sz )
        {
            ok = -3;
            break;
        }

        if (chk_fmw_hdr2(content, file, len))
        {
            ok = -3;
            break;
        }
        diag_printf("[CFG] FMW upload\n");
        diag_printf("[CFG] FMW, sz %d B to flash:", len);

        cyg_scheduler_lock();
        rc = flsh_erase(flsh_cfg_fwm_off, len);
        cyg_scheduler_unlock();
        if (rc)
        {
            diag_printf("er err %d\n", rc);
            ok = -3;
            break;
        }
        
        cyg_scheduler_lock();
        rc=flsh_write2(flsh_cfg_fwm_off, content, file, len);
        cyg_scheduler_unlock();
        
        if (rc)
        {
            diag_printf("wr err %d\n", rc);
            ok = -3;
            break;
        }
        else
            diag_printf("OK!\n");
        break;

    case 0:
        diag_printf("[CFG] update profile!len=%d\n",len);
        cfg_init_header();
        ok = CFG_read_prof(file, len);     // reload to CFG
        cfg_load_static(); 
        if (ok == 0)
        {
            CFG_commit(CFG_DELAY_EVENT);
        }
        break;

    default:
        diag_printf("unknown");
        break;
    }
    
err_out:
    return ok;
}
Beispiel #15
0
 void  FreeMyMsg(COMMAND* pMsg)
 { cyg_scheduler_lock();if(pMsg!=NULL)m_MyMsgPool.free(pMsg);cyg_scheduler_unlock(); }  // m_MyMsgPool.alloc() in dsr
Beispiel #16
0
void
_cyg_scheduler_unlock(char *file, int line)
{
    cyg_scheduler_unlock();
    do_sched_event(__FUNCTION__, file, line, SPLX_TRACE_DATA());
}
Beispiel #17
0
// ------------------------------------------------------------------------
// 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;
}
Beispiel #18
0
void init_all_network_interfaces(void)
{
    cyg_bool_t use_bootp;
    cyg_bool_t setup_network = false;
    in_addr_t  local_ip_addr = 0;
    in_addr_t  broadcast_addr = 0;
    in_addr_t  server_addr = 0;
    in_addr_t  gateway_addr = 0;
    in_addr_t  network_mask = 0;
    char       server_str[16];
    char       network_str[16];
    char       gateway_str[16];
    char       broadcast_str[16];
    char       ip_addr_str[16];
    int        i;
    int        net_up = false;
    static volatile int in_init_all_network_interfaces = 0;

    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

    // Fetch values from saved config data, if available
    CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                "app_bootn", &setup_network, 
                                CYGNUM_FLASH_CFG_OP_CONFIG_BOOL);

    if (setup_network)
    {
        // Set defaults as appropriate
        use_bootp = true;

        // Fetch values from saved config data, if available
        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                    "app_bootp", &use_bootp, 
                                    CYGNUM_FLASH_CFG_OP_CONFIG_BOOL);
        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                    "app_bootp_localip_addr", &local_ip_addr,
                                    CYGNUM_FLASH_CFG_OP_CONFIG_IP);
        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                    "app_bootp_localip_mask", &network_mask, 
                                    CYGNUM_FLASH_CFG_OP_CONFIG_IP);
        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                    "app_bootp_mygateway_addr", &gateway_addr, 
                                    CYGNUM_FLASH_CFG_OP_CONFIG_IP);
        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                    "app_bootp_ubroadcast_addr", 
                                    &broadcast_addr, 
                                    CYGNUM_FLASH_CFG_OP_CONFIG_IP);
        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                    "app_bootp_serverip_addr", &server_addr, 
                                    CYGNUM_FLASH_CFG_OP_CONFIG_IP);

        if (use_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 {
                printf("BOOTP/DHCP failed on eth0\n");
                eth0_up = false;
            }
        }
        else
        {
            eth0_up = true;
            strncpy(ip_addr_str, 
                    inet_ntoa(*(struct in_addr *) &local_ip_addr), 16);
            strncpy(broadcast_str, 
                    inet_ntoa(*(struct in_addr *) &broadcast_addr), 16);
            strncpy(gateway_str, inet_ntoa(*(struct in_addr *) &gateway_addr), 
                    16);
            strncpy(network_str, inet_ntoa(*(struct in_addr *) &network_mask), 
                    16);
            strncpy(server_str, inet_ntoa(*(struct in_addr *) &server_addr), 
                    16);

            /* load flash configuration parameters */
            build_bootp_record(&eth0_bootp_data, eth0_name, ip_addr_str, 
                               network_str,  broadcast_str, gateway_str, 
                               server_str);
#ifdef CYGHWR_NET_DRIVER_ETH0_BOOTP_SHOW
            show_bootp(eth0_name, &eth0_bootp_data);
#endif
        }
    }

#endif

#ifdef CYGHWR_NET_DRIVER_ETH1
    setup_network = false;

    // Fetch values from saved config data, if available
    CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                "app_c_bootn", &setup_network, 
                                CYGNUM_FLASH_CFG_OP_CONFIG_BOOL);

    if (setup_network)
    {
        // Set defaults as appropriate
        use_bootp = true;

        // Fetch values from saved config data, if available
        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                    "app_c_bootp", &use_bootp, 
                                    CYGNUM_FLASH_CFG_OP_CONFIG_BOOL);
        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                    "app_c_bootp_localip_addr", &local_ip_addr,
                                    CYGNUM_FLASH_CFG_OP_CONFIG_IP);
        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                    "app_c_bootp_localip_mask", &network_mask, 
                                    CYGNUM_FLASH_CFG_OP_CONFIG_IP);
        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                    "app_c_bootp_mygateway_addr", &gateway_addr,
                                    CYGNUM_FLASH_CFG_OP_CONFIG_IP);
        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                    "app_c_bootp_ubroadcast_addr", 
                                    &broadcast_addr, 
                                    CYGNUM_FLASH_CFG_OP_CONFIG_IP);
        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                    "app_c_bootp_serverip_addr", &server_addr, 
                                    CYGNUM_FLASH_CFG_OP_CONFIG_IP);

        if (use_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
//            eth0_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 {
                printf("BOOTP/DHCP failed on eth1\n");
                eth1_up = false;
            }
        }
        else
        {
            eth1_up = true;
            strncpy(ip_addr_str, 
                    inet_ntoa(*(struct in_addr *) &local_ip_addr), 16);
            strncpy(broadcast_str, 
                    inet_ntoa(*(struct in_addr *) &broadcast_addr), 16);
            strncpy(gateway_str, inet_ntoa(*(struct in_addr *) &gateway_addr), 
                    16);
            strncpy(network_str, inet_ntoa(*(struct in_addr *) &network_mask), 
                    16);
            strncpy(server_str, inet_ntoa(*(struct in_addr *) &server_addr), 
                    16);

            /* load flash configuration parameters */
            build_bootp_record(&eth1_bootp_data, eth1_name, ip_addr_str, 
                               network_str,  broadcast_str, gateway_str, 
                               server_str);
#ifdef CYGHWR_NET_DRIVER_ETH1_BOOTP_SHOW
            show_bootp(eth1_name, &eth1_bootp_data);
#endif
        }
    }
#endif

#ifdef CYGHWR_NET_DRIVER_ETH0
    if (eth0_up) {
        if (!init_net(eth0_name, &eth0_bootp_data)) {
            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
        if (eth0_up)
        {
            unsigned int length = 4;
            struct in_addr temp;
            diag_printf("\nIP: %s", inet_ntoa(eth0_bootp_data.bp_yiaddr));
                
            get_bootp_option(&eth0_bootp_data, TAG_SUBNET_MASK, 
                             (void *)&temp, &length);
            diag_printf("/%s", inet_ntoa(temp));
            get_bootp_option(&eth0_bootp_data, TAG_GATEWAY, 
                             (void *)&temp, &length);
//          diag_printf(", Gateway: %s\n", inet_ntoa(eth0_bootp_data.bp_giaddr));
            diag_printf(", Gateway: %s\n", inet_ntoa(temp));
            diag_printf("Server: %s", inet_ntoa(eth0_bootp_data.bp_siaddr));
            net_up = true;
        }
    }
#endif

#ifdef CYGHWR_NET_DRIVER_ETH1
    if (eth1_up) {
        if (!init_net(eth1_name, &eth1_bootp_data)) {
            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
        if (eth1_up)
        {
            unsigned int length = 4;
            struct in_addr temp;
            diag_printf("\nIP: %s", inet_ntoa(eth1_bootp_data.bp_yiaddr));
                
            get_bootp_option(&eth1_bootp_data, TAG_SUBNET_MASK, 
                             (void *)&temp, &length);
            diag_printf("/%s", inet_ntoa(temp));
            get_bootp_option(&eth1_bootp_data, TAG_GATEWAY, 
                             (void *)&temp, &length);
//          diag_printf(", Gateway: %s\n", inet_ntoa(eth1_bootp_data.bp_giaddr));
            diag_printf(", Gateway: %s\n", inet_ntoa(temp));
            diag_printf("Server: %s", inet_ntoa(eth1_bootp_data.bp_siaddr));
            net_up = true;
        }
    }
#endif
#ifdef CYGPKG_NET_NLOOP
#if 0 < CYGPKG_NET_NLOOP
    // Create a local IP Address for each of the DSP's */
    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();
#endif
 
#ifdef CYGPKG_NS_DNS_BUILD
    if (net_up)
    {
        struct in_addr dns_addr = {0};
        int        len;
        char       *dns_domainname;
        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                    "app_dns_ip", &dns_addr, 
                                    CYGNUM_FLASH_CFG_OP_CONFIG_IP);
      
        cyg_dns_res_init(&dns_addr);

        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                    "app_dns_domain_name", 
                                    &dns_domainname, 
                                    CYGNUM_FLASH_CFG_OP_CONFIG_STRING);
        len = strlen(dns_domainname);
      
        setdomainname(dns_domainname,len);
        diag_printf(", DNS server IP: %s", 
                    inet_ntoa(*(struct in_addr *)&dns_addr));

    }
#endif
    
    if (!net_up)
    {
        diag_printf("Network Disabled");
    }
    diag_printf("\n\n");
}
Beispiel #19
0
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();       
               
                
       }
} 
Beispiel #20
0
//
// 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;

}