Esempio n. 1
0
/*
 *	Remove the top element, or object.
 */
int fr_heap_extract(fr_heap_t *hp, void *data)
{
	int child, parent;
	int max;

	if (!hp || (hp->num_elements == 0)) return 0;

	max = hp->num_elements - 1;

	/*
	 *	Extract element.  Default is the first one.
	 */
	if (!data) {
		parent = 0;

	} else {		/* extract from the middle */
		if (!hp->offset) return 0;

		parent = *((int *)(((uint8_t *)data) + hp->offset));

		/*
		 *	Out of bounds.
		 */
		if (parent < 0 || parent >= hp->num_elements) return 0;
	}

	RESET_OFFSET(hp, parent);
	child = HEAP_LEFT(parent);
	while (child <= max) {
		/*
		 *	Maybe take the right child.
		 */
		if ((child != max) &&
		    (hp->cmp(hp->p[child + 1], hp->p[child]) < 0)) {
			child = child + 1;
		}
		hp->p[parent] = hp->p[child];
		SET_OFFSET(hp, parent);
		parent = child;
		child = HEAP_LEFT(child);
	}
	hp->num_elements--;

	/*
	 *	We didn't end up at the last element in the heap.
	 *	This element has to be re-inserted.
	 */
	if (parent != max) {
		/*
		 *	Fill hole with last entry and bubble up,
		 *	reusing the insert code
		 */
		hp->p[parent] = hp->p[max];
		return fr_heap_bubble(hp, parent);
	}

	return 1;
}
Esempio n. 2
0
static int
aw_reset_assert(device_t dev, intptr_t id, bool reset)
{
	struct aw_reset_softc *sc;
	uint32_t reg_value;

	sc = device_get_softc(dev);

	mtx_lock(&sc->mtx);
	reg_value = RESET_READ(sc, RESET_OFFSET(id));
	if (reset)
		reg_value &= ~(1 << RESET_SHIFT(id));
	else
		reg_value |= (1 << RESET_SHIFT(id));
	RESET_WRITE(sc, RESET_OFFSET(id), reg_value);
	mtx_unlock(&sc->mtx);

	return (0);
}
Esempio n. 3
0
static int
aw_reset_is_asserted(device_t dev, intptr_t id, bool *reset)
{
	struct aw_reset_softc *sc;
	uint32_t reg_value;

	sc = device_get_softc(dev);

	mtx_lock(&sc->mtx);
	reg_value = RESET_READ(sc, RESET_OFFSET(id));
	mtx_unlock(&sc->mtx);

	*reset = (reg_value & (1 << RESET_SHIFT(id))) != 0 ? false : true;

	return (0);
}
Esempio n. 4
0
/*
 * remove top element from heap, or obj if obj != NULL
 */
void
heap_extract(struct dn_heap *h, void *obj)
{
    int child, father, max = h->elements - 1;

    if (max < 0) {
        printf("--- %s: empty heap 0x%p\n", __FUNCTION__, h);
        return;
    }
    if (obj == NULL)
        father = 0; /* default: move up smallest child */
    else { /* extract specific element, index is at offset */
        if (h->ofs <= 0)
            panic("%s: extract from middle not set on %p\n",
                  __FUNCTION__, h);
        father = *((int *)((char *)obj + h->ofs));
        if (father < 0 || father >= h->elements) {
            panic("%s: father %d out of bound 0..%d\n",
                  __FUNCTION__, father, h->elements);
        }
    }
    /*
     * below, father is the index of the empty element, which
     * we replace at each step with the smallest child until we
     * reach the bottom level.
     */
    // XXX why removing RESET_OFFSET increases runtime by 10% ?
    RESET_OFFSET(h, father);
    while ( (child = HEAP_LEFT(father)) <= max ) {
        if (child != max &&
                DN_KEY_LT(h->p[child+1].key, h->p[child].key) )
            child++; /* take right child, otherwise left */
        h->p[father] = h->p[child];
        SET_OFFSET(h, father);
        father = child;
    }
    h->elements--;
    if (father != max) {
        /*
         * Fill hole with last entry and bubble up,
         * reusing the insert code
         */
        h->p[father] = h->p[max];
        heap_insert(h, father, NULL);
    }
}
Esempio n. 5
0
	u8 phy_addr;
	u8 offset;
} PHY_cfg;

typedef struct {
	u8 link:1,speed:2,duplex:3,changed:1;
	u8 length;
	u32 rx_err;
	u32 link_time;
} PHY;

void print(char *str);

static XGpio gpio;
static PHY_cfg phyCfg[3]={
		{MDC_OFFSET(0),MDIO_OFFSET(0),LINK_OFFSET(0),SPEED_OFFSET(0),DUPLEX_OFFSET(0),RESET_OFFSET(0),PHY0_PADDR},
		{MDC_OFFSET(1),MDIO_OFFSET(1),LINK_OFFSET(1),SPEED_OFFSET(1),DUPLEX_OFFSET(1),RESET_OFFSET(1),PHY1_PADDR},
		{MDC_OFFSET(2),MDIO_OFFSET(2),LINK_OFFSET(2),SPEED_OFFSET(2),DUPLEX_OFFSET(2),RESET_OFFSET(2),PHY2_PADDR},
};
static PHY phy[3];

static u8 decipher_key[8] = DECIPHER_KEY;

void delay(u32 d)
{
	while(d--);
}

void IO_SetDirection(u8 bit, u8 dir)
{
	u32 mask;