Ejemplo n.º 1
0
static void pc98_inhibit_repeat(void)
{
    uint8_t code;

    while (serial_recv()) ;
RETRY:
    PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
    _delay_ms(500);
    serial_send(0x9C);

    PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
    _delay_ms(100);
    while (!(code = serial_recv())) ;
    print("PC98: send 9C: "); print_hex8(code); print("\n");
    if (code != 0xFA) goto RETRY;



    PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
    _delay_ms(100);
    serial_send(0x70);

    PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
    _delay_ms(100);
    //code = serial_recv();
    while (!(code = serial_recv())) ;
    print("PC98: send 70: "); print_hex8(code); print("\n");
    if (code != 0xFA) goto RETRY;
}
Ejemplo n.º 2
0
Archivo: util.c Proyecto: B-Rich/morbo
/**
 * Output a single char.
 * Note: We allow only to put a char on the last line.
 */
int
out_char(unsigned value)
{
#define BASE(ROW) ((unsigned short *) (0xb8000+ROW*160))
  static unsigned int col;
  if (value!='\n')
    {
      unsigned short *p = BASE(24)+col;
      *p = 0x0f00 | value;
      col++;
    }
  if (col>=80 || value == '\n')
    {
      col=0;
      unsigned short *p=BASE(0);
      memcpy(p, p+80, 24*160);
      memset(BASE(24), 0, 160);
    }


  serial_send(value);

  if (value == '\n')
    serial_send('\r');

  return value;
}
Ejemplo n.º 3
0
//------------------------------------------------------------------------
// This re-sends an ARP request if there was no response to
// the first one.	 It is called every 0.5 seconds.  If there
// is no response after 2 re-tries, the datagram that IP was 
// trying to send is deleted
//-----------------------------------------------------------------------
void arp_retransmit(void)
{
	static UCHAR idata retries = 0; 
	
	if ((waiting_for_arp) && (wait.timer))
	{
		wait.timer--;
		if (wait.timer == 0)
		{
			retries++;
			if (retries <= 2)
			{
				if (debug) serial_send("ARP: Re-sending ARP broadcast\r");
	 			arp_send(NULL, wait.ipaddr, ARP_REQUEST);
				wait.timer = ARP_TIMEOUT;
			}
			else
			{	
				if (debug) serial_send("ARP: Gave up waiting for response\r");
	 			wait.timer = 0;
				waiting_for_arp = 0;
				free(wait.buf);
			}
		}
	}
}
Ejemplo n.º 4
0
void main()
{
	uchar buf=0;
	uint i;
	Init_Device();
	serial_init();
//	delay05ms(1);
	buf = EEPROM_ByteRead(0);//读0字节
	serial_send(&buf);	 //串口发送

	EEPROM_ByteWrite(0, 0x64);  //写0字节为100

	buf = 0;//清0
	buf = EEPROM_ByteRead(0); //读0字节
	serial_send(&buf);	  //串口发送0字节
	led = 0;
//	clear_24cXX(32768);
	led = 1;
	for(i=0;i<32768;i++)
	{
		buf = EEPROM_ByteRead(i);//读0字节
		serial_send(&buf);	 //串口发送
	}
	while(1)
	{
		;		
	}
 }
