コード例 #1
0
ファイル: usart.c プロジェクト: bgamari/solar-charger-v2
void usart1_isr(void)
{
  if (usart_get_flag(USART1, USART_SR_RXNE)) {
    char c = usart_recv(USART1);
    if (c == '\n') {
      if (rx_head > 0) {
        rx_buf[rx_head] = 0;
        usart_on_line_recv(rx_buf, rx_head);
      }
      rx_head = 0;
    } else {
      rx_buf[rx_head] = c;
      rx_head = (rx_head + 1) % sizeof(rx_buf);
    }
  }

  if (usart_get_flag(USART1, USART_SR_TXE)) {
    if (waiting_tx_bytes() > 0) {
      usart_send(USART1, tx_buf[tx_tail]);
      tx_tail = (tx_tail + 1) % sizeof(tx_buf);
    } else {
      usart_disable_tx_interrupt(USART1);
    }
  }
}
コード例 #2
0
ファイル: STM32_USART.c プロジェクト: lireric/ssn
void usart3_isr(void)
{

	long xHigherPriorityTaskWoken = pdFALSE;
	char cChar;

	if (usart_get_flag(USART3, USART_SR_TXE) == true) {
		/* The interrupt was caused by the THR becoming empty.  Are there any
		 more characters to transmit? */
		if (xQueueReceiveFromISR(xCharsForTx[2], &cChar,
				&xHigherPriorityTaskWoken)) {
			gpio_set(GPIO_BANK_USART3_RTS, GPIO_USART3_RTS); // set RTS
			/* A character was retrieved from the buffer so can be sent to the THR now. */
			usart_send(USART3, (uint8_t) cChar);
		} else {
//			gpio_clear(GPIO_BANK_USART3_RTS, GPIO_USART3_RTS); // clear RTS
		}
	}

	if (usart_get_flag(USART3, USART_SR_RXNE) == true) {
		cChar = (char) usart_recv(USART3);
		xQueueSendFromISR(xRxedChars[2], &cChar, &xHigherPriorityTaskWoken);
	}

// ----- transmission complete:
	if (usart_get_flag(USART3, USART_SR_TC) == true) {
		gpio_clear(GPIO_BANK_USART3_RTS, GPIO_USART3_RTS); // clear RTS
		USART_SR(USART3) &= ~USART_SR_TC;	// reset flag TC
		usart_disable_tx_interrupt(USART3);
	}

	portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);

}
コード例 #3
0
ファイル: usart.c プロジェクト: liangzelang/Bootloader_PX4_SD
void uart7_cout(uint32_t whichUsart,uint8_t *buf,unsigned len)
{
	while (len--) {
			usart_send_blocking(whichUsart, *buf++);
			while(usart_get_flag(UART7, USART_SR_TC) !=1);
		}
}
コード例 #4
0
ファイル: gps.c プロジェクト: cuspaceflight/DorMouse
static int command(char *command, size_t length)
{
    size_t i;

    calculate_crc_and_ack(command, length);

    for (i = 0; i < length; i++)
        usart_send_blocking(USART2, command[i]);

    timer_set_counter(TIM5, 0);
    timer_clear_flag(TIM5, TIM_SR_UIF);
    timer_enable_counter(TIM5);

    for (i = 0; i < sizeof(expect_ack); )
    {
        while (!timer_get_flag(TIM5, TIM_SR_UIF) &&
               !usart_get_flag(USART2, USART_SR_RXNE));

        if (timer_get_flag(TIM5, TIM_SR_UIF))
            break;

        if (expect_ack[i] != usart_recv(USART2))
            break;
    }

    timer_disable_counter(TIM5);

    return (i == sizeof(expect_ack));
}
コード例 #5
0
ファイル: bsp.c プロジェクト: mour/ratfist-stm32
/**
 * Interrupt handler for the USART1 peripheral.
 *
 * If the interrupt was caused by a received character, the handler adds the
 * chararacter to the rx_buffer. If the interrupt was caused by the peripheral
 * being ready to send a character, the handler takes one from the tx_buffer,
 * and writes it to the peripheral. In case the interrupt was caused by a USART
 * peripheral buffer overrun (typically happens during debugging), the handler
 * clears that interrupt flag.
 */
