示例#1
0
void start(void)
{	
	uint16_t count;
	uint8_t index;

	buffer = (char *)mos_mem_alloc((uint16_t)BUFFER_SIZE);
	memset(buffer, 'X', BUFFER_SIZE);

	/* For safety, erase entire FLASH */
	dev_ioctl(DEV_TELOS_FLASH, TELOS_FLASH_BULK_ERASE);

	/* Turn on the FLASH */
	dev_mode(DEV_TELOS_FLASH, DEV_MODE_ON);
	
	/* Acquire lock on FLASH and preliminarly 
	 * write 64 bits of data */
	dev_open(DEV_TELOS_FLASH);
	count = dev_write(DEV_TELOS_FLASH, "abcdefgh", 8);
	printf("%d bytes of data have been written to FLASH memory\n", count);
	dev_close(DEV_TELOS_FLASH);

			/* Perform experiments over R/W pointer to FLASH */	

	/* Experiment#1 - flash is on, lock is free; aquire lock and read 
	 *                without using any SEEK function */
	dev_open(DEV_TELOS_FLASH);
	count = dev_read(DEV_TELOS_FLASH, buffer, 1);
	printf("#1 : %c has been read from FLASH memory\n", buffer[0]);	
	dev_close(DEV_TELOS_FLASH);

	/* Move pointer */
	dev_open(DEV_TELOS_FLASH);
	dev_ioctl(DEV_TELOS_FLASH, DEV_SEEK, 3);
	dev_close(DEV_TELOS_FLASH);	

	/* Experiment#2 - flash is on, lock is free; aquire lock, read single data, 
	 * write single data and read multiple data from it */
	dev_open(DEV_TELOS_FLASH);
	dev_read(DEV_TELOS_FLASH, buffer, 1);
	printf("#2 : %c has been read\n"
		   "   : FLASH memory written\n", buffer[0]);
	dev_write(DEV_TELOS_FLASH, "l", 1);	
	count =	dev_read(DEV_TELOS_FLASH, buffer, 1);
	printf("   : %d bytes have been read from FLASH memory: ", count);
	for(index = 0; index < count; index++)
	{
		printf("%c ", buffer[index]);
	}
	printf("\n");
	dev_close(DEV_TELOS_FLASH);

	/* Release lock and free resources */
	dev_close(DEV_TELOS_FLASH);
	dev_mode(DEV_TELOS_FLASH, DEV_MODE_OFF);
	mos_mem_free(buffer);

	return;
}
示例#2
0
inline
static int try_acquire_counter(void)
{
	extern struct perf_counter_operations *perf_counter_ops;
	extern u8 r5900_perf_mode;
	int fd=-1;

	if (r5900_perf_mode == PERF_MODE_SAMPLE){
		return -EBUSY;
	} 
	if (r5900_perf_mode == PERF_MODE_COUNTER) {
		struct perf_dev_internal_cmd cmd_pkt;
		void * taskp;

		cmd_pkt.cmd = PERF_WRITER;
		taskp = (void *) perf_counter_ops->control (0, 
			PERF_IOCINTERNAL, &cmd_pkt);
		if (taskp ==  current) {
			return 0;
		}
		return -EBUSY;
	}

	fd = dev_open("/dev/" PERF_DEV_COUNTER_NAME, O_RDWR, 0);
	if (fd<0) {
		return fd;
	}
	return 0;
}
/** Add the interface (net device) for a vnet.
 * Sets the dev field of the vnet on success.
 * Does nothing if the vnet already has an interface.
 *
 * @param vnet vnet
 * @return 0 on success, error code otherwise
 */
