Ejemplo n.º 1
0
void uos_on_task_switch(task_t *t)
{
    int i;
    unsigned m = TSK_PIN_TIMER<<1;

    if (0)
    if (task_is_active(h_udp_task))
    if (h_udp_task != t)
    {
        debug_printf("%s(%d)\n", t->name, t->prio);
        debug_putchar(0, '$');
    }
    else
        debug_putchar(0, '4');

    //debug_printf("@%s\n", t->name);
    for (i = 0; i < 8; i++, m = m<<1 ){
        if (trace_tasks[i] != 0){
        if ((unsigned)t == trace_tasks[i]){
            TSK_PORT_IO.data |= m;
            //debug_putchar(0,'0'+i);
            //debug_printf("%x[%d]\n", (unsigned)t, i);
        }
        else
            TSK_PORT_IO.data &= ~m;
        }
    }
}
Ejemplo n.º 2
0
void __putchar(const char c)
{
  #if defined(CFG_USB) && defined(CFG_PRINTF_USBCDC)
    if (usb_isConfigured())
    {
      while(usb_cdc_isConnected() && !usb_cdc_putc(c) ) // blocking
      {
        ASM("nop");
      }
    }
  #endif

  #ifdef CFG_PRINTF_UART
    uartSendByte(c);
  #endif

  /* Handle PRINTF_DEBUG redirection for Crossworks for ARM */
  #ifdef __CROSSWORKS_ARM
    #ifdef CFG_PRINTF_DEBUG
      #if defined CFG_MCU_FAMILY_LPC13UXX
        /* On the M3 we can check if a debugger is connected */
        if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)==CoreDebug_DHCSR_C_DEBUGEN_Msk)
        {
          debug_putchar(c);
        }
      #else
        /* On the M0 the processor doesn't have access to CoreDebug, so this
         * will cause problems if no debugger is connected! */
        debug_putchar(c);
      #endif
    #endif
  #endif
}
Ejemplo n.º 3
0
/* Prints out the specified game grid (it's assumed that if it exists, it is
 * state->width * state->height in size, which should always be true): */
static void dump_grid(nbstate *state, grid *g)
{
	grid *gp;
	int x, y;
	/* The letters that symbolise each of the power-ups and power-downs: */
	char powers[] = " WSTPNFRI";

	/* If the grid is empty, just print "<empty>" and return: */
	if(!g) {
		debug_printf ("\t<empty>\n");
		return;
	}

	/* Print the title and top line of the bricks description box: */
	debug_printf ("\tbricks:\n\t\t");
	for(x = 0; x < state->width + 2; x++) debug_putchar (0, '-');
	debug_putchar (0, '\n');

	gp = g;
	for(y = 0; y < state->height; y++) { /* For each grid row. */
		debug_printf ("\t\t|"); /* Left side of the box. */
		for(x = 0; x < state->width; x++) { /* For each grid column. */
			/* Print a space if there is no brick in this grid
			 * box or the brick identifier if there is one: */
			if(!gp->b) debug_putchar (0, ' ');
			else debug_putchar (0, gp->b->identifier);
			gp++;
		}
		debug_printf ("|\n"); /* Right side of the box. */
	}
	/* The bottom line of the box: */
	debug_printf ("\t\t");
	for(x = 0; x < state->width + 2; x++) debug_putchar (0, '-');

	/* Print the title and top line of the powers description box: */
	debug_printf ("\n\tpowers:\n\t\t");
	for(x = 0; x < state->width + 2; x++) debug_putchar (0, '-');
	debug_putchar (0, '\n');

	gp = g;
	for(y = 0; y < state->height; y++) { /* For each grid row. */
		debug_printf ("\t\t|"); /* Left side of the box. */
		for(x = 0; x < state->width; x++) { /* For each grid row. */
			/* Print the symbol associated with this power: */
			debug_putchar (0, powers[gp->power + 1]);
			gp++;
		}
		debug_printf ("|\n"); /* Right side of the box. */
	}
	/* The bottom line of the box: */
	debug_printf ("\t\t");
	for(x = 0; x < state->width + 2; x++) debug_putchar (0, '-');
	debug_putchar (0, '\n');
}
Ejemplo n.º 4
0
static void
mysql_main(void)
{
    if (uip_aborted() || uip_timedout()) {
	MYDEBUG ("connection aborted\n");
	mysql_conn = NULL;
    }

    if (uip_closed()) {
	MYDEBUG ("connection closed\n");
	mysql_conn = NULL;
    }

    if (uip_connected()) {
	MYDEBUG ("new connection\n");
	STATE->stage = MYSQL_WAIT_GREETING;
	STATE->sent = MYSQL_WAIT_GREETING;
	STATE->packetid = 0;
    }

    if (uip_newdata() && uip_len) {
#ifdef DEBUG_MYSQL
	MYDEBUG ("received data: %s\n", uip_appdata);
	for (uint16_t i = 0; i < uip_len; i ++)
	    debug_putchar (((unsigned char *) uip_appdata)[i]);
	debug_putchar (10);
#endif

	if (mysql_parse ()) {
	    uip_close ();		/* Parse error */
	    return;
	}
    }

    if (uip_rexmit()) {
	STATE->packetid --;
	mysql_send_data (STATE->sent);
    }
    else if ((STATE->stage > STATE->sent || STATE->stage == MYSQL_CONNECTED)
	     && (uip_newdata()
		 || uip_acked()
		 || uip_connected()))
	mysql_send_data (STATE->stage);
    else if (STATE->stage == MYSQL_CONNECTED
	     && uip_poll() && *STATE->u.stmtbuf)
	mysql_send_data(STATE->stage);

}
Ejemplo n.º 5
0
/*
 * Read a newline-terminated string from stream.
 */