Ejemplo n.º 5
0
static void send_consumer(uint16_t data)
{
    uint16_t bits = usage2bits(data);
    serial_send(0xFD);  // Raw report mode
    serial_send(3);     // length
    serial_send(3);     // descriptor type
    serial_send(bits&0xFF);
    serial_send((bits>>8)&0xFF);
}
Ejemplo n.º 6
0
int serial_sendv(int id, void* pdata1, unsigned int size1, void* pdata2, unsigned int size2)
{
  if(serial_send(id, pdata1, size1) != size1)
  {
    return -1;
  }
  if(serial_send(id, pdata2, size2) != size2)
  {
    return -1;
  }
  return 0;
}
Ejemplo n.º 7
0
static void command_debounce(const char * command)
{
  if ( command[1] == '?' ) 
  {
    char buf[5];
    strcpy(buf, command);  
    setval(buf, board_config->debounce, 1,4);
    serial_send(buf);
  }
  else
  {
    board_config->debounce = getval(command, 1, 4);    
    serial_send(command);
  }  
}
Ejemplo n.º 8
0
void usart1_isr(void)
{
    unsigned char c;

	/* Check if we were called because of RXNE. */
	if (((USART_CR1(USART1) & USART_CR1_RXNEIE) != 0) &&
        ((USART_SR(USART1) & USART_SR_RXNE) != 0) &&
        (!serial_rb_full(&srx))) {
        c = serial_recv();
        serial_rb_write(&srx, c);
	}
	/* Check if we were called because of TXE. */
	else if (((USART_CR1(USART1) & USART_CR1_TXEIE) != 0) &&
             ((USART_SR(USART1) & USART_SR_TXE) != 0)) {

        if(!serial_rb_empty(&stx)) {
            serial_send(serial_rb_read(&stx));
        }
        else {
            /* Disable the TXE interrupt, it's no longer needed. */
            USART_CR1(USART1) &= ~USART_CR1_TXEIE;
        }
	}
	else {
        c = serial_recv();
	}
}
Ejemplo n.º 9
0
void matrix_init(void)
{
    DDRD |= (1<<6);
    PORTD |= (1<<6);
    //debug_enable = true;

    serial_init();

    // initialize matrix state: all keys off
    for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;

    // wait for keyboard coming up
    // otherwise LED status update fails
    print("Reseting ");
    while (1) {
        print(".");
        while (serial_recv());
        serial_send(0x01);
        _delay_ms(500);
        if (serial_recv() == 0xFF) {
            _delay_ms(500);
            if (serial_recv() == 0x04)
                break;
        }
    }
    print(" Done\n");
    return;
}
Ejemplo n.º 10
0
static void em_decode(struct gps_state *gps)
{
    if (packet_idx < 1) return;

#ifndef __arm__
    fprintf(stderr, "receiving %x\n", packet[0]);
#endif

    /* NMEA lines should start with a '$' */
    if (packet[0] == 'E') {
        /* recognize earthmate's 'EARTHA' message */
        if (packet_idx >= 6 && memcmp(packet, "EARTHA", 6) == 0)
            serial_send("EARTHA\r\n", 8);
        return;
    }

    draw_activity(0);

    /* verify checksum XXX */

    switch(INT16(&packet[0])) {
    case 1000: em_1000geodpos(gps); break;
    case 1002: em_1002chsum(gps); break;
    case 1003: em_1003sats(gps); break;
    }
}
Ejemplo n.º 11
0
void log_message(log_level_e lvl, char *msg) {
  int sent_bytes;
  int msg_len;
  if ((sent_bytes = serial_get_sent_bytes(USB_COMM)) > 0) {
    g_serial_state.bytes_buffered -= sent_bytes;
    if (g_serial_state.bytes_buffered > 0) {
      strncpy(&g_serial_state.serbuf[sent_bytes],
	      &g_serial_state.serbuf[0],
	      g_serial_state.bytes_buffered);
    }
  }

  // at this point everything there will be bytes_buffered
  // bytes sitting at the start of the buffer
  msg_len = strlen(msg);
  if ((msg_len + 2 + g_serial_state.bytes_buffered) > sizeof g_serial_state.serbuf) {
    g_serial_state.bytes_buffered = 0;
  }
  strncpy(&g_serial_state.serbuf[g_serial_state.bytes_buffered],
	  msg,
	  msg_len);
  g_serial_state.serbuf[g_serial_state.bytes_buffered + msg_len] = '\r';
  g_serial_state.serbuf[g_serial_state.bytes_buffered + msg_len + 1] = '\n';
  g_serial_state.bytes_buffered += (msg_len + 2);
  serial_send(USB_COMM, g_serial_state.serbuf, g_serial_state.bytes_buffered);
}
Ejemplo n.º 12
0
static int fetch_nodelist(struct motefs_node *nodes)
{
    int n, i, k, op, result, res = 0;
    uint8_t buf[MFS_DATA_SIZE];

    serial_lock();

    if (serial_send(0, MFS_OP_NODELIST, NULL, 0))
    {
        res = -EIO;
        goto ret;
    }

    /* the mote should send exactly `node_count` packets */
    for (i = 0; i < node_count; i++)
    {
        res = serial_receive(&n, &op, &result, buf, sizeof buf);
        if (res == -1 || !result || !(op & MFS_OP_NODELIST))
        {
            res = -1;
            goto ret;
        }

        nodes[n].type = result;
        for (k = 0; k < MFS_DATA_SIZE; k++)
            nodes[n].name[k] = buf[k];
    }

ret:
    serial_unlock();
    if (res < 0)
        return -1;
    return 0;
}
Ejemplo n.º 13
0
static void taip_init(void)
{
    char *cmd;
    
    /* Report position every second */
    cmd = ">FPV00010000<";
    serial_send(cmd, sizeof(cmd));

    /* Report time every 15 seconds */
    cmd = ">FTM00150000<";
    serial_send(cmd, sizeof(cmd));

    /* Get current time */
    cmd = ">QTM<";
    serial_send(cmd, sizeof(cmd));
}
Ejemplo n.º 14
0
void serial_print_char( const char myChar )
{
	wait_for_sending_to_finish();
	memset( send_buffer, 0, sizeof(send_buffer) );
	send_buffer[0] = myChar;
	serial_send( USB_COMM, send_buffer, 1 );
}
Ejemplo n.º 15
0
Archivo: ui.c Proyecto: russells/hc2
static void show_temperature(int16_t t)
{
	const char *tstring;

	SERIALSTR("t: ");
	serial_send_int(t);
	if (INVALIDTI == t) {
		tstring = "  ???  ";
	} else if (LOWTI == t) {
		tstring = "  ?" "?-  ";
	} else if (MINTI == t) {
		tstring = "  ?--  ";
	} else if (HIGHTI == t) {
		tstring = "  ?" "?+  ";
	} else if (MAXTI == t) {
		tstring = "  ?++  ";
	} else {
		SERIALSTR(":");
		t -= MINTI;	    /* Move the scale up to zero-based. */
		Q_ASSERT( t >= 0 ); /* Range checking. */
		Q_ASSERT( t < NCONVERSIONS );
		t /= 2;		/* Scale to whole degrees. */
		serial_send_int(t);
		tstring = tstrings[t];
	}
	SERIALSTR("\"");
	serial_send(tstring);
	SERIALSTR("\"\r\n");
	lcd_showstring(tstring);
}
Ejemplo n.º 16
0
void command_parse(uint32_t current_timestamp, const char * command, int len)
{
  if ( len != 5 )
  {
    serial_send_error(3);
    return;
  }
  
  switch (command[0])
  {
  case 'V':
    serial_send("V0100"); 
    break;
  case 'D':
    command_ddr(command);
    break;
  case 'B':
    command_debounce(command);
    break;
  case 'P':
    command_pin(command);    
    break;    
  case 'R':
    command_factory_reset(command);
    break;  
    
  default:
    serial_send_error(4);
    
  }  
}
Ejemplo n.º 17
0
void print_normal_time(struct NormalTime nt)
{
	char buf[10];

	snprintf(buf, 10, "%02d:%02d:%02d", nt.h, nt.m, nt.s);
	serial_send(buf);
}
Ejemplo n.º 18
0
void print_usb( char *buffer )
{
    int length;
    length = strlen( buffer );
    serial_send( USB_COMM, buffer, length );
    wait_for_sending_to_finish();
}
Ejemplo n.º 19
0
static void pc98_send(uint8_t data)
{
    PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
    _delay_ms(1);
    serial_send(data);
    _delay_ms(1);
    PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
}
Ejemplo n.º 20
0
void serial_sendstr(char* str)
{
	while (1)
	{
		switch (*str)
		{
			case '\0':
				return;
			case '\n':
				serial_send('\r');
			default:
				serial_send(*str);
		}
		str++;
	}
	return;
}
Ejemplo n.º 21
0
// do calibration
void slave_calibrate()
{
	serial_send("\xB4",1);
	int tmp_buffer[5];

	// read 10 characters (but we won't use them)
	serial_receive_blocking((char *)tmp_buffer, 10, 100);
}
Ejemplo n.º 22
0
void rob_serial_send_usb_comm (char * pBuffer, unsigned char size)
{
    vTaskSuspendAll();
    {
        serial_send (USB_COMM, pBuffer, size);
    }
    xTaskResumeAll();
}
Ejemplo n.º 23
0
uint32_t write_serial(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
	uint32_t sent = 0;
	while (sent < size) {
		serial_send((int)node->device, buffer[sent]);
		sent++;
	}
	return size;
}
Ejemplo n.º 24
0
void zodiac_send(int type, unsigned short *dat, int dlen)
{
    struct zodiac_header h;

    h.flags = 0;

    h.sync = 0x81ff;
    h.id = (unsigned short) type;
    h.ndata = dlen - 1; /* data checksum word doesn't count */
    h.csum = zodiac_checksum((unsigned short *) &h, 4);

    /* Add data checksum */
    dat[dlen - 1] = zodiac_checksum(dat, dlen - 1);

    serial_send((char *)&h, sizeof(h));
    serial_send((char *)dat, (sizeof(unsigned short) * dlen));
}
Ejemplo n.º 25
0
void dbg_out(){
	dbg_cnt++;
	debug_data[0].id = dbg_cnt;
	serial_send(
			SERIAL_PORT,
			sizeof( debug_data ),
			(uint8_t *)&debug_data
	);
}
Ejemplo n.º 26
0
interrupt(USCIAB0TX_VECTOR) USCI0TX_ISR(void)
{
	if(!serial_rb_empty(&stx)) {
    	serial_send(serial_rb_read(&stx));
    }
    else {
		IE2 &= ~UCA0TXIE; 
    }
}
Ejemplo n.º 27
0
static void sio_data_write(void *opaque, uint32_t addr, uint32_t value)
{
    SerialPortState *s = opaque;

    if (s->status & SIO_STAT_TXRDY) {
        s->status &= ~SIO_STAT_TXE;
        serial_send(s, value);
    }
}
Ejemplo n.º 28
0
int main()
{
	clear();	// clear the LCD
	print("Send serial");
	lcd_goto_xy(0, 1);	// go to start of second LCD row
	print("or press B");

	// Set the baud rate to 9600 bits per second.  Each byte takes ten bit
	// times, so you can get at most 960 bytes per second at this speed.
	serial_set_baud_rate(USB_COMM, 9600);

	// Start receiving bytes in the ring buffer.
	serial_receive_ring(USB_COMM, receive_buffer, sizeof(receive_buffer));

    while(1)
    {
		// USB_COMM is always in SERIAL_CHECK mode, so we need to call this
		// function often to make sure serial receptions and transmissions
		// occur.
		serial_check();

		// Deal with any new bytes received.
		check_for_new_bytes_received();

		// If the user presses the middle button, send "Hi there!"
		// and wait until the user releases the button.
		if (button_is_pressed(MIDDLE_BUTTON))
		{
			wait_for_sending_to_finish();
			memcpy_P(send_buffer, PSTR("Hi there!\r\n"), 11);
			serial_send(USB_COMM, send_buffer, 11);
			send_buffer[11] = 0;	// terminate the string
			clear();				// clear the LCD
			lcd_goto_xy(0, 1);		// go to start of second LCD row
			print("TX: ");
			print(send_buffer);

			// Wait for the user to release the button.  While the processor is
			// waiting, the OrangutanSerial library will not be able to receive
			// bytes from the USB_COMM port since this requires calls to the
			// serial_check() function, which could cause serial bytes to be
			// lost.  It will also not be able to send any bytes, so the bytes
			// bytes we just queued for transmission will not be sent until
			// after the following blocking function exits once the button is
			// released.  If any of this is a concern, you can replace the
			// following line with:
			// do
			// {
			//   while (button_is_pressed(MIDDLE_BUTTON))
			//     serial_check();	// receive and transmit as needed
			//   delay_ms(10);		// debounce the button press/release
			// }
			// while (button_is_pressed(MIDDLE_BUTTON));
			wait_for_button_release(MIDDLE_BUTTON);
		}
    }
}
Ejemplo n.º 29
0
static void bluefruit_serial_send(uint8_t data)
{
#ifdef BLUEFRUIT_TRACE_SERIAL
    dprintf(" ");
    debug_hex8(data);
    dprintf(" ");
#endif
    serial_send(data);
}
Ejemplo n.º 30
0
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
	// put your per-action keyboard code here
	// runs for every action, just before processing by the firmware
  if (record->event.pressed) {
    #ifdef LED_ENABLE
      serial_send((record->event.key.row*16)+record->event.key.col);
    #endif
  }
	return process_record_user(keycode, record);
}