int vnet_dev_add(Vnet *vnet){
    int err = 0;
    struct net_device *dev = NULL;

    if(vnet->dev) goto exit;
    vnet->header_n = ETH_HLEN + sizeof(struct iphdr) + sizeof(struct etheriphdr);
    if(etherip_in_udp){
        vnet->header_n += sizeof(struct VnetMsgHdr);
        vnet->header_n += sizeof(struct udphdr);
    }
    vnet->header_n = roundupto(vnet->header_n, 4);
    dev = alloc_netdev(0, vnet->device, vnet_dev_init);
    if(!dev){
        err = -ENOMEM;
        goto exit;
    }
    err = vnet_dev_setup(vnet, dev);
    if(err) goto exit;
    rtnl_lock();
    dev_open(dev);
    rtnl_unlock();

  exit:
    return err;
}
示例#4
0
BOOL ota_check(void)
{
  ota_bl_info_t bl_info = {0};
  charsto_cfg_t charsto_cfg = {0};
  void  *p_dev = NULL;
  RET_CODE ret = ERR_FAILURE;

  /******char storage init******/
  ret = ATTACH_DRIVER(CHARSTO, warriors, default, default);
  MT_ASSERT(ret == SUCCESS);

  p_dev = dev_find_identifier(NULL, DEV_IDT_TYPE, SYS_DEV_TYPE_CHARSTO);
  MT_ASSERT(NULL != p_dev);

  charsto_cfg.size = CHARSTO_SIZE; //4
  charsto_cfg.spi_clk = FLASH_C_CLK_P6;
  charsto_cfg.rd_mode = SPI_FR_MODE;
  //charsto_cfg.multi_io_rd = 1;
  //charsto_cfg.multi_io_wd = 1;
  ret = dev_open(p_dev, &charsto_cfg);
  MT_ASSERT(ret == SUCCESS);

  /* open uio */
  uio_init();

  mtos_task_delay_ms(M_TASK_DELAY_TIME);

  if(mul_ota_dm_api_check_intact_picec(OTA_DM_BLOCK_PIECE_OTA_BLINFO_ID) == FALSE)
  {
      ui_ota_api_bootload_info_init();
  }

  mul_ota_dm_api_read_bootload_info(&bl_info);
  OS_PRINTF("\r\n[OTA]%s:ota_tri[%d] ",__FUNCTION__, bl_info.ota_status);



  /* flash burning is not finished, force ota*/
  if( bl_info.destroy_flag == TRUE) 
  {
      bl_info.ota_status = OTA_TRI_MODE_FORC;
      mul_ota_dm_api_save_bootload_info(&bl_info);
      return TRUE;
  }

  if(is_force_key_press())
  {
    bl_info.ota_status = OTA_TRI_MODE_AUTO;
    mul_ota_dm_api_save_bootload_info(&bl_info);
    return TRUE;
  }

  if((bl_info.ota_status == OTA_TRI_MODE_AUTO)
  ||(bl_info.ota_status == OTA_TRI_MODE_FORC))
  {
      return TRUE;
  }

  return FALSE;
}
示例#5
0
static struct net_device *ipmr_reg_vif(void)
{
    struct net_device *dev;
    struct in_device *in_dev;

    dev = alloc_netdev(sizeof(struct net_device_stats), "pimreg",
                       reg_vif_setup);

    if (dev == NULL)
        return NULL;

    if (register_netdevice(dev)) {
        free_netdev(dev);
        return NULL;
    }
    dev->iflink = 0;

    if ((in_dev = inetdev_init(dev)) == NULL)
        goto failure;

    in_dev->cnf.rp_filter = 0;

    if (dev_open(dev))
        goto failure;

    return dev;

failure:
    unregister_netdevice(dev);
    return NULL;
}
示例#6
0
/*****************************************************************************
 * Open the "real" network devices. Return the number of opened interfaces.
 *****************************************************************************/