unsigned char *
debug_gets (unsigned char *buf, int len)
{
	int c;
	unsigned char *s;

	s = buf;
        while (--len > 0) {
		c = debug_getchar ();
		if (c == '\b') {
			if (s > buf) {
				--s;
				debug_puts ("\b \b");
			}
			continue;
		}
		if (c == '\r')
			c = '\n';
		debug_putchar (0, c);
		*s++ = c;
		if (c == '\n')
			break;
	}
	*s = '\0';
	return buf;
}
Ejemplo n.º 6
0
void task_tcl (void *arg)
{
	unsigned char *cmd;
	unsigned char result, got_partial, quit_flag;
	Tcl_Interp *interp;
	Tcl_CmdBuf buffer;

	configure_ram ();
	mem_init (&pool, (size_t) RAM_START, (size_t) RAM_END);
again:
	debug_printf ("\nEmbedded TCL\n\n");

	interp = Tcl_CreateInterp (&pool);
	Tcl_CreateCommand (interp, (unsigned char*) "loop", loop_cmd, 0, 0);
	Tcl_CreateCommand (interp, (unsigned char*) "echo", echo_cmd, 0, 0);

	buffer = Tcl_CreateCmdBuf (&pool);
	got_partial = 0;
	quit_flag = 0;
	while (! quit_flag) {
/*		clearerr (stdin);*/
		if (! got_partial) {
			debug_puts ("% ");
		}
		if (! debug_gets (line, sizeof (line))) {
			if (! got_partial)
				break;

			line[0] = 0;
		}
		cmd = Tcl_AssembleCmd (buffer, line);
		if (! cmd) {
			got_partial = 1;
			continue;
		}

		got_partial = 0;
		result = Tcl_Eval (interp, cmd, 0, 0);

		if (result != TCL_OK) {
			debug_puts ("Error");

			if (result != TCL_ERROR)
				debug_printf (" %d", result);

			if (*interp->result != 0)
				debug_printf (": %s", interp->result);

			debug_putchar (0, '\n');
			continue;
		}

		if (*interp->result != 0)
			debug_printf ("%s\n", interp->result);
	}

	Tcl_DeleteInterp (interp);
	Tcl_DeleteCmdBuf (buffer);
	goto again;
}
Ejemplo n.º 7
0
/**
 * Send a single byte
 *
 * \param c byte value
 *
 * \return 0 success
 * \return -1 failure
 */
int8_t debug_put(uint8_t c)
{
	int8_t retval;
	if (xSemaphoreTake( debug_tx_lock, 20 / portTICK_RATE_MS) != pdTRUE) return -1;
	retval = debug_putchar(c);
	xSemaphoreGive( debug_tx_lock );
	return retval;
}
Ejemplo n.º 8
0
/*
 ******************************************************************************
 *函数:void debug_putstr(const void *str)
 *输入:void
 *输出:str : 要输出的字符串
 *描述:调试串口输出字符串
 ******************************************************************************
 */ 
