Ejemplo n.º 1
0
int mon_data(int argc, char **argv){
  FIL fil;
  power_pkt pkt; 
  FRESULT fr; 
  UINT r;
  if(argc!=2){
    printf("specify [read] or [erase]\n");
    return -1;
  }
  if(strcmp(argv[1],"read")==0){
    //print the data out to STDOUT
    fr = f_open(&fil, DATA_FILE, FA_READ);
    if(fr){
      printf("error reading data: %d\n",(int)fr);
      return -1;
    }
    while(f_read(&fil, &pkt, sizeof(pkt), &r)==0){
      if(r==0) //all done
	break;
      if(r!=sizeof(pkt)){
	core_log("corrupt data buffer");
	break;
      }
      while(!udi_cdc_is_tx_ready()); //wait for buffer
      //data is binary so write directly to the USB buffer
      udi_cdc_write_buf(&pkt,sizeof(pkt));
    }
    f_close(&fil);

    memset(&pkt,'x',sizeof(pkt));  //set up termination string
    while(!udi_cdc_is_tx_ready()); //wait for buffer
    udi_cdc_write_buf(&pkt,sizeof(pkt)); //send it

    return 0;
  }
  else if(strcmp(argv[1],"erase")==0){
    fs_erase_data();
    if(wemo_config.echo)
      printf("erased data\n");
    return 0;
  }
  else{
    printf("specify [read] or [erase]\n");
    return -1;
  }
  //shouldn't get here
  return 0;
}
Ejemplo n.º 2
0
int udi_cdc_putc(int value)
{
	irqflags_t flags;
	bool b_databit_9;
	uint8_t buf_sel;

	b_databit_9 = (9 == udi_cdc_line_coding.bDataBits);

udi_cdc_putc_process_one_byte:
	// Check avaliable space
	if (!udi_cdc_is_tx_ready()) {
		if (!udi_cdc_running) {
			return false;
		}
		goto udi_cdc_putc_process_one_byte;
	}

	// Write value
	flags = cpu_irq_save();
	buf_sel = udi_cdc_tx_buf_sel;
	udi_cdc_tx_buf[buf_sel][udi_cdc_tx_buf_nb[buf_sel]++] = value;
	cpu_irq_restore(flags);

	if (b_databit_9) {
		// Send MSB
		b_databit_9 = false;
		value = value >> 8;
		goto udi_cdc_putc_process_one_byte;
	}
	return true;
}
Ejemplo n.º 3
0
void usb_int_send_byte(usb_config_t *usb_conf, uint8_t data) 
{
	for(uint8_t i=0;i<3;i++)
	{
		if (udi_cdc_is_tx_ready())
		{
			stdio_usb_putchar(NULL, (int)data);
			return;
		}	
	}
	
}
Ejemplo n.º 4
0
iram_size_t udi_cdc_write_buf(const int* buf, iram_size_t size)
{
	irqflags_t flags;
	uint8_t buf_sel;
	uint16_t buf_nb;
	iram_size_t copy_nb;
	uint8_t *ptr_buf = (uint8_t *)buf;

	if (9 == udi_cdc_line_coding.bDataBits) {
		size *=2;
	}

udi_cdc_write_buf_loop_wait:
	// Check avaliable space
	if (!udi_cdc_is_tx_ready()) {
		if (!udi_cdc_running) {
			return size;
		}
		goto udi_cdc_write_buf_loop_wait;
	}

	// Write values
	flags = cpu_irq_save();
	buf_sel = udi_cdc_tx_buf_sel;
	buf_nb = udi_cdc_tx_buf_nb[buf_sel];
	copy_nb = UDI_CDC_TX_BUFFERS - buf_nb;
	if (copy_nb>size) {
		copy_nb = size;
	}
	memcpy(&udi_cdc_tx_buf[buf_sel][buf_nb], ptr_buf, copy_nb);
	udi_cdc_tx_buf_nb[buf_sel] = buf_nb + copy_nb;
	cpu_irq_restore(flags);

	// Update buffer pointer
	ptr_buf = ptr_buf + copy_nb;
	size -= copy_nb;

	if (size) {
		goto udi_cdc_write_buf_loop_wait;
	}

	return 0;
}
/**
 * \internal
 * \brief USART interrupt callback function
 *
 * Called by USART driver when receiving is complete.
 *
 * * \param module USART module causing the interrupt (not used)
 */
static void usart_rx_callback(struct usart_module *const module)
{
	/* Data received */
	ui_com_tx_start();

	/* Transfer UART RX fifo to CDC TX */
	if (!udi_cdc_is_tx_ready()) {
		/* Fifo full */
		udi_cdc_signal_overrun();
		ui_com_overflow();
	} else {
		udi_cdc_putc(rx_data);
	}

	ui_com_tx_stop();

	usart_read_buffer_job(&usart_module_edbg, &rx_data, 1);

	return;
}
Ejemplo n.º 6
0
void core_putc(void* stream, char c){
  //only wait 2 systicks and then give up
  static uint8_t locked = false; //prevent re-entrant
  int prev_tick; //prevent deadlock when USB isn't connected (bad disconnect)
  if(locked)
    return; //udc spinlock is not re-entrant
  prev_tick = sys_tick; //grab the current sys_tick
  if(b_usb_enabled && wemo_config.echo){
    locked = true; //enter spin
    while(!udi_cdc_is_tx_ready()){
      if(sys_tick>(prev_tick+1)){ //check if we timeout
	core_usb_enable(0,false); //turn off USB
	locked = false;
	return;
      }
    }
    //success, got USB TX ready signal
    udi_cdc_write_buf(&c,1);
    locked = false; //release
  }
}
/*! \brief Write data buffer via USB or serial port.
 *
 * This application uses a serial or USB connection to transmit sensor data.
 * This routine takes the specified input buffer and writes each byte to
 * the appropriate output device.
 *
 * \param   buffer    The address of a buffer containing the data to transmit
 * \param   num_bytes The number of bytes to transmit
 *
 * \return  Nothing.
 */
void adv_write_buf(uint8_t *buffer, int num_bytes)
{
#if UC3
#  if UC3L
	/* Use regular USART stdio output */

	/* Transmit each character */
	while (num_bytes-- > 0) {
		putchar(*buffer++);         /* write char via usart */
	}

#  else
	/* Use internal USB controller (CDC device) */

	/* Check if USB ready to transmit */
	if (!(udi_cdc_is_tx_ready())) {
		return;
	}

	/* Transmit each character */
	while (num_bytes-- > 0) {
		udi_cdc_putc(*buffer++);         /* write char via USB CDC
		                                  * device */
	}
#  endif

#elif XMEGA
	/* Transmit each character */
	while (num_bytes-- > 0) {
		putchar(*buffer++);         /* write char via usart */
	}
#endif

	/* Delay to allow all bytes to output */
	delay_ms(PKT_XMIT_DELAY);

	return;
}
Ejemplo n.º 8
0
int usb_data_write_byte(Byte data)
{
	while(!udi_cdc_is_tx_ready());
	return udi_cdc_putc(data);
}