int open_network_devices(int promisc)
{
	struct net_device *dev;
	struct net *net;
	int err = 0, cnt = 0;

	DEBUG(ANKH_DEBUG_INIT, "%s() \n", __func__);

	for_each_net(net) {
		for_each_netdev(net, dev)
		{
			DEBUG(ANKH_DEBUG_INIT, "opening %s\n", dev->name);

			// beam us to promiscuous mode, so that we can receive packets that
			// are not meant for the NIC's MAC address --> we need that, because
			// ORe clients have different MAC addresses
			if (promisc && netdev_set_promisc(dev) == 0)
					DEBUG(ANKH_DEBUG_INIT, "set interface to promiscuous mode.\n");

			err = dev_open(dev);
			if (err)
			{
				DEBUG(ANKH_DEBUG_INIT, "error opening %s : %d\n", dev->name, err);
				return err;
			}
			else // success
				netdev_add(dev);

		cnt++;
		//xmit_lock_add(dev->name);
		}
	}
示例#7
0
static struct net_device *ip6mr_reg_vif(struct net *net)
{
	struct net_device *dev;

	dev = alloc_netdev(0, "pim6reg", reg_vif_setup);
	if (dev == NULL)
		return NULL;

	dev_net_set(dev, net);

	if (register_netdevice(dev)) {
		free_netdev(dev);
		return NULL;
	}
	dev->iflink = 0;

	if (dev_open(dev))
		goto failure;

	dev_hold(dev);
	return dev;

failure:
	/* allow the register to be completed before unregistering. */
	rtnl_unlock();
	rtnl_lock();

	unregister_netdevice(dev);
	return NULL;
}
示例#8
0
/* Unused */
int label_verify(struct device *dev)
{
#pragma pack(8)
        char buf[LABEL_SIZE];
#pragma pack()
        struct labeller *l;
        //char buf[LABEL_SIZE] __attribute((aligned(8)));
        uint64_t sector;
        struct lvmcache_info *info;
        int r = 0;

        if (!dev_open(dev)) {
                if ((info = info_from_pvid(dev->pvid)))
                        lvmcache_update_vgname_and_id(info, ORPHAN, ORPHAN,
                                                      0, NULL);

                return_0;
        }

        if (!(l = _find_labeller(dev, buf, &sector, UINT64_C(0))))
                goto_out;

        r = l->ops->verify ? l->ops->verify(l, buf, sector) : 1;

      out:
        if (!dev_close(dev))
                stack;

        return r;
}
static struct net_device *ipmr_reg_vif(void)
{
	struct net_device *dev;
	struct in_device *in_dev;

	dev = alloc_netdev(sizeof(struct net_device_stats), "pimreg",
			   reg_vif_setup);

	if (dev == NULL)
		return NULL;

	if (register_netdevice(dev)) {
		free_netdev(dev);
		return NULL;
	}
	dev->iflink = 0;

	if ((in_dev = inetdev_init(dev)) == NULL)
		goto failure;

	in_dev->cnf.rp_filter = 0;

	if (dev_open(dev))
		goto failure;

	return dev;

failure:
	/* allow the register to be completed before unregistering. */
	rtnl_unlock();
	rtnl_lock();

	unregister_netdevice(dev);
	return NULL;
}
示例#10
0
void rds(char *arg)
{
	int c;
	char *val, err[0xff];
	struct pcimaxfm_rds_set rds_set;

	while (*arg != '\0') {
		if ((c = (getsubopt(&arg, rds_params_name, &val))) == -1)
			ERROR_MSG("Invalid RDS parameter \"%s\".", val);

		if (validate_rds(c, val, sizeof(err), err)) {
			ERROR_MSG("%s", err);
		}

		dev_open();

		rds_set.param = c;
		rds_set.value = val;

		if(ioctl(fd, PCIMAXFM_RDS_SET, &rds_set) == -1) {
			ERROR_MSG("Writing RDS parameter %s = \"%s\" failed.",
					rds_params_name[rds_set.param],
					rds_set.value);
		}

		NOTICE_MSG("RDS: %-4s = \"%s\"",
				rds_params_name[rds_set.param], rds_set.value);
	}
}
示例#11
0
void power(const char *arg)
{
	int power;

	dev_open();
	if (arg) {
		if (sscanf(arg, "%u", &power) < 1) {
			ERROR_MSG("Invalid power level. Got \"%s\", expected integer in the range of %d-%d.", arg, PCIMAXFM_POWER_MIN, PCIMAXFM_POWER_MAX);
		}

		if (power < PCIMAXFM_POWER_MIN || power > PCIMAXFM_POWER_MAX) {
			ERROR_MSG("Power level out of range. Got %d, expected %d-%d.", power, PCIMAXFM_POWER_MIN, PCIMAXFM_POWER_MAX);
		}

		if (ioctl(fd, PCIMAXFM_POWER_SET, &power) == -1) {
			ERROR_MSG("Setting power level failed.");
		}
	} else {
		if (ioctl(fd, PCIMAXFM_POWER_GET, &power) == -1) {
			ERROR_MSG("Reading power level failed.");
		}

		if (power == PCIMAXFM_POWER_NA) {
			NOTICE_MSG("Power level not set yet.");
			return;
		}
	}

	NOTICE_MSG("Power level: %d/%d", power, PCIMAXFM_POWER_MAX);
}
示例#12
0
文件: main.c 项目: webconnme/wc-s
int main (void)
{
	unsigned int mainkey;

	char buf[128] = {0,};

	printf("Program Start...\n");
	

	dev_fd = dev_open("/dev/webconn", WEBCONN_MAJOR, 0);

	write(dev_fd, "khkrai", 128);

	read(dev_fd, &buf, 128);

	printf("\n\nbuf=%s\n", buf);

	printf("%x\n", IOCTL_WRITE);
	printf("%x\n", IOCTL_READ);
	ioctl(dev_fd, IOCTL_WRITE, 1);
	ioctl(dev_fd, IOCTL_READ, 0);


	close(dev_fd);
		return 0;
}
示例#13
0
/* Called whenever someone tries to open our node (even for a stat).  We
   delay opening the kernel device until this point, as we can usefully
   return errors from here.  */
static error_t
check_open_hook (struct trivfs_control *trivfs_control,
		 struct iouser *user,
		 int flags)
{
  struct dev *const dev = trivfs_control->hook;
  error_t err = 0;

  if (!err && dev_is_readonly (dev) && (flags & O_WRITE))
    return EROFS;

  mutex_lock (&dev->lock);
  if (dev->store == NULL)
    {
      /* Try and open the store.  */
      err = dev_open (dev);
      if (err && (flags & (O_READ|O_WRITE)) == 0)
	/* If we're not opening for read or write, then just ignore the
	   error, as this allows stat to work correctly.  XXX  */
	err = 0;
    }
  mutex_unlock (&dev->lock);

  return err;
}
示例#14
0
文件: ipmr.c 项目: mfleming/linux-2.6
static
struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v)
{
	struct net_device  *dev;

	dev = __dev_get_by_name(net, "tunl0");

	if (dev) {
		const struct net_device_ops *ops = dev->netdev_ops;
		int err;
		struct ifreq ifr;
		struct ip_tunnel_parm p;
		struct in_device  *in_dev;

		memset(&p, 0, sizeof(p));
		p.iph.daddr = v->vifc_rmt_addr.s_addr;
		p.iph.saddr = v->vifc_lcl_addr.s_addr;
		p.iph.version = 4;
		p.iph.ihl = 5;
		p.iph.protocol = IPPROTO_IPIP;
		sprintf(p.name, "dvmrp%d", v->vifc_vifi);
		ifr.ifr_ifru.ifru_data = (__force void __user *)&p;

		if (ops->ndo_do_ioctl) {
			mm_segment_t oldfs = get_fs();

			set_fs(KERNEL_DS);
			err = ops->ndo_do_ioctl(dev, &ifr, SIOCADDTUNNEL);
			set_fs(oldfs);
		} else
			err = -EOPNOTSUPP;

		dev = NULL;

		if (err == 0 &&
		    (dev = __dev_get_by_name(net, p.name)) != NULL) {
			dev->flags |= IFF_MULTICAST;

			in_dev = __in_dev_get_rtnl(dev);
			if (in_dev == NULL)
				goto failure;

			ipv4_devconf_setall(in_dev);
			IPV4_DEVCONF(in_dev->cnf, RP_FILTER) = 0;

			if (dev_open(dev))
				goto failure;
			dev_hold(dev);
		}
	}
	return dev;

failure:
	/* allow the register to be completed before unregistering. */
	rtnl_unlock();
	rtnl_lock();

	unregister_netdevice(dev);
	return NULL;
}
示例#15
0
文件: dev.c 项目: HarryR/sanos
void install_drivers() {
  dev_t console;

  // Register /proc/units
  register_proc_inode("units", units_proc, NULL);
  register_proc_inode("devices", devices_proc, NULL);
  register_proc_inode("devstat", devstat_proc, NULL);

  // Parse driver binding database
  parse_bindings();

  // Match bindings to units
  bind_units();

  // Install legacy drivers
  install_legacy_drivers();

  // Make sure we have a console device
  console = dev_open("console");
  if (console == NODEV) {
    initialize_driver(NULL, "krnl.dll!console");
  } else {
    dev_close(console);
  }
}
示例#16
0
/* FIXME Avoid repeated re-reading if cache lock held */
int label_read(struct device *dev, struct label **result,
                uint64_t scan_sector)
{
#pragma pack(8)
        char buf[LABEL_SIZE]; //__attribute((aligned(8)));
#pragma pack()
        struct labeller *l;
        uint64_t sector;
        struct lvmcache_info *info;
        int r = 0;

        if (!dev_open(dev)) {
                stack;

                if ((info = info_from_pvid(dev->pvid)))
                        lvmcache_update_vgname_and_id(info, ORPHAN, ORPHAN,
                                                      0, NULL);

                return r;
        }

        if (!(l = _find_labeller(dev, buf, &sector, scan_sector)))
                goto_out;

        if ((r = (l->ops->read)(l, dev, buf, result)) && result && *result)
                (*result)->sector = sector;

      out:
        if (!dev_close(dev))
                stack;

        return r;
}
示例#17
0
int DeviceV4L2Base::open_dev(int color_model)
{
	v4l2_lock->lock("DeviceV4L2Base::open_dev");
	int result = 0;
	if( !opened )
	{
		result = dev_open();
		if( !result )
			result = v4l2_open(color_model);
		if( !result )
			result = start_dev();
		if( !result )
		{
			qbfrs_lock->reset();
			video_lock->reset();
			getq = new DeviceV4L2BufferQ(total_buffers+1);
			put_thread = new DeviceV4L2Put(this);
			put_thread->start();
			done = 0;
			Thread::start();
		}
		else
			printf("DeviceV4L2Base::open_dev failed\n");
	}
	if( result )
	{
		printf("DeviceV4L2Base::open_dev: adaptor open failed\n");
		stop_dev();
		dev_close();
	}
	else
		opened = 1;
	v4l2_lock->unlock();
	return result;
}
示例#18
0
文件: ether.c 项目: HarryR/sanos
struct netif *ether_netif_add(char *name, char *devname, struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw) {
  struct netif *netif;
  struct dhcp_state *state;
  dev_t devno;