void debug_putstr(const void *str)
{
  uint8_t *s = (uint8_t*)str;
  while (USART_GetFlagStatus(DEBUG_UART, USART_FLAG_TC) == RESET);
  while(*s) {
    debug_putchar(*s++);    
  }
}
Ejemplo n.º 9
0
void noinline
debug_putstr_(const char *d)
{
  while (*d != 0)
  {
    debug_putchar(*d++);
  }
}
Ejemplo n.º 10
0
void read_lc_segment64(char *p)
{
	int i;
	char buffer[1024];
	struct segment_command_64	*p_segcmd = (struct segment_command_64*)p;
	if (p_segcmd->cmd != LC_SEGMENT_64)	return;
	
	debug_putchar('\t');
	debug_printf("segname: %s\n", p_segcmd->segname);
	debug_putchar('\t');
	debug_printf("vmaddr:  0x%llx\n", p_segcmd->vmaddr);
	debug_putchar('\t');
	debug_printf("vmsize:  0x%llx\n", p_segcmd->vmsize);
	debug_putchar('\t');
	debug_printf("fileoff: 0x%llx\n", p_segcmd->fileoff);
	debug_putchar('\t');
	debug_printf("filesize:0x%llx\n", p_segcmd->filesize);
	debug_putchar('\t');
	debug_printf("nsects:  %d\n", p_segcmd->nsects);

	p += sizeof(struct segment_command_64);
	for(i = 0; i < p_segcmd->nsects; i++) {
		read_section_64(p);
		p += sizeof(struct section_64);
	}
}
Ejemplo n.º 11
0
void
debug_puts (const char *p)
{
	char c;

	for (;;) {
		c = *p;
		if (! c)
			return;
		debug_putchar (0, c);
		++p;
	}
}
Ejemplo n.º 12
0
	/* ARGSUSED */
static int
echo_cmd (void *clientData, Tcl_Interp *interp, int argc, unsigned char **argv)
{
	int i;

	for (i=1; ; i++) {
		if (! argv[i]) {
			if (i != argc)
echoError:			snprintf (interp->result, TCL_RESULT_SIZE,
					"argument list wasn't properly NULL-terminated in \"%s\" command",
					argv[0]);
			break;
		}
		if (i >= argc)
			goto echoError;

		if (i > 1)
			debug_putchar (0, ' ');
		debug_puts ((char*) argv[i]);
	}
	debug_putchar (0, '\n');
	return TCL_OK;
}
Ejemplo n.º 13
0
void debug_printhex_halfbyte(char b){
char c;
switch (b)
{
case 0b00000000 : 	c='0';break;
case 0b00000001 : 	c='1';break;
case 0b00000010 : 	c='2';break;
case 0b00000011 : 	c='3';break;
case 0b00000100 : 	c='4';break;
case 0b00000101 : 	c='5';break;
case 0b00000110 : 	c='6';break;
case 0b00000111 : 	c='7';break;
case 0b00001000 : 	c='8';break;
case 0b00001001 : 	c='9';break;
case 0b00001010 : 	c='A';break;
case 0b00001011 : 	c='B';break;
case 0b00001100 : 	c='C';break;
case 0b00001101 : 	c='D';break;
case 0b00001110 : 	c='E';break;
case 0b00001111 : 	c='F';break;
}
debug_putchar(c);
};
Ejemplo n.º 14
0
/**
 * Send multiple bytes
 *
 * \param buffer pointer to data
 * \param length buffer length
 *
 * \todo wait time for task
 *
 * \return number of bytes sent
 */
int8_t debug_send(uint8_t *buffer, uint8_t length)
{
	uint8_t i = 0;

	if (xSemaphoreTake( debug_tx_lock, 20 / portTICK_RATE_MS) != pdTRUE) return 0;
	
	while(i < length)
	{
		if (debug_putchar(buffer[i]) == -1)
		{	/*buffer full, discard the rest*/
/*			taskYIELD();*/
			xSemaphoreGive( debug_tx_lock );
			return i;			

		}
		else
		{
			i++;
		}
	}
	xSemaphoreGive( debug_tx_lock );
  return i;
}
Ejemplo n.º 15
0
/**
 * Send a constant string.
 *
 * \param s pointer to string
 *
 * \todo wait time for task
 *
 * \return nr. of bytes sent
 */
