예제 #1
0
파일: STM32_USART.c 프로젝트: lireric/ssn
long lSerialPutString( long lPort, const char * const pcString, unsigned long ulStringLength )
{
long lReturn;
unsigned long ul;

	if( lPort < serNUM_COM_PORTS )
	{
		lReturn = pdPASS;

		for( ul = 0; ul < ulStringLength; ul++ )
		{
			if( xQueueSend( xCharsForTx[ lPort ], &( pcString[ ul ] ), serPUT_STRING_CHAR_DELAY ) != pdPASS )
			{
				/* Cannot fit any more in the queue.  Try turning the Tx on to 
				clear some space. */
				usart_enable_tx_interrupt(xUSART[lPort]);
				vTaskDelay( serPUT_STRING_CHAR_DELAY );
				ul--;
				/* Go back and try again. */
				continue;
			}
		}

		usart_enable_tx_interrupt(xUSART[lPort]);
	}
	else
	{
		lReturn = pdFAIL;
	}

	return lReturn;
}
예제 #2
0
void serial_rxint(void)
{
  uint8_t data = usart_recv(USART2);;
  uint32_t next_head;

  // Pick off realtime command characters directly from the serial stream. These characters are
  // not passed into the buffer, but these set system state flag bits for realtime execution.
  switch (data) {
    case CMD_STATUS_REPORT: bit_true_atomic(sys.rt_exec_state, EXEC_STATUS_REPORT); break; // Set as true
    case CMD_CYCLE_START:   bit_true_atomic(sys.rt_exec_state, EXEC_CYCLE_START); break; // Set as true
    case CMD_FEED_HOLD:     bit_true_atomic(sys.rt_exec_state, EXEC_FEED_HOLD); break; // Set as true
    case CMD_SAFETY_DOOR:   bit_true_atomic(sys.rt_exec_state, EXEC_SAFETY_DOOR); break; // Set as true
    case CMD_RESET:         mc_reset(); break; // Call motion control reset routine.
    default: // Write character to buffer
      next_head = serial_rx_buffer_head + 1;
      if (next_head == RX_BUFFER_SIZE) { next_head = 0; }

      // Write data to buffer unless it is full.
      if (next_head != serial_rx_buffer_tail) {
        serial_rx_buffer[serial_rx_buffer_head] = data;
        serial_rx_buffer_head = next_head;

        #ifdef ENABLE_XONXOFF
          if ((serial_get_rx_buffer_count() >= RX_BUFFER_FULL) && flow_ctrl == XON_SENT) {
            flow_ctrl = SEND_XOFF;
            usart_enable_tx_interrupt(USART2);
          }
        #endif

      }
      //TODO: else alarm on overflow?
  }
}
예제 #3
0
void usart2_isr(void)
{
	static u8 data = 'A';

	/* Check if we were called because of RXNE. */
	if (((USART_CR1(USART2) & USART_CR1_RXNEIE) != 0) &&
	    ((USART_SR(USART2) & USART_SR_RXNE) != 0)) {

		/* Indicate that we got data. */
		gpio_toggle(GPIOD, GPIO12);

		/* Retrieve the data from the peripheral. */
		data = usart_recv(USART2);

		/* Enable transmit interrupt so it sends back the data. */
		usart_enable_tx_interrupt(USART2);
	}

	/* Check if we were called because of TXE. */
	if (((USART_CR1(USART2) & USART_CR1_TXEIE) != 0) &&
	    ((USART_SR(USART2) & USART_SR_TXE) != 0)) {

		/* Put data into the transmit register. */
		usart_send(USART2, data);

		/* Disable the TXE interrupt as we don't need it anymore. */
		usart_disable_tx_interrupt(USART2);
	}
}
예제 #4
0
파일: portserial.c 프로젝트: nucleron/yaplc
/* ----------------------- Enable USART interrupts -----------------------------*/
void
vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable )
{
    /* If xRXEnable enable serial receive interrupts. If xTxENable enable
     * transmitter empty interrupts.
     */
    if (xRxEnable)
    {
        txen = false;
        usart_enable_rx_interrupt(MB_USART);
    }
    else
    {
        usart_disable_rx_interrupt(MB_USART);
    }

    if (xTxEnable)
    {
        txen = true;
        gpio_set(MB_USART_TXEN_PORT, MB_USART_TXEN_PIN);

        usart_enable_tx_interrupt(MB_USART);
    }
    else
    {
        txen = false;
        usart_disable_tx_interrupt(MB_USART);
    }
}
예제 #5
0
int main(void)
{
	clock_setup();
	gpio_setup();
	usart_setup();
	spi_setup();
	buffer_init(send_buffer,BUFFER_SIZE);
	buffer_init(receive_buffer,BUFFER_SIZE);
	usart_enable_tx_interrupt(USART1);

/* Send a greeting message on USART1. */
	usart_print_string("SD Card SPI Mode Test\r\n");

	while (1)
	{
/* Command interface */
        if (buffer_input_available(receive_buffer))
        {
            char character = buffer_get(receive_buffer);
            if (character == 0x0D)
            {
                line[characterPosition] = 0;
                characterPosition = 0;
                parseCommand(line);
            }
            else line[characterPosition++] = character;
        }
	}

	return 0;
}
예제 #6
0
void Serial_stm32::flush(void)
{
    usart_enable_tx_interrupt(config_.device);

    // Wait until the transmit buffer is empty
    while (!tx_buffer_.empty())
    {
        ;
    }
}
예제 #7
0
파일: uart.c 프로젝트: ChuckM/libcpa
/*
 * uart_putc
 *
 * This pushes a character into the transmit buffer for
 * the channel and turns on TX interrupts (which will fire
 * because initially the register will be empty.) If the
 * ISR sends out the last character it turns off the transmit
 * interrupt flag, so that it won't keep firing on an empty
 * transmit buffer.
 */
