Exemplo n.º 1
1
/* Interrupt routine for example_uart */
static void App_Interrupt_Test(void)
{
    uint8_t isExit = 0, userInput;
    int len;
    App_Interrupt_Init();

    /* Print out uart interrupt menu */
    Print_Menu_Interrupt(LPC_UART);

    while (!isExit) {
        len = 0;
        while (len == 0) {
            len = Chip_UART_ReadRB(LPC_UART, &rxring, &userInput, 1);
        }
        if (userInput == '1') {
            Chip_UART_SendRB(LPC_UART, &txring, (uint8_t *) &uart_interrupt_menu1[0], sizeof(uart_interrupt_menu1));
        }
        else if (userInput == '2') {
            Chip_UART_SendRB(LPC_UART, &txring, (uint8_t *) &uart_interrupt_menu2[0], sizeof(uart_interrupt_menu2));
        }
        else if (userInput == '3') {
            Chip_UART_SendRB(LPC_UART, &txring, (uint8_t *) &uart_interrupt_menu3[0], sizeof(uart_interrupt_menu3));
        }
        else if (userInput == '4') {
            Chip_UART_SendRB(LPC_UART, &txring, (uint8_t *) &uart_interrupt_menu4[0], sizeof(uart_interrupt_menu4));
        }
        else if (( userInput == 'x') || ( userInput == 'X') ) {
            isExit = 1;
        }
    }

    App_Interrupt_DeInit();
}
Exemplo n.º 2
0
/**
 * @brief	Main UART program body
 * @return	Always returns 1
 */