int8_t debug_constant(prog_char *s)
{
	uint8_t i = 0;

	if (xSemaphoreTake( debug_tx_lock, 20 / portTICK_RATE_MS) != pdTRUE) return 0;
	
	while(*s)
	{
		if (debug_putchar(*s) == -1)
		{	/*buffer full, discard the rest*/
/*			taskYIELD();*/
			xSemaphoreGive( debug_tx_lock );
			return i;			
		}
		else
		{
			s++;
			i++;
		}
	}
	xSemaphoreGive( debug_tx_lock );
  return i;
}
Ejemplo n.º 16
0
void
bootp_handle_reply(void)
{
    int i;
    struct bootp *pk = uip_appdata;

    if(pk->bp_op != BOOTREPLY)
	return;					/* ugh? shouldn't happen */

    if(pk->bp_htype != HTYPE_ETHERNET)
	return;

    for(i = 0; i < 4; i ++) {
	if(pk->bp_xid[i] != uip_udp_conn->appstate.bootp.xid[i])
	    return;				/* session id doesn't match */

	if(pk->bp_vend[i] != replycookie[i])
	    return;				/* reply cookie doesn't match */
    }


    /*
     * looks like we have received a valid bootp reply,
     * prepare to override eeprom configuration
     */
    uip_ipaddr_t ips[5];
    memset(&ips, 0, sizeof(ips));

    /* extract our ip addresses, subnet-mask and gateway ... */
    memcpy(&ips[0], pk->bp_yiaddr, 4);
    uip_sethostaddr(&ips[0]);

    debug_printf ("BOOTP: configured new ip address %d.%d.%d.%d\n",
                  ((unsigned char *) ips)[0], ((unsigned char *) ips)[1],
                  ((unsigned char *) ips)[2], ((unsigned char *) ips)[3]);

    unsigned char *ptr = pk->bp_vend + 4;
    while(*ptr != 0xFF) {
	switch(* ptr) {
	case TAG_SUBNET_MASK:
	    memcpy(&ips[1], &ptr[2], 4);
	    uip_setnetmask(&ips[1]);
	    break;

	case TAG_GATEWAY:
	    memcpy(&ips[2], &ptr[2], 4);
	    uip_setdraddr(&ips[2]);
	    break;
#ifdef DNS_SUPPORT
        case TAG_DOMAIN_SERVER:
	    memcpy(&ips[3], &ptr[2], 4);
            resolv_conf(&ips[3]);
            break;
#endif
#ifdef NTP_SUPPORT
        case TAG_NTP_SERVER:
            /* This will set the ntp connection to the server set by the bootp
             * request
             */
	    memcpy(&ips[4], &ptr[2], 4);
            ntp_conf(&ips[4]);
            break;
#endif
	}

	ptr = ptr + ptr[1] + 2;
    }

    /* Remove the bootp connection */
    uip_udp_remove(uip_udp_conn);

#ifdef BOOTP_TO_EEPROM_SUPPORT
    eeprom_save(ip, &ips[0], IPADDR_LEN);
    eeprom_save(netmask, &ips[1], IPADDR_LEN);
    eeprom_save(gateway, &ips[2], IPADDR_LEN);
#ifdef DNS_SUPPORT
    eeprom_save(dns_server, &ips[3], IPADDR_LEN);
#endif
#ifdef NTP_SUPPORT
    eeprom_save(ntp_server, &ips[4], IPADDR_LEN);
#endif
#endif /* BOOTP_TO_EEPROM_SUPPORT */

#ifdef DYNDNS_SUPPORT
    dyndns_update();
#endif

#if defined(TFTP_SUPPORT) && defined(BOOTLOADER_SUPPORT)
    if(pk->bp_file[0] == 0)
	return;					/* no boot filename provided */

    debug_putstr("load:");
    debug_putstr(pk->bp_file);
    debug_putchar('\n');

    /* create tftp connection, which will fire the download request */
    uip_ipaddr_t ip;
    uip_ipaddr(&ip, pk->bp_siaddr[0], pk->bp_siaddr[1],
	       pk->bp_siaddr[2], pk->bp_siaddr[3]);

    tftp_fire_tftpomatic(&ip, pk->bp_file);
#endif /* TFTP_SUPPORT */
}
Ejemplo n.º 17
0
int debug_serial_device_putchar(struct serial_device* dev, char c) {
	debug_putchar(c);
	return 1;
}
Ejemplo n.º 18
0
/*
 * Fast receive interrupt handler.
 * Fetch and process all received data from the network controller.
 */