  // Open device
  devno = dev_open(devname);
  if (devno == NODEV) return NULL;
  if (device(devno)->driver->type != DEV_TYPE_PACKET) return NULL;

  // Attach device to network interface
  netif = netif_add(name, ipaddr, netmask, gw);
  if (!netif) return NULL;

  netif->output = ether_output;
  netif->state = (void *) devno;

  dev_attach(devno, netif, ether_input);

  // Obtain network parameters using DHCP
  if (ip_addr_isany(ipaddr)) {
    state = dhcp_start(netif);
    if (state) {
      if (wait_for_object(&state->binding_complete, 30000)  < 0) {
        kprintf(KERN_WARNING "ether: timeout waiting for dhcp to complete on %s\n", name);
      }
    }
  }

  kprintf(KERN_INFO "%s: device %s addr %a mask %a gw %a\n", name, devname, &netif->ipaddr, &netif->netmask, &netif->gw);

  return netif;
}
示例#19
0
static int _dev_read_ahead_dev(struct device *dev, uint32_t *read_ahead)
{
	long read_ahead_long;

	if (dev->read_ahead != -1) {
		*read_ahead = (uint32_t) dev->read_ahead;
		return 1;
	}

	if (!dev_open(dev))
		return_0;

	if (ioctl(dev->fd, BLKRAGET, &read_ahead_long) < 0) {
		log_sys_error("ioctl BLKRAGET", dev_name(dev));
		if (!dev_close(dev))
			stack;
		return 0;
	}

	if (!dev_close(dev))
		stack;

	*read_ahead = (uint32_t) read_ahead_long;
	dev->read_ahead = read_ahead_long;

	log_very_verbose("%s: read_ahead is %u sectors",
			 dev_name(dev), *read_ahead);

	return 1;
}
示例#20
0
文件: inittab.c 项目: unixz/procd
static void fork_worker(struct init_action *a)
{
	int fd;
	pid_t p;

	a->proc.pid = fork();
	if (!a->proc.pid) {
		p = setsid();

		fd = dev_open(a->id);
		if (fd != -1)
		{
			dup2(fd, STDIN_FILENO);
			dup2(fd, STDOUT_FILENO);
			dup2(fd, STDERR_FILENO);
			if (fd > STDERR_FILENO)
				close(fd);
		}

		ioctl(STDIN_FILENO, TIOCSCTTY, 1);
		tcsetpgrp(STDIN_FILENO, p);

		execvp(a->argv[0], a->argv);
		ERROR("Failed to execute %s\n", a->argv[0]);
		exit(-1);
	}

	if (a->proc.pid > 0) {
		DEBUG(4, "Launched new %s action, pid=%d\n",
					a->handler->name,
					(int) a->proc.pid);
		uloop_process_add(&a->proc);
	}
}
示例#21
0
static int _dev_discard_blocks(struct device *dev, uint64_t offset_bytes, uint64_t size_bytes)
{
	uint64_t discard_range[2];

	if (!dev_open(dev))
		return_0;

	discard_range[0] = offset_bytes;
	discard_range[1] = size_bytes;

	log_debug_devs("Discarding %" PRIu64 " bytes offset %" PRIu64 " bytes on %s.",
		       size_bytes, offset_bytes, dev_name(dev));
	if (ioctl(dev->fd, BLKDISCARD, &discard_range) < 0) {
		log_error("%s: BLKDISCARD ioctl at offset %" PRIu64 " size %" PRIu64 " failed: %s.",
			  dev_name(dev), offset_bytes, size_bytes, strerror(errno));
		if (!dev_close(dev))
			stack;
		/* It doesn't matter if discard failed, so return success. */
		return 1;
	}

	if (!dev_close(dev))
		stack;

	return 1;
}
void get_rssi()
{
   uint16_t rssi_val;
   dev_open(DEV_AVR_RSSI);
   dev_read(DEV_AVR_RSSI, &rssi_val, sizeof(rssi_val));
   dev_close(DEV_AVR_RSSI);
   printf("rssi %d\n",rssi_val);
}
示例#23
0
/* Open a connection to an IO device */
int io_dev_open(const io_dev_connector_t *dev_con, const uintptr_t dev_spec,
		uintptr_t *handle)
{
	int result;
	assert(handle != NULL);

	result = dev_open(dev_con, dev_spec, (io_dev_info_t **)handle);
	return result;
}
示例#24
0
bool FW_writeFlash(char *filename)
{
	FILE *fp;
	uint8_t *buf = 0;
	uint32_t *buf32, chksum;
	int i, filesize;

	if ((fp = fopen(filename, "rb")) == 0) {
		printf("unable to open firmware '%s'\n", filename);
		return(false);
	}
	fseek(fp, 0, SEEK_END);
	filesize = ftell(fp);
	fseek(fp, 0, SEEK_SET);
	if (filesize > (0x8000 - 8)) {
		printf("firmware image too large\n");
		fclose(fp);
		return(false);
	}
	buf = (uint8_t*)malloc(0x8000);
	buf32 = (uint32_t*)buf;
	memset(buf, 0, 0x8000);
	fread(buf, 1, filesize, fp);
	fclose(fp);

	buf32[(0x8000 - 8) / 4] = 0xDEADBEEF;

	chksum = 0;
	for (i = 0; i<(0x8000 - 4); i += 4) {
		chksum ^= buf32[i / 4];
	}

	printf("firmware is %d bytes, checksum is $%08X\n", filesize, chksum);

	buf32[(0x8000 - 4) / 4] = chksum;

	printf("uploading new firmware");
	if (!spi_writeFlash2(buf, 0x8000, 0x8000)) {
		printf("Write failed.\n");
		return false;
	}
	free(buf);

	printf("waiting for device to reboot\n");

	dev_updateFirmware();   //start update, device will reset itself
	sleep_ms(5000);

	if (!dev_open()) {
		printf("Open failed.\n");
		return false;
	}
	printf("Updated to build %d\n", dev_fwVersion);

	return true;
}
示例#25
0
文件: inittab.c 项目: unixz/procd
static int dev_exist(const char *dev)
{
	int res;

	res = dev_open(dev);
	if (res != -1)
		close(res);

	return (res != -1);
}
示例#26
0
/*===========================================================================*
 *				fs_readsuper				     *
 *===========================================================================*/
