soc/picorv32/test/badger_lwip/liblwip/badgerif.c
/**
 * This function should do the actual transmission of the packet. The packet is
 * contained in the pbuf that is passed to the function. This pbuf
 * might be chained.
 *
 * @param netif the lwip network interface structure for this ethernetif
 * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
 * @return ERR_OK if the packet could be sent
 *         an err_t value if the packet couldn't be sent
 *
 * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
 *       strange results. You might consider waiting for space in the DMA queue
 *       to become available since the stack doesn't retry to send a packet
 *       dropped because of memory failure (except for the TCP timers).
 */
This function should do the actual transmission of the packet. The packet is
contained in the pbuf that is passed to the function. This pbuf
might be chained.

@param netif the lwip network interface structure for this ethernetif
@param p the MAC packet to send
@return ERR_OK if the packet could be sent
an err_t value if the packet couldn't be sent

@note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
strange results. You might consider waiting for space in the DMA queue
to become available since the stack doesn't retry to send a packet
dropped because of memory failure (except for the TCP timers).
This function should do the actual transmission of the packet . The packet is contained in the pbuf that is passed to the function . This pbuf might be chained . @param netif the lwip network interface structure for this ethernetif @param p the MAC packet to send @return ERR_OK if the packet could be sent an err_t value if the packet couldn ' t be sent @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to strange results . You might consider waiting for space in the DMA queue to become available since the stack doesn ' t retry to send a packet dropped because of memory failure ( except for the TCP timers ) .
static err_t badger_output(struct netif *netif, struct pbuf *p)
{
    LWIP_UNUSED_ARG(netif);
    struct pbuf *q;
    if (GET_SFR1(BASE_BADGER_SFR, 0, BIT_BADGER_TX_START)) {
        while(!GET_SFR1(BASE_BADGER_SFR, 0, BIT_BADGER_TX_DONE));
        SET_SFR1(BASE_BADGER_SFR, 0, BIT_BADGER_TX_START, 0);
    }
    SET_REG16(BASE_BADGER_SFR, 0);
    uint8_t *buf_tx = (uint8_t*)(BASE_BADGER_TX + 2);
    unsigned txlen = 0;
    q = p;
    while(q) {
        memcpy(buf_tx, q->payload, q->len);
        buf_tx += q->len;
        txlen += q->len;
        if(q->tot_len != q->len)
            q = q->next;
        else
            q = NULL;
    }
    buf_tx = (uint8_t*)(BASE_BADGER_TX);
    buf_tx[0] = txlen;
    buf_tx[1] = txlen >> 8;
    SET_SFR1(BASE_BADGER_SFR, 0, BIT_BADGER_TX_START, 1);
    return ERR_OK;
}
static err_t badger_output ( struct netif * netif , struct pbuf * p ) { LWIP_UNUSED_ARG ( netif ) ; struct pbuf * q ; if ( GET_SFR1 ( BASE_BADGER_SFR , 0 , BIT_BADGER_TX_START ) ) { while ( ! GET_SFR1 ( BASE_BADGER_SFR , 0 , BIT_BADGER_TX_DONE ) ) ; SET_SFR1 ( BASE_BADGER_SFR , 0 , BIT_BADGER_TX_START , 0 ) ; } SET_REG16 ( BASE_BADGER_SFR , 0 ) ; uint8_t * buf_tx = ( uint8_t * ) ( BASE_BADGER_TX + 2 ) ; unsigned txlen = 0 ; q = p ; while ( q ) { memcpy ( buf_tx , q -> payload , q -> len ) ; buf_tx += q -> len ; txlen += q -> len ; if ( q -> tot_len != q -> len ) q = q -> next ; else q = NULL ; } buf_tx = ( uint8_t * ) ( BASE_BADGER_TX ) ; buf_tx [ 0 ] = txlen ; buf_tx [ 1 ] = txlen >> 8 ; SET_SFR1 ( BASE_BADGER_SFR , 0 , BIT_BADGER_TX_START , 1 ) ; return ERR_OK ; }
This function should do the actual transmission of the packet.
This function should do the actual transmission of the packet .
// Wait for eventual previous TX to finish // start_addr refers to an offset to BASE_BADGER_TX in [16 bit words] // Write data to memory where badger will expect it // first 16 bit word is packet length (will be set later) // pbuf is a linked list, go trough each item // and copy its payload into buf_tx // first 16 bit word is packet length // Put the packet on the wire