Example #1
0
int arp_register()
{
	uint32_t output_size = 0;
	ncp_header m_ncp ;
	volatile frame * my_frame = get_free_frame();

	create_arp_req(my_frame);
	TransmitPacket(my_frame->f_data, my_frame->f_len);
	release_frame(my_frame);
	return 0;
}
Example #2
0
int client_register()
{
	uint32_t output_size = 0;

	ncp_header m_ncp ;
	volatile frame * my_frame = get_free_frame();
	ncp_register(&m_ncp,NCP_HEADER_SIZE);

	my_frame->f_len = create_packiet(my_frame->f_data,ETHER_MAX_LEN,&m_ncp,NCP_HEADER_SIZE);
	TransmitPacket(my_frame->f_data, my_frame->f_len);
	release_frame(my_frame);
	return 0;
}
Example #3
0
/*
 * decrement the ref_count of a map cache and free if necessary
 */
void release_image_channel(struct image_channel *channel)
{
	if (channel->ref_count == 0) {
		err_printf("release_image_channel: suspicious channel has ref_count of 0\n");
	}
	if (channel->ref_count == 1) {
		if (channel->fr)
			release_frame(channel->fr);
		free(channel);
		return;
	}
	channel->ref_count--;
}
Example #4
0
int arp_response(frame * arp)
{
	frame *output;
	uint32_t output_size = 0;
	frame  *m_frame = get_free_frame();

	create_arp_res(arp,output);
	TransmitPacket(output->f_data, output->f_len);
	release_frame(output);
	return 0;



}
Example #5
0
void asm_proc_function_block(struct ir_code *head, struct ir_code *tail) {
    assert(head && tail && head != tail);
    assert(head->kind == IR_FUNCTION);
    assert(frame == NULL);
    new_frame();
    add_mips_inst(new_mips_inst(MIPS_LABEL, .label=head->op->name));
    // Generate prologue:
    // sw $fp, 0($sp)
    // sw $ra, -4($sp)
    // move $fp, $sp
    // addi $sp, $sp, -frame_size
    struct mips_inst *inst;
    add_mips_inst(new_mips_inst(MIPS_SW, .op1=reg_op[REG_FP], \
                .op2 = new_mips_op(MIPS_OP_ADDR, .reg=REG_SP, .offset=0)));
    add_mips_inst(new_mips_inst(MIPS_SW, .op1=reg_op[REG_RA], \
                .op2 = new_mips_op(MIPS_OP_ADDR, .reg=REG_SP, .offset=-4)));
    add_mips_inst(new_mips_inst(MIPS_MOVE, .op1=reg_op[REG_FP], .op2=reg_op[REG_SP]));
    add_mips_inst(inst = new_mips_inst(MIPS_ADDI, .op1=reg_op[REG_SP], \
                .op2=reg_op[REG_SP], .op3=new_mips_op(MIPS_OP_IMM)));
    int *p_frame_size = {&inst->op3->value}; // wait to be filled
    // put arguments in the frame variables table
    struct ir_code *p = head->next;
    while (p->kind == IR_PARAM) {
        add_arg_var(p->op->kind, p->op->no);
        p = p->next;
    }
    // Process other code (cut them into basic blocks)
    while (p != tail->next) {
        switch (p->kind) {
        case IR_FUNCTION:
        case IR_PARAM:
            assert(false);
        default:
            asm_proc_ir_code(p);
        }
        p = p->next;
    }
    // back fill
    *p_frame_size = frame->var_offset;
    release_frame();
}
Example #6
0
dc1394error_t
dc1394_juju_capture_stop(platform_camera_t *craw)
{
    dc1394camera_t * camera = craw->camera;
    struct fw_cdev_stop_iso stop;
    int i;

    if (craw->capture_is_set == 0)
        return DC1394_CAPTURE_IS_NOT_SET;

    stop.handle = craw->iso_handle;
    if (ioctl(craw->iso_fd, FW_CDEV_IOC_STOP_ISO, &stop) < 0)
        return DC1394_IOCTL_FAILURE;

    munmap(craw->buffer, craw->buffer_size);
    close(craw->iso_fd);
    for (i = 0; i<craw->num_frames; i++)
        release_frame(craw, i);
    free (craw->frames);
    craw->frames = NULL;
    craw->capture_is_set = 0;

    if (craw->capture_iso_resource) {
        if (juju_iso_deallocate (craw, craw->capture_iso_resource) < 0)
            dc1394_log_warning ("juju: Failed to deallocate iso resources");
        craw->capture_iso_resource = NULL;
    }

    // stop ISO if it was started automatically
    if (craw->iso_auto_started>0) {
        dc1394error_t err=dc1394_video_set_transmission(camera, DC1394_OFF);
        DC1394_ERR_RTN(err,"Could not stop ISO!");
        craw->iso_auto_started=0;
    }

    return DC1394_SUCCESS;
}
Example #7
0
int reciever::assemble_and_out()
{
	if (current_frame_id < 0 || current_packet_count == 0)
		return 0;

	int payload_packet_count = 0;
	int parity_packet_count;
	for(int i=0; i<256; i++)
	{
		if (packets[i].payload_packet_count)
		{
			payload_packet_count = packets[i].payload_packet_count;
			parity_packet_count = packets[i].parity_packet_count;
			break;
		}
	}

	// we have enough valid packets? packets properly formed?
	if (current_packet_count < payload_packet_count || payload_packet_count <= 0 || parity_packet_count <= 0)
	{
		// no, clear up and exit
		current_frame_id = -1;
		current_packet_count = 0;
		for(int i=0; i<256; i++)
		{
			memset(&packets[i], 0, sizeof(raw_packet));
			packets[i].payload_packet_count = 0;
		}
	}
	
	// assemble and do FEC if needed

	// create erasures
	int slice_size = payload_packet_count + parity_packet_count;
	int erasures[256];
	int erasures_count = 0;
	for(int i=0; i<slice_size; i++)
		if (packets[i].payload_packet_count == 0)	// current only missing packets checked, TODO: CRC
			erasures[erasures_count++] = i;

	// decode and output
	rsDecoder decoder;
	bool error = false;
	decoder.init(parity_packet_count);
	uint8_t slice_data[256];
	int max_packet_payload_size = sizeof(raw_packet)-5;
	frame * f = alloc_frame(payload_packet_count * max_packet_payload_size, current_frame_id, true);
	for(int i=0; i<max_packet_payload_size; i++)
	{
		for(int j=0; j<slice_size; j++)
			slice_data[j] = packets[j].data[i];		

		if (!decoder.correct_errors_erasures(slice_data, slice_size, erasures_count, erasures))
			error = true;


		for(int j=0; j<payload_packet_count; j++)
		{
			((uint8_t*)f->payload)[j*max_packet_payload_size + i] = slice_data[j];			
		}
	}

	f->integrality = !error;
	if (cb)
		cb->handle_frame(*f);
	release_frame(f);

	// clear up
	current_frame_id = -1;
	current_packet_count = 0;
	for(int i=0; i<256; i++)
	{
		packets[i].payload_packet_count = 0;
		memset(&packets[i], 0, sizeof(raw_packet));
	}
		
	return 0;
}
Example #8
0
dc1394error_t
dc1394_juju_capture_setup(platform_camera_t *craw, uint32_t num_dma_buffers,
        uint32_t flags)
{
    struct fw_cdev_create_iso_context create;
    struct fw_cdev_start_iso start_iso;
    dc1394error_t err;
    dc1394video_frame_t proto;
    int i, j, retval;
    dc1394camera_t * camera = craw->camera;

    if (flags & DC1394_CAPTURE_FLAGS_DEFAULT)
        flags = DC1394_CAPTURE_FLAGS_CHANNEL_ALLOC |
            DC1394_CAPTURE_FLAGS_BANDWIDTH_ALLOC;

    craw->flags = flags;

    // if capture is already set, abort
    if (craw->capture_is_set>0)
        return DC1394_CAPTURE_IS_RUNNING;

    // if auto iso is requested, stop ISO (if necessary)
    if (flags & DC1394_CAPTURE_FLAGS_AUTO_ISO) {
        dc1394switch_t is_iso_on;
        dc1394_video_get_transmission(camera, &is_iso_on);
        if (is_iso_on == DC1394_ON) {
            err=dc1394_video_set_transmission(camera, DC1394_OFF);
            DC1394_ERR_RTN(err,"Could not stop ISO!");
        }
    }

    if (capture_basic_setup(camera, &proto) != DC1394_SUCCESS) {
        dc1394_log_error("basic setup failed");
        return DC1394_FAILURE;
    }

    if (flags & (DC1394_CAPTURE_FLAGS_CHANNEL_ALLOC |
                DC1394_CAPTURE_FLAGS_BANDWIDTH_ALLOC)) {
        uint64_t channels_allowed = 0;
        unsigned int bandwidth_units = 0;
        int channel;
        if (flags & DC1394_CAPTURE_FLAGS_CHANNEL_ALLOC)
            channels_allowed = 0xffff;
        if (flags & DC1394_CAPTURE_FLAGS_BANDWIDTH_ALLOC)
            dc1394_video_get_bandwidth_usage (camera, &bandwidth_units);
        err = juju_iso_allocate (craw, channels_allowed,
                bandwidth_units, &craw->capture_iso_resource);
        if (err == DC1394_SUCCESS) {
            channel = craw->capture_iso_resource->channel;
        } else if (err == DC1394_FUNCTION_NOT_SUPPORTED) {
            channel = craw->node_id & 0x3f;
            dc1394_log_warning ("iso allocation not available in this kernel, "
                    "using channel %d...", channel);
        } else {
            dc1394_log_error ("juju: Failed to allocate iso resources");
            return err;
        }

        if (dc1394_video_set_iso_channel (camera, channel) != DC1394_SUCCESS)
            return DC1394_NO_ISO_CHANNEL;
    }

    if (dc1394_video_get_iso_channel (camera, &craw->iso_channel)
            != DC1394_SUCCESS)
        return DC1394_FAILURE;
    dc1394_log_debug ("juju: Receiving from iso channel %d", craw->iso_channel);

    craw->iso_fd = open(craw->filename, O_RDWR);
    if (craw->iso_fd < 0) {
        dc1394_log_error("error opening file: %s", strerror (errno));
        return DC1394_FAILURE;
    }

    create.type = FW_CDEV_ISO_CONTEXT_RECEIVE;
    create.header_size = craw->header_size;
    create.channel = craw->iso_channel;
    create.speed = SCODE_400;
    err = DC1394_IOCTL_FAILURE;
    if (ioctl(craw->iso_fd, FW_CDEV_IOC_CREATE_ISO_CONTEXT, &create) < 0) {
        dc1394_log_error("failed to create iso context");
        goto error_fd;
    }

    craw->iso_handle = create.handle;

    craw->num_frames = num_dma_buffers;
    craw->current = -1;
    craw->buffer_size = proto.total_bytes * num_dma_buffers;
    craw->buffer =
        mmap(NULL, craw->buffer_size, PROT_READ | PROT_WRITE , MAP_SHARED, craw->iso_fd, 0);
    err = DC1394_IOCTL_FAILURE;
    if (craw->buffer == MAP_FAILED)
        goto error_fd;

    err = DC1394_MEMORY_ALLOCATION_FAILURE;
    craw->frames = malloc (num_dma_buffers * sizeof *craw->frames);
    if (craw->frames == NULL)
        goto error_mmap;

    for (i = 0; i < num_dma_buffers; i++) {
        err = init_frame(craw, i, &proto);
        if (err != DC1394_SUCCESS) {
            dc1394_log_error("error initing frames");
            break;
        }
    }
    if (err != DC1394_SUCCESS) {
        for (j = 0; j < i; j++)
            release_frame(craw, j);
        goto error_mmap;
    }

    for (i = 0; i < num_dma_buffers; i++) {
        err = queue_frame(craw, i);
        if (err != DC1394_SUCCESS) {
            dc1394_log_error("error queuing");
            goto error_frames;
        }
    }

    // starting from here we use the ISO channel so we set the flag in
    // the camera struct:
    craw->capture_is_set = 1;

    start_iso.cycle   = -1;
    start_iso.tags = FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS;
    start_iso.sync = 1;
    start_iso.handle = craw->iso_handle;
    retval = ioctl(craw->iso_fd, FW_CDEV_IOC_START_ISO, &start_iso);
    err = DC1394_IOCTL_FAILURE;
    if (retval < 0) {
        dc1394_log_error("error starting iso");
        goto error_frames;
    }

    // if auto iso is requested, start ISO
    if (flags & DC1394_CAPTURE_FLAGS_AUTO_ISO) {
        err=dc1394_video_set_transmission(camera, DC1394_ON);
        DC1394_ERR_RTN(err,"Could not start ISO!");
        craw->iso_auto_started=1;
    }

    return DC1394_SUCCESS;

error_frames:
    for (i = 0; i < num_dma_buffers; i++)
        release_frame(craw, i);
error_mmap:
    munmap(craw->buffer, craw->buffer_size);
error_fd:
    close(craw->iso_fd);

    return err;
}
Example #9
0
/**
 * Reciving singlas from ethernet controller -
 * TX - transmited packet
 * RX - recived packet
 * LinkChange - Connected/Diconncted Ethernet Cable
 *
 */