PUBLIC int fs_readsuper() {

  cp_grant_id_t label_gid;
  size_t label_len;
  int r = OK;
  endpoint_t driver_e;
  int readonly;

  fs_dev    = fs_m_in.REQ_DEV;
  label_gid = fs_m_in.REQ_GRANT;
  label_len = fs_m_in.REQ_PATH_LEN;
  readonly  = 1;			/* Always mount devices read only. */

  if (label_len > sizeof(fs_dev_label)) 
	return(EINVAL);

  r = sys_safecopyfrom(fs_m_in.m_source, label_gid, 0, (vir_bytes)fs_dev_label,
		       label_len, D);
  if (r != OK) {
	printf("ISOFS %s:%d safecopyfrom failed: %d\n", __FILE__, __LINE__, r);
	return(EINVAL);
  }

  r = ds_retrieve_label_endpt(fs_dev_label, &driver_e);
  if (r != OK) {
	printf("ISOFS %s:%d ds_retrieve_label_endpt failed for '%s': %d\n",
		__FILE__, __LINE__, fs_dev_label, r);
	return(EINVAL);
  }

  /* Map the driver endpoint for this major */
  driver_endpoints[(fs_dev >> MAJOR) & BYTE].driver_e =  driver_e;

  /* Open the device the file system lives on */
  if (dev_open(driver_e, fs_dev, driver_e,
	readonly ? R_BIT : (R_BIT|W_BIT)) != OK) {
        return(EINVAL);
  }

  /* Read the superblock */
  r = read_vds(&v_pri, fs_dev);
  if (r != OK)
	return(r);

  /* Return some root inode properties */
  fs_m_out.RES_INODE_NR = ID_DIR_RECORD(v_pri.dir_rec_root);
  fs_m_out.RES_MODE = v_pri.dir_rec_root->d_mode;
  fs_m_out.RES_FILE_SIZE_LO = v_pri.dir_rec_root->d_file_size;
  fs_m_out.RES_UID = SYS_UID; /* Always root */
  fs_m_out.RES_GID = SYS_GID; /* operator */

  fs_m_out.RES_CONREQS = 1;	/* We can handle only 1 request at a time */

  return(r);
}
示例#27
0
void send_packet(uint8_t packet_id)
{
   static uint8_t inited = 0;
   uint16_t temp;
   uint16_t hum;
   
   if (!inited)
   {
      inited = 1;
      dev_open(DEV_MSP_HUMIDITY);
      if (dev_mode(DEV_MSP_HUMIDITY, DEV_MODE_ON) == DEV_FAILURE)
      {
	 no_sensor = 1;
      }
      
   }
   
   mos_mutex_lock(&send_mutex);

   if (no_sensor)
   {
      temp = rand();
      hum = rand();
   }
   else
   {
      
      dev_read(DEV_MSP_TEMPERATURE, &temp, sizeof(temp));
      dev_read(DEV_MSP_HUMIDITY, &hum, sizeof(hum));
   }
   

   buf.size = 13;
   buf.data[0] = packet_id;
   
   buf_insert_WORD(buf.data, 1, mos_node_id_get());
   buf_insert_WORD(buf.data, 3, temp);
   buf_insert_WORD(buf.data, 5, hum);
   if (no_sensor)
   {
      buf_insert_WORD(buf.data, 7, rand());
      buf_insert_WORD(buf.data, 9, rand());
   }
   else
   {
      buf_insert_WORD(buf.data, 7, adc_get_conversion16(4));
      buf_insert_WORD(buf.data, 9, adc_get_conversion16(5));
   }
   
   buf_insert_WORD(buf.data, 11, crc_compute(buf.data, 11));

   com_send(IFACE_RADIO, &buf);

   mos_mutex_unlock(&send_mutex);
}
示例#28
0
/**
 * hns_nic_self_test - self test
 * @dev: net device
 * @eth_test: test cmd
 * @data: test result
 */