int main(void)
{
	uint8_t key;
	int bytes;

	SystemCoreClockUpdate();
	Board_Init();
	Board_UART_Init(LPC_UARTX);
	Board_LED_Set(0, false);

	/* Setup UART for 115.2K8N1 */
	Chip_UART_Init(LPC_UARTX);
	Chip_UART_SetBaud(LPC_UARTX, 115200);
	Chip_UART_ConfigData(LPC_UARTX, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT));
	Chip_UART_SetupFIFOS(LPC_UARTX, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));
	Chip_UART_TXEnable(LPC_UARTX);

	/* 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);

	/* Reset and enable FIFOs, FIFO trigger level 3 (14 chars) */
	Chip_UART_SetupFIFOS(LPC_UARTX, (UART_FCR_FIFO_EN | UART_FCR_RX_RS |
							UART_FCR_TX_RS | UART_FCR_TRG_LEV3));

	/* Enable receive data and line status interrupt */
	Chip_UART_IntEnable(LPC_UARTX, (UART_IER_RBRINT | UART_IER_RLSINT));

	/* preemption = 1, sub-priority = 1 */
	NVIC_SetPriority(UARTx_IRQn, 1);
	NVIC_EnableIRQ(UARTx_IRQn);

	/* Send initial messages */
	Chip_UART_SendRB(LPC_UARTX, &txring, inst1, sizeof(inst1) - 1);
	Chip_UART_SendRB(LPC_UARTX, &txring, inst2, sizeof(inst2) - 1);

	/* Poll the receive ring buffer for the ESC (ASCII 27) key */
	key = 0;
	while (key != 27) {
		bytes = Chip_UART_ReadRB(LPC_UARTX, &rxring, &key, 1);
		if (bytes > 0) {
			/* Wrap value back around */
			if (Chip_UART_SendRB(LPC_UARTX, &txring, (const uint8_t *) &key, 1) != 1) {
				Board_LED_Toggle(0);/* Toggle LED if the TX FIFO is full */
			}
		}
	}

	/* DeInitialize UART0 peripheral */
	NVIC_DisableIRQ(UARTx_IRQn);
	Chip_UART_DeInit(LPC_UARTX);

	return 1;
}
Exemplo n.º 3
0
/* Print Welcome Screen Menu subroutine by Interrupt mode */
static void Print_Menu_Interrupt(LPC_USART_T *UARTx)
{
    uint32_t tmp;
    uint8_t *pDat;

    tmp = sizeof(uart_interrupt_menu);
    pDat = (uint8_t *) &uart_interrupt_menu[0];
    Chip_UART_SendRB(UARTx, &txring, pDat, tmp);
}
Exemplo n.º 4
0
/* Send data to uart */
uint32_t uart_write(uint8_t *pbuf, uint32_t len)
{
    uint32_t ret = 0;

    if (pbuf)
        ret = Chip_UART_SendRB(LPC_USART, &uart_txrb, pbuf, len);

    return ret;
}
Exemplo n.º 5
0
/* Send data to uart */
uint32_t UART_Write(uint8_t *pBuf, uint32_t len)
{
	uint32_t ret = 0;

	if(pBuf)
	{
		ret = Chip_UART_SendRB(LPC_USART, &uart_txrb, pBuf, len);
	}

	return ret;
}
Exemplo n.º 6
0
static void ether_to_uart(uint8_t sock)
{
	uint8_t sock_state;
	uint8_t dstip[4];
	uint16_t dstport, len = 0;

	getsockopt(sock, SO_STATUS, &sock_state);

	switch (sock_state) {
		case SOCK_UDP:
			getsockopt(sock, SO_RECVBUF, &len);

			if(len > UART_SRB_SIZE)
				len = UART_SRB_SIZE;

			if((len > 0) && len <= RingBuffer_GetFree(&txring)) {
				len = recvfrom(sock, g_recv_buf, sizeof(g_recv_buf), dstip, &dstport);
				if(len < 0) {
					//printf("recvfrom error\r\n");
					return;
				}
				ether_recv_cnt += len;
			} else
				len = 0;

			break;

		case SOCK_ESTABLISHED:
			getsockopt(sock, SO_RECVBUF, &len);

			if(len > UART_SRB_SIZE)
				len = UART_SRB_SIZE;

			if((len > 0) && len <= RingBuffer_GetFree(&txring)) {
				len = recv(sock, g_recv_buf, sizeof(g_recv_buf));
				if(len < 0) {
					//printf("recv error\r\n");
					return;
				}
				ether_recv_cnt += len;
			} else
				len = 0;

			break;
		default:
			break;
	}

	if(len) {
		Chip_UART_SendRB(UART_DATA, &txring, g_recv_buf, len);
		uart_send_cnt += len;
	}
}
Exemplo n.º 7
0
static void trigger_state3_process(uint8_t sock)
{
	if(trigger_flag == 2) {
		trigger_state = TRIG_STATE_NONE;
#ifdef __TRIG_DEBUG__
		printf("[%s] TRIG_STATE_NONE #1\r\n", __func__);
#endif
		trigger_flag = uart_size_prev = 0;
		pattern_offset = 0;

		disconnect(sock);
		UART_buffer_flush(&rxring);
		UART_buffer_flush(&txring);

		Chip_UART_SendRB(UART_DATA, &txring, "\r\n\r\n\r\n[W,0]\r\n", 13);
		Chip_UART_SendRB(UART_DATA, &txring, "[S,0]\r\n", 7);
		op_mode = OP_COMMAND;

		close(sock);
		return;
	}

	if(pattern_cnt < RingBuffer_GetCount(&rxring)) {
		trigger_state = TRIG_STATE_NONE;
#ifdef __TRIG_DEBUG__
		printf("[%s] TRIG_STATE_NONE #2\r\n", __func__);
#endif
		trigger_flag = trigger_time = uart_size_prev = 0;
	}

	if(uart_size_prev != RingBuffer_GetCount(&rxring)) {
		trigger_state = TRIG_STATE_NONE;
#ifdef __TRIG_DEBUG__
		printf("[%s] TRIG_STATE_NONE #3\r\n", __func__);
#endif
		trigger_flag = trigger_time = uart_size_prev = 0;
	}
}
Exemplo n.º 8
0
int uartSend(ciaaUART_e nUART, void * data, int datalen)
{
	uartData_t * u = &(uarts[nUART]);

	return Chip_UART_SendRB(u->uart, u->trb, data, datalen);
}
Exemplo n.º 9
0
uint32_t UART_write(void *data, int bytes)
{
	return Chip_UART_SendRB(LPC_USART, &txring, data, bytes);
}
Exemplo n.º 10
0
void skynetbase_gps_config(char msg[]) {
	Chip_UART_SendRB(GPS_UART, &txring, (void*)msg, strlen(msg));
}
Exemplo n.º 11
0
void skynetbase_gps_query(void) {
	char tmp[] = "$PUBX,00*33\r\n";
	Chip_UART_SendRB(GPS_UART, &txring, (void*)tmp, sizeof(tmp) - 1);
}
Exemplo n.º 12
0
Arquivo: uart_rb.c Projeto: taphier/lk
/**
 * @brief	Main UART program body
 * @return	Always returns 1
 */
