Ejemplo n.º 1
0
int uart_set_sample_rate(int ureg, int rate) {
	if(ureg > 4)
		return -1; // Invalid ureg

	uint32_t newSampleRate;
	switch(rate) {
		case 4:
			newSampleRate = UART_SAMPLERATE_4;
			break;
		case 8:
			newSampleRate = UART_SAMPLERATE_8;
			break;
		case 16:
			newSampleRate = UART_SAMPLERATE_16;
			break;
		default:
			return -1; // Invalid sample rate
	}

	SET_REG(HWUarts[ureg].UBAUD,
		(GET_REG(HWUarts[ureg].UBAUD) & (~UART_SAMPLERATE_MASK)) | (newSampleRate << UART_SAMPLERATE_SHIFT));

	UARTs[ureg].sample_rate = rate;
	uart_set_baud_rate(ureg, UARTs[ureg].baud);

	return 0;
}
Ejemplo n.º 2
0
int serial_init( void )
{
    if ( uart_initted || uart_probe() == 0 ) return 0;

    /* Disable hardware interrupts */

    WRITE( MCR, 0 );
    WRITE( IER, 0 );

    /* Disable FIFO's for 16550 devices */

    WRITE( FCR, 0 );

    /* Set for 8-bit, no parity, DLAB bit cleared */

    WRITE( LCR, UART_LCR_8BITS );

    /* Set baud rate */

    uart_set_baud_rate( UART_BAUD_RATE );

    /* Assert DTR# and RTS# lines (OUT2?) */

    WRITE( MCR, UART_MCR_DTR | UART_MCR_RTS );

    /* Clear any garbage in the input buffer */

    READ( RBR );

    uart_initted = 1;

    return 1;
}
Ejemplo n.º 3
0
int radio_setup_2g()
{
	gpio_pin_output(RADIO_GPIO_BB_MUX_SEL, OFF);

	gpio_pulldown_configure(RADIO_BB_PULLDOWN, GPIOPDDown);

	gpio_pin_output(RADIO_GPIO_BB_ON, OFF);
	udelay(100000);
	gpio_pin_output(RADIO_GPIO_RADIO_ON, ON);
	udelay(100000);
	gpio_pin_output(RADIO_GPIO_BB_RESET, ON);
	udelay(100000);
	gpio_pin_output(RADIO_GPIO_BB_RESET, OFF);
	udelay(100000);

	gpio_pin_use_as_input(RADIO_GPIO_BB_DETECT);
	if(gpio_pin_state(RADIO_GPIO_BB_DETECT) != 0)
	{
		bufferPrintf("radio: comm board not present, powered on, or at+xdrv=10,2 had been issued.\r\n");
		return -1;
	}

	bufferPrintf("radio: comm board detected.\r\n");

    
	if(!radio_wait_for_ok(10))
	{
		bufferPrintf("radio: no response from baseband!\r\n");
		return -1;
	}
  

	bufferPrintf("radio: setting speed to 750000 baud.\r\n");

	radio_write("at+ipr=750000\r\n");

	// wait a millisecond for the command to totally clear uart
	// I wasn't able to detect this condition with uart registers (looking at FIFO count, transmitter empty)
	udelay(1000);

	uart_set_baud_rate(RADIO_UART, 750000);

	if(!radio_wait_for_ok(10))
	{
		bufferPrintf("radio: no response from baseband!\r\n");
		return -1;
	}

	RadioAvailable = TRUE;

	bufferPrintf("radio: ready.\r\n");

	speaker_setup();

	return 0;
}
Ejemplo n.º 4
0
int uart_set_clk(int ureg, int clock) {
	if(ureg > 4)
		return -1; // Invalid ureg

	if(clock != UART_CLOCK_PCLK && clock != UART_CLOCK_EXT_UCLK0 && clock != UART_CLOCK_EXT_UCLK1) {
		return -1; // Invalid clock		
	}

	SET_REG(HWUarts[ureg].UCON,
		(GET_REG(HWUarts[ureg].UCON) & (~UART_CLOCK_SELECTION_MASK)) | (clock << UART_CLOCK_SELECTION_SHIFT));

	UARTs[ureg].clock = clock;
	uart_set_baud_rate(ureg, UARTs[ureg].baud);

	return 0;
}
Ejemplo n.º 5
0
void
uart_init(uart_t *p_uart)
{
    /* UART停止 */
    // uart_close(p_uart);

    //p_uart->PWREMU_MGMT |= (0x1u << 15) & 0x00008000;
	//p_uart->PWREMU_MGMT = (0x1 << 14) | (0x1 << 13) | 0x1;

//    /* Set to 16x Over-Sampling Mode */
//    p_uart->MDR = 0x00;
//
//	/* ボーレートを設定 */
//    uint32_t div = CORE_CLK_MHZ * 1000000 / 16 / 2 / BAUD_RATE;
//    p_uart->DLL = div & 0xFF;
//    p_uart->DLH = (div >> 8) & 0xFF;

    uart_open(p_uart);

    /* Clear, enable, and reset FIFO */
    p_uart->IIR_FCR = 0x0;
    p_uart->IIR_FCR = 0x1;
    //p_uart->IIR_FCR = 0x7;
    p_uart->IIR_FCR = 0x7 | (0x02 << 6); // FIFO trigger level 8 bytes
//    p_uart->IIR_FCR = 0xC7;

    /* 8 bits data, no parity, one stop bit and clear DLAB bit */
    p_uart->LCR = 0x03;

    /* Disable autoflow control */
    p_uart->MCR = 0x00;

    // Disable interrupts
    //p_uart->IER = 0x03;
    p_uart->IER = 0x0;

    uart_set_baud_rate(p_uart, 115200);
}