static int
slip_receive_data (slip_t *u)
{
    unsigned char c = 0;

    for (;;) {
#ifdef clear_receive_errors
        clear_receive_errors (u->port);
#else
        if (test_frame_error (u->port)) {
            debug_putchar (0, '%');
            /*debug_printf ("slip: FRAME ERROR\n");*/
            clear_frame_error (u->port);
        }
        if (test_parity_error (u->port)) {
            debug_putchar (0, '@');
            /*debug_printf ("slip: PARITY ERROR\n");*/
            clear_parity_error (u->port);
        }
        if (test_overrun_error (u->port)) {
            debug_putchar (0, '#');
            /*debug_printf ("slip: RECEIVE OVERRUN\n");*/
            clear_overrun_error (u->port);
        }
        if (test_break_error (u->port)) {
            /*debug_printf ("BREAK DETECTED\n");*/
            clear_break_error (u->port);
        }
#endif
#ifndef TRANSMIT_IRQ
        if (test_transmitter_enabled (u->port))
            slip_transmit_start (u);
#endif
        /* Check that receive data is available,
         * and get the received byte. */
        if (! test_get_receive_data (u->port, &c)) {
            enable_receive_interrupt (u->port);
            return 1;
        }

        debug_printf ("<%x> ", c);
        if (! u->in_ptr)
            continue;

        switch (c) {
        case SLIP_FLAG:
            u->in_escape = 0;
            if (u->in_ptr > u->in->payload) {
                /* Received whole packet. */
                return 0;
            }
            break;

        case SLIP_ESC:
            u->in_escape = 1;
            break;

        default:
            if (u->in_escape) {
                u->in_escape = 0;
                switch (c) {
                case SLIP_ESC_FLAG:
                    c = SLIP_FLAG;
                    break;
                case SLIP_ESC_ESC:
                    c = SLIP_ESC;
                    break;
                }
            }
            if (u->in_ptr >= u->in_limit) {
                /* Ignore input on buffer overflow. */
                debug_putchar (0, '!');
                /*				debug_printf ("slip_receive_data: ignore packet - buffer overflow\n");*/
                ++u->netif.in_errors;
                u->in_ptr = u->in->payload;
                break;
            }
            *u->in_ptr++ = c;
            ++u->netif.in_bytes;
            break;
        }
    }
}
Ejemplo n.º 19
0
__inline void put_char(unsigned char ch)
{
  debug_putchar(ch);    
}
Ejemplo n.º 20
0
int send(char c)
{debug_putchar(c);
return 1;}
Ejemplo n.º 21
0
void
tftp_handle_packet(void)
{
    /*
     * overwrite udp connection information (i.e. take from incoming packet)
     */
    uip_ipaddr_copy(uip_udp_conn->ripaddr, BUF->srcipaddr);
    uip_udp_conn->rport = BUF->srcport;

    /*
     * care for incoming tftp packet now ...
     */
    uint16_t i;
    flash_base_t base;
    struct tftp_hdr *pk = uip_appdata;

    switch(HTONS(pk->type)) {
#ifndef TFTP_UPLOAD_ONLY
    /*
     * streaming data back to the client (download) ...
     */
    case 1: /* read request */
	uip_udp_conn->appstate.tftp.download = 1;
	uip_udp_conn->appstate.tftp.transfered = 0;
	uip_udp_conn->appstate.tftp.finished = 0;

        bootload_delay = 0;                      /* Stop bootloader. */

	goto send_data;

    case 4: /* acknowledgement */
	if(uip_udp_conn->appstate.tftp.download != 1)
	    goto error_out;

	if(HTONS(pk->u.ack.block) < uip_udp_conn->appstate.tftp.transfered
	   || (HTONS(pk->u.ack.block) >
	       uip_udp_conn->appstate.tftp.transfered + 1))
	    goto error_out; /* ack out of order */

	uip_udp_conn->appstate.tftp.transfered = HTONS(pk->u.ack.block);

    send_data:
	if(uip_udp_conn->appstate.tftp.finished) {
            bootload_delay = CONF_BOOTLOAD_DELAY;    /* Restart bootloader. */
	    return;                                  /* nothing more to do */
	}

	pk->type = HTONS(3); /* data packet */
	pk->u.data.block = HTONS(uip_udp_conn->appstate.tftp.transfered + 1);

	base = TFTP_BLOCK_SIZE * uip_udp_conn->appstate.tftp.transfered;

	/* base overflowed ! */
#if FLASHEND == UINT16_MAX
	if(uip_udp_conn->appstate.tftp.transfered && base == 0)
#else
	if(base > FLASHEND)
#endif
	{
	    uip_udp_send(4); /* send empty packet to finish transfer */
	    uip_udp_conn->appstate.tftp.finished = 1;
	    return;
	}

	for (i = 0; i < TFTP_BLOCK_SIZE; i++)
	  pk->u.data.data[i] = __pgm_read_byte (base + i);

	uip_udp_send(4 + TFTP_BLOCK_SIZE);
	uip_udp_conn->appstate.tftp.transfered ++;
	break;
#endif /* not TFTP_UPLOAD_ONLY */

    /*
     * streaming data from the client (firmware upload) ...
     */
    case 2: /* write request */
	uip_udp_conn->appstate.tftp.download = 0;
	uip_udp_conn->appstate.tftp.transfered = 0;
	uip_udp_conn->appstate.tftp.finished = 0;

	pk->u.ack.block = HTONS(0);
	goto send_ack;

    case 3: /* data packet */
        bootload_delay = 0;                      /* Stop bootloader. */

	if(uip_udp_conn->appstate.tftp.download != 0)
	    goto error_out;

	if(HTONS(pk->u.ack.block) < uip_udp_conn->appstate.tftp.transfered)
	    goto error_out;                     /* too early */

	if(HTONS(pk->u.ack.block) == uip_udp_conn->appstate.tftp.transfered)
	    goto send_ack;			/* already handled */

	if(HTONS(pk->u.ack.block) > uip_udp_conn->appstate.tftp.transfered + 1)
	    goto error_out;			/* too late */

	base = TFTP_BLOCK_SIZE * (HTONS(pk->u.ack.block) - 1);

	for(i = uip_datalen() - 4; i < TFTP_BLOCK_SIZE; i ++)
	    pk->u.data.data[i] = 0xFF;	        /* EOF reached, init rest */

	debug_putchar('.');

	for(i = 0; i < TFTP_BLOCK_SIZE / SPM_PAGESIZE; i ++)
	    flash_page(base + i * SPM_PAGESIZE,
		       pk->u.data.data + i * SPM_PAGESIZE);

	if(uip_datalen() < TFTP_BLOCK_SIZE + 4) {
	    uip_udp_conn->appstate.tftp.finished = 1;

#           ifdef TFTPOMATIC_SUPPORT
            bootload_delay = 1;                      /* ack, then start app */
#           else
            bootload_delay = CONF_BOOTLOAD_DELAY;    /* Restart bootloader. */
#           endif

            debug_putstr("end\n");
	}

	uip_udp_conn->appstate.tftp.transfered = HTONS(pk->u.ack.block);

    send_ack:
	pk->type = HTONS(4);
	uip_udp_send(4);              /* send ack */
	break;

    /*
     * protocol errors
     */
    error_out:
    case 5: /* error */
    default:
	pk->type = HTONS(5);          /* data packet */
	pk->u.error.code = HTONS(0);  /* undefined error code */
	pk->u.error.msg[0] = 0;       /* yes, really expressive */
	uip_udp_send(5);
	break;
    }
}
Ejemplo n.º 22
0
void debug_putc (char c)
{
	debug_putchar (0, c);
}
Ejemplo n.º 23
0
void
debug_puts (const char *p)
{
    for (; *p; ++p)
        debug_putchar (0, *p);
}
Ejemplo n.º 24
0
void debug_write(const char*c,int i)
{int k;
for (k=0;k<i;k++)
debug_putchar(*(c+k));
};