Пример #1
0
/* Write character to USART0.  This blocks.  */
int
usart0_putc (char ch)
{
    if (ch == '\n')
        usart0_putc ('\r');

    USART0_PUTC (ch);
    return ch;
}
Пример #2
0
/* Write string to USART0.  This blocks until the string is written.  */
int
usart0_puts (const char *str)
{
    while (*str)
    {
        if (usart0_putc (*str++) < 0)
            return -1;
    }
    return 1;
}
Пример #3
0
	/**
	 * Writes an array of bytes with
	 * the length n
	 * @param  n      Number of bytes to write
	 * @param  array  Array of bytes to be written
	 * @return        Number of bytes written
	 */
	int usart0_putn(size_t n, const uint8_t *array) {
		if (array == NULL) return -1;

		int i;
		for (i = 0; i < n; ++i){
			usart0_putc(array[i]);
		}

		return i;
	}
Пример #4
0
	/**
	 * Writes a null terminated c-string
	 * to the USART
	 *
	 * @param  str String that is written
	 * @return     Number of bytes written
	 */
	int usart0_puts(const char *str) {
		if (str == NULL) return -1;
		int i = 0;

		while(str[i] != '\0'){
			usart0_putc(str[i++]);
		}

		return i;
	}
Пример #5
0
void main(void)
{
	clock_init();
	usart0_init();

	/* Give PIO control over the RGB pins */
	SAM3_PIOA.enable = (1 << 20) | (1 << 16) | (1 << 0);
	SAM3_PIOA.output_enable = (1 << 20) | (1 << 16) | (1 << 0);

	/* Drive them */
	for (;;) {
		SAM3_PIOA.set_output_data = (1 << 20) | (1 << 16) | (1 << 0);
		delay_ms(100);
		SAM3_PIOA.clear_output_data = (1 << 20) | (1 << 16) | (1 << 0);
		delay_ms(100);
		usart0_putc('X');
	}
}
Пример #6
0
	/**
	 * Put a byte on USART. unless
	 * USART0_NON_UNIX_LIKE_LINE_ENDINGS is
	 * defined this will put a '\r' before every '\n'
	 * to mimic unix like line endings
	 *
	 * @param  c Byte to transmit
	 * @return   positive if success
	 */
	int usart0_putc(const uint8_t c) {
	#ifndef USART0_NON_UNIX_LIKE_LINE_ENDINGS
		if(c == '\n'){
			usart0_putc('\r');
		}
	#endif

	#ifdef NO_USART0_BUFFERED_OUTPUT
		while (USART0_TX_IS_BUSY());
		UDR0 = c;
	#else
		// Wait for free space in buffer
		while (rb_push(&usart0_outBuff, c) != 0);
		USART0_ENABLE_DATA_REG_EMPTY_INTERRUPT();
	#endif

		return c;
	}