Exemplo n.º 1
0
/* Set baud rate for UART */
void Chip_UART_SetBaud(LPC_USART_T *pUART, uint32_t baudrate)
{
	uint32_t err, uart_fra_multiplier, baudRateGenerator;
	uint32_t AsyncSysconSystemClock = Chip_Clock_GetAsyncSysconClockRate();

	/* Calculate baudrate generator value */
	baudRateGenerator = AsyncSysconSystemClock / (16 * baudrate);
	err = AsyncSysconSystemClock - baudRateGenerator * 16 * baudrate;
	uart_fra_multiplier = (err * 0xFF) / (baudRateGenerator * 16 * baudrate);
	pUART->BRG = baudRateGenerator - 1;	/* baud rate */
	Chip_Clock_EnableAsyncPeriphClock(ASYNC_SYSCTL_CLOCK_FRG);
	Chip_SYSCTL_SetUSARTFRGCtrl(uart_fra_multiplier, 0xFF);
}
Exemplo n.º 2
0
/* Initialize stopwatch */
void StopWatch_Init(void)
{
	/* Use timer 1. Set prescaler to divide by 8 */
	const uint32_t prescaleDivisor = 8;
	Chip_TIMER_Init(LPC_TIMER32_1);
	Chip_TIMER_PrescaleSet(LPC_TIMER32_1, prescaleDivisor - 1);
	Chip_TIMER_Enable(LPC_TIMER32_1);

	/* Pre-compute tick rate. */
	ticksPerSecond = Chip_Clock_GetAsyncSysconClockRate() / prescaleDivisor;
	ticksPerMs = ticksPerSecond / 1000;
	ticksPerUs = ticksPerSecond / 1000000;
}
Exemplo n.º 3
0
/* Setup UART handle and parameters */
static void setupUART()
{
	uint32_t frg_mult;

	/* 115.2KBPS, 8N1, ASYNC mode, no errors, clock filled in later */
	UART_CONFIG_T cfg = {
		0,				/* U_PCLK frequency in Hz */
		115200,		/* Baud Rate in Hz */
		1,				/* 8N1 */
		0,				/* Asynchronous Mode */
		NO_ERR_EN	/* Enable No Errors */
	};

	/* Perform a sanity check on the storage allocation */
	if (LPC_UARTD_API->uart_get_mem_size() > sizeof(uartHandleMEM)) {
		/* Example only: this should never happen and probably isn't needed for
		   most UART code. */
		errorUART();
	}

	/* Setup the UART handle */
	uartHandle = LPC_UARTD_API->uart_setup((uint32_t) LPC_USART0, (uint8_t *) &uartHandleMEM);
	if (uartHandle == NULL) {
		errorUART();
	}

	/* Need to tell UART ROM API function the current UART peripheral clock
	     speed */
	cfg.sys_clk_in_hz = Chip_Clock_GetAsyncSysconClockRate();

	/* Initialize the UART with the configuration parameters */
	frg_mult = LPC_UARTD_API->uart_init(uartHandle, &cfg);
	if (frg_mult) {
		Chip_Clock_EnableAsyncPeriphClock(ASYNC_SYSCTL_CLOCK_FRG);
		Chip_SYSCTL_SetUSARTFRGCtrl(frg_mult, 0xFF);
	}
}