static void hns_nic_self_test(struct net_device *ndev,
			      struct ethtool_test *eth_test, u64 *data)
{
	struct hns_nic_priv *priv = netdev_priv(ndev);
	bool if_running = netif_running(ndev);
#define SELF_TEST_TPYE_NUM 3
	int st_param[SELF_TEST_TPYE_NUM][2];
	int i;
	int test_index = 0;

	st_param[0][0] = MAC_INTERNALLOOP_MAC; /* XGE not supported lb */
	st_param[0][1] = (priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII);
	st_param[1][0] = MAC_INTERNALLOOP_SERDES;
	st_param[1][1] = 1; /*serdes must exist*/
	st_param[2][0] = MAC_INTERNALLOOP_PHY; /* only supporte phy node*/
	st_param[2][1] = ((!!(priv->ae_handle->phy_dev)) &&
		(priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII));

	if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
		set_bit(NIC_STATE_TESTING, &priv->state);

		if (if_running)
			dev_close(ndev);

		for (i = 0; i < SELF_TEST_TPYE_NUM; i++) {
			if (!st_param[i][1])
				continue;	/* NEXT testing */

			data[test_index] = __lb_up(ndev,
				(enum hnae_loop)st_param[i][0]);
			if (!data[test_index]) {
				data[test_index] = __lb_run_test(
					ndev, (enum hnae_loop)st_param[i][0]);
				(void)__lb_down(ndev,
						(enum hnae_loop)st_param[i][0]);
			}

			if (data[test_index])
				eth_test->flags |= ETH_TEST_FL_FAILED;

			test_index++;
		}

