/** \brief main compare functions
 */
int netif_stat_t::compare(const netif_stat_t &other)	const throw()
{
	// handle the case where at least one is null
	if(  is_null() && !other.is_null() )		return -1;
	if( !is_null() &&  other.is_null() )		return +1;
	if(  is_null() &&  other.is_null() )		return  0;
	// NOTE: here both are NOT null

	// compare the name
	if( name() < other.name() )			return -1;
	if( name() > other.name() )			return +1;
	// NOTE: here both name are equal

	// compare the capture_date
	if( capture_date() < other.capture_date() )	return -1;
	if( capture_date() > other.capture_date() )	return +1;
	// NOTE: here both capture_date are equal

	// compare the rx_byte
	if( rx_byte() < other.rx_byte() )		return -1;
	if( rx_byte() > other.rx_byte() )		return +1;
	// NOTE: here both rx_byte are equal

	// compare the tx_byte
	if( tx_byte() < other.tx_byte() )		return -1;
	if( tx_byte() > other.tx_byte() )		return +1;
	// NOTE: here both tx_byte are equal

	// here both are considered equal
	return 0;
}
unsigned int memread(void) 
{ 
    start_bit(); 
    tx_byte(0x00);
    tx_byte(0x07); 
    start_bit(); 
    tx_byte(0x01); 
    DataL=RX_byte(0); 
    DataH=RX_byte(0);
    Pecreg=RX_byte(1); 
    STOP_bit(); 
    return(DataH*256+DataL); 
} 
Exemple #3
0
/************************************************************************
 * void udp_send(WORD datalength)
 * This function is called by the application to send a UDP
 * packet. Values from global variables, common memory
 * space and the passed data length are used.
 * Optionally, a pseudo header is constructed and the UDP
 * checksum calculated.
 ***********************************************************************/
