Example #1
0
File: gdb.c Project: vocho/openqnx
void
putpacket(void) {
    unsigned char checksum;
    int  count;
    char ch;

    gdb_compress(outbuf, scratch);
  
#ifdef DEBUG_GDB
	kprintf("Response packet '%s'\n", scratch);
#endif	

    /*  $<packet info>#<checksum>. */

    dbg_putc('$');
    checksum = 0;
    count    = 0;
  
    while((ch = scratch[count])) {
		dbg_putc(ch);
		checksum += ch;
		count += 1;
    }
	
    dbg_putc('#');
    dbg_putc(tohexchar(checksum >> 4));
    dbg_putc(tohexchar(checksum));
}
Example #2
0
void dbg_printk(const char* fmt, ...)
{
    char tmp[256];
    int i;
    va_list arg;

    va_start(arg, fmt);
    vsprintf(tmp, fmt, arg);
    va_end(arg);
    for (i = 0; tmp[i]; i++) {
        if (tmp[i] == '\n') {
            dbg_putc('\r');
        }
        dbg_putc(tmp[i]);
    }
}
Example #3
0
File: gdb.c Project: vocho/openqnx
/*
 * gdb_putstr - low level string output routine
 */ 
void
gdb_putstr(const char *text, int len) {
	int i;

	if(len == 0) len = strlen(text);

	for(i = 0; i < len; i++) dbg_putc(text[i]);
}
Example #4
0
int load_image(const char *fn, _u8 *dst) {
  _i32 fh;
  SlFsFileInfo_t fi;
  _i32 r = sl_FsGetInfo((const _u8 *) fn, 0, &fi);
  dbg_putc(r == 0 ? '+' : '-');
  if (r != 0) return r;
  {
    char buf[20];
    __utoa(fi.FileLen, buf, 10);
    dbg_puts(buf);
  }
  r = sl_FsOpen((const _u8 *) fn, FS_MODE_OPEN_READ, NULL, &fh);
  dbg_putc(r == 0 ? '+' : '-');
  if (r != 0) return r;
  r = sl_FsRead(fh, 0, dst, fi.FileLen);
  if (r != fi.FileLen) return r;
  sl_FsClose(fh, NULL, NULL, 0);
  return 0;
}
Example #5
0
int main(void)
{
    uint8_t i;

    cpu_init();
      
    while(1)
    {
        dint();
        ir_setup();
        eint();

        while(times_index < SAMPLES)
        {
            // spin
        }

        P1IE &= ~IR_BIT;    // interrupt enable

        dint();
        uart_init();
        eint();

#ifdef DUMP_RAW_PULSES
        for (i=0;i<times_index;i++)
        {
            dbg_putdec(times[i]);
            dbg_putc(',');
        }
        dbg_newline();
#else
        for (i=0;i<times_index;i++)
        {
            dbg_putc(times[i] > 40 ? '1' : '0');
        }
        dbg_newline();
        dbg_newline();
#endif
    }
}
Example #6
0
//*****************************************************************************
//*****************************************************************************
void dbg_putstr(const char * str)
{
    while(*str != '\0')
        dbg_putc(*str++, NULL);
}
Example #7
0
void abort(void) {
  dbg_putc('X');
  while (1) {
  }
}
Example #8
0
void dbg_puts(const char *s) {
  for (; *s != '\0'; s++) dbg_putc(*s);
}
Example #9
0
int main(void) {
  MAP_IntVTableBaseSet((unsigned long) &int_vectors[0]);
  MAP_IntMasterEnable();
  PRCMCC3200MCUInit();

/* Console UART init. */
#ifndef NO_DEBUG
  MAP_PRCMPeripheralClkEnable(DEBUG_UART_PERIPH, PRCM_RUN_MODE_CLK);
#if MIOT_DEBUG_UART == 0
  MAP_PinTypeUART(PIN_55, PIN_MODE_3); /* UART0_TX */
  MAP_PinTypeUART(PIN_57, PIN_MODE_3); /* UART0_RX */
#else
  MAP_PinTypeUART(PIN_07, PIN_MODE_5); /* UART1_TX */
  MAP_PinTypeUART(PIN_08, PIN_MODE_5); /* UART1_RX */
#endif
  MAP_UARTConfigSetExpClk(
      DEBUG_UART_BASE, MAP_PRCMPeripheralClockGet(DEBUG_UART_PERIPH),
      MIOT_DEBUG_UART_BAUD_RATE,
      (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
  MAP_UARTFIFOLevelSet(DEBUG_UART_BASE, UART_FIFO_TX1_8, UART_FIFO_RX4_8);
  MAP_UARTFIFODisable(DEBUG_UART_BASE);
#endif

  dbg_puts("\r\n\n");

  if (sl_Start(NULL, NULL, NULL) < 0) abort();
  dbg_putc('S');

  int cidx = get_active_boot_cfg_idx();
  if (cidx < 0) abort();
  dbg_putc('0' + cidx);
  struct boot_cfg cfg;
  if (read_boot_cfg(cidx, &cfg) < 0) abort();

  dbg_puts(cfg.app_image_file);
  dbg_putc('@');
  print_addr(cfg.app_load_addr);

  /*
   * Zero memory before loading.
   * This should provide proper initialisation for BSS, wherever it is.
   */
  uint32_t *pstart = (uint32_t *) 0x20000000;
  uint32_t *pend = (&_text_start - 0x100 /* our stack */);
  for (uint32_t *p = pstart; p < pend; p++) *p = 0;

  if (load_image(cfg.app_image_file, (_u8 *) cfg.app_load_addr) != 0) {
    abort();
  }

  dbg_putc('.');

  sl_Stop(0);
  print_addr(*(((uint32_t *) cfg.app_load_addr) + 1));
  dbg_puts("\r\n\n");

  MAP_IntMasterDisable();
  MAP_IntVTableBaseSet(cfg.app_load_addr);

  run(cfg.app_load_addr); /* Does not return. */

  abort();

  return 0; /* not reached */
}
Example #10
0
File: gdb.c Project: vocho/openqnx
/*
 * This function does all command procesing for interfacing to gdb.
 */
static boolean
do_gdb_interface(struct kdebug_entry *entry, CPU_REGISTERS *ctx, ulong_t signal) {
    int    length;

struct kdebug_info		*kinfo;
const struct kdebug_private	*kprivate;
THREAD *thread;

    /* 
     * Indicate that we've gone back to debug mode
     */
    for (length = 0; length < 4; length++) dbg_putc('|');
	if(protocol == 0) {
		// generic GDB 4.16 wants the response to the continue/step
		// command sent before it transmits anything else.
		ksprintf(outbuf,"S%02xk", (unsigned)signal);
		putpacket();
	}

	while(getpacket()) {
		connected = TRUE;

		outbuf[0] = 0;

#ifdef DEBUG_GDB
kprintf("Processing packet '%s'\n", inbuf);		
#endif
        switch(inbuf[0]) {

		/* Tell the gdb client our signal number */
		case '?' :
			if(gdb_test_reloc_sem()) {
				paddr_t					base;
				char					*str = SYSPAGE_ENTRY(strings)->data;
				struct asinfo_entry		*as = SYSPAGE_ENTRY(asinfo);
		
				while(strcmp(&str[as->name], "imagefs") != 0) {
					++as;
				}
				base = gdb_image_base(as->start);
				gdb_clear_reloc_sem();
				ksprintf(outbuf,"N%02x%P;%P;%P",
					(unsigned)signal, base, base, (paddr_t)(base + as->end - as->start + 1));
			} else {
				ksprintf(outbuf,"S%02xk", (unsigned)signal);
			}
	
			for(length=1;outbuf[length];length++) {
				if((outbuf[length] >= 'A') && 
					(outbuf[length] <='Z'))
					outbuf[length]=outbuf[length]+('a'-'A');
			}
			if(gdb_debug) gdb_printf("%s", outbuf);
	
			break;
	
		/* toggle debug flag */
		case 'd' :
			gdb_debug = !(gdb_debug);
			break; 
		
		/* return the value of the CPU registers */
		case 'g' :
/* temp solution, need to add an offset item in kdebug_private for fpu data	*/
			if((kinfo = private->kdebug_info)== NULL || (kprivate = kinfo->kdbg_private) == NULL ||
				(thread = ((void **)kprivate->actives)[0]) == NULL) {
				gdb_get_cpuregs(ctx,NULL);
			} else {
				gdb_get_cpuregs(ctx,thread->fpudata);
			}
			break;
	
		/* set the value of the CPU registers - return OK */
		case 'G' : 
/* temp solution, need to add an offset item in kdebug_private for fpu data	*/
			if((kinfo = private->kdebug_info)== NULL || (kprivate = kinfo->kdbg_private) == NULL ||
				(thread = ((void **)kprivate->actives)[0]) == NULL) {
				gdb_set_cpuregs(ctx,NULL);
			} else {
				gdb_set_cpuregs(ctx,thread->fpudata);
			}
			strcpy(outbuf,"OK");
			break;

		/* get target information */
		case 'i':
			gdb_get_info();
			break;
		  
		/* mAA..AA,LLLL  Read LLLL bytes at address AA..AA */
		case 'm' : 
			gdb_read_membytes(ctx);
			break;
		  
		/* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
		case 'M' : 
			gdb_write_membytes(ctx);
			break;
		 
		/* cAA..AA    Continue at address AA..AA(optional) */
		case 'c' : 
			gdb_proc_continue(ctx, 0);	/* continue the process */
			return(TRUE);
	
		/* sAA..AA   Step one instruction from AA..AA(optional) */
		case 's' : 
			gdb_proc_continue(ctx, 1);	/* step one instruction */
			return(TRUE);

		/* q???? Generic query */	

		case 'q': 
			if(memcmp(&inbuf[1], "Rcmd,", 5) == 0) {
				// remote command
				char	*p;

				p = &inbuf[6];
				hex2mem(p, scratch, strlen(p));
				#define MEM_CMD	"mem "
				if(memcmp(scratch, MEM_CMD, sizeof(MEM_CMD)-1) == 0) {
					monitor_mem(&scratch[sizeof(MEM_CMD)-1]);
				}
			}
			break;

		/* k		Kill program */
		case 'k' :
			putpacket(); /*ACK the packet early (since we're going bye-bye) */
			gdb_prep_reboot();
			SYSPAGE_ENTRY(callout)->reboot(_syspage_ptr, 0);
			break;

		/* D		Detach from host */
		case 'D' :
			connected = FALSE;
			return(FALSE);
			  
		} /* switch */ 
Example #11
0
File: gdb.c Project: vocho/openqnx
/* 
 * scan for the sequence $<data>#<checksum>
 */
boolean
getpacket() {
    unsigned char checksum;
    unsigned char xmitcsum;
    int  i;
    int  count;
    int ch;
	int cs1;
	int cs2;
	int	(*init_getc)(void);
  
 	init_getc = connected ? dbg_getc : dbg_getc_connect_check;
    for( ;; ) {
try_again:
		/* wait around for the start character, ignore all other characters */
		do {
			ch = init_getc();
			if(ch == -1) return(FALSE);
		} while(ch != '$');

try_again2:		
		checksum = 0;
		count = 0;
		cs1 = cs2 = 0;
		
		/* now, read until a # or end of buffer is found */
		for( ;; ) {
			if(count >= BUFMAX) goto try_again;
			ch = dbg_getc();
			if(ch == -1) return(FALSE);
			if(ch == '#') break;
			if(ch == '$') goto try_again2;
			checksum = checksum + ch;
			scratch[count++] = ch;
		}
		/* collect the checksum */
		cs1 = dbg_getc();
		if(cs1 == -1) return(FALSE);
		cs2 = dbg_getc();
		if(cs2 == -1) return(FALSE);

		scratch[count] = 0;
		gdb_expand(scratch, inbuf);
		
		xmitcsum = (chartohex(cs1) << 4) + chartohex(cs2);
		if(checksum == xmitcsum) break;
		if(gdb_debug) {
			gdb_printf("bad checksum.  My count = 0x%x, sent=0x%x. buf=%s\n",
			   checksum,xmitcsum,inbuf);
		}
		dbg_putc('-');  /* failed checksum */ 
    } 
	dbg_putc('+');  /* successful transfer */
	/* if a sequence char is present, reply the sequence ID */
	if(inbuf[2] == ':') {
		dbg_putc(inbuf[0]);
		dbg_putc(inbuf[1]);
		/* remove sequence chars from buffer */
		i = 3;
		for( ;; ) {
			inbuf[i-3] = inbuf[i];
			if(inbuf[i] == '\0') break;
			++i;
		}
	} 
    return(TRUE);
}
Example #12
0
static uint8_t umpl_parse_input(uint8_t in, int8_t * out)
{   
    // Return flag indicates we wrote to *out.
    uint8_t returnflag = 0;
    // Internal state:
    static uint8_t input_valid = 0; // Current packet is valid (correct packet type)
    static uint8_t input_idx = 0;   // Index of in
    static uint8_t buf[9];          // Buffer for rotation matrix payload.
    
    if (input_valid){
        switch (input_idx)
        {
        case 0:
            if (in == '$') {     // Packet starts with '$'
                input_idx++;
            } else {
                input_valid = 0;
            }
        break;
        case 1:
            if (in == 10) {      // Second byte should be 10
                input_idx++;     // (we use other values here to
            } else {             // indicate other packet types)
                input_valid = 0;
            }
        break;
        case 2:  // bytes 2 through 10 are
        case 3:  // the rotation matrix payload
        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
        case 9:
        case 10:
            buf[input_idx-2] = in;
            input_idx++;
        break;
        case 11:
            // now we have the whole payload, and can write it to *out
            {
                uint8_t ii;
                for (ii = 0; ii < 9; ii++)
                    out[ii] = (int8_t) buf[ii]; // Copy buf to *out.
                returnflag = 1;                 // Tell caller we wrote to *out.
                dbg_putc("1"); // (for debugging)
            }
            input_idx++;
        break;
        case 12:
            input_idx++;
        break;
        case 13:          // packets are 14 bytes long.
            input_idx = 0;
        break;
        default:
            input_valid = 0;
        }
    } else { // input_valid = 0
        if (in == '$')  // '$' is always the packet start character.
        {
            input_valid = 1;
            input_idx = 1;
        }
    }
    return returnflag;
}
Example #13
0
void
main_app_loop(void)
{
    uint8_t umpl_got;
	const uint64_t millis = pulse_get_millis();

        // If the not-charging state has not been toggled in the last
        // 30 seconds, schedule a power down soon.
        if (not_charging && millis - not_charging > 60000)
	{
		if (!shutdown_scheduled)
			pulse_update_power_down_timer(1);
		shutdown_scheduled = 1;
		return;
	}

    /* The umpl_input_handler is nonblocking.
     * It will read a packet off the debug serial
     * port, and copy the rotation matrix payload 
     * to the provided buffer.
     */

    umpl_got = umpl_input_handler(default_m);

    if (umpl_got)
        dbg_putc((char)0); // (for debugging)

	camera_setup_rmat(&camera, 4000, rmats[selected_mat]);


#if 1
	pixel_t temp_pixels[ARRAY_COUNT(pixels)];
	wireframe_draw(
		&camera,
		ARRAY_COUNT(vertices),
		vertices,
		ARRAY_COUNT(edges),
		edges,
		pixels,
		temp_pixels
	);
#else
	for (int i = 0 ; i < ARRAY_COUNT(vertices) ; i++)
	{
		const vertex_t * const v = &vertices[i];
		pixel_t * const p = &pixels[i];
		draw_pixel(COLOR_BLACK24, p->x, p->y);
		camera_project(&camera, v, p);
		draw_pixel(COLOR_GREEN, p->x, p->y);
	}
#endif

	// Update the clock once per minute
	struct pulse_time_tm now;
	pulse_get_time_date(&now);
	if (last_sec == now.tm_sec)
		return;
	last_sec = now.tm_sec;
	if (last_min != now.tm_min)
		pulse_blank_canvas();
	last_min = now.tm_min;

	char buf[16];
	sprintf(buf, "%02d:%02d",
		now.tm_hour,
		now.tm_min
	);

	draw_monostring(8, VSCREEN_HEIGHT - FONT_HEIGHT - 1, COLOR_GREEN, buf);
}