int main(void)
{
    uint8_t key;
    int bytes;

    SystemCoreClockUpdate();
    Board_Init();
    Init_UART_PinMux();
    Board_LED_Set(0, false);

    /* Before setting up the UART, the global UART clock for USARTS 1-4
       must first be setup. This requires setting the UART divider and
       the UART base clock rate to 16x the maximum UART rate for all
       UARTs. */
#if defined(USE_INTEGER_CLOCK)
    /* Use main clock rate as base for UART baud rate divider */
    Chip_Clock_SetUARTBaseClockRate(Chip_Clock_GetMainClockRate(), false);

#else
    /* Use 128x expected UART baud rate for fractional baud mode. */
    Chip_Clock_SetUARTBaseClockRate((115200 * 128), true);
#endif

    /* Setup UART */
    Chip_UART_Init(LPC_USART);
    Chip_UART_ConfigData(LPC_USART, UART_CFG_DATALEN_8 | UART_CFG_PARITY_NONE | UART_CFG_STOPLEN_1);
    Chip_UART_SetBaud(LPC_USART, UART_TEST_DEFAULT_BAUDRATE);
    /* Optional for low clock rates only: Chip_UART_SetBaudWithRTC32K(LPC_USART, 300); */
    Chip_UART_Enable(LPC_USART);
    Chip_UART_TXEnable(LPC_USART);

    /* Before using the ring buffers, initialize them using the ring
       buffer init function */
    RingBuffer_Init(&rxring, rxbuff, 1, UART_RB_SIZE);
    RingBuffer_Init(&txring, txbuff, 1, UART_RB_SIZE);

    /* Enable receive data and line status interrupt */
    Chip_UART_IntEnable(LPC_USART, UART_INTEN_RXRDY);
    Chip_UART_IntDisable(LPC_USART, UART_INTEN_TXRDY);	/* May not be needed */

    /* Enable UART interrupt */
    NVIC_EnableIRQ(LPC_IRQNUM);

    /* Initial message sent using blocking method to prevent ring
       buffer overflow */
    Chip_UART_SendBlocking(LPC_USART, inst1, sizeof(inst1) - 1);
    Chip_UART_SendRB(LPC_USART, &txring, inst2, sizeof(inst2) - 1);

    /* Poll the receive ring buffer for the ESC (ASCII 27) key */
    key = 0;
    while (key != 27) {
        bytes = Chip_UART_ReadRB(LPC_USART, &rxring, &key, 1);
        if (bytes > 0) {
            /* Wrap value back around */
            if (Chip_UART_SendRB(LPC_USART, &txring, (const uint8_t *) &key, 1) != 1) {
                Board_LED_Toggle(0);/* Toggle LED if the TX FIFO is full */
            }
        }
    }

    /* DeInitialize UART peripheral */
    NVIC_DisableIRQ(LPC_IRQNUM);
    Chip_UART_DeInit(LPC_USART);

    return 1;
}