void udp_send(WORD datalength, BYTE ephemeral)
{
	WORD cssum;
	
	ipstat.udptx++;
	/* total size of IP datagram is the size of IP header */
	/* plus UDP header, plus UDP data */
	ip.totallen=IPSIZE+UDPHSIZE+datalength;
	/* place IP header and start of trasnmit buffer */
	txpos=0;
	ip_header(PROTUDP);
	/* use an ephemeral source port, this depends on the
	 * application, and must be specified when calling
	 * the function */
	if (ephemeral) tx_word(local_port());
	else tx_word(udph.dest);
	/* destination port, as source port from incoming packet */
	tx_word(udph.src);
	/* UDP length, header length plus data length */
	tx_word(UDPHSIZE+datalength);
	/* UDP checksum */
	tx_word(0x00);
	
	/* UDP checksumming is specified at compile time
	 * if checksumming is disabled, a zero value is sent
	 * otherwise the pseudo header is added and checksummed
	 * but NOT sent */
	#ifdef UPDCHECKSUM
		txpos+=datalength;
		tx_byte(IP1);
		tx_byte(IP2);
		tx_byte(IP3);
		tx_byte(IP4);
		tx_byte(ip.destaddr[0]);
		tx_byte(ip.destaddr[1]);
		tx_byte(ip.destaddr[2]);
		tx_byte(ip.destaddr[3]);
		tx_byte(0x00);
		tx_byte(PROTUDP);
		tx_word(10+udpdatal);
		
		cssum = chksm(&txbuffer[20],8+datalength+12);
		put_checksum(cssum,&txbuffer[IPSIZE+6]);
	#endif
	
	/* call SLIP to send out the packet */
	slip_send(txbuffer,IPSIZE+UDPHSIZE+datalength);
}
Exemple #4
0
int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args)
{
	int len;
	unsigned long long num;
	int i, base;
	const char *s;

	int flags;		/* flags to number() */

	int field_width;	/* width of output field */
	int precision;		/* min. # of digits for integers; max
				   number of chars for from string */
	int qualifier;		/* 'h', 'l', or 'L' for integer fields */

	int count;

	for (count=0; *fmt ; ++fmt) {
		if (*fmt != '%') {
			tx_byte(*fmt), count++;
			continue;
		}

		/* process flags */
		flags = 0;
		repeat:
			++fmt;		/* this also skips first '%' */
			switch (*fmt) {
				case '-': flags |= LEFT; goto repeat;
				case '+': flags |= PLUS; goto repeat;
				case ' ': flags |= SPACE; goto repeat;
				case '#': flags |= SPECIAL; goto repeat;
				case '0': flags |= ZEROPAD; goto repeat;
				}

		/* get field width */
		field_width = -1;
		if (is_digit(*fmt))
			field_width = skip_atoi(&fmt);
		else if (*fmt == '*') {
			++fmt;
			/* it's the next argument */
			field_width = va_arg(args, int);
			if (field_width < 0) {
				field_width = -field_width;
				flags |= LEFT;
			}
		}

		/* get the precision */
		precision = -1;
		if (*fmt == '.') {
			++fmt;
			if (is_digit(*fmt))
				precision = skip_atoi(&fmt);
			else if (*fmt == '*') {
				++fmt;
				/* it's the next argument */
				precision = va_arg(args, int);
			}
int rf_default_simple_tx(unsigned char* buffer, size_t num_bytes, unsigned int pin) {
	size_t i;
	int num_transmitted = 0;
	for (i = 0; i < num_bytes; i++) {
		tx_byte(buffer[i], pin);	
		num_transmitted++;
	}
	return num_transmitted;
}
Exemple #6
0
nrfx_err_t nrfx_uart_tx(nrfx_uart_t const * p_instance,
                        uint8_t const *     p_data,
                        size_t              length)
{
    uart_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx];
    NRFX_ASSERT(p_cb->state == NRFX_DRV_STATE_INITIALIZED);
    NRFX_ASSERT(p_data);
    NRFX_ASSERT(length > 0);

    nrfx_err_t err_code;

    if (nrfx_uart_tx_in_progress(p_instance))
    {
        err_code = NRFX_ERROR_BUSY;
        NRFX_LOG_WARNING("Function: %s, error code: %s.",
                         __func__,
                         NRFX_LOG_ERROR_STRING_GET(err_code));
        return err_code;
    }
    p_cb->tx_buffer_length = length;
    p_cb->p_tx_buffer      = p_data;
    p_cb->tx_counter       = 0;
    p_cb->tx_abort         = false;

    NRFX_LOG_INFO("Transfer tx_len: %d.", p_cb->tx_buffer_length);
    NRFX_LOG_DEBUG("Tx data:");
    NRFX_LOG_HEXDUMP_DEBUG(p_cb->p_tx_buffer,
                           p_cb->tx_buffer_length * sizeof(p_cb->p_tx_buffer[0]));

    err_code = NRFX_SUCCESS;

    nrf_uart_event_clear(p_instance->p_reg, NRF_UART_EVENT_TXDRDY);
    nrf_uart_task_trigger(p_instance->p_reg, NRF_UART_TASK_STARTTX);

    tx_byte(p_instance->p_reg, p_cb);

    if (p_cb->handler == NULL)
    {
        if (!tx_blocking(p_instance->p_reg, p_cb))
        {
            // The transfer has been aborted.
            err_code = NRFX_ERROR_FORBIDDEN;
        }
        else
        {
            // Wait until the last byte is completely transmitted.
            while (!nrf_uart_event_check(p_instance->p_reg, NRF_UART_EVENT_TXDRDY))
            {}
            nrf_uart_task_trigger(p_instance->p_reg, NRF_UART_TASK_STOPTX);
        }
        p_cb->tx_buffer_length = 0;
    }

    NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code));
    return err_code;
}
Exemple #7
0
/************************************************************************
 * void tftp()
 * Simple application layer server to return data
 * The only functionality provided is reading, and only one 'file'.
 * this function doesn't need to know anything about buffer
 * positions, it simply uses functions provided by the IP layer.
 ***********************************************************************/