void ethernet_interrupts_simple()
{
    frame *curr_frame = 0;
	int filtered;
	uint8_t interruption =ior(ISR);    //which interruption

    packet_num++;

    iow(IMR, 0);
 //   iow(IMR, PAR_set);
   // printf("ISR 0x%2X \n",interruption);

    if( interruption & 0x01 )      //RX
    {

    	iow(ISR,0x01);
    	curr_frame = get_free_frame();
    	if(curr_frame == 0)
    	{
    		return; //ERROR no more free frames
    	}

    	aaa=ReceivePacket(curr_frame->f_data,&curr_frame->f_len);
    	if(aaa == 0)
    	{
        	filtered =   filter_packiets(curr_frame->f_data,curr_frame->f_len);

        	if (filtered == 0)
        	{
        		printf(" RX:UDP \n");
        		add_rx_frame(curr_frame);

        	}
        	else if (filtered == 10) //arp
        	{
        		printf(" RX:ARP \n");
        		add_rx_frame(curr_frame);
        	}
        	else
        	{
    			release_frame(curr_frame);
    		}
        	curr_frame = 0;

    	}
    	else
    	{
    		printf("%s Recived Bad Frame \n",__FUNCTION__);

    		release_frame(curr_frame);
    		curr_frame = 0;
    	}

    	/* ethernet_header *tmp = (ethernet_header *) RXT;
    	 ether_addr adres =  { 0x01, 0x60, 0x6E, 0x11, 0x01, 0x1F  };


    	 tmp->eth_src_addr = adres;
         TransmitPacket(RXT,rx_len);*/
    }


    if(interruption & 0x02)    //TX
    {
    	iow(ISR,0x02);
    	tx_control = 0;

    }
    if(interruption & 0x20)    //LinkChange
    {
    	iow(ISR,0x20);

/*    	iow(0x00,0x01);  // software reset
    	usleep(10);
    	  enable interrupts to activate DM9000 ~on
    	  iow(IMR, INTR_set2);    IMR REG. FFH PAR=1 only, or + PTM=1& PRM=1 enable RxTx interrupts
    	  iow(0xFF, 0x80);
    	   enable RX (Broadcast/ ALL_MULTICAST) ~go
    	  iow(RCR , RCR_set | RX_ENABLE | PASS_MULTICAST);   RCR REG. 05 RXEN Bit [0] = 1 to enable the RX machine/ filter */

    	//printf(" LinkCHange \n");
    	if(link_control == 0)
    		link_control = 1;
    	else
    		link_control = 0;
    }




    iow(IMR, INTR_set2);
}
Example #10
0
/**
 * Main processing loop
 */