void
uart_putc(int chan, char c) {
    uint32_t usart = channel_to_uart_map[chan];

    /* block if the transmit buffer is full */
    while (((nxt_xmit_ndx[chan] + 1) % UART_BUF_SIZE) == cur_xmit_ndx[chan]) {
        __asm__("NOP");
    }
    xmit_buf[chan][nxt_xmit_ndx[chan]] = c;
    nxt_xmit_ndx[chan] = (nxt_xmit_ndx[chan] + 1) % UART_BUF_SIZE;
    usart_enable_tx_interrupt(usart);
}
예제 #8
0
파일: usart.c 프로젝트: alex-sever-h/robot
void tty_put(u8 ch)
{
#ifdef BUFFERED
	//put char to the buffer
	buffer_put(&u1tx, ch);
	//enable Transmit Data Register empty interrupt
	usart_enable_tx_interrupt(USART1);
#else

	usart_send_blocking(USART1, ch);

#endif
}
static void prvUsartTask( void *pvParameters )
{
    for( ;; )
	{
		uint16_t data = buffer_get(receive_buffer);
		if (data == BUFFER_EMPTY) taskYIELD();
		else
		{
			buffer_put(send_buffer, data);
			usart_enable_tx_interrupt(USART1);
		}
	}
}
예제 #10
0
파일: debug-uart.c 프로젝트: jimmyH/contiki
int uart_putchar(char c)
{
	if( c == '\n')
		uart_putchar('\r');
	if(!queue_is_full(&uart_tx_buf)) {
		queue_enqueue(&uart_tx_buf, &c);
	} else {
		return -ENOMEM;
	}

	usart_enable_tx_interrupt(USART1);

	return 0;
}
예제 #11
0
unsigned char canSend(CAN_PORT notused, Message *m)
{
        unsigned char i;

/* Send the message as raw bytes (note little-endianness of Cortex M3) */
	buffer_put(send_buffer, (m->cob_id) & 0xFF);
	buffer_put(send_buffer, (m->cob_id) >> 8);
	buffer_put(send_buffer, (m->rtr));
	buffer_put(send_buffer, (m->len));
	for (i= 0; i < (m->len); i++)
		buffer_put(send_buffer, m->data[i]);
/* Start sending by enabling the interrupt */
	usart_enable_tx_interrupt(USART1);
        return 1;	// successful
}
예제 #12
0
unsigned int usart_putc(char c)
{
  cm_disable_interrupts();
  unsigned int next = (tx_head + 1) % sizeof(tx_buf);
  if (waiting_tx_bytes() == sizeof(tx_buf)) {
    cm_enable_interrupts();
    return 0;
  }

  tx_buf[tx_head] = c;
  tx_head = next;
  cm_enable_interrupts();
  usart_enable_tx_interrupt(USART1);
  return 1;
}
예제 #13
0
파일: STM32_USART.c 프로젝트: lireric/ssn
signed long xSerialPutChar( long lPort, signed char cOutChar, portTickType xBlockTime )
{
long lReturn;

	if( xQueueSend( xCharsForTx[ lPort ], &cOutChar, xBlockTime ) == pdPASS )
	{
		lReturn = pdPASS;
		usart_enable_tx_interrupt(xUSART[lPort]);
	}
	else
	{
		lReturn = pdFAIL;
	}

	return lReturn;
}
예제 #14
0
파일: plc_serial.c 프로젝트: nucleron/yaplc
int dbg_serial_write( unsigned char *d, unsigned short n )
{
    int res = 0;
    cm_disable_interrupts();
    res = dbg_fifo_write( &usart_tx_buf, d, n );
    if( res && !(USART_CR1(DBG_USART) & USART_CR1_TXEIE) )
    {
        if( dbg_fifo_read_byte( &usart_tx_buf, &usart_data ) )
        {
            while( !(USART_SR(DBG_USART) & USART_SR_TXE) );///пока буфер не пуст
            usart_send(DBG_USART, usart_data);
            usart_enable_tx_interrupt(DBG_USART);
        }
    }
    cm_enable_interrupts();
    return res;
}
예제 #15
0
파일: usart.c 프로젝트: alex-sever-h/robot
void tty_puts(const char * string)
{
#ifdef BUFFERED
	while(*string)
	{
		buffer_put(&u1tx, *string);
		usart_enable_tx_interrupt(USART1);
		string++;
	}
#else
	while(*string)
	{
		tty_put(*string);
		string++;
	}
#endif
}
예제 #16
0
// Writes one byte to the TX serial buffer. Called by main program.
// TODO: Check if we can speed this up for writing strings, rather than single bytes.
void serial_write(uint8_t data) {
  // Calculate next head
  uint32_t next_head = serial_tx_buffer_head + 1;
  if (next_head == TX_BUFFER_SIZE) { next_head = 0; }

  // Wait until there is space in the buffer
  while (next_head == serial_tx_buffer_tail) {
    // TODO: Restructure st_prep_buffer() calls to be executed here during a long print.
    if (sys.rt_exec_state & EXEC_RESET) { return; } // Only check for abort to avoid an endless loop.
  }

  // Store data and advance head
  serial_tx_buffer[serial_tx_buffer_head] = data;
  serial_tx_buffer_head = next_head;

  // Enable Data Register Empty Interrupt to make sure tx-streaming is running
  usart_enable_tx_interrupt(USART2);

}
예제 #17
0
void Serial_stm32::irq_handler(void)
{
    uint8_t data = 0;

    // Check if we were called because of RXNE
    if (((USART_CR1(config_.device) & USART_CR1_RXNEIE) != 0) &&
            ((USART_SR(config_.device)  & USART_SR_RXNE)    != 0))
    {

        // Retrieve the data from the peripheral
        data = usart_recv(config_.device);
        rx_buffer_.put_lossy(data);

        // Enable transmit interrupt so it sends back the data
        usart_enable_tx_interrupt(config_.device);
    }

    // Check if we were called because of TXE
    if (((USART_CR1(config_.device) & USART_CR1_TXEIE) != 0) &&
            ((USART_SR(config_.device)  & USART_SR_TXE)    != 0))
    {
        if (tx_buffer_.readable() > 0)
        {
            // Get data from output buffer
            tx_buffer_.get(data);

            // Put data into the transmit register
            usart_send(config_.device, data);
        }
        else
        {
            // Disable the TXE interrupt as we don't need it anymore
            usart_disable_tx_interrupt(config_.device);
        }
    }

    // Call callback function if attached
    if (irq_callback != 0)
    {
        irq_callback(this);
    }
}
예제 #18
0
void
usart_init(int usart, int irq, int baudrate, int over8) {
  /* Setup USART parameters. */
  nvic_disable_irq(irq);
  usart_disable_rx_interrupt(usart);
  usart_disable_tx_interrupt(usart);
  usart_disable(usart);
  USART_CR1(usart) |= over8;  /* This doubles the listed baudrate. */
  usart_set_baudrate(usart, baudrate);
  usart_set_databits(usart, 8);
  usart_set_stopbits(usart, USART_STOPBITS_1);
  usart_set_mode(usart, USART_MODE_TX_RX);
  usart_set_parity(usart, USART_PARITY_NONE);
  usart_set_flow_control(usart, USART_FLOWCONTROL_NONE);
  /* Finally enable the USART. */
  usart_enable(usart);
  usart_enable_rx_interrupt(usart);
  usart_enable_tx_interrupt(usart);
  nvic_enable_irq(irq);
}
예제 #19
0
bool Serial_stm32::write(const uint8_t* bytes, const uint32_t size)
{
    bool ret = false;

    //  Queue byte
    if (writeable() >= size)
    {
        for (uint32_t i = 0; i < size; ++i)
        {
            tx_buffer_.put(bytes[i]);
        }
        ret = true;
    }

    // Start transmission
    if (tx_buffer_.readable() >= 1)
    {
        usart_enable_tx_interrupt(config_.device);
    }

    return ret;
}
예제 #20
0
void
Board_FY20AP::com_tx_start()
{
	usart_enable_tx_interrupt(USART1);
}
예제 #21
0
파일: bsp.c 프로젝트: mour/ratfist-stm32
static void enable_usart1_tx_interrupt(void)
{
	usart_enable_tx_interrupt(USART1);
}
예제 #22
0
파일: commslib.c 프로젝트: ksarkies/SMPS
void commsPrintChar(char *ch)
{
    usart_disable_tx_interrupt(USART2);
    buffer_put(sendBuffer,*ch);
    usart_enable_tx_interrupt(USART2);
}
예제 #23
0
int main(void)
{
    float voltage;
    uint8_t skytraq_packet_id = 0;

    clock_setup();
    gpio_setup();
    usart_setup();
    adc_setup();
    
    delay_ms(100);
    gps_tx_queue.enqueue(binary_rate);
    usart_enable_tx_interrupt(USART2); // enable GPS TX interrupt
    
    while (1) {
        voltage = get_voltage();
        if (voltage < 6.2) {
        //    char buf[100];
        //    sprintf(buf, "%f\r\n", voltage);
        //    for(int i = 0; i < strlen(buf); ++i){
        //        usart_send_blocking(USART1, buf[i]);
        //    }
            usart_disable_tx_interrupt(USART2);
            usart_disable_rx_interrupt(USART2);
            gpio_clear(GPIOB, GPIO2 | GPIO12); // hold both GPS and XBEE in reset
            usart_disable_tx_interrupt(USART3);
            usart_disable_rx_interrupt(USART3);
            while(1); // and spin
        } 
        xbee_packet_t xbee_pkt;

        if (!gps_rx_queue.isEmpty()) {
            gps_packet_t gps_pkt = gps_rx_queue.dequeue();

            if (gps_pkt.payload[0] == GPS_ACK
                    || gps_pkt.payload[0] == GPS_NACK) { // ignore ACK and NACK
                continue;
            }

            ++skytraq_packet_id;
            // length/max_length + 1 more if remainder is bigger than 0
            uint8_t fragments_needed = (gps_pkt.length / MAX_FRAG_LENGTH)
                    + (((gps_pkt.length % MAX_FRAG_LENGTH) > 0) ? 1 : 0);

            xbee_build_header(xbee_pkt);
            //xbee_set_dest_addr(xbee_pkt, 0x0013A20040AD1B15, 0xFFFE);
            xbee_set_dest_addr(xbee_pkt, 0x000000000000FFFF, 0xFFFE);
            uint8_t current_fragment = 1;
            char* src_ptr = &(gps_pkt.payload[0]);

            while (current_fragment <= fragments_needed) {
                xbee_pkt.payload[INDEX_TYPE] = TYPE_SKYTRAQ;
                xbee_pkt.payload[INDEX_ID] = skytraq_packet_id;
                xbee_pkt.payload[INDEX_X] = current_fragment;
                xbee_pkt.payload[INDEX_Y] = fragments_needed;
                size_t bytes_to_copy = (
                        (current_fragment == fragments_needed) ?
                                (gps_pkt.length % MAX_FRAG_LENGTH) :
                                MAX_FRAG_LENGTH);
                memcpy(&(xbee_pkt.payload[INDEX_SKYTRAQ_START]), src_ptr,
                        bytes_to_copy);
                if (current_fragment == fragments_needed) {
                    xbee_pkt.length = INDEX_SKYTRAQ_START
                            + (gps_pkt.length % MAX_FRAG_LENGTH) + 1;
                } else {
                    xbee_pkt.length = INDEX_SKYTRAQ_START + MAX_FRAG_LENGTH + 1;
                }
                xbee_tx_queue.enqueue(xbee_pkt);
                usart_enable_tx_interrupt(USART3); // enable XBEE TX interrupt
                ++current_fragment;
                src_ptr += bytes_to_copy;
            }
        }

        if (!xbee_rx_queue.isEmpty()) {
            xbee_rx_queue.dequeue();
        }
    } // while(1)

    return 0;
}