void tftp()
{
	WORD opcode;
	/* read the operation code */
	copy_rx_word(&opcode);
	/* read request */
	if (opcode == TFTP_READ) {
		/* check the requested filename is 'stats' */
		if (rx_byte() == 's' && rx_byte() == 't' && rx_byte() == 'a' &&
			rx_byte() == 't' && rx_byte() == 's' && rx_byte() == 0x00)
		{
			tx_word(TFTP_DATA);	/* op code */
			tx_word(0x0001);	/* block number */
			q_string("   IP Statistics   \n\n",21);
			q_string("Received:\t",10);
			q_num(ipstat.rxpackets);		
			q_string("\nTransmitted:\t",14);
			q_num(ipstat.txpackets);
			q_string("\nDropped:\t",10);
			q_num(ipstat.dropped);
			q_string("\n\n",2);
		}
		/* requested a different file, not found */
		else {
			tx_word(TFTP_ERR);
			tx_word(0x0001);
			q_string("File Not Found.",15);
			tx_byte(0x00);
		}
		udp_send(txpos-IPSIZE-UDPHSIZE,1);
	}
	/* write request, send error code and message */
	else if (opcode == TFTP_WRITE) {
		tx_word(TFTP_ERR);
		tx_word(0x0002);
		q_string("Access Violation.",17);
		tx_byte(0x00);
		udp_send(txpos-IPSIZE-UDPHSIZE,1);
	}
}
/** \brief convert the object to a string
 */
