示例#1
0
static u16 log_to_host(){
  static __xdata u16 sequence_num = 0;
  u16 crc = crc16(locked_page, log_block_size, 
      crc16((u8 *)&(++sequence_num), sizeof(sequence_num), 0));
  if(!(cdc_tx(protocol_header, sizeof(protocol_header))
      && cdc_tx((u8 *)&sequence_num, sizeof(sequence_num))
      && (cdc_tx(locked_page, log_block_size) == log_block_size)
      && cdc_tx((u8 *)&crc, sizeof(crc)))){
    return 0;
  }
  return log_block_size;
}
示例#2
0
void cdc_polling(){
  static __xdata u8 previous_frame_num = 0;
  u8 current_frame_num = usb_frame_num & 0xF0; // per 16 frames

  u8 read_count;
  char buf[CDC_DATA_EP_OUT_PACKET_SIZE + 1];
  
  buf[0] = 'D'; // debug
  while(read_count = min(((u8)cdc_rx_size()), sizeof(buf) - 1)){
    cdc_rx(buf + 1, read_count);
  }

  if(previous_frame_num == current_frame_num){
    return;
  }
  previous_frame_num = current_frame_num;

  cdc_tx(NULL, 0); // flush
  
#ifndef CDC_IS_REPLACED_BY_FTDI
  /*{
    // ResponseAvailable
    static const __code u8 buf[] = {
      0xA1, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    };
    usb_write(buf, sizeof(buf), CDC_COM_EP_IN);
  }*/
  {
    // SerialState
    static const __code u8 buf[] = {
      0xA1, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
      0x03, 0x00
    };
    usb_write(buf, sizeof(buf), CDC_COM_EP_IN);
  }
#endif
}