Beispiel #1
0
void LEUART0_IRQHandler(void)
{
  if (LEUART0->IF & LEUART_IF_RXDATAV)
  {
	  uint8_t data = LEUART0->RXDATA;
	  buf_write_byte(leu_rx_buf, data);
	  if (leu_rx_buf->count == 0)
		  LEUART0->IEN &= ~ LEUART_IEN_RXDATAV;  // disable rx interrupt
  }

  if (LEUART0->IF & LEUART_IF_TXBL)
  {
	  uint8_t data;
	  if (buf_read_byte(leu_tx_buf, & data))
	  {
		  while (LEUART0->SYNCBUSY)
			  ;
		  LEUART0->TXDATA = data;
	  }
	  else
		  LEUART0->IEN &= ~ LEUART_IEN_TXBL;  // disable tx interrupt
  }

  // XXX do we need to explicitly clear interrupts?
  //LEUART_IntClear(LEUART0, ???);
}
Beispiel #2
0
int buf_vunpack(Buf *self, char *fmt, va_list ap) {
	char *s;
	char *p;
	uint8_t *u8p;
	uint16_t *u16p;
	uint32_t *u32p;
	size_t len;
	int res;
	int bytes = 0;

	for (p = fmt; *p != '\0'; p++) {
		switch(*p) {
		case 'b': /* char */
			u8p = va_arg(ap, uint8_t*);
			res = buf_read_byte(self, u8p);
			break;
		case 'h': /* short */
			u16p = va_arg(ap, uint16_t*);
			res = buf_read_short(self, u16p);
			break;
		case 'u': /* uint */
			u32p = va_arg(ap, uint32_t*);
			res = buf_read_uint(self, u32p);
			break;
		case 's': /* string */
			s = va_arg(ap, char*);
			len = va_arg(ap, size_t);
			res = buf_read_string(self, s, len);
			break;
		default: /* illegal format */
			res = -1;
		}
		if (res == -1) {
			return -1;
		}
		bytes += res;
	}
	return bytes;
}
Beispiel #3
0
bool buf_read_char(buf_t *buf, char *c)
{
	return buf_read_byte(buf, (uint8_t *) c);
}