std::string	netif_stat_t::to_string()				const throw()
{
	std::ostringstream	oss;
	// handle the null case
	if( is_null() )	return "null";
	// build the string to return
	oss        << "name="		<< name();
	oss << " " << "capture_date="	<< capture_date();
	oss << " " << "rx_byte="	<< rx_byte();
	oss << " " << "tx_byte="	<< tx_byte();
	
	// return the just built string
	return oss.str();
}
Exemple #9
0
static void c3_tx(uint8_t cmd, uint8_t a1, uint8_t a2, uint8_t a3, uint8_t a4)
{
	tx_byte(0xAA);
	tx_byte(cmd);
	tx_byte(a1);
	tx_byte(a2);
	tx_byte(a3);
	tx_byte(a4);
}
Exemple #10
0
static bool tx_blocking(NRF_UART_Type * p_uart, uart_control_block_t * p_cb)
{
    while (p_cb->tx_counter < p_cb->tx_buffer_length)
    {
        // Wait until the transmitter is ready to accept a new byte.
        // Exit immediately if the transfer has been aborted.
        while (!nrf_uart_event_check(p_uart, NRF_UART_EVENT_TXDRDY))
        {
            if (p_cb->tx_abort)
            {
                return false;
            }
        }

        tx_byte(p_uart, p_cb);
    }

    return true;
}
Exemple #11
0
IRAM void miot_uart_dev_dispatch_tx_top(struct miot_uart_state *us) {
  int uart_no = us->uart_no;
  cs_rbuf_t *txb = &us->tx_buf;
  uint32_t txn = 0;
  /* TX */
  if (txb->used > 0) {
    while (txb->used > 0) {
      int i;
      uint8_t *data;
      uint16_t len;
      int tx_av = us->cfg->tx_fifo_full_thresh - esp_uart_tx_fifo_len(uart_no);
      if (tx_av <= 0) break;
      len = cs_rbuf_get(txb, tx_av, &data);
      for (i = 0; i < len; i++, data++) {
        tx_byte(uart_no, *data);
      }
      txn += len;
      cs_rbuf_consume(txb, len);
    }
    us->stats.tx_bytes += txn;
  }
}
Exemple #12
0
static void uart_irq_handler(NRF_UART_Type *        p_uart,
                             uart_control_block_t * p_cb)
{
    if (nrf_uart_int_enable_check(p_uart, NRF_UART_INT_MASK_ERROR) &&
        nrf_uart_event_check(p_uart, NRF_UART_EVENT_ERROR))
    {
        nrfx_uart_event_t event;
        nrf_uart_event_clear(p_uart, NRF_UART_EVENT_ERROR);
        NRFX_LOG_DEBUG("Event: %s.", EVT_TO_STR(NRF_UART_EVENT_ERROR));
        nrf_uart_int_disable(p_uart, NRF_UART_INT_MASK_RXDRDY |
                                     NRF_UART_INT_MASK_ERROR);
        if (!p_cb->rx_enabled)
        {
            nrf_uart_task_trigger(p_uart, NRF_UART_TASK_STOPRX);
        }
        event.type                   = NRFX_UART_EVT_ERROR;
        event.data.error.error_mask  = nrf_uart_errorsrc_get_and_clear(p_uart);
        event.data.error.rxtx.bytes  = p_cb->rx_buffer_length;
        event.data.error.rxtx.p_data = p_cb->p_rx_buffer;

        // Abort transfer.
        p_cb->rx_buffer_length = 0;
        p_cb->rx_secondary_buffer_length = 0;

        p_cb->handler(&event,p_cb->p_context);
    }
    else if (nrf_uart_int_enable_check(p_uart, NRF_UART_INT_MASK_RXDRDY) &&
             nrf_uart_event_check(p_uart, NRF_UART_EVENT_RXDRDY))
    {
        rx_byte(p_uart, p_cb);
        if (p_cb->rx_buffer_length == p_cb->rx_counter)
        {
            if (p_cb->rx_secondary_buffer_length)
            {
                uint8_t * p_data     = p_cb->p_rx_buffer;
                size_t    rx_counter = p_cb->rx_counter;

                // Switch to secondary buffer.
                p_cb->rx_buffer_length = p_cb->rx_secondary_buffer_length;
                p_cb->p_rx_buffer = p_cb->p_rx_secondary_buffer;
                p_cb->rx_secondary_buffer_length = 0;
                p_cb->rx_counter = 0;
                rx_done_event(p_cb, rx_counter, p_data);
            }
            else
            {
                if (!p_cb->rx_enabled)
                {
                    nrf_uart_task_trigger(p_uart, NRF_UART_TASK_STOPRX);
                }
                nrf_uart_int_disable(p_uart, NRF_UART_INT_MASK_RXDRDY |
                                             NRF_UART_INT_MASK_ERROR);
                p_cb->rx_buffer_length = 0;
                rx_done_event(p_cb, p_cb->rx_counter, p_cb->p_rx_buffer);
            }
        }
    }

    if (nrf_uart_event_check(p_uart, NRF_UART_EVENT_TXDRDY))
    {
        if (p_cb->tx_counter < p_cb->tx_buffer_length &&
            !p_cb->tx_abort)
        {
            tx_byte(p_uart, p_cb);
        }
        else
        {
            nrf_uart_event_clear(p_uart, NRF_UART_EVENT_TXDRDY);
            if (p_cb->tx_buffer_length)
            {
                tx_done_event(p_cb, p_cb->tx_buffer_length);
            }
        }
    }

    if (nrf_uart_event_check(p_uart, NRF_UART_EVENT_RXTO))
    {
        nrf_uart_event_clear(p_uart, NRF_UART_EVENT_RXTO);

        // RXTO event may be triggered as a result of abort call. In th
        if (p_cb->rx_enabled)
        {
            nrf_uart_task_trigger(p_uart, NRF_UART_TASK_STARTRX);
        }
        if (p_cb->rx_buffer_length)
        {
            p_cb->rx_buffer_length = 0;
            rx_done_event(p_cb, p_cb->rx_counter, p_cb->p_rx_buffer);
        }
    }
}
Exemple #13
0
int i2c_xfer(const imx_i2c_request_t *rq, int dir)
{
    uint32_t reg;
    uint32_t ret = 0;
    uint16_t i2cr;
    uint8_t i;
    uint8_t data;
    uint32_t instance = i2c_get_request_instance(rq);
    uint8_t address = (rq->device ? rq->device->address : rq->dev_addr) << 1;

    if (rq->buffer_sz == 0 || rq->buffer == NULL) {
        debug_printf("Invalid register address size=%x, buffer size=%x, buffer=%x\n",
               rq->reg_addr_sz, rq->buffer_sz, (unsigned int)rq->buffer);
        return ERR_INVALID_REQUEST;
    }

    // clear the status register 
    HW_I2C_I2SR_WR(instance, 0);

    // enable the I2C controller 
    HW_I2C_I2CR_WR(instance, BM_I2C_I2CR_IEN);

    // Check if bus is free, if not return error 
    if (is_bus_free(instance) != 0) {
        return -1;
    }
    
    // If the request has device info attached and it has a non-zero bit rate, then
    // change the clock to the specified rate.
    if (rq->device && rq->device->freq)
    {
        set_i2c_clock(instance, rq->device->freq);
    }

    // Step 1: Select master mode, assert START signal and also indicate TX mode 
    HW_I2C_I2CR_WR(instance, BM_I2C_I2CR_IEN | BM_I2C_I2CR_MSTA | BM_I2C_I2CR_MTX);

    // make sure bus is busy after the START signal 
    if (wait_till_busy(instance) != 0) {
        debug_printf("1\n");
        return -1;
    }
    
    // Step 2: send slave address + read/write at the LSB 
    data = address | I2C_WRITE;

    if ((ret = tx_byte(&data, instance)) != 0) {
        debug_printf("START TX ERR %d\n", ret);

        if (ret == ERR_NO_ACK) {
            return ERR_NO_ACK_ON_START;
        } else {
            return ret;
        }
    }
    
    // Step 3: send I2C device register address 
    if (rq->reg_addr_sz > 4) {
        debug_printf("Warning register address size %d should less than 4\n", rq->reg_addr_sz);
        return ERR_INVALID_REQUEST;
    }

    reg = rq->reg_addr;

    for (i = 0; i < rq->reg_addr_sz; i++, reg >>= 8) {
        data = reg & 0xFF;
        
#if TRACE_I2C
        debug_printf("sending I2C=%d device register: data=0x%x, byte %d\n", instance, data, i);
#endif // TRACE_I2C

        if (tx_byte(&data, instance) != 0) {
            return -1;
        }
    }

    // Step 4: read/write data 
    if (dir == I2C_READ) {
        // do repeat-start 
        HW_I2C_I2CR(instance).B.RSTA = 1;

        // make sure bus is busy after the REPEATED START signal 
        if (wait_till_busy(instance) != 0) {
            return ERR_TX;
        }
        
        // send slave address again, but indicate read operation 
        data = address | I2C_READ;

        if (tx_byte(&data, instance) != 0) {
            return -1;
        }

        // change to receive mode 
        i2cr = HW_I2C_I2CR_RD(instance) & ~BM_I2C_I2CR_MTX;
        
        // if only one byte to read, make sure don't send ack 
        if (rq->buffer_sz == 1) {
            i2cr |= BM_I2C_I2CR_TXAK;
        }
        HW_I2C_I2CR_WR(instance, i2cr);

        // dummy read 
        data = HW_I2C_I2DR_RD(instance);

        // now reading ... 
        if (rx_bytes(rq->buffer, instance, rq->buffer_sz) != 0) {
            return -1;
        }
    } else {
        // I2C_WRITE 
        for (i = 0; i < rq->buffer_sz; i++) {
            // send device register value 
            data = rq->buffer[i];

            if ((ret = tx_byte(&data, instance)) != 0) {
                break;
            }
        }
    }

    // generate STOP by clearing MSTA bit 
    imx_send_stop(instance);

    // Check if bus is free, if not return error 
    if (is_bus_free(instance) != 0) {
        debug_printf("WARNING: bus is not free\n");
    }
    
    // disable the controller 
    HW_I2C_I2CR_WR(instance, 0);

    return ret;
}
Exemple #14
0
static int number(void (*tx_byte)(unsigned char byte),
	unsigned long long num, int base, int size, int precision, int type)
{
	char c,sign,tmp[66];
	const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
	int i;
	int count = 0;

	if (type & LARGE)
		digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	if (type & LEFT)
		type &= ~ZEROPAD;
	if (base < 2 || base > 36)
		return 0;
	c = (type & ZEROPAD) ? '0' : ' ';
	sign = 0;
	if (type & SIGN) {
		if ((signed long long)num < 0) {
			sign = '-';
			num = -num;
			size--;
		} else if (type & PLUS) {
			sign = '+';
			size--;
		} else if (type & SPACE) {
			sign = ' ';
			size--;
		}
	}
	if (type & SPECIAL) {
		if (base == 16)
			size -= 2;
		else if (base == 8)
			size--;
	}
	i = 0;
	if (num == 0)
		tmp[i++]='0';
	else while (num != 0)
		tmp[i++] = digits[do_div(num,base)];
	if (i > precision)
		precision = i;
	size -= precision;
	if (!(type&(ZEROPAD+LEFT)))
		while(size-->0)
			tx_byte(' '), count++;
	if (sign)
		tx_byte(sign), count++;
	if (type & SPECIAL) {
		if (base==8)
			tx_byte('0'), count++;
		else if (base==16) {
			tx_byte('0'), count++;
			tx_byte(digits[33]), count++;
		}
	}
	if (!(type & LEFT))
		while (size-- > 0)
			tx_byte(c), count++;
	while (i < precision--)
		tx_byte('0'), count++;
	while (i-- > 0)
		tx_byte(tmp[i]), count++;
	while (size-- > 0)
		tx_byte(' '), count++;
	return count;
}
/*f c_uart_testbench::run_exec_file
 */