		hns_nic_net_reset(priv->netdev);

		clear_bit(NIC_STATE_TESTING, &priv->state);

		if (if_running)
			(void)dev_open(ndev, NULL);
	}
	/* Online tests aren't run; pass by default */

	(void)msleep_interruptible(4 * 1000);
}
示例#29
0
void spiflash_cfg( )
{
    RET_CODE ret;
    void *p_dev = NULL;
    void *p_spi = NULL;
    charsto_cfg_t charsto_cfg = {0};
    spi_cfg_t spiCfg;

    spiCfg.bus_clk_mhz   = 50;//10;
    spiCfg.bus_clk_delay = 12;//8;
    spiCfg.io_num        = 1;
    spiCfg.lock_mode     = OS_MUTEX_LOCK;
    spiCfg.op_mode       = 0;
    spiCfg.pins_cfg[0].miso1_src  = 0;
    spiCfg.pins_cfg[0].miso0_src  = 1;
    spiCfg.pins_cfg[0].spiio1_src = 0;
    spiCfg.pins_cfg[0].spiio0_src = 0;
    spiCfg.pins_dir[0].spiio1_dir = 3;
    spiCfg.pins_dir[0].spiio0_dir = 3;
    spiCfg.spi_id = 0;

    ret = spi_concerto_attach("spi_concerto_0");
    MT_ASSERT(SUCCESS == ret);
    p_spi = dev_find_identifier(NULL,DEV_IDT_NAME, (u32)"spi_concerto_0");
    spiCfg.spi_id = 0;
    ret = dev_open(p_spi, &spiCfg);
    MT_ASSERT(SUCCESS == ret);

    spiflash_jazz_attach("charsto_concerto");
    OS_PRINTF("drv --charsto 1\n");

    p_dev = dev_find_identifier(NULL, DEV_IDT_TYPE, SYS_DEV_TYPE_CHARSTO);
    MT_ASSERT(NULL != p_dev);
    OS_PRINTF("drv --charsto 2\n");

    charsto_cfg.rd_mode = SPI_FR_MODE;
    charsto_cfg.p_bus_handle = p_spi;
    charsto_cfg.size = CHARSTO_SIZE;
    ret = dev_open(p_dev, &charsto_cfg);
    MT_ASSERT(SUCCESS == ret);
}
示例#30
0
/*
 *	Set destination address.
 *	Special case for SIT interfaces where we create a new "virtual"
 *	device.
 */