int ethernet_main_loop()
{
	frame * my_frame =0 ;
	ethernet_header * eth =0;
	int a=0;
	printf("Info:Inited_app\n");
	  while (1)
	  {
	  //  TransmitPacket(TXT,0x40);
		  if(link_control == 0) // no ethernet connection
			  continue;
		  else
		  {
			  my_frame = get_rx_frame();
			  if(my_frame != 0)
			  {
				  eth = my_frame->f_data;
				  if(eth->ether_type == 0x0608)
				  {
					  printf("Info:ARP response\n");
					  arp_response(my_frame);
				  }
				  else if(eth->ether_type == 0x0008)
				  {
					  printf("Info:Frame to process\n");
					  manage_ncp_loop(my_frame->f_data,my_frame->f_len);
				  }
				  my_frame->f_len = 0;
				  release_frame(my_frame);
				  my_frame = 0;
			  }
			  else
				usleep(100);
		  }

		 if (tx_control == 0)
		 {
			 a++;
			 //a - zlicza pakiety
			 //tx_control - prosty mutex na wysy³anie pakietu, zwalniany gdy karta sieciowa przesle sygna³ potwierdzaj¹cy wys³anie pakietu

			// tx_control = 1;
			 //send_packiet();
		 }

		  if(a%100000 == 0)
		  {
			  printf("Working\n");

		  }
	/*
		  my_frame = get_rx_frame();
		  if (my_frame != NULL)
		  {
			  printf( "przetwarzam ramke ! \n");
			  release_frame(my_frame);
			  my_frame = 0;
		  }
	*/


		  //TransmitPacket(TXT,0x40);

	  }
	  return 0;
}
Example #11
0
void rs_release_frame(rs_device * device, rs_frame_ref * frame, rs_error ** error) try
{
    VALIDATE_NOT_NULL(device);
    VALIDATE_NOT_NULL(frame);
    device->release_frame(frame);
}
Example #12
0
/* attach a frame to the given window/channel for display
 * if the requested channel does not exist, it is created;
 * it ref's the frame, so the frame should be released after
 * frame_to_channel is called
 */
