コード例 #1
0
ファイル: intel_hex.c プロジェクト: AdamLaurie/CC-Bootloader
void ihx_read_print(__xdata uint8_t* start_addr, uint16_t len) {
  __xdata char buff[45];
  uint8_t byte, sum, i, chunk;
  
  while (len) {
    sum = 0;
    if(len > 0x10)
      chunk = 0x10;
    else
      chunk = len;
    
    buff[0] = ':';
    to_hex8_ascii(&buff[1], chunk);
    sum += chunk;
    // Write address into buffer
    to_hex16_ascii(&buff[3], (uint16_t)start_addr);
    sum += (uint16_t)start_addr & 0xFF;
    sum += ((uint16_t)start_addr >> 8) & 0xFF;
    // Write record type into buffer
    to_hex8_ascii(&buff[7], 0x00);
    // Write data bytes into buffer
    for (i=0; i<chunk; i++) {
      byte = *(start_addr+i);
      sum += byte;
      to_hex8_ascii(&buff[9 + 2*i], byte);
    }
    // Write checksum into buffer
    to_hex8_ascii(&buff[9 + 2*i], (uint8_t)(-(int8_t)sum));
    buff[11 + 2*i] = '\n';
    buff[12 + 2*i] = 0;
    
    // Print buffer over usb
    usb_putstr(buff);
    
    // Updates for next go round
    if(len > 0x10) {
      start_addr += 0x10;
      len -= 0x10;
    } else // we're done
      len = 0;
  }
  usb_putstr(":00000001FF\n");
}
コード例 #2
0
ファイル: driver.c プロジェクト: dclovesdc1/pingrf
static int
hexwrite(int fd, void *p, int n)
{
	char hex[RCALLMAX*2];
	int i, nw;
	char *cp = (char*)p;
	
	for(i=0; i<n; i++)
		to_hex8_ascii(&hex[i*2], cp[i]);
		
	nw = fdwrite(fd, hex, n*2);
	if(nw < 0)
		return -1;

	return nw/2;
}
コード例 #3
0
ファイル: usbsrv.c プロジェクト: dclovesdc1/pingrf
void
srvtx()
{
	int i;
	uint8 length;
	char txcall_in_ascii[SPIMAX * 2];
	int ascii_idx;

	flag &= ~Ftxcall;
	length = txcall[0];

	for (ntx = 0; ntx < length; ntx++) {
		to_hex8_ascii(&txcall_in_ascii[ntx * 2], txcall[ntx]);
	}

	for (ascii_idx = 0; ascii_idx < length * 2; ascii_idx++) {
		usb_putchar(txcall_in_ascii[ascii_idx]);
	}
	usb_flush( );
	flag |= Ftxcall;
}
コード例 #4
0
ファイル: intel_hex.c プロジェクト: AdamLaurie/CC-Bootloader
void to_hex16_ascii(char buff[], uint16_t x) {
  to_hex8_ascii(&buff[2], x & 0xFF);
  to_hex8_ascii(&buff[0], (x>>8) & 0xFF);  
}