int addrconf_set_dstaddr(void *arg)
{
    struct in6_ifreq ireq;
    struct device *dev;
    int err = -EINVAL;

    rtnl_lock();

    err = -EFAULT;
    if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
        goto err_exit;

    dev = dev_get_by_index(ireq.ifr6_ifindex);

    err = -ENODEV;
    if (dev == NULL)
        goto err_exit;

    if (dev->type == ARPHRD_SIT) {
        struct ifreq ifr;
        mm_segment_t	oldfs;
        struct ip_tunnel_parm p;

        err = -EADDRNOTAVAIL;
        if (!(ipv6_addr_type(&ireq.ifr6_addr) & IPV6_ADDR_COMPATv4))
            goto err_exit;

        memset(&p, 0, sizeof(p));
        p.iph.daddr = ireq.ifr6_addr.s6_addr32[3];
        p.iph.saddr = 0;
        p.iph.version = 4;
        p.iph.ihl = 5;
        p.iph.protocol = IPPROTO_IPV6;
        p.iph.ttl = 64;
        ifr.ifr_ifru.ifru_data = (void*)&p;

        oldfs = get_fs();
        set_fs(KERNEL_DS);
        err = dev->do_ioctl(dev, &ifr, SIOCADDTUNNEL);
        set_fs(oldfs);

        if (err == 0) {
            err = -ENOBUFS;
            if ((dev = dev_get(p.name)) == NULL)
                goto err_exit;
            err = dev_open(dev);
        }
    }

err_exit:
    rtnl_unlock();
    return err;
}