static void tnetw1130_write0l(tnetw1130_t *s, hwaddr addr, uint32_t value) { if (addr < TNETW1130_MEM0_SIZE) { reg_write32(s->mem0, addr, value); } if (addr == TNETW1130_SLV_MEM_ADDR) { s->fw_addr = value; if (value >= TNETW1130_FW_SIZE) { UNEXPECTED(); } } else if (addr == TNETW1130_SLV_MEM_DATA) { reg_write32(s->fw, s->fw_addr, value); } else if (addr == TNETW1130_SLV_MEM_CTL) { if (value == 0) { TRACE(TNETW, logout("basic mode\n")); } else if (value == 1) { TRACE(TNETW, logout("autoincrement mode\n")); MISSING(); } else { UNEXPECTED(); } } else if (addr == TNETW1130_SLV_END_CTL) { } TRACE(TNETW, logout("addr %s = 0x%08x\n", tnetw1130_regname(addr), value)); }
/* * Initialize networkiness. * * Empty comments in column 1 indicate things that need to be undone upon * failure or in net_shutdown. * * Returns zero on success, an error code from <oskit/error.h> otherwise. */ oskit_error_t net_init(void) { #define BUFSIZE 128 struct bootp_net_info bpi; struct in_addr gw, ns; char hn[64], dn[64]; static char buf[BUFSIZE]; oskit_etherdev_t **alldevs; int ndev; int i, ix; unsigned required_flags; int interactive = 0; oskit_socket_factory_t *fsc; #ifdef FREEBSD_NET oskit_error_t err; #endif /* * Find all the Ethernet device nodes. */ retry: ndev = osenv_device_lookup(&oskit_etherdev_iid, (void***)&alldevs); #ifdef BOOTP_IF if (ndev < BOOTP_IF) panic("BOOTP Ethernet adaptor %d not found!", BOOTP_IF); #else if (ndev <= 0) panic("no Ethernet adaptors found!"); #endif dev = NULL; memset(&bpi, 0, sizeof bpi); /* * Prompt user for info */ if (interactive) { char *cp; do { printf("Enter ethernet IF to use [%d-%d]: ", 0, ndev-1); fgets(buf, BUFSIZE, stdin); ix = atoi(buf); if (ix < 0) goto gotinfo; } while (ix >= ndev); do { printf("Enter IP address: "); fgets(buf, BUFSIZE, stdin); } while (inet_aton(buf, &bpi.ip) == 0); do { printf("Enter netmask: "); fgets(buf, BUFSIZE, stdin); } while (inet_aton(buf, &bpi.netmask) == 0); do { printf("Enter gateway IP address: "); fgets(buf, BUFSIZE, stdin); } while (inet_aton(buf, &gw) == 0); bpi.gateway.addr = &gw; bpi.gateway.len = 1; printf("Enter hostname: "); fgets(buf, BUFSIZE, stdin); if ((cp = strchr(buf, '\n')) != 0) *cp = '\0'; memcpy(hn, buf, sizeof hn); bpi.hostname = hn; printf("Enter domainname: "); fgets(buf, BUFSIZE, stdin); if ((cp = strchr(buf, '\n')) != 0) *cp = '\0'; memcpy(dn, buf, sizeof dn); bpi.domainname = dn; do { printf("Enter nameserver IP address: "); fgets(buf, BUFSIZE, stdin); } while (inet_aton(buf, &ns) == 0); bpi.dns_server.addr = &ns; bpi.dns_server.len = 1; dev = alldevs[ix]; goto gotinfo; } /* * Try bootp on each dev and use the first one that succeeds. */ ix = ndev; for (i = 0; i < ndev; i++) { #ifdef BOOTP_IF if (i != BOOTP_IF) { oskit_etherdev_release(alldevs[i]); continue; } #else if (dev) { /* Have choice, but must release the others anyway. */ oskit_etherdev_release(alldevs[i]); continue; } #endif if (bootp(alldevs[i], &bpi) != 0) { oskit_etherdev_release(alldevs[i]); continue; } required_flags = (BOOTP_NET_IP | BOOTP_NET_NETMASK | BOOTP_NET_GATEWAY | BOOTP_NET_DNS_SERVER | BOOTP_NET_DOMAINNAME | BOOTP_NET_HOSTNAME); if ((bpi.flags & required_flags) != required_flags) { #define MISSING(flag, name) if ((bpi.flags & flag) == 0) \ printf("bootp did not supply %s\n", name) MISSING(BOOTP_NET_IP, "my IP address"); MISSING(BOOTP_NET_NETMASK, "my netmask"); MISSING(BOOTP_NET_GATEWAY, "gateway address"); MISSING(BOOTP_NET_DNS_SERVER, "DNS servers"); MISSING(BOOTP_NET_DOMAINNAME, "domainname"); MISSING(BOOTP_NET_HOSTNAME, "my hostname"); #undef MISSING oskit_etherdev_release(alldevs[i]); continue; } /**/ dev = alldevs[i]; ix = i; } gotinfo: if (dev == NULL) { #ifdef UTAHTESTBED /* * XXX fer now hack */ static int tried; if (tried++ < 5) goto retry; #endif #ifdef BOOTP_IF printf("No bootp server found for eth%d!", BOOTP_IF); #else printf("No bootp server found for any interface!"); #endif printf(" Try again? [n] "); fgets(buf, BUFSIZE, stdin); if (buf[0] == 'y' || buf[0] == 'Y') goto retry; printf("Enter bootp information manually? [y] "); fgets(buf, BUFSIZE, stdin); if (buf[0] != 'n' && buf[0] != 'N') { interactive = 1; goto retry; } return OSKIT_E_FAIL; } /* * Now we know our bootp struct has all we need, * so we copy the info out. */ ipaddr = strdup(inet_ntoa(bpi.ip)); netmask = strdup(inet_ntoa(bpi.netmask)); gateway = strdup(inet_ntoa(bpi.gateway.addr[0])); domain = strdup(bpi.domainname); { struct bootp_addr_array ns; int x; ns = bpi.dns_server; nameservers = mustcalloc(1, (sizeof(char*) * ns.len) + 1); for (x = 0; x < ns.len; x++) nameservers[x] = strdup(inet_ntoa(ns.addr[x])); nameservers[ns.len] = NULL; } /* Hostnamelen needs to be word aligned for RPC code. */ hostname = (char *)mustcalloc(strlen(bpi.hostname) + 3, 1); strcpy(hostname, bpi.hostname); hostnamelen = (strlen(hostname) + 3) & ~3; #ifdef DEBUG bootp_dump(&bpi); #endif printf("I am %s.%s (IP: %s, GW: %s, mask: %s)\n", hostname, domain, ipaddr, gateway, netmask); #ifdef FREEBSD_NET err = start_conf_network_init(start_osenv(), &fsc); assert(!err); err = start_conf_network_eifstart(i, ipaddr, netmask); assert(!err); start_conf_network_host(hostname, gateway, domain, nameservers); #else /* Now init the fudp module. It will open the device */ udplib_init(dev, hostname, ipaddr, netmask, gateway, &fsc); /* * This writes out the DNS files. We need the freebsd stub * function below since it thinks its dealing with the freebsd * network stack. */ start_conf_network_host(hostname, gateway, domain, nameservers); #endif /* * Register to socket factory so that UDP might be useful for others. * Its a long shot! */ #ifdef PTHREADS pthread_init_socketfactory(fsc); #else oskit_register(&oskit_socket_factory_iid, (void *) fsc); #endif return 0; }
static void tnetw1130_reset(tnetw1130_t *s) { MISSING(); }
TVoid ODS_DetermineZcoordinate( NefisFileInfoPtr file_info, /* I Contents of the file */ ParameterInfoPtr wl_info, /* I Parameter: water level */ ParameterInfoPtr depth_info, /* I Parameter: depth */ TInt4 cell_index[5][3], /* I Cell indexes to retrieve */ TInt4 * loc, /* I Details about locations */ TInt4 * ndim, /* I Array dimensions */ TInt4 * lgrid, /* I Grid indices */ TReal4 misval, /* I missing value */ TReal4 ** zcrd_ptr ) /* IO z-coordinate (will be allocated if NULL on entry!) */ { TInt4 i ; TInt4 i2 ; TInt4 i3 ; TInt4 i4 ; TInt4 k ; TInt4 t ; TInt4 nosegl ; TInt4 nolay ; TInt4 idxpar ; TInt4 idxzcrd ; TInt4 idxsigma ; TInt4 notimes ; TInt4 nodata ; TInt4 nodummy ; TInt4 elem_size ; TInt4 number_cells ; TInt4 cell_index2[5][3] ; TReal4 * water_level ; TReal4 * depth ; TReal4 * thickn ; TReal4 * zlevel ; TReal4 * th_factor ; TReal4 * z_coordinate ; LocationInfoPtr loc_info ; /* Get the data we always need TODO: time-dependent bottom! */ loc_info = wl_info->location_info ; notimes = cell_index[0][1] - cell_index[0][0] + 1 ; nolay = ndim[2] - 1 ; nodata = ndim[0] * ndim[1] ; water_level = (TReal4 *) malloc( nodata*notimes*sizeof(TReal4) ) ; depth = (TReal4 *) malloc( nodata*sizeof(TReal4) ) ; thickn = NULL; zlevel = NULL; th_factor = NULL; z_coordinate = NULL; (void) GNF_FindParameter( wl_info->group_name, wl_info->elem_name, 1, file_info->no_items, file_info->items, &idxpar ) ; GNF_GetActualData( file_info, wl_info, idxpar, &cell_index[0][0], loc, misval, water_level, &nodummy ) ; (void) GNF_FindParameter( depth_info->group_name, depth_info->elem_name, 1, file_info->no_items, file_info->items, &idxpar ) ; cell_index2[0][0] = 0 ; cell_index2[0][1] = 0 ; cell_index2[0][2] = 1 ; GNF_GetActualData( file_info, depth_info, idxpar, &cell_index2[0][0], loc, misval, depth, &nodummy ) ; nosegl = ndim[0]*ndim[1] ; /* Delft3D-FLOW specific (somewhat): Decide on the method */ idxsigma = -1 ; (void) GNF_FindParameter( loc_info->zcoord_group, loc_info->zcoord_elem, 1, file_info->no_items, file_info->items, &idxzcrd ) ; if ( idxzcrd == -1 || file_info->items->elem_dims[0] < 1 ) { idxzcrd = -1 ; (void) GNF_FindParameter( loc_info->sigmalayer_group, loc_info->sigmalayer_elem, 1, file_info->no_items, file_info->items, &idxsigma ) ; if ( idxsigma == -1 ) { idxsigma = -2 ; } } /* Use z-layers */ if ( idxzcrd != -1 ) { cell_index2[0][0] = 0 ; cell_index2[0][1] = 0 ; cell_index2[0][2] = 1 ; GNF_GetRealBuffer( file_info, idxzcrd, &cell_index2[0][0], &zlevel, &elem_size, &number_cells ) ; /* Make sure we only use as much of the array as is allowed -- deep problems with the vertical direction ** TODO ** */ if ( nolay > elem_size-1 ) { nolay = elem_size-1 ; } /* Allocate the z-coordinates array? */ if ( (*zcrd_ptr) == NULL ) { (*zcrd_ptr) = (TReal4 *) malloc( (nolay+1)*nosegl*notimes*sizeof(TReal4) ) ; } z_coordinate = *zcrd_ptr ; #define MISSING(x) (fabs(x-misval)<0.0001) i4 = 0 ; for ( t = 0 ; t < notimes ; t ++ ) { for ( k = 0 ; k < nolay+1 ; k ++ ) { i2 = 0 ; i3 = t * nosegl ; for ( i = 0 ; i < nosegl ; i ++ ) { /* Keep the bottom depth fixed for the moment! */ z_coordinate[i4] = zlevel[k] ; if ( zlevel[k] < -depth[i2] ) { z_coordinate[i4] = -depth[i2] ; } if ( zlevel[k] > water_level[i3] ) { z_coordinate[i4] = water_level[i3] ; } if ( lgrid[i] <= 0 || MISSING(depth[i2]) || MISSING(water_level[i3]) ) { z_coordinate[i4] = misval ; } /* -- if ( z_coordinate[i4] > -10.0 && z_coordinate[i4] < 1200.0 ) printf( "i,k: %d %d - %g %g %g %g\n", i,k, z_coordinate[i4], zlevel[k], water_level[i3], depth[i2] ) ; -- */ i2 ++ ; i3 ++ ; i4 ++ ; } } } free( zlevel ) ; } /* Use sigma-layers */ if ( idxsigma != -1 ) { if ( idxsigma != -2 ) { cell_index2[0][0] = 0 ; cell_index2[0][1] = 0 ; cell_index2[0][2] = 1 ; GNF_GetRealBuffer( file_info, idxsigma, &cell_index2[0][0], &thickn, &elem_size, &number_cells ) ; } else { /* Assume a uniform distribution */ elem_size = nolay ; thickn = (TReal4 *) malloc( (nolay+1)*sizeof(TReal4) ) ; for ( i = 1 ; i < nolay+1 ; i ++ ) { thickn[i] = 1.0/nolay ; } } /* Make sure we only use as much of the array as is allowed -- deep problems with the vertical direction ** TODO ** */ if ( nolay > elem_size ) { nolay = elem_size ; } /* Two-dimensional quantities? */ if ( nolay == 1 ) { thickn[0] = 1.0 ; } /* Allocate the z-coordinates array? */ if ( (*zcrd_ptr) == NULL ) { (*zcrd_ptr) = (TReal4 *) malloc( (nolay+1)*nosegl*notimes*sizeof(TReal4) ) ; } z_coordinate = *zcrd_ptr ; th_factor = (TReal4 *) malloc( (nolay+1)*sizeof(TReal4) ) ; th_factor[0] = 0.0 ; for ( i = 1 ; i < nolay+1 ; i ++ ) { th_factor[i] = th_factor[i-1] + thickn[i-1] ; } i4 = 0 ; for ( t = 0 ; t < notimes ; t ++ ) { for ( k = 0 ; k < nolay+1 ; k ++ ) { i2 = 0 ; i3 = t * nosegl ; for ( i = 0 ; i < nosegl ; i ++ ) { /* Keep the bottom depth fixed for the moment! */ z_coordinate[i4] = water_level[i3] - th_factor[k] * ( water_level[i3] + depth[i2] ) ; if ( lgrid[i] <= 0 ) { z_coordinate[i4] = misval ; } i2 ++ ; i3 ++ ; i4 ++ ; } } } free( thickn ) ; free( th_factor ) ; } free( water_level ) ; free( depth ) ; return ; }