Esempio n. 1
0
void uart_init(void)
{
	/* Disable interrupts */
	out32(UART_BASE + UART_OFFSET_IDR, UART_IXR_MASK);
	/* Disable TX and RX */
	uart_disable();
	/* Reset TX and RX, Clear FIFO */
	out32(UART_BASE + UART_OFFSET_CR, UART_CR_TXRST | UART_CR_RXRST);
	/* Clear Flags */
	out32(UART_BASE + UART_OFFSET_ISR, UART_IXR_MASK);
	/* Mode Reset to Normal/8-N-1 */
	out32(UART_BASE + UART_OFFSET_MR, 
		UART_MR_CHMODE_NORM | UART_MR_CHARLEN_8_BIT |
		UART_MR_PARITY_NONE | UART_MR_STOPMODE_1_BIT);
	/* Trigger Reset */
	out32(UART_BASE + UART_OFFSET_RXWM, UART_RXWM_RESET_VAL);
	out32(UART_BASE + UART_OFFSET_TXWM, UART_TXWM_RESET_VAL);
	/* Disable RX timeout */
	out32(UART_BASE + UART_OFFSET_RXTOUT, UART_RXTOUT_DISABLE);
	/* Reset baud rate generator and divider to genetate 115200 */
	out32(UART_BASE + UART_OFFSET_BAUDGEN, 0x3E);
	out32(UART_BASE + UART_OFFSET_BAUDDIV, 0x06);
	/* Set CR Value */
	out32(UART_BASE + UART_OFFSET_CR, 
		UART_CR_RX_DIS | UART_CR_TX_DIS | UART_CR_STOPBRK);
}
Esempio n. 2
0
void usbuart_init(void)
{
	UART_PIN_SETUP();
	
	periph_clock_enable(USBUART_CLK);
	__asm__("nop"); __asm__("nop"); __asm__("nop");
	
	uart_disable(USBUART);

	/* Setup UART parameters. */
	uart_clock_from_sysclk(USBUART);
	uart_set_baudrate(USBUART, 38400);
	uart_set_databits(USBUART, 8);
	uart_set_stopbits(USBUART, 1);
	uart_set_parity(USBUART, UART_PARITY_NONE);

	// Enable FIFO
	uart_enable_fifo(USBUART);

	// Set FIFO interrupt trigger levels to 1/8 full for RX buffer and
	// 7/8 empty (1/8 full) for TX buffer
	uart_set_fifo_trigger_levels(USBUART, UART_FIFO_RX_TRIG_1_8, UART_FIFO_TX_TRIG_7_8);

	uart_clear_interrupt_flag(USBUART, UART_INT_RX | UART_INT_RT);

	/* Enable interrupts */
	uart_enable_interrupts(UART0, UART_INT_RX| UART_INT_RT);

	/* Finally enable the USART. */
	uart_enable(USBUART);

	//nvic_set_priority(USBUSART_IRQ, IRQ_PRI_USBUSART);
	nvic_enable_irq(USBUART_IRQ);
}
static void uart_setup(void)
{
	u32 pins;
	/* Enable GPIOA in run mode. */
	periph_clock_enable(RCC_GPIOA);
	/* Configure PA0 and PA1 as alternate function pins */
	pins = GPIO0 | GPIO1;
	GPIO_AFSEL(GPIOA) |= pins;
	GPIO_DEN(GPIOA) |= pins;
	/* PA0 and PA1 are muxed to UART0 during power on, by default */

	/* Enable the UART clock */
	periph_clock_enable(RCC_UART0);
	/* We need a brief delay before we can access UART config registers */
	__asm__("nop");
	/* Disable the UART while we mess with its setings */
	uart_disable(UART0);
	/* Configure the UART clock source as precision internal oscillator */
	uart_clock_from_piosc(UART0);
	/* Set communication parameters */
	uart_set_baudrate(UART0, 921600);
	uart_set_databits(UART0, 8);
	uart_set_parity(UART0, UART_PARITY_NONE);
	uart_set_stopbits(UART0, 1);
	/* Now that we're done messing with the settings, enable the UART */
	uart_enable(UART0);

}
static void update_host_wake_locked(int host_wake)
{
	if (host_wake == bt_lpm.host_wake)
		return;

	bt_lpm.host_wake = host_wake;

	if (host_wake) {
		wake_lock(&bt_lpm.wake_lock);
		if (!host_wake_uart_enabled) {
			WARN_ON(!bt_lpm.tty_dev);
			uart_enable(bt_lpm.tty_dev);
		}
	} else  {
		if (host_wake_uart_enabled) {
			WARN_ON(!bt_lpm.tty_dev);
			uart_disable(bt_lpm.tty_dev);
		}
		/*
		 * Take a timed wakelock, so that upper layers can take it.
		 * The chipset deasserts the hostwake lock, when there is no
		 * more data to send.
		 */
		wake_lock_timeout(&bt_lpm.wake_lock, HZ/2);
	}

	host_wake_uart_enabled = host_wake;

}
Esempio n. 5
0
void platform_disable_uart()
{
    // Set pins analog and disable the print UART
    gpio_set_analog(GPIO_A, GPIO_PIN_9);
    gpio_set_analog(GPIO_A, GPIO_PIN_10);
    uart_disable(uart_print);

}
Esempio n. 6
0
int main(void)
{
	WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
	uart_timer_configure();
	uart_init();
    _enable_interrupts();

    uart_puts("\n\r***************\n\r");
    uart_puts("MSP430 SunV2\n\r");
    uart_puts("***************\n\r\n\r");

    uint8_t c;

    // Timeshare between UART and dimming
    while(1) {
        if(uart_getc(&c)) {
            if(c == '\r') {
                 uart_putc('\n');
                 uart_putc('\r');
            } else {
                uart_putc('[');
                uart_putc(c);
                uart_putc(']');
            
                // Clear UART configuration
                _disable_interrupts();
                timer_deconfigure();
                uart_disable();
                uart_timerA_disable();
                switch (c)
                {
                    case 'w':
                        turnOn();
                        break;
                    case 's':
                        turnOff();
                        break;
                    case 'r':
                        remember();
                        break;
                    case 'd':
                        dimUp();
                        break;
                    case 'a':
                        dimDown();
                        break;
                }
                // UART configuration
                art_init();
                timer_deconfigure();
                uart_timer_configure();
                uart_timerA_enable();
                _enable_interrupts();
            }
        }
    }
}
Esempio n. 7
0
/**
 * \brief This function closes and disables communication in the specified UART.
 *
 * \param chn  Communication channel [0, 1]
 *
 * \retval true on success.
 * \retval false on failure.
 */