void c_uart_testbench::run_exec_file( void )
{
     int cmd, cmd_type;
     t_sl_exec_file_value *args;
     int i;
     t_uart_event_data *event;

     if (exec_file_data)
     {
          while (1)
          {
               cmd_type = sl_exec_file_get_next_cmd( exec_file_data, &cmd, &args );
               if ( (cmd_type==0) || (cmd_type==2) ) // Break if nothing left to do
               {
                    break;
               }
               if (cmd_type==1) // If given command, handle that
               {
                    if (engine->simulation_handle_exec_file_command( exec_file_data, cmd, args ))
                    {
                    }
                    else if (engine->waveform_handle_exec_file_command( exec_file_data, cmd, args ))
                    {
                    }
                    else
                    {
                         switch (cmd)
                         {
                         case cmd_uart_tx_string:
                             for (i=0; args[0].p.string[i]; i++)
                             {
                                 tx_byte( args[0].p.string[i] );
                             }
                             tx_byte( 0 );
                             break;
                         case cmd_uart_tx_line:
                             for (i=0; args[0].p.string[i]; i++)
                             {
                                 tx_byte( args[0].p.string[i] );
                             }
                             tx_byte( 10 );
                             break;
                         case cmd_uart_tx_byte:
                             tx_byte( args[0].integer );
                             break;
                         case cmd_wait:
                             if ( (event = uart_add_event( "wait", event_flag_none, 0, args[0].integer )) != NULL )
                             {
                                 fprintf(stderr,"Waiting for time %d\n", args[0].integer);
                                 sl_exec_file_wait_for_event( exec_file_data, NULL, event->event );
                             }
                             break;
                         case cmd_wait_until_rx_ne:
                             if ( (event = uart_add_event( "wait_until_rx_ne", event_flag_rx_ne, 1, -1 )) != NULL )
                             {
                                 sl_exec_file_wait_for_event( exec_file_data, NULL, event->event );
                             }
                             break;
                         case cmd_wait_until_rx_has_string:
                             if ( (event = uart_add_event( "wait_until_rx_has_string", event_flag_rx_has_string, 1, -1 )) != NULL )
                             {
                                 sl_exec_file_wait_for_event( exec_file_data, NULL, event->event );
                             }
                             break;
                         case cmd_wait_until_rx_has_line:
                             if ( (event = uart_add_event( "wait_until_rx_has_line", event_flag_rx_has_line, 1, -1 )) != NULL )
                             {
                                 sl_exec_file_wait_for_event( exec_file_data, NULL, event->event );
                             }
                             break;
                         }
                    }
               }
          }
     }
}