Example #1
0
	void USARTRead(){
	   // poll for data available
	  //while ( (UCSR0A & _BV(RXC0)) == 0 );
        
		ring_data_t temp = UDR0;
    	ring_insert((Ring_t*)&uart_ring, temp);
		
	}
Example #2
0
void ring_create_node(char *node_id) {
  Node *node = NULL;
  /* @TODO */
  printf("Shouldn't be here\n");
  
  D2("Creating Node:", node_id);
  
  node = node_init(node_id);
  
  /* @TODO: check node_id doesn't exist */
  
  ring_insert(node);
}
Example #3
0
File: tesc.c Project: bytemine/ut
/*
 *	tesc_enq_wq()
 *
 *	enqueues the message 'm' for output via 'ch'
 *
 *	if queue was empty and channel requests
 *	stall-detection, record time of insertion
 *	in the respective fdio.
 *
 *	returns 0 on success, -1 on error
 */
int tesc_enq_wq (chn_t *ch, msg_t *m)
{
int fd = ch->fd;
struct fdio *fdio;

    if (fd < 0 || fd >= FDMAPSIZ) {
	/* illegal fd */
	return -1;
    }

#ifdef DEBUG
    if (! (ch->flags & CHN_F_WR)) {
	/* not open for writing */
	return -1;
    }
#endif

    if (! schdat.fdio[fd]) {
	/* allocate fdio structure */
	schdat.fdio[fd] = new_fdio (ch);		/* may exit */
	/* add it to the list of active fdios */
	ring_insert (schdat.fdio[fd]);			/* may exit */
    }

    if (!m) 		/* used by mlpx_init to (only) create fdio */
	return 0;

    /* finally append to 'wq' and record time if needed */
    fdio = schdat.fdio[fd];

    if (ch->timeout && !fdio->wq) {
	/* stall-detection timeout is set and queue was empty: record time */
	if (gettimeofday (&schdat.fdio[fd]->ts, 0) == -1) {
	    mlpx_printf (CHN_MSG, MF_ERR,
		"tesc_enq_wq(): cannot get current time: %s\n",
							strerror (errno));
	}
    }

    if (!fdio->wq) {
	fdio->wq = m;
	fdio->wt = m;
    } else {
	fdio->wt->next = m;
	fdio->wt = m;
    }

    return 0;
}
Example #4
0
File: tesc.c Project: bytemine/ut
/*
 *	tesc_add_reader()
 *
 *	register 'rf' to be called with arg 'b' whenever
 *	data is available for read on 'ch->fd'
 *
 *	buffer 'b' need not be kept elsewhere since
 *	it will be deleted in 'tesc_del_reader()'
 *
 *	returns 0 on success, -1 on error
 */
int tesc_add_reader (chn_t *ch, bfifun_t rf, buf_t *b)
{
int fd = ch->fd;

    if (fd < 0 || fd >= FDMAPSIZ) {
	/* illegal fd */
	return -1;
    }

    if (schdat.fdio[fd]) {
	/* fdio structure already exists */
	if (schdat.fdio[fd]->rf) {
	    /* huh, reader exists already */
	    return -1;
	}
    } else {
	/* allocate fdio structure */
	schdat.fdio[fd] = new_fdio (ch);		/* may exit */
    }

#ifdef DEBUG
    if (! (ch->flags & CHN_F_RD)) {
	/* not open for reading */
	if (schdat.fdio[fd]->kf) {
	    schdat.fdio[fd]->rf = 0;
	    schdat.fdio[fd]->rb = 0;
	}
	return -1;
    }
#endif

    /* store func and buf */
    schdat.fdio[fd]->rf = rf;
    schdat.fdio[fd]->rb = b;

    /* add it to the list of active fdios */
    ring_insert (schdat.fdio[fd]);			/* may exit */

    return 0;
}