/** * [InitTask description] */ __task void InitTask(void) { int msg_len = 0; int clockRate = Chip_Clock_GetMainClockRate(); /* Enabled Clock To GPPIO */ Chip_GPIO_Init(LPC_GPIO); // Set the pin direction, set high for an output LED2 Chip_GPIO_SetPinDIR(LPC_GPIO, 0, 2, 1); /* Serial Driver Enable */ SER_Init(); msg_len = snprintf(message, sizeof(message), "Main clock is: %d\r\n", clockRate); Chip_UART0_SendRB(LPC_USART0, &txring, message, msg_len); for(;;) { os_dly_wait(50); Chip_UART0_SendRB(LPC_USART0, &txring, "Sveiki\r\n", strlen("Sveiki\r\n")); Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 2, 0); os_dly_wait(100); Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 2, 1); } }
/** * @remarks: behavior changed to block only when txring buffer is full (prior to return) * Guarantees that everything is written (thus retries whenever necessary) */ static void uart0_write_internal(const uint8_t* data, size_t size, bool in_rtos) { uint32_t written; while (size > 0) { written = Chip_UART0_SendRB(LPC_USART0, &txring, data, size); data += written; size -= written; if (in_rtos && RingBuffer_IsFull(&txring) && xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) { xSemaphoreTake(sem_uart_ready, portMAX_DELAY); } } }
/** * [SER_Init Initalize Uart Driver] */ void SER_Init (void) { uint8_t key; int bytes; Init_UART_PinMux(); Chip_UART0_Init(LPC_USART0); Chip_UART0_SetBaud(LPC_USART0, 115200); Chip_UART0_ConfigData(LPC_USART0, (UART0_LCR_WLEN8 | UART0_LCR_SBS_1BIT)); Chip_UART0_SetupFIFOS(LPC_USART0, (UART0_FCR_FIFO_EN | UART0_FCR_TRG_LEV2)); Chip_UART0_TXEnable(LPC_USART0); /* Before using the ring buffers, initialize them using the ring buffer init function */ RingBuffer_Init(&rxring, rxbuff, 1, UART_RRB_SIZE); RingBuffer_Init(&txring, txbuff, 1, UART_SRB_SIZE); /* Enable receive data and line status interrupt */ Chip_UART0_IntEnable(LPC_USART0, (UART0_IER_RBRINT | UART0_IER_RLSINT)); /* Enable UART 0 interrupt */ NVIC_EnableIRQ(USART0_IRQn); /* Send initial messages */ Chip_UART0_SendRB(LPC_USART0, &txring, inst1, sizeof(inst1) - 1); Chip_UART0_SendRB(LPC_USART0, &txring, inst2, sizeof(inst2) - 1); /* Poll the receive ring buffer for the ESC (ASCII 27) key */ key = 0; // while (key != ' ') { // bytes = Chip_UART0_ReadRB(LPC_USART0, &rxring, &key, 1); // if (bytes > 0) { // /* Wrap value back around */ // if (Chip_UART0_SendRB(LPC_USART0, &txring, (const uint8_t *) &key, 1) != 1) { // } // } // } }