/* 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();
}
Beispiel #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;
}
/* Read data from uart */
uint32_t UART_Read(uint8_t *pBuf, uint32_t buf_len)
{
	uint16_t cnt = 0;

	if(pBuf)
	{
		cnt = Chip_UART_ReadRB(LPC_USART, &uart_rxrb, pBuf, buf_len);
	}

	return cnt;
}
Beispiel #4
0
/* Read data from uart */
uint32_t uart_read(uint8_t *pbuf, uint32_t buf_len)
{
    uint16_t cnt = 0;
    uint8_t h1 = 0;
    uint8_t h2 = 0;

    Chip_UART_ReadRB(LPC_USART, &uart_rxrb, &h1, 1);
    if (h1 != AVAM_H1)
        return 0;

    Chip_UART_ReadRB(LPC_USART, &uart_rxrb, &h2, 1);
    if (h2 != AVAM_H2)
        return 0;

    if (pbuf) {
        pbuf[0] = h1;
        pbuf[1] = h2;
        pbuf += 2;
        cnt = Chip_UART_ReadRB(LPC_USART, &uart_rxrb, pbuf, (buf_len - 2));
    }

    return cnt + 2;
}
Beispiel #5
0
void skynetbase_gps_receive_data(void) {
	char c;
	int bytes = Chip_UART_ReadRB(GPS_UART, &rxring, &c, 1);
	if (bytes < 1) return;

	if (c == '$') { // beginning
		gpsoutpos = 0;
	}
	else if (c == '*' && gpsoutpos > 0) { // ending, for now ignore checksum
		gpsout[gpsoutpos] = 0;
		skynetbase_gps_received_data(gpsout, gpsoutpos);
		return;
	}

	gpsout[gpsoutpos++] = c;
}
Beispiel #6
0
int uartRecv(ciaaUART_e nUART, void * data, int datalen)
{
	uartData_t * u = &(uarts[nUART]);

	return Chip_UART_ReadRB(u->uart, u->rrb, data, datalen);
}
Beispiel #7
0
int UART_read(void *data, int bytes)
{
	return Chip_UART_ReadRB(LPC_USART, &rxring, data, bytes);
}
static void uart_to_ether(uint8_t sock)
{
	struct __network_info *net = (struct __network_info *)get_S2E_Packet_pointer()->network_info;
	uint8_t sock_state, snd_flag = 0, mask_bit = 0;
	uint16_t len = 0;
	int ret, uart_read_len = sizeof(g_send_buf);

	if(RingBuffer_IsEmpty(&rxring))
		return;

	/* Serial Trigger Process */
	if((trigger_state != TRIG_STATE_NONE) && (trigger_state != TRIG_STATE_READY))
		return;

	/* UART Packing Size Check */
	if(net->packing_size)
		mask_bit |= 0x01;

	if(RingBuffer_GetCount(&rxring) < net->packing_size)
		snd_flag |= 0x01;
	else {
		if(net->packing_size)
			uart_read_len = net->packing_size;
	}

	/* Nagle Timer Process */
	if(net->packing_time)
		mask_bit |= 0x02;

	if(!nagle_flag && net->packing_time)
		snd_flag |= 0x02;

	/* Seperator Process */
	if(net->packing_delimiter_length)  {
		mask_bit |= 0x04;
		if(!(ret = RingBuffer_SerachPattern(&rxring, 0, net->packing_delimiter, net->packing_delimiter_length)))
			snd_flag |= 0x04;
		else {
			if(!(mask_bit & 0x01) || (snd_flag & 0x01) || (ret + net->packing_data_appendix < net->packing_size)) {
				uart_read_len = ret + net->packing_data_appendix;

				if(RingBuffer_GetCount(&rxring) < uart_read_len)
					snd_flag |= 0x04;
			}
		}
	}

	//printf("snd_flag = %02x / mask_bit = %02x\r\n", snd_flag, mask_bit);
	if(mask_bit != 0)				// mask_bit : Enable Uart Packing Condition bit
		if((snd_flag & mask_bit) == mask_bit)
			return;

	/* Serial Trigger Process */
	if(trigger_state == TRIG_STATE_READY)
		if(ready_cnt != RingBuffer_GetCount(&rxring))
			return;

	getsockopt(sock, SO_STATUS, &sock_state);

	if(sock_state != SOCK_UDP && sock_state != SOCK_ESTABLISHED)
		return;

	/* Data Transfer */
	len = Chip_UART_ReadRB(UART_DATA, &rxring, &g_send_buf, uart_read_len);
	if(len < 0) {
		//printf("uart recv error\r\n");
		return;
	}
	uart_recv_cnt += len;
	pattern_offset = 0;

	if(sock_state == SOCK_UDP) {
		uint8_t remote_ip[4];
		memcpy(remote_ip, net->remote_ip, sizeof(remote_ip));
		ret = sendto(sock, g_send_buf, len, remote_ip, net->remote_port);
		if(ret != len) {
			//printf("sendto error\r\n");
			return;
		}
		ether_send_cnt += len;
	} else if(sock_state == SOCK_ESTABLISHED) {
		ret = send(sock, g_send_buf, len);
		if(ret != len) {
			//printf("send error\r\n");
			return;
		}
		ether_send_cnt += len;
	}

	nagle_flag = nagle_time = uart_recv_count = 0;
}
Beispiel #9
0
/**
 * @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;
}