int8_t buart_if_close(uint8_t chn)
{
	if (!buart_chn_open[chn]) {
		return false;
	}

	switch (chn) {
#ifdef CONF_BOARD_UART0
	case 0:
	{
		uart_disable(UART0);
		uart_disable_interrupt(UART0, US_IDR_RXRDY);
		uart_disable_interrupt(UART0, US_IER_ENDRX);

		/* Stop TC */
		if (!buart_chn_open[1]) {
			tc_stop(TC_UART, TC_UART_CHN);
		}

		return true;
	}
	break;
#endif

#ifdef CONF_BOARD_UART1
	case 1:
	{
		uart_disable(UART1);
		uart_disable_interrupt(UART1, US_IDR_RXRDY);
		uart_disable_interrupt(UART1, US_IER_ENDRX);

		/* Stop TC */
		if (!buart_chn_open[0]) {
			tc_stop(TC_UART, TC_UART_CHN);
		}

		return true;
	}
	break;
#endif
	default:
		return false;
	}
}
Esempio n. 8
0
int16_t uart_driver_close(device_id_t device)
{
    registered_uart_t* reg = uart_get_registered(device);
    if (reg != NULL)
    {
        reg->used=FALSE;
        uart_disable(reg->uart_port);
    }
    return 0;
}
Esempio n. 9
0
void uart_set_baudrate(unsigned long baud)
{
    uart_disable();

    // Set the baud rate
    // BRG = freq/( baud * 16)
    U0BR = FREQ/((unsigned long)baud * 16UL);
    baudrate = baud;

    uart_enable();
}
Esempio n. 10
0
void measure_rpm() {
	while(uart_tx_active == 1){} // wait for pending uart transmission to finish
	uart_disable();
	
	measure_channel_rpm(0); // channel 1
	measure_channel_rpm(1); // channel 2
	measure_channel_rpm(2); // channel 3
	//measure_channel_rpm(3); // channel 4
	
	uart_enable();
}
Esempio n. 11
0
void uart_set_bits(const char *value)
{
    uart_disable();

    if(strcmp(value, UART_BIT7) == 0) {
        U0CTL0 &= ~UART_TWO_STOP;
    }
    else if(strcmp(value, UART_BIT8) == 0) {
        U0CTL0 |= UART_TWO_STOP;
    }

    uart_enable();
}
int glue_set_line_coding_cb(uint32_t baud, uint8_t databits,
			    enum usb_cdc_line_coding_bParityType cdc_parity,
			    enum usb_cdc_line_coding_bCharFormat cdc_stopbits)
{
	enum uart_parity parity;
	uint8_t uart_stopbits;