void usart1_isr(void)
{
	if (usart_get_flag(USART1, USART_ISR_RXNE)) {
		char ch = (char) usart_recv(USART1);
		os_char_buffer_write_ch(&bsp_rx_buffer, ch);

	} else if (usart_get_flag(USART1, USART_ISR_TXE)) {
		char ch = '\0';
		if (os_char_buffer_read_ch(&bsp_tx_buffer, &ch)) {
			usart_send(USART1, (uint8_t) ch);
		} else {
			usart_disable_tx_interrupt(USART1);
		}

	} else if (usart_get_flag(USART1, USART_ISR_ORE)) {
		USART_ICR(USART1) |= USART_ICR_ORECF;
	}
}
コード例 #6
0
ファイル: gps.c プロジェクト: cuspaceflight/DorMouse
static int silence_nmea()
{
    int attempt;
    size_t i;

    /* Configure the GPS */
    for (attempt = 0; attempt < 4; attempt++)
    {
        calculate_crc_and_ack(set_port, sizeof(silence_nmea));

        for (i = 0; i < sizeof(set_port); i++)
            usart_send_blocking(USART2, set_port[i]);

        timer_clear_flag(TIM5, TIM_SR_UIF);
        timer_set_counter(TIM5, 0);
        timer_enable_counter(TIM5);

        for (i = 0; i < sizeof(expect_ack); )
        {
            while (!timer_get_flag(TIM5, TIM_SR_UIF) &&
                   !usart_get_flag(USART2, USART_SR_RXNE));

            if (timer_get_flag(TIM5, TIM_SR_UIF))
                break;

            if (expect_ack[i] == usart_recv(USART2))
                i++;
            else
                i = 0;
        }

        timer_disable_counter(TIM5);

        if (i < sizeof(expect_ack))
            continue;
        else
            break;
    }

    while (usart_get_flag(USART2, USART_SR_RXNE))
        usart_recv(USART2);

    return attempt < 4;
}
コード例 #7
0
ファイル: commslib.c プロジェクト: ksarkies/SMPS
void usart2_isr(void)
{
	static uint16_t data;

	/* Check if we were called because of RXNE. */
	if (usart_get_flag(USART2,USART_SR_RXNE))
	{
		/* If buffer full we'll just drop it */
		buffer_put(receiveBuffer, (uint8_t) usart_recv(USART2));
	}
	/* Check if we were called because of TXE. */
	if (usart_get_flag(USART2,USART_SR_TXE))
	{
		/* If buffer empty, disable the tx interrupt */
		data = buffer_get(sendBuffer);
		if ((data & 0xFF00) > 0) usart_disable_tx_interrupt(USART2);
		else usart_send(USART2, (data & 0xFF));
	}
}
コード例 #8
0
ファイル: serial_stm32.c プロジェクト: JamesLinus/ARM-Ports
void usart1_isr(void)
{
	static UNS16 data;

/* Check if we were called because of RXNE. */
	if (usart_get_flag(USART1,USART_SR_RXNE))
	{
/* Put to temporary message buffer */
		data = (UNS8) usart_recv(USART1);
		message_temp[msg_recv_status] = (UNS8) data;
		msg_recv_status++;
/* At this point we should check for integrity of the message, but there is no
way to recover if the message length sent is wrong. So we'll do what we can and
hope we can catch up eventually. */
		if ((msg_recv_status > 3) && (message_temp[3] > 8))
		{
/* Bad message length - abort and restart a new message */
			msg_recv_status = 0;
		}
/* Check if we are finished (message length is in element 3) */
		else if (msg_recv_status == 4 + message_temp[3])
		{
			msg_recv_status = 0;
			msg_received++;			/* Signal another message arrived */
			UNS8 i;
/* Dump to buffer; if full we'll just have to drop it */
			for (i=0; i < 4 + message_temp[3]; i++)
				buffer_put(receive_buffer,message_temp[i]);
		}
	}
/* Check if we were called because of TXE. */
	else if (usart_get_flag(USART1,USART_SR_TXE))
	{
		data = buffer_get(send_buffer);
/* If buffer empty, disable the tx interrupt */
		if ((data & 0xFF00) > 0) usart_disable_tx_interrupt(USART1);
		else
        {
                usart_send(USART1, (data & 0xFF));
        }
	}
}
コード例 #9
0
ファイル: debug-uart.c プロジェクト: jimmyH/contiki
void usart1_isr(void)
{
	char c;
	if (usart_get_flag(USART1, USART_SR_TXE)) {
		if (!queue_is_empty(&uart_tx_buf)) {
			queue_dequeue(&uart_tx_buf, &c);
			usart_send(USART1, (uint16_t)c);
		} else {
			usart_disable_tx_interrupt(USART1);
		}
	}


	if (usart_get_flag(USART1, USART_SR_RXNE)) {
		if (!queue_is_full(&uart_rx_buf)) {
			c = usart_recv(USART1);
			queue_enqueue(&uart_rx_buf, &c);
		}
	}
}
コード例 #10
0
ファイル: board_fy20ap.cpp プロジェクト: px4dev/mavmon
OS_INTERRUPT void
usart1_isr(void)
{
	OS::scmRTOS_ISRW_TYPE ISR;

	/* receiver not empty? */
	if (usart_get_flag(USART1, USART_SR_RXNE))
		board_fy20ap.com_rx(usart_recv(USART1));

	/* transmitter ready? */
	if (usart_get_flag(USART1, USART_SR_TXE)) {

		uint8_t c;

		if (board_fy20ap.com_tx(c)) {
			usart_send(USART1, c);

		} else {
			/* clear TX empty interrupt as we have no data */
			usart_disable_tx_interrupt(USART1);
		}
	}
}
コード例 #11
0
/* USART ISR */
void usart1_isr(void)
{
/* Find out what interrupted and get or send data as appropriate */
	/* Check if we were called because of RXNE. */
	if (usart_get_flag(USART1,USART_SR_RXNE))
	{
		/* If buffer full we'll just drop it */
		buffer_put(receive_buffer, (uint8_t) usart_recv(USART1));
	}
	/* Check if we were called because of TXE. */
	if (usart_get_flag(USART1,USART_SR_TXE))
	{
		/* If buffer empty, disable the tx interrupt */
		uint16_t data = buffer_get(send_buffer);
		if (data == BUFFER_EMPTY)
		{
			usart_disable_tx_interrupt(USART1);
		}
		else
		{
			usart_send(USART1, data);
		}
	}
}
コード例 #12
0
ファイル: stm32f4-discovery.c プロジェクト: via/tfi-computer
int usart_tx_ready() {
  return usart_get_flag(USART1, USART_SR_TC);
}