Exemple #1
0
int son_phy_open(son_phy_t * phy, const char * name, int32_t flags, int32_t mode){
	phy->message = 0;
	phy->message_offset = 0;
	phy->message_size = 0;
	if( phy->driver == 0 ){
		//create using fopen()
		char open_code[8];

		if( (flags & SON_O_ACCESS) == SON_O_RDONLY ){
            sprintf(open_code, "rb");
		} else if( ((flags & SON_O_ACCESS) == SON_O_RDWR) && (flags & SON_O_CREAT) ){
			sprintf(open_code, "wb+");
		} else {
            sprintf(open_code, "rb+");
		}

		phy->f = fopen(name, open_code);
		if( phy->f != 0 ){
			return 0;
		}

		return -1;
	} else {
#if defined __link
		phy->fd = link_open(phy->driver, name, flags, mode);
		if( phy->fd < 0 ){
			return -1;
		}
		return 0;
#else
		return -1;
#endif
	}
}
Exemple #2
0
int main(int argc, char **argv)
{
	int e;
	
	if( argc < 3 ) error("usage: sarun link bootfile");

	link = atoi(argv[1]);

	/* open the link for raw I/O */	
	if( !link_open(link) ) error("failed to open link %d",link);

	/* boot the program through it */
	if( (e=link_boot(link,argv[2]))!=0 ) error("link_boot error %d",e);

	/* now spool stdin into the link and	*/
	/* anything from the link to stdout	*/
	
	InitSemaphore(&sync,0);
	
	Fork(2000,input,4,link);
	
	Fork(2000,output,4,link);
	
	Wait(&sync);
	Wait(&sync);
	
	if( !link_close(link) ) error("failed to close link %d",link);
}
Exemple #3
0
int Periph::_open(const char * name, int flags){
	char buffer[12];
	int len;

	strcpy(buffer, "/dev/");
	strcat(buffer, name);
	len = strlen(buffer);
	if( port_ != NO_PORT_NUMBER ){
		buffer[len] = '0' + port_;
		buffer[len+1] = '\0';
	} else {
		port_ = 0;
	}
	if ( fd[port_] != -1 ){
		//the port is already open
		printf("port is already open\n");
		return 0;
	}
	fd[port_] = link_open(handle, buffer, LINK_O_RDWR | flags);
	if( fd[port_] < 0 ){
		printf("Port failed to open %d\n", link_errno);
		return -1;
	}
	return 0;
}
int reset_device(link_phy_t handle, bool invoke_bootloader){
	//use "/dev/core" to reset
	int fd;
	link_op_t op;

	fd = link_open(handle, "/dev/core", LINK_O_RDWR);
	if ( fd < 0 ){
		return -1;
	}

	op.ioctl.cmd = LINK_CMD_IOCTL;
	op.ioctl.fildes = fd;
	op.ioctl.arg = (size_t)NULL;

	if( invoke_bootloader == false ){
		link_debug(3, "Try to reset\n");
		op.ioctl.request = I_CORE_RESET;

	} else {
		link_debug(3, "Try to invoke bootloader\n");
		op.ioctl.request = I_CORE_INVOKEBOOTLOADER;
	}

	link_protocol_masterwrite(handle, &op, sizeof(link_ioctl_t));
	link_phy_close(handle);
	return 0;
}
Exemple #5
0
/*
 *      get_hardware_address    -- Get the Ethernet MAC address associated
 *                                 with the given device.
 *      Inputs:
 *
 *      if_name		The name of the network interface
 *      hw_address	(output) the Ethernet MAC address
 *
 *      Returns:
 *
 *      None
 */
void
get_hardware_address(const char *if_name, unsigned char hw_address[]) {
   union DL_primitives *dlp;
   unsigned char buf[MAXDLBUF];
   link_t *handle;

   handle = link_open(if_name);

   dlp = (union DL_primitives*) buf;
   dlp->physaddr_req.dl_primitive = DL_PHYS_ADDR_REQ;
   dlp->physaddr_req.dl_addr_type = DL_CURR_PHYS_ADDR;
   if (dlpi_msg(handle->fd, dlp, DL_PHYS_ADDR_REQ_SIZE, 0, DL_PHYS_ADDR_ACK,
                DL_PHYS_ADDR_ACK_SIZE, sizeof(buf)) < 0) {
      err_msg("dlpi_msg failed");
   }

   link_close(handle);
   memcpy(hw_address, buf + dlp->physaddr_ack.dl_addr_offset, ETH_ALEN);
}