	if (databits < 5 || databits > 8)
		return 0;

	switch (cdc_parity) {
	case USB_CDC_NO_PARITY:
		parity = UART_PARITY_NONE;
		break;
	case USB_CDC_ODD_PARITY:
		parity = UART_PARITY_ODD;
		break;
	case USB_CDC_EVEN_PARITY:
		parity = UART_PARITY_EVEN;
		break;
	default:
		return 0;
	}

	switch (cdc_stopbits) {
	case USB_CDC_1_STOP_BITS:
		uart_stopbits = 1;
		break;
	case USB_CDC_2_STOP_BITS:
		uart_stopbits = 2;
		break;
	default:
		return 0;
	}

	/* Disable the UART while we mess with its settings */
	uart_disable(UART1);
	/* Set communication parameters */
	uart_set_baudrate(UART1, baud);
	uart_set_databits(UART1, databits);
	uart_set_parity(UART1, parity);
	uart_set_stopbits(UART1, uart_stopbits);
	/* Back to work. */
	uart_enable(UART1);

	return 1;
}
Esempio n. 13
0
void uart_set_parity(const char *value)
{
    uart_disable();

    if(strcmp(value, UART_EVEN) == 0) {
        U0CTL0 |= UART_PARITY_EN;
        U0CTL0 &= ~UART_PARITY_ODD;
    }
    else if(strcmp(value, UART_ODD) == 0) {
        U0CTL0 |= UART_PARITY_EN | UART_PARITY_ODD;
    }
    else if(strcmp(value, UART_NONE) == 0) {
        U0CTL0 &= ~UART_PARITY_EN;
    }

    uart_enable();
}
static void set_wake_locked(int wake)
{
	bt_lpm.wake = wake;

	if (!wake)
		wake_unlock(&bt_lpm.wake_lock);

	if (!wake_uart_enabled && wake) {
		WARN_ON(!bt_lpm.tty_dev);
		uart_enable(bt_lpm.tty_dev);
	}

	gpio_set_value(bt_lpm.gpio_wake, wake);

	if (wake_uart_enabled && !wake) {
		WARN_ON(!bt_lpm.tty_dev);
		uart_disable(bt_lpm.tty_dev);
	}
	wake_uart_enabled = wake;
}
Esempio n. 15
0
void traceswo_init(void)
{
	periph_clock_enable(RCC_GPIOD);
	periph_clock_enable(TRACEUART_CLK);
	__asm__("nop"); __asm__("nop"); __asm__("nop");

	gpio_mode_setup(SWO_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, SWO_PIN);
	gpio_set_af(SWO_PORT, 1, SWO_PIN); /* U2RX */

	uart_disable(TRACEUART);

	/* Setup UART parameters. */
	uart_clock_from_sysclk(TRACEUART);
	uart_set_baudrate(TRACEUART, 800000);
	uart_set_databits(TRACEUART, 8);
	uart_set_stopbits(TRACEUART, 1);
	uart_set_parity(TRACEUART, UART_PARITY_NONE);

	// Enable FIFO
	uart_enable_fifo(TRACEUART);

	// Set FIFO interrupt trigger levels to 4/8 full for RX buffer and
	// 7/8 empty (1/8 full) for TX buffer
	uart_set_fifo_trigger_levels(TRACEUART, UART_FIFO_RX_TRIG_1_2, UART_FIFO_TX_TRIG_7_8);

	uart_clear_interrupt_flag(TRACEUART, UART_INT_RX | UART_INT_RT);

	/* Enable interrupts */
	uart_enable_interrupts(TRACEUART, UART_INT_RX | UART_INT_RT);

	/* Finally enable the USART. */
	uart_enable(TRACEUART);

	nvic_set_priority(TRACEUART_IRQ, 0);
	nvic_enable_irq(TRACEUART_IRQ);

	/* Un-stall USB endpoint */
	usbd_ep_stall_set(usbdev, 0x85, 0);

	gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO3);
}
static void uart_setup(void)
{
	/* Enable GPIOA in run mode. */
	periph_clock_enable(RCC_GPIOA);
	/* Mux PA0 and PA1 to UART0 (alternate function 1) */
	gpio_set_af(GPIOA, 1, GPIO0 | GPIO1);

	/* Enable the UART clock */
	periph_clock_enable(RCC_UART0);
	/* We need a brief delay before we can access UART config registers */
	__asm__("nop");
	/* Disable the UART while we mess with its setings */
	uart_disable(UART0);
	/* Configure the UART clock source as precision internal oscillator */
	uart_clock_from_piosc(UART0);
	/* Set communication parameters */
	uart_set_baudrate(UART0, 921600);
	uart_set_databits(UART0, 8);
	uart_set_parity(UART0, UART_PARITY_NONE);
	uart_set_stopbits(UART0, 1);
	/* Now that we're done messing with the settings, enable the UART */
	uart_enable(UART0);
}
Esempio n. 17
0
int
main(void)
{
	int i, j, k, l;
	unsigned button[3];
	unsigned steps[3];
	unsigned hz;

	/*-------------------------------------------------------------
	 * First things first:  Start the watchdog
	 */

	fido_setup(0x1000);

	/*-------------------------------------------------------------
	 * Setup GPIO
	 */

	LPC_SYSCON->SYSAHBCLKCTRL |=  (1 << 6);			// GPIO
	LPC_SYSCON->PRESETCTRL    &= ~(1 << 10);		// GPIO reset
	LPC_SYSCON->PRESETCTRL    |= (1 << 10);

	LPC_IOCON->PIO0_0 = 0
		| (1 << 3)					// Pull down
		| (1 << 5)					// Hysteresis
		;

	LPC_IOCON->PIO0_1 = 0
		| (2 << 3)					// Pull up
		| (1 << 5)					// Hysteresis
		;

	LPC_IOCON->PIO0_2 = 0
		| (2 << 3)					// Pull up
		| (1 << 5)					// Hysteresis
		;

	LPC_IOCON->PIO0_3 = 0
		| (2 << 3)					// Pull up
		| (1 << 5)					// Hysteresis
		;

	LPC_IOCON->PIO0_5 = 0
		| (2 << 3)					// Pull up
		| (1 << 5)					// Hysteresis
		;

	/*-------------------------------------------------------------
	 * Provide a chance to enter the boot-loader
	 */

	check_bootloader();

	/*-------------------------------------------------------------
	 * Enable UART for startup-debugging
	 */

	uart0Init(115200);
	uart_enable();

	/*-------------------------------------------------------------
	 * Start timer
	 */

	mrtInit(__SYSTEM_CLOCK/1000);

	/*-------------------------------------------------------------
	 * Enable reset pin
	 */

	LPC_SWM->PINENABLE0 = ~(1 << 6);		// PIO0_5 RESET_EN

	/*-------------------------------------------------------------
	 * Hello World
	 */

	welcome();

	/*-------------------------------------------------------------
	 * Detect pin-configuration by counting edges on the two possible
	 * possible clock inputs.
 	 *
	 * If neither is active the watch-dog will trigger.
	 */

	do {
		/* Measure input frequency on PIO0_1 and PIO0_2 */
		for (i = 1; i < 3; i++) {
			sct_setup(i);
			k = LPC_SCT->COUNT_U;
			mrtDelay(100);
			l = LPC_SCT->COUNT_U;
			hz = 10 * (l-k);
			printf("Rate PIO0_%d = %u\r\n", i, hz);
			if (hz > 1000)
				break;
		}
	} while (hz < 1000);

	/*-------------------------------------------------------------
 	 * Configure counter
	 */

	mrtDelay(100);
	printf("Using PIO0_%d\r\n", i);
	mrtDelay(100);
	uart_disable();

	button[0] = 1<<(3-i);	steps[0] = 1;
	button[1] = 1<<3;	steps[1] = 60;
	button[2] = 1<<5;	steps[2] = 3600;
	if (i == 1) {

		LPC_SWM->PINENABLE0 &= ~(1 << 7);       // Enable CLKIN

		LPC_SYSCON->MAINCLKSEL = 0x1;		// PLL input
		LPC_SYSCON->MAINCLKUEN = 0x0;
		LPC_SYSCON->MAINCLKUEN = 0x1;

		LPC_SYSCON->SYSPLLCLKSEL = 0x3;		// CLKIN
		LPC_SYSCON->SYSPLLCLKUEN = 0x0;
		LPC_SYSCON->SYSPLLCLKUEN = 0x1;

		LPC_SYSCON->SYSAHBCLKDIV = 1;

		sct_setup(0xff);
		mrtInit(FREQ/1000);

		/* Calibrated to look like 0x00 at 115200 bps */
		pulse_lo = 29;
		pulse_hi = 10;
	} else {
		sct_setup(2);
	}

	sct_output(4);

	/*-------------------------------------------------------------
	 * Until the clock is set, have it run 11 times too fast
	 */
	while (1) {
		fido_pat();
		if (!(LPC_GPIO_PORT->PIN0 & button[0]))
			break;
		if (!(LPC_GPIO_PORT->PIN0 & button[1]))
			break;
		if (!(LPC_GPIO_PORT->PIN0 & button[2]))
			break;
		mrtDelay(100);
		run_pulse();
	}

	LPC_SWM->PINENABLE0 |= (1 << 6);		// Disable RESET

	j = 0;
	while(1) {
		if (j == 0 && LPC_SCT->COUNT_U < 10000) {
			fido_pat();
			j = 1;
		}
		if (j == 1 && LPC_SCT->COUNT_U > 10000) {
			j = 0;
		}

		for (i = 0; i < 3; i++) {
			if (LPC_GPIO_PORT->PIN0 & button[i])
				continue;

			fido_pat();

			for(k = 0; k < steps[i]; k++)
				run_pulse();

			if (i > 0) {
				/*
				 * Min/Hour button release
				 * If you hold them for 10+ seconds
				 * The watch-dog bites
				 */
				for(k = 0; k < 1000; k++) {
					if (LPC_GPIO_PORT->PIN0 & button[i])
						continue;
					k = 0;
				}
				continue;
			}

			/* Check if the Sec button is held for >1s */

			mrt_counter = 0;
			for(k = 0; k < 1000; k++) {
				if (LPC_GPIO_PORT->PIN0 & button[i])
					break;
				if (mrt_counter > 1000)
					break;
				k = 0;
			}
			if (k == 1000)
				continue;

			/* Stop counter */
			sct_stop();

			/*
			 * Restart counter on button release
			 * or sync input
			 */
			for(k = 0; k < 1000; k++) {
				if (LPC_GPIO_PORT->PIN0 & button[i])
					break;
				l = LPC_GPIO_PORT->PIN0 & (1<<0);
				if (l)
					k = 0;
			}

			l = (1 << 0) | button[i];
			while (!(LPC_GPIO_PORT->PIN0 & l))
				continue;

			/*
			 * Calibrated for falling edge = PPI rising edge
			 * PPSO comes 164ns after PPS1
			 */
			LPC_SCT->COUNT_U = FREQ - 366;
			LPC_SCT->CTRL_L &= ~(1 << 2);		// Start

			for(k = 0; k < 1000; k++) {
				if (LPC_GPIO_PORT->PIN0 & button[i])
					continue;
				k = 0;
			}
		}
	}
}
Esempio n. 18
0
void msg_disableRx(void)
{
    uart_disable();
    rf_setMode(RF_MODE_SLEEP);
}
Esempio n. 19
0
File: uart.c Progetto: nesl/sos-2x
uart_recv_interrupt() {
	uart_disable();
}
Esempio n. 20
0
File: uart.c Progetto: nesl/sos-2x
uart_send_interrupt() {
	uart_disable();
}