int frame_to_channel(struct ccd_frame *fr, GtkWidget *window, char *chname)
{
	struct map_cache *cache;
	struct image_channel *channel;
	struct map_geometry *geom;
	struct wcs *wcs;
	GtkDrawingArea *darea;

        /* get the old stuff from the window */
	cache = g_object_get_data(G_OBJECT(window), "map_cache");
	channel = g_object_get_data(G_OBJECT(window), chname);
	geom = g_object_get_data(G_OBJECT(window), "geometry");
	darea = g_object_get_data(G_OBJECT(window), "image");
	wcs = g_object_get_data(G_OBJECT(window), "wcs_of_window");
        /* now update them and create if necessary */

	if ((fr->magic & FRAME_VALID_RGB) == 0)
		bayer_interpolate(fr);

	if (cache == NULL) {
		int w=100, h=100, x, y, d;
		if (window->window)
			gdk_window_get_geometry(window->window, &x, &y, &w, &h, &d);

		if (fr->magic & FRAME_VALID_RGB)
			cache = new_map_cache((w + MAX_ZOOM) * (h + MAX_ZOOM),
					      MAP_CACHE_RGB);
		else
			cache = new_map_cache((w + MAX_ZOOM) * (h + MAX_ZOOM),
					      MAP_CACHE_GRAY);
		g_object_set_data_full(G_OBJECT(window), "map_cache",
					 cache, (GDestroyNotify)release_map_cache);
	}
	cache->cache_valid = 0;

	if (geom == NULL) {
		geom = new_map_geometry();
		g_object_set_data_full(G_OBJECT(window), "geometry",
					 geom, (GDestroyNotify)release_map_geometry);
	}

	if (channel == NULL) {
		channel = new_image_channel();
		g_object_set_data_full(G_OBJECT(window), chname,
					 channel, (GDestroyNotify)release_image_channel);
		get_frame(fr);
		channel->fr = fr;
		if (fr->magic & FRAME_VALID_RGB)
			channel->color = 1;
	} else { /* replace the frame in the current channel */
		release_frame(channel->fr);
		get_frame(fr);
		channel->fr = fr;
		if (fr->magic & FRAME_VALID_RGB)
			channel->color = 1;
	}

	/* set default cuts */
	if (!fr->stats.statsok)
		frame_stats(fr);
	if (fr->stats.statsok)
		set_default_channel_cuts(channel);

	if (wcs == NULL) {
		wcs = wcs_new();
		g_object_set_data_full(G_OBJECT(window), "wcs_of_window",
					 wcs, (GDestroyNotify)wcs_release);
		wcs_from_frame(fr, wcs);
	} else {
		struct wcs *nwcs;
		nwcs = wcs_new();
		wcs_from_frame(fr, nwcs);
		if (nwcs->wcsset >= WCS_INITIAL) {
			memcpy(wcs, nwcs, sizeof (struct wcs));
			wcs->flags &= ~WCS_HINTED;
		} else {
			wcs->wcsset = WCS_INITIAL;
			wcs->flags |= WCS_HINTED;
		}
		wcs_release(nwcs);
	}
	wcsedit_refresh(window);

	channel->channel_changed = 1;

	if (darea) {
		int zoom_in = 1;
		int zoom_out = 1;
		if (geom->zoom > 1.0 && geom->zoom <= 16.0) {
			zoom_in = floor(geom->zoom + 0.5);
		} else if (geom->zoom < 1.0 && geom->zoom >= (1.0 / 16.0)) {
			zoom_out = floor(1.0 / geom->zoom + 0.5);
		}
		geom->width = fr->w;
		geom->height = fr->h;

		set_darea_size(window, geom, 0.5, 0.5);

	}
	gtk_window_set_title (GTK_WINDOW (window), fr->name);
	remove_stars(window, TYPE_MASK_FRSTAR, 0);

	stats_cb(window, 0);
	show_zoom_cuts(window);
	gtk_widget_queue_draw(GTK_WIDGET(window));
	return 0;
}
Example #13
0
 void reset() noexcept
 {
     release_frame();
     _ptr = nullptr;
 }
Example #14
0
 ~coroutine()
 {
     release_frame();
 }