Merge branch 'master' of https://github.com/RT-Thread/rt-thread
This commit is contained in:
commit
dedc22379a
@ -37,7 +37,7 @@
|
||||
#define LSR_RXFE 0x80
|
||||
|
||||
/**
|
||||
* @addtogroup LPC11xx
|
||||
* @addtogroup LPC176x
|
||||
*/
|
||||
|
||||
/*@{*/
|
||||
@ -54,12 +54,12 @@ struct rt_uart_lpc
|
||||
/* buffer for reception */
|
||||
rt_uint8_t read_index, save_index;
|
||||
rt_uint8_t rx_buffer[RT_UART_RX_BUFFER_SIZE];
|
||||
}uart_device;
|
||||
} uart_device;
|
||||
|
||||
void UART0_IRQHandler(void)
|
||||
{
|
||||
rt_ubase_t level, iir;
|
||||
struct rt_uart_lpc* uart = &uart_device;
|
||||
struct rt_uart_lpc *uart = &uart_device;
|
||||
|
||||
/* read IIR and clear it */
|
||||
iir = LPC_UART->IIR;
|
||||
@ -79,7 +79,7 @@ void UART0_IRQHandler(void)
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
/* invoke callback */
|
||||
if(uart->parent.rx_indicate != RT_NULL)
|
||||
if (uart->parent.rx_indicate != RT_NULL)
|
||||
{
|
||||
rt_size_t length;
|
||||
if (uart->read_index > uart->save_index)
|
||||
@ -90,11 +90,15 @@ void UART0_IRQHandler(void)
|
||||
uart->parent.rx_indicate(&uart->parent, length);
|
||||
}
|
||||
}
|
||||
else if (iir == IIR_RLS)
|
||||
{
|
||||
iir = LPC_UART->LSR; //oe pe fe oe read for clear interrupt
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static rt_err_t rt_uart_init (rt_device_t dev)
|
||||
static rt_err_t rt_uart_init(rt_device_t dev)
|
||||
{
|
||||
rt_uint32_t Fdiv;
|
||||
rt_uint32_t pclkdiv, pclk;
|
||||
@ -108,31 +112,31 @@ static rt_err_t rt_uart_init (rt_device_t dev)
|
||||
all the peripherals is 1/4 of the SystemFrequency. */
|
||||
/* Bit 6~7 is for UART0 */
|
||||
pclkdiv = (LPC_SC->PCLKSEL0 >> 6) & 0x03;
|
||||
switch ( pclkdiv )
|
||||
switch (pclkdiv)
|
||||
{
|
||||
case 0x00:
|
||||
default:
|
||||
pclk = SystemCoreClock/4;
|
||||
pclk = SystemCoreClock / 4;
|
||||
break;
|
||||
case 0x01:
|
||||
pclk = SystemCoreClock;
|
||||
break;
|
||||
case 0x02:
|
||||
pclk = SystemCoreClock/2;
|
||||
pclk = SystemCoreClock / 2;
|
||||
break;
|
||||
case 0x03:
|
||||
pclk = SystemCoreClock/8;
|
||||
pclk = SystemCoreClock / 8;
|
||||
break;
|
||||
}
|
||||
|
||||
LPC_UART0->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
|
||||
Fdiv = ( pclk / 16 ) / UART_BAUDRATE; /*baud rate */
|
||||
Fdiv = (pclk / 16) / UART_BAUDRATE; /*baud rate */
|
||||
LPC_UART0->DLM = Fdiv / 256;
|
||||
LPC_UART0->DLL = Fdiv % 256;
|
||||
LPC_UART0->LCR = 0x03; /* DLAB = 0 */
|
||||
LPC_UART0->FCR = 0x07; /* Enable and reset TX and RX FIFO. */
|
||||
}
|
||||
else if ((LPC_UART1_TypeDef*)LPC_UART == LPC_UART1)
|
||||
else if ((LPC_UART1_TypeDef *)LPC_UART == LPC_UART1)
|
||||
{
|
||||
LPC_PINCON->PINSEL4 &= ~0x0000000F;
|
||||
LPC_PINCON->PINSEL4 |= 0x0000000A; /* Enable RxD1 P2.1, TxD1 P2.0 */
|
||||
@ -141,25 +145,25 @@ static rt_err_t rt_uart_init (rt_device_t dev)
|
||||
all the peripherals is 1/4 of the SystemFrequency. */
|
||||
/* Bit 8,9 are for UART1 */
|
||||
pclkdiv = (LPC_SC->PCLKSEL0 >> 8) & 0x03;
|
||||
switch ( pclkdiv )
|
||||
switch (pclkdiv)
|
||||
{
|
||||
case 0x00:
|
||||
default:
|
||||
pclk = SystemCoreClock/4;
|
||||
pclk = SystemCoreClock / 4;
|
||||
break;
|
||||
case 0x01:
|
||||
pclk = SystemCoreClock;
|
||||
break;
|
||||
case 0x02:
|
||||
pclk = SystemCoreClock/2;
|
||||
pclk = SystemCoreClock / 2;
|
||||
break;
|
||||
case 0x03:
|
||||
pclk = SystemCoreClock/8;
|
||||
pclk = SystemCoreClock / 8;
|
||||
break;
|
||||
}
|
||||
|
||||
LPC_UART1->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
|
||||
Fdiv = ( pclk / 16 ) / UART_BAUDRATE ; /*baud rate */
|
||||
Fdiv = (pclk / 16) / UART_BAUDRATE ; /*baud rate */
|
||||
LPC_UART1->DLM = Fdiv / 256;
|
||||
LPC_UART1->DLL = Fdiv % 256;
|
||||
LPC_UART1->LCR = 0x03; /* DLAB = 0 */
|
||||
@ -167,8 +171,8 @@ static rt_err_t rt_uart_init (rt_device_t dev)
|
||||
}
|
||||
|
||||
/* Ensure a clean start, no data in either TX or RX FIFO. */
|
||||
while (( LPC_UART->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) );
|
||||
while ( LPC_UART->LSR & LSR_RDR )
|
||||
while ((LPC_UART->LSR & (LSR_THRE | LSR_TEMT)) != (LSR_THRE | LSR_TEMT));
|
||||
while (LPC_UART->LSR & LSR_RDR)
|
||||
{
|
||||
Fdiv = LPC_UART->RBR; /* Dump data from RX FIFO */
|
||||
}
|
||||
@ -201,14 +205,14 @@ static rt_err_t rt_uart_close(rt_device_t dev)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_size_t rt_uart_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
|
||||
static rt_size_t rt_uart_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
|
||||
{
|
||||
rt_uint8_t* ptr;
|
||||
struct rt_uart_lpc *uart = (struct rt_uart_lpc*)dev;
|
||||
rt_uint8_t *ptr;
|
||||
struct rt_uart_lpc *uart = (struct rt_uart_lpc *)dev;
|
||||
RT_ASSERT(uart != RT_NULL);
|
||||
|
||||
/* point to buffer */
|
||||
ptr = (rt_uint8_t*) buffer;
|
||||
ptr = (rt_uint8_t *) buffer;
|
||||
if (dev->flag & RT_DEVICE_FLAG_INT_RX)
|
||||
{
|
||||
while (size)
|
||||
@ -248,10 +252,10 @@ static rt_size_t rt_uart_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_si
|
||||
return 0;
|
||||
}
|
||||
|
||||
static rt_size_t rt_uart_write(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
|
||||
static rt_size_t rt_uart_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
|
||||
{
|
||||
char *ptr;
|
||||
ptr = (char*)buffer;
|
||||
ptr = (char *)buffer;
|
||||
|
||||
if (dev->flag & RT_DEVICE_FLAG_STREAM)
|
||||
{
|
||||
@ -261,13 +265,13 @@ static rt_size_t rt_uart_write(rt_device_t dev, rt_off_t pos, const void* buffer
|
||||
if (*ptr == '\n')
|
||||
{
|
||||
/* THRE status, contain valid data */
|
||||
while ( !(LPC_UART->LSR & LSR_THRE) );
|
||||
while (!(LPC_UART->LSR & LSR_THRE));
|
||||
/* write data */
|
||||
LPC_UART->THR = '\r';
|
||||
}
|
||||
|
||||
/* THRE status, contain valid data */
|
||||
while ( !(LPC_UART->LSR & LSR_THRE) );
|
||||
while (!(LPC_UART->LSR & LSR_THRE));
|
||||
/* write data */
|
||||
LPC_UART->THR = *ptr;
|
||||
|
||||
@ -277,10 +281,10 @@ static rt_size_t rt_uart_write(rt_device_t dev, rt_off_t pos, const void* buffer
|
||||
}
|
||||
else
|
||||
{
|
||||
while ( size != 0 )
|
||||
while (size != 0)
|
||||
{
|
||||
/* THRE status, contain valid data */
|
||||
while ( !(LPC_UART->LSR & LSR_THRE) );
|
||||
while (!(LPC_UART->LSR & LSR_THRE));
|
||||
|
||||
/* write data */
|
||||
LPC_UART->THR = *ptr;
|
||||
@ -295,7 +299,7 @@ static rt_size_t rt_uart_write(rt_device_t dev, rt_off_t pos, const void* buffer
|
||||
|
||||
void rt_hw_uart_init(void)
|
||||
{
|
||||
struct rt_uart_lpc* uart;
|
||||
struct rt_uart_lpc *uart;
|
||||
|
||||
/* get uart device */
|
||||
uart = &uart_device;
|
||||
|
@ -282,6 +282,37 @@ int cmd_ifconfig(int argc, char **argv)
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT_ALIAS(cmd_ifconfig, __cmd_ifconfig, list the information of network interfaces);
|
||||
|
||||
#ifdef RT_LWIP_DNS
|
||||
#include <lwip/api.h>
|
||||
#include <lwip/dns.h>
|
||||
int cmd_dns(int argc, char **argv)
|
||||
{
|
||||
extern void set_dns(char* dns_server);
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
int index;
|
||||
struct ip_addr ip_addr;
|
||||
for(index=0; index<DNS_MAX_SERVERS; index++)
|
||||
{
|
||||
ip_addr = dns_getserver(index);
|
||||
rt_kprintf("dns server #%d: %s\n", index, ipaddr_ntoa(&(ip_addr)));
|
||||
}
|
||||
}
|
||||
else if (argc == 2)
|
||||
{
|
||||
rt_kprintf("dns : %s\n", argv[1]);
|
||||
set_dns(argv[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("bad parameter! e.g: dns 114.114.114.114\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT_ALIAS(cmd_dns, __cmd_dns, list the information of dns);
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_TCP
|
||||
int cmd_netstat(int argc, char **argv)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user