From 958d9405755560e108e730ab2bb6cdd68ec6009a Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 17 Mar 2021 02:26:35 +0800 Subject: [PATCH] [lpcxxx] auto formatted --- bsp/lpc1114/driver/board.c | 4 +- bsp/lpc1114/driver/drv_uart.c | 2 +- bsp/lpc176x/applications/application.c | 36 +- bsp/lpc176x/applications/platform.c | 8 +- bsp/lpc176x/applications/platform.h | 2 +- bsp/lpc176x/applications/startup.c | 56 +- bsp/lpc176x/drivers/board.c | 34 +- bsp/lpc176x/drivers/board.h | 2 +- bsp/lpc176x/drivers/emac.c | 840 +++---- bsp/lpc176x/drivers/emac.h | 11 +- bsp/lpc176x/drivers/led.h | 2 +- bsp/lpc176x/drivers/sd.c | 8 +- bsp/lpc176x/drivers/spi.c | 249 +- bsp/lpc176x/drivers/spi.h | 25 +- bsp/lpc176x/drivers/uart.c | 10 +- bsp/lpc176x/rtconfig.h | 52 +- bsp/lpc178x/applications/application.c | 90 +- bsp/lpc178x/applications/startup.c | 64 +- bsp/lpc178x/drivers/board.c | 2 +- bsp/lpc178x/drivers/board.h | 4 +- bsp/lpc178x/drivers/drv_glcd.c | 370 +-- bsp/lpc178x/drivers/drv_glcd.h | 12 +- bsp/lpc178x/drivers/emac.c | 836 +++---- bsp/lpc178x/drivers/emac.h | 11 +- bsp/lpc178x/drivers/lpc177x_8x_clkpwr.c | 376 +-- bsp/lpc178x/drivers/lpc177x_8x_clkpwr.h | 174 +- bsp/lpc178x/drivers/lpc177x_8x_emc.c | 500 ++-- bsp/lpc178x/drivers/lpc177x_8x_emc.h | 142 +- bsp/lpc178x/drivers/lpc177x_8x_pinsel.c | 418 ++-- bsp/lpc178x/drivers/lpc177x_8x_pinsel.h | 348 +-- bsp/lpc178x/drivers/lpc177x_8x_uart.c | 2144 ++++++++--------- bsp/lpc178x/drivers/lpc177x_8x_uart.h | 514 ++-- bsp/lpc178x/drivers/lpc17xx_lcd.c | 96 +- bsp/lpc178x/drivers/lpc_types.h | 36 +- bsp/lpc178x/drivers/sdram.c | 112 +- bsp/lpc178x/drivers/sdram.h | 9 + bsp/lpc178x/drivers/uart.c | 342 +-- bsp/lpc178x/rtconfig.h | 56 +- bsp/lpc2148/applications/application.c | 2 +- bsp/lpc2148/applications/startup.c | 2 +- bsp/lpc2148/drivers/board.c | 86 +- bsp/lpc2148/drivers/board.h | 8 +- bsp/lpc2148/drivers/dm9000.c | 96 +- bsp/lpc2148/drivers/sd.c | 90 +- bsp/lpc2148/drivers/serial.c | 506 ++-- bsp/lpc2148/rtconfig.h | 46 +- bsp/lpc2478/applications/application.c | 2 +- bsp/lpc2478/applications/startup.c | 2 +- bsp/lpc2478/drivers/board.c | 28 +- bsp/lpc2478/drivers/board.h | 140 +- bsp/lpc2478/drivers/serial.c | 528 ++-- bsp/lpc2478/rtconfig.h | 38 +- bsp/lpc408x/applications/main.c | 8 +- bsp/lpc408x/drivers/board.c | 2 +- bsp/lpc408x/drivers/board.h | 2 +- bsp/lpc408x/drivers/drv_emac.c | 2 +- bsp/lpc408x/drivers/drv_emac.h | 2 +- bsp/lpc408x/drivers/drv_hwtimer.c | 2 +- bsp/lpc408x/drivers/drv_hwtimer.h | 2 +- bsp/lpc408x/drivers/drv_led.c | 2 +- bsp/lpc408x/drivers/drv_led.h | 2 +- bsp/lpc408x/drivers/drv_sdram.c | 2 +- bsp/lpc408x/drivers/drv_sdram.h | 2 +- bsp/lpc408x/drivers/drv_uart.c | 2 +- bsp/lpc408x/drivers/drv_uart.h | 2 +- bsp/lpc43xx/M0/applications/application.c | 2 +- bsp/lpc43xx/M0/applications/board.c | 2 +- bsp/lpc43xx/M0/applications/board.h | 2 +- bsp/lpc43xx/M0/applications/startup.c | 2 +- bsp/lpc43xx/M0/applications/vbus_drv.c | 4 +- bsp/lpc43xx/M0/applications/vbus_hw.h | 4 +- bsp/lpc43xx/M4/applications/application.c | 6 +- bsp/lpc43xx/M4/applications/board.c | 2 +- bsp/lpc43xx/M4/applications/board.h | 2 +- bsp/lpc43xx/M4/applications/startup.c | 2 +- bsp/lpc43xx/M4/applications/vbus_drv.c | 4 +- bsp/lpc43xx/M4/applications/vbus_hw.h | 4 +- bsp/lpc43xx/drivers/drv_emac.c | 2 +- bsp/lpc43xx/drivers/drv_emac.h | 2 +- bsp/lpc43xx/drivers/drv_led.c | 2 +- bsp/lpc43xx/drivers/drv_uart.c | 8 +- bsp/lpc5410x/applications/application.c | 2 +- bsp/lpc5410x/applications/board.c | 4 +- bsp/lpc5410x/applications/board.h | 2 +- bsp/lpc5410x/applications/demo_thread.c | 60 +- bsp/lpc5410x/applications/startup.c | 2 +- bsp/lpc5410x/drivers/drv_led.c | 2 +- bsp/lpc5410x/drivers/drv_led.h | 9 + bsp/lpc5410x/drivers/drv_uart.c | 2 +- bsp/lpc5410x/drivers/drv_uart.h | 9 + bsp/lpc5410x/rtconfig.h | 52 +- bsp/lpc54114-lite/applications/main.c | 6 +- bsp/lpc54114-lite/applications/mnt.c | 10 +- bsp/lpc54114-lite/drivers/audio/drv_mic.c | 4 +- bsp/lpc54114-lite/drivers/audio/drv_mic.h | 2 +- bsp/lpc54114-lite/drivers/audio/drv_sound.c | 4 +- bsp/lpc54114-lite/drivers/audio/drv_sound.h | 2 +- bsp/lpc54114-lite/drivers/board.c | 8 +- bsp/lpc54114-lite/drivers/board.h | 2 +- bsp/lpc54114-lite/drivers/drv_gpio.c | 130 +- bsp/lpc54114-lite/drivers/drv_gpio.h | 4 +- bsp/lpc54114-lite/drivers/drv_i2c.c | 40 +- bsp/lpc54114-lite/drivers/drv_i2c.h | 12 +- bsp/lpc54114-lite/drivers/drv_romfs.c | 18 +- bsp/lpc54114-lite/drivers/drv_sdcard.c | 22 +- bsp/lpc54114-lite/drivers/drv_sdcard.h | 12 +- bsp/lpc54114-lite/drivers/drv_spi.c | 138 +- bsp/lpc54114-lite/drivers/drv_spi.h | 16 +- bsp/lpc54114-lite/drivers/drv_spi_flash.c | 28 +- bsp/lpc54114-lite/drivers/drv_spi_flash.h | 4 +- bsp/lpc54114-lite/drivers/drv_uart.c | 46 +- bsp/lpc54114-lite/drivers/drv_uart.h | 4 +- .../applications/application.c | 10 +- bsp/lpc54608-LPCXpresso/applications/mnt.c | 8 +- .../applications/startup.c | 6 +- bsp/lpc54608-LPCXpresso/drivers/board.c | 10 +- bsp/lpc54608-LPCXpresso/drivers/board.h | 2 +- bsp/lpc54608-LPCXpresso/drivers/drt_mpu.c | 6 +- bsp/lpc54608-LPCXpresso/drivers/drt_mpu.h | 2 +- bsp/lpc54608-LPCXpresso/drivers/drv_emac.c | 126 +- bsp/lpc54608-LPCXpresso/drivers/drv_emac.h | 2 +- bsp/lpc54608-LPCXpresso/drivers/drv_ft5406.c | 4 +- bsp/lpc54608-LPCXpresso/drivers/drv_i2c.c | 4 +- bsp/lpc54608-LPCXpresso/drivers/drv_lcd.c | 6 +- bsp/lpc54608-LPCXpresso/drivers/drv_sd.c | 28 +- bsp/lpc54608-LPCXpresso/drivers/drv_sd.h | 4 +- bsp/lpc54608-LPCXpresso/drivers/drv_sdram.c | 12 +- bsp/lpc54608-LPCXpresso/drivers/drv_sdram.h | 2 +- bsp/lpc54608-LPCXpresso/drivers/drv_sram.c | 2 +- bsp/lpc54608-LPCXpresso/drivers/drv_sram.h | 2 +- bsp/lpc54608-LPCXpresso/drivers/drv_uart.c | 6 +- bsp/lpc54608-LPCXpresso/drivers/fsl_phy.c | 6 +- bsp/lpc55sxx/Libraries/drivers/drv_adc.c | 14 +- bsp/lpc55sxx/Libraries/drivers/drv_adc.h | 2 +- bsp/lpc55sxx/Libraries/drivers/drv_hwtimer.c | 34 +- bsp/lpc55sxx/Libraries/drivers/drv_hwtimer.h | 2 +- bsp/lpc55sxx/Libraries/drivers/drv_i2c.c | 8 +- bsp/lpc55sxx/Libraries/drivers/drv_i2c.h | 8 +- bsp/lpc55sxx/Libraries/drivers/drv_key.c | 12 +- bsp/lpc55sxx/Libraries/drivers/drv_key.h | 8 +- bsp/lpc55sxx/Libraries/drivers/drv_led.c | 2 +- bsp/lpc55sxx/Libraries/drivers/drv_led.h | 8 +- bsp/lpc55sxx/Libraries/drivers/drv_log.h | 2 +- bsp/lpc55sxx/Libraries/drivers/drv_mma8562.c | 14 +- bsp/lpc55sxx/Libraries/drivers/drv_pin.c | 70 +- bsp/lpc55sxx/Libraries/drivers/drv_pin.h | 8 +- bsp/lpc55sxx/Libraries/drivers/drv_pwm.c | 24 +- bsp/lpc55sxx/Libraries/drivers/drv_pwm.h | 2 +- bsp/lpc55sxx/Libraries/drivers/drv_rtc.c | 122 +- bsp/lpc55sxx/Libraries/drivers/drv_rtc.h | 8 +- bsp/lpc55sxx/Libraries/drivers/drv_sd.c | 14 +- bsp/lpc55sxx/Libraries/drivers/drv_sd.h | 4 +- bsp/lpc55sxx/Libraries/drivers/drv_spi.c | 228 +- bsp/lpc55sxx/Libraries/drivers/drv_spi.h | 14 +- bsp/lpc55sxx/Libraries/drivers/drv_uart.c | 36 +- bsp/lpc55sxx/Libraries/drivers/drv_uart.h | 2 +- bsp/lpc55sxx/Libraries/drivers/drv_wdt.c | 14 +- bsp/lpc55sxx/Libraries/drivers/drv_wdt.h | 2 +- .../template/lpc55s6xxxx/applications/main.c | 4 +- .../template/lpc55s6xxxx/board/board.c | 18 +- .../template/lpc55s6xxxx/board/board.h | 2 +- .../lpc55s69_nxp_evk/applications/main.c | 2 +- bsp/lpc55sxx/lpc55s69_nxp_evk/board/board.c | 18 +- bsp/lpc55sxx/lpc55s69_nxp_evk/board/board.h | 2 +- bsp/lpc824/applications/application.c | 20 +- bsp/lpc824/applications/startup.c | 4 +- bsp/lpc824/drivers/board.c | 4 +- bsp/lpc824/drivers/board.h | 2 +- bsp/lpc824/drivers/usart.c | 86 +- bsp/lpc824/drivers/usart.h | 2 +- bsp/lpc824/rtconfig.h | 20 +- 171 files changed, 5733 insertions(+), 5670 deletions(-) diff --git a/bsp/lpc1114/driver/board.c b/bsp/lpc1114/driver/board.c index 6f2a4c85a3..03aa631e71 100644 --- a/bsp/lpc1114/driver/board.c +++ b/bsp/lpc1114/driver/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -33,7 +33,7 @@ #define NVIC_ISPR HWREG32(SCB_BASE + 0x200) #define NVIC_ICPR HWREG32(SCB_BASE + 0x280) #define NVIC_IPR(irqno) HWREG32(SCB_BASE + 0x400 + (((irqno) / 4) << 2)) -#define SCB_SHPR3 HWREG32(SCB_BASE + 0xd20) +#define SCB_SHPR3 HWREG32(SCB_BASE + 0xd20) extern unsigned char __bss_end__[]; extern unsigned char _ram_end[]; diff --git a/bsp/lpc1114/driver/drv_uart.c b/bsp/lpc1114/driver/drv_uart.c index 96cf6f760d..10956140c1 100644 --- a/bsp/lpc1114/driver/drv_uart.c +++ b/bsp/lpc1114/driver/drv_uart.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2019, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc176x/applications/application.c b/bsp/lpc176x/applications/application.c index 9facb30aa8..173e2df1bb 100644 --- a/bsp/lpc176x/applications/application.c +++ b/bsp/lpc176x/applications/application.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -38,44 +38,44 @@ extern int lwip_system_init(void); /* thread phase init */ void rt_init_thread_entry(void *parameter) { - /* initialize platform */ - platform_init(); + /* initialize platform */ + platform_init(); #ifdef RT_USING_LWIP /* register Ethernet interface device */ lpc17xx_emac_hw_init(); /* initialize lwip stack */ - /* register ethernetif device */ - eth_system_device_init(); + /* register ethernetif device */ + eth_system_device_init(); - /* initialize lwip system */ - lwip_system_init(); - rt_kprintf("TCP/IP initialized!\n"); + /* initialize lwip system */ + lwip_system_init(); + rt_kprintf("TCP/IP initialized!\n"); #endif /* Filesystem Initialization */ #ifdef RT_USING_DFS rt_hw_sdcard_init(); - /* initialize the device file system */ - dfs_init(); + /* initialize the device file system */ + dfs_init(); #ifdef RT_USING_DFS_ELMFAT - /* initialize the elm chan FatFS file system*/ - elm_init(); + /* initialize the elm chan FatFS file system*/ + elm_init(); #endif /* mount sd card fat partition 1 as root directory */ if (dfs_mount("sd0", "/", "elm", 0, 0) == 0) - rt_kprintf("File System initialized!\n"); + rt_kprintf("File System initialized!\n"); else - rt_kprintf("File System init failed!\n"); + rt_kprintf("File System init failed!\n"); #endif #ifdef RT_USING_FINSH - /* initialize finsh */ - finsh_system_init(); + /* initialize finsh */ + finsh_system_init(); #endif } @@ -84,8 +84,8 @@ int rt_application_init() rt_thread_t tid; tid = rt_thread_create("init", - rt_init_thread_entry, RT_NULL, - 2048, RT_THREAD_PRIORITY_MAX/3, 20); + rt_init_thread_entry, RT_NULL, + 2048, RT_THREAD_PRIORITY_MAX/3, 20); if (tid != RT_NULL) rt_thread_startup(tid); return 0; diff --git a/bsp/lpc176x/applications/platform.c b/bsp/lpc176x/applications/platform.c index 4bab858aa4..05ff436e8d 100644 --- a/bsp/lpc176x/applications/platform.c +++ b/bsp/lpc176x/applications/platform.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -16,11 +16,11 @@ static struct rt_memheap _memheap; void platform_init(void) { #ifdef RT_USING_MEMHEAP - /* create memory heap object on 0x2007 C000 - 0x2008 4000*/ + /* create memory heap object on 0x2007 C000 - 0x2008 4000*/ #ifdef RT_USING_LWIP - rt_memheap_init(&_memheap, "system", (void*)0x2007C000, 16*1024); + rt_memheap_init(&_memheap, "system", (void*)0x2007C000, 16*1024); #else - rt_memheap_init(&_memheap, "system", (void*)0x2007C000, 32*1024); + rt_memheap_init(&_memheap, "system", (void*)0x2007C000, 32*1024); #endif #endif } diff --git a/bsp/lpc176x/applications/platform.h b/bsp/lpc176x/applications/platform.h index e52e4066c2..25a97d8666 100644 --- a/bsp/lpc176x/applications/platform.h +++ b/bsp/lpc176x/applications/platform.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc176x/applications/startup.c b/bsp/lpc176x/applications/startup.c index 63d5b0f9a5..b9db54c429 100644 --- a/bsp/lpc176x/applications/startup.c +++ b/bsp/lpc176x/applications/startup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -33,28 +33,28 @@ extern int __bss_end; */ void rtthread_startup(void) { - /* initialize board */ - rt_hw_board_init(); + /* initialize board */ + rt_hw_board_init(); - /* show version */ - rt_show_version(); + /* show version */ + rt_show_version(); #ifdef RT_USING_HEAP - /* initialize memory system */ - #ifdef __CC_ARM - rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)0x10008000); - #elif __ICCARM__ - rt_system_heap_init(__segment_end("HEAP"), (void*)0x10008000); - #else - rt_system_heap_init((void*)&__bss_end, (void*)0x10008000); - #endif + /* initialize memory system */ + #ifdef __CC_ARM + rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)0x10008000); + #elif __ICCARM__ + rt_system_heap_init(__segment_end("HEAP"), (void*)0x10008000); + #else + rt_system_heap_init((void*)&__bss_end, (void*)0x10008000); + #endif #endif - /* initialize scheduler system */ - rt_system_scheduler_init(); + /* initialize scheduler system */ + rt_system_scheduler_init(); - /* initialize application */ - rt_application_init(); + /* initialize application */ + rt_application_init(); /* initialize timer */ rt_system_timer_init(); @@ -62,25 +62,25 @@ void rtthread_startup(void) /* initialize timer thread */ rt_system_timer_thread_init(); - /* initialize idle thread */ - rt_thread_idle_init(); + /* initialize idle thread */ + rt_thread_idle_init(); - /* start scheduler */ - rt_system_scheduler_start(); + /* start scheduler */ + rt_system_scheduler_start(); - /* never reach here */ - return ; + /* never reach here */ + return ; } int main(void) { - /* disable interrupt first */ - rt_hw_interrupt_disable(); + /* disable interrupt first */ + rt_hw_interrupt_disable(); - /* startup RT-Thread RTOS */ - rtthread_startup(); + /* startup RT-Thread RTOS */ + rtthread_startup(); - return 0; + return 0; } /*@}*/ diff --git a/bsp/lpc176x/drivers/board.c b/bsp/lpc176x/drivers/board.c index c636462a2e..de3e476d55 100644 --- a/bsp/lpc176x/drivers/board.c +++ b/bsp/lpc176x/drivers/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -29,13 +29,13 @@ */ void rt_hw_timer_handler(void) { - /* enter interrupt */ - rt_interrupt_enter(); + /* enter interrupt */ + rt_interrupt_enter(); - rt_tick_increase(); + rt_tick_increase(); - /* leave interrupt */ - rt_interrupt_leave(); + /* leave interrupt */ + rt_interrupt_leave(); } void SysTick_Handler(void) @@ -48,24 +48,24 @@ void SysTick_Handler(void) */ void rt_hw_board_init() { - /* NVIC Configuration */ + /* NVIC Configuration */ #define NVIC_VTOR_MASK 0x3FFFFF80 #ifdef VECT_TAB_RAM - /* Set the Vector Table base location at 0x10000000 */ - SCB->VTOR = (0x10000000 & NVIC_VTOR_MASK); + /* Set the Vector Table base location at 0x10000000 */ + SCB->VTOR = (0x10000000 & NVIC_VTOR_MASK); #else /* VECT_TAB_FLASH */ - /* Set the Vector Table base location at 0x00000000 */ - SCB->VTOR = (0x00000000 & NVIC_VTOR_MASK); + /* Set the Vector Table base location at 0x00000000 */ + SCB->VTOR = (0x00000000 & NVIC_VTOR_MASK); #endif - /* initialize systick */ - SysTick_Config( SystemCoreClock/RT_TICK_PER_SECOND); - /* set pend exception priority */ - NVIC_SetPriority(PendSV_IRQn, (1<<__NVIC_PRIO_BITS) - 1); + /* initialize systick */ + SysTick_Config( SystemCoreClock/RT_TICK_PER_SECOND); + /* set pend exception priority */ + NVIC_SetPriority(PendSV_IRQn, (1<<__NVIC_PRIO_BITS) - 1); #ifdef RT_USING_UART0 - rt_hw_uart_init(); - rt_console_set_device(RT_CONSOLE_DEVICE_NAME); + rt_hw_uart_init(); + rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #endif } diff --git a/bsp/lpc176x/drivers/board.h b/bsp/lpc176x/drivers/board.h index 951a2c4cda..1e51e87615 100644 --- a/bsp/lpc176x/drivers/board.h +++ b/bsp/lpc176x/drivers/board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc176x/drivers/emac.c b/bsp/lpc176x/drivers/emac.c index 27fc55397a..e4f0363626 100644 --- a/bsp/lpc176x/drivers/emac.c +++ b/bsp/lpc176x/drivers/emac.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -11,20 +11,20 @@ #include "lwipopts.h" #include -#define EMAC_PHY_AUTO 0 -#define EMAC_PHY_10MBIT 1 -#define EMAC_PHY_100MBIT 2 +#define EMAC_PHY_AUTO 0 +#define EMAC_PHY_10MBIT 1 +#define EMAC_PHY_100MBIT 2 #define MAX_ADDR_LEN 6 struct lpc17xx_emac { - /* inherit from ethernet device */ - struct eth_device parent; + /* inherit from ethernet device */ + struct eth_device parent; - rt_uint8_t phy_mode; + rt_uint8_t phy_mode; - /* interface address info. */ - rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* hw address */ + /* interface address info. */ + rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* hw address */ }; static struct lpc17xx_emac lpc17xx_emac_device; static struct rt_semaphore sem_lock; @@ -36,40 +36,40 @@ static rt_uint16_t read_PHY (rt_uint8_t PhyReg) ; void ENET_IRQHandler(void) { - rt_uint32_t status; + rt_uint32_t status; /* enter interrupt */ rt_interrupt_enter(); - status = LPC_EMAC->IntStatus; - - if (status & INT_RX_DONE) - { - /* Disable EMAC RxDone interrupts. */ - LPC_EMAC->IntEnable = INT_TX_DONE; - - /* a frame has been received */ - eth_device_ready(&(lpc17xx_emac_device.parent)); - } - else if (status & INT_TX_DONE) - { - /* set event */ - rt_event_send(&tx_event, 0x01); - } - - if (status & INT_RX_OVERRUN) - { - rt_kprintf("rx overrun\n"); - } - - if (status & INT_TX_UNDERRUN) - { - rt_kprintf("tx underrun\n"); - } - - /* Clear the interrupt. */ - LPC_EMAC->IntClear = status; - + status = LPC_EMAC->IntStatus; + + if (status & INT_RX_DONE) + { + /* Disable EMAC RxDone interrupts. */ + LPC_EMAC->IntEnable = INT_TX_DONE; + + /* a frame has been received */ + eth_device_ready(&(lpc17xx_emac_device.parent)); + } + else if (status & INT_TX_DONE) + { + /* set event */ + rt_event_send(&tx_event, 0x01); + } + + if (status & INT_RX_OVERRUN) + { + rt_kprintf("rx overrun\n"); + } + + if (status & INT_TX_UNDERRUN) + { + rt_kprintf("tx underrun\n"); + } + + /* Clear the interrupt. */ + LPC_EMAC->IntClear = status; + /* leave interrupt */ rt_interrupt_leave(); } @@ -77,440 +77,440 @@ void ENET_IRQHandler(void) /* phy write */ static void write_PHY (rt_uint32_t PhyReg, rt_uint32_t Value) { - unsigned int tout; - - LPC_EMAC->MADR = DP83848C_DEF_ADR | PhyReg; - LPC_EMAC->MWTD = Value; - - /* Wait utill operation completed */ - tout = 0; - for (tout = 0; tout < MII_WR_TOUT; tout++) - { - if ((LPC_EMAC->MIND & MIND_BUSY) == 0) - { - break; - } - } + unsigned int tout; + + LPC_EMAC->MADR = DP83848C_DEF_ADR | PhyReg; + LPC_EMAC->MWTD = Value; + + /* Wait utill operation completed */ + tout = 0; + for (tout = 0; tout < MII_WR_TOUT; tout++) + { + if ((LPC_EMAC->MIND & MIND_BUSY) == 0) + { + break; + } + } } /* phy read */ static rt_uint16_t read_PHY (rt_uint8_t PhyReg) { - rt_uint32_t tout; - - LPC_EMAC->MADR = DP83848C_DEF_ADR | PhyReg; - LPC_EMAC->MCMD = MCMD_READ; - - /* Wait until operation completed */ - tout = 0; - for (tout = 0; tout < MII_RD_TOUT; tout++) - { - if ((LPC_EMAC->MIND & MIND_BUSY) == 0) - { - break; - } - } - LPC_EMAC->MCMD = 0; - return (LPC_EMAC->MRDD); + rt_uint32_t tout; + + LPC_EMAC->MADR = DP83848C_DEF_ADR | PhyReg; + LPC_EMAC->MCMD = MCMD_READ; + + /* Wait until operation completed */ + tout = 0; + for (tout = 0; tout < MII_RD_TOUT; tout++) + { + if ((LPC_EMAC->MIND & MIND_BUSY) == 0) + { + break; + } + } + LPC_EMAC->MCMD = 0; + return (LPC_EMAC->MRDD); } /* init rx descriptor */ rt_inline void rx_descr_init (void) { - rt_uint32_t i; - - for (i = 0; i < NUM_RX_FRAG; i++) - { - RX_DESC_PACKET(i) = RX_BUF(i); - RX_DESC_CTRL(i) = RCTRL_INT | (ETH_FRAG_SIZE-1); - RX_STAT_INFO(i) = 0; - RX_STAT_HASHCRC(i) = 0; - } - - /* Set EMAC Receive Descriptor Registers. */ - LPC_EMAC->RxDescriptor = RX_DESC_BASE; - LPC_EMAC->RxStatus = RX_STAT_BASE; - LPC_EMAC->RxDescriptorNumber = NUM_RX_FRAG-1; - - /* Rx Descriptors Point to 0 */ - LPC_EMAC->RxConsumeIndex = 0; + rt_uint32_t i; + + for (i = 0; i < NUM_RX_FRAG; i++) + { + RX_DESC_PACKET(i) = RX_BUF(i); + RX_DESC_CTRL(i) = RCTRL_INT | (ETH_FRAG_SIZE-1); + RX_STAT_INFO(i) = 0; + RX_STAT_HASHCRC(i) = 0; + } + + /* Set EMAC Receive Descriptor Registers. */ + LPC_EMAC->RxDescriptor = RX_DESC_BASE; + LPC_EMAC->RxStatus = RX_STAT_BASE; + LPC_EMAC->RxDescriptorNumber = NUM_RX_FRAG-1; + + /* Rx Descriptors Point to 0 */ + LPC_EMAC->RxConsumeIndex = 0; } /* init tx descriptor */ rt_inline void tx_descr_init (void) { - rt_uint32_t i; - - for (i = 0; i < NUM_TX_FRAG; i++) - { - TX_DESC_PACKET(i) = TX_BUF(i); - TX_DESC_CTRL(i) = (1ul<<31) | (1ul<<30) | (1ul<<29) | (1ul<<28) | (1ul<<26) | (ETH_FRAG_SIZE-1); - TX_STAT_INFO(i) = 0; - } - - /* Set EMAC Transmit Descriptor Registers. */ - LPC_EMAC->TxDescriptor = TX_DESC_BASE; - LPC_EMAC->TxStatus = TX_STAT_BASE; - LPC_EMAC->TxDescriptorNumber = NUM_TX_FRAG-1; - - /* Tx Descriptors Point to 0 */ - LPC_EMAC->TxProduceIndex = 0; + rt_uint32_t i; + + for (i = 0; i < NUM_TX_FRAG; i++) + { + TX_DESC_PACKET(i) = TX_BUF(i); + TX_DESC_CTRL(i) = (1ul<<31) | (1ul<<30) | (1ul<<29) | (1ul<<28) | (1ul<<26) | (ETH_FRAG_SIZE-1); + TX_STAT_INFO(i) = 0; + } + + /* Set EMAC Transmit Descriptor Registers. */ + LPC_EMAC->TxDescriptor = TX_DESC_BASE; + LPC_EMAC->TxStatus = TX_STAT_BASE; + LPC_EMAC->TxDescriptorNumber = NUM_TX_FRAG-1; + + /* Tx Descriptors Point to 0 */ + LPC_EMAC->TxProduceIndex = 0; } static rt_err_t lpc17xx_emac_init(rt_device_t dev) { - /* Initialize the EMAC ethernet controller. */ - rt_uint32_t regv, tout, id1, id2; - - /* Power Up the EMAC controller. */ - LPC_SC->PCONP |= 0x40000000; - - /* Enable P1 Ethernet Pins. */ - LPC_PINCON->PINSEL2 = 0x50150105; - LPC_PINCON->PINSEL3 = (LPC_PINCON->PINSEL3 & ~0x0000000F) | 0x00000005; - - /* Reset all EMAC internal modules. */ - LPC_EMAC->MAC1 = MAC1_RES_TX | MAC1_RES_MCS_TX | MAC1_RES_RX | MAC1_RES_MCS_RX | - MAC1_SIM_RES | MAC1_SOFT_RES; - LPC_EMAC->Command = CR_REG_RES | CR_TX_RES | CR_RX_RES; - - /* A short delay after reset. */ - for (tout = 100; tout; tout--); - - /* Initialize MAC control registers. */ - LPC_EMAC->MAC1 = MAC1_PASS_ALL; - LPC_EMAC->MAC2 = MAC2_CRC_EN | MAC2_PAD_EN; - LPC_EMAC->MAXF = ETH_MAX_FLEN; - LPC_EMAC->CLRT = CLRT_DEF; - LPC_EMAC->IPGR = IPGR_DEF; - - /* PCLK=18MHz, clock select=6, MDC=18/6=3MHz */ - /* Enable Reduced MII interface. */ - LPC_EMAC->MCFG = MCFG_CLK_DIV20 | MCFG_RES_MII; - for (tout = 100; tout; tout--); - LPC_EMAC->MCFG = MCFG_CLK_DIV20; - - /* Enable Reduced MII interface. */ - LPC_EMAC->Command = CR_RMII | CR_PASS_RUNT_FRM | CR_PASS_RX_FILT; - - /* Reset Reduced MII Logic. */ - LPC_EMAC->SUPP = SUPP_RES_RMII | SUPP_SPEED; - for (tout = 100; tout; tout--); - LPC_EMAC->SUPP = SUPP_SPEED; - - /* Put the PHY in reset mode */ - write_PHY (PHY_REG_BMCR, 0x8000); - for (tout = 1000; tout; tout--); - - /* Wait for hardware reset to end. */ - for (tout = 0; tout < 10000; tout++) - { - regv = read_PHY (PHY_REG_BMCR); - if (!(regv & 0x8000)) - { - /* Reset complete */ - break; - } - } - if (tout >= 10000) - { - //return -RT_ERROR; /* reset failed */ - rt_kprintf("\tPHY Read PHY_REG_BMSR,Reset timeout,tout: %d.\n",tout); - } - - /* Check if this is a DP83848C PHY. */ - id1 = read_PHY (PHY_REG_IDR1); - id2 = read_PHY (PHY_REG_IDR2); - - if (((id1 << 16) | (id2 & 0xFFF0)) != DP83848C_ID) - { - // return -RT_ERROR; - rt_kprintf("\tPHY Read PHY_REG_IDRx,PHY chip isn't DP83848C,Chip ID is %d.\n",((id1 << 16) | (id2 & 0xFFF0))); - } - else - { - /* Configure the PHY device */ - /* Configure the PHY device */ - switch (lpc17xx_emac_device.phy_mode) - { - case EMAC_PHY_AUTO: - /* Use auto negotiation about the link speed. */ - write_PHY (PHY_REG_BMCR, PHY_AUTO_NEG); - /* Wait to complete Auto_Negotiation. */ - for (tout = 0; tout < 200000; tout++) - { - regv = read_PHY (PHY_REG_BMSR); - if (regv & 0x0020) - { - /* Auto negotiation Complete. */ - break; - } - } - if(tout >= 200000) - { - rt_kprintf("\tPHY Read PHY_REG_BMSR,Auto nego timeout,tout: %d.\n",tout); - } - break; - case EMAC_PHY_10MBIT: - /* Connect at 10MBit */ - write_PHY (PHY_REG_BMCR, PHY_FULLD_10M); - break; - case EMAC_PHY_100MBIT: - /* Connect at 100MBit */ - write_PHY (PHY_REG_BMCR, PHY_FULLD_100M); - break; - } - } - //if (tout >= 0x100000) return -RT_ERROR; // auto_neg failed - - /* Check the link status. */ - for (tout = 0; tout < 100; tout++) - { - regv = read_PHY (PHY_REG_STS); - if (regv & 0x0001) - { - /* Link is on. */ - break; - } - } - if (tout >= 100) - { - //return -RT_ERROR; - rt_kprintf("\tPHY Read PHY_REG_BMSR,Link on timeout,tout: %d.\n",tout); - } - /* Configure Full/Half Duplex mode. */ - if (regv & 0x0004) - { - /* Full duplex is enabled. */ - LPC_EMAC->MAC2 |= MAC2_FULL_DUP; - LPC_EMAC->Command |= CR_FULL_DUP; - LPC_EMAC->IPGT = IPGT_FULL_DUP; - } - else - { - /* Half duplex mode. */ - LPC_EMAC->IPGT = IPGT_HALF_DUP; - } - - /* Configure 100MBit/10MBit mode. */ - if (regv & 0x0002) - { - /* 10MBit mode. */ - LPC_EMAC->SUPP = 0; - } - else - { - /* 100MBit mode. */ - LPC_EMAC->SUPP = SUPP_SPEED; - } - - /* Set the Ethernet MAC Address registers */ - LPC_EMAC->SA0 = (lpc17xx_emac_device.dev_addr[1]<<8) | lpc17xx_emac_device.dev_addr[0]; - LPC_EMAC->SA1 = (lpc17xx_emac_device.dev_addr[3]<<8) | lpc17xx_emac_device.dev_addr[2]; - LPC_EMAC->SA2 = (lpc17xx_emac_device.dev_addr[5]<<8) | lpc17xx_emac_device.dev_addr[4]; - - /* Initialize Tx and Rx DMA Descriptors */ - rx_descr_init (); - tx_descr_init (); - - /* Receive Broadcast and Perfect Match Packets */ - LPC_EMAC->RxFilterCtrl = RFC_BCAST_EN | RFC_PERFECT_EN; - - /* Reset all interrupts */ - LPC_EMAC->IntClear = 0xFFFF; - - /* Enable EMAC interrupts. */ - LPC_EMAC->IntEnable = INT_RX_DONE | INT_TX_DONE; - - /* Enable receive and transmit mode of MAC Ethernet core */ - LPC_EMAC->Command |= (CR_RX_EN | CR_TX_EN); - LPC_EMAC->MAC1 |= MAC1_REC_EN; - - /* Enable the ENET Interrupt */ - NVIC_EnableIRQ(ENET_IRQn); - - return RT_EOK; + /* Initialize the EMAC ethernet controller. */ + rt_uint32_t regv, tout, id1, id2; + + /* Power Up the EMAC controller. */ + LPC_SC->PCONP |= 0x40000000; + + /* Enable P1 Ethernet Pins. */ + LPC_PINCON->PINSEL2 = 0x50150105; + LPC_PINCON->PINSEL3 = (LPC_PINCON->PINSEL3 & ~0x0000000F) | 0x00000005; + + /* Reset all EMAC internal modules. */ + LPC_EMAC->MAC1 = MAC1_RES_TX | MAC1_RES_MCS_TX | MAC1_RES_RX | MAC1_RES_MCS_RX | + MAC1_SIM_RES | MAC1_SOFT_RES; + LPC_EMAC->Command = CR_REG_RES | CR_TX_RES | CR_RX_RES; + + /* A short delay after reset. */ + for (tout = 100; tout; tout--); + + /* Initialize MAC control registers. */ + LPC_EMAC->MAC1 = MAC1_PASS_ALL; + LPC_EMAC->MAC2 = MAC2_CRC_EN | MAC2_PAD_EN; + LPC_EMAC->MAXF = ETH_MAX_FLEN; + LPC_EMAC->CLRT = CLRT_DEF; + LPC_EMAC->IPGR = IPGR_DEF; + + /* PCLK=18MHz, clock select=6, MDC=18/6=3MHz */ + /* Enable Reduced MII interface. */ + LPC_EMAC->MCFG = MCFG_CLK_DIV20 | MCFG_RES_MII; + for (tout = 100; tout; tout--); + LPC_EMAC->MCFG = MCFG_CLK_DIV20; + + /* Enable Reduced MII interface. */ + LPC_EMAC->Command = CR_RMII | CR_PASS_RUNT_FRM | CR_PASS_RX_FILT; + + /* Reset Reduced MII Logic. */ + LPC_EMAC->SUPP = SUPP_RES_RMII | SUPP_SPEED; + for (tout = 100; tout; tout--); + LPC_EMAC->SUPP = SUPP_SPEED; + + /* Put the PHY in reset mode */ + write_PHY (PHY_REG_BMCR, 0x8000); + for (tout = 1000; tout; tout--); + + /* Wait for hardware reset to end. */ + for (tout = 0; tout < 10000; tout++) + { + regv = read_PHY (PHY_REG_BMCR); + if (!(regv & 0x8000)) + { + /* Reset complete */ + break; + } + } + if (tout >= 10000) + { + //return -RT_ERROR; /* reset failed */ + rt_kprintf("\tPHY Read PHY_REG_BMSR,Reset timeout,tout: %d.\n",tout); + } + + /* Check if this is a DP83848C PHY. */ + id1 = read_PHY (PHY_REG_IDR1); + id2 = read_PHY (PHY_REG_IDR2); + + if (((id1 << 16) | (id2 & 0xFFF0)) != DP83848C_ID) + { + // return -RT_ERROR; + rt_kprintf("\tPHY Read PHY_REG_IDRx,PHY chip isn't DP83848C,Chip ID is %d.\n",((id1 << 16) | (id2 & 0xFFF0))); + } + else + { + /* Configure the PHY device */ + /* Configure the PHY device */ + switch (lpc17xx_emac_device.phy_mode) + { + case EMAC_PHY_AUTO: + /* Use auto negotiation about the link speed. */ + write_PHY (PHY_REG_BMCR, PHY_AUTO_NEG); + /* Wait to complete Auto_Negotiation. */ + for (tout = 0; tout < 200000; tout++) + { + regv = read_PHY (PHY_REG_BMSR); + if (regv & 0x0020) + { + /* Auto negotiation Complete. */ + break; + } + } + if(tout >= 200000) + { + rt_kprintf("\tPHY Read PHY_REG_BMSR,Auto nego timeout,tout: %d.\n",tout); + } + break; + case EMAC_PHY_10MBIT: + /* Connect at 10MBit */ + write_PHY (PHY_REG_BMCR, PHY_FULLD_10M); + break; + case EMAC_PHY_100MBIT: + /* Connect at 100MBit */ + write_PHY (PHY_REG_BMCR, PHY_FULLD_100M); + break; + } + } + //if (tout >= 0x100000) return -RT_ERROR; // auto_neg failed + + /* Check the link status. */ + for (tout = 0; tout < 100; tout++) + { + regv = read_PHY (PHY_REG_STS); + if (regv & 0x0001) + { + /* Link is on. */ + break; + } + } + if (tout >= 100) + { + //return -RT_ERROR; + rt_kprintf("\tPHY Read PHY_REG_BMSR,Link on timeout,tout: %d.\n",tout); + } + /* Configure Full/Half Duplex mode. */ + if (regv & 0x0004) + { + /* Full duplex is enabled. */ + LPC_EMAC->MAC2 |= MAC2_FULL_DUP; + LPC_EMAC->Command |= CR_FULL_DUP; + LPC_EMAC->IPGT = IPGT_FULL_DUP; + } + else + { + /* Half duplex mode. */ + LPC_EMAC->IPGT = IPGT_HALF_DUP; + } + + /* Configure 100MBit/10MBit mode. */ + if (regv & 0x0002) + { + /* 10MBit mode. */ + LPC_EMAC->SUPP = 0; + } + else + { + /* 100MBit mode. */ + LPC_EMAC->SUPP = SUPP_SPEED; + } + + /* Set the Ethernet MAC Address registers */ + LPC_EMAC->SA0 = (lpc17xx_emac_device.dev_addr[1]<<8) | lpc17xx_emac_device.dev_addr[0]; + LPC_EMAC->SA1 = (lpc17xx_emac_device.dev_addr[3]<<8) | lpc17xx_emac_device.dev_addr[2]; + LPC_EMAC->SA2 = (lpc17xx_emac_device.dev_addr[5]<<8) | lpc17xx_emac_device.dev_addr[4]; + + /* Initialize Tx and Rx DMA Descriptors */ + rx_descr_init (); + tx_descr_init (); + + /* Receive Broadcast and Perfect Match Packets */ + LPC_EMAC->RxFilterCtrl = RFC_BCAST_EN | RFC_PERFECT_EN; + + /* Reset all interrupts */ + LPC_EMAC->IntClear = 0xFFFF; + + /* Enable EMAC interrupts. */ + LPC_EMAC->IntEnable = INT_RX_DONE | INT_TX_DONE; + + /* Enable receive and transmit mode of MAC Ethernet core */ + LPC_EMAC->Command |= (CR_RX_EN | CR_TX_EN); + LPC_EMAC->MAC1 |= MAC1_REC_EN; + + /* Enable the ENET Interrupt */ + NVIC_EnableIRQ(ENET_IRQn); + + return RT_EOK; } static rt_err_t lpc17xx_emac_open(rt_device_t dev, rt_uint16_t oflag) { - return RT_EOK; + return RT_EOK; } static rt_err_t lpc17xx_emac_close(rt_device_t dev) { - return RT_EOK; + return RT_EOK; } static rt_size_t lpc17xx_emac_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) { - rt_set_errno(-RT_ENOSYS); - return 0; + rt_set_errno(-RT_ENOSYS); + return 0; } static rt_size_t lpc17xx_emac_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) { - rt_set_errno(-RT_ENOSYS); - return 0; + rt_set_errno(-RT_ENOSYS); + return 0; } static rt_err_t lpc17xx_emac_control(rt_device_t dev, int cmd, void *args) { - switch (cmd) - { - case NIOCTL_GADDR: - /* get mac address */ - if (args) rt_memcpy(args, lpc17xx_emac_device.dev_addr, 6); - else return -RT_ERROR; - break; - - default : - break; - } - - return RT_EOK; + switch (cmd) + { + case NIOCTL_GADDR: + /* get mac address */ + if (args) rt_memcpy(args, lpc17xx_emac_device.dev_addr, 6); + else return -RT_ERROR; + break; + + default : + break; + } + + return RT_EOK; } /* EtherNet Device Interface */ /* transmit packet. */ rt_err_t lpc17xx_emac_tx( rt_device_t dev, struct pbuf* p) { - rt_uint32_t Index, IndexNext; - struct pbuf *q; - rt_uint8_t *ptr; - - /* calculate next index */ - IndexNext = LPC_EMAC->TxProduceIndex + 1; - if(IndexNext > LPC_EMAC->TxDescriptorNumber) IndexNext = 0; - - /* check whether block is full */ - while (IndexNext == LPC_EMAC->TxConsumeIndex) - { - rt_err_t result; - rt_uint32_t recved; - - /* there is no block yet, wait a flag */ - result = rt_event_recv(&tx_event, 0x01, - RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &recved); - - RT_ASSERT(result == RT_EOK); - } - - /* lock EMAC device */ - rt_sem_take(&sem_lock, RT_WAITING_FOREVER); - - /* get produce index */ - Index = LPC_EMAC->TxProduceIndex; - - /* calculate next index */ - IndexNext = LPC_EMAC->TxProduceIndex + 1; - if(IndexNext > LPC_EMAC->TxDescriptorNumber) - IndexNext = 0; - - /* copy data to tx buffer */ - q = p; - ptr = (rt_uint8_t*)TX_BUF(Index); - while (q) - { - memcpy(ptr, q->payload, q->len); - ptr += q->len; - q = q->next; - } - - TX_DESC_CTRL(Index) &= ~0x7ff; - TX_DESC_CTRL(Index) |= (p->tot_len - 1) & 0x7ff; - - /* change index to the next */ - LPC_EMAC->TxProduceIndex = IndexNext; - - /* unlock EMAC device */ - rt_sem_release(&sem_lock); - - return RT_EOK; + rt_uint32_t Index, IndexNext; + struct pbuf *q; + rt_uint8_t *ptr; + + /* calculate next index */ + IndexNext = LPC_EMAC->TxProduceIndex + 1; + if(IndexNext > LPC_EMAC->TxDescriptorNumber) IndexNext = 0; + + /* check whether block is full */ + while (IndexNext == LPC_EMAC->TxConsumeIndex) + { + rt_err_t result; + rt_uint32_t recved; + + /* there is no block yet, wait a flag */ + result = rt_event_recv(&tx_event, 0x01, + RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &recved); + + RT_ASSERT(result == RT_EOK); + } + + /* lock EMAC device */ + rt_sem_take(&sem_lock, RT_WAITING_FOREVER); + + /* get produce index */ + Index = LPC_EMAC->TxProduceIndex; + + /* calculate next index */ + IndexNext = LPC_EMAC->TxProduceIndex + 1; + if(IndexNext > LPC_EMAC->TxDescriptorNumber) + IndexNext = 0; + + /* copy data to tx buffer */ + q = p; + ptr = (rt_uint8_t*)TX_BUF(Index); + while (q) + { + memcpy(ptr, q->payload, q->len); + ptr += q->len; + q = q->next; + } + + TX_DESC_CTRL(Index) &= ~0x7ff; + TX_DESC_CTRL(Index) |= (p->tot_len - 1) & 0x7ff; + + /* change index to the next */ + LPC_EMAC->TxProduceIndex = IndexNext; + + /* unlock EMAC device */ + rt_sem_release(&sem_lock); + + return RT_EOK; } /* reception packet. */ struct pbuf *lpc17xx_emac_rx(rt_device_t dev) { - struct pbuf* p; - rt_uint32_t size; - rt_uint32_t Index; - - /* init p pointer */ - p = RT_NULL; - - /* lock EMAC device */ - rt_sem_take(&sem_lock, RT_WAITING_FOREVER); - - Index = LPC_EMAC->RxConsumeIndex; - if(Index != LPC_EMAC->RxProduceIndex) - { - size = (RX_STAT_INFO(Index) & 0x7ff)+1; - if (size > ETH_FRAG_SIZE) size = ETH_FRAG_SIZE; - - /* allocate buffer */ - p = pbuf_alloc(PBUF_LINK, size, PBUF_RAM); - if (p != RT_NULL) - { - struct pbuf* q; - rt_uint8_t *ptr; - - ptr = (rt_uint8_t*)RX_BUF(Index); - for (q = p; q != RT_NULL; q= q->next) - { - memcpy(q->payload, ptr, q->len); - ptr += q->len; - } - } - - /* move Index to the next */ - if(++Index > LPC_EMAC->RxDescriptorNumber) - Index = 0; - - /* set consume index */ - LPC_EMAC->RxConsumeIndex = Index; - } - else - { - /* Enable RxDone interrupt */ - LPC_EMAC->IntEnable = INT_RX_DONE | INT_TX_DONE; - } - - /* unlock EMAC device */ - rt_sem_release(&sem_lock); - - return p; + struct pbuf* p; + rt_uint32_t size; + rt_uint32_t Index; + + /* init p pointer */ + p = RT_NULL; + + /* lock EMAC device */ + rt_sem_take(&sem_lock, RT_WAITING_FOREVER); + + Index = LPC_EMAC->RxConsumeIndex; + if(Index != LPC_EMAC->RxProduceIndex) + { + size = (RX_STAT_INFO(Index) & 0x7ff)+1; + if (size > ETH_FRAG_SIZE) size = ETH_FRAG_SIZE; + + /* allocate buffer */ + p = pbuf_alloc(PBUF_LINK, size, PBUF_RAM); + if (p != RT_NULL) + { + struct pbuf* q; + rt_uint8_t *ptr; + + ptr = (rt_uint8_t*)RX_BUF(Index); + for (q = p; q != RT_NULL; q= q->next) + { + memcpy(q->payload, ptr, q->len); + ptr += q->len; + } + } + + /* move Index to the next */ + if(++Index > LPC_EMAC->RxDescriptorNumber) + Index = 0; + + /* set consume index */ + LPC_EMAC->RxConsumeIndex = Index; + } + else + { + /* Enable RxDone interrupt */ + LPC_EMAC->IntEnable = INT_RX_DONE | INT_TX_DONE; + } + + /* unlock EMAC device */ + rt_sem_release(&sem_lock); + + return p; } int lpc17xx_emac_hw_init(void) { - rt_event_init(&tx_event, "tx_event", RT_IPC_FLAG_FIFO); - rt_sem_init(&sem_lock, "eth_lock", 1, RT_IPC_FLAG_FIFO); - - /* set auto negotiation mode */ - lpc17xx_emac_device.phy_mode = EMAC_PHY_AUTO; - - // OUI 00-60-37 NXP Semiconductors - lpc17xx_emac_device.dev_addr[0] = 0x00; - lpc17xx_emac_device.dev_addr[1] = 0x60; - lpc17xx_emac_device.dev_addr[2] = 0x37; - /* set mac address: (only for test) */ - lpc17xx_emac_device.dev_addr[3] = 0x12; - lpc17xx_emac_device.dev_addr[4] = 0x34; - lpc17xx_emac_device.dev_addr[5] = 0x56; - - lpc17xx_emac_device.parent.parent.init = lpc17xx_emac_init; - lpc17xx_emac_device.parent.parent.open = lpc17xx_emac_open; - lpc17xx_emac_device.parent.parent.close = lpc17xx_emac_close; - lpc17xx_emac_device.parent.parent.read = lpc17xx_emac_read; - lpc17xx_emac_device.parent.parent.write = lpc17xx_emac_write; - lpc17xx_emac_device.parent.parent.control = lpc17xx_emac_control; - lpc17xx_emac_device.parent.parent.user_data = RT_NULL; - - lpc17xx_emac_device.parent.eth_rx = lpc17xx_emac_rx; - lpc17xx_emac_device.parent.eth_tx = lpc17xx_emac_tx; - - eth_device_init(&(lpc17xx_emac_device.parent), "e0"); - return 0; + rt_event_init(&tx_event, "tx_event", RT_IPC_FLAG_FIFO); + rt_sem_init(&sem_lock, "eth_lock", 1, RT_IPC_FLAG_FIFO); + + /* set auto negotiation mode */ + lpc17xx_emac_device.phy_mode = EMAC_PHY_AUTO; + + // OUI 00-60-37 NXP Semiconductors + lpc17xx_emac_device.dev_addr[0] = 0x00; + lpc17xx_emac_device.dev_addr[1] = 0x60; + lpc17xx_emac_device.dev_addr[2] = 0x37; + /* set mac address: (only for test) */ + lpc17xx_emac_device.dev_addr[3] = 0x12; + lpc17xx_emac_device.dev_addr[4] = 0x34; + lpc17xx_emac_device.dev_addr[5] = 0x56; + + lpc17xx_emac_device.parent.parent.init = lpc17xx_emac_init; + lpc17xx_emac_device.parent.parent.open = lpc17xx_emac_open; + lpc17xx_emac_device.parent.parent.close = lpc17xx_emac_close; + lpc17xx_emac_device.parent.parent.read = lpc17xx_emac_read; + lpc17xx_emac_device.parent.parent.write = lpc17xx_emac_write; + lpc17xx_emac_device.parent.parent.control = lpc17xx_emac_control; + lpc17xx_emac_device.parent.parent.user_data = RT_NULL; + + lpc17xx_emac_device.parent.eth_rx = lpc17xx_emac_rx; + lpc17xx_emac_device.parent.eth_tx = lpc17xx_emac_tx; + + eth_device_init(&(lpc17xx_emac_device.parent), "e0"); + return 0; } INIT_DEVICE_EXPORT(lpc17xx_emac_hw_init); diff --git a/bsp/lpc176x/drivers/emac.h b/bsp/lpc176x/drivers/emac.h index d0edd25d63..1fc8973249 100644 --- a/bsp/lpc176x/drivers/emac.h +++ b/bsp/lpc176x/drivers/emac.h @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #ifndef __LPC17XX_EMAC_H #define __LPC17XX_EMAC_H @@ -11,7 +20,7 @@ #define ETH_MAX_FLEN 1536 /* Max. Ethernet Frame Size */ /* EMAC variables located in 16K Ethernet SRAM */ -#define RX_DESC_BASE 0x20080000 +#define RX_DESC_BASE 0x20080000 #define RX_STAT_BASE (RX_DESC_BASE + NUM_RX_FRAG*8) #define TX_DESC_BASE (RX_STAT_BASE + NUM_RX_FRAG*8) #define TX_STAT_BASE (TX_DESC_BASE + NUM_TX_FRAG*8) diff --git a/bsp/lpc176x/drivers/led.h b/bsp/lpc176x/drivers/led.h index 658ed16d1c..92f6ff4ffd 100644 --- a/bsp/lpc176x/drivers/led.h +++ b/bsp/lpc176x/drivers/led.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc176x/drivers/sd.c b/bsp/lpc176x/drivers/sd.c index 61e34ba43a..53b57676de 100644 --- a/bsp/lpc176x/drivers/sd.c +++ b/bsp/lpc176x/drivers/sd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -467,12 +467,12 @@ static rt_err_t rt_sdcard_control(rt_device_t dev, int cmd, void *args) if (cmd == RT_DEVICE_CTRL_BLK_GETGEOME) { struct rt_device_blk_geometry *geometry; - + geometry = (struct rt_device_blk_geometry *)args; - + if (geometry == RT_NULL) return -RT_ERROR; if (dev->user_data == RT_NULL) return -RT_ERROR; - + geometry->bytes_per_sector = ((SDCFG *)dev->user_data)->sectorsize; geometry->block_size = ((SDCFG *)dev->user_data)->blocksize; geometry->sector_count = ((SDCFG *)dev->user_data)->sectorcnt; diff --git a/bsp/lpc176x/drivers/spi.c b/bsp/lpc176x/drivers/spi.c index a6561195c5..ef328bc793 100644 --- a/bsp/lpc176x/drivers/spi.c +++ b/bsp/lpc176x/drivers/spi.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #include "LPC17xx.h" /* LPC17xx definitions */ #include "spi.h" @@ -21,98 +30,98 @@ static uint8_t LPC17xx_SPI_SendRecvByte (uint8_t byte_s); /* Initialize the SSP0, SSP0_PCLK=CCLK=72MHz */ void LPC17xx_SPI_Init (void) { - uint32_t dummy; + uint32_t dummy; - dummy = dummy; // avoid warning + dummy = dummy; // avoid warning #if 0 - /* Initialize and enable the SSP0 Interface module. */ - LPC_SC->PCONP |= (1 << 21); /* Enable power to SSPI0 block */ - - /* SSEL is GPIO, output set to high. */ - LPC_GPIO0->FIODIR |= (1<<16); /* P0.16 is output */ - LPC_PINCON->PINSEL1 &= ~(3<<0); /* P0.16 SSEL (used as GPIO) */ - LPC17xx_SPI_DeSelect (); /* set P0.16 high (SSEL inactiv) */ - - /* SCK, MISO, MOSI are SSP pins. */ - LPC_PINCON->PINSEL0 &= ~(3UL<<30); /* P0.15 cleared */ - LPC_PINCON->PINSEL0 |= (2UL<<30); /* P0.15 SCK0 */ - LPC_PINCON->PINSEL1 &= ~((3<<2) | (3<<4)); /* P0.17, P0.18 cleared */ - LPC_PINCON->PINSEL1 |= ((2<<2) | (2<<4)); /* P0.17 MISO0, P0.18 MOSI0 */ + /* Initialize and enable the SSP0 Interface module. */ + LPC_SC->PCONP |= (1 << 21); /* Enable power to SSPI0 block */ + + /* SSEL is GPIO, output set to high. */ + LPC_GPIO0->FIODIR |= (1<<16); /* P0.16 is output */ + LPC_PINCON->PINSEL1 &= ~(3<<0); /* P0.16 SSEL (used as GPIO) */ + LPC17xx_SPI_DeSelect (); /* set P0.16 high (SSEL inactiv) */ + + /* SCK, MISO, MOSI are SSP pins. */ + LPC_PINCON->PINSEL0 &= ~(3UL<<30); /* P0.15 cleared */ + LPC_PINCON->PINSEL0 |= (2UL<<30); /* P0.15 SCK0 */ + LPC_PINCON->PINSEL1 &= ~((3<<2) | (3<<4)); /* P0.17, P0.18 cleared */ + LPC_PINCON->PINSEL1 |= ((2<<2) | (2<<4)); /* P0.17 MISO0, P0.18 MOSI0 */ #else - LPC_SC->PCONP |= (1 << 21); /* Enable power to SSPI0 block */ - - /* SSEL is GPIO, output set to high. */ - LPC_GPIO1->FIODIR |= (1<<21); /* P1.21 is output */ - LPC_GPIO1->FIOPIN |= (1<<21); /* set P1.21 high (SSEL inact.)*/ - LPC_PINCON->PINSEL3 &= ~(0<<10); /* P1.21 SSEL (used as GPIO) */ - - /* P3.26 is SD Card Power Supply Enable Pin */ - LPC_GPIO3->FIODIR |= (1<<26); /* P3.26 is output */ - LPC_GPIO3->FIOPIN &= ~(1<<26); /* set P3.26 low(enable power) */ - - /* SCK, MISO, MOSI are SSP pins. */ - LPC_PINCON->PINSEL3 &= ~(3UL<<8); /* P1.20 cleared */ - LPC_PINCON->PINSEL3 |= (3UL<<8); /* P1.20 SCK0 */ - LPC_PINCON->PINSEL3 &= ~((3<<14) | (3<<16)); /* P1.23, P1.24 cleared */ - LPC_PINCON->PINSEL3 |= ((3<<14) | (3<<16)); /* P1.23 MISO0, P1.24 MOSI0 */ + LPC_SC->PCONP |= (1 << 21); /* Enable power to SSPI0 block */ + + /* SSEL is GPIO, output set to high. */ + LPC_GPIO1->FIODIR |= (1<<21); /* P1.21 is output */ + LPC_GPIO1->FIOPIN |= (1<<21); /* set P1.21 high (SSEL inact.)*/ + LPC_PINCON->PINSEL3 &= ~(0<<10); /* P1.21 SSEL (used as GPIO) */ + + /* P3.26 is SD Card Power Supply Enable Pin */ + LPC_GPIO3->FIODIR |= (1<<26); /* P3.26 is output */ + LPC_GPIO3->FIOPIN &= ~(1<<26); /* set P3.26 low(enable power) */ + + /* SCK, MISO, MOSI are SSP pins. */ + LPC_PINCON->PINSEL3 &= ~(3UL<<8); /* P1.20 cleared */ + LPC_PINCON->PINSEL3 |= (3UL<<8); /* P1.20 SCK0 */ + LPC_PINCON->PINSEL3 &= ~((3<<14) | (3<<16)); /* P1.23, P1.24 cleared */ + LPC_PINCON->PINSEL3 |= ((3<<14) | (3<<16)); /* P1.23 MISO0, P1.24 MOSI0 */ #endif - /* PCLK_SSP0=CCLK */ - LPC_SC->PCLKSEL1 &= ~(3<<10); /* PCLKSP0 = CCLK/4 (18MHz) */ - LPC_SC->PCLKSEL1 |= (1<<10); /* PCLKSP0 = CCLK (72MHz) */ + /* PCLK_SSP0=CCLK */ + LPC_SC->PCLKSEL1 &= ~(3<<10); /* PCLKSP0 = CCLK/4 (18MHz) */ + LPC_SC->PCLKSEL1 |= (1<<10); /* PCLKSP0 = CCLK (72MHz) */ - LPC_SSP0->CR0 = 0x0007; /* 8Bit, CPOL=0, CPHA=0 */ - LPC_SSP0->CR1 = 0x0002; /* SSP0 enable, master */ + LPC_SSP0->CR0 = 0x0007; /* 8Bit, CPOL=0, CPHA=0 */ + LPC_SSP0->CR1 = 0x0002; /* SSP0 enable, master */ - LPC17xx_SPI_SetSpeed (SPI_SPEED_400kHz); + LPC17xx_SPI_SetSpeed (SPI_SPEED_400kHz); - /* wait for busy gone */ - while( LPC_SSP0->SR & ( 1 << SSPSR_BSY ) ); + /* wait for busy gone */ + while( LPC_SSP0->SR & ( 1 << SSPSR_BSY ) ); - /* drain SPI RX FIFO */ - while( LPC_SSP0->SR & ( 1 << SSPSR_RNE ) ) - { - dummy = LPC_SSP0->DR; - } + /* drain SPI RX FIFO */ + while( LPC_SSP0->SR & ( 1 << SSPSR_RNE ) ) + { + dummy = LPC_SSP0->DR; + } } /* Close SSP0 */ void LPC17xx_SPI_DeInit( void ) { - // disable SPI - LPC_SSP0->CR1 = 0; + // disable SPI + LPC_SSP0->CR1 = 0; #if 0 - // Pins to GPIO - LPC_PINCON->PINSEL0 &= ~(3UL<<30); - LPC_PINCON->PINSEL1 &= ~((3<<2) | (3<<4)); + // Pins to GPIO + LPC_PINCON->PINSEL0 &= ~(3UL<<30); + LPC_PINCON->PINSEL1 &= ~((3<<2) | (3<<4)); #else - LPC_PINCON->PINSEL3 &= ~(3UL<<8); /* P1.20 cleared */ - LPC_PINCON->PINSEL3 &= ~((3<<14) | (3<<16)); /* P1.23, P1.24 cleared */ + LPC_PINCON->PINSEL3 &= ~(3UL<<8); /* P1.20 cleared */ + LPC_PINCON->PINSEL3 &= ~((3<<14) | (3<<16)); /* P1.23, P1.24 cleared */ #endif - // disable SSP power - LPC_SC->PCONP &= ~(1 << 21); + // disable SSP power + LPC_SC->PCONP &= ~(1 << 21); } /* Set a SSP0 clock speed to desired value. */ void LPC17xx_SPI_SetSpeed (uint8_t speed) { - speed &= 0xFE; - if ( speed < 2 ) { - speed = 2 ; - } - LPC_SSP0->CPSR = speed; + speed &= 0xFE; + if ( speed < 2 ) { + speed = 2 ; + } + LPC_SSP0->CPSR = speed; } /* SSEL: low */ void LPC17xx_SPI_Select () { #if 0 - LPC_GPIO0->FIOPIN &= ~(1<<16); + LPC_GPIO0->FIOPIN &= ~(1<<16); #else - LPC_GPIO1->FIOPIN &= ~(1<<21); /* SSEL is GPIO, set to high. */ + LPC_GPIO1->FIOPIN &= ~(1<<21); /* SSEL is GPIO, set to high. */ #endif } @@ -120,41 +129,41 @@ void LPC17xx_SPI_Select () void LPC17xx_SPI_DeSelect () { #if 0 - LPC_GPIO0->FIOPIN |= (1<<16); + LPC_GPIO0->FIOPIN |= (1<<16); #else - LPC_GPIO1->FIOPIN |= (1<<21); /* SSEL is GPIO, set to high. */ + LPC_GPIO1->FIOPIN |= (1<<21); /* SSEL is GPIO, set to high. */ #endif } /* Send one byte then recv one byte of response. */ static uint8_t LPC17xx_SPI_SendRecvByte (uint8_t byte_s) { - uint8_t byte_r; + uint8_t byte_r; - LPC_SSP0->DR = byte_s; - while (LPC_SSP0->SR & (1 << SSPSR_BSY) /*BSY*/); /* Wait for transfer to finish */ - byte_r = LPC_SSP0->DR; + LPC_SSP0->DR = byte_s; + while (LPC_SSP0->SR & (1 << SSPSR_BSY) /*BSY*/); /* Wait for transfer to finish */ + byte_r = LPC_SSP0->DR; - return byte_r; /* Return received value */ + return byte_r; /* Return received value */ } /* Send one byte */ void LPC17xx_SPI_SendByte (uint8_t data) { - LPC17xx_SPI_SendRecvByte (data); + LPC17xx_SPI_SendRecvByte (data); } /* Recv one byte */ uint8_t LPC17xx_SPI_RecvByte () { - return LPC17xx_SPI_SendRecvByte (0xFF); + return LPC17xx_SPI_SendRecvByte (0xFF); } /* Release SSP0 */ void LPC17xx_SPI_Release (void) { - LPC17xx_SPI_DeSelect (); - LPC17xx_SPI_RecvByte (); + LPC17xx_SPI_DeSelect (); + LPC17xx_SPI_RecvByte (); } @@ -163,66 +172,66 @@ void LPC17xx_SPI_Release (void) #define FIFO_ELEM 8 /* Receive btr (must be multiple of 4) bytes of data and store in buff. */ -void LPC17xx_SPI_RecvBlock_FIFO (uint8_t *buff, uint32_t btr) +void LPC17xx_SPI_RecvBlock_FIFO (uint8_t *buff, uint32_t btr) { - uint32_t hwtr, startcnt, i, rec; - - hwtr = btr/2; /* byte number in unit of short */ - if ( btr < FIFO_ELEM ) { - startcnt = hwtr; - } else { - startcnt = FIFO_ELEM; - } - - LPC_SSP0 -> CR0 |= 0x0f; /* DSS to 16 bit */ - - for ( i = startcnt; i; i-- ) { - LPC_SSP0 -> DR = 0xffff; /* fill TX FIFO, prepare clk for receive */ - } - - do { - while ( !(LPC_SSP0->SR & ( 1 << SSPSR_RNE ) ) ) { - // wait for data in RX FIFO (RNE set) - } - rec = LPC_SSP0->DR; - if ( i < ( hwtr - startcnt ) ) { - LPC_SSP0->DR = 0xffff; /* fill TX FIFO, prepare clk for receive */ - } - *buff++ = (uint8_t)(rec>>8); - *buff++ = (uint8_t)(rec); - i++; - } while ( i < hwtr ); - - LPC_SSP0->CR0 &= ~0x08; /* DSS to 8 bit */ + uint32_t hwtr, startcnt, i, rec; + + hwtr = btr/2; /* byte number in unit of short */ + if ( btr < FIFO_ELEM ) { + startcnt = hwtr; + } else { + startcnt = FIFO_ELEM; + } + + LPC_SSP0 -> CR0 |= 0x0f; /* DSS to 16 bit */ + + for ( i = startcnt; i; i-- ) { + LPC_SSP0 -> DR = 0xffff; /* fill TX FIFO, prepare clk for receive */ + } + + do { + while ( !(LPC_SSP0->SR & ( 1 << SSPSR_RNE ) ) ) { + // wait for data in RX FIFO (RNE set) + } + rec = LPC_SSP0->DR; + if ( i < ( hwtr - startcnt ) ) { + LPC_SSP0->DR = 0xffff; /* fill TX FIFO, prepare clk for receive */ + } + *buff++ = (uint8_t)(rec>>8); + *buff++ = (uint8_t)(rec); + i++; + } while ( i < hwtr ); + + LPC_SSP0->CR0 &= ~0x08; /* DSS to 8 bit */ } /* Send 512 bytes of data block (stored in buff). */ void LPC17xx_SPI_SendBlock_FIFO (const uint8_t *buff) { - uint32_t cnt; - uint16_t data; + uint32_t cnt; + uint16_t data; - LPC_SSP0->CR0 |= 0x0f; /* DSS to 16 bit */ + LPC_SSP0->CR0 |= 0x0f; /* DSS to 16 bit */ - /* fill the FIFO unless it is full */ - for ( cnt = 0; cnt < ( 512 / 2 ); cnt++ ) - { - /* wait for TX FIFO not full (TNF) */ - while ( !( LPC_SSP0->SR & ( 1 << SSPSR_TNF ) ) ); + /* fill the FIFO unless it is full */ + for ( cnt = 0; cnt < ( 512 / 2 ); cnt++ ) + { + /* wait for TX FIFO not full (TNF) */ + while ( !( LPC_SSP0->SR & ( 1 << SSPSR_TNF ) ) ); - data = (*buff++) << 8; - data |= *buff++; - LPC_SSP0->DR = data; - } + data = (*buff++) << 8; + data |= *buff++; + LPC_SSP0->DR = data; + } - /* wait for BSY gone */ - while ( LPC_SSP0->SR & ( 1 << SSPSR_BSY ) ); + /* wait for BSY gone */ + while ( LPC_SSP0->SR & ( 1 << SSPSR_BSY ) ); - /* drain receive FIFO */ - while ( LPC_SSP0->SR & ( 1 << SSPSR_RNE ) ) { - data = LPC_SSP0->DR; - } + /* drain receive FIFO */ + while ( LPC_SSP0->SR & ( 1 << SSPSR_RNE ) ) { + data = LPC_SSP0->DR; + } - LPC_SSP0->CR0 &= ~0x08; /* DSS to 8 bit */ + LPC_SSP0->CR0 &= ~0x08; /* DSS to 8 bit */ } #endif /* USE_FIFO */ diff --git a/bsp/lpc176x/drivers/spi.h b/bsp/lpc176x/drivers/spi.h index d1d9c14732..bad75d38b4 100644 --- a/bsp/lpc176x/drivers/spi.h +++ b/bsp/lpc176x/drivers/spi.h @@ -1,17 +1,26 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #ifndef __LPC17XX_SPI_H__ #define __LPC17XX_SPI_H__ #include #include -// if not use FIFO, R: 600kB/s, W: 500kB/s -// if use FIFO, R: 1.2MB/s, W: 800kB/s +// if not use FIFO, R: 600kB/s, W: 500kB/s +// if use FIFO, R: 1.2MB/s, W: 800kB/s #define USE_FIFO 1 -/* bit-frequency = PCLK / (CPSDVSR * [SCR+1]), here SCR=0, PCLK=72MHz, must be even */ -#define SPI_SPEED_20MHz 4 /* => 18MHz */ -#define SPI_SPEED_25MHz 4 /* => 18MHz */ -#define SPI_SPEED_400kHz 180 /* => 400kHz */ +/* bit-frequency = PCLK / (CPSDVSR * [SCR+1]), here SCR=0, PCLK=72MHz, must be even */ +#define SPI_SPEED_20MHz 4 /* => 18MHz */ +#define SPI_SPEED_25MHz 4 /* => 18MHz */ +#define SPI_SPEED_400kHz 180 /* => 400kHz */ /* external functions */ void LPC17xx_SPI_Init (void); @@ -24,8 +33,8 @@ void LPC17xx_SPI_SendByte (uint8_t data); uint8_t LPC17xx_SPI_RecvByte (void); #if USE_FIFO -void LPC17xx_SPI_RecvBlock_FIFO (uint8_t *buff, uint32_t btr); +void LPC17xx_SPI_RecvBlock_FIFO (uint8_t *buff, uint32_t btr); void LPC17xx_SPI_SendBlock_FIFO (const uint8_t *buff); #endif -#endif // __LPC17XX_SPI_H__ +#endif // __LPC17XX_SPI_H__ diff --git a/bsp/lpc176x/drivers/uart.c b/bsp/lpc176x/drivers/uart.c index 231eccb10a..a32952124b 100644 --- a/bsp/lpc176x/drivers/uart.c +++ b/bsp/lpc176x/drivers/uart.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -56,8 +56,8 @@ void UART0_IRQHandler(void) { rt_ubase_t level, iir; struct rt_uart_lpc *uart = &uart_device; - /* enter interrupt */ - rt_interrupt_enter(); + /* enter interrupt */ + rt_interrupt_enter(); /* read IIR and clear it */ iir = LPC_UART->IIR; @@ -91,8 +91,8 @@ void UART0_IRQHandler(void) { iir = LPC_UART->LSR; //oe pe fe oe read for clear interrupt } - /* leave interrupt */ - rt_interrupt_leave(); + /* leave interrupt */ + rt_interrupt_leave(); return; } diff --git a/bsp/lpc176x/rtconfig.h b/bsp/lpc176x/rtconfig.h index 6b28d64d32..5096b2f71d 100644 --- a/bsp/lpc176x/rtconfig.h +++ b/bsp/lpc176x/rtconfig.h @@ -4,17 +4,17 @@ // // -#define RT_NAME_MAX 6 +#define RT_NAME_MAX 6 // -#define RT_ALIGN_SIZE 4 +#define RT_ALIGN_SIZE 4 // // 8 // 32 // 256 // -#define RT_THREAD_PRIORITY_MAX 32 +#define RT_THREAD_PRIORITY_MAX 32 // -#define RT_TICK_PER_SECOND 100 +#define RT_TICK_PER_SECOND 100 //
#define RT_DEBUG #define RT_DEBUG_COLOR @@ -29,11 +29,11 @@ //
// #define RT_USING_TIMER_SOFT // -#define RT_TIMER_THREAD_PRIO 4 +#define RT_TIMER_THREAD_PRIO 4 // -#define RT_TIMER_THREAD_STACK_SIZE 512 +#define RT_TIMER_THREAD_STACK_SIZE 512 // -#define RT_TIMER_TICK_PER_SECOND 10 +#define RT_TIMER_TICK_PER_SECOND 10 //
//
@@ -67,15 +67,15 @@ // #define RT_USING_UART0 // -#define RT_UART_RX_BUFFER_SIZE 64 +#define RT_UART_RX_BUFFER_SIZE 64 //
//
#define RT_USING_CONSOLE // -#define RT_CONSOLEBUF_SIZE 128 +#define RT_CONSOLEBUF_SIZE 128 // -#define RT_CONSOLE_DEVICE_NAME "uart0" +#define RT_CONSOLE_DEVICE_NAME "uart0" //
// @@ -87,7 +87,7 @@ // #define FINSH_USING_DESCRIPTION // -#define FINSH_THREAD_STACK_SIZE 4096 +#define FINSH_THREAD_STACK_SIZE 4096 //
//
@@ -102,16 +102,16 @@ // #define DFS_USING_WORKDIR // -#define DFS_FILESYSTEMS_MAX 2 +#define DFS_FILESYSTEMS_MAX 2 // -#define DFS_FD_MAX 4 +#define DFS_FD_MAX 4 // #define RT_USING_DFS_ELMFAT // // 1 // 2 // -#define RT_DFS_ELM_USE_LFN 1 +#define RT_DFS_ELM_USE_LFN 1 // // 932 // 936 @@ -142,7 +142,7 @@ // #define RT_DFS_ELM_CODE_PAGE 437 // -#define RT_DFS_ELM_MAX_LFN 64 +#define RT_DFS_ELM_MAX_LFN 64 // // #define RT_USING_DFS_YAFFS2 // @@ -152,7 +152,7 @@ // // #define RT_USING_DFS_NFS // -#define RT_NFS_HOST_EXPORT "192.168.1.5:/" +#define RT_NFS_HOST_EXPORT "192.168.1.5:/" //
//
@@ -168,29 +168,29 @@ // #define RT_LWIP_DNS // -#define RT_LWIP_PBUF_NUM 4 +#define RT_LWIP_PBUF_NUM 4 // -#define RT_LWIP_TCP_PCB_NUM 3 +#define RT_LWIP_TCP_PCB_NUM 3 // -#define RT_LWIP_TCP_SND_BUF (2 * TCP_MSS) +#define RT_LWIP_TCP_SND_BUF (2 * TCP_MSS) // -#define RT_LWIP_TCP_WND 2048 +#define RT_LWIP_TCP_WND 2048 // // #define RT_LWIP_SNMP // // #define RT_LWIP_DHCP // -#define RT_LWIP_TCPTHREAD_PRIORITY 12 +#define RT_LWIP_TCPTHREAD_PRIORITY 12 // -#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8 +#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8 // -#define RT_LWIP_TCPTHREAD_STACKSIZE 4096 +#define RT_LWIP_TCPTHREAD_STACKSIZE 4096 // -#define RT_LWIP_ETHTHREAD_PRIORITY 14 +#define RT_LWIP_ETHTHREAD_PRIORITY 14 // -#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8 +#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8 // -#define RT_LWIP_ETHTHREAD_STACKSIZE 512 +#define RT_LWIP_ETHTHREAD_STACKSIZE 512 // #define RT_LWIP_IPADDR "192.168.1.30" // diff --git a/bsp/lpc178x/applications/application.c b/bsp/lpc178x/applications/application.c index 9780d42154..b4f437405b 100644 --- a/bsp/lpc178x/applications/application.c +++ b/bsp/lpc178x/applications/application.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -75,33 +75,33 @@ void rt_init_thread_entry(void *parameter) #ifdef RT_USING_RTGUI { - extern void rtgui_system_server_init(void); - extern void application_init(void); + extern void rtgui_system_server_init(void); + extern void application_init(void); - rt_device_t lcd; + rt_device_t lcd; - /* init lcd */ - rt_hw_lcd_init(); + /* init lcd */ + rt_hw_lcd_init(); - /* find lcd device */ - lcd = rt_device_find("lcd"); - if (lcd != RT_NULL) - { - /* set lcd device as rtgui graphic driver */ - rtgui_graphic_set_device(lcd); + /* find lcd device */ + lcd = rt_device_find("lcd"); + if (lcd != RT_NULL) + { + /* set lcd device as rtgui graphic driver */ + rtgui_graphic_set_device(lcd); - /* init rtgui system server */ - rtgui_system_server_init(); + /* init rtgui system server */ + rtgui_system_server_init(); - /* startup rtgui in demo of RT-Thread/GUI examples */ - application_init(); - } + /* startup rtgui in demo of RT-Thread/GUI examples */ + application_init(); + } } #endif #ifdef RT_USING_FINSH - /* initialize finsh */ - finsh_system_init(); + /* initialize finsh */ + finsh_system_init(); #endif } @@ -143,22 +143,22 @@ static void rt_thread_entry_led(void* parameter) int rt_application_init(void) { - rt_thread_t tid; - - rt_thread_init(&thread_led, - "led", - rt_thread_entry_led, - RT_NULL, - &thread_led_stack[0], - sizeof(thread_led_stack),11,5); - rt_thread_startup(&thread_led); - - tid = rt_thread_create("init", - rt_init_thread_entry, RT_NULL, - 2048, RT_THREAD_PRIORITY_MAX/3, 20); - if (tid != RT_NULL) rt_thread_startup(tid); - - return 0; + rt_thread_t tid; + + rt_thread_init(&thread_led, + "led", + rt_thread_entry_led, + RT_NULL, + &thread_led_stack[0], + sizeof(thread_led_stack),11,5); + rt_thread_startup(&thread_led); + + tid = rt_thread_create("init", + rt_init_thread_entry, RT_NULL, + 2048, RT_THREAD_PRIORITY_MAX/3, 20); + if (tid != RT_NULL) rt_thread_startup(tid); + + return 0; } #if defined(RT_USING_RTGUI) && defined(RT_USING_FINSH) @@ -170,20 +170,20 @@ int rt_application_init(void) void key(rt_uint32_t key) { - struct rtgui_event_kbd ekbd; + struct rtgui_event_kbd ekbd; - RTGUI_EVENT_KBD_INIT(&ekbd); - ekbd.mod = RTGUI_KMOD_NONE; - ekbd.unicode = 0; - ekbd.key = key; + RTGUI_EVENT_KBD_INIT(&ekbd); + ekbd.mod = RTGUI_KMOD_NONE; + ekbd.unicode = 0; + ekbd.key = key; - ekbd.type = RTGUI_KEYDOWN; - rtgui_server_post_event((struct rtgui_event*)&ekbd, sizeof(ekbd)); + ekbd.type = RTGUI_KEYDOWN; + rtgui_server_post_event((struct rtgui_event*)&ekbd, sizeof(ekbd)); - rt_thread_delay(2); + rt_thread_delay(2); - ekbd.type = RTGUI_KEYUP; - rtgui_server_post_event((struct rtgui_event*)&ekbd, sizeof(ekbd)); + ekbd.type = RTGUI_KEYUP; + rtgui_server_post_event((struct rtgui_event*)&ekbd, sizeof(ekbd)); } FINSH_FUNCTION_EXPORT(key, send a key to gui server); #endif diff --git a/bsp/lpc178x/applications/startup.c b/bsp/lpc178x/applications/startup.c index 07698574b5..8b25e7d405 100644 --- a/bsp/lpc178x/applications/startup.c +++ b/bsp/lpc178x/applications/startup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -37,11 +37,11 @@ extern int __bss_end; *******************************************************************************/ void assert_failed(u8* file, u32 line) { - rt_kprintf("\n\r Wrong parameter value detected on\r\n"); - rt_kprintf(" file %s\r\n", file); - rt_kprintf(" line %d\r\n", line); + rt_kprintf("\n\r Wrong parameter value detected on\r\n"); + rt_kprintf(" file %s\r\n", file); + rt_kprintf(" line %d\r\n", line); - while (1) ; + while (1) ; } #endif @@ -50,28 +50,28 @@ void assert_failed(u8* file, u32 line) */ void rtthread_startup(void) { - /* initialize board */ - rt_hw_board_init(); + /* initialize board */ + rt_hw_board_init(); - /* show version */ - rt_show_version(); + /* show version */ + rt_show_version(); #ifdef RT_USING_HEAP - /* initialize memory system */ - #ifdef __CC_ARM - rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)(0x10000000 + 1024*64)); - #elif __ICCARM__ - rt_system_heap_init(__segment_end("HEAP"), (void*)(0x10000000 + 1024*64)); - #else - rt_system_heap_init((void*)&__bss_end, (void*)(0x10000000 + 1024*64)); - #endif + /* initialize memory system */ + #ifdef __CC_ARM + rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)(0x10000000 + 1024*64)); + #elif __ICCARM__ + rt_system_heap_init(__segment_end("HEAP"), (void*)(0x10000000 + 1024*64)); + #else + rt_system_heap_init((void*)&__bss_end, (void*)(0x10000000 + 1024*64)); + #endif #endif - /* initialize scheduler system */ - rt_system_scheduler_init(); + /* initialize scheduler system */ + rt_system_scheduler_init(); - /* initialize application */ - rt_application_init(); + /* initialize application */ + rt_application_init(); /* initialize timer */ rt_system_timer_init(); @@ -79,23 +79,23 @@ void rtthread_startup(void) /* initialize timer thread */ rt_system_timer_thread_init(); - /* initialize idle thread */ - rt_thread_idle_init(); + /* initialize idle thread */ + rt_thread_idle_init(); - /* start scheduler */ - rt_system_scheduler_start(); + /* start scheduler */ + rt_system_scheduler_start(); - /* never reach here */ - return ; + /* never reach here */ + return ; } int main(void) { - /* disable interrupt first */ - rt_hw_interrupt_disable(); + /* disable interrupt first */ + rt_hw_interrupt_disable(); - /* startup RT-Thread RTOS */ - rtthread_startup(); + /* startup RT-Thread RTOS */ + rtthread_startup(); - return 0; + return 0; } diff --git a/bsp/lpc178x/drivers/board.c b/bsp/lpc178x/drivers/board.c index df06d7f2f8..c07150e525 100644 --- a/bsp/lpc178x/drivers/board.c +++ b/bsp/lpc178x/drivers/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc178x/drivers/board.h b/bsp/lpc178x/drivers/board.h index 1a6d82e4b7..3c0a7fad71 100644 --- a/bsp/lpc178x/drivers/board.h +++ b/bsp/lpc178x/drivers/board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -31,7 +31,7 @@ //#define RT_USING_UART2 // -#define RT_CONSOLE_DEVICE_NAME "uart0" +#define RT_CONSOLE_DEVICE_NAME "uart0" // diff --git a/bsp/lpc178x/drivers/drv_glcd.c b/bsp/lpc178x/drivers/drv_glcd.c index ba02efeb67..6fa9c7b84e 100644 --- a/bsp/lpc178x/drivers/drv_glcd.c +++ b/bsp/lpc178x/drivers/drv_glcd.c @@ -37,14 +37,14 @@ #define C_GLCD_LINES_PER_FRAME (C_GLCD_V_SIZE + C_GLCD_V_PULSE + C_GLCD_V_FRONT_PORCH + C_GLCD_V_BACK_PORCH) #define C_GLCD_PIX_CLK (C_GLCD_CLK_PER_LINE * C_GLCD_LINES_PER_FRAME) -//LPC_LCD_TypeDef * const g_pLCD = ((LPC_LCD_TypeDef*) LPC_LCD_BASE); +//LPC_LCD_TypeDef * const g_pLCD = ((LPC_LCD_TypeDef*) LPC_LCD_BASE); //LPC_SC_TypeDef * const g_pSC = ((LPC_SC_TypeDef*) LPC_SC_BASE); -#define SDRAM_BASE 0xA0000000 /* CS0 */ -#define SDRAM_BASE_ADDR SDRAM_BASE +#define SDRAM_BASE 0xA0000000 /* CS0 */ +#define SDRAM_BASE_ADDR SDRAM_BASE -#define LCD_VRAM_BASE_ADDR ((unsigned long)SDRAM_BASE_ADDR + 0x00000000) -#define LCD_CURSOR_BASE_ADDR ((unsigned long)0x20088800) +#define LCD_VRAM_BASE_ADDR ((unsigned long)SDRAM_BASE_ADDR + 0x00000000) +#define LCD_CURSOR_BASE_ADDR ((unsigned long)0x20088800) static pFontType_t pCurrFont = NULL; @@ -155,18 +155,18 @@ void GLCD_Move_Cursor(int x, int y) *************************************************************************/ void GLCD_Copy_Cursor (const unsigned long *pCursor, int cursor, int size) { - unsigned long i ; - unsigned long * pDst = (unsigned long *)LCD_CURSOR_BASE_ADDR; - - pDst += cursor*64; - - for(i = 0; i < size ; i++) -// *pDst++ = *pCursor++; - { - *pDst = *pCursor; - pDst++; - pCursor++; - } + unsigned long i ; + unsigned long * pDst = (unsigned long *)LCD_CURSOR_BASE_ADDR; + + pDst += cursor*64; + + for(i = 0; i < size ; i++) +// *pDst++ = *pCursor++; + { + *pDst = *pCursor; + pDst++; + pCursor++; + } } /************************************************************************* * Function Name: GLCD_Init @@ -179,101 +179,101 @@ void GLCD_Copy_Cursor (const unsigned long *pCursor, int cursor, int size) *************************************************************************/ void GLCD_Init (void* VRAMBase) { - // unsigned long i; - // Assign pins - LPC_IOCON->P2_9 = 0x06; // VD3, R0 - LPC_IOCON->P2_6 = 0x07; // VD4, R1 - LPC_IOCON->P2_7 = 0x07; // VD5, R2 - LPC_IOCON->P4_28 = 0x05; // VD6, R3 - LPC_IOCON->P4_29 = 0x05; // VD7, R4 - - LPC_IOCON->P1_20 = 0x07; // VD10, G0 - LPC_IOCON->P1_21 = 0x07; // VD11, G1 - LPC_IOCON->P1_22 = 0x07; // VD12, G2 - LPC_IOCON->P1_23 = 0x07; // VD13, G3 - LPC_IOCON->P1_24 = 0x07; // VD14, G4 - LPC_IOCON->P1_25 = 0x07; // VD15, G5 - - LPC_IOCON->P2_13 = 0x07; // VD19, B0 - LPC_IOCON->P1_26 = 0x07; // VD20, B1 - LPC_IOCON->P1_27 = 0x07; // VD21, B2 - LPC_IOCON->P1_28 = 0x07; // VD22, B3 - LPC_IOCON->P1_29 = 0x07; // VD23, B4 - - LPC_IOCON->P2_2 = 0x07; // DCLK - LPC_IOCON->P2_0 = 0x07; // DSIP(power) - LPC_IOCON->P2_5 = 0x07; // HSYNC - LPC_IOCON->P2_3 = 0x07; // VSYNC - LPC_IOCON->P2_4 = 0x07; // DataEn - -// LPC_IOCON->P5_4 = 0x00; // Backlight - - // >>> debug >>> - - // <<< debug <<< - - /*Back light enable*/ -// LPC_GPIO5->DIR = (1<<4); -// LPC_GPIO5->SET= (5<<4); - - //Turn on LCD clock - CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCLCD, ENABLE); - - // Disable cursor - LPC_LCD->CRSR_CTRL &=~(1<<0); - - // disable GLCD controller - LPC_LCD->CTRL = 0; - // RGB888 - LPC_LCD->CTRL &= ~(0x07 <<1); - LPC_LCD->CTRL |= (6<<1); - - // TFT panel - LPC_LCD->CTRL |= (1<<5); - // single panel - LPC_LCD->CTRL &= ~(1<<7); - // notmal output - LPC_LCD->CTRL &= ~(1<<8); - // little endian byte order - LPC_LCD->CTRL &= ~(1<<9); - // little endian pix order - LPC_LCD->CTRL &= ~(1<<10); - // disable power - LPC_LCD->CTRL &= ~(1<<11); - // init pixel clock -// g_pSC->LCD_CFG = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER) / ((unsigned long)C_GLCD_PIX_CLK); - LPC_SC->LCD_CFG = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER) / ((unsigned long)C_GLCD_PIX_CLK); - // bypass inrenal clk divider - LPC_LCD->POL |=(1<<26); - // clock source for the LCD block is HCLK - LPC_LCD->POL &= ~(1<<5); - // LCDFP pin is active LOW and inactive HIGH - LPC_LCD->POL |= (1<<11); - // LCDLP pin is active LOW and inactive HIGH - LPC_LCD->POL |= (1<<12); - // data is driven out into the LCD on the falling edge - LPC_LCD->POL &= ~(1<<13); - // active high - LPC_LCD->POL &= ~(1<<14); - LPC_LCD->POL &= ~(0x3FF <<16); - LPC_LCD->POL |= (C_GLCD_H_SIZE-1)<<16; - - // init Horizontal Timing - LPC_LCD->TIMH = 0; //reset TIMH before set value - LPC_LCD->TIMH |= (C_GLCD_H_BACK_PORCH - 1)<<24; - LPC_LCD->TIMH |= (C_GLCD_H_FRONT_PORCH - 1)<<16; - LPC_LCD->TIMH |= (C_GLCD_H_PULSE - 1)<<8; - LPC_LCD->TIMH |= ((C_GLCD_H_SIZE/16) - 1)<<2; - - // init Vertical Timing - LPC_LCD->TIMV = 0; //reset TIMV value before setting - LPC_LCD->TIMV |= (C_GLCD_V_BACK_PORCH)<<24; - LPC_LCD->TIMV |= (C_GLCD_V_FRONT_PORCH)<<16; - LPC_LCD->TIMV |= (C_GLCD_V_PULSE - 1)<<10; - LPC_LCD->TIMV |= C_GLCD_V_SIZE - 1; - // Frame Base Address doubleword aligned - LPC_LCD->UPBASE = (unsigned long)VRAMBase & ~7UL ; - LPC_LCD->LPBASE = (unsigned long)VRAMBase & ~7UL ; + // unsigned long i; + // Assign pins + LPC_IOCON->P2_9 = 0x06; // VD3, R0 + LPC_IOCON->P2_6 = 0x07; // VD4, R1 + LPC_IOCON->P2_7 = 0x07; // VD5, R2 + LPC_IOCON->P4_28 = 0x05; // VD6, R3 + LPC_IOCON->P4_29 = 0x05; // VD7, R4 + + LPC_IOCON->P1_20 = 0x07; // VD10, G0 + LPC_IOCON->P1_21 = 0x07; // VD11, G1 + LPC_IOCON->P1_22 = 0x07; // VD12, G2 + LPC_IOCON->P1_23 = 0x07; // VD13, G3 + LPC_IOCON->P1_24 = 0x07; // VD14, G4 + LPC_IOCON->P1_25 = 0x07; // VD15, G5 + + LPC_IOCON->P2_13 = 0x07; // VD19, B0 + LPC_IOCON->P1_26 = 0x07; // VD20, B1 + LPC_IOCON->P1_27 = 0x07; // VD21, B2 + LPC_IOCON->P1_28 = 0x07; // VD22, B3 + LPC_IOCON->P1_29 = 0x07; // VD23, B4 + + LPC_IOCON->P2_2 = 0x07; // DCLK + LPC_IOCON->P2_0 = 0x07; // DSIP(power) + LPC_IOCON->P2_5 = 0x07; // HSYNC + LPC_IOCON->P2_3 = 0x07; // VSYNC + LPC_IOCON->P2_4 = 0x07; // DataEn + +// LPC_IOCON->P5_4 = 0x00; // Backlight + + // >>> debug >>> + + // <<< debug <<< + + /*Back light enable*/ +// LPC_GPIO5->DIR = (1<<4); +// LPC_GPIO5->SET= (5<<4); + + //Turn on LCD clock + CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCLCD, ENABLE); + + // Disable cursor + LPC_LCD->CRSR_CTRL &=~(1<<0); + + // disable GLCD controller + LPC_LCD->CTRL = 0; + // RGB888 + LPC_LCD->CTRL &= ~(0x07 <<1); + LPC_LCD->CTRL |= (6<<1); + + // TFT panel + LPC_LCD->CTRL |= (1<<5); + // single panel + LPC_LCD->CTRL &= ~(1<<7); + // notmal output + LPC_LCD->CTRL &= ~(1<<8); + // little endian byte order + LPC_LCD->CTRL &= ~(1<<9); + // little endian pix order + LPC_LCD->CTRL &= ~(1<<10); + // disable power + LPC_LCD->CTRL &= ~(1<<11); + // init pixel clock +// g_pSC->LCD_CFG = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER) / ((unsigned long)C_GLCD_PIX_CLK); + LPC_SC->LCD_CFG = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER) / ((unsigned long)C_GLCD_PIX_CLK); + // bypass inrenal clk divider + LPC_LCD->POL |=(1<<26); + // clock source for the LCD block is HCLK + LPC_LCD->POL &= ~(1<<5); + // LCDFP pin is active LOW and inactive HIGH + LPC_LCD->POL |= (1<<11); + // LCDLP pin is active LOW and inactive HIGH + LPC_LCD->POL |= (1<<12); + // data is driven out into the LCD on the falling edge + LPC_LCD->POL &= ~(1<<13); + // active high + LPC_LCD->POL &= ~(1<<14); + LPC_LCD->POL &= ~(0x3FF <<16); + LPC_LCD->POL |= (C_GLCD_H_SIZE-1)<<16; + + // init Horizontal Timing + LPC_LCD->TIMH = 0; //reset TIMH before set value + LPC_LCD->TIMH |= (C_GLCD_H_BACK_PORCH - 1)<<24; + LPC_LCD->TIMH |= (C_GLCD_H_FRONT_PORCH - 1)<<16; + LPC_LCD->TIMH |= (C_GLCD_H_PULSE - 1)<<8; + LPC_LCD->TIMH |= ((C_GLCD_H_SIZE/16) - 1)<<2; + + // init Vertical Timing + LPC_LCD->TIMV = 0; //reset TIMV value before setting + LPC_LCD->TIMV |= (C_GLCD_V_BACK_PORCH)<<24; + LPC_LCD->TIMV |= (C_GLCD_V_FRONT_PORCH)<<16; + LPC_LCD->TIMV |= (C_GLCD_V_PULSE - 1)<<10; + LPC_LCD->TIMV |= C_GLCD_V_SIZE - 1; + // Frame Base Address doubleword aligned + LPC_LCD->UPBASE = (unsigned long)VRAMBase & ~7UL ; + LPC_LCD->LPBASE = (unsigned long)VRAMBase & ~7UL ; } /************************************************************************* @@ -287,13 +287,13 @@ void GLCD_Init (void* VRAMBase) *************************************************************************/ void GLCD_SetPallet (const unsigned long * pPallete) { - unsigned long i; - unsigned long * pDst = (unsigned long *)LPC_LCD->PAL; - // //assert(pPallete); - for (i = 0; i < 128; i++) - { - *pDst++ = *pPallete++; - } + unsigned long i; + unsigned long * pDst = (unsigned long *)LPC_LCD->PAL; + // //assert(pPallete); + for (i = 0; i < 128; i++) + { + *pDst++ = *pPallete++; + } } /************************************************************************* @@ -307,7 +307,7 @@ void GLCD_SetPallet (const unsigned long * pPallete) *************************************************************************/ void GLCD_Ctrl (Bool bEna) { - volatile unsigned long i; + volatile unsigned long i; if (bEna) { // LCD_CTRL_bit.LcdEn = 1; @@ -473,7 +473,7 @@ Bool GLCD_TextCalcWindow (unsigned long * pXL, unsigned long * pXR, *pXR = XL_Win + ((TextX_Pos+1)*pCurrFont->H_Size) - 1; if(*pXR > XR_Win) { - *pH_Size -= *pXR - XR_Win; + *pH_Size -= *pXR - XR_Win; *pXR = XR_Win; } @@ -514,19 +514,19 @@ unsigned long i, j, k; ++TextY_Pos; break; case '\r': // go to begin of this line (Carriage Return) - // clear from current position to end of line - while(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size)) - { + // clear from current position to end of line + while(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size)) + { LCD_SET_WINDOW(xl,xr,yu,yd); - for(i = 0; i < V_Size; ++i) - { - for(j = 0; j < H_Size; ++j) - { - LCD_WRITE_PIXEL(TextBackgndColour); - } - } - ++TextX_Pos; - } + for(i = 0; i < V_Size; ++i) + { + for(j = 0; j < H_Size; ++j) + { + LCD_WRITE_PIXEL(TextBackgndColour); + } + } + ++TextX_Pos; + } TextX_Pos = 0; break; case '\b': // go back one position (BackSpace) @@ -534,45 +534,45 @@ unsigned long i, j, k; { --TextX_Pos; // del current position - if(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size)) - { + if(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size)) + { LCD_SET_WINDOW(xl,xr,yu,yd); - for(i = 0; i < V_Size; ++i) - { - for(j = 0; j < H_Size; ++j) - { - LCD_WRITE_PIXEL(TextBackgndColour); - } - } - } + for(i = 0; i < V_Size; ++i) + { + for(j = 0; j < H_Size; ++j) + { + LCD_WRITE_PIXEL(TextBackgndColour); + } + } + } } break; case '\t': // go to next Horizontal Tab stop - WhiteSpaceNumb = TabSize - (TextX_Pos%TabSize); - for(k = 0; k < WhiteSpaceNumb; ++k) - { + WhiteSpaceNumb = TabSize - (TextX_Pos%TabSize); + for(k = 0; k < WhiteSpaceNumb; ++k) + { LCD_SET_WINDOW(xl,xr,yu,yd); - if(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size)) - { - for(i = 0; i < V_Size; ++i) - { - for(j = 0; j < H_Size; ++j) - { - LCD_WRITE_PIXEL(TextBackgndColour); - } - } - ++TextX_Pos; - } - else - { - break; - } - } + if(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size)) + { + for(i = 0; i < V_Size; ++i) + { + for(j = 0; j < H_Size; ++j) + { + LCD_WRITE_PIXEL(TextBackgndColour); + } + } + ++TextX_Pos; + } + else + { + break; + } + } break; case '\f': // go to top of page (Form Feed) - // clear entire window - H_Size = XR_Win - XL_Win; - V_Size = YD_Win - YU_Win; + // clear entire window + H_Size = XR_Win - XL_Win; + V_Size = YD_Win - YU_Win; // set character window X left, Y right LCD_SET_WINDOW(XL_Win,XR_Win,YU_Win,YD_Win); // Fill window with background font color @@ -584,7 +584,7 @@ unsigned long i, j, k; } } - TextX_Pos = TextY_Pos = 0; + TextX_Pos = TextY_Pos = 0; break; case '\a': // signal an alert (BELl) TEXT_BEL1_FUNC(); @@ -593,37 +593,37 @@ unsigned long i, j, k; // Calculate the current character base address from stream // and the character position if((c < pCurrFont->CharacterOffset) && - (c >= pCurrFont->CharactersNuber)) - { - c = 0; + (c >= pCurrFont->CharactersNuber)) + { + c = 0; } else { - c -= pCurrFont->CharacterOffset; + c -= pCurrFont->CharacterOffset; } pSrc = pCurrFont->pFontStream + (H_Line * pCurrFont->V_Size * c); // Calculate character window and fit it in the text window if(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size)) { - // set character window X left, Y right - LCD_SET_WINDOW(xl,xr,yu,yd); - // Send char data - for(i = 0; i < V_Size; ++i) - { + // set character window X left, Y right + LCD_SET_WINDOW(xl,xr,yu,yd); + // Send char data + for(i = 0; i < V_Size; ++i) + { SrcInc = H_Line; for(j = 0; j < H_Size; ++j) - { - Temp = (*pSrc & (1UL << (j&0x7)))?TextColour:TextBackgndColour; - LCD_WRITE_PIXEL(Temp); - if((j&0x7) == 7) - { - ++pSrc; + { + Temp = (*pSrc & (1UL << (j&0x7)))?TextColour:TextBackgndColour; + LCD_WRITE_PIXEL(Temp); + if((j&0x7) == 7) + { + ++pSrc; --SrcInc; - } - } + } + } // next line of character - pSrc += SrcInc; - } + pSrc += SrcInc; + } } ++TextX_Pos; } diff --git a/bsp/lpc178x/drivers/drv_glcd.h b/bsp/lpc178x/drivers/drv_glcd.h index 1453bd4782..5a28ceb6b3 100644 --- a/bsp/lpc178x/drivers/drv_glcd.h +++ b/bsp/lpc178x/drivers/drv_glcd.h @@ -33,7 +33,7 @@ typedef unsigned long Boolean; /** * @brief A struct for Bitmap on LCD screen */ -typedef struct _Bmp_t +typedef struct _Bmp_t { U32 H_Size; U32 V_Size; @@ -47,8 +47,8 @@ typedef struct _Bmp_t /** * @brief A struct for Font Type on LCD screen */ - -typedef struct _FontType_t + +typedef struct _FontType_t { U32 H_Size; U32 V_Size; @@ -62,9 +62,9 @@ typedef U32 LdcPixel_t, *pLdcPixel_t; #define C_GLCD_REFRESH_FREQ (60HZ) #define C_GLCD_H_SIZE 480 -#define C_GLCD_H_PULSE 2 // -#define C_GLCD_H_FRONT_PORCH 5 // -#define C_GLCD_H_BACK_PORCH 40 // +#define C_GLCD_H_PULSE 2 // +#define C_GLCD_H_FRONT_PORCH 5 // +#define C_GLCD_H_BACK_PORCH 40 // #define C_GLCD_V_SIZE 272 #define C_GLCD_V_PULSE 2 #define C_GLCD_V_FRONT_PORCH 8 diff --git a/bsp/lpc178x/drivers/emac.c b/bsp/lpc178x/drivers/emac.c index a16dc49770..ec48ea8833 100644 --- a/bsp/lpc178x/drivers/emac.c +++ b/bsp/lpc178x/drivers/emac.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -14,20 +14,20 @@ #include "lwipopts.h" #include -#define EMAC_PHY_AUTO 0 -#define EMAC_PHY_10MBIT 1 -#define EMAC_PHY_100MBIT 2 +#define EMAC_PHY_AUTO 0 +#define EMAC_PHY_10MBIT 1 +#define EMAC_PHY_100MBIT 2 #define MAX_ADDR_LEN 6 struct lpc17xx_emac { - /* inherit from ethernet device */ - struct eth_device parent; + /* inherit from ethernet device */ + struct eth_device parent; - rt_uint8_t phy_mode; + rt_uint8_t phy_mode; - /* interface address info. */ - rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* hw address */ + /* interface address info. */ + rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* hw address */ }; static struct lpc17xx_emac lpc17xx_emac_device; static struct rt_semaphore sem_lock; @@ -39,39 +39,39 @@ static rt_uint16_t read_PHY (rt_uint8_t PhyReg) ; void ENET_IRQHandler(void) { - rt_uint32_t status; + rt_uint32_t status; /* enter interrupt */ rt_interrupt_enter(); - status = LPC_EMAC->IntStatus; + status = LPC_EMAC->IntStatus; - if (status & INT_RX_DONE) - { - /* Disable EMAC RxDone interrupts. */ - LPC_EMAC->IntEnable = INT_TX_DONE; + if (status & INT_RX_DONE) + { + /* Disable EMAC RxDone interrupts. */ + LPC_EMAC->IntEnable = INT_TX_DONE; - /* a frame has been received */ - eth_device_ready(&(lpc17xx_emac_device.parent)); - } - else if (status & INT_TX_DONE) - { - /* set event */ - rt_event_send(&tx_event, 0x01); - } + /* a frame has been received */ + eth_device_ready(&(lpc17xx_emac_device.parent)); + } + else if (status & INT_TX_DONE) + { + /* set event */ + rt_event_send(&tx_event, 0x01); + } - if (status & INT_RX_OVERRUN) - { - rt_kprintf("rx overrun\n"); - } + if (status & INT_RX_OVERRUN) + { + rt_kprintf("rx overrun\n"); + } - if (status & INT_TX_UNDERRUN) - { - rt_kprintf("tx underrun\n"); - } + if (status & INT_TX_UNDERRUN) + { + rt_kprintf("tx underrun\n"); + } - /* Clear the interrupt. */ - LPC_EMAC->IntClear = status; + /* Clear the interrupt. */ + LPC_EMAC->IntClear = status; /* leave interrupt */ rt_interrupt_leave(); @@ -80,84 +80,84 @@ void ENET_IRQHandler(void) /* phy write */ static void write_PHY (rt_uint32_t PhyReg, rt_uint32_t Value) { - unsigned int tout; - - LPC_EMAC->MADR = DP83848C_DEF_ADR | PhyReg; - LPC_EMAC->MWTD = Value; - - /* Wait utill operation completed */ - tout = 0; - for (tout = 0; tout < MII_WR_TOUT; tout++) - { - if ((LPC_EMAC->MIND & MIND_BUSY) == 0) - { - break; - } - } + unsigned int tout; + + LPC_EMAC->MADR = DP83848C_DEF_ADR | PhyReg; + LPC_EMAC->MWTD = Value; + + /* Wait utill operation completed */ + tout = 0; + for (tout = 0; tout < MII_WR_TOUT; tout++) + { + if ((LPC_EMAC->MIND & MIND_BUSY) == 0) + { + break; + } + } } /* phy read */ static rt_uint16_t read_PHY (rt_uint8_t PhyReg) { - rt_uint32_t tout; - - LPC_EMAC->MADR = DP83848C_DEF_ADR | PhyReg; - LPC_EMAC->MCMD = MCMD_READ; - - /* Wait until operation completed */ - tout = 0; - for (tout = 0; tout < MII_RD_TOUT; tout++) - { - if ((LPC_EMAC->MIND & MIND_BUSY) == 0) - { - break; - } - } - LPC_EMAC->MCMD = 0; - return (LPC_EMAC->MRDD); + rt_uint32_t tout; + + LPC_EMAC->MADR = DP83848C_DEF_ADR | PhyReg; + LPC_EMAC->MCMD = MCMD_READ; + + /* Wait until operation completed */ + tout = 0; + for (tout = 0; tout < MII_RD_TOUT; tout++) + { + if ((LPC_EMAC->MIND & MIND_BUSY) == 0) + { + break; + } + } + LPC_EMAC->MCMD = 0; + return (LPC_EMAC->MRDD); } /* init rx descriptor */ rt_inline void rx_descr_init (void) { - rt_uint32_t i; - - for (i = 0; i < NUM_RX_FRAG; i++) - { - RX_DESC_PACKET(i) = RX_BUF(i); - RX_DESC_CTRL(i) = RCTRL_INT | (ETH_FRAG_SIZE-1); - RX_STAT_INFO(i) = 0; - RX_STAT_HASHCRC(i) = 0; - } - - /* Set EMAC Receive Descriptor Registers. */ - LPC_EMAC->RxDescriptor = RX_DESC_BASE; - LPC_EMAC->RxStatus = RX_STAT_BASE; - LPC_EMAC->RxDescriptorNumber = NUM_RX_FRAG-1; - - /* Rx Descriptors Point to 0 */ - LPC_EMAC->RxConsumeIndex = 0; + rt_uint32_t i; + + for (i = 0; i < NUM_RX_FRAG; i++) + { + RX_DESC_PACKET(i) = RX_BUF(i); + RX_DESC_CTRL(i) = RCTRL_INT | (ETH_FRAG_SIZE-1); + RX_STAT_INFO(i) = 0; + RX_STAT_HASHCRC(i) = 0; + } + + /* Set EMAC Receive Descriptor Registers. */ + LPC_EMAC->RxDescriptor = RX_DESC_BASE; + LPC_EMAC->RxStatus = RX_STAT_BASE; + LPC_EMAC->RxDescriptorNumber = NUM_RX_FRAG-1; + + /* Rx Descriptors Point to 0 */ + LPC_EMAC->RxConsumeIndex = 0; } /* init tx descriptor */ rt_inline void tx_descr_init (void) { - rt_uint32_t i; - - for (i = 0; i < NUM_TX_FRAG; i++) - { - TX_DESC_PACKET(i) = TX_BUF(i); - TX_DESC_CTRL(i) = (1ul<<31) | (1ul<<30) | (1ul<<29) | (1ul<<28) | (1ul<<26) | (ETH_FRAG_SIZE-1); - TX_STAT_INFO(i) = 0; - } - - /* Set EMAC Transmit Descriptor Registers. */ - LPC_EMAC->TxDescriptor = TX_DESC_BASE; - LPC_EMAC->TxStatus = TX_STAT_BASE; - LPC_EMAC->TxDescriptorNumber = NUM_TX_FRAG-1; - - /* Tx Descriptors Point to 0 */ - LPC_EMAC->TxProduceIndex = 0; + rt_uint32_t i; + + for (i = 0; i < NUM_TX_FRAG; i++) + { + TX_DESC_PACKET(i) = TX_BUF(i); + TX_DESC_CTRL(i) = (1ul<<31) | (1ul<<30) | (1ul<<29) | (1ul<<28) | (1ul<<26) | (ETH_FRAG_SIZE-1); + TX_STAT_INFO(i) = 0; + } + + /* Set EMAC Transmit Descriptor Registers. */ + LPC_EMAC->TxDescriptor = TX_DESC_BASE; + LPC_EMAC->TxStatus = TX_STAT_BASE; + LPC_EMAC->TxDescriptorNumber = NUM_TX_FRAG-1; + + /* Tx Descriptors Point to 0 */ + LPC_EMAC->TxProduceIndex = 0; } /* @@ -178,375 +178,375 @@ REF_CLK P1_15 */ static rt_err_t lpc17xx_emac_init(rt_device_t dev) { - /* Initialize the EMAC ethernet controller. */ - rt_uint32_t regv, tout; - - /* Power Up the EMAC controller. */ - LPC_SC->PCONP |= (1UL<<30); - - /* config RESET */ - PINSEL_ConfigPin(3, 19, 0); - PINSEL_SetPinMode(3, 19, IOCON_MODE_PLAIN); - LPC_GPIO3->DIR |= 1<<19; - LPC_GPIO3->CLR = 1<<19; - - /* Enable P1 Ethernet Pins. */ - PINSEL_ConfigPin(1, 0, 1); /**< P1_0 ENET_TXD0 */ - PINSEL_ConfigPin(1, 1, 1); /**< P1_1 ENET_TXD1 */ - PINSEL_ConfigPin(1, 4, 1); /**< P1_4 ENET_TX_EN */ - PINSEL_ConfigPin(1, 8, 1); /**< P1_8 ENET_CRS_DV */ - PINSEL_ConfigPin(1, 9, 1); /**< P1_9 ENET_RXD0 */ - PINSEL_ConfigPin(1, 10, 1); /**< P1_10 ENET_RXD1 */ - PINSEL_ConfigPin(1, 14, 1); /**< P1_14 ENET_RX_ER */ - PINSEL_ConfigPin(1, 15, 1); /**< P1_15 ENET_REF_CLK */ - PINSEL_ConfigPin(1, 16, 1); /**< P1_16 ENET_MDC */ - PINSEL_ConfigPin(1, 17, 1); /**< P1_17 ENET_MDIO */ - - LPC_GPIO3->SET = 1<<19; - - /* Reset all EMAC internal modules. */ - LPC_EMAC->MAC1 = MAC1_RES_TX | MAC1_RES_MCS_TX | MAC1_RES_RX | MAC1_RES_MCS_RX | - MAC1_SIM_RES | MAC1_SOFT_RES; - LPC_EMAC->Command = CR_REG_RES | CR_TX_RES | CR_RX_RES; - - /* A short delay after reset. */ - for (tout = 100; tout; tout--); - - /* Initialize MAC control registers. */ - LPC_EMAC->MAC1 = MAC1_PASS_ALL; - LPC_EMAC->MAC2 = MAC2_CRC_EN | MAC2_PAD_EN; - LPC_EMAC->MAXF = ETH_MAX_FLEN; - LPC_EMAC->CLRT = CLRT_DEF; - LPC_EMAC->IPGR = IPGR_DEF; - - /* PCLK=18MHz, clock select=6, MDC=18/6=3MHz */ - /* Enable Reduced MII interface. */ - LPC_EMAC->MCFG = MCFG_CLK_DIV20 | MCFG_RES_MII; - for (tout = 100; tout; tout--); - LPC_EMAC->MCFG = MCFG_CLK_DIV20; - - /* Enable Reduced MII interface. */ - LPC_EMAC->Command = CR_RMII | CR_PASS_RUNT_FRM | CR_PASS_RX_FILT; - - /* Reset Reduced MII Logic. */ - LPC_EMAC->SUPP = SUPP_RES_RMII | SUPP_SPEED; - for (tout = 100; tout; tout--); - LPC_EMAC->SUPP = SUPP_SPEED; - - /* Put the PHY in reset mode */ - write_PHY (PHY_REG_BMCR, 0x8000); - for (tout = 1000; tout; tout--); - -// /* Wait for hardware reset to end. */ -// for (tout = 0; tout < 0x100000; tout++) -// { -// regv = read_PHY (PHY_REG_BMCR); -// if (!(regv & 0x8000)) -// { -// /* Reset complete */ -// break; -// } -// } -// if (tout >= 0x100000) + /* Initialize the EMAC ethernet controller. */ + rt_uint32_t regv, tout; + + /* Power Up the EMAC controller. */ + LPC_SC->PCONP |= (1UL<<30); + + /* config RESET */ + PINSEL_ConfigPin(3, 19, 0); + PINSEL_SetPinMode(3, 19, IOCON_MODE_PLAIN); + LPC_GPIO3->DIR |= 1<<19; + LPC_GPIO3->CLR = 1<<19; + + /* Enable P1 Ethernet Pins. */ + PINSEL_ConfigPin(1, 0, 1); /**< P1_0 ENET_TXD0 */ + PINSEL_ConfigPin(1, 1, 1); /**< P1_1 ENET_TXD1 */ + PINSEL_ConfigPin(1, 4, 1); /**< P1_4 ENET_TX_EN */ + PINSEL_ConfigPin(1, 8, 1); /**< P1_8 ENET_CRS_DV */ + PINSEL_ConfigPin(1, 9, 1); /**< P1_9 ENET_RXD0 */ + PINSEL_ConfigPin(1, 10, 1); /**< P1_10 ENET_RXD1 */ + PINSEL_ConfigPin(1, 14, 1); /**< P1_14 ENET_RX_ER */ + PINSEL_ConfigPin(1, 15, 1); /**< P1_15 ENET_REF_CLK */ + PINSEL_ConfigPin(1, 16, 1); /**< P1_16 ENET_MDC */ + PINSEL_ConfigPin(1, 17, 1); /**< P1_17 ENET_MDIO */ + + LPC_GPIO3->SET = 1<<19; + + /* Reset all EMAC internal modules. */ + LPC_EMAC->MAC1 = MAC1_RES_TX | MAC1_RES_MCS_TX | MAC1_RES_RX | MAC1_RES_MCS_RX | + MAC1_SIM_RES | MAC1_SOFT_RES; + LPC_EMAC->Command = CR_REG_RES | CR_TX_RES | CR_RX_RES; + + /* A short delay after reset. */ + for (tout = 100; tout; tout--); + + /* Initialize MAC control registers. */ + LPC_EMAC->MAC1 = MAC1_PASS_ALL; + LPC_EMAC->MAC2 = MAC2_CRC_EN | MAC2_PAD_EN; + LPC_EMAC->MAXF = ETH_MAX_FLEN; + LPC_EMAC->CLRT = CLRT_DEF; + LPC_EMAC->IPGR = IPGR_DEF; + + /* PCLK=18MHz, clock select=6, MDC=18/6=3MHz */ + /* Enable Reduced MII interface. */ + LPC_EMAC->MCFG = MCFG_CLK_DIV20 | MCFG_RES_MII; + for (tout = 100; tout; tout--); + LPC_EMAC->MCFG = MCFG_CLK_DIV20; + + /* Enable Reduced MII interface. */ + LPC_EMAC->Command = CR_RMII | CR_PASS_RUNT_FRM | CR_PASS_RX_FILT; + + /* Reset Reduced MII Logic. */ + LPC_EMAC->SUPP = SUPP_RES_RMII | SUPP_SPEED; + for (tout = 100; tout; tout--); + LPC_EMAC->SUPP = SUPP_SPEED; + + /* Put the PHY in reset mode */ + write_PHY (PHY_REG_BMCR, 0x8000); + for (tout = 1000; tout; tout--); + +// /* Wait for hardware reset to end. */ +// for (tout = 0; tout < 0x100000; tout++) +// { +// regv = read_PHY (PHY_REG_BMCR); +// if (!(regv & 0x8000)) +// { +// /* Reset complete */ +// break; +// } +// } +// if (tout >= 0x100000) // { // rt_kprintf("reset failed\r\n"); // return -RT_ERROR; /* reset failed */ // } -// /* Check if this is a DP83848C PHY. */ -// id1 = read_PHY (PHY_REG_IDR1); -// id2 = read_PHY (PHY_REG_IDR2); +// /* Check if this is a DP83848C PHY. */ +// id1 = read_PHY (PHY_REG_IDR1); +// id2 = read_PHY (PHY_REG_IDR2); // -// if (((id1 << 16) | (id2 & 0xFFF0)) != DP83848C_ID) -// return -RT_ERROR; - - /* Configure the PHY device */ - /* Configure the PHY device */ - switch (lpc17xx_emac_device.phy_mode) - { - case EMAC_PHY_AUTO: - /* Use autonegotiation about the link speed. */ - write_PHY (PHY_REG_BMCR, PHY_AUTO_NEG); - /* Wait to complete Auto_Negotiation. */ -// for (tout = 0; tout < 0x100000; tout++) -// { -// regv = read_PHY (PHY_REG_BMSR); -// if (regv & 0x0020) -// { -// /* Autonegotiation Complete. */ -// break; -// } -// } - break; - case EMAC_PHY_10MBIT: - /* Connect at 10MBit */ - write_PHY (PHY_REG_BMCR, PHY_FULLD_10M); - break; - case EMAC_PHY_100MBIT: - /* Connect at 100MBit */ - write_PHY (PHY_REG_BMCR, PHY_FULLD_100M); - break; - } - if (tout >= 0x100000) return -RT_ERROR; // auto_neg failed - -// /* Check the link status. */ -// for (tout = 0; tout < 0x10000; tout++) -// { -// regv = read_PHY (PHY_REG_STS); -// if (regv & 0x0001) -// { -// /* Link is on. */ -// break; -// } -// } -// if (tout >= 0x10000) return -RT_ERROR; - - regv = 0x0004; - /* Configure Full/Half Duplex mode. */ - if (regv & 0x0004) - { - /* Full duplex is enabled. */ - LPC_EMAC->MAC2 |= MAC2_FULL_DUP; - LPC_EMAC->Command |= CR_FULL_DUP; - LPC_EMAC->IPGT = IPGT_FULL_DUP; - } - else - { - /* Half duplex mode. */ - LPC_EMAC->IPGT = IPGT_HALF_DUP; - } - - /* Configure 100MBit/10MBit mode. */ - if (regv & 0x0002) - { - /* 10MBit mode. */ - LPC_EMAC->SUPP = 0; - } - else - { - /* 100MBit mode. */ - LPC_EMAC->SUPP = SUPP_SPEED; - } - - /* Set the Ethernet MAC Address registers */ - LPC_EMAC->SA0 = (lpc17xx_emac_device.dev_addr[1]<<8) | lpc17xx_emac_device.dev_addr[0]; - LPC_EMAC->SA1 = (lpc17xx_emac_device.dev_addr[3]<<8) | lpc17xx_emac_device.dev_addr[2]; - LPC_EMAC->SA2 = (lpc17xx_emac_device.dev_addr[5]<<8) | lpc17xx_emac_device.dev_addr[4]; - - /* Initialize Tx and Rx DMA Descriptors */ - rx_descr_init (); - tx_descr_init (); - - /* Receive Broadcast and Perfect Match Packets */ - LPC_EMAC->RxFilterCtrl = RFC_BCAST_EN | RFC_PERFECT_EN; - - /* Reset all interrupts */ - LPC_EMAC->IntClear = 0xFFFF; - - /* Enable EMAC interrupts. */ - LPC_EMAC->IntEnable = INT_RX_DONE | INT_TX_DONE; - - /* Enable receive and transmit mode of MAC Ethernet core */ - LPC_EMAC->Command |= (CR_RX_EN | CR_TX_EN); - LPC_EMAC->MAC1 |= MAC1_REC_EN; - - /* Enable the ENET Interrupt */ - NVIC_EnableIRQ(ENET_IRQn); - - return RT_EOK; +// if (((id1 << 16) | (id2 & 0xFFF0)) != DP83848C_ID) +// return -RT_ERROR; + + /* Configure the PHY device */ + /* Configure the PHY device */ + switch (lpc17xx_emac_device.phy_mode) + { + case EMAC_PHY_AUTO: + /* Use autonegotiation about the link speed. */ + write_PHY (PHY_REG_BMCR, PHY_AUTO_NEG); + /* Wait to complete Auto_Negotiation. */ +// for (tout = 0; tout < 0x100000; tout++) +// { +// regv = read_PHY (PHY_REG_BMSR); +// if (regv & 0x0020) +// { +// /* Autonegotiation Complete. */ +// break; +// } +// } + break; + case EMAC_PHY_10MBIT: + /* Connect at 10MBit */ + write_PHY (PHY_REG_BMCR, PHY_FULLD_10M); + break; + case EMAC_PHY_100MBIT: + /* Connect at 100MBit */ + write_PHY (PHY_REG_BMCR, PHY_FULLD_100M); + break; + } + if (tout >= 0x100000) return -RT_ERROR; // auto_neg failed + +// /* Check the link status. */ +// for (tout = 0; tout < 0x10000; tout++) +// { +// regv = read_PHY (PHY_REG_STS); +// if (regv & 0x0001) +// { +// /* Link is on. */ +// break; +// } +// } +// if (tout >= 0x10000) return -RT_ERROR; + + regv = 0x0004; + /* Configure Full/Half Duplex mode. */ + if (regv & 0x0004) + { + /* Full duplex is enabled. */ + LPC_EMAC->MAC2 |= MAC2_FULL_DUP; + LPC_EMAC->Command |= CR_FULL_DUP; + LPC_EMAC->IPGT = IPGT_FULL_DUP; + } + else + { + /* Half duplex mode. */ + LPC_EMAC->IPGT = IPGT_HALF_DUP; + } + + /* Configure 100MBit/10MBit mode. */ + if (regv & 0x0002) + { + /* 10MBit mode. */ + LPC_EMAC->SUPP = 0; + } + else + { + /* 100MBit mode. */ + LPC_EMAC->SUPP = SUPP_SPEED; + } + + /* Set the Ethernet MAC Address registers */ + LPC_EMAC->SA0 = (lpc17xx_emac_device.dev_addr[1]<<8) | lpc17xx_emac_device.dev_addr[0]; + LPC_EMAC->SA1 = (lpc17xx_emac_device.dev_addr[3]<<8) | lpc17xx_emac_device.dev_addr[2]; + LPC_EMAC->SA2 = (lpc17xx_emac_device.dev_addr[5]<<8) | lpc17xx_emac_device.dev_addr[4]; + + /* Initialize Tx and Rx DMA Descriptors */ + rx_descr_init (); + tx_descr_init (); + + /* Receive Broadcast and Perfect Match Packets */ + LPC_EMAC->RxFilterCtrl = RFC_BCAST_EN | RFC_PERFECT_EN; + + /* Reset all interrupts */ + LPC_EMAC->IntClear = 0xFFFF; + + /* Enable EMAC interrupts. */ + LPC_EMAC->IntEnable = INT_RX_DONE | INT_TX_DONE; + + /* Enable receive and transmit mode of MAC Ethernet core */ + LPC_EMAC->Command |= (CR_RX_EN | CR_TX_EN); + LPC_EMAC->MAC1 |= MAC1_REC_EN; + + /* Enable the ENET Interrupt */ + NVIC_EnableIRQ(ENET_IRQn); + + return RT_EOK; } static rt_err_t lpc17xx_emac_open(rt_device_t dev, rt_uint16_t oflag) { - return RT_EOK; + return RT_EOK; } static rt_err_t lpc17xx_emac_close(rt_device_t dev) { - return RT_EOK; + return RT_EOK; } static rt_size_t lpc17xx_emac_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) { - rt_set_errno(-RT_ENOSYS); - return 0; + rt_set_errno(-RT_ENOSYS); + return 0; } static rt_size_t lpc17xx_emac_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) { - rt_set_errno(-RT_ENOSYS); - return 0; + rt_set_errno(-RT_ENOSYS); + return 0; } static rt_err_t lpc17xx_emac_control(rt_device_t dev, int cmd, void *args) { - switch (cmd) - { - case NIOCTL_GADDR: - /* get mac address */ - if (args) rt_memcpy(args, lpc17xx_emac_device.dev_addr, 6); - else return -RT_ERROR; - break; - - default : - break; - } - - return RT_EOK; + switch (cmd) + { + case NIOCTL_GADDR: + /* get mac address */ + if (args) rt_memcpy(args, lpc17xx_emac_device.dev_addr, 6); + else return -RT_ERROR; + break; + + default : + break; + } + + return RT_EOK; } /* EtherNet Device Interface */ /* transmit packet. */ rt_err_t lpc17xx_emac_tx( rt_device_t dev, struct pbuf* p) { - rt_uint32_t Index, IndexNext; - struct pbuf *q; - rt_uint8_t *ptr; - - /* calculate next index */ - IndexNext = LPC_EMAC->TxProduceIndex + 1; - if(IndexNext > LPC_EMAC->TxDescriptorNumber) IndexNext = 0; - - /* check whether block is full */ - while (IndexNext == LPC_EMAC->TxConsumeIndex) - { - rt_err_t result; - rt_uint32_t recved; - - /* there is no block yet, wait a flag */ - result = rt_event_recv(&tx_event, 0x01, - RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &recved); - - RT_ASSERT(result == RT_EOK); - } - - /* lock EMAC device */ - rt_sem_take(&sem_lock, RT_WAITING_FOREVER); - - /* get produce index */ - Index = LPC_EMAC->TxProduceIndex; - - /* calculate next index */ - IndexNext = LPC_EMAC->TxProduceIndex + 1; - if(IndexNext > LPC_EMAC->TxDescriptorNumber) - IndexNext = 0; - - /* copy data to tx buffer */ - q = p; - ptr = (rt_uint8_t*)TX_BUF(Index); - while (q) - { - memcpy(ptr, q->payload, q->len); - ptr += q->len; - q = q->next; - } - - TX_DESC_CTRL(Index) &= ~0x7ff; - TX_DESC_CTRL(Index) |= (p->tot_len - 1) & 0x7ff; - - /* change index to the next */ - LPC_EMAC->TxProduceIndex = IndexNext; - - /* unlock EMAC device */ - rt_sem_release(&sem_lock); - - return RT_EOK; + rt_uint32_t Index, IndexNext; + struct pbuf *q; + rt_uint8_t *ptr; + + /* calculate next index */ + IndexNext = LPC_EMAC->TxProduceIndex + 1; + if(IndexNext > LPC_EMAC->TxDescriptorNumber) IndexNext = 0; + + /* check whether block is full */ + while (IndexNext == LPC_EMAC->TxConsumeIndex) + { + rt_err_t result; + rt_uint32_t recved; + + /* there is no block yet, wait a flag */ + result = rt_event_recv(&tx_event, 0x01, + RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &recved); + + RT_ASSERT(result == RT_EOK); + } + + /* lock EMAC device */ + rt_sem_take(&sem_lock, RT_WAITING_FOREVER); + + /* get produce index */ + Index = LPC_EMAC->TxProduceIndex; + + /* calculate next index */ + IndexNext = LPC_EMAC->TxProduceIndex + 1; + if(IndexNext > LPC_EMAC->TxDescriptorNumber) + IndexNext = 0; + + /* copy data to tx buffer */ + q = p; + ptr = (rt_uint8_t*)TX_BUF(Index); + while (q) + { + memcpy(ptr, q->payload, q->len); + ptr += q->len; + q = q->next; + } + + TX_DESC_CTRL(Index) &= ~0x7ff; + TX_DESC_CTRL(Index) |= (p->tot_len - 1) & 0x7ff; + + /* change index to the next */ + LPC_EMAC->TxProduceIndex = IndexNext; + + /* unlock EMAC device */ + rt_sem_release(&sem_lock); + + return RT_EOK; } /* reception packet. */ struct pbuf *lpc17xx_emac_rx(rt_device_t dev) { - struct pbuf* p; - rt_uint32_t size; - rt_uint32_t Index; - - /* init p pointer */ - p = RT_NULL; - - /* lock EMAC device */ - rt_sem_take(&sem_lock, RT_WAITING_FOREVER); - - Index = LPC_EMAC->RxConsumeIndex; - if(Index != LPC_EMAC->RxProduceIndex) - { - size = (RX_STAT_INFO(Index) & 0x7ff)+1; - if (size > ETH_FRAG_SIZE) size = ETH_FRAG_SIZE; - - /* allocate buffer */ - p = pbuf_alloc(PBUF_LINK, size, PBUF_RAM); - if (p != RT_NULL) - { - struct pbuf* q; - rt_uint8_t *ptr; - - ptr = (rt_uint8_t*)RX_BUF(Index); - for (q = p; q != RT_NULL; q= q->next) - { - memcpy(q->payload, ptr, q->len); - ptr += q->len; - } - } - - /* move Index to the next */ - if(++Index > LPC_EMAC->RxDescriptorNumber) - Index = 0; - - /* set consume index */ - LPC_EMAC->RxConsumeIndex = Index; - } - else - { - /* Enable RxDone interrupt */ - LPC_EMAC->IntEnable = INT_RX_DONE | INT_TX_DONE; - } - - /* unlock EMAC device */ - rt_sem_release(&sem_lock); - - return p; + struct pbuf* p; + rt_uint32_t size; + rt_uint32_t Index; + + /* init p pointer */ + p = RT_NULL; + + /* lock EMAC device */ + rt_sem_take(&sem_lock, RT_WAITING_FOREVER); + + Index = LPC_EMAC->RxConsumeIndex; + if(Index != LPC_EMAC->RxProduceIndex) + { + size = (RX_STAT_INFO(Index) & 0x7ff)+1; + if (size > ETH_FRAG_SIZE) size = ETH_FRAG_SIZE; + + /* allocate buffer */ + p = pbuf_alloc(PBUF_LINK, size, PBUF_RAM); + if (p != RT_NULL) + { + struct pbuf* q; + rt_uint8_t *ptr; + + ptr = (rt_uint8_t*)RX_BUF(Index); + for (q = p; q != RT_NULL; q= q->next) + { + memcpy(q->payload, ptr, q->len); + ptr += q->len; + } + } + + /* move Index to the next */ + if(++Index > LPC_EMAC->RxDescriptorNumber) + Index = 0; + + /* set consume index */ + LPC_EMAC->RxConsumeIndex = Index; + } + else + { + /* Enable RxDone interrupt */ + LPC_EMAC->IntEnable = INT_RX_DONE | INT_TX_DONE; + } + + /* unlock EMAC device */ + rt_sem_release(&sem_lock); + + return p; } void lpc17xx_emac_hw_init(void) { - rt_event_init(&tx_event, "tx_event", RT_IPC_FLAG_FIFO); - rt_sem_init(&sem_lock, "eth_lock", 1, RT_IPC_FLAG_FIFO); - - /* set autonegotiation mode */ - lpc17xx_emac_device.phy_mode = EMAC_PHY_AUTO; - - // OUI 00-60-37 NXP Semiconductors - lpc17xx_emac_device.dev_addr[0] = 0x00; - lpc17xx_emac_device.dev_addr[1] = 0x60; - lpc17xx_emac_device.dev_addr[2] = 0x37; - /* set mac address: (only for test) */ - lpc17xx_emac_device.dev_addr[3] = 0x12; - lpc17xx_emac_device.dev_addr[4] = 0x34; - lpc17xx_emac_device.dev_addr[5] = 0x56; - - lpc17xx_emac_device.parent.parent.init = lpc17xx_emac_init; - lpc17xx_emac_device.parent.parent.open = lpc17xx_emac_open; - lpc17xx_emac_device.parent.parent.close = lpc17xx_emac_close; - lpc17xx_emac_device.parent.parent.read = lpc17xx_emac_read; - lpc17xx_emac_device.parent.parent.write = lpc17xx_emac_write; - lpc17xx_emac_device.parent.parent.control = lpc17xx_emac_control; - lpc17xx_emac_device.parent.parent.user_data = RT_NULL; - - lpc17xx_emac_device.parent.eth_rx = lpc17xx_emac_rx; - lpc17xx_emac_device.parent.eth_tx = lpc17xx_emac_tx; - - eth_device_init(&(lpc17xx_emac_device.parent), "e0"); + rt_event_init(&tx_event, "tx_event", RT_IPC_FLAG_FIFO); + rt_sem_init(&sem_lock, "eth_lock", 1, RT_IPC_FLAG_FIFO); + + /* set autonegotiation mode */ + lpc17xx_emac_device.phy_mode = EMAC_PHY_AUTO; + + // OUI 00-60-37 NXP Semiconductors + lpc17xx_emac_device.dev_addr[0] = 0x00; + lpc17xx_emac_device.dev_addr[1] = 0x60; + lpc17xx_emac_device.dev_addr[2] = 0x37; + /* set mac address: (only for test) */ + lpc17xx_emac_device.dev_addr[3] = 0x12; + lpc17xx_emac_device.dev_addr[4] = 0x34; + lpc17xx_emac_device.dev_addr[5] = 0x56; + + lpc17xx_emac_device.parent.parent.init = lpc17xx_emac_init; + lpc17xx_emac_device.parent.parent.open = lpc17xx_emac_open; + lpc17xx_emac_device.parent.parent.close = lpc17xx_emac_close; + lpc17xx_emac_device.parent.parent.read = lpc17xx_emac_read; + lpc17xx_emac_device.parent.parent.write = lpc17xx_emac_write; + lpc17xx_emac_device.parent.parent.control = lpc17xx_emac_control; + lpc17xx_emac_device.parent.parent.user_data = RT_NULL; + + lpc17xx_emac_device.parent.eth_rx = lpc17xx_emac_rx; + lpc17xx_emac_device.parent.eth_tx = lpc17xx_emac_tx; + + eth_device_init(&(lpc17xx_emac_device.parent), "e0"); } #ifdef RT_USING_FINSH #include void emac_dump() { - rt_kprintf("Command : %08x\n", LPC_EMAC->Command); - rt_kprintf("Status : %08x\n", LPC_EMAC->Status); - rt_kprintf("RxStatus : %08x\n", LPC_EMAC->RxStatus); - rt_kprintf("TxStatus : %08x\n", LPC_EMAC->TxStatus); - rt_kprintf("IntEnable: %08x\n", LPC_EMAC->IntEnable); - rt_kprintf("IntStatus: %08x\n", LPC_EMAC->IntStatus); + rt_kprintf("Command : %08x\n", LPC_EMAC->Command); + rt_kprintf("Status : %08x\n", LPC_EMAC->Status); + rt_kprintf("RxStatus : %08x\n", LPC_EMAC->RxStatus); + rt_kprintf("TxStatus : %08x\n", LPC_EMAC->TxStatus); + rt_kprintf("IntEnable: %08x\n", LPC_EMAC->IntEnable); + rt_kprintf("IntStatus: %08x\n", LPC_EMAC->IntStatus); } FINSH_FUNCTION_EXPORT(emac_dump, dump emac register); #endif diff --git a/bsp/lpc178x/drivers/emac.h b/bsp/lpc178x/drivers/emac.h index dafcd36e9b..4b89c8ca82 100644 --- a/bsp/lpc178x/drivers/emac.h +++ b/bsp/lpc178x/drivers/emac.h @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #ifndef __LPC17XX_EMAC_H #define __LPC17XX_EMAC_H @@ -11,7 +20,7 @@ #define ETH_MAX_FLEN 1536 /* Max. Ethernet Frame Size */ /* EMAC variables located in 16K Ethernet SRAM */ -#define RX_DESC_BASE 0x20000000 +#define RX_DESC_BASE 0x20000000 #define RX_STAT_BASE (RX_DESC_BASE + NUM_RX_FRAG*8) #define TX_DESC_BASE (RX_STAT_BASE + NUM_RX_FRAG*8) #define TX_STAT_BASE (TX_DESC_BASE + NUM_TX_FRAG*8) diff --git a/bsp/lpc178x/drivers/lpc177x_8x_clkpwr.c b/bsp/lpc178x/drivers/lpc177x_8x_clkpwr.c index ad9bfffeba..3e7abe8b3b 100644 --- a/bsp/lpc178x/drivers/lpc177x_8x_clkpwr.c +++ b/bsp/lpc178x/drivers/lpc177x_8x_clkpwr.c @@ -1,13 +1,13 @@ /********************************************************************** -* $Id$ lpc177x_8x_clkpwr.c 2011-06-02 +* $Id$ lpc177x_8x_clkpwr.c 2011-06-02 *//** -* @file lpc177x_8x_clkpwr.c -* @brief Contains all functions support for Clock and Power Control -* firmware library on LPC177x_8x -* @version 1.0 -* @date 02. June. 2011 -* @author NXP MCU SW Application Team -* +* @file lpc177x_8x_clkpwr.c +* @brief Contains all functions support for Clock and Power Control +* firmware library on LPC177x_8x +* @version 1.0 +* @date 02. June. 2011 +* @author NXP MCU SW Application Team +* * Copyright(C) 2011, NXP Semiconductor * All rights reserved. * @@ -41,253 +41,253 @@ uint32_t SPIFIFrequency = 0; */ /*********************************************************************//** - * @brief Set value of each Peripheral Clock Selection - * @param[in] ClkType clock type that will be divided, should be: - * - CLKPWR_CLKTYPE_CPU : CPU clock - * - CLKPWR_CLKTYPE_PER : Peripheral clock - * - CLKPWR_CLKTYPE_EMC : EMC clock - * - CLKPWR_CLKTYPE_USB : USB clock - * @param[in] DivVal Value of divider. This value should be set as follows: - * - CPU clock: DivVal must be in range: 0..31 - * - Peripheral clock: DivVal must be in range: 0..31 - * - EMC clock: DivVal must be: - * + 0: The EMC uses the same clock as the CPU - * + 1: The EMC uses a clock at half the rate of the CPU - * - USB clock: DivVal must be: - * + 0: the divider is turned off, no clock will - * be provided to the USB subsystem - * + 4: PLL0 output is divided by 4. PLL0 output must be 192MHz - * + 6: PLL0 output is divided by 6. PLL0 output must be 288MHz + * @brief Set value of each Peripheral Clock Selection + * @param[in] ClkType clock type that will be divided, should be: + * - CLKPWR_CLKTYPE_CPU : CPU clock + * - CLKPWR_CLKTYPE_PER : Peripheral clock + * - CLKPWR_CLKTYPE_EMC : EMC clock + * - CLKPWR_CLKTYPE_USB : USB clock + * @param[in] DivVal Value of divider. This value should be set as follows: + * - CPU clock: DivVal must be in range: 0..31 + * - Peripheral clock: DivVal must be in range: 0..31 + * - EMC clock: DivVal must be: + * + 0: The EMC uses the same clock as the CPU + * + 1: The EMC uses a clock at half the rate of the CPU + * - USB clock: DivVal must be: + * + 0: the divider is turned off, no clock will + * be provided to the USB subsystem + * + 4: PLL0 output is divided by 4. PLL0 output must be 192MHz + * + 6: PLL0 output is divided by 6. PLL0 output must be 288MHz * @return none * Note: Pls assign right DivVal, this function will not check if it is illegal. **********************************************************************/ void CLKPWR_SetCLKDiv (uint8_t ClkType, uint8_t DivVal) { - switch(ClkType) - { - case CLKPWR_CLKTYPE_CPU: - LPC_SC->CCLKSEL = DivVal; - SystemCoreClockUpdate(); //Update clock - break; - case CLKPWR_CLKTYPE_PER: - LPC_SC->PCLKSEL = DivVal; - SystemCoreClockUpdate(); //Update clock - break; - case CLKPWR_CLKTYPE_EMC: - LPC_SC->EMCCLKSEL = DivVal; - SystemCoreClockUpdate(); //Update clock - break; - case CLKPWR_CLKTYPE_USB: - LPC_SC->USBCLKSEL &= ~(0x0000001F); - LPC_SC->USBCLKSEL |= DivVal; - break; - default: - while(1);//Error Loop; - } + switch(ClkType) + { + case CLKPWR_CLKTYPE_CPU: + LPC_SC->CCLKSEL = DivVal; + SystemCoreClockUpdate(); //Update clock + break; + case CLKPWR_CLKTYPE_PER: + LPC_SC->PCLKSEL = DivVal; + SystemCoreClockUpdate(); //Update clock + break; + case CLKPWR_CLKTYPE_EMC: + LPC_SC->EMCCLKSEL = DivVal; + SystemCoreClockUpdate(); //Update clock + break; + case CLKPWR_CLKTYPE_USB: + LPC_SC->USBCLKSEL &= ~(0x0000001F); + LPC_SC->USBCLKSEL |= DivVal; + break; + default: + while(1);//Error Loop; + } } /*********************************************************************//** - * @brief Get current clock value - * @param[in] ClkType clock type that will be divided, should be: - * - CLKPWR_CLKTYPE_CPU : CPU clock - * - CLKPWR_CLKTYPE_PER : Peripheral clock - * - CLKPWR_CLKTYPE_EMC : EMC clock - * - CLKPWR_CLKTYPE_USB : USB clock + * @brief Get current clock value + * @param[in] ClkType clock type that will be divided, should be: + * - CLKPWR_CLKTYPE_CPU : CPU clock + * - CLKPWR_CLKTYPE_PER : Peripheral clock + * - CLKPWR_CLKTYPE_EMC : EMC clock + * - CLKPWR_CLKTYPE_USB : USB clock **********************************************************************/ uint32_t CLKPWR_GetCLK (uint8_t ClkType) { - switch(ClkType) - { - case CLKPWR_CLKTYPE_CPU: - return SystemCoreClock; + switch(ClkType) + { + case CLKPWR_CLKTYPE_CPU: + return SystemCoreClock; - case CLKPWR_CLKTYPE_PER: - return PeripheralClock; + case CLKPWR_CLKTYPE_PER: + return PeripheralClock; - case CLKPWR_CLKTYPE_EMC: - return EMCClock; + case CLKPWR_CLKTYPE_EMC: + return EMCClock; - case CLKPWR_CLKTYPE_USB: - return USBClock; + case CLKPWR_CLKTYPE_USB: + return USBClock; - default: - while(1);//error loop - } + default: + while(1);//error loop + } } /*********************************************************************//** - * @brief Configure power supply for each peripheral according to NewState - * @param[in] PPType Type of peripheral used to enable power, - * should be one of the following: - * - CLKPWR_PCONP_PCLCD : LCD - * - CLKPWR_PCONP_PCTIM0 : Timer 0 - - CLKPWR_PCONP_PCTIM1 : Timer 1 - - CLKPWR_PCONP_PCUART0 : UART 0 - - CLKPWR_PCONP_PCUART1 : UART 1 - - CLKPWR_PCONP_PCPWM0 : PWM 0 - - CLKPWR_PCONP_PCPWM1 : PWM 1 - - CLKPWR_PCONP_PCI2C0 : I2C 0 - - CLKPWR_PCONP_PCUART4 : UART4 - - CLKPWR_PCONP_PCRTC : RTC - - CLKPWR_PCONP_PCSSP1 : SSP 1 - - CLKPWR_PCONP_PCEMC : EMC - - CLKPWR_PCONP_PCADC : ADC - - CLKPWR_PCONP_PCAN1 : CAN 1 - - CLKPWR_PCONP_PCAN2 : CAN 2 - - CLKPWR_PCONP_PCGPIO : GPIO - - CLKPWR_PCONP_PCMC : MCPWM - - CLKPWR_PCONP_PCQEI : QEI - - CLKPWR_PCONP_PCI2C1 : I2C 1 - - CLKPWR_PCONP_PCSSP2 : SSP 2 - - CLKPWR_PCONP_PCSSP0 : SSP 0 - - CLKPWR_PCONP_PCTIM2 : Timer 2 - - CLKPWR_PCONP_PCTIM3 : Timer 3 - - CLKPWR_PCONP_PCUART2 : UART 2 - - CLKPWR_PCONP_PCUART3 : UART 3 - - CLKPWR_PCONP_PCI2C2 : I2C 2 - - CLKPWR_PCONP_PCI2S : I2S - - CLKPWR_PCONP_PCSDC : SDC - - CLKPWR_PCONP_PCGPDMA : GPDMA - - CLKPWR_PCONP_PCENET : Ethernet - - CLKPWR_PCONP_PCUSB : USB + * @brief Configure power supply for each peripheral according to NewState + * @param[in] PPType Type of peripheral used to enable power, + * should be one of the following: + * - CLKPWR_PCONP_PCLCD : LCD + * - CLKPWR_PCONP_PCTIM0 : Timer 0 + - CLKPWR_PCONP_PCTIM1 : Timer 1 + - CLKPWR_PCONP_PCUART0 : UART 0 + - CLKPWR_PCONP_PCUART1 : UART 1 + - CLKPWR_PCONP_PCPWM0 : PWM 0 + - CLKPWR_PCONP_PCPWM1 : PWM 1 + - CLKPWR_PCONP_PCI2C0 : I2C 0 + - CLKPWR_PCONP_PCUART4 : UART4 + - CLKPWR_PCONP_PCRTC : RTC + - CLKPWR_PCONP_PCSSP1 : SSP 1 + - CLKPWR_PCONP_PCEMC : EMC + - CLKPWR_PCONP_PCADC : ADC + - CLKPWR_PCONP_PCAN1 : CAN 1 + - CLKPWR_PCONP_PCAN2 : CAN 2 + - CLKPWR_PCONP_PCGPIO : GPIO + - CLKPWR_PCONP_PCMC : MCPWM + - CLKPWR_PCONP_PCQEI : QEI + - CLKPWR_PCONP_PCI2C1 : I2C 1 + - CLKPWR_PCONP_PCSSP2 : SSP 2 + - CLKPWR_PCONP_PCSSP0 : SSP 0 + - CLKPWR_PCONP_PCTIM2 : Timer 2 + - CLKPWR_PCONP_PCTIM3 : Timer 3 + - CLKPWR_PCONP_PCUART2 : UART 2 + - CLKPWR_PCONP_PCUART3 : UART 3 + - CLKPWR_PCONP_PCI2C2 : I2C 2 + - CLKPWR_PCONP_PCI2S : I2S + - CLKPWR_PCONP_PCSDC : SDC + - CLKPWR_PCONP_PCGPDMA : GPDMA + - CLKPWR_PCONP_PCENET : Ethernet + - CLKPWR_PCONP_PCUSB : USB * - * @param[in] NewState New state of Peripheral Power, should be: - * - ENABLE : Enable power for this peripheral - * - DISABLE : Disable power for this peripheral + * @param[in] NewState New state of Peripheral Power, should be: + * - ENABLE : Enable power for this peripheral + * - DISABLE : Disable power for this peripheral * * @return none **********************************************************************/ void CLKPWR_ConfigPPWR (uint32_t PPType, FunctionalState NewState) { - if (NewState == ENABLE) - { - LPC_SC->PCONP |= PPType; - } - else if (NewState == DISABLE) - { - LPC_SC->PCONP &= ~PPType; - } + if (NewState == ENABLE) + { + LPC_SC->PCONP |= PPType; + } + else if (NewState == DISABLE) + { + LPC_SC->PCONP &= ~PPType; + } } #if 0 // nxp21346 /*********************************************************************//** - * @brief Configure hardware reset for each peripheral according to NewState - * @param[in] PPType Type of peripheral used to enable power, - * should be one of the following: - * - CLKPWR_RSTCON0_LCD : LCD - * - CLKPWR_RSTCON0_TIM0 : Timer 0 - - CLKPWR_RSTCON0_TIM1 : Timer 1 - - CLKPWR_RSTCON0_UART0 : UART 0 - - CLKPWR_RSTCON0_UART1 : UART 1 - - CLKPWR_RSTCON0_PWM0 : PWM 0 - - CLKPWR_RSTCON0_PWM1 : PWM 1 - - CLKPWR_RSTCON0_I2C0 : I2C 0 - - CLKPWR_RSTCON0_UART4 : UART 4 - - CLKPWR_RSTCON0_RTC : RTC - - CLKPWR_RSTCON0_SSP1 : SSP 1 - - CLKPWR_RSTCON0_EMC : EMC - - CLKPWR_RSTCON0_ADC : ADC - - CLKPWR_RSTCON0_CAN1 : CAN 1 - - CLKPWR_RSTCON0_CAN2 : CAN 2 - - CLKPWR_RSTCON0_GPIO : GPIO - - CLKPWR_RSTCON0_MCPWM : MCPWM - - CLKPWR_RSTCON0_QEI : QEI - - CLKPWR_RSTCON0_I2C1 : I2C 1 - - CLKPWR_RSTCON0_SSP2 : SSP 2 - - CLKPWR_RSTCON0_SSP0 : SSP 0 - - CLKPWR_RSTCON0_TIM2 : Timer 2 - - CLKPWR_RSTCON0_TIM3 : Timer 3 - - CLKPWR_RSTCON0_UART2 : UART 2 - - CLKPWR_RSTCON0_UART3 : UART 3 - - CLKPWR_RSTCON0_I2C2 : I2C 2 - - CLKPWR_RSTCON0_I2S : I2S - - CLKPWR_RSTCON0_SDC : SDC - - CLKPWR_RSTCON0_GPDMA : GPDMA - - CLKPWR_RSTCON0_ENET : Ethernet - - CLKPWR_RSTCON0_USB : USB + * @brief Configure hardware reset for each peripheral according to NewState + * @param[in] PPType Type of peripheral used to enable power, + * should be one of the following: + * - CLKPWR_RSTCON0_LCD : LCD + * - CLKPWR_RSTCON0_TIM0 : Timer 0 + - CLKPWR_RSTCON0_TIM1 : Timer 1 + - CLKPWR_RSTCON0_UART0 : UART 0 + - CLKPWR_RSTCON0_UART1 : UART 1 + - CLKPWR_RSTCON0_PWM0 : PWM 0 + - CLKPWR_RSTCON0_PWM1 : PWM 1 + - CLKPWR_RSTCON0_I2C0 : I2C 0 + - CLKPWR_RSTCON0_UART4 : UART 4 + - CLKPWR_RSTCON0_RTC : RTC + - CLKPWR_RSTCON0_SSP1 : SSP 1 + - CLKPWR_RSTCON0_EMC : EMC + - CLKPWR_RSTCON0_ADC : ADC + - CLKPWR_RSTCON0_CAN1 : CAN 1 + - CLKPWR_RSTCON0_CAN2 : CAN 2 + - CLKPWR_RSTCON0_GPIO : GPIO + - CLKPWR_RSTCON0_MCPWM : MCPWM + - CLKPWR_RSTCON0_QEI : QEI + - CLKPWR_RSTCON0_I2C1 : I2C 1 + - CLKPWR_RSTCON0_SSP2 : SSP 2 + - CLKPWR_RSTCON0_SSP0 : SSP 0 + - CLKPWR_RSTCON0_TIM2 : Timer 2 + - CLKPWR_RSTCON0_TIM3 : Timer 3 + - CLKPWR_RSTCON0_UART2 : UART 2 + - CLKPWR_RSTCON0_UART3 : UART 3 + - CLKPWR_RSTCON0_I2C2 : I2C 2 + - CLKPWR_RSTCON0_I2S : I2S + - CLKPWR_RSTCON0_SDC : SDC + - CLKPWR_RSTCON0_GPDMA : GPDMA + - CLKPWR_RSTCON0_ENET : Ethernet + - CLKPWR_RSTCON0_USB : USB * - * @param[in] NewState New state of Peripheral Power, should be: - * - ENABLE : Enable power for this peripheral - * - DISABLE : Disable power for this peripheral + * @param[in] NewState New state of Peripheral Power, should be: + * - ENABLE : Enable power for this peripheral + * - DISABLE : Disable power for this peripheral * * @return none **********************************************************************/ void CLKPWR_ConfigReset(uint8_t PType, FunctionalState NewState) { - if(PType < 32) - { - if(NewState == ENABLE) - LPC_SC->RSTCON0 |=(1<RSTCON0 &=~(1<RSTCON1 |= (1<<(PType - 31)); - else - LPC_SC->RSTCON1 &= ~(1<<(PType - 31)); - } + if(PType < 32) + { + if(NewState == ENABLE) + LPC_SC->RSTCON0 |=(1<RSTCON0 &=~(1<RSTCON1 |= (1<<(PType - 31)); + else + LPC_SC->RSTCON1 &= ~(1<<(PType - 31)); + } } // nxp21346 #endif /*********************************************************************//** - * @brief Enter Sleep mode with co-operated instruction by the Cortex-M3. - * @param[in] None - * @return None + * @brief Enter Sleep mode with co-operated instruction by the Cortex-M3. + * @param[in] None + * @return None **********************************************************************/ void CLKPWR_Sleep(void) { - LPC_SC->PCON = 0x00; - /* Sleep Mode*/ - __WFI(); + LPC_SC->PCON = 0x00; + /* Sleep Mode*/ + __WFI(); } /*********************************************************************//** - * @brief Enter Deep Sleep mode with co-operated instruction by the Cortex-M3. - * @param[in] None - * @return None + * @brief Enter Deep Sleep mode with co-operated instruction by the Cortex-M3. + * @param[in] None + * @return None **********************************************************************/ void CLKPWR_DeepSleep(void) { /* Deep-Sleep Mode, set SLEEPDEEP bit */ - SCB->SCR = 0x4; - LPC_SC->PCON = 0x8; - /* Deep Sleep Mode*/ - __WFI(); + SCB->SCR = 0x4; + LPC_SC->PCON = 0x8; + /* Deep Sleep Mode*/ + __WFI(); } /*********************************************************************//** - * @brief Enter Power Down mode with co-operated instruction by the Cortex-M3. - * @param[in] None - * @return None + * @brief Enter Power Down mode with co-operated instruction by the Cortex-M3. + * @param[in] None + * @return None **********************************************************************/ void CLKPWR_PowerDown(void) { /* Deep-Sleep Mode, set SLEEPDEEP bit */ - SCB->SCR = 0x4; - LPC_SC->PCON = 0x09; - /* Power Down Mode*/ - __WFI(); + SCB->SCR = 0x4; + LPC_SC->PCON = 0x09; + /* Power Down Mode*/ + __WFI(); } /*********************************************************************//** - * @brief Enter Deep Power Down mode with co-operated instruction by the Cortex-M3. - * @param[in] None - * @return None + * @brief Enter Deep Power Down mode with co-operated instruction by the Cortex-M3. + * @param[in] None + * @return None **********************************************************************/ void CLKPWR_DeepPowerDown(void) { /* Deep-Sleep Mode, set SLEEPDEEP bit */ - SCB->SCR = 0x4; - LPC_SC->PCON = 0x03; - /* Deep Power Down Mode*/ - __WFI(); + SCB->SCR = 0x4; + LPC_SC->PCON = 0x03; + /* Deep Power Down Mode*/ + __WFI(); } /** diff --git a/bsp/lpc178x/drivers/lpc177x_8x_clkpwr.h b/bsp/lpc178x/drivers/lpc177x_8x_clkpwr.h index 427ccc0279..b1bf670b52 100644 --- a/bsp/lpc178x/drivers/lpc177x_8x_clkpwr.h +++ b/bsp/lpc178x/drivers/lpc177x_8x_clkpwr.h @@ -1,14 +1,14 @@ /********************************************************************** -* $Id$ lpc177x_8x_clkpwr.h 2011-06-02 +* $Id$ lpc177x_8x_clkpwr.h 2011-06-02 *//** -* @file lpc177x_8x_clkpwr.h -* @brief Contains all macro definitions and function prototypes -* support for Clock and Power Control firmware library on -* LPC177x_8x -* @version 1.0 -* @date 02. June. 2011 -* @author NXP MCU SW Application Team -* +* @file lpc177x_8x_clkpwr.h +* @brief Contains all macro definitions and function prototypes +* support for Clock and Power Control firmware library on +* LPC177x_8x +* @version 1.0 +* @date 02. June. 2011 +* @author NXP MCU SW Application Team +* * Copyright(C) 2011, NXP Semiconductor * All rights reserved. * @@ -26,7 +26,7 @@ **********************************************************************/ /* Peripheral group ----------------------------------------------------------- */ -/** @defgroup CLKPWR Clock Power +/** @defgroup CLKPWR Clock Power * @ingroup LPC177x_8xCMSIS_FwLib_Drivers * @{ */ @@ -52,163 +52,163 @@ extern "C" /******************************************************************** * Clock Source Selection Definitions **********************************************************************/ -#define CLKPWR_CLKSRCSEL_IRCOSC ((uint32_t)(0)) -#define CLKPWR_CLKSRCSEL_MAINOSC ((uint32_t)(1)) +#define CLKPWR_CLKSRCSEL_IRCOSC ((uint32_t)(0)) +#define CLKPWR_CLKSRCSEL_MAINOSC ((uint32_t)(1)) /******************************************************************** * Clock type/domain Definitions (calculated from input and pre-configuration * parameter(s) **********************************************************************/ -#define CLKPWR_CLKTYPE_CPU ((uint32_t)(0)) -#define CLKPWR_CLKTYPE_PER ((uint32_t)(1)) -#define CLKPWR_CLKTYPE_EMC ((uint32_t)(2)) -#define CLKPWR_CLKTYPE_USB ((uint32_t)(3)) +#define CLKPWR_CLKTYPE_CPU ((uint32_t)(0)) +#define CLKPWR_CLKTYPE_PER ((uint32_t)(1)) +#define CLKPWR_CLKTYPE_EMC ((uint32_t)(2)) +#define CLKPWR_CLKTYPE_USB ((uint32_t)(3)) /******************************************************************** * Power Control for Peripherals Definitions **********************************************************************/ /** LCD controller power/clock control bit */ -#define CLKPWR_PCONP_PCLCD ((uint32_t)(1<<0)) +#define CLKPWR_PCONP_PCLCD ((uint32_t)(1<<0)) /** Timer/Counter 0 power/clock control bit */ -#define CLKPWR_PCONP_PCTIM0 ((uint32_t)(1<<1)) +#define CLKPWR_PCONP_PCTIM0 ((uint32_t)(1<<1)) /* Timer/Counter 1 power/clock control bit */ -#define CLKPWR_PCONP_PCTIM1 ((uint32_t)(1<<2)) +#define CLKPWR_PCONP_PCTIM1 ((uint32_t)(1<<2)) /** UART0 power/clock control bit */ -#define CLKPWR_PCONP_PCUART0 ((uint32_t)(1<<3)) +#define CLKPWR_PCONP_PCUART0 ((uint32_t)(1<<3)) /** UART1 power/clock control bit */ -#define CLKPWR_PCONP_PCUART1 ((uint32_t)(1<<4)) +#define CLKPWR_PCONP_PCUART1 ((uint32_t)(1<<4)) /** PWM0 power/clock control bit */ -#define CLKPWR_PCONP_PCPWM0 ((uint32_t)(1<<5)) +#define CLKPWR_PCONP_PCPWM0 ((uint32_t)(1<<5)) /** PWM1 power/clock control bit */ -#define CLKPWR_PCONP_PCPWM1 ((uint32_t)(1<<6)) +#define CLKPWR_PCONP_PCPWM1 ((uint32_t)(1<<6)) /** The I2C0 interface power/clock control bit */ -#define CLKPWR_PCONP_PCI2C0 ((uint32_t)(1<<7)) +#define CLKPWR_PCONP_PCI2C0 ((uint32_t)(1<<7)) /** UART4 power/clock control bit */ -#define CLKPWR_PCONP_PCUART4 ((uint32_t)(1<<8)) +#define CLKPWR_PCONP_PCUART4 ((uint32_t)(1<<8)) /** The RTC power/clock control bit */ -#define CLKPWR_PCONP_PCRTC ((uint32_t)(1<<9)) +#define CLKPWR_PCONP_PCRTC ((uint32_t)(1<<9)) /** The SSP1 interface power/clock control bit */ -#define CLKPWR_PCONP_PCSSP1 ((uint32_t)(1<<10)) +#define CLKPWR_PCONP_PCSSP1 ((uint32_t)(1<<10)) /** External Memory controller power/clock control bit */ -#define CLKPWR_PCONP_PCEMC ((uint32_t)(1<<11)) +#define CLKPWR_PCONP_PCEMC ((uint32_t)(1<<11)) /** A/D converter 0 (ADC0) power/clock control bit */ -#define CLKPWR_PCONP_PCADC ((uint32_t)(1<<12)) +#define CLKPWR_PCONP_PCADC ((uint32_t)(1<<12)) /** CAN Controller 1 power/clock control bit */ -#define CLKPWR_PCONP_PCAN1 ((uint32_t)(1<<13)) +#define CLKPWR_PCONP_PCAN1 ((uint32_t)(1<<13)) /** CAN Controller 2 power/clock control bit */ -#define CLKPWR_PCONP_PCAN2 ((uint32_t)(1<<14)) +#define CLKPWR_PCONP_PCAN2 ((uint32_t)(1<<14)) /** GPIO power/clock control bit */ -#define CLKPWR_PCONP_PCGPIO ((uint32_t)(1<<15)) +#define CLKPWR_PCONP_PCGPIO ((uint32_t)(1<<15)) /** Motor Control PWM */ -#define CLKPWR_PCONP_PCMCPWM ((uint32_t)(1<<17)) +#define CLKPWR_PCONP_PCMCPWM ((uint32_t)(1<<17)) /** Quadrature Encoder Interface power/clock control bit */ -#define CLKPWR_PCONP_PCQEI ((uint32_t)(1<<18)) +#define CLKPWR_PCONP_PCQEI ((uint32_t)(1<<18)) /** The I2C1 interface power/clock control bit */ -#define CLKPWR_PCONP_PCI2C1 ((uint32_t)(1<<19)) +#define CLKPWR_PCONP_PCI2C1 ((uint32_t)(1<<19)) /** The SSP2 interface power/clock control bit */ -#define CLKPWR_PCONP_PCSSP2 ((uint32_t)(1<<20)) +#define CLKPWR_PCONP_PCSSP2 ((uint32_t)(1<<20)) /** The SSP0 interface power/clock control bit */ -#define CLKPWR_PCONP_PCSSP0 ((uint32_t)(1<<21)) +#define CLKPWR_PCONP_PCSSP0 ((uint32_t)(1<<21)) /** Timer 2 power/clock control bit */ -#define CLKPWR_PCONP_PCTIM2 ((uint32_t)(1<<22)) +#define CLKPWR_PCONP_PCTIM2 ((uint32_t)(1<<22)) /** Timer 3 power/clock control bit */ -#define CLKPWR_PCONP_PCTIM3 ((uint32_t)(1<<23)) +#define CLKPWR_PCONP_PCTIM3 ((uint32_t)(1<<23)) /** UART 2 power/clock control bit */ -#define CLKPWR_PCONP_PCUART2 ((uint32_t)(1<<24)) +#define CLKPWR_PCONP_PCUART2 ((uint32_t)(1<<24)) /** UART 3 power/clock control bit */ -#define CLKPWR_PCONP_PCUART3 ((uint32_t)(1<<25)) +#define CLKPWR_PCONP_PCUART3 ((uint32_t)(1<<25)) /** I2C interface 2 power/clock control bit */ -#define CLKPWR_PCONP_PCI2C2 ((uint32_t)(1<<26)) +#define CLKPWR_PCONP_PCI2C2 ((uint32_t)(1<<26)) /** I2S interface power/clock control bit*/ -#define CLKPWR_PCONP_PCI2S ((uint32_t)(1<<27)) +#define CLKPWR_PCONP_PCI2S ((uint32_t)(1<<27)) /** SD card interface power/clock control bit */ -#define CLKPWR_PCONP_PCSDC ((uint32_t)(1<<28)) +#define CLKPWR_PCONP_PCSDC ((uint32_t)(1<<28)) /** GP DMA function power/clock control bit*/ -#define CLKPWR_PCONP_PCGPDMA ((uint32_t)(1<<29)) +#define CLKPWR_PCONP_PCGPDMA ((uint32_t)(1<<29)) /** Ethernet block power/clock control bit*/ -#define CLKPWR_PCONP_PCENET ((uint32_t)(1<<30)) +#define CLKPWR_PCONP_PCENET ((uint32_t)(1<<30)) /** USB interface power/clock control bit*/ -#define CLKPWR_PCONP_PCUSB ((uint32_t)(1<<31)) +#define CLKPWR_PCONP_PCUSB ((uint32_t)(1<<31)) /******************************************************************** * Power Control for Peripherals Definitions **********************************************************************/ -#define CLKPWR_RSTCON0_LCD ((uint32_t)(0)) -#define CLKPWR_RSTCON0_TIM0 ((uint32_t)(1)) -#define CLKPWR_RSTCON0_TIM1 ((uint32_t)(2)) -#define CLKPWR_RSTCON0_UART0 ((uint32_t)(3)) -#define CLKPWR_RSTCON0_UART1 ((uint32_t)(4)) -#define CLKPWR_RSTCON0_PWM0 ((uint32_t)(5)) -#define CLKPWR_RSTCON0_PWM1 ((uint32_t)(6)) -#define CLKPWR_RSTCON0_I2C0 ((uint32_t)(7)) -#define CLKPWR_RSTCON0_UART4 ((uint32_t)(8)) -#define CLKPWR_RSTCON0_RTC ((uint32_t)(9)) -#define CLKPWR_RSTCON0_SSP1 ((uint32_t)(10)) -#define CLKPWR_RSTCON0_EMC ((uint32_t)(11)) -#define CLKPWR_RSTCON0_ADC ((uint32_t)(12)) -#define CLKPWR_RSTCON0_CAN1 ((uint32_t)(13)) -#define CLKPWR_RSTCON0_CAN2 ((uint32_t)(14)) -#define CLKPWR_RSTCON0_GPIO ((uint32_t)(15)) -#define CLKPWR_RSTCON0_MCPWM ((uint32_t)(17)) -#define CLKPWR_RSTCON0_QEI ((uint32_t)(18)) -#define CLKPWR_RSTCON0_I2C1 ((uint32_t)(19)) -#define CLKPWR_RSTCON0_SSP2 ((uint32_t)(20)) -#define CLKPWR_RSTCON0_SSP0 ((uint32_t)(21)) -#define CLKPWR_RSTCON0_TIM2 ((uint32_t)(22)) -#define CLKPWR_RSTCON0_TIM3 ((uint32_t)(23)) -#define CLKPWR_RSTCON0_UART2 ((uint32_t)(24)) -#define CLKPWR_RSTCON0_UART3 ((uint32_t)(25)) -#define CLKPWR_RSTCON0_I2C2 ((uint32_t)(26)) -#define CLKPWR_RSTCON0_I2S ((uint32_t)(27)) -#define CLKPWR_RSTCON0_SDC ((uint32_t)(28)) -#define CLKPWR_RSTCON0_GPDMA ((uint32_t)(29)) -#define CLKPWR_RSTCON0_ENET ((uint32_t)(30)) -#define CLKPWR_RSTCON0_USB ((uint32_t)(31)) - -#define CLKPWR_RSTCON1_IOCON ((uint32_t)(32)) -#define CLKPWR_RSTCON1_DAC ((uint32_t)(33)) -#define CLKPWR_RSTCON1_CANACC ((uint32_t)(34)) +#define CLKPWR_RSTCON0_LCD ((uint32_t)(0)) +#define CLKPWR_RSTCON0_TIM0 ((uint32_t)(1)) +#define CLKPWR_RSTCON0_TIM1 ((uint32_t)(2)) +#define CLKPWR_RSTCON0_UART0 ((uint32_t)(3)) +#define CLKPWR_RSTCON0_UART1 ((uint32_t)(4)) +#define CLKPWR_RSTCON0_PWM0 ((uint32_t)(5)) +#define CLKPWR_RSTCON0_PWM1 ((uint32_t)(6)) +#define CLKPWR_RSTCON0_I2C0 ((uint32_t)(7)) +#define CLKPWR_RSTCON0_UART4 ((uint32_t)(8)) +#define CLKPWR_RSTCON0_RTC ((uint32_t)(9)) +#define CLKPWR_RSTCON0_SSP1 ((uint32_t)(10)) +#define CLKPWR_RSTCON0_EMC ((uint32_t)(11)) +#define CLKPWR_RSTCON0_ADC ((uint32_t)(12)) +#define CLKPWR_RSTCON0_CAN1 ((uint32_t)(13)) +#define CLKPWR_RSTCON0_CAN2 ((uint32_t)(14)) +#define CLKPWR_RSTCON0_GPIO ((uint32_t)(15)) +#define CLKPWR_RSTCON0_MCPWM ((uint32_t)(17)) +#define CLKPWR_RSTCON0_QEI ((uint32_t)(18)) +#define CLKPWR_RSTCON0_I2C1 ((uint32_t)(19)) +#define CLKPWR_RSTCON0_SSP2 ((uint32_t)(20)) +#define CLKPWR_RSTCON0_SSP0 ((uint32_t)(21)) +#define CLKPWR_RSTCON0_TIM2 ((uint32_t)(22)) +#define CLKPWR_RSTCON0_TIM3 ((uint32_t)(23)) +#define CLKPWR_RSTCON0_UART2 ((uint32_t)(24)) +#define CLKPWR_RSTCON0_UART3 ((uint32_t)(25)) +#define CLKPWR_RSTCON0_I2C2 ((uint32_t)(26)) +#define CLKPWR_RSTCON0_I2S ((uint32_t)(27)) +#define CLKPWR_RSTCON0_SDC ((uint32_t)(28)) +#define CLKPWR_RSTCON0_GPDMA ((uint32_t)(29)) +#define CLKPWR_RSTCON0_ENET ((uint32_t)(30)) +#define CLKPWR_RSTCON0_USB ((uint32_t)(31)) + +#define CLKPWR_RSTCON1_IOCON ((uint32_t)(32)) +#define CLKPWR_RSTCON1_DAC ((uint32_t)(33)) +#define CLKPWR_RSTCON1_CANACC ((uint32_t)(34)) /** * @} */ - + /* External clock variable from system_LPC177x_8x.h */ -extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ -extern uint32_t PeripheralClock; /*!< Peripheral Clock Frequency (Pclk) */ -extern uint32_t EMCClock; /*!< EMC Clock Frequency */ +extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ +extern uint32_t PeripheralClock; /*!< Peripheral Clock Frequency (Pclk) */ +extern uint32_t EMCClock; /*!< EMC Clock Frequency */ /* External clock variable from lpc177x_8x_clkpwr.h */ -extern uint32_t USBClock; /*!< USB Frequency */ +extern uint32_t USBClock; /*!< USB Frequency */ /* Public Functions ----------------------------------------------------------- */ /** @defgroup CLKPWR_Public_Functions CLKPWR Public Functions diff --git a/bsp/lpc178x/drivers/lpc177x_8x_emc.c b/bsp/lpc178x/drivers/lpc177x_8x_emc.c index c3009589a3..4047dbf623 100644 --- a/bsp/lpc178x/drivers/lpc177x_8x_emc.c +++ b/bsp/lpc178x/drivers/lpc177x_8x_emc.c @@ -1,13 +1,13 @@ /********************************************************************** -* $Id$ lpc177x_8x_emc.c 2011-06-02 +* $Id$ lpc177x_8x_emc.c 2011-06-02 *//** -* @file lpc177x_8x_emc.c -* @brief Contains all functions support for EMC firmware library -* on LPC177x_8x -* @version 1.0 -* @date 02. June. 2011 -* @author NXP MCU SW Application Team -* +* @file lpc177x_8x_emc.c +* @brief Contains all functions support for EMC firmware library +* on LPC177x_8x +* @version 1.0 +* @date 02. June. 2011 +* @author NXP MCU SW Application Team +* * Copyright(C) 2011, NXP Semiconductor * All rights reserved. * @@ -30,23 +30,23 @@ /*********************************************************************//** - * @brief EMC initialize - * @param[in] None - * @return None + * @brief EMC initialize + * @param[in] None + * @return None **********************************************************************/ void EMC_Init(void) { - uint8_t i; + uint8_t i; - /* Enable clock for EMC */ -// CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCEMC, ENABLE); -// LPC_EMC->Control = 0x00000001; -// LPC_EMC->Config = 0x00000000; + /* Enable clock for EMC */ +// CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCEMC, ENABLE); +// LPC_EMC->Control = 0x00000001; +// LPC_EMC->Config = 0x00000000; - LPC_SC->PCONP |= 0x00000800; - LPC_SC->EMCDLYCTL = 0x00001010; - LPC_EMC->Control = 0x00000001; - LPC_EMC->Config = 0x00000000; + LPC_SC->PCONP |= 0x00000800; + LPC_SC->EMCDLYCTL = 0x00001010; + LPC_EMC->Control = 0x00000001; + LPC_EMC->Config = 0x00000000; /* Pin configuration: * P2.14 - /EMC_CS2 @@ -81,40 +81,40 @@ void EMC_Init(void) * P4.30 - /EMC_CS0 * P4.31 - /EMC_CS1 */ - PINSEL_ConfigPin(2,14,1); - PINSEL_ConfigPin(2,15,1); - PINSEL_ConfigPin(2,16,1); - PINSEL_ConfigPin(2,17,1); - PINSEL_ConfigPin(2,18,1); - PINSEL_ConfigPin(2,19,1); - PINSEL_ConfigPin(2,20,1); - PINSEL_ConfigPin(2,21,1); - PINSEL_ConfigPin(2,22,1); - PINSEL_ConfigPin(2,23,1); - PINSEL_ConfigPin(2,24,1); - PINSEL_ConfigPin(2,25,1); - PINSEL_ConfigPin(2,26,1); - PINSEL_ConfigPin(2,27,1); - PINSEL_ConfigPin(2,28,1); - PINSEL_ConfigPin(2,29,1); - PINSEL_ConfigPin(2,30,1); - PINSEL_ConfigPin(2,31,1); - - PINSEL_ConfigPin(5,0,1); - PINSEL_ConfigPin(5,1,1); - - for(i = 0; i < 32; i++) - { - PINSEL_ConfigPin(3,i,1); - PINSEL_ConfigPin(4,i,1); - } + PINSEL_ConfigPin(2,14,1); + PINSEL_ConfigPin(2,15,1); + PINSEL_ConfigPin(2,16,1); + PINSEL_ConfigPin(2,17,1); + PINSEL_ConfigPin(2,18,1); + PINSEL_ConfigPin(2,19,1); + PINSEL_ConfigPin(2,20,1); + PINSEL_ConfigPin(2,21,1); + PINSEL_ConfigPin(2,22,1); + PINSEL_ConfigPin(2,23,1); + PINSEL_ConfigPin(2,24,1); + PINSEL_ConfigPin(2,25,1); + PINSEL_ConfigPin(2,26,1); + PINSEL_ConfigPin(2,27,1); + PINSEL_ConfigPin(2,28,1); + PINSEL_ConfigPin(2,29,1); + PINSEL_ConfigPin(2,30,1); + PINSEL_ConfigPin(2,31,1); + + PINSEL_ConfigPin(5,0,1); + PINSEL_ConfigPin(5,1,1); + + for(i = 0; i < 32; i++) + { + PINSEL_ConfigPin(3,i,1); + PINSEL_ConfigPin(4,i,1); + } } /*********************************************************************//** - * @brief Configure Little Endian/Big Endian mode for EMC - * @param[in] endia_mode Endian mode, should be: - * - EMC_LITTLE_ENDIAN_MODE: Little-endian mode - * - EMC_BIG_ENDIAN_MODE : Big-endian mode - * @return None + * @brief Configure Little Endian/Big Endian mode for EMC + * @param[in] endia_mode Endian mode, should be: + * - EMC_LITTLE_ENDIAN_MODE: Little-endian mode + * - EMC_BIG_ENDIAN_MODE : Big-endian mode + * @return None **********************************************************************/ void EMC_ConfigEndianMode(uint32_t endian_mode) { @@ -123,12 +123,12 @@ void EMC_ConfigEndianMode(uint32_t endian_mode) /****************** Group of Dynamic control functions************************/ /*********************************************************************//** - * @brief Set the value for dynamic clock enable bit - * @param[in] clock_enable clock enable mode, should be: - * - 0: Clock enable of idle devices are deasserted to - * save power - * - 1: All clock enables are driven HIGH continuously - * @return None + * @brief Set the value for dynamic clock enable bit + * @param[in] clock_enable clock enable mode, should be: + * - 0: Clock enable of idle devices are deasserted to + * save power + * - 1: All clock enables are driven HIGH continuously + * @return None **********************************************************************/ void EMC_DynCtrlClockEnable(uint32_t clock_enable) { @@ -136,13 +136,13 @@ void EMC_DynCtrlClockEnable(uint32_t clock_enable) } /*********************************************************************//** - * @brief Set the value for dynamic memory clock control: - * stops or runs continuously - * @param[in] clock_control clock control mode, should be: - * - 0: CLKOUT stops when all SDRAMs are idle and - * during self-refresh mode - * - 1: CLKOUT runs continuously - * @return None + * @brief Set the value for dynamic memory clock control: + * stops or runs continuously + * @param[in] clock_control clock control mode, should be: + * - 0: CLKOUT stops when all SDRAMs are idle and + * during self-refresh mode + * - 1: CLKOUT runs continuously + * @return None **********************************************************************/ void EMC_DynCtrlClockControl(int32_t clock_control) { @@ -151,11 +151,11 @@ void EMC_DynCtrlClockControl(int32_t clock_control) } /*********************************************************************//** - * @brief Switch the Self-refresh mode between normal and self-refresh mode - * @param[in] self_refresh_mode self refresh mode, should be: - * - 0: Normal mode - * - 1: Enter self-refresh mode - * @return None + * @brief Switch the Self-refresh mode between normal and self-refresh mode + * @param[in] self_refresh_mode self refresh mode, should be: + * - 0: Normal mode + * - 1: Enter self-refresh mode + * @return None **********************************************************************/ void EMC_DynCtrlSelfRefresh(uint32_t self_refresh_mode) { @@ -164,11 +164,11 @@ void EMC_DynCtrlSelfRefresh(uint32_t self_refresh_mode) } /*********************************************************************//** - * @brief Enable/disable CLKOUT - * @param[in] MMC_val Memory clock control mode, should be: - * - 0: CLKOUT enabled - * - 1: CLKOUT disabled - * @return None + * @brief Enable/disable CLKOUT + * @param[in] MMC_val Memory clock control mode, should be: + * - 0: CLKOUT enabled + * - 1: CLKOUT disabled + * @return None **********************************************************************/ void EMC_DynCtrlMMC(uint32_t MMC_val) { @@ -177,13 +177,13 @@ void EMC_DynCtrlMMC(uint32_t MMC_val) } /*********************************************************************//** - * @brief Issue SDRAM command - * @param[in] SDRAM_command Command mode, should be: - * - 0x00: Issue SDRAM NORMAL operation command - * - 0x01: Issue SDRAM MODE command - * - 0x02: Issue SDRAM PALL (precharge all) command - * - 0x03: Issue SRAM NOP (no operation) command - * @return None + * @brief Issue SDRAM command + * @param[in] SDRAM_command Command mode, should be: + * - 0x00: Issue SDRAM NORMAL operation command + * - 0x01: Issue SDRAM MODE command + * - 0x02: Issue SDRAM PALL (precharge all) command + * - 0x03: Issue SRAM NOP (no operation) command + * @return None **********************************************************************/ void EMC_DynCtrlSDRAMInit(uint32_t SDRAM_command) { @@ -192,11 +192,11 @@ void EMC_DynCtrlSDRAMInit(uint32_t SDRAM_command) } /*********************************************************************//** - * @brief Switch between Normal operation and deep sleep power mode - * @param[in] Power_command Low-power SDRAM deep-sleep mode, should be: - * - 0: Normal operation - * - 1: Enter deep-sleep mode - * @return None + * @brief Switch between Normal operation and deep sleep power mode + * @param[in] Power_command Low-power SDRAM deep-sleep mode, should be: + * - 0: Normal operation + * - 1: Enter deep-sleep mode + * @return None **********************************************************************/ void EMC_DynCtrlPowerDownMode(uint32_t Power_command) { @@ -205,22 +205,22 @@ void EMC_DynCtrlPowerDownMode(uint32_t Power_command) } /*********************************************************************//** - * @brief Set the value of EMC dynamic memory registers - * @param[in] par EMC register that will set value, should be: - * - EMC_DYN_MEM_REFRESH_TIMER: Dynamic Refresh register - * - EMC_DYN_MEM_READ_CONFIG: Dynamic Read Config register - * - EMC_DYN_MEM_TRP: Dynamic RP register - * - EMC_DYN_MEM_TRAS: Dynamic RAS register - * - EMC_DYN_MEM_TSREX: Dynamic SREX register - * - EMC_DYN_MEM_TAPR: Dynamic APR register - * - EMC_DYN_MEM_TDAL: Dynamic DAL register - * - EMC_DYN_MEM_TWR: Dynamic WR register - * - EMC_DYN_MEM_TRC: Dynamic RC register - * - EMC_DYN_MEM_TRFC: Dynamic RFC register - * - EMC_DYN_MEM_TXSR: Dynamic XSR register - * - EMC_DYN_MEM_TRRD: Dynamic RRD register - * - EMC_DYN_MEM_TMRD: Dynamic MRD register - * @return None + * @brief Set the value of EMC dynamic memory registers + * @param[in] par EMC register that will set value, should be: + * - EMC_DYN_MEM_REFRESH_TIMER: Dynamic Refresh register + * - EMC_DYN_MEM_READ_CONFIG: Dynamic Read Config register + * - EMC_DYN_MEM_TRP: Dynamic RP register + * - EMC_DYN_MEM_TRAS: Dynamic RAS register + * - EMC_DYN_MEM_TSREX: Dynamic SREX register + * - EMC_DYN_MEM_TAPR: Dynamic APR register + * - EMC_DYN_MEM_TDAL: Dynamic DAL register + * - EMC_DYN_MEM_TWR: Dynamic WR register + * - EMC_DYN_MEM_TRC: Dynamic RC register + * - EMC_DYN_MEM_TRFC: Dynamic RFC register + * - EMC_DYN_MEM_TXSR: Dynamic XSR register + * - EMC_DYN_MEM_TRRD: Dynamic RRD register + * - EMC_DYN_MEM_TMRD: Dynamic MRD register + * @return None **********************************************************************/ void EMC_SetDynMemoryParameter(EMC_DYN_MEM_PAR par, uint32_t val) { @@ -269,9 +269,9 @@ void EMC_SetDynMemoryParameter(EMC_DYN_MEM_PAR par, uint32_t val) } /*********************************************************************//** - * @brief Set extended wait time out for accessing static memory - * @param[in] Extended_wait_time_out timeout value that will be set - * @return None + * @brief Set extended wait time out for accessing static memory + * @param[in] Extended_wait_time_out timeout value that will be set + * @return None **********************************************************************/ void EMC_StaticExtendedWait(uint32_t Extended_wait_time_out) { @@ -279,13 +279,13 @@ void EMC_StaticExtendedWait(uint32_t Extended_wait_time_out) } /*********************************************************************//** - * @brief Configure the memory device - * @param[in] index index number, should be from 0 to 3 - * @param[in] mem_dev Memory device, should be: - * - 0x00: SDRAM - * - 0x01: Low-power SDRAM - * - 0x02: Micron Syncflash - * @return None + * @brief Configure the memory device + * @param[in] index index number, should be from 0 to 3 + * @param[in] mem_dev Memory device, should be: + * - 0x00: SDRAM + * - 0x01: Low-power SDRAM + * - 0x02: Micron Syncflash + * @return None **********************************************************************/ void EMC_DynMemConfigMD(uint32_t index , uint32_t mem_dev) { @@ -294,24 +294,24 @@ void EMC_DynMemConfigMD(uint32_t index , uint32_t mem_dev) { case 0: LPC_EMC->DynamicConfig0 = (LPC_EMC->DynamicConfig0 & mask) | mem_dev; - break; + break; case 1: LPC_EMC->DynamicConfig1 = (LPC_EMC->DynamicConfig1 & mask) | mem_dev; - break; + break; case 2: LPC_EMC->DynamicConfig2 =(LPC_EMC->DynamicConfig2 & mask) | mem_dev; - break; + break; case 3: LPC_EMC->DynamicConfig3 = (LPC_EMC->DynamicConfig3 & mask) | mem_dev; - break; + break; } } /*********************************************************************//** - * @brief Map the address for the memory device - * @param[in] index index number, should be from 0 to 3 - * @param[in] add_mapped address where the memory will be mapped - * @return None + * @brief Map the address for the memory device + * @param[in] index index number, should be from 0 to 3 + * @param[in] add_mapped address where the memory will be mapped + * @return None **********************************************************************/ void EMC_DynMemConfigAM(uint32_t index , uint32_t add_mapped) { @@ -321,26 +321,26 @@ void EMC_DynMemConfigAM(uint32_t index , uint32_t add_mapped) { case 0: LPC_EMC->DynamicConfig0 = ( LPC_EMC->DynamicConfig0 & mask) | add_mapped; - break; + break; case 1: LPC_EMC->DynamicConfig1 = (LPC_EMC->DynamicConfig1 & mask) | add_mapped; - break; + break; case 2: LPC_EMC->DynamicConfig2 = (LPC_EMC->DynamicConfig2 & mask) | add_mapped; - break; + break; case 3: LPC_EMC->DynamicConfig3 = (LPC_EMC->DynamicConfig3 & mask) | add_mapped; - break; + break; } } /*********************************************************************//** - * @brief Enable/disable the buffer - * @param[in] index index number, should be from 0 to 3 - * @param[in] buff_control buffer control mode, should be: - * - ENABLE - * - DISABLE - * @return None + * @brief Enable/disable the buffer + * @param[in] index index number, should be from 0 to 3 + * @param[in] buff_control buffer control mode, should be: + * - ENABLE + * - DISABLE + * @return None **********************************************************************/ void EMC_DynMemConfigB(uint32_t index , uint32_t buff_control) { @@ -349,27 +349,27 @@ void EMC_DynMemConfigB(uint32_t index , uint32_t buff_control) { case 0: LPC_EMC->DynamicConfig0 = (LPC_EMC->DynamicConfig0 & mask) | buff_control; - break; + break; case 1: LPC_EMC->DynamicConfig1 = ( LPC_EMC->DynamicConfig1 & mask) | buff_control; - break; + break; case 2: LPC_EMC->DynamicConfig2 = (LPC_EMC->DynamicConfig2 & mask)| buff_control; - break; + break; case 3: LPC_EMC->DynamicConfig3 = (LPC_EMC->DynamicConfig3 & mask) | buff_control; - break; + break; } } /*********************************************************************//** - * @brief Configure write permission: protect or not - * @param[in] index index number, should be from 0 to 3 - * @param[in] permission permission mode, should be: - * - ENABLE: protect - * - DISABLE: not protect - * @return None + * @brief Configure write permission: protect or not + * @param[in] index index number, should be from 0 to 3 + * @param[in] permission permission mode, should be: + * - ENABLE: protect + * - DISABLE: not protect + * @return None **********************************************************************/ void EMC_DynMemConfigP(uint32_t index , uint32_t permission) { @@ -378,24 +378,24 @@ void EMC_DynMemConfigP(uint32_t index , uint32_t permission) { case 0: LPC_EMC->DynamicConfig0 = (LPC_EMC->DynamicConfig0 & mask) | permission; - break; + break; case 1: LPC_EMC->DynamicConfig1 = (LPC_EMC->DynamicConfig1 & mask) | permission; - break; + break; case 2: LPC_EMC->DynamicConfig2 = ( LPC_EMC->DynamicConfig2 & mask) | permission; - break; + break; case 3: LPC_EMC->DynamicConfig3 = (LPC_EMC->DynamicConfig3 & mask) | permission; - break; + break; } } /*********************************************************************//** - * @brief Set value for RAS latency - * @param[in] index index number, should be from 0 to 3 - * @param[in] ras_val RAS value should be in range: 0..3 - * @return None + * @brief Set value for RAS latency + * @param[in] index index number, should be from 0 to 3 + * @param[in] ras_val RAS value should be in range: 0..3 + * @return None **********************************************************************/ void EMC_DynMemRAS(uint32_t index , uint32_t ras_val) { @@ -405,24 +405,24 @@ void EMC_DynMemRAS(uint32_t index , uint32_t ras_val) { case 0: LPC_EMC->DynamicRasCas0 = (LPC_EMC->DynamicRasCas0 & mask) | ras_val; - break; + break; case 1: LPC_EMC->DynamicRasCas1 = (LPC_EMC->DynamicRasCas1 & mask) | ras_val; - break; + break; case 2: LPC_EMC->DynamicRasCas2 = (LPC_EMC->DynamicRasCas2 & mask) | ras_val; - break; + break; case 3: LPC_EMC->DynamicRasCas3 = (LPC_EMC->DynamicRasCas3 & mask) | ras_val; - break; + break; } } /*********************************************************************//** - * @brief Set value for CAS latency - * @param[in] index index number, should be from 0 to 3 - * @param[in] ras_val CAS value should be in range: 0..3 - * @return None + * @brief Set value for CAS latency + * @param[in] index index number, should be from 0 to 3 + * @param[in] ras_val CAS value should be in range: 0..3 + * @return None **********************************************************************/ void EMC_DynMemCAS(uint32_t index , uint32_t cas_val) { @@ -431,26 +431,26 @@ void EMC_DynMemCAS(uint32_t index , uint32_t cas_val) { case 0: LPC_EMC->DynamicRasCas0 = (LPC_EMC->DynamicRasCas0 & mask) | cas_val; - break; + break; case 1: LPC_EMC->DynamicRasCas1 = (LPC_EMC->DynamicRasCas1 & mask) | cas_val; - break; + break; case 2: LPC_EMC->DynamicRasCas2 = (LPC_EMC->DynamicRasCas2 & mask )| cas_val; - break; + break; case 3: LPC_EMC->DynamicRasCas3 = ( LPC_EMC->DynamicRasCas3 & mask) | cas_val; - break; + break; } } /*********************************************************************//** - * @brief Configure the memory width - * @param[in] index index number, should be from 0 to 3 - * @param[in] mem_width memory width, should be: - * - 0x00: 8-bits - * - 0x01: 16-bits - * - 0x02: 32-bits - * @return None + * @brief Configure the memory width + * @param[in] index index number, should be from 0 to 3 + * @param[in] mem_width memory width, should be: + * - 0x00: 8-bits + * - 0x01: 16-bits + * - 0x02: 32-bits + * @return None **********************************************************************/ void EMC_StaMemConfigMW(uint32_t index , uint32_t mem_width) { @@ -459,25 +459,25 @@ void EMC_StaMemConfigMW(uint32_t index , uint32_t mem_width) { case 0: LPC_EMC->StaticConfig0 = (LPC_EMC->StaticConfig0 & mask) | mem_width; - break; + break; case 1: LPC_EMC->StaticConfig1 = (LPC_EMC->StaticConfig1 & mask) | mem_width; - break; + break; case 2: LPC_EMC->StaticConfig2 = (LPC_EMC->StaticConfig2 & mask)| mem_width; - break; + break; case 3: LPC_EMC->StaticConfig3 = (LPC_EMC->StaticConfig3 & mask) | mem_width; - break; + break; } } /*********************************************************************//** - * @brief Configure the page mode - * @param[in] index index number, should be from 0 to 3 - * @param[in] page_mode page mode, should be: - * - 0: disable - * - 1: asynchronous page mode enable - * @return None + * @brief Configure the page mode + * @param[in] index index number, should be from 0 to 3 + * @param[in] page_mode page mode, should be: + * - 0: disable + * - 1: asynchronous page mode enable + * @return None **********************************************************************/ void EMC_StaMemConfigPM(uint32_t index , uint32_t page_mode) { @@ -486,25 +486,25 @@ void EMC_StaMemConfigPM(uint32_t index , uint32_t page_mode) { case 0: LPC_EMC->StaticConfig0 = (LPC_EMC->StaticConfig0 & mask) | page_mode; - break; + break; case 1: LPC_EMC->StaticConfig1 = (LPC_EMC->StaticConfig1 & mask) | page_mode; - break; + break; case 2: LPC_EMC->StaticConfig2 = (LPC_EMC->StaticConfig2 & mask)| page_mode; - break; + break; case 3: LPC_EMC->StaticConfig3 = (LPC_EMC->StaticConfig3 & mask)| page_mode; - break; + break; } } /*********************************************************************//** - * @brief Configure the chip select polarity - * @param[in] index index number, should be from 0 to 3 - * @param[in] pagepol_val_mode page mode, should be: - * - 0: Active LOW ship select - * - 1: Active HIGH chip select - * @return None + * @brief Configure the chip select polarity + * @param[in] index index number, should be from 0 to 3 + * @param[in] pagepol_val_mode page mode, should be: + * - 0: Active LOW ship select + * - 1: Active HIGH chip select + * @return None **********************************************************************/ void EMC_StaMemConfigPC(uint32_t index , uint32_t pol_val) { @@ -513,26 +513,26 @@ void EMC_StaMemConfigPC(uint32_t index , uint32_t pol_val) { case 0: LPC_EMC->StaticConfig0 = (LPC_EMC->StaticConfig0 & mask) | pol_val; - break; + break; case 1: LPC_EMC->StaticConfig1 = (LPC_EMC->StaticConfig1 & mask)| pol_val; - break; + break; case 2: LPC_EMC->StaticConfig2 = (LPC_EMC->StaticConfig2 & mask) | pol_val; - break; + break; case 3: LPC_EMC->StaticConfig3 = (LPC_EMC->StaticConfig3 & mask) | pol_val; - break; + break; } } /*********************************************************************//** - * @brief Configure the byte lane state - * @param[in] index index number, should be from 0 to 3 - * @param[in] pb_val Byte lane state, should be: - * - 0: For reads all bits in BLSn[3:0] are HIGH. - * - 1: For reads all bits in BLSn[3:0] are LOW. - * @return None + * @brief Configure the byte lane state + * @param[in] index index number, should be from 0 to 3 + * @param[in] pb_val Byte lane state, should be: + * - 0: For reads all bits in BLSn[3:0] are HIGH. + * - 1: For reads all bits in BLSn[3:0] are LOW. + * @return None **********************************************************************/ void EMC_StaMemConfigPB(uint32_t index , uint32_t pb_val) { @@ -541,26 +541,26 @@ void EMC_StaMemConfigPB(uint32_t index , uint32_t pb_val) { case 0: LPC_EMC->StaticConfig0 = (LPC_EMC->StaticConfig0 & mask)| pb_val; - break; + break; case 1: LPC_EMC->StaticConfig1 = (LPC_EMC->StaticConfig1 & mask)| pb_val; - break; + break; case 2: LPC_EMC->StaticConfig2 =( LPC_EMC->StaticConfig2 & mask)| pb_val; - break; + break; case 3: LPC_EMC->StaticConfig3 = (LPC_EMC->StaticConfig3 & mask)| pb_val; - break; + break; } } /*********************************************************************//** - * @brief Configure the extended wait value - * @param[in] index index number, should be from 0 to 3 - * @param[in] ex_wait Extended wait mode, should be: - * - 0: Extended wait disabled. - * - 1: Extended wait enabled. - * @return None + * @brief Configure the extended wait value + * @param[in] index index number, should be from 0 to 3 + * @param[in] ex_wait Extended wait mode, should be: + * - 0: Extended wait disabled. + * - 1: Extended wait enabled. + * @return None **********************************************************************/ void EMC_StaMemConfigEW(uint32_t index , uint32_t ex_wait) { @@ -569,26 +569,26 @@ void EMC_StaMemConfigEW(uint32_t index , uint32_t ex_wait) { case 0: LPC_EMC->StaticConfig0 = (LPC_EMC->StaticConfig0 & mask) | ex_wait; - break; + break; case 1: LPC_EMC->StaticConfig1 = (LPC_EMC->StaticConfig1 & mask) | ex_wait; - break; + break; case 2: LPC_EMC->StaticConfig2 = (LPC_EMC->StaticConfig2 & mask) | ex_wait; - break; + break; case 3: LPC_EMC->StaticConfig3 =( LPC_EMC->StaticConfig3 & mask) | ex_wait; - break; + break; } } /*********************************************************************//** - * @brief Configure the buffer enable value - * @param[in] index index number, should be from 0 to 3 - * @param[in] buf_val Buffer mode, should be: - * - 0: Buffer disabled. - * - 1: Buffer enabled. - * @return None + * @brief Configure the buffer enable value + * @param[in] index index number, should be from 0 to 3 + * @param[in] buf_val Buffer mode, should be: + * - 0: Buffer disabled. + * - 1: Buffer enabled. + * @return None **********************************************************************/ void EMC_StaMemConfigB(uint32_t index , uint32_t buf_val) { @@ -597,26 +597,26 @@ void EMC_StaMemConfigB(uint32_t index , uint32_t buf_val) { case 0: LPC_EMC->StaticConfig0 = (LPC_EMC->StaticConfig0 & mask) | buf_val; - break; + break; case 1: LPC_EMC->StaticConfig1 = (LPC_EMC->StaticConfig1 & mask) | buf_val; - break; + break; case 2: LPC_EMC->StaticConfig2 = (LPC_EMC->StaticConfig2 & mask) | buf_val; - break; + break; case 3: LPC_EMC->StaticConfig3 = (LPC_EMC->StaticConfig3 & mask) | buf_val; - break; + break; } } /*********************************************************************//** - * @brief Configure the write permission - * @param[in] index index number, should be from 0 to 3 - * @param[in] per_val Permission mode, should be: - * - 0: Write not protected. - * - 1: Write protected. - * @return None + * @brief Configure the write permission + * @param[in] index index number, should be from 0 to 3 + * @param[in] per_val Permission mode, should be: + * - 0: Write not protected. + * - 1: Write protected. + * @return None **********************************************************************/ void EMC_StaMemConfigpP(uint32_t index , uint32_t per_val) { @@ -625,36 +625,36 @@ void EMC_StaMemConfigpP(uint32_t index , uint32_t per_val) { case 0: LPC_EMC->StaticConfig0 = (LPC_EMC->StaticConfig0 & mask) | per_val; - break; + break; case 1: LPC_EMC->StaticConfig1 = (LPC_EMC->StaticConfig1 & mask) | per_val; - break; + break; case 2: LPC_EMC->StaticConfig2 = (LPC_EMC->StaticConfig2 & mask) | per_val; - break; + break; case 3: LPC_EMC->StaticConfig3 = (LPC_EMC->StaticConfig3 & mask) | per_val; - break; + break; } } /*********************************************************************//** - * @brief Set the value of LPC_EMC static memory registers - * @param[in] index index number, should be from 0 to 3 - * @param[in] EMC_STA_MEM_PAR Static register, should be: - * - EMC_STA_MEM_WAITWEN: StaticWaitWen0 register - * - EMC_STA_MEM_WAITOEN: StaticWaitOen0 register - * - EMC_STA_MEM_WAITRD: StaticWaitRd0 register - * - EMC_STA_MEM_WAITPAGE: StaticWaitPage0 register - * - EMC_STA_MEM_WAITWR: StaticWaitWr0 register - * - EMC_STA_MEM_WAITTURN: StaticWaitTurn0 register - * @return None + * @brief Set the value of LPC_EMC static memory registers + * @param[in] index index number, should be from 0 to 3 + * @param[in] EMC_STA_MEM_PAR Static register, should be: + * - EMC_STA_MEM_WAITWEN: StaticWaitWen0 register + * - EMC_STA_MEM_WAITOEN: StaticWaitOen0 register + * - EMC_STA_MEM_WAITRD: StaticWaitRd0 register + * - EMC_STA_MEM_WAITPAGE: StaticWaitPage0 register + * - EMC_STA_MEM_WAITWR: StaticWaitWr0 register + * - EMC_STA_MEM_WAITTURN: StaticWaitTurn0 register + * @return None **********************************************************************/ void EMC_SetStaMemoryParameter(uint32_t index ,EMC_STA_MEM_PAR par, uint32_t val) { switch (index) { - case 0: + case 0: switch ( par) { case EMC_STA_MEM_WAITWEN: @@ -676,8 +676,8 @@ void EMC_SetStaMemoryParameter(uint32_t index ,EMC_STA_MEM_PAR par, uint32_t val LPC_EMC->StaticWaitTurn0 = val; break; } - break; - case 1: + break; + case 1: switch ( par) { case EMC_STA_MEM_WAITWEN: @@ -699,8 +699,8 @@ void EMC_SetStaMemoryParameter(uint32_t index ,EMC_STA_MEM_PAR par, uint32_t val LPC_EMC->StaticWaitTurn1 = val; break; } - break; - case 2: + break; + case 2: switch ( par) { case EMC_STA_MEM_WAITWEN: @@ -722,8 +722,8 @@ void EMC_SetStaMemoryParameter(uint32_t index ,EMC_STA_MEM_PAR par, uint32_t val LPC_EMC->StaticWaitTurn2 = val; break; } - break; - case 3: + break; + case 3: switch ( par) { case EMC_STA_MEM_WAITWEN: @@ -745,7 +745,7 @@ void EMC_SetStaMemoryParameter(uint32_t index ,EMC_STA_MEM_PAR par, uint32_t val LPC_EMC->StaticWaitTurn3 = val; break; } - break; + break; } } diff --git a/bsp/lpc178x/drivers/lpc177x_8x_emc.h b/bsp/lpc178x/drivers/lpc177x_8x_emc.h index 41d9cbfcc1..497521edb8 100644 --- a/bsp/lpc178x/drivers/lpc177x_8x_emc.h +++ b/bsp/lpc178x/drivers/lpc177x_8x_emc.h @@ -1,13 +1,13 @@ /********************************************************************** -* $Id$ lpc177x_8x_emc.h 2011-06-02 +* $Id$ lpc177x_8x_emc.h 2011-06-02 *//** -* @file lpc177x_8x_emc.h -* @brief Contains all macro definitions and function prototypes -* support for EMC firmware library on LPC177x_8x -* @version 1.0 -* @date 02. June. 2011 -* @author NXP MCU SW Application Team -* +* @file lpc177x_8x_emc.h +* @brief Contains all macro definitions and function prototypes +* support for EMC firmware library on LPC177x_8x +* @version 1.0 +* @date 02. June. 2011 +* @author NXP MCU SW Application Team +* * Copyright(C) 2011, NXP Semiconductor * All rights reserved. * @@ -25,7 +25,7 @@ **********************************************************************/ /* Peripheral group ----------------------------------------------------------- */ -/** @defgroup EMC EMC (External Memory Controller) +/** @defgroup EMC EMC (External Memory Controller) * @ingroup LPC177x_8xCMSIS_FwLib_Drivers * @{ */ @@ -45,233 +45,233 @@ * EMC Control Register (EMCControl) **********************************************************************/ /* Control register mask */ -#define EMC_Control_MASK ((uint32_t )0x07) +#define EMC_Control_MASK ((uint32_t )0x07) /* Control register EMC: Enable control. */ -#define EMC_Control_E ((uint32_t )(1<<0)) +#define EMC_Control_E ((uint32_t )(1<<0)) /* Control register EMC: Address mirror control. */ -#define EMC_Control_M ((uint32_t )(1<<1)) +#define EMC_Control_M ((uint32_t )(1<<1)) /* Control register EMC: Low-power mode control. */ -#define EMC_Control_L ((uint32_t )(1<<2)) +#define EMC_Control_L ((uint32_t )(1<<2)) /*********************************************************************** * EMC Status Register (EMCStatus) **********************************************************************/ /* Status register mask */ -#define EMC_Status_MASK ((uint32_t )0x07) +#define EMC_Status_MASK ((uint32_t )0x07) /* Status register EMC: Busy. */ -#define EMC_Status_B ((uint32_t )(1<<0)) +#define EMC_Status_B ((uint32_t )(1<<0)) /* Status register EMC: Write buffer status. */ -#define EMC_Status_S ((uint32_t )(1<<1)) +#define EMC_Status_S ((uint32_t )(1<<1)) /* Status register EMC: Self-refresh acknowledge.. */ -#define EMC_Status_SA ((uint32_t )(1<<2)) +#define EMC_Status_SA ((uint32_t )(1<<2)) /*********************************************************************** * EMC Configuration register (EMCConfig) **********************************************************************/ /* EMC Configuration register : Enable control. */ -#define EMC_Config_Endian_Mode ((uint32_t )(1<<0)) +#define EMC_Config_Endian_Mode ((uint32_t )(1<<0)) /* EMC Configuration register: CCLK. */ -#define EMC_Config_CCLK ((uinr32_t)(1<<8)) +#define EMC_Config_CCLK ((uinr32_t)(1<<8)) /* EMC Configuration register mask */ -#define EMC_Config_MASK ((uint32_t)(0x101)) +#define EMC_Config_MASK ((uint32_t)(0x101)) /*********************************************************************** * Dynamic Memory Control register (EMCDynamicControl) **********************************************************************/ /* Dynamic Memory Control register EMC: Dynamic memory clock enable. */ -#define EMC_DynamicControl_CE ((uint32_t )(1<<0)) +#define EMC_DynamicControl_CE ((uint32_t )(1<<0)) /* Dynamic Memory Control register EMC: Dynamic memory clock control */ -#define EMC_DynamicControl_CS ((uint32_t )(1<<1)) +#define EMC_DynamicControl_CS ((uint32_t )(1<<1)) /* Dynamic Memory Control register EMC: Self-refresh request, EMCSREFREQ*/ -#define EMC_DynamicControl_SR ((uint32_t )(1<<2)) +#define EMC_DynamicControl_SR ((uint32_t )(1<<2)) /* Dynamic Memory Control register EMC: Memory clock control (MMC)*/ -#define EMC_DynamicControl_MMC ((uint32_t )(1<<5)) +#define EMC_DynamicControl_MMC ((uint32_t )(1<<5)) /* Dynamic Memory Control register EMC: SDRAM initialization*/ -#define EMC_DynamicControl_I(n) ((uint32_t )(n<<7)) +#define EMC_DynamicControl_I(n) ((uint32_t )(n<<7)) /* Dynamic Memory Control register EMC: Low-power SDRAM deep-sleep mode (DP)*/ -#define EMC_DynamicControl_DP ((uint32_t ) (1<<13)) +#define EMC_DynamicControl_DP ((uint32_t ) (1<<13)) /*********************************************************************** * Dynamic Memory Refresh Timer register (EMCDynamicRefresh) **********************************************************************/ /* Dynamic Memory Refresh Timer register EMC: Refresh timer (REFRESH) */ -#define EMC_DynamicRefresh_REFRESH(n) ((uint32_t ) (n & 0x3ff)) +#define EMC_DynamicRefresh_REFRESH(n) ((uint32_t ) (n & 0x3ff)) /*********************************************************************** * Dynamic Memory Read Configuration register (EMCDynamicReadConfig) **********************************************************************/ /* EMCDynamicReadConfig register EMC:Read data strategy (RD) */ -#define EMC_DynamicReadConfig_RD(n) ((uint32_t )(n & 0x03)) +#define EMC_DynamicReadConfig_RD(n) ((uint32_t )(n & 0x03)) /*********************************************************************** * Dynamic Memory Percentage Command Period register (EMCDynamictRP) **********************************************************************/ /* EMCDynamictRP register EMC: Precharge command period (tRP). */ -#define EMC_DynamictRP_tRP(n) ((uint32_t )(n & 0x0f)) +#define EMC_DynamictRP_tRP(n) ((uint32_t )(n & 0x0f)) /*********************************************************************** * Dynamic Memory Active to Precharge Command Period register (EMCDynamictRAS) **********************************************************************/ /* EMCDynamictRAS register EMC: Active to precharge command period (tRAS) */ -#define EMC_DynamictRP_tRAS(n) ((uint32_t )(n & 0x0f)) +#define EMC_DynamictRP_tRAS(n) ((uint32_t )(n & 0x0f)) /*********************************************************************** * Dynamic Memory Last Data Out to Active Time register (EMCDynamictAPR) **********************************************************************/ /* EMCDynamictAPR register EMC: Last-data-out to active command time (tAPR) */ -#define EMC_DynamictAPR_tAPR(n) ((uint32_t )(n & 0x0f)) +#define EMC_DynamictAPR_tAPR(n) ((uint32_t )(n & 0x0f)) /*********************************************************************** * Dynamic Memory Data-in to Active Command Time register (EMCDynamictDAL) **********************************************************************/ /* EMCDynamictDAL register EMC: Data-in to active command (tDAL)*/ -#define EMC_DynamictDAL_tDAL(n) ((uint32_t )(n & 0x0f)) +#define EMC_DynamictDAL_tDAL(n) ((uint32_t )(n & 0x0f)) /*********************************************************************** * Dynamic Memory Write Recovery Time register (EMCDynamictWR) **********************************************************************/ /* EMCDynamictWR register EMC: Write recovery time (tWR)*/ -#define EMC_DynamictWR_tWR(n) (uint32_t )(n & 0x0f) +#define EMC_DynamictWR_tWR(n) (uint32_t )(n & 0x0f) /*********************************************************************** * Dynamic Memory Active to Active Command Period register (EMCDynamictRC) **********************************************************************/ /* EMCDynamictRC register EMC: Active to active command period (tRC)*/ -#define EMC_DynamictRC_tRC(n) (uint32_t )(n & 0x1f) +#define EMC_DynamictRC_tRC(n) (uint32_t )(n & 0x1f) /*********************************************************************** * Dynamic Memory Auto-refresh Period register (EMCDynamictRFC) **********************************************************************/ /* EMCDynamictRFC register EMC: Auto-refresh period and auto-refresh to active command period (tRFC)*/ -#define EMC_DynamictRFC_tRFC(n) ((uint32_t )(n & 0x1f)) +#define EMC_DynamictRFC_tRFC(n) ((uint32_t )(n & 0x1f)) /*********************************************************************** * Dynamic Memory Exit Self-refresh register (EMCDynamictXSR) **********************************************************************/ /* EMCDynamictXSR register EMC: Exit self-refresh to active command time (tXSR)*/ -#define EMC_DynamictXSR_tXSR(n) ((uint32_t )(n & 0x1f)) +#define EMC_DynamictXSR_tXSR(n) ((uint32_t )(n & 0x1f)) /*********************************************************************** * Dynamic Memory Active Bank A to Active Bank B Time register (EMCDynamictRRD) **********************************************************************/ /* EMCDynamictRRD register EMC: Active bank A to active bank B latency (tRRD )*/ -#define EMC_DynamictRRD_tRRD(n) ((uint32_t )(n & 0x0f)) +#define EMC_DynamictRRD_tRRD(n) ((uint32_t )(n & 0x0f)) /*********************************************************************** Dynamic Memory Load Mode register to Active Command Time (EMCDynamictMRD) **********************************************************************/ /* EMCDynamictMRD register EMC: Load mode register to active command time (tMRD)*/ -#define EMC_DynamictMRD_tMRD(n) ((uint32_t )(n & 0x1f)) +#define EMC_DynamictMRD_tMRD(n) ((uint32_t )(n & 0x1f)) /*********************************************************************** * Static Memory Extended Wait Register (EMCStaticExtendedWait) **********************************************************************/ /* StaticExtendedWait register EMC: External wait time out. */ -#define EMC_StaticExtendedWait_EXTENDEDWAIT(n) ((uint32_t )(n & 0x3ff)) +#define EMC_StaticExtendedWait_EXTENDEDWAIT(n) ((uint32_t )(n & 0x3ff)) /*********************************************************************** * Dynamic Memory Configuration registers (EMCDynamicConfig0-3) **********************************************************************/ /* DynamicConfig register EMC: Memory device (MD). */ -#define EMC_DynamicConfig_MD(n) ((uint32_t )(n << 3)) +#define EMC_DynamicConfig_MD(n) ((uint32_t )(n << 3)) /* DynamicConfig register EMC: Address mapping (AM) */ -#define EMC_DynamicConfig_AM1(n) ((uint32_t )(n << 7)) +#define EMC_DynamicConfig_AM1(n) ((uint32_t )(n << 7)) /* DynamicConfig register EMC: Address mapping (AM) */ -#define EMC_DynamicConfig_AM2(n) ((uint32_t )(1 << 14)) +#define EMC_DynamicConfig_AM2(n) ((uint32_t )(1 << 14)) /* DynamicConfig register EMC: Buffer enable */ -#define EMC_DynamicConfig_B ((uint32_t )(1 << 19)) +#define EMC_DynamicConfig_B ((uint32_t )(1 << 19)) /* DynamicConfig register EMC: Write protect (P) */ -#define EMC_DynamicConfig_P ((uint32_t )(1 << 20)) +#define EMC_DynamicConfig_P ((uint32_t )(1 << 20)) /*********************************************************************** * Dynamic Memory RAS & CAS Delay registers (EMCDynamicRASCAS0-3) **********************************************************************/ /* DynamicRASCAS register EMC: RAS latency (active to read/write delay) (RAS). */ -#define EMC_DynamicConfig_RAS(n) ((uint32_t )(n & 0x03)) +#define EMC_DynamicConfig_RAS(n) ((uint32_t )(n & 0x03)) /* DynamicRASCAS register EMC: CAS latency (CAS)*/ -#define EMC_DynamicConfig_CAS(n) ((uint32_t )(n << 8)) +#define EMC_DynamicConfig_CAS(n) ((uint32_t )(n << 8)) /*********************************************************************** * Static Memory Configuration registers (EMCStaticConfig0-3) **********************************************************************/ /* StaticConfig register EMC: Memory width (MW). */ -#define EMC_StaticConfig_MW(n) ((uint32_t )(n & 0x03)) +#define EMC_StaticConfig_MW(n) ((uint32_t )(n & 0x03)) /* StaticConfig register EMC: Memory width 8bit . */ -#define EMC_StaticConfig_MW_8BITS (EMC_StaticConfig_MW(0)) +#define EMC_StaticConfig_MW_8BITS (EMC_StaticConfig_MW(0)) /* StaticConfig register EMC: Memory width 16bit . */ -#define EMC_StaticConfig_MW_16BITS (EMC_StaticConfig_MW(1)) +#define EMC_StaticConfig_MW_16BITS (EMC_StaticConfig_MW(1)) /* StaticConfig register EMC: Memory width 32bit . */ -#define EMC_StaticConfig_MW_32BITS (EMC_StaticConfig_MW(2)) +#define EMC_StaticConfig_MW_32BITS (EMC_StaticConfig_MW(2)) /* StaticConfig register EMC: Page mode (PM) */ -#define EMC_StaticConfig_PM ((uint32_t )(1 << 3)) +#define EMC_StaticConfig_PM ((uint32_t )(1 << 3)) /* StaticConfig register EMC: Chip select polarity (PC) */ -#define EMC_StaticConfig_PC ((uint32_t )(1 << 6)) +#define EMC_StaticConfig_PC ((uint32_t )(1 << 6)) /* StaticConfig register EMC: Byte lane state (PB) */ -#define EMC_StaticConfig_PB ((uint32_t )(1 << 7)) +#define EMC_StaticConfig_PB ((uint32_t )(1 << 7)) /* StaticConfig register EMC: Extended wait (EW) */ -#define EMC_StaticConfig_EW ((uint32_t )(1 << 8)) +#define EMC_StaticConfig_EW ((uint32_t )(1 << 8)) /* StaticConfig register EMC: Buffer enable (B) */ -#define EMC_StaticConfig_B ((uint32_t )(1 << 19)) +#define EMC_StaticConfig_B ((uint32_t )(1 << 19)) /* StaticConfig register EMC: Write protect (P) */ -#define EMC_StaticConfig_P ((uint32_t )(1 << 20)) +#define EMC_StaticConfig_P ((uint32_t )(1 << 20)) /*********************************************************************** * Static Memory Write Enable Delay registers (EMCStaticWaitWen0-3) **********************************************************************/ /* StaticWaitWen register EMC: Wait write enable (WAITWEN). */ -#define EMC_StaticWaitWen_WAITWEN(n) ((uint32_t )(n & 0x0f)) +#define EMC_StaticWaitWen_WAITWEN(n) ((uint32_t )(n & 0x0f)) /*********************************************************************** * Static Memory Output Enable Delay registers (EMCStaticWaitOen0-3) **********************************************************************/ /* StaticWaitOen register EMC: Wait output enable (WAITOEN). */ -#define EMC_StaticWaitOen_WAITOEN(n) ((uint32_t )(n & 0x0f)) +#define EMC_StaticWaitOen_WAITOEN(n) ((uint32_t )(n & 0x0f)) /*********************************************************************** * Static Memory Read Delay registers (EMCStaticWaitRd0-3) **********************************************************************/ /* StaticWaitRd register EMC: Non-page mode read wait states or asynchronous page mode read first access wait state (WAITRD) */ -#define EMC_StaticWaitRd_WAITRD(n) ((uint32_t )(n & 0x1f)) +#define EMC_StaticWaitRd_WAITRD(n) ((uint32_t )(n & 0x1f)) /*********************************************************************** * Static Memory Page Mode Read Delay registers (EMCStaticwaitPage0-3) **********************************************************************/ /* StaticwaitPage register EMC: Asynchronous page mode read after the first read wait states (WAITPAGE). */ -#define EMC_StaticwaitPage_WAITPAGE(n) ((uint32_t )(n & 0x1f)) +#define EMC_StaticwaitPage_WAITPAGE(n) ((uint32_t )(n & 0x1f)) /*********************************************************************** * Static Memory Write Delay registers (EMCStaticWaitwr0-3) **********************************************************************/ /* StaticWaitwr register EMC: Write wait states (WAITWR). */ -#define EMC_StaticWaitwr_WAITWR(n) ((uint32_t )(n & 0x1f)) +#define EMC_StaticWaitwr_WAITWR(n) ((uint32_t )(n & 0x1f)) /*********************************************************************** * Static Memory Turn Round Delay registers (EMCStaticWaitTurn0-3) **********************************************************************/ /* StaticWaitTurn register EMC: Bus turnaround cycles (WAITTURN). */ -#define EMC_StaticWaitTurn_WAITTURN(n) ((uint32_t )(n & 0x0f)) +#define EMC_StaticWaitTurn_WAITTURN(n) ((uint32_t )(n & 0x0f)) /*********************************************************************** * Delay Control register (EMCDLYCTL) **********************************************************************/ -#define EMC_DLYCTL_CMDDLY(n) ((uint32_t)(n&0x1F)) -#define EMC_DLYCTL_FBCLKDLY(n) ((uint32_t)((n&0x1F)<<8)) -#define EMC_DLYCTL_CLKOUT0DLY(n) ((uint32_t)((n&0x1F)<<16)) -#define EMC_DLYCTL_CLKOUT1DLY(n) ((uint32_t)((n&0x1F)<<24)) +#define EMC_DLYCTL_CMDDLY(n) ((uint32_t)(n&0x1F)) +#define EMC_DLYCTL_FBCLKDLY(n) ((uint32_t)((n&0x1F)<<8)) +#define EMC_DLYCTL_CLKOUT0DLY(n) ((uint32_t)((n&0x1F)<<16)) +#define EMC_DLYCTL_CLKOUT1DLY(n) ((uint32_t)((n&0x1F)<<24)) /*********************************************************************** * EMC Calibration register (EMCCAL) **********************************************************************/ -#define EMC_CAL_CALVALUE(n) ((uint32_t)(n&0xFF)) -#define EMC_CAL_START ((uint32_t)(1<<14)) -#define EMC_CAL_DONE ((uint32_t)(1<<15)) +#define EMC_CAL_CALVALUE(n) ((uint32_t)(n&0xFF)) +#define EMC_CAL_START ((uint32_t)(1<<14)) +#define EMC_CAL_DONE ((uint32_t)(1<<15)) -#define EMC_LITTLE_ENDIAN_MODE ((uint32_t)(0)) -#define EMC_BIG_ENDIAN_MODE ((uint32_t)(1)) +#define EMC_LITTLE_ENDIAN_MODE ((uint32_t)(0)) +#define EMC_BIG_ENDIAN_MODE ((uint32_t)(1)) /** * @} diff --git a/bsp/lpc178x/drivers/lpc177x_8x_pinsel.c b/bsp/lpc178x/drivers/lpc177x_8x_pinsel.c index d767af1180..062224decf 100644 --- a/bsp/lpc178x/drivers/lpc177x_8x_pinsel.c +++ b/bsp/lpc178x/drivers/lpc177x_8x_pinsel.c @@ -1,13 +1,13 @@ /********************************************************************** -* $Id$ lpc177x_8x_pinsel.c 2011-06-02 +* $Id$ lpc177x_8x_pinsel.c 2011-06-02 *//** -* @file lpc177x_8x_pinsel.c -* @brief Contains all functions support for Pin-connection block -* firmware library on LPC177x_8x -* @version 1.0 -* @date 02. June. 2011 -* @author NXP MCU SW Application Team -* +* @file lpc177x_8x_pinsel.c +* @brief Contains all functions support for Pin-connection block +* firmware library on LPC177x_8x +* @version 1.0 +* @date 02. June. 2011 +* @author NXP MCU SW Application Team +* * Copyright(C) 2011, NXP Semiconductor * All rights reserved. * @@ -32,39 +32,39 @@ /* Includes ------------------------------------------------------------------- */ #include "lpc177x_8x_pinsel.h" -#define PINSEL_I2C_MODE_POS (8) -#define PINSEL_I2C_MODE_NUMBITS (2) -#define PINSEL_I2C_MODE_BITMASK (0x03) +#define PINSEL_I2C_MODE_POS (8) +#define PINSEL_I2C_MODE_NUMBITS (2) +#define PINSEL_I2C_MODE_BITMASK (0x03) -#define PINSEL_BASIC_MODE_POS (3) -#define PINSEL_BASIC_MODE_NUMBITS (2) -#define PINSEL_BASIC_MODE_BITMASK (0x03) +#define PINSEL_BASIC_MODE_POS (3) +#define PINSEL_BASIC_MODE_NUMBITS (2) +#define PINSEL_BASIC_MODE_BITMASK (0x03) -#define PINSEL_DACEN_POS (16) -#define PINSEL_DACEN_BITMASK (0x01) -#define PINSEL_DACEN_NUMBITS (1) +#define PINSEL_DACEN_POS (16) +#define PINSEL_DACEN_BITMASK (0x01) +#define PINSEL_DACEN_NUMBITS (1) -#define PINSEL_GLITCH_FILTER_POS (8) -#define PINSEL_GLITCH_FILTER_BITMASK (0x01) -#define PINSEL_GLITCH_FILTER_NUMBITS (1) +#define PINSEL_GLITCH_FILTER_POS (8) +#define PINSEL_GLITCH_FILTER_BITMASK (0x01) +#define PINSEL_GLITCH_FILTER_NUMBITS (1) -#define PINSEL_ADMODE_POS (7) -#define PINSEL_ADMODE_BITMASK (0x01) -#define PINSEL_ADMODE_NUMBITS (1) +#define PINSEL_ADMODE_POS (7) +#define PINSEL_ADMODE_BITMASK (0x01) +#define PINSEL_ADMODE_NUMBITS (1) /* Private Functions ---------------------------------------------------------- */ /*********************************************************************//** - * @brief Get pointer to GPIO peripheral due to GPIO port - * @param[in] portnum Port Number value, should be in range from 0..3. - * @param[in] pinnum Pin number value, should be in range from 0..31 - * @return Pointer to GPIO peripheral + * @brief Get pointer to GPIO peripheral due to GPIO port + * @param[in] portnum Port Number value, should be in range from 0..3. + * @param[in] pinnum Pin number value, should be in range from 0..31 + * @return Pointer to GPIO peripheral **********************************************************************/ static uint32_t * PIN_GetPointer(uint8_t portnum, uint8_t pinnum) { - uint32_t *pPIN = NULL; - pPIN = (uint32_t *)(LPC_IOCON_BASE + ((portnum * 32 + pinnum)*sizeof(uint32_t))); - return pPIN; + uint32_t *pPIN = NULL; + pPIN = (uint32_t *)(LPC_IOCON_BASE + ((portnum * 32 + pinnum)*sizeof(uint32_t))); + return pPIN; } /* Public Functions ----------------------------------------------------------- */ @@ -73,268 +73,268 @@ static uint32_t * PIN_GetPointer(uint8_t portnum, uint8_t pinnum) */ /*********************************************************************//** - * @brief Setup the pin selection function - * @param[in] portnum PORT number, should be in range: 0..3 - * @param[in] pinnum Pin number, should be in range: 0..31 - * @param[in] funcnum Function number, should be range: 0..7 - * - 0: Select GPIO (Default) - * - 1: Selects the 1st alternate function - * - 2: Selects the 2nd alternate function - * ... - * - 7: Selects the 7th alternate function - * @return None + * @brief Setup the pin selection function + * @param[in] portnum PORT number, should be in range: 0..3 + * @param[in] pinnum Pin number, should be in range: 0..31 + * @param[in] funcnum Function number, should be range: 0..7 + * - 0: Select GPIO (Default) + * - 1: Selects the 1st alternate function + * - 2: Selects the 2nd alternate function + * ... + * - 7: Selects the 7th alternate function + * @return None **********************************************************************/ void PINSEL_ConfigPin ( uint8_t portnum, uint8_t pinnum, uint8_t funcnum) { - uint32_t *pPIN = NULL; - pPIN = PIN_GetPointer(portnum, pinnum); - *pPIN &= 0x00000007;//Clear function bits - *pPIN |= funcnum; + uint32_t *pPIN = NULL; + pPIN = PIN_GetPointer(portnum, pinnum); + *pPIN &= 0x00000007;//Clear function bits + *pPIN |= funcnum; } /*********************************************************************//** - * @brief Setup resistor mode for each pin - * @param[in] portnum PORT number, should be in range: 0..3 - * @param[in] pinnum Pin number, should be in range: 0..31 - * @param[in] modenum: Mode number, should be in range: 0..3 - - IOCON_MODE_PLAIN: Plain output - - IOCON_MODE_PULLDOWN: Pull-down enable - - IOCON_MODE_PULLUP: Pull-up enable - - IOCON_MODE_REPEATER: Repeater mode - * @return None + * @brief Setup resistor mode for each pin + * @param[in] portnum PORT number, should be in range: 0..3 + * @param[in] pinnum Pin number, should be in range: 0..31 + * @param[in] modenum: Mode number, should be in range: 0..3 + - IOCON_MODE_PLAIN: Plain output + - IOCON_MODE_PULLDOWN: Pull-down enable + - IOCON_MODE_PULLUP: Pull-up enable + - IOCON_MODE_REPEATER: Repeater mode + * @return None **********************************************************************/ void PINSEL_SetPinMode ( uint8_t portnum, uint8_t pinnum, PinSel_BasicMode modenum) { - uint32_t *pPIN = NULL; - pPIN = PIN_GetPointer(portnum, pinnum); - *(uint32_t *)pPIN &= ~(3<<3);//Clear function bits - *(uint32_t *)pPIN |= modenum; + uint32_t *pPIN = NULL; + pPIN = PIN_GetPointer(portnum, pinnum); + *(uint32_t *)pPIN &= ~(3<<3);//Clear function bits + *(uint32_t *)pPIN |= modenum; } /*********************************************************************//** - * @brief Setup hysteresis for each pin - * @param[in] portnum Port number, should be in range: 0..3 - * @param[in] pinnum Pin number, should be in range: 0..31 - * @param[in] NewState new state of Hysteresis mode, should be: - * - ENABLE: Hysteresis enable - * - DISABLE: Hysteresis disable - * @return None + * @brief Setup hysteresis for each pin + * @param[in] portnum Port number, should be in range: 0..3 + * @param[in] pinnum Pin number, should be in range: 0..31 + * @param[in] NewState new state of Hysteresis mode, should be: + * - ENABLE: Hysteresis enable + * - DISABLE: Hysteresis disable + * @return None **********************************************************************/ void PINSEL_SetHysMode(uint8_t portnum, uint8_t pinnum, FunctionalState NewState) { - uint32_t *pPIN = NULL; - pPIN = PIN_GetPointer(portnum, pinnum); - if(NewState == DISABLE) - { - *(uint32_t *)pPIN &= ~IOCON_HYS;//Clear hys bits - } - else - *(uint32_t *)pPIN |= IOCON_HYS; + uint32_t *pPIN = NULL; + pPIN = PIN_GetPointer(portnum, pinnum); + if(NewState == DISABLE) + { + *(uint32_t *)pPIN &= ~IOCON_HYS;//Clear hys bits + } + else + *(uint32_t *)pPIN |= IOCON_HYS; } /*********************************************************************//** - * @brief Setup Slew rate for each pin - * @param[in] portnum Port number, should be in range: 0..3 - * @param[in] pinnum Pin number, should be in range: 0..31 - * @param[in] NewState new state of Slew rate control, should be: - * - ENABLE: Output slew rate control is enable - * - DISABLE: Output slew rate control is disable - * @return None + * @brief Setup Slew rate for each pin + * @param[in] portnum Port number, should be in range: 0..3 + * @param[in] pinnum Pin number, should be in range: 0..31 + * @param[in] NewState new state of Slew rate control, should be: + * - ENABLE: Output slew rate control is enable + * - DISABLE: Output slew rate control is disable + * @return None **********************************************************************/ void PINSEL_SetSlewMode(uint8_t portnum, uint8_t pinnum, FunctionalState NewState) { - uint32_t *pPIN = NULL; - pPIN = PIN_GetPointer(portnum, pinnum); - if(NewState == DISABLE) - { - *(uint32_t *)pPIN &= ~IOCON_SLEW;//Clear hys bits - } - else - *(uint32_t *)pPIN |= IOCON_SLEW; + uint32_t *pPIN = NULL; + pPIN = PIN_GetPointer(portnum, pinnum); + if(NewState == DISABLE) + { + *(uint32_t *)pPIN &= ~IOCON_SLEW;//Clear hys bits + } + else + *(uint32_t *)pPIN |= IOCON_SLEW; } /*********************************************************************//** - * @brief Setup Input Buffer for each pin - * @param[in] portnum Port number, should be in range: 0..3 - * @param[in] pinnum Pin number, should be in range: 0..31 - * @param[in] NewState new state of Input buffer mode, should be: - * - ENABLE: The input buffer is enable - * - DISABLE: The input buffer is disable - * @return None + * @brief Setup Input Buffer for each pin + * @param[in] portnum Port number, should be in range: 0..3 + * @param[in] pinnum Pin number, should be in range: 0..31 + * @param[in] NewState new state of Input buffer mode, should be: + * - ENABLE: The input buffer is enable + * - DISABLE: The input buffer is disable + * @return None **********************************************************************/ void PINSEL_SetInBufMode(uint8_t portnum, uint8_t pinnum, FunctionalState NewState) { - uint32_t *pPIN = NULL; - pPIN = PIN_GetPointer(portnum, pinnum); - if(NewState == DISABLE) - { - *(uint32_t *)pPIN &= ~IOCON_INBUF;//Clear hys bits - } - else - *(uint32_t *)pPIN |= IOCON_INBUF; + uint32_t *pPIN = NULL; + pPIN = PIN_GetPointer(portnum, pinnum); + if(NewState == DISABLE) + { + *(uint32_t *)pPIN &= ~IOCON_INBUF;//Clear hys bits + } + else + *(uint32_t *)pPIN |= IOCON_INBUF; } /*********************************************************************//** - * @brief Setup I2CMode for only pins that provide special I2C functionality - * @param[in] portnum Port number, should be in range: 0..3 - * @param[in] pinnum Pin number, should be in range: 0..31 - * @param[in] I2CMode I2C mode, should be: - * - IOCON_I2CMODE_FAST: Fast mode and standard I2C mode - * - IOCON_I2CMODE_OPENDRAIN: Open drain I/O - * - IOCON_I2CMODE_FASTPLUS: Fast Mode Plus I/O - * - IOCON_I2CMODE_HIGHOPENDRAIN: High drive open drain I/O - * @return None + * @brief Setup I2CMode for only pins that provide special I2C functionality + * @param[in] portnum Port number, should be in range: 0..3 + * @param[in] pinnum Pin number, should be in range: 0..31 + * @param[in] I2CMode I2C mode, should be: + * - IOCON_I2CMODE_FAST: Fast mode and standard I2C mode + * - IOCON_I2CMODE_OPENDRAIN: Open drain I/O + * - IOCON_I2CMODE_FASTPLUS: Fast Mode Plus I/O + * - IOCON_I2CMODE_HIGHOPENDRAIN: High drive open drain I/O + * @return None **********************************************************************/ void PINSEL_SetI2CMode(uint8_t portnum, uint8_t pinnum, PinSel_I2cMode I2CMode) { - uint32_t *pPIN = NULL; - pPIN = PIN_GetPointer(portnum, pinnum); + uint32_t *pPIN = NULL; + pPIN = PIN_GetPointer(portnum, pinnum); - *(uint32_t *)pPIN &= ~(PINSEL_I2C_MODE_BITMASK<< PINSEL_I2C_MODE_POS); - *(uint32_t *)pPIN |= (I2CMode << PINSEL_I2C_MODE_POS); + *(uint32_t *)pPIN &= ~(PINSEL_I2C_MODE_BITMASK<< PINSEL_I2C_MODE_POS); + *(uint32_t *)pPIN |= (I2CMode << PINSEL_I2C_MODE_POS); } /*********************************************************************//** - * @brief Setup Open-drain mode in each pin - * @param[in] portnum Port number, should be in range: 0..3 - * @param[in] pinnum Pin number, should be in range: 0..31 - * @param[in] NewState new state of Open-drain mode: - * - DISABLE: Normal pin I/O mode - * - ENABLE: Open-drain enable - * @return None + * @brief Setup Open-drain mode in each pin + * @param[in] portnum Port number, should be in range: 0..3 + * @param[in] pinnum Pin number, should be in range: 0..31 + * @param[in] NewState new state of Open-drain mode: + * - DISABLE: Normal pin I/O mode + * - ENABLE: Open-drain enable + * @return None **********************************************************************/ void PINSEL_SetOpenDrainMode(uint8_t portnum, uint8_t pinnum, FunctionalState NewState) { - uint32_t *pPIN = NULL; - pPIN = PIN_GetPointer(portnum, pinnum); - if(NewState == DISABLE) - { - *(uint32_t *)pPIN &= ~IOCON_ODMODE;//Clear hys bits - } - else - { - *(uint32_t *)pPIN |= IOCON_ODMODE; - } + uint32_t *pPIN = NULL; + pPIN = PIN_GetPointer(portnum, pinnum); + if(NewState == DISABLE) + { + *(uint32_t *)pPIN &= ~IOCON_ODMODE;//Clear hys bits + } + else + { + *(uint32_t *)pPIN |= IOCON_ODMODE; + } } /*********************************************************************//** - * @brief Enable the Analog mode for each pin (default is as Digital pins) - * @param[in] portnum PORT number, should be in range: 0..3 - * @param[in] pinnum Pin number, should be in range: 0..31 - * @param[in] enable: the state of the pin that is expected to run - - ENABLE: Enable the DAC mode of the pin - - DISABLE: Disable the DAC mode - * @return None + * @brief Enable the Analog mode for each pin (default is as Digital pins) + * @param[in] portnum PORT number, should be in range: 0..3 + * @param[in] pinnum Pin number, should be in range: 0..31 + * @param[in] enable: the state of the pin that is expected to run + - ENABLE: Enable the DAC mode of the pin + - DISABLE: Disable the DAC mode + * @return None **********************************************************************/ void PINSEL_SetAnalogPinMode (uint8_t portnum, uint8_t pinnum, uint8_t enable) { - uint32_t *pPIN = NULL; + uint32_t *pPIN = NULL; - uint8_t condition = 0; + uint8_t condition = 0; - condition = ((portnum == 0) && (pinnum == 12)) || ((portnum == 0) && (pinnum == 13)) - | ((portnum == 0) && (pinnum <= 26) && (pinnum >= 23)) - | ((portnum == 1) && (pinnum == 30)) || ((portnum == 1) && (pinnum == 31)); + condition = ((portnum == 0) && (pinnum == 12)) || ((portnum == 0) && (pinnum == 13)) + | ((portnum == 0) && (pinnum <= 26) && (pinnum >= 23)) + | ((portnum == 1) && (pinnum == 30)) || ((portnum == 1) && (pinnum == 31)); - if(!condition) - { - return; - } + if(!condition) + { + return; + } - pPIN = PIN_GetPointer(portnum, pinnum); + pPIN = PIN_GetPointer(portnum, pinnum); - //Clear this bit to set the pin to Analog mode - *(uint32_t *)pPIN &= ~(PINSEL_ADMODE_BITMASK << PINSEL_ADMODE_POS); + //Clear this bit to set the pin to Analog mode + *(uint32_t *)pPIN &= ~(PINSEL_ADMODE_BITMASK << PINSEL_ADMODE_POS); - if(enable) - { + if(enable) + { - } - else - { - *(uint32_t *)pPIN |= (1 << PINSEL_ADMODE_POS);//Set 16th bit to one - } + } + else + { + *(uint32_t *)pPIN |= (1 << PINSEL_ADMODE_POS);//Set 16th bit to one + } - return; + return; } /*********************************************************************//** - * @brief Choose the DAC mode for each pin - * @param[in] portnum PORT number, should be in range: 0..3 - * @param[in] pinnum Pin number, should be in range: 0..31 - * @param[in] enable: the state of the pin that is expected to run - - ENABLE: Enable the DAC mode of the pin - - DISABLE: Disable the DAC mode - * @return None + * @brief Choose the DAC mode for each pin + * @param[in] portnum PORT number, should be in range: 0..3 + * @param[in] pinnum Pin number, should be in range: 0..31 + * @param[in] enable: the state of the pin that is expected to run + - ENABLE: Enable the DAC mode of the pin + - DISABLE: Disable the DAC mode + * @return None **********************************************************************/ void PINSEL_DacEnable (uint8_t portnum, uint8_t pinnum, uint8_t enable) { - uint32_t *pPIN = NULL; + uint32_t *pPIN = NULL; - // This setting is only for DAC pin (output pin) - if(!((portnum == 0) && (pinnum == 26))) - { - return; - } + // This setting is only for DAC pin (output pin) + if(!((portnum == 0) && (pinnum == 26))) + { + return; + } - pPIN = PIN_GetPointer(portnum, pinnum); + pPIN = PIN_GetPointer(portnum, pinnum); - //Clear DAC Enable function bits - *(uint32_t *)pPIN &= ~(PINSEL_DACEN_BITMASK << PINSEL_DACEN_POS); + //Clear DAC Enable function bits + *(uint32_t *)pPIN &= ~(PINSEL_DACEN_BITMASK << PINSEL_DACEN_POS); - if(enable) - { - *(uint32_t *)pPIN |= (1 << PINSEL_DACEN_POS);//Set 16th bit to one - } - else - { + if(enable) + { + *(uint32_t *)pPIN |= (1 << PINSEL_DACEN_POS);//Set 16th bit to one + } + else + { - } + } - return; + return; } /*********************************************************************//** - * @brief Control the glitch filter for each pin - * @param[in] portnum PORT number, should be in range: 0..3 - * @param[in] pinnum Pin number, should be in range: 0..31 - * @param[in] enable: the state of the pin that is expected to run - - ENABLE: The noise pulses below approximately 10ns are filtered out - - DISABLE: No input filtering is done. - * @return None + * @brief Control the glitch filter for each pin + * @param[in] portnum PORT number, should be in range: 0..3 + * @param[in] pinnum Pin number, should be in range: 0..31 + * @param[in] enable: the state of the pin that is expected to run + - ENABLE: The noise pulses below approximately 10ns are filtered out + - DISABLE: No input filtering is done. + * @return None **********************************************************************/ void PINSEL_SetFilter (uint8_t portnum, uint8_t pinnum, uint8_t enable) { - uint32_t *pPIN = NULL; + uint32_t *pPIN = NULL; - // This setting is only for DAC pin (output pin) - if(!((portnum == 0) && ((pinnum == 7) || (pinnum == 8) || (pinnum == 9)))) - { - return; - } + // This setting is only for DAC pin (output pin) + if(!((portnum == 0) && ((pinnum == 7) || (pinnum == 8) || (pinnum == 9)))) + { + return; + } - pPIN = PIN_GetPointer(portnum, pinnum); + pPIN = PIN_GetPointer(portnum, pinnum); - *(uint32_t *)pPIN |= (1 << 7);//Set 7th bit for normal operation following the UM1.0 + *(uint32_t *)pPIN |= (1 << 7);//Set 7th bit for normal operation following the UM1.0 - //Clear Filter bits - *(uint32_t *)pPIN &= ~(PINSEL_GLITCH_FILTER_BITMASK << PINSEL_GLITCH_FILTER_POS); + //Clear Filter bits + *(uint32_t *)pPIN &= ~(PINSEL_GLITCH_FILTER_BITMASK << PINSEL_GLITCH_FILTER_POS); - if(!enable) - { - *(uint32_t *)pPIN |= (1 << PINSEL_GLITCH_FILTER_POS);//Set 8th bit to one - } - else - { + if(!enable) + { + *(uint32_t *)pPIN |= (1 << PINSEL_GLITCH_FILTER_POS);//Set 8th bit to one + } + else + { - } + } - *pPIN = *pPIN; + *pPIN = *pPIN; - return; + return; } /** diff --git a/bsp/lpc178x/drivers/lpc177x_8x_pinsel.h b/bsp/lpc178x/drivers/lpc177x_8x_pinsel.h index ca83c91fc5..d7a291cff7 100644 --- a/bsp/lpc178x/drivers/lpc177x_8x_pinsel.h +++ b/bsp/lpc178x/drivers/lpc177x_8x_pinsel.h @@ -1,13 +1,13 @@ /********************************************************************** -* $Id$ lpc177x_8x_pinsel.h 2011-06-02 +* $Id$ lpc177x_8x_pinsel.h 2011-06-02 *//** -* @file lpc177x_8x_pinsel.h -* @brief Contains all macro definitions and function prototypes -* support for Pin-connection block firmware library on LPC177x_8x -* @version 1.0 -* @date 02. June. 2011 -* @author NXP MCU SW Application Team -* +* @file lpc177x_8x_pinsel.h +* @brief Contains all macro definitions and function prototypes +* support for Pin-connection block firmware library on LPC177x_8x +* @version 1.0 +* @date 02. June. 2011 +* @author NXP MCU SW Application Team +* * Copyright(C) 2011, NXP Semiconductor * All rights reserved. * @@ -25,7 +25,7 @@ **********************************************************************/ /* Peripheral group ----------------------------------------------------------- */ -/** @defgroup PINSEL Pin Selection +/** @defgroup PINSEL Pin Selection * @ingroup LPC177x_8xCMSIS_FwLib_Drivers * @{ */ @@ -44,160 +44,160 @@ */ /* Macros define IOCON bits */ -#define IOCON_MODE_PLAIN ((0<<3)) -#define IOCON_MODE_PULLDOWN ((1<<3)) -#define IOCON_MODE_PULLUP ((2<<3)) -#define IOCON_MODE_REPEATER ((3<<3)) -#define IOCON_HYS ((1<<5)) -#define IOCON_SLEW ((1<<6)) -#define IOCON_INBUF ((1<<7)) -#define IOCON_I2CMODE_FAST ((0<<8)) -#define IOCON_I2CMODE_OPENDRAIN ((1<<8)) -#define IOCON_I2CMODE_FASTPLUS ((2<<8)) -#define IOCON_I2CMODE_HIGHOPENDRAIN ((3<<8)) -#define IOCON_ODMODE ((1<<10)) +#define IOCON_MODE_PLAIN ((0<<3)) +#define IOCON_MODE_PULLDOWN ((1<<3)) +#define IOCON_MODE_PULLUP ((2<<3)) +#define IOCON_MODE_REPEATER ((3<<3)) +#define IOCON_HYS ((1<<5)) +#define IOCON_SLEW ((1<<6)) +#define IOCON_INBUF ((1<<7)) +#define IOCON_I2CMODE_FAST ((0<<8)) +#define IOCON_I2CMODE_OPENDRAIN ((1<<8)) +#define IOCON_I2CMODE_FASTPLUS ((2<<8)) +#define IOCON_I2CMODE_HIGHOPENDRAIN ((3<<8)) +#define IOCON_ODMODE ((1<<10)) /* Macros define for LOC registers */ -#define LOC_CAN_RD_1_P0_0 ((0)) /**< Input for CAN_RD_1 comes from P0.0 */ -#define LOC_CAN_RD_1_P0_21 ((1)) /**< Input for CAN_RD_1 comes from P0.21 */ -#define LOC_CAN_RD_2_P2_7 ((0)) /**< Input for CAN_RD_2 comes from P2.7 */ -#define LOC_CAN_RD_2_P0_4 ((1)) /**< Input for CAN_RD_2 comes from P0.4 */ -#define LOC_ENET_MDIO_P2_9 ((0)) /**< Input for ENET_MDIO comes from P2.9 */ -#define LOC_ENET_MDIO_P1_17 ((1)) /**< Input for ENET_MDIO comes from P1.17 */ -#define LOC_EINT_0_P0_29 ((0)) /**< Input for EINT_0 comes from P0.29 */ -#define LOC_EINT_0_P2_10 ((1)) /**< Input for EINT_0 comes from P2.10 */ -#define LOC_EINT_1_P0_30 ((0)) /**< Input for EINT_1 comes from P0.30 */ -#define LOC_EINT_1_P2_11 ((1)) /**< Input for EINT_1 comes from P2.11 */ -#define LOC_I2C0_SCL_P1_31 ((0)) /**< Input for I2C0_SCL comes from P1.31 */ -#define LOC_I2C0_SCL_P0_28 ((1)) /**< Input for I2C0_SCL comes from P0.28 */ -#define LOC_I2C0_SCL_P5_3 ((2)) /**< Input for I2C0_SCL comes from P5.3 */ -#define LOC_I2C0_SDA_P1_30 ((0)) /**< Input for I2C0_SDA comes from P1.30 */ -#define LOC_I2C0_SDA_P0_27 ((1)) /**< Input for I2C0_SDA comes from P0.27 */ -#define LOC_I2C0_SDA_P5_2 ((2)) /**< Input for I2C0_SDA comes from P5.2 */ -#define LOC_I2C1_SCL_P0_1 ((0)) /**< Input for I2C1_SCL comes from P0.1 */ -#define LOC_I2C1_SCL_P2_15 ((1)) /**< Input for I2C1_SCL comes from P2.15 */ -#define LOC_I2C1_SCL_P0_20 ((2)) /**< Input for I2C1_SCL comes from P0.20 */ -#define LOC_I2C1_SDA_P2_14 ((0)) /**< Input for I2C1_SDA comes from P2.14 */ -#define LOC_I2C1_SDA_P0_0 ((1)) /**< Input for I2C1_SDA comes from P0.0 */ -#define LOC_I2C1_SDA_P0_19 ((2)) /**< Input for I2C1_SDA comes from P0.19 */ -#define LOC_I2C2_SCL_P2_31 ((0)) /**< Input for I2C2_SCL comes from P2.31 */ -#define LOC_I2C2_SCL_P0_11 ((1)) /**< Input for I2C2_SCL comes from P0.11 */ -#define LOC_I2C2_SCL_P4_21 ((2)) /**< Input for I2C2_SCL comes from P4.21 */ -#define LOC_I2C2_SCL_P4_29 ((3)) /**< Input for I2C2_SCL comes from P4.29 */ -#define LOC_I2C2_SDA_P2_30 ((0)) /**< Input for I2C2_SDA comes from P2.30 */ -#define LOC_I2C2_SDA_P0_10 ((1)) /**< Input for I2C2_SDA comes from P0.10 */ -#define LOC_I2C2_SDA_P4_20 ((2)) /**< Input for I2C2_SDA comes from P4.20 */ -#define LOC_I2C2_SDA_P1_15 ((3)) /**< Input for I2C2_SDA comes from P1.15 */ -#define LOC_I2S_RX_SCK_P0_23 ((0)) /**< Input for I2S_RX_SCK comes from P0.23 */ -#define LOC_I2S_RX_SCK_P0_4 ((1)) /**< Input for I2S_RX_SCK comes from P0.4 */ -#define LOC_I2S_RX_SDA_P0_25 ((0)) /**< Input for I2S_RX_SDA comes from P0.25 */ -#define LOC_I2S_RX_SDA_P0_6 ((1)) /**< Input for I2S_RX_SDA comes from P0.6 */ -#define LOC_I2S_RX_WS_P0_24 ((0)) /**< Input for I2S_RX_WS comes from P0.24 */ -#define LOC_I2S_RX_WS_P0_5 ((1)) /**< Input for I2S_RX_WS comes from P0.5 */ -#define LOC_I2S_TX_SCK_P2_11 ((0)) /**< Input for I2S_TX_SCK comes from P2.11 */ -#define LOC_I2S_TX_SCK_P0_7 ((1)) /**< Input for I2S_TX_SCK comes from P0.7 */ -#define LOC_I2S_TX_WS_P2_12 ((0)) /**< Input for I2S_TX_WS comes from P2.12 */ -#define LOC_I2S_TX_WS_P0_8 ((1)) /**< Input for I2S_TX_WS comes from P0.8 */ -#define LOC_PWM0_CAP_0_P1_12 ((0)) /**< Input for PWM0_CAP_0 comes from P1.12 */ -#define LOC_PWM0_CAP_0_P3_22 ((1)) /**< Input for PWM0_CAP_0 comes from P3.22 */ -#define LOC_PWM1_CAP_0_P3_23 ((0)) /**< Input for PWM1_CAP_0 comes from P3.23 */ -#define LOC_PWM1_CAP_0_P1_28 ((1)) /**< Input for PWM1_CAP_0 comes from P1.28 */ -#define LOC_PWM1_CAP_0_P2_6 ((2)) /**< Input for PWM1_CAP_0 comes from P2.6 */ -#define LOC_SD_CMD_P0_20 ((0)) /**< Input for SD_CMD comes from P0.20 */ -#define LOC_SD_CMD_P1_3 ((1)) /**< Input for SD_CMD comes from P1.3 */ -#define LOC_SD_DAT_0_P0_22 ((0)) /**< Input for SD_DAT_0 comes from P0.22 */ -#define LOC_SD_DAT_0_P1_6 ((1)) /**< Input for SD_DAT_0 comes from P1.6 */ -#define LOC_SD_DAT_1_P2_11 ((0)) /**< Input for SD_DAT_1 comes from P2.11 */ -#define LOC_SD_DAT_1_P1_7 ((1)) /**< Input for SD_DAT_1 comes from P1.7 */ -#define LOC_SD_DAT_2_P2_12 ((0)) /**< Input for SD_DAT_2 comes from P2.12 */ -#define LOC_SD_DAT_2_P1_11 ((1)) /**< Input for SD_DAT_2 comes from P1.11 */ -#define LOC_SD_DAT_3_P2_13 ((0)) /**< Input for SD_DAT_3 comes from P2.13 */ -#define LOC_SD_DAT_3_P1_12 ((1)) /**< Input for SD_DAT_3 comes from P1.12 */ -#define LOC_SSP0_MISO_P2_26 ((0)) /**< Input for SSP0_MISO comes from P2.26 */ -#define LOC_SSP0_MISO_P1_23 ((1)) /**< Input for SSP0_MISO comes from P1_23 */ -#define LOC_SSP0_MISO_P0_17 ((2)) /**< Input for SSP0_MISO comes from P0_17 */ -#define LOC_SSP0_MOSI_P2_27 ((0)) /**< Input for SSP0_MOSI comes from P2.27 */ -#define LOC_SSP0_MOSI_P1_24 ((1)) /**< Input for SSP0_MOSI comes from P1.24 */ -#define LOC_SSP0_MOSI_P0_18 ((2)) /**< Input for SSP0_MOSI comes from P0.18 */ -#define LOC_SSP0_SCK_P1_20 ((0)) /**< Input for SSP0_SCK comes from P1.20 */ -#define LOC_SSP0_SCK_P2_22 ((1)) /**< Input for SSP0_SCK comes from P2.22 */ -#define LOC_SSP0_SCK_P0_15 ((2)) /**< Input for SSP0_SCK comes from P0_15 */ -#define LOC_SSP0_SSEL_P2_23 ((0)) /**< Input for SSP0_SSEL comes from P2.23 */ -#define LOC_SSP0_SSEL_P1_21 ((1)) /**< Input for SSP0_SSEL comes from P1.21 */ -#define LOC_SSP0_SSEL_P1_28 ((2)) /**< Input for SSP0_SSEL comes from P1.28 */ -#define LOC_SSP0_SSEL_P0_16 ((3)) /**< Input for SSP0_SSEL comes from P0.16 */ -#define LOC_SSP1_MISO_P0_12 ((0)) /**< Input for SSP1_MISO comes from P0.12 */ -#define LOC_SSP1_MISO_P1_18 ((1)) /**< Input for SSP1_MISO comes from P1.18 */ -#define LOC_SSP1_MISO_P4_22 ((2)) /**< Input for SSP1_MISO comes from P4_22 */ -#define LOC_SSP1_MISO_P0_8 ((3)) /**< Input for SSP1_MISO comes from P0.8 */ -#define LOC_SSP1_MOSI_P0_13 ((0)) /**< Input for SSP1_MOSI comes from P0.13 */ -#define LOC_SSP1_MOSI_P1_22 ((1)) /**< Input for SSP1_MOSI comes from P1.22 */ -#define LOC_SSP1_MOSI_P4_23 ((2)) /**< Input for SSP1_MOSI comes from P4.23 */ -#define LOC_SSP1_MOSI_P0_9 ((3)) /**< Input for SSP1_MOSI comes from P0.9 */ -#define LOC_SSP1_SCK_P1_31 ((0)) /**< Input for SSP1_SCK comes from P1.31 */ -#define LOC_SSP1_SCK_P1_19 ((1)) /**< Input for SSP1_SCK comes from P1.19 */ -#define LOC_SSP1_SCK_P4_20 ((2)) /**< Input for SSP1_SCK comes from P4_20 */ -#define LOC_SSP1_SCK_P0_7 ((3)) /**< Input for SSP1_SCK comes from P0_7 */ -#define LOC_SSP1_SSEL_P0_14 ((0)) /**< Input for SSP1_SSEL comes from P0.14 */ -#define LOC_SSP1_SSEL_P1_26 ((1)) /**< Input for SSP1_SSEL comes from P1.26 */ -#define LOC_SSP1_SSEL_P4_21 ((2)) /**< Input for SSP1_SSEL comes from P4.21 */ -#define LOC_SSP1_SSEL_P0_6 ((3)) /**< Input for SSP1_SSEL comes from P0.6 */ -#define LOC_SSP2_MISO_P1_4 ((1)) /**< Input for SSP2_MISO comes from P1.4 */ -#define LOC_SSP2_MOSI_P1_1 ((1)) /**< Input for SSP2_MOSI comes from P1.1 */ -#define LOC_SSP2_SCK_P1_0 ((1)) /**< Input for SSP2_SCK comes from P1.0 */ -#define LOC_SSP2_SSEL_P1_8 ((1)) /**< Input for SSP2_SSEL comes from P1.8 */ -#define LOC_T0_CAP_0_P3_23 ((0)) /**< Input for T0_CAP_0 comes from P3.23 */ -#define LOC_T0_CAP_0_P1_26 ((1)) /**< Input for T0_CAP_0 comes from P1.26 */ -#define LOC_T0_CAP_1_P3_24 ((0)) /**< Input for T0_CAP_1 comes from P3.24 */ -#define LOC_T0_CAP_1_P1_27 ((1)) /**< Input for T0_CAP_1 comes from P1.27 */ -#define LOC_T1_CAP_0_P1_18 ((0)) /**< Input for T1_CAP_0 comes from P1.18 */ -#define LOC_T1_CAP_0_P3_27 ((1)) /**< Input for T1_CAP_0 comes from P3.27 */ -#define LOC_T1_CAP_1_P3_28 ((0)) /**< Input for T1_CAP_1 comes from P3.28 */ -#define LOC_T1_CAP_1_P1_19 ((1)) /**< Input for T1_CAP_1 comes from P1.19 */ -#define LOC_T2_CAP_0_P2_14 ((0)) /**< Input for T2_CAP_0 comes from P2.14 */ -#define LOC_T2_CAP_0_P2_6 ((1)) /**< Input for T2_CAP_0 comes from P2.6 */ -#define LOC_T2_CAP_0_P0_4 ((2)) /**< Input for T2_CAP_0 comes from P0.4 */ -#define LOC_T2_CAP_0_P1_14 ((3)) /**< Input for T2_CAP_0 comes from P1.14 */ -#define LOC_T2_CAP_1_P2_15 ((0)) /**< Input for T2_CAP_1 comes from P2.15 */ -#define LOC_T2_CAP_1_P0_5 ((1)) /**< Input for T2_CAP_1 comes from P0.5 */ -#define LOC_T3_CAP_0_P0_23 ((0)) /**< Input for T3_CAP_0 comes from P0.23 */ -#define LOC_T3_CAP_0_P2_22 ((1)) /**< Input for T3_CAP_0 comes from P2.22 */ -#define LOC_T3_CAP_0_P1_10 ((2)) /**< Input for T3_CAP_0 comes from P1.10 */ -#define LOC_T3_CAP_1_P0_24 ((0)) /**< Input for T3_CAP_1 comes from P0.24 */ -#define LOC_T3_CAP_1_P2_23 ((1)) /**< Input for T3_CAP_1 comes from P2.23 */ -#define LOC_T3_CAP_1_P1_0 ((2)) /**< Input for T3_CAP_1 comes from P1.0 */ -#define LOC_U0_RXD_P0_1 ((0)) /**< Input for U0_RXD comes from P0.1 */ -#define LOC_U0_RXD_P0_3 ((1)) /**< Input for U0_RXD comes from P0.3 */ -#define LOC_U1_CTS_P0_17 ((0)) /**< Input for U1_CTS comes from P0.17 */ -#define LOC_U1_CTS_P2_8 ((1)) /**< Input for U1_CTS comes from P2.8 */ -#define LOC_U1_CTS_P2_2 ((2)) /**< Input for U1_CTS comes from P2.2 */ -#define LOC_U1_CTS_P3_18 ((3)) /**< Input for U1_CTS comes from P3.18 */ -#define LOC_U1_DCD_P0_18 ((0)) /**< Input for U1_DCD comes from P0.18 */ -#define LOC_U1_DCD_P2_3 ((1)) /**< Input for U1_DCD comes from P2.3 */ -#define LOC_U1_DCD_P3_19 ((2)) /**< Input for U1_DCD comes from P3_19 */ -#define LOC_U1_DSR_P0_19 ((0)) /**< Input for U1_DSR comes from P0.19 */ -#define LOC_U1_DSR_P2_4 ((1)) /**< Input for U1_DSR comes from P2.4 */ -#define LOC_U1_DSR_P3_20 ((2)) /**< Input for U1_DSR comes from P0.19 */ -#define LOC_U1_RI_P0_21 ((0)) /**< Input for U1_RI comes from P0.21 */ -#define LOC_U1_RI_P2_6 ((1)) /**< Input for U1_RI comes from P2.6 */ -#define LOC_U1_RI_P3_22 ((2)) /**< Input for U1_RI comes from P3.22 */ -#define LOC_U1_RXD_P0_16 ((0)) /**< Input for U1_RXD comes from P0.16 */ -#define LOC_U1_RXD_P3_17 ((1)) /**< Input for U1_RXD comes from P3.17 */ -#define LOC_U1_RXD_P2_1 ((2)) /**< Input for U1_RXD comes from P2.1 */ -#define LOC_U2_RXD_P0_11 ((0)) /**< Input for U2_RXD comes from P0.11 */ -#define LOC_U2_RXD_P4_23 ((1)) /**< Input for U2_RXD comes from P4.23 */ -#define LOC_U2_RXD_P2_9 ((2)) /**< Input for U2_RXD comes from P2.9 */ -#define LOC_U3_RXD_P0_26 ((0)) /**< Input for U3_RXD comes from P0.26 */ -#define LOC_U3_RXD_P0_1 ((1)) /**< Input for U3_RXD comes from P0.1 */ -#define LOC_U3_RXD_P4_29 ((2)) /**< Input for U3_RXD comes from P4.29 */ -#define LOC_U3_RXD_P0_3 ((3)) /**< Input for U3_RXD comes from P0.3 */ -#define LOC_U4_RXD_P2_9 ((0)) /**< Input for U4_RXD comes from P2.9 */ -#define LOC_U4_RXD_P5_3 ((1)) /**< Input for U4_RXD comes from P5.3 */ -#define LOC_USB_SCL_P0_28 ((0)) /**< Input for USB_SCL comes from P0.28 */ -#define LOC_USB_SCL_P1_28 ((1)) /**< Input for USB_SCL comes from P1.28 */ -#define LOC_USB_SDA_P0_27 ((0)) /**< Input for USB_SDA comes from P0.27 */ -#define LOC_USB_SDA_P1_29 ((1)) /**< Input for USB_SDA comes from P1.29 */ +#define LOC_CAN_RD_1_P0_0 ((0)) /**< Input for CAN_RD_1 comes from P0.0 */ +#define LOC_CAN_RD_1_P0_21 ((1)) /**< Input for CAN_RD_1 comes from P0.21 */ +#define LOC_CAN_RD_2_P2_7 ((0)) /**< Input for CAN_RD_2 comes from P2.7 */ +#define LOC_CAN_RD_2_P0_4 ((1)) /**< Input for CAN_RD_2 comes from P0.4 */ +#define LOC_ENET_MDIO_P2_9 ((0)) /**< Input for ENET_MDIO comes from P2.9 */ +#define LOC_ENET_MDIO_P1_17 ((1)) /**< Input for ENET_MDIO comes from P1.17 */ +#define LOC_EINT_0_P0_29 ((0)) /**< Input for EINT_0 comes from P0.29 */ +#define LOC_EINT_0_P2_10 ((1)) /**< Input for EINT_0 comes from P2.10 */ +#define LOC_EINT_1_P0_30 ((0)) /**< Input for EINT_1 comes from P0.30 */ +#define LOC_EINT_1_P2_11 ((1)) /**< Input for EINT_1 comes from P2.11 */ +#define LOC_I2C0_SCL_P1_31 ((0)) /**< Input for I2C0_SCL comes from P1.31 */ +#define LOC_I2C0_SCL_P0_28 ((1)) /**< Input for I2C0_SCL comes from P0.28 */ +#define LOC_I2C0_SCL_P5_3 ((2)) /**< Input for I2C0_SCL comes from P5.3 */ +#define LOC_I2C0_SDA_P1_30 ((0)) /**< Input for I2C0_SDA comes from P1.30 */ +#define LOC_I2C0_SDA_P0_27 ((1)) /**< Input for I2C0_SDA comes from P0.27 */ +#define LOC_I2C0_SDA_P5_2 ((2)) /**< Input for I2C0_SDA comes from P5.2 */ +#define LOC_I2C1_SCL_P0_1 ((0)) /**< Input for I2C1_SCL comes from P0.1 */ +#define LOC_I2C1_SCL_P2_15 ((1)) /**< Input for I2C1_SCL comes from P2.15 */ +#define LOC_I2C1_SCL_P0_20 ((2)) /**< Input for I2C1_SCL comes from P0.20 */ +#define LOC_I2C1_SDA_P2_14 ((0)) /**< Input for I2C1_SDA comes from P2.14 */ +#define LOC_I2C1_SDA_P0_0 ((1)) /**< Input for I2C1_SDA comes from P0.0 */ +#define LOC_I2C1_SDA_P0_19 ((2)) /**< Input for I2C1_SDA comes from P0.19 */ +#define LOC_I2C2_SCL_P2_31 ((0)) /**< Input for I2C2_SCL comes from P2.31 */ +#define LOC_I2C2_SCL_P0_11 ((1)) /**< Input for I2C2_SCL comes from P0.11 */ +#define LOC_I2C2_SCL_P4_21 ((2)) /**< Input for I2C2_SCL comes from P4.21 */ +#define LOC_I2C2_SCL_P4_29 ((3)) /**< Input for I2C2_SCL comes from P4.29 */ +#define LOC_I2C2_SDA_P2_30 ((0)) /**< Input for I2C2_SDA comes from P2.30 */ +#define LOC_I2C2_SDA_P0_10 ((1)) /**< Input for I2C2_SDA comes from P0.10 */ +#define LOC_I2C2_SDA_P4_20 ((2)) /**< Input for I2C2_SDA comes from P4.20 */ +#define LOC_I2C2_SDA_P1_15 ((3)) /**< Input for I2C2_SDA comes from P1.15 */ +#define LOC_I2S_RX_SCK_P0_23 ((0)) /**< Input for I2S_RX_SCK comes from P0.23 */ +#define LOC_I2S_RX_SCK_P0_4 ((1)) /**< Input for I2S_RX_SCK comes from P0.4 */ +#define LOC_I2S_RX_SDA_P0_25 ((0)) /**< Input for I2S_RX_SDA comes from P0.25 */ +#define LOC_I2S_RX_SDA_P0_6 ((1)) /**< Input for I2S_RX_SDA comes from P0.6 */ +#define LOC_I2S_RX_WS_P0_24 ((0)) /**< Input for I2S_RX_WS comes from P0.24 */ +#define LOC_I2S_RX_WS_P0_5 ((1)) /**< Input for I2S_RX_WS comes from P0.5 */ +#define LOC_I2S_TX_SCK_P2_11 ((0)) /**< Input for I2S_TX_SCK comes from P2.11 */ +#define LOC_I2S_TX_SCK_P0_7 ((1)) /**< Input for I2S_TX_SCK comes from P0.7 */ +#define LOC_I2S_TX_WS_P2_12 ((0)) /**< Input for I2S_TX_WS comes from P2.12 */ +#define LOC_I2S_TX_WS_P0_8 ((1)) /**< Input for I2S_TX_WS comes from P0.8 */ +#define LOC_PWM0_CAP_0_P1_12 ((0)) /**< Input for PWM0_CAP_0 comes from P1.12 */ +#define LOC_PWM0_CAP_0_P3_22 ((1)) /**< Input for PWM0_CAP_0 comes from P3.22 */ +#define LOC_PWM1_CAP_0_P3_23 ((0)) /**< Input for PWM1_CAP_0 comes from P3.23 */ +#define LOC_PWM1_CAP_0_P1_28 ((1)) /**< Input for PWM1_CAP_0 comes from P1.28 */ +#define LOC_PWM1_CAP_0_P2_6 ((2)) /**< Input for PWM1_CAP_0 comes from P2.6 */ +#define LOC_SD_CMD_P0_20 ((0)) /**< Input for SD_CMD comes from P0.20 */ +#define LOC_SD_CMD_P1_3 ((1)) /**< Input for SD_CMD comes from P1.3 */ +#define LOC_SD_DAT_0_P0_22 ((0)) /**< Input for SD_DAT_0 comes from P0.22 */ +#define LOC_SD_DAT_0_P1_6 ((1)) /**< Input for SD_DAT_0 comes from P1.6 */ +#define LOC_SD_DAT_1_P2_11 ((0)) /**< Input for SD_DAT_1 comes from P2.11 */ +#define LOC_SD_DAT_1_P1_7 ((1)) /**< Input for SD_DAT_1 comes from P1.7 */ +#define LOC_SD_DAT_2_P2_12 ((0)) /**< Input for SD_DAT_2 comes from P2.12 */ +#define LOC_SD_DAT_2_P1_11 ((1)) /**< Input for SD_DAT_2 comes from P1.11 */ +#define LOC_SD_DAT_3_P2_13 ((0)) /**< Input for SD_DAT_3 comes from P2.13 */ +#define LOC_SD_DAT_3_P1_12 ((1)) /**< Input for SD_DAT_3 comes from P1.12 */ +#define LOC_SSP0_MISO_P2_26 ((0)) /**< Input for SSP0_MISO comes from P2.26 */ +#define LOC_SSP0_MISO_P1_23 ((1)) /**< Input for SSP0_MISO comes from P1_23 */ +#define LOC_SSP0_MISO_P0_17 ((2)) /**< Input for SSP0_MISO comes from P0_17 */ +#define LOC_SSP0_MOSI_P2_27 ((0)) /**< Input for SSP0_MOSI comes from P2.27 */ +#define LOC_SSP0_MOSI_P1_24 ((1)) /**< Input for SSP0_MOSI comes from P1.24 */ +#define LOC_SSP0_MOSI_P0_18 ((2)) /**< Input for SSP0_MOSI comes from P0.18 */ +#define LOC_SSP0_SCK_P1_20 ((0)) /**< Input for SSP0_SCK comes from P1.20 */ +#define LOC_SSP0_SCK_P2_22 ((1)) /**< Input for SSP0_SCK comes from P2.22 */ +#define LOC_SSP0_SCK_P0_15 ((2)) /**< Input for SSP0_SCK comes from P0_15 */ +#define LOC_SSP0_SSEL_P2_23 ((0)) /**< Input for SSP0_SSEL comes from P2.23 */ +#define LOC_SSP0_SSEL_P1_21 ((1)) /**< Input for SSP0_SSEL comes from P1.21 */ +#define LOC_SSP0_SSEL_P1_28 ((2)) /**< Input for SSP0_SSEL comes from P1.28 */ +#define LOC_SSP0_SSEL_P0_16 ((3)) /**< Input for SSP0_SSEL comes from P0.16 */ +#define LOC_SSP1_MISO_P0_12 ((0)) /**< Input for SSP1_MISO comes from P0.12 */ +#define LOC_SSP1_MISO_P1_18 ((1)) /**< Input for SSP1_MISO comes from P1.18 */ +#define LOC_SSP1_MISO_P4_22 ((2)) /**< Input for SSP1_MISO comes from P4_22 */ +#define LOC_SSP1_MISO_P0_8 ((3)) /**< Input for SSP1_MISO comes from P0.8 */ +#define LOC_SSP1_MOSI_P0_13 ((0)) /**< Input for SSP1_MOSI comes from P0.13 */ +#define LOC_SSP1_MOSI_P1_22 ((1)) /**< Input for SSP1_MOSI comes from P1.22 */ +#define LOC_SSP1_MOSI_P4_23 ((2)) /**< Input for SSP1_MOSI comes from P4.23 */ +#define LOC_SSP1_MOSI_P0_9 ((3)) /**< Input for SSP1_MOSI comes from P0.9 */ +#define LOC_SSP1_SCK_P1_31 ((0)) /**< Input for SSP1_SCK comes from P1.31 */ +#define LOC_SSP1_SCK_P1_19 ((1)) /**< Input for SSP1_SCK comes from P1.19 */ +#define LOC_SSP1_SCK_P4_20 ((2)) /**< Input for SSP1_SCK comes from P4_20 */ +#define LOC_SSP1_SCK_P0_7 ((3)) /**< Input for SSP1_SCK comes from P0_7 */ +#define LOC_SSP1_SSEL_P0_14 ((0)) /**< Input for SSP1_SSEL comes from P0.14 */ +#define LOC_SSP1_SSEL_P1_26 ((1)) /**< Input for SSP1_SSEL comes from P1.26 */ +#define LOC_SSP1_SSEL_P4_21 ((2)) /**< Input for SSP1_SSEL comes from P4.21 */ +#define LOC_SSP1_SSEL_P0_6 ((3)) /**< Input for SSP1_SSEL comes from P0.6 */ +#define LOC_SSP2_MISO_P1_4 ((1)) /**< Input for SSP2_MISO comes from P1.4 */ +#define LOC_SSP2_MOSI_P1_1 ((1)) /**< Input for SSP2_MOSI comes from P1.1 */ +#define LOC_SSP2_SCK_P1_0 ((1)) /**< Input for SSP2_SCK comes from P1.0 */ +#define LOC_SSP2_SSEL_P1_8 ((1)) /**< Input for SSP2_SSEL comes from P1.8 */ +#define LOC_T0_CAP_0_P3_23 ((0)) /**< Input for T0_CAP_0 comes from P3.23 */ +#define LOC_T0_CAP_0_P1_26 ((1)) /**< Input for T0_CAP_0 comes from P1.26 */ +#define LOC_T0_CAP_1_P3_24 ((0)) /**< Input for T0_CAP_1 comes from P3.24 */ +#define LOC_T0_CAP_1_P1_27 ((1)) /**< Input for T0_CAP_1 comes from P1.27 */ +#define LOC_T1_CAP_0_P1_18 ((0)) /**< Input for T1_CAP_0 comes from P1.18 */ +#define LOC_T1_CAP_0_P3_27 ((1)) /**< Input for T1_CAP_0 comes from P3.27 */ +#define LOC_T1_CAP_1_P3_28 ((0)) /**< Input for T1_CAP_1 comes from P3.28 */ +#define LOC_T1_CAP_1_P1_19 ((1)) /**< Input for T1_CAP_1 comes from P1.19 */ +#define LOC_T2_CAP_0_P2_14 ((0)) /**< Input for T2_CAP_0 comes from P2.14 */ +#define LOC_T2_CAP_0_P2_6 ((1)) /**< Input for T2_CAP_0 comes from P2.6 */ +#define LOC_T2_CAP_0_P0_4 ((2)) /**< Input for T2_CAP_0 comes from P0.4 */ +#define LOC_T2_CAP_0_P1_14 ((3)) /**< Input for T2_CAP_0 comes from P1.14 */ +#define LOC_T2_CAP_1_P2_15 ((0)) /**< Input for T2_CAP_1 comes from P2.15 */ +#define LOC_T2_CAP_1_P0_5 ((1)) /**< Input for T2_CAP_1 comes from P0.5 */ +#define LOC_T3_CAP_0_P0_23 ((0)) /**< Input for T3_CAP_0 comes from P0.23 */ +#define LOC_T3_CAP_0_P2_22 ((1)) /**< Input for T3_CAP_0 comes from P2.22 */ +#define LOC_T3_CAP_0_P1_10 ((2)) /**< Input for T3_CAP_0 comes from P1.10 */ +#define LOC_T3_CAP_1_P0_24 ((0)) /**< Input for T3_CAP_1 comes from P0.24 */ +#define LOC_T3_CAP_1_P2_23 ((1)) /**< Input for T3_CAP_1 comes from P2.23 */ +#define LOC_T3_CAP_1_P1_0 ((2)) /**< Input for T3_CAP_1 comes from P1.0 */ +#define LOC_U0_RXD_P0_1 ((0)) /**< Input for U0_RXD comes from P0.1 */ +#define LOC_U0_RXD_P0_3 ((1)) /**< Input for U0_RXD comes from P0.3 */ +#define LOC_U1_CTS_P0_17 ((0)) /**< Input for U1_CTS comes from P0.17 */ +#define LOC_U1_CTS_P2_8 ((1)) /**< Input for U1_CTS comes from P2.8 */ +#define LOC_U1_CTS_P2_2 ((2)) /**< Input for U1_CTS comes from P2.2 */ +#define LOC_U1_CTS_P3_18 ((3)) /**< Input for U1_CTS comes from P3.18 */ +#define LOC_U1_DCD_P0_18 ((0)) /**< Input for U1_DCD comes from P0.18 */ +#define LOC_U1_DCD_P2_3 ((1)) /**< Input for U1_DCD comes from P2.3 */ +#define LOC_U1_DCD_P3_19 ((2)) /**< Input for U1_DCD comes from P3_19 */ +#define LOC_U1_DSR_P0_19 ((0)) /**< Input for U1_DSR comes from P0.19 */ +#define LOC_U1_DSR_P2_4 ((1)) /**< Input for U1_DSR comes from P2.4 */ +#define LOC_U1_DSR_P3_20 ((2)) /**< Input for U1_DSR comes from P0.19 */ +#define LOC_U1_RI_P0_21 ((0)) /**< Input for U1_RI comes from P0.21 */ +#define LOC_U1_RI_P2_6 ((1)) /**< Input for U1_RI comes from P2.6 */ +#define LOC_U1_RI_P3_22 ((2)) /**< Input for U1_RI comes from P3.22 */ +#define LOC_U1_RXD_P0_16 ((0)) /**< Input for U1_RXD comes from P0.16 */ +#define LOC_U1_RXD_P3_17 ((1)) /**< Input for U1_RXD comes from P3.17 */ +#define LOC_U1_RXD_P2_1 ((2)) /**< Input for U1_RXD comes from P2.1 */ +#define LOC_U2_RXD_P0_11 ((0)) /**< Input for U2_RXD comes from P0.11 */ +#define LOC_U2_RXD_P4_23 ((1)) /**< Input for U2_RXD comes from P4.23 */ +#define LOC_U2_RXD_P2_9 ((2)) /**< Input for U2_RXD comes from P2.9 */ +#define LOC_U3_RXD_P0_26 ((0)) /**< Input for U3_RXD comes from P0.26 */ +#define LOC_U3_RXD_P0_1 ((1)) /**< Input for U3_RXD comes from P0.1 */ +#define LOC_U3_RXD_P4_29 ((2)) /**< Input for U3_RXD comes from P4.29 */ +#define LOC_U3_RXD_P0_3 ((3)) /**< Input for U3_RXD comes from P0.3 */ +#define LOC_U4_RXD_P2_9 ((0)) /**< Input for U4_RXD comes from P2.9 */ +#define LOC_U4_RXD_P5_3 ((1)) /**< Input for U4_RXD comes from P5.3 */ +#define LOC_USB_SCL_P0_28 ((0)) /**< Input for USB_SCL comes from P0.28 */ +#define LOC_USB_SCL_P1_28 ((1)) /**< Input for USB_SCL comes from P1.28 */ +#define LOC_USB_SDA_P0_27 ((0)) /**< Input for USB_SDA comes from P0.27 */ +#define LOC_USB_SDA_P1_29 ((1)) /**< Input for USB_SDA comes from P1.29 */ /** * @} @@ -206,32 +206,32 @@ /** @defgroup PINSEL_Public_Types PINSEL Public Types * @{ */ - + typedef enum { - PINSEL_BASICMODE_PLAINOUT = 0, /**< Plain output */ - PINSEL_BASICMODE_PULLDOWN, /**< Pull-down enabled */ - PINSEL_BASICMODE_PULLUP, /**< Pull-up enabled (default) */ - PINSEL_BASICMODE_REPEATER /**< Repeater mode */ + PINSEL_BASICMODE_PLAINOUT = 0, /**< Plain output */ + PINSEL_BASICMODE_PULLDOWN, /**< Pull-down enabled */ + PINSEL_BASICMODE_PULLUP, /**< Pull-up enabled (default) */ + PINSEL_BASICMODE_REPEATER /**< Repeater mode */ }PinSel_BasicMode; typedef enum { - /** Fast mode (400 kHz clock rate) and standard (100 kHz clock rate) */ - PINSEL_I2CMODE_FAST_STANDARD = 0, - /** Open drain I/O (not I2C). No glitch filter, 3 mA typical output drive */ - PINSEL_I2CMODE_OPENDRAINIO, - /** Fast Mode Plus I2C. This includes a filter for <50 ns glitches */ - PINSEL_I2CMODE_FASTMODEPLUS, - /** High drive open drain I/O (not I2C). No glitch filter, 20 mA typical output drive */ - PINSEL_I2CMODE_HIDRIVE_OPENDRAIN + /** Fast mode (400 kHz clock rate) and standard (100 kHz clock rate) */ + PINSEL_I2CMODE_FAST_STANDARD = 0, + /** Open drain I/O (not I2C). No glitch filter, 3 mA typical output drive */ + PINSEL_I2CMODE_OPENDRAINIO, + /** Fast Mode Plus I2C. This includes a filter for <50 ns glitches */ + PINSEL_I2CMODE_FASTMODEPLUS, + /** High drive open drain I/O (not I2C). No glitch filter, 20 mA typical output drive */ + PINSEL_I2CMODE_HIDRIVE_OPENDRAIN }PinSel_I2cMode; /** * @} */ - + /* Public Functions ----------------------------------------------------------- */ /** @defgroup PINSEL_Public_Functions diff --git a/bsp/lpc178x/drivers/lpc177x_8x_uart.c b/bsp/lpc178x/drivers/lpc177x_8x_uart.c index 4e0f4e1d7c..7661a32b13 100644 --- a/bsp/lpc178x/drivers/lpc177x_8x_uart.c +++ b/bsp/lpc178x/drivers/lpc177x_8x_uart.c @@ -1,13 +1,13 @@ /********************************************************************** -* $Id$ lpc177x_8x_uart.c 2011-06-02 +* $Id$ lpc177x_8x_uart.c 2011-06-02 *//** -* @file lpc177x_8x_uart.c -* @brief Contains all functions support for UART firmware library -* on LPC177x_8x -* @version 1.0 -* @date 02. June. 2011 -* @author NXP MCU SW Application Team -* +* @file lpc177x_8x_uart.c +* @brief Contains all functions support for UART firmware library +* on LPC177x_8x +* @version 1.0 +* @date 02. June. 2011 +* @author NXP MCU SW Application Team +* * Copyright(C) 2011, NXP Semiconductor * All rights reserved. * @@ -39,127 +39,127 @@ static Status uart_set_divisors(LPC_UART_TypeDef *UARTx, uint32_t baudrate); /*********************************************************************//** - * @brief Determines best dividers to get a target clock rate - * @param[in] UARTx Pointer to selected UART peripheral, should be: - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @param[in] baudrate Desired UART baud rate. - * @return Error status, could be: - * - SUCCESS - * - ERROR + * @brief Determines best dividers to get a target clock rate + * @param[in] UARTx Pointer to selected UART peripheral, should be: + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @param[in] baudrate Desired UART baud rate. + * @return Error status, could be: + * - SUCCESS + * - ERROR **********************************************************************/ static Status uart_set_divisors(LPC_UART_TypeDef *UARTx, uint32_t baudrate) { - Status errorStatus = ERROR; - - uint32_t uClk; - uint32_t d, m, bestd, bestm, tmp; - uint64_t best_divisor, divisor; - uint32_t current_error, best_error; - uint32_t recalcbaud; - - /* get UART block clock */ - uClk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER); - - /* In the Uart IP block, baud rate is calculated using FDR and DLL-DLM registers - * The formula is : - * BaudRate= uClk * (mulFracDiv/(mulFracDiv+dividerAddFracDiv) / (16 * (DLL) - * It involves floating point calculations. That's the reason the formulae are adjusted with - * Multiply and divide method.*/ - - /* The value of mulFracDiv and dividerAddFracDiv should comply to the following expressions: - * 0 < mulFracDiv <= 15, 0 <= dividerAddFracDiv <= 15 */ - best_error = 0xFFFFFFFF; /* Worst case */ - bestd = 0; - bestm = 0; - best_divisor = 0; - - for (m = 1 ; m <= 15 ;m++) - { - for (d = 0 ; d < m ; d++) - { - divisor = ((uint64_t)uClk << 28)*m / (baudrate*(m+d)); - current_error = divisor & 0xFFFFFFFF; - - tmp = divisor>>32; - - /* Adjust error */ - if(current_error > ((uint32_t)1<<31)) - { - current_error = -current_error; - tmp++; - } - - /* Out of range */ - if(tmp < 1 || tmp > 65536) - continue; - - if( current_error < best_error) - { - best_error = current_error; - best_divisor = tmp; - bestd = d; - bestm = m; - - if(best_error == 0) - break; - } - } /* end of inner for loop */ - - if (best_error == 0) - break; - } /* end of outer for loop */ - - /* can not find best match */ - if(best_divisor == 0) - return ERROR; - - recalcbaud = (uClk >> 4) * bestm / (best_divisor * (bestm + bestd)); - - /* reuse best_error to evaluate baud error*/ - if(baudrate > recalcbaud) - best_error = baudrate - recalcbaud; - else - best_error = recalcbaud -baudrate; - - best_error = best_error * 100 / baudrate; - - if (best_error < UART_ACCEPTED_BAUDRATE_ERROR) - { - if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - ((LPC_UART1_TypeDef *)UARTx)->LCR |= UART_LCR_DLAB_EN; - - ((LPC_UART1_TypeDef *)UARTx)->DLM = UART_LOAD_DLM(best_divisor); - - ((LPC_UART1_TypeDef *)UARTx)->DLL = UART_LOAD_DLL(best_divisor); - - /* Then reset DLAB bit */ - ((LPC_UART1_TypeDef *)UARTx)->LCR &= (~UART_LCR_DLAB_EN) & UART_LCR_BITMASK; - - ((LPC_UART1_TypeDef *)UARTx)->FDR = (UART_FDR_MULVAL(bestm) - | UART_FDR_DIVADDVAL(bestd)) & UART_FDR_BITMASK; - } - else - { - UARTx->LCR |= UART_LCR_DLAB_EN; - - UARTx->DLM = UART_LOAD_DLM(best_divisor); - - UARTx->DLL = UART_LOAD_DLL(best_divisor); - - /* Then reset DLAB bit */ - UARTx->LCR &= (~UART_LCR_DLAB_EN) & UART_LCR_BITMASK; - - UARTx->FDR = (UART_FDR_MULVAL(bestm) \ - | UART_FDR_DIVADDVAL(bestd)) & UART_FDR_BITMASK; - } - errorStatus = SUCCESS; - } - - return errorStatus; + Status errorStatus = ERROR; + + uint32_t uClk; + uint32_t d, m, bestd, bestm, tmp; + uint64_t best_divisor, divisor; + uint32_t current_error, best_error; + uint32_t recalcbaud; + + /* get UART block clock */ + uClk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER); + + /* In the Uart IP block, baud rate is calculated using FDR and DLL-DLM registers + * The formula is : + * BaudRate= uClk * (mulFracDiv/(mulFracDiv+dividerAddFracDiv) / (16 * (DLL) + * It involves floating point calculations. That's the reason the formulae are adjusted with + * Multiply and divide method.*/ + + /* The value of mulFracDiv and dividerAddFracDiv should comply to the following expressions: + * 0 < mulFracDiv <= 15, 0 <= dividerAddFracDiv <= 15 */ + best_error = 0xFFFFFFFF; /* Worst case */ + bestd = 0; + bestm = 0; + best_divisor = 0; + + for (m = 1 ; m <= 15 ;m++) + { + for (d = 0 ; d < m ; d++) + { + divisor = ((uint64_t)uClk << 28)*m / (baudrate*(m+d)); + current_error = divisor & 0xFFFFFFFF; + + tmp = divisor>>32; + + /* Adjust error */ + if(current_error > ((uint32_t)1<<31)) + { + current_error = -current_error; + tmp++; + } + + /* Out of range */ + if(tmp < 1 || tmp > 65536) + continue; + + if( current_error < best_error) + { + best_error = current_error; + best_divisor = tmp; + bestd = d; + bestm = m; + + if(best_error == 0) + break; + } + } /* end of inner for loop */ + + if (best_error == 0) + break; + } /* end of outer for loop */ + + /* can not find best match */ + if(best_divisor == 0) + return ERROR; + + recalcbaud = (uClk >> 4) * bestm / (best_divisor * (bestm + bestd)); + + /* reuse best_error to evaluate baud error*/ + if(baudrate > recalcbaud) + best_error = baudrate - recalcbaud; + else + best_error = recalcbaud -baudrate; + + best_error = best_error * 100 / baudrate; + + if (best_error < UART_ACCEPTED_BAUDRATE_ERROR) + { + if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + ((LPC_UART1_TypeDef *)UARTx)->LCR |= UART_LCR_DLAB_EN; + + ((LPC_UART1_TypeDef *)UARTx)->DLM = UART_LOAD_DLM(best_divisor); + + ((LPC_UART1_TypeDef *)UARTx)->DLL = UART_LOAD_DLL(best_divisor); + + /* Then reset DLAB bit */ + ((LPC_UART1_TypeDef *)UARTx)->LCR &= (~UART_LCR_DLAB_EN) & UART_LCR_BITMASK; + + ((LPC_UART1_TypeDef *)UARTx)->FDR = (UART_FDR_MULVAL(bestm) + | UART_FDR_DIVADDVAL(bestd)) & UART_FDR_BITMASK; + } + else + { + UARTx->LCR |= UART_LCR_DLAB_EN; + + UARTx->DLM = UART_LOAD_DLM(best_divisor); + + UARTx->DLL = UART_LOAD_DLL(best_divisor); + + /* Then reset DLAB bit */ + UARTx->LCR &= (~UART_LCR_DLAB_EN) & UART_LCR_BITMASK; + + UARTx->FDR = (UART_FDR_MULVAL(bestm) \ + | UART_FDR_DIVADDVAL(bestd)) & UART_FDR_BITMASK; + } + errorStatus = SUCCESS; + } + + return errorStatus; } /* End of Private Functions ---------------------------------------------------- */ @@ -171,1192 +171,1192 @@ static Status uart_set_divisors(LPC_UART_TypeDef *UARTx, uint32_t baudrate) */ /* UART Init/DeInit functions -------------------------------------------------*/ /********************************************************************//** - * @brief Initializes the UARTx peripheral according to the specified + * @brief Initializes the UARTx peripheral according to the specified * parameters in the UART_ConfigStruct. - * @param[in] UARTx UART peripheral selected, should be: - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * - LPC_UART4: UART4 peripheral - * @param[in] UART_ConfigStruct Pointer to a UART_CFG_Type structure + * @param[in] UARTx UART peripheral selected, should be: + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * - LPC_UART4: UART4 peripheral + * @param[in] UART_ConfigStruct Pointer to a UART_CFG_Type structure * that contains the configuration information for the * specified UART peripheral. - * @return None + * @return None *********************************************************************/ void UART_Init(LPC_UART_TypeDef *UARTx, UART_CFG_Type *UART_ConfigStruct) { - uint32_t tmp; - - if(UARTx == LPC_UART0) - { - /* Set up clock and power for UART module */ - CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART0, ENABLE); - } - if(((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - /* Set up clock and power for UART module */ - CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART1, ENABLE); - } - if(UARTx == LPC_UART2) - { - /* Set up clock and power for UART module */ - CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART2, ENABLE); - } - if(UARTx == LPC_UART3) - { - /* Set up clock and power for UART module */ - CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART3, ENABLE); - } - - /* FIFOs are empty */ - UARTx->FCR = ( UART_FCR_FIFO_EN | UART_FCR_RX_RS | UART_FCR_TX_RS); - - // Disable FIFO - UARTx->FCR = 0; - - // Dummy reading - while (UARTx->LSR & UART_LSR_RDR) - { - tmp = UARTx->RBR; - } - - UARTx->TER = UART_TER_TXEN; - - // Wait for current transmit complete - while (!(UARTx->LSR & UART_LSR_THRE)); - - // Disable Tx - UARTx->TER = 0; - - // Disable interrupt - UARTx->IER = 0; - - // Set LCR to default state - UARTx->LCR = 0; - - // Set ACR to default state - UARTx->ACR = 0; - - // Set RS485 control to default state - UARTx->RS485CTRL = 0; - - // Set RS485 delay timer to default state - UARTx->RS485DLY = 0; - - // Set RS485 addr match to default state - UARTx->ADRMATCH = 0; - - // Dummy reading - tmp = UARTx->LSR; - - if(((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - // Set Modem Control to default state - ((LPC_UART1_TypeDef *)UARTx)->MCR = 0; - - //Dummy Reading to Clear Status - tmp = ((LPC_UART1_TypeDef *)UARTx)->MSR; - } - else - { - // Set IrDA to default state for all UART other than UART1 - UARTx->ICR = 0; - } - - // Set Line Control register ---------------------------- - - uart_set_divisors(UARTx, (UART_ConfigStruct->Baud_rate)); - - if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - tmp = (((LPC_UART1_TypeDef *)UARTx)->LCR & (UART_LCR_DLAB_EN | UART_LCR_BREAK_EN)) \ - & UART_LCR_BITMASK; - } - else - { - tmp = (UARTx->LCR & (UART_LCR_DLAB_EN | UART_LCR_BREAK_EN)) & UART_LCR_BITMASK; - } - - switch (UART_ConfigStruct->Databits) - { - case UART_DATABIT_5: - tmp |= UART_LCR_WLEN5; - break; - - case UART_DATABIT_6: - tmp |= UART_LCR_WLEN6; - break; - - case UART_DATABIT_7: - tmp |= UART_LCR_WLEN7; - break; - - case UART_DATABIT_8: - - default: - tmp |= UART_LCR_WLEN8; - break; - } - - if (UART_ConfigStruct->Parity == UART_PARITY_NONE) - { - // Do nothing... - } - else - { - tmp |= UART_LCR_PARITY_EN; - switch (UART_ConfigStruct->Parity) - { - case UART_PARITY_ODD: - tmp |= UART_LCR_PARITY_ODD; - break; - - case UART_PARITY_EVEN: - tmp |= UART_LCR_PARITY_EVEN; - break; - - case UART_PARITY_SP_1: - tmp |= UART_LCR_PARITY_F_1; - break; - - case UART_PARITY_SP_0: - tmp |= UART_LCR_PARITY_F_0; - break; - - default: - break; - } - } - - switch (UART_ConfigStruct->Stopbits) - { - case UART_STOPBIT_2: - tmp |= UART_LCR_STOPBIT_SEL; - break; - - case UART_STOPBIT_1: - - default: - // Do no thing - break; - } - - - // Write back to LCR, configure FIFO and Disable Tx - if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - ((LPC_UART1_TypeDef *)UARTx)->LCR = (uint8_t)(tmp & UART_LCR_BITMASK); - } - else - { - UARTx->LCR = (uint8_t)(tmp & UART_LCR_BITMASK); - } + uint32_t tmp; + + if(UARTx == LPC_UART0) + { + /* Set up clock and power for UART module */ + CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART0, ENABLE); + } + if(((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + /* Set up clock and power for UART module */ + CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART1, ENABLE); + } + if(UARTx == LPC_UART2) + { + /* Set up clock and power for UART module */ + CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART2, ENABLE); + } + if(UARTx == LPC_UART3) + { + /* Set up clock and power for UART module */ + CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART3, ENABLE); + } + + /* FIFOs are empty */ + UARTx->FCR = ( UART_FCR_FIFO_EN | UART_FCR_RX_RS | UART_FCR_TX_RS); + + // Disable FIFO + UARTx->FCR = 0; + + // Dummy reading + while (UARTx->LSR & UART_LSR_RDR) + { + tmp = UARTx->RBR; + } + + UARTx->TER = UART_TER_TXEN; + + // Wait for current transmit complete + while (!(UARTx->LSR & UART_LSR_THRE)); + + // Disable Tx + UARTx->TER = 0; + + // Disable interrupt + UARTx->IER = 0; + + // Set LCR to default state + UARTx->LCR = 0; + + // Set ACR to default state + UARTx->ACR = 0; + + // Set RS485 control to default state + UARTx->RS485CTRL = 0; + + // Set RS485 delay timer to default state + UARTx->RS485DLY = 0; + + // Set RS485 addr match to default state + UARTx->ADRMATCH = 0; + + // Dummy reading + tmp = UARTx->LSR; + + if(((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + // Set Modem Control to default state + ((LPC_UART1_TypeDef *)UARTx)->MCR = 0; + + //Dummy Reading to Clear Status + tmp = ((LPC_UART1_TypeDef *)UARTx)->MSR; + } + else + { + // Set IrDA to default state for all UART other than UART1 + UARTx->ICR = 0; + } + + // Set Line Control register ---------------------------- + + uart_set_divisors(UARTx, (UART_ConfigStruct->Baud_rate)); + + if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + tmp = (((LPC_UART1_TypeDef *)UARTx)->LCR & (UART_LCR_DLAB_EN | UART_LCR_BREAK_EN)) \ + & UART_LCR_BITMASK; + } + else + { + tmp = (UARTx->LCR & (UART_LCR_DLAB_EN | UART_LCR_BREAK_EN)) & UART_LCR_BITMASK; + } + + switch (UART_ConfigStruct->Databits) + { + case UART_DATABIT_5: + tmp |= UART_LCR_WLEN5; + break; + + case UART_DATABIT_6: + tmp |= UART_LCR_WLEN6; + break; + + case UART_DATABIT_7: + tmp |= UART_LCR_WLEN7; + break; + + case UART_DATABIT_8: + + default: + tmp |= UART_LCR_WLEN8; + break; + } + + if (UART_ConfigStruct->Parity == UART_PARITY_NONE) + { + // Do nothing... + } + else + { + tmp |= UART_LCR_PARITY_EN; + switch (UART_ConfigStruct->Parity) + { + case UART_PARITY_ODD: + tmp |= UART_LCR_PARITY_ODD; + break; + + case UART_PARITY_EVEN: + tmp |= UART_LCR_PARITY_EVEN; + break; + + case UART_PARITY_SP_1: + tmp |= UART_LCR_PARITY_F_1; + break; + + case UART_PARITY_SP_0: + tmp |= UART_LCR_PARITY_F_0; + break; + + default: + break; + } + } + + switch (UART_ConfigStruct->Stopbits) + { + case UART_STOPBIT_2: + tmp |= UART_LCR_STOPBIT_SEL; + break; + + case UART_STOPBIT_1: + + default: + // Do no thing + break; + } + + + // Write back to LCR, configure FIFO and Disable Tx + if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + ((LPC_UART1_TypeDef *)UARTx)->LCR = (uint8_t)(tmp & UART_LCR_BITMASK); + } + else + { + UARTx->LCR = (uint8_t)(tmp & UART_LCR_BITMASK); + } } /*********************************************************************//** - * @brief De-initializes the UARTx peripheral registers to their + * @brief De-initializes the UARTx peripheral registers to their * default reset values. - * @param[in] UARTx UART peripheral selected, should be: - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @return None + * @param[in] UARTx UART peripheral selected, should be: + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @return None **********************************************************************/ void UART_DeInit(LPC_UART_TypeDef* UARTx) { - UART_TxCmd(UARTx, DISABLE); - - if (UARTx == LPC_UART0) - { - /* Set up clock and power for UART module */ - CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART0, DISABLE); - } - - if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - /* Set up clock and power for UART module */ - CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART1, DISABLE); - } - - if (UARTx == LPC_UART2) - { - /* Set up clock and power for UART module */ - CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART2, DISABLE); - } - - if (UARTx == LPC_UART3) - { - /* Set up clock and power for UART module */ - CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART3, DISABLE); - } + UART_TxCmd(UARTx, DISABLE); + + if (UARTx == LPC_UART0) + { + /* Set up clock and power for UART module */ + CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART0, DISABLE); + } + + if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + /* Set up clock and power for UART module */ + CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART1, DISABLE); + } + + if (UARTx == LPC_UART2) + { + /* Set up clock and power for UART module */ + CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART2, DISABLE); + } + + if (UARTx == LPC_UART3) + { + /* Set up clock and power for UART module */ + CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART3, DISABLE); + } } /*****************************************************************************//** -* @brief Fills each UART_InitStruct member with its default value: -* - 9600 bps -* - 8-bit data -* - 1 Stopbit -* - None Parity -* @param[in] UART_InitStruct Pointer to a UART_CFG_Type structure +* @brief Fills each UART_InitStruct member with its default value: +* - 9600 bps +* - 8-bit data +* - 1 Stopbit +* - None Parity +* @param[in] UART_InitStruct Pointer to a UART_CFG_Type structure * which will be initialized. -* @return None +* @return None *******************************************************************************/ void UART_ConfigStructInit(UART_CFG_Type *UART_InitStruct) { - UART_InitStruct->Baud_rate = 9600; + UART_InitStruct->Baud_rate = 9600; - UART_InitStruct->Databits = UART_DATABIT_8; + UART_InitStruct->Databits = UART_DATABIT_8; - UART_InitStruct->Parity = UART_PARITY_NONE; + UART_InitStruct->Parity = UART_PARITY_NONE; - UART_InitStruct->Stopbits = UART_STOPBIT_1; + UART_InitStruct->Stopbits = UART_STOPBIT_1; } /* UART Send/Recieve functions -------------------------------------------------*/ /*********************************************************************//** - * @brief Transmit a single data through UART peripheral - * @param[in] UARTx UART peripheral selected, should be: - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @param[in] Data Data to transmit (must be 8-bit long) - * @return None + * @brief Transmit a single data through UART peripheral + * @param[in] UARTx UART peripheral selected, should be: + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @param[in] Data Data to transmit (must be 8-bit long) + * @return None **********************************************************************/ void UART_SendByte(LPC_UART_TypeDef* UARTx, uint8_t Data) { - if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - ((LPC_UART1_TypeDef *)UARTx)->THR = Data & UART_THR_MASKBIT; - } - else - { - UARTx->THR = Data & UART_THR_MASKBIT; - } + if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + ((LPC_UART1_TypeDef *)UARTx)->THR = Data & UART_THR_MASKBIT; + } + else + { + UARTx->THR = Data & UART_THR_MASKBIT; + } } /*********************************************************************//** - * @brief Receive a single data from UART peripheral - * @param[in] UARTx UART peripheral selected, should be: - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @return Data received + * @brief Receive a single data from UART peripheral + * @param[in] UARTx UART peripheral selected, should be: + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @return Data received **********************************************************************/ uint8_t UART_ReceiveByte(LPC_UART_TypeDef* UARTx) { - if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - return (((LPC_UART1_TypeDef *)UARTx)->RBR & UART_RBR_MASKBIT); - } - else - { - return (UARTx->RBR & UART_RBR_MASKBIT); - } + if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + return (((LPC_UART1_TypeDef *)UARTx)->RBR & UART_RBR_MASKBIT); + } + else + { + return (UARTx->RBR & UART_RBR_MASKBIT); + } } /*********************************************************************//** - * @brief Send a block of data via UART peripheral - * @param[in] UARTx Selected UART peripheral used to send data, should be: - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @param[in] txbuf Pointer to Transmit buffer - * @param[in] buflen Length of Transmit buffer - * @param[in] flag Flag used in UART transfer, should be - * NONE_BLOCKING or BLOCKING - * @return Number of bytes sent. + * @brief Send a block of data via UART peripheral + * @param[in] UARTx Selected UART peripheral used to send data, should be: + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @param[in] txbuf Pointer to Transmit buffer + * @param[in] buflen Length of Transmit buffer + * @param[in] flag Flag used in UART transfer, should be + * NONE_BLOCKING or BLOCKING + * @return Number of bytes sent. * * Note: when using UART in BLOCKING mode, a time-out condition is used * via defined symbol UART_BLOCKING_TIMEOUT. **********************************************************************/ uint32_t UART_Send(LPC_UART_TypeDef *UARTx, uint8_t *txbuf, - uint32_t buflen, TRANSFER_BLOCK_Type flag) + uint32_t buflen, TRANSFER_BLOCK_Type flag) { - uint32_t bToSend, bSent, timeOut, fifo_cnt; - uint8_t *pChar = txbuf; + uint32_t bToSend, bSent, timeOut, fifo_cnt; + uint8_t *pChar = txbuf; - bToSend = buflen; + bToSend = buflen; - // blocking mode - if (flag == BLOCKING) - { - bSent = 0; - while (bToSend) - { - timeOut = UART_BLOCKING_TIMEOUT; + // blocking mode + if (flag == BLOCKING) + { + bSent = 0; + while (bToSend) + { + timeOut = UART_BLOCKING_TIMEOUT; - // Wait for THR empty with timeout - while (!(UARTx->LSR & UART_LSR_THRE)) - { - if (timeOut == 0) - break; + // Wait for THR empty with timeout + while (!(UARTx->LSR & UART_LSR_THRE)) + { + if (timeOut == 0) + break; - timeOut--; - } + timeOut--; + } - // Time out! - if(timeOut == 0) - break; + // Time out! + if(timeOut == 0) + break; - fifo_cnt = UART_TX_FIFO_SIZE; + fifo_cnt = UART_TX_FIFO_SIZE; - while (fifo_cnt && bToSend) - { - UART_SendByte(UARTx, (*pChar++)); + while (fifo_cnt && bToSend) + { + UART_SendByte(UARTx, (*pChar++)); - fifo_cnt--; + fifo_cnt--; - bToSend--; + bToSend--; - bSent++; - } - } - } + bSent++; + } + } + } - // None blocking mode - else - { - bSent = 0; - while (bToSend) - { - if (bToSend == 0) - break; + // None blocking mode + else + { + bSent = 0; + while (bToSend) + { + if (bToSend == 0) + break; - if (!(UARTx->LSR & UART_LSR_THRE)) - { - break; - } + if (!(UARTx->LSR & UART_LSR_THRE)) + { + break; + } - fifo_cnt = UART_TX_FIFO_SIZE; + fifo_cnt = UART_TX_FIFO_SIZE; - while (fifo_cnt && bToSend) - { - UART_SendByte(UARTx, (*pChar++)); + while (fifo_cnt && bToSend) + { + UART_SendByte(UARTx, (*pChar++)); - bToSend--; + bToSend--; - fifo_cnt--; + fifo_cnt--; - bSent++; - } - } - } + bSent++; + } + } + } - return bSent; + return bSent; } /*********************************************************************//** - * @brief Receive a block of data via UART peripheral - * @param[in] UARTx Selected UART peripheral used to send data, - * should be: - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @param[out] rxbuf Pointer to Received buffer - * @param[in] buflen Length of Received buffer - * @param[in] flag Flag mode, should be NONE_BLOCKING or BLOCKING - - * @return Number of bytes received + * @brief Receive a block of data via UART peripheral + * @param[in] UARTx Selected UART peripheral used to send data, + * should be: + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @param[out] rxbuf Pointer to Received buffer + * @param[in] buflen Length of Received buffer + * @param[in] flag Flag mode, should be NONE_BLOCKING or BLOCKING + + * @return Number of bytes received * * Note: when using UART in BLOCKING mode, a time-out condition is used * via defined symbol UART_BLOCKING_TIMEOUT. **********************************************************************/ uint32_t UART_Receive(LPC_UART_TypeDef *UARTx, uint8_t *rxbuf, - uint32_t buflen, TRANSFER_BLOCK_Type flag) + uint32_t buflen, TRANSFER_BLOCK_Type flag) { - uint32_t bToRecv, bRecv, timeOut; - uint8_t *pChar = rxbuf; - - bToRecv = buflen; - - // Blocking mode - if (flag == BLOCKING) - { - bRecv = 0; - while (bToRecv) - { - timeOut = UART_BLOCKING_TIMEOUT; - while (!(UARTx->LSR & UART_LSR_RDR)) - { - if (timeOut == 0) - break; - - timeOut--; - } - - // Time out! - if(timeOut == 0) - break; - - // Get data from the buffer - (*pChar++) = UART_ReceiveByte(UARTx); - - bToRecv--; - - bRecv++; - } - } - // None blocking mode - else - { - bRecv = 0; - while (bToRecv) - { - if (!(UARTx->LSR & UART_LSR_RDR)) - { - break; - } - else - { - (*pChar++) = UART_ReceiveByte(UARTx); - - bRecv++; - - bToRecv--; - } - } - } - - return bRecv; + uint32_t bToRecv, bRecv, timeOut; + uint8_t *pChar = rxbuf; + + bToRecv = buflen; + + // Blocking mode + if (flag == BLOCKING) + { + bRecv = 0; + while (bToRecv) + { + timeOut = UART_BLOCKING_TIMEOUT; + while (!(UARTx->LSR & UART_LSR_RDR)) + { + if (timeOut == 0) + break; + + timeOut--; + } + + // Time out! + if(timeOut == 0) + break; + + // Get data from the buffer + (*pChar++) = UART_ReceiveByte(UARTx); + + bToRecv--; + + bRecv++; + } + } + // None blocking mode + else + { + bRecv = 0; + while (bToRecv) + { + if (!(UARTx->LSR & UART_LSR_RDR)) + { + break; + } + else + { + (*pChar++) = UART_ReceiveByte(UARTx); + + bRecv++; + + bToRecv--; + } + } + } + + return bRecv; } /*********************************************************************//** - * @brief Force BREAK character on UART line, output pin UARTx TXD is - forced to logic 0. - * @param[in] UARTx UART peripheral selected, should be: - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @return None + * @brief Force BREAK character on UART line, output pin UARTx TXD is + forced to logic 0. + * @param[in] UARTx UART peripheral selected, should be: + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @return None **********************************************************************/ void UART_ForceBreak(LPC_UART_TypeDef* UARTx) { - if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - ((LPC_UART1_TypeDef *)UARTx)->LCR |= UART_LCR_BREAK_EN; - } - else - { - UARTx->LCR |= UART_LCR_BREAK_EN; - } + if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + ((LPC_UART1_TypeDef *)UARTx)->LCR |= UART_LCR_BREAK_EN; + } + else + { + UARTx->LCR |= UART_LCR_BREAK_EN; + } } /********************************************************************//** - * @brief Enable or disable specified UART interrupt. - * @param[in] UARTx UART peripheral selected, should be - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @param[in] UARTIntCfg Specifies the interrupt flag, - * should be one of the following: - - UART_INTCFG_RBR : RBR Interrupt enable - - UART_INTCFG_THRE : THR Interrupt enable - - UART_INTCFG_RLS : RX line status interrupt enable - - UART1_INTCFG_MS : Modem status interrupt enable (UART1 only) - - UART1_INTCFG_CTS : CTS1 signal transition interrupt enable (UART1 only) - - UART_INTCFG_ABEO : Enables the end of auto-baud interrupt - - UART_INTCFG_ABTO : Enables the auto-baud time-out interrupt - * @param[in] NewState New state of specified UART interrupt type, - * should be: - * - ENALBE: Enable this UART interrupt type. -* - DISALBE: Disable this UART interrupt type. - * @return None + * @brief Enable or disable specified UART interrupt. + * @param[in] UARTx UART peripheral selected, should be + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @param[in] UARTIntCfg Specifies the interrupt flag, + * should be one of the following: + - UART_INTCFG_RBR : RBR Interrupt enable + - UART_INTCFG_THRE : THR Interrupt enable + - UART_INTCFG_RLS : RX line status interrupt enable + - UART1_INTCFG_MS : Modem status interrupt enable (UART1 only) + - UART1_INTCFG_CTS : CTS1 signal transition interrupt enable (UART1 only) + - UART_INTCFG_ABEO : Enables the end of auto-baud interrupt + - UART_INTCFG_ABTO : Enables the auto-baud time-out interrupt + * @param[in] NewState New state of specified UART interrupt type, + * should be: + * - ENALBE: Enable this UART interrupt type. +* - DISALBE: Disable this UART interrupt type. + * @return None *********************************************************************/ void UART_IntConfig(LPC_UART_TypeDef *UARTx, UART_INT_Type UARTIntCfg, FunctionalState NewState) { - uint32_t tmp; - - switch(UARTIntCfg) - { - case UART_INTCFG_RBR: - tmp = UART_IER_RBRINT_EN; - break; - - case UART_INTCFG_THRE: - tmp = UART_IER_THREINT_EN; - break; - - case UART_INTCFG_RLS: - tmp = UART_IER_RLSINT_EN; - break; - - case UART1_INTCFG_MS: - tmp = UART1_IER_MSINT_EN; - break; - - case UART1_INTCFG_CTS: - tmp = UART1_IER_CTSINT_EN; - break; - - case UART_INTCFG_ABEO: - tmp = UART_IER_ABEOINT_EN; - break; - - case UART_INTCFG_ABTO: - tmp = UART_IER_ABTOINT_EN; - break; - } - - if (NewState == ENABLE) - { - if ((LPC_UART1_TypeDef *) UARTx == LPC_UART1) - { - ((LPC_UART1_TypeDef *)UARTx)->IER |= tmp; - } - else - { - UARTx->IER |= tmp; - } - } - else - { - if ((LPC_UART1_TypeDef *) UARTx == LPC_UART1) - { - ((LPC_UART1_TypeDef *)UARTx)->IER &= (~tmp) & UART1_IER_BITMASK; - } - else - { - UARTx->IER &= (~tmp) & UART_IER_BITMASK; - } - } + uint32_t tmp; + + switch(UARTIntCfg) + { + case UART_INTCFG_RBR: + tmp = UART_IER_RBRINT_EN; + break; + + case UART_INTCFG_THRE: + tmp = UART_IER_THREINT_EN; + break; + + case UART_INTCFG_RLS: + tmp = UART_IER_RLSINT_EN; + break; + + case UART1_INTCFG_MS: + tmp = UART1_IER_MSINT_EN; + break; + + case UART1_INTCFG_CTS: + tmp = UART1_IER_CTSINT_EN; + break; + + case UART_INTCFG_ABEO: + tmp = UART_IER_ABEOINT_EN; + break; + + case UART_INTCFG_ABTO: + tmp = UART_IER_ABTOINT_EN; + break; + } + + if (NewState == ENABLE) + { + if ((LPC_UART1_TypeDef *) UARTx == LPC_UART1) + { + ((LPC_UART1_TypeDef *)UARTx)->IER |= tmp; + } + else + { + UARTx->IER |= tmp; + } + } + else + { + if ((LPC_UART1_TypeDef *) UARTx == LPC_UART1) + { + ((LPC_UART1_TypeDef *)UARTx)->IER &= (~tmp) & UART1_IER_BITMASK; + } + else + { + UARTx->IER &= (~tmp) & UART_IER_BITMASK; + } + } } /********************************************************************//** - * @brief Get current value of Line Status register in UART peripheral. - * @param[in] UARTx UART peripheral selected, should be: - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @return Current value of Line Status register in UART peripheral. - * Note: The return value of this function must be ANDed with each member in - * UART_LS_Type enumeration to determine current flag status - * corresponding to each Line status type. Because some flags in - * Line Status register will be cleared after reading, the next reading - * Line Status register could not be correct. So this function used to - * read Line status register in one time only, then the return value - * used to check all flags. + * @brief Get current value of Line Status register in UART peripheral. + * @param[in] UARTx UART peripheral selected, should be: + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @return Current value of Line Status register in UART peripheral. + * Note: The return value of this function must be ANDed with each member in + * UART_LS_Type enumeration to determine current flag status + * corresponding to each Line status type. Because some flags in + * Line Status register will be cleared after reading, the next reading + * Line Status register could not be correct. So this function used to + * read Line status register in one time only, then the return value + * used to check all flags. *********************************************************************/ uint8_t UART_GetLineStatus(LPC_UART_TypeDef* UARTx) { - if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - return ((((LPC_UART1_TypeDef *)LPC_UART1)->LSR) & UART_LSR_BITMASK); - } - else - { - return ((UARTx->LSR) & UART_LSR_BITMASK); - } + if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + return ((((LPC_UART1_TypeDef *)LPC_UART1)->LSR) & UART_LSR_BITMASK); + } + else + { + return ((UARTx->LSR) & UART_LSR_BITMASK); + } } /********************************************************************//** - * @brief Get Interrupt Identification value - * @param[in] UARTx UART peripheral selected, should be: - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @return Current value of UART UIIR register in UART peripheral. + * @brief Get Interrupt Identification value + * @param[in] UARTx UART peripheral selected, should be: + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @return Current value of UART UIIR register in UART peripheral. *********************************************************************/ uint32_t UART_GetIntId(LPC_UART_TypeDef* UARTx) { - return (UARTx->IIR & 0x03CF); + return (UARTx->IIR & 0x03CF); } /*********************************************************************//** - * @brief Check whether if UART is busy or not - * @param[in] UARTx UART peripheral selected, should be: - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @return RESET if UART is not busy, otherwise return SET. + * @brief Check whether if UART is busy or not + * @param[in] UARTx UART peripheral selected, should be: + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @return RESET if UART is not busy, otherwise return SET. **********************************************************************/ FlagStatus UART_CheckBusy(LPC_UART_TypeDef *UARTx) { - if (UARTx->LSR & UART_LSR_TEMT) - { - return RESET; - } - else - { - return SET; - } + if (UARTx->LSR & UART_LSR_TEMT) + { + return RESET; + } + else + { + return SET; + } } /*********************************************************************//** - * @brief Configure FIFO function on selected UART peripheral - * @param[in] UARTx UART peripheral selected, should be: - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @param[in] FIFOCfg Pointer to a UART_FIFO_CFG_Type Structure that - * contains specified information about FIFO configuration - * @return none + * @brief Configure FIFO function on selected UART peripheral + * @param[in] UARTx UART peripheral selected, should be: + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @param[in] FIFOCfg Pointer to a UART_FIFO_CFG_Type Structure that + * contains specified information about FIFO configuration + * @return none **********************************************************************/ void UART_FIFOConfig(LPC_UART_TypeDef *UARTx, UART_FIFO_CFG_Type *FIFOCfg) { - uint8_t tmp = 0; - - tmp |= UART_FCR_FIFO_EN; - - switch (FIFOCfg->FIFO_Level) - { - case UART_FIFO_TRGLEV0: - tmp |= UART_FCR_TRG_LEV0; - break; - - case UART_FIFO_TRGLEV1: - tmp |= UART_FCR_TRG_LEV1; - break; - - case UART_FIFO_TRGLEV2: - tmp |= UART_FCR_TRG_LEV2; - break; - - case UART_FIFO_TRGLEV3: - - default: - tmp |= UART_FCR_TRG_LEV3; - break; - } - - if (FIFOCfg->FIFO_ResetTxBuf == ENABLE) - { - tmp |= UART_FCR_TX_RS; - } - - if (FIFOCfg->FIFO_ResetRxBuf == ENABLE) - { - tmp |= UART_FCR_RX_RS; - } - - if (FIFOCfg->FIFO_DMAMode == ENABLE) - { - tmp |= UART_FCR_DMAMODE_SEL; - } - - - //write to FIFO control register - if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - ((LPC_UART1_TypeDef *)UARTx)->FCR = tmp & UART_FCR_BITMASK; - } - else - { - UARTx->FCR = tmp & UART_FCR_BITMASK; - } + uint8_t tmp = 0; + + tmp |= UART_FCR_FIFO_EN; + + switch (FIFOCfg->FIFO_Level) + { + case UART_FIFO_TRGLEV0: + tmp |= UART_FCR_TRG_LEV0; + break; + + case UART_FIFO_TRGLEV1: + tmp |= UART_FCR_TRG_LEV1; + break; + + case UART_FIFO_TRGLEV2: + tmp |= UART_FCR_TRG_LEV2; + break; + + case UART_FIFO_TRGLEV3: + + default: + tmp |= UART_FCR_TRG_LEV3; + break; + } + + if (FIFOCfg->FIFO_ResetTxBuf == ENABLE) + { + tmp |= UART_FCR_TX_RS; + } + + if (FIFOCfg->FIFO_ResetRxBuf == ENABLE) + { + tmp |= UART_FCR_RX_RS; + } + + if (FIFOCfg->FIFO_DMAMode == ENABLE) + { + tmp |= UART_FCR_DMAMODE_SEL; + } + + + //write to FIFO control register + if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + ((LPC_UART1_TypeDef *)UARTx)->FCR = tmp & UART_FCR_BITMASK; + } + else + { + UARTx->FCR = tmp & UART_FCR_BITMASK; + } } /*****************************************************************************//** -* @brief Fills each UART_FIFOInitStruct member with its default value: -* - FIFO_DMAMode = DISABLE -* - FIFO_Level = UART_FIFO_TRGLEV0 -* - FIFO_ResetRxBuf = ENABLE -* - FIFO_ResetTxBuf = ENABLE -* - FIFO_State = ENABLE - -* @param[in] UART_FIFOInitStruct Pointer to a UART_FIFO_CFG_Type structure +* @brief Fills each UART_FIFOInitStruct member with its default value: +* - FIFO_DMAMode = DISABLE +* - FIFO_Level = UART_FIFO_TRGLEV0 +* - FIFO_ResetRxBuf = ENABLE +* - FIFO_ResetTxBuf = ENABLE +* - FIFO_State = ENABLE + +* @param[in] UART_FIFOInitStruct Pointer to a UART_FIFO_CFG_Type structure * which will be initialized. -* @return None +* @return None *******************************************************************************/ void UART_FIFOConfigStructInit(UART_FIFO_CFG_Type *UART_FIFOInitStruct) { - UART_FIFOInitStruct->FIFO_DMAMode = DISABLE; + UART_FIFOInitStruct->FIFO_DMAMode = DISABLE; - UART_FIFOInitStruct->FIFO_Level = UART_FIFO_TRGLEV0; + UART_FIFOInitStruct->FIFO_Level = UART_FIFO_TRGLEV0; - UART_FIFOInitStruct->FIFO_ResetRxBuf = ENABLE; + UART_FIFOInitStruct->FIFO_ResetRxBuf = ENABLE; - UART_FIFOInitStruct->FIFO_ResetTxBuf = ENABLE; + UART_FIFOInitStruct->FIFO_ResetTxBuf = ENABLE; } /*********************************************************************//** - * @brief Start/Stop Auto Baudrate activity - * @param[in] UARTx UART peripheral selected, should be - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @param[in] ABConfigStruct A pointer to UART_AB_CFG_Type structure that - * contains specified information about UART - * auto baudrate configuration - * @param[in] NewState New State of Auto baudrate activity, should be: - * - ENABLE: Start this activity - * - DISABLE: Stop this activity - * Note: Auto-baudrate mode enable bit will be cleared once this mode - * completed. - * @return none + * @brief Start/Stop Auto Baudrate activity + * @param[in] UARTx UART peripheral selected, should be + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @param[in] ABConfigStruct A pointer to UART_AB_CFG_Type structure that + * contains specified information about UART + * auto baudrate configuration + * @param[in] NewState New State of Auto baudrate activity, should be: + * - ENABLE: Start this activity + * - DISABLE: Stop this activity + * Note: Auto-baudrate mode enable bit will be cleared once this mode + * completed. + * @return none **********************************************************************/ void UART_ABCmd(LPC_UART_TypeDef *UARTx, UART_AB_CFG_Type *ABConfigStruct, - FunctionalState NewState) + FunctionalState NewState) { - uint32_t tmp; - - tmp = 0; - if (NewState == ENABLE) - { - if (ABConfigStruct->ABMode == UART_AUTOBAUD_MODE1) - { - tmp |= UART_ACR_MODE; - } - if (ABConfigStruct->AutoRestart == ENABLE) - { - tmp |= UART_ACR_AUTO_RESTART; - } - } - - if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - if (NewState == ENABLE) - { - // Clear DLL and DLM value - ((LPC_UART1_TypeDef *)UARTx)->LCR |= UART_LCR_DLAB_EN; - - ((LPC_UART1_TypeDef *)UARTx)->DLL = 0; - - ((LPC_UART1_TypeDef *)UARTx)->DLM = 0; - - ((LPC_UART1_TypeDef *)UARTx)->LCR &= ~UART_LCR_DLAB_EN; - - // FDR value must be reset to default value - ((LPC_UART1_TypeDef *)UARTx)->FDR = 0x10; - - ((LPC_UART1_TypeDef *)UARTx)->ACR = UART_ACR_START | tmp; - } - else - { - ((LPC_UART1_TypeDef *)UARTx)->ACR = 0; - } - } - else - { - if (NewState == ENABLE) - { - // Clear DLL and DLM value - UARTx->LCR |= UART_LCR_DLAB_EN; - - UARTx->DLL = 0; - - UARTx->DLM = 0; - - UARTx->LCR &= ~UART_LCR_DLAB_EN; - - // FDR value must be reset to default value - UARTx->FDR = 0x10; - - UARTx->ACR = UART_ACR_START | tmp; - } - else - { - UARTx->ACR = 0; - } - } + uint32_t tmp; + + tmp = 0; + if (NewState == ENABLE) + { + if (ABConfigStruct->ABMode == UART_AUTOBAUD_MODE1) + { + tmp |= UART_ACR_MODE; + } + if (ABConfigStruct->AutoRestart == ENABLE) + { + tmp |= UART_ACR_AUTO_RESTART; + } + } + + if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + if (NewState == ENABLE) + { + // Clear DLL and DLM value + ((LPC_UART1_TypeDef *)UARTx)->LCR |= UART_LCR_DLAB_EN; + + ((LPC_UART1_TypeDef *)UARTx)->DLL = 0; + + ((LPC_UART1_TypeDef *)UARTx)->DLM = 0; + + ((LPC_UART1_TypeDef *)UARTx)->LCR &= ~UART_LCR_DLAB_EN; + + // FDR value must be reset to default value + ((LPC_UART1_TypeDef *)UARTx)->FDR = 0x10; + + ((LPC_UART1_TypeDef *)UARTx)->ACR = UART_ACR_START | tmp; + } + else + { + ((LPC_UART1_TypeDef *)UARTx)->ACR = 0; + } + } + else + { + if (NewState == ENABLE) + { + // Clear DLL and DLM value + UARTx->LCR |= UART_LCR_DLAB_EN; + + UARTx->DLL = 0; + + UARTx->DLM = 0; + + UARTx->LCR &= ~UART_LCR_DLAB_EN; + + // FDR value must be reset to default value + UARTx->FDR = 0x10; + + UARTx->ACR = UART_ACR_START | tmp; + } + else + { + UARTx->ACR = 0; + } + } } /*********************************************************************//** - * @brief Clear Autobaud Interrupt Pending - * @param[in] UARTx UART peripheral selected, should be - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @param[in] ABIntType type of auto-baud interrupt, should be: - * - UART_AUTOBAUD_INTSTAT_ABEO: End of Auto-baud interrupt - * - UART_AUTOBAUD_INTSTAT_ABTO: Auto-baud time out interrupt - * @return none + * @brief Clear Autobaud Interrupt Pending + * @param[in] UARTx UART peripheral selected, should be + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @param[in] ABIntType type of auto-baud interrupt, should be: + * - UART_AUTOBAUD_INTSTAT_ABEO: End of Auto-baud interrupt + * - UART_AUTOBAUD_INTSTAT_ABTO: Auto-baud time out interrupt + * @return none **********************************************************************/ void UART_ABClearIntPending(LPC_UART_TypeDef *UARTx, UART_ABEO_Type ABIntType) { - if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - UARTx->ACR |= ABIntType; - } - else - UARTx->ACR |= ABIntType; + if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + UARTx->ACR |= ABIntType; + } + else + UARTx->ACR |= ABIntType; } /*********************************************************************//** - * @brief Enable/Disable transmission on UART TxD pin - * @param[in] UARTx UART peripheral selected, should be: - * - LPC_UART0: UART0 peripheral - * - LPC_UART1: UART1 peripheral - * - LPC_UART2: UART2 peripheral - * - LPC_UART3: UART3 peripheral - * @param[in] NewState New State of Tx transmission function, should be: - * - ENABLE: Enable this function - - DISABLE: Disable this function + * @brief Enable/Disable transmission on UART TxD pin + * @param[in] UARTx UART peripheral selected, should be: + * - LPC_UART0: UART0 peripheral + * - LPC_UART1: UART1 peripheral + * - LPC_UART2: UART2 peripheral + * - LPC_UART3: UART3 peripheral + * @param[in] NewState New State of Tx transmission function, should be: + * - ENABLE: Enable this function + - DISABLE: Disable this function * @return none **********************************************************************/ void UART_TxCmd(LPC_UART_TypeDef *UARTx, FunctionalState NewState) { - if (NewState == ENABLE) - { - if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - ((LPC_UART1_TypeDef *)UARTx)->TER |= UART_TER_TXEN; - } - else - { - UARTx->TER |= UART_TER_TXEN; - } - } - else - { - if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) - { - ((LPC_UART1_TypeDef *)UARTx)->TER &= (~UART_TER_TXEN) & UART_TER_BITMASK; - } - else - { - UARTx->TER &= (~UART_TER_TXEN) & UART_TER_BITMASK; - } - } + if (NewState == ENABLE) + { + if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + ((LPC_UART1_TypeDef *)UARTx)->TER |= UART_TER_TXEN; + } + else + { + UARTx->TER |= UART_TER_TXEN; + } + } + else + { + if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) + { + ((LPC_UART1_TypeDef *)UARTx)->TER &= (~UART_TER_TXEN) & UART_TER_BITMASK; + } + else + { + UARTx->TER &= (~UART_TER_TXEN) & UART_TER_BITMASK; + } + } } /* UART IrDA functions ---------------------------------------------------*/ /*********************************************************************//** - * @brief Enable or disable inverting serial input function of IrDA - * on UART peripheral. - * @param[in] UARTx UART peripheral selected, should be LPC_UART3 (only) - * @param[in] NewState New state of inverting serial input, should be: - * - ENABLE: Enable this function. - * - DISABLE: Disable this function. + * @brief Enable or disable inverting serial input function of IrDA + * on UART peripheral. + * @param[in] UARTx UART peripheral selected, should be LPC_UART3 (only) + * @param[in] NewState New state of inverting serial input, should be: + * - ENABLE: Enable this function. + * - DISABLE: Disable this function. * @return none **********************************************************************/ void UART_IrDAInvtInputCmd(LPC_UART_TypeDef* UARTx, FunctionalState NewState) { - if (NewState == ENABLE) - { - UARTx->ICR |= UART_ICR_IRDAINV; - } - else if (NewState == DISABLE) - { - UARTx->ICR &= (~UART_ICR_IRDAINV) & UART_ICR_BITMASK; - } + if (NewState == ENABLE) + { + UARTx->ICR |= UART_ICR_IRDAINV; + } + else if (NewState == DISABLE) + { + UARTx->ICR &= (~UART_ICR_IRDAINV) & UART_ICR_BITMASK; + } } /*********************************************************************//** - * @brief Enable or disable IrDA function on UART peripheral. - * @param[in] UARTx UART peripheral selected, should be LPC_UART3 (only) - * @param[in] NewState New state of IrDA function, should be: - * - ENABLE: Enable this function. - * - DISABLE: Disable this function. + * @brief Enable or disable IrDA function on UART peripheral. + * @param[in] UARTx UART peripheral selected, should be LPC_UART3 (only) + * @param[in] NewState New state of IrDA function, should be: + * - ENABLE: Enable this function. + * - DISABLE: Disable this function. * @return none **********************************************************************/ void UART_IrDACmd(LPC_UART_TypeDef* UARTx, FunctionalState NewState) { - if (NewState == ENABLE) - { - UARTx->ICR |= UART_ICR_IRDAEN; - } - else - { - UARTx->ICR &= (~UART_ICR_IRDAEN) & UART_ICR_BITMASK; - } + if (NewState == ENABLE) + { + UARTx->ICR |= UART_ICR_IRDAEN; + } + else + { + UARTx->ICR &= (~UART_ICR_IRDAEN) & UART_ICR_BITMASK; + } } /*********************************************************************//** - * @brief Configure Pulse divider for IrDA function on UART peripheral. - * @param[in] UARTx UART peripheral selected, should be LPC_UART3 (only) - * @param[in] PulseDiv Pulse Divider value from Peripheral clock, - * should be one of the following: - - UART_IrDA_PULSEDIV2 : Pulse width = 2 * Tpclk - - UART_IrDA_PULSEDIV4 : Pulse width = 4 * Tpclk - - UART_IrDA_PULSEDIV8 : Pulse width = 8 * Tpclk - - UART_IrDA_PULSEDIV16 : Pulse width = 16 * Tpclk - - UART_IrDA_PULSEDIV32 : Pulse width = 32 * Tpclk - - UART_IrDA_PULSEDIV64 : Pulse width = 64 * Tpclk - - UART_IrDA_PULSEDIV128 : Pulse width = 128 * Tpclk - - UART_IrDA_PULSEDIV256 : Pulse width = 256 * Tpclk + * @brief Configure Pulse divider for IrDA function on UART peripheral. + * @param[in] UARTx UART peripheral selected, should be LPC_UART3 (only) + * @param[in] PulseDiv Pulse Divider value from Peripheral clock, + * should be one of the following: + - UART_IrDA_PULSEDIV2 : Pulse width = 2 * Tpclk + - UART_IrDA_PULSEDIV4 : Pulse width = 4 * Tpclk + - UART_IrDA_PULSEDIV8 : Pulse width = 8 * Tpclk + - UART_IrDA_PULSEDIV16 : Pulse width = 16 * Tpclk + - UART_IrDA_PULSEDIV32 : Pulse width = 32 * Tpclk + - UART_IrDA_PULSEDIV64 : Pulse width = 64 * Tpclk + - UART_IrDA_PULSEDIV128 : Pulse width = 128 * Tpclk + - UART_IrDA_PULSEDIV256 : Pulse width = 256 * Tpclk * @return none **********************************************************************/ void UART_IrDAPulseDivConfig(LPC_UART_TypeDef *UARTx, UART_IrDA_PULSE_Type PulseDiv) { - uint32_t tmp, tmp1; + uint32_t tmp, tmp1; - tmp1 = UART_ICR_PULSEDIV(PulseDiv); + tmp1 = UART_ICR_PULSEDIV(PulseDiv); - tmp = UARTx->ICR & (~ UART_ICR_PULSEDIV(7)); + tmp = UARTx->ICR & (~ UART_ICR_PULSEDIV(7)); - tmp |= tmp1 | UART_ICR_FIXPULSE_EN; + tmp |= tmp1 | UART_ICR_FIXPULSE_EN; - UARTx->ICR = tmp & UART_ICR_BITMASK; + UARTx->ICR = tmp & UART_ICR_BITMASK; } /* UART1 FullModem function ---------------------------------------------*/ /*********************************************************************//** - * @brief Force pin DTR/RTS corresponding to given state (Full modem mode) - * @param[in] UARTx LPC_UART1 (only) - * @param[in] Pin Pin that NewState will be applied to, should be: - * - UART1_MODEM_PIN_DTR: DTR pin. - * - UART1_MODEM_PIN_RTS: RTS pin. - * @param[in] NewState New State of DTR/RTS pin, should be: - * - INACTIVE: Force the pin to inactive signal. - - ACTIVE: Force the pin to active signal. + * @brief Force pin DTR/RTS corresponding to given state (Full modem mode) + * @param[in] UARTx LPC_UART1 (only) + * @param[in] Pin Pin that NewState will be applied to, should be: + * - UART1_MODEM_PIN_DTR: DTR pin. + * - UART1_MODEM_PIN_RTS: RTS pin. + * @param[in] NewState New State of DTR/RTS pin, should be: + * - INACTIVE: Force the pin to inactive signal. + - ACTIVE: Force the pin to active signal. * @return none **********************************************************************/ void UART_FullModemForcePinState(LPC_UART1_TypeDef *UARTx, - UART_MODEM_PIN_Type Pin, - UART1_SignalState NewState) + UART_MODEM_PIN_Type Pin, + UART1_SignalState NewState) { - uint8_t tmp = 0; - - switch (Pin) - { - case UART1_MODEM_PIN_DTR: - tmp = UART1_MCR_DTR_CTRL; - break; - - case UART1_MODEM_PIN_RTS: - tmp = UART1_MCR_RTS_CTRL; - break; - - default: - break; - } - - if (NewState == ACTIVE) - { - UARTx->MCR |= tmp; - } - else - { - UARTx->MCR &= (~tmp) & UART1_MCR_BITMASK; - } + uint8_t tmp = 0; + + switch (Pin) + { + case UART1_MODEM_PIN_DTR: + tmp = UART1_MCR_DTR_CTRL; + break; + + case UART1_MODEM_PIN_RTS: + tmp = UART1_MCR_RTS_CTRL; + break; + + default: + break; + } + + if (NewState == ACTIVE) + { + UARTx->MCR |= tmp; + } + else + { + UARTx->MCR &= (~tmp) & UART1_MCR_BITMASK; + } } /*********************************************************************//** - * @brief Configure Full Modem mode for UART peripheral - * @param[in] UARTx LPC_UART1 (only) - * @param[in] Mode Full Modem mode, should be: - * - UART1_MODEM_MODE_LOOPBACK: Loop back mode. - * - UART1_MODEM_MODE_AUTO_RTS: Auto-RTS mode. - * - UART1_MODEM_MODE_AUTO_CTS: Auto-CTS mode. - * @param[in] NewState New State of this mode, should be: - * - ENABLE: Enable this mode. - - DISABLE: Disable this mode. + * @brief Configure Full Modem mode for UART peripheral + * @param[in] UARTx LPC_UART1 (only) + * @param[in] Mode Full Modem mode, should be: + * - UART1_MODEM_MODE_LOOPBACK: Loop back mode. + * - UART1_MODEM_MODE_AUTO_RTS: Auto-RTS mode. + * - UART1_MODEM_MODE_AUTO_CTS: Auto-CTS mode. + * @param[in] NewState New State of this mode, should be: + * - ENABLE: Enable this mode. + - DISABLE: Disable this mode. * @return none **********************************************************************/ void UART_FullModemConfigMode(LPC_UART1_TypeDef *UARTx, UART_MODEM_MODE_Type Mode, - FunctionalState NewState) + FunctionalState NewState) { - uint8_t tmp; - - switch(Mode) - { - case UART1_MODEM_MODE_LOOPBACK: - tmp = UART1_MCR_LOOPB_EN; - break; - - case UART1_MODEM_MODE_AUTO_RTS: - tmp = UART1_MCR_AUTO_RTS_EN; - break; - - case UART1_MODEM_MODE_AUTO_CTS: - tmp = UART1_MCR_AUTO_CTS_EN; - break; - - default: - break; - } - - if (NewState == ENABLE) - { - UARTx->MCR |= tmp; - } - else - { - UARTx->MCR &= (~tmp) & UART1_MCR_BITMASK; - } + uint8_t tmp; + + switch(Mode) + { + case UART1_MODEM_MODE_LOOPBACK: + tmp = UART1_MCR_LOOPB_EN; + break; + + case UART1_MODEM_MODE_AUTO_RTS: + tmp = UART1_MCR_AUTO_RTS_EN; + break; + + case UART1_MODEM_MODE_AUTO_CTS: + tmp = UART1_MCR_AUTO_CTS_EN; + break; + + default: + break; + } + + if (NewState == ENABLE) + { + UARTx->MCR |= tmp; + } + else + { + UARTx->MCR &= (~tmp) & UART1_MCR_BITMASK; + } } /*********************************************************************//** - * @brief Get current status of modem status register - * @param[in] UARTx LPC_UART1 (only) - * @return Current value of modem status register - * Note: The return value of this function must be ANDed with each member - * UART_MODEM_STAT_type enumeration to determine current flag status - * corresponding to each modem flag status. Because some flags in - * modem status register will be cleared after reading, the next reading - * modem register could not be correct. So this function used to - * read modem status register in one time only, then the return value - * used to check all flags. + * @brief Get current status of modem status register + * @param[in] UARTx LPC_UART1 (only) + * @return Current value of modem status register + * Note: The return value of this function must be ANDed with each member + * UART_MODEM_STAT_type enumeration to determine current flag status + * corresponding to each modem flag status. Because some flags in + * modem status register will be cleared after reading, the next reading + * modem register could not be correct. So this function used to + * read modem status register in one time only, then the return value + * used to check all flags. **********************************************************************/ uint8_t UART_FullModemGetStatus(LPC_UART1_TypeDef *UARTx) { - return ((UARTx->MSR) & UART1_MSR_BITMASK); + return ((UARTx->MSR) & UART1_MSR_BITMASK); } /* UART RS485 functions --------------------------------------------------------------*/ /*********************************************************************//** - * @brief Configure UART peripheral in RS485 mode according to the specified + * @brief Configure UART peripheral in RS485 mode according to the specified * parameters in the RS485ConfigStruct. - * @param[in] UARTx LPC_UART1 (only) - * @param[in] RS485ConfigStruct Pointer to a UART1_RS485_CTRLCFG_Type structure + * @param[in] UARTx LPC_UART1 (only) + * @param[in] RS485ConfigStruct Pointer to a UART1_RS485_CTRLCFG_Type structure * that contains the configuration information for specified UART * in RS485 mode. - * @return None + * @return None **********************************************************************/ void UART_RS485Config(LPC_UART_TypeDef *UARTx, UART1_RS485_CTRLCFG_Type *RS485ConfigStruct) { - uint32_t tmp; - - tmp = 0; - - // If Auto Direction Control is enabled - This function is used in Master mode - if (RS485ConfigStruct->AutoDirCtrl_State == ENABLE) - { - tmp |= UART1_RS485CTRL_DCTRL_EN; - - // Set polar - if (RS485ConfigStruct->DirCtrlPol_Level == SET) - { - tmp |= UART1_RS485CTRL_OINV_1; - } - - // Set pin according to. This condition is only with UART1. The others are used - // OE pin as default for control the direction of RS485 buffer IC - if ((RS485ConfigStruct->DirCtrlPin == UART1_RS485_DIRCTRL_DTR) - && ((LPC_UART1_TypeDef *)UARTx == LPC_UART1)) - { - tmp |= UART1_RS485CTRL_SEL_DTR; - } - - // Fill delay time - UARTx->RS485DLY = RS485ConfigStruct->DelayValue & UART1_RS485DLY_BITMASK; - } - - // MultiDrop mode is enable - if (RS485ConfigStruct->NormalMultiDropMode_State == ENABLE) - { - tmp |= UART1_RS485CTRL_NMM_EN; - } - - // Auto Address Detect function - if (RS485ConfigStruct->AutoAddrDetect_State == ENABLE) - { - tmp |= UART1_RS485CTRL_AADEN; - - // Fill Match Address - UARTx->ADRMATCH = RS485ConfigStruct->MatchAddrValue & UART1_RS485ADRMATCH_BITMASK; - } - - // Receiver is disable - if (RS485ConfigStruct->Rx_State == DISABLE) - { - tmp |= UART1_RS485CTRL_RX_DIS; - } - - // write back to RS485 control register - UARTx->RS485CTRL = tmp & UART1_RS485CTRL_BITMASK; - - // Enable Parity function and leave parity in stick '0' parity as default - UARTx->LCR |= (UART_LCR_PARITY_F_0 | UART_LCR_PARITY_EN); + uint32_t tmp; + + tmp = 0; + + // If Auto Direction Control is enabled - This function is used in Master mode + if (RS485ConfigStruct->AutoDirCtrl_State == ENABLE) + { + tmp |= UART1_RS485CTRL_DCTRL_EN; + + // Set polar + if (RS485ConfigStruct->DirCtrlPol_Level == SET) + { + tmp |= UART1_RS485CTRL_OINV_1; + } + + // Set pin according to. This condition is only with UART1. The others are used + // OE pin as default for control the direction of RS485 buffer IC + if ((RS485ConfigStruct->DirCtrlPin == UART1_RS485_DIRCTRL_DTR) + && ((LPC_UART1_TypeDef *)UARTx == LPC_UART1)) + { + tmp |= UART1_RS485CTRL_SEL_DTR; + } + + // Fill delay time + UARTx->RS485DLY = RS485ConfigStruct->DelayValue & UART1_RS485DLY_BITMASK; + } + + // MultiDrop mode is enable + if (RS485ConfigStruct->NormalMultiDropMode_State == ENABLE) + { + tmp |= UART1_RS485CTRL_NMM_EN; + } + + // Auto Address Detect function + if (RS485ConfigStruct->AutoAddrDetect_State == ENABLE) + { + tmp |= UART1_RS485CTRL_AADEN; + + // Fill Match Address + UARTx->ADRMATCH = RS485ConfigStruct->MatchAddrValue & UART1_RS485ADRMATCH_BITMASK; + } + + // Receiver is disable + if (RS485ConfigStruct->Rx_State == DISABLE) + { + tmp |= UART1_RS485CTRL_RX_DIS; + } + + // write back to RS485 control register + UARTx->RS485CTRL = tmp & UART1_RS485CTRL_BITMASK; + + // Enable Parity function and leave parity in stick '0' parity as default + UARTx->LCR |= (UART_LCR_PARITY_F_0 | UART_LCR_PARITY_EN); } /*********************************************************************//** - * @brief Enable/Disable receiver in RS485 module in UART1 - * @param[in] UARTx LPC_UART1 (only) - * @param[in] NewState New State of command, should be: - * - ENABLE: Enable this function. - * - DISABLE: Disable this function. - * @return None + * @brief Enable/Disable receiver in RS485 module in UART1 + * @param[in] UARTx LPC_UART1 (only) + * @param[in] NewState New State of command, should be: + * - ENABLE: Enable this function. + * - DISABLE: Disable this function. + * @return None **********************************************************************/ void UART_RS485ReceiverCmd(LPC_UART_TypeDef *UARTx, FunctionalState NewState) { - if (NewState == ENABLE) - { - UARTx->RS485CTRL &= ~UART1_RS485CTRL_RX_DIS; - } - else - { - UARTx->RS485CTRL |= UART1_RS485CTRL_RX_DIS; - } + if (NewState == ENABLE) + { + UARTx->RS485CTRL &= ~UART1_RS485CTRL_RX_DIS; + } + else + { + UARTx->RS485CTRL |= UART1_RS485CTRL_RX_DIS; + } } /*********************************************************************//** - * @brief Send data on RS485 bus with specified parity stick value (9-bit mode). - * @param[in] UARTx LPC_UART1 (only) - * @param[in] pDatFrm Pointer to data frame. - * @param[in] size Size of data. - * @param[in] ParityStick Parity Stick value, should be 0 or 1. - * @return None + * @brief Send data on RS485 bus with specified parity stick value (9-bit mode). + * @param[in] UARTx LPC_UART1 (only) + * @param[in] pDatFrm Pointer to data frame. + * @param[in] size Size of data. + * @param[in] ParityStick Parity Stick value, should be 0 or 1. + * @return None **********************************************************************/ uint32_t UART_RS485Send(LPC_UART_TypeDef *UARTx, uint8_t *pDatFrm, - uint32_t size, uint8_t ParityStick) + uint32_t size, uint8_t ParityStick) { - uint8_t tmp, save; - uint32_t cnt; + uint8_t tmp, save; + uint32_t cnt; - if (ParityStick) - { - save = tmp = UARTx->LCR & UART_LCR_BITMASK; + if (ParityStick) + { + save = tmp = UARTx->LCR & UART_LCR_BITMASK; - tmp &= ~(UART_LCR_PARITY_EVEN); + tmp &= ~(UART_LCR_PARITY_EVEN); - UARTx->LCR = tmp; + UARTx->LCR = tmp; - cnt = UART_Send((LPC_UART_TypeDef *)UARTx, pDatFrm, size, BLOCKING); + cnt = UART_Send((LPC_UART_TypeDef *)UARTx, pDatFrm, size, BLOCKING); - while (!(UARTx->LSR & UART_LSR_TEMT)); + while (!(UARTx->LSR & UART_LSR_TEMT)); - UARTx->LCR = save; - } - else - { - cnt = UART_Send((LPC_UART_TypeDef *)UARTx, pDatFrm, size, BLOCKING); + UARTx->LCR = save; + } + else + { + cnt = UART_Send((LPC_UART_TypeDef *)UARTx, pDatFrm, size, BLOCKING); - while (!(UARTx->LSR & UART_LSR_TEMT)); - } + while (!(UARTx->LSR & UART_LSR_TEMT)); + } - return cnt; + return cnt; } /*********************************************************************//** - * @brief Send Slave address frames on RS485 bus. - * @param[in] UARTx LPC_UART1 (only) - * @param[in] SlvAddr Slave Address. - * @return None + * @brief Send Slave address frames on RS485 bus. + * @param[in] UARTx LPC_UART1 (only) + * @param[in] SlvAddr Slave Address. + * @return None **********************************************************************/ void UART_RS485SendSlvAddr(LPC_UART_TypeDef *UARTx, uint8_t SlvAddr) { - UART_RS485Send(UARTx, &SlvAddr, 1, 1); + UART_RS485Send(UARTx, &SlvAddr, 1, 1); } /*********************************************************************//** - * @brief Send Data frames on RS485 bus. - * @param[in] UARTx LPC_UART1 (only) - * @param[in] pData Pointer to data to be sent. - * @param[in] size Size of data frame to be sent. - * @return None + * @brief Send Data frames on RS485 bus. + * @param[in] UARTx LPC_UART1 (only) + * @param[in] pData Pointer to data to be sent. + * @param[in] size Size of data frame to be sent. + * @return None **********************************************************************/ uint32_t UART_RS485SendData(LPC_UART_TypeDef *UARTx, uint8_t *pData, uint32_t size) { - return (UART_RS485Send(UARTx, pData, size, 0)); + return (UART_RS485Send(UARTx, pData, size, 0)); } /** diff --git a/bsp/lpc178x/drivers/lpc177x_8x_uart.h b/bsp/lpc178x/drivers/lpc177x_8x_uart.h index 2b8a6f85cb..35c756d0c7 100644 --- a/bsp/lpc178x/drivers/lpc177x_8x_uart.h +++ b/bsp/lpc178x/drivers/lpc177x_8x_uart.h @@ -1,13 +1,13 @@ /********************************************************************** -* $Id$ lpc177x_8x_uart.h 2011-06-02 +* $Id$ lpc177x_8x_uart.h 2011-06-02 *//** -* @file lpc177x_8x_uart.h -* @brief Contains all macro definitions and function prototypes -* support for UART firmware library on LPC177x_8x -* @version 1.0 -* @date 02. June. 2011 -* @author NXP MCU SW Application Team -* +* @file lpc177x_8x_uart.h +* @brief Contains all macro definitions and function prototypes +* support for UART firmware library on LPC177x_8x +* @version 1.0 +* @date 02. June. 2011 +* @author NXP MCU SW Application Team +* * Copyright(C) 2011, NXP Semiconductor * All rights reserved. * @@ -25,7 +25,7 @@ **********************************************************************/ /* Peripheral group ----------------------------------------------------------- */ -/** @defgroup UART UART (Universal Asynchronous Receiver/Transmitter) +/** @defgroup UART UART (Universal Asynchronous Receiver/Transmitter) * @ingroup LPC177x_8xCMSIS_FwLib_Drivers * @{ */ @@ -51,7 +51,7 @@ extern "C" /** UART time-out definitions in case of using Read() and Write function * with Blocking Flag mode */ -#define UART_BLOCKING_TIMEOUT (0xFFFFFFFFUL) +#define UART_BLOCKING_TIMEOUT (0xFFFFFFFFUL) /** * @} @@ -63,7 +63,7 @@ extern "C" */ /* Accepted Error baud rate value (in percent unit) */ -#define UART_ACCEPTED_BAUDRATE_ERROR (3) /*!< Acceptable UART baudrate error */ +#define UART_ACCEPTED_BAUDRATE_ERROR (3) /*!< Acceptable UART baudrate error */ /* --------------------- BIT DEFINITIONS -------------------------------------- */ @@ -71,27 +71,27 @@ extern "C" * Macro defines for Macro defines for UARTn Receiver Buffer Register **********************************************************************/ /** UART Received Buffer mask bit (8 bits) */ -#define UART_RBR_MASKBIT ((uint8_t)0xFF) +#define UART_RBR_MASKBIT ((uint8_t)0xFF) /*********************************************************************//** * Macro defines for Macro defines for UARTn Transmit Holding Register **********************************************************************/ /** UART Transmit Holding mask bit (8 bits) */ -#define UART_THR_MASKBIT ((uint8_t)0xFF) +#define UART_THR_MASKBIT ((uint8_t)0xFF) /*********************************************************************//** * Macro defines for Macro defines for UARTn Divisor Latch LSB register **********************************************************************/ /** Macro for loading least significant halfs of divisors */ -#define UART_LOAD_DLL(div) ((div) & 0xFF) +#define UART_LOAD_DLL(div) ((div) & 0xFF) /** Divisor latch LSB bit mask */ -#define UART_DLL_MASKBIT ((uint8_t)0xFF) +#define UART_DLL_MASKBIT ((uint8_t)0xFF) /*********************************************************************//** * Macro defines for Macro defines for UARTn Divisor Latch MSB register **********************************************************************/ /** Divisor latch MSB bit mask */ -#define UART_DLM_MASKBIT ((uint8_t)0xFF) +#define UART_DLM_MASKBIT ((uint8_t)0xFF) /** Macro for loading most significant halfs of divisors */ #define UART_LOAD_DLM(div) (((div) >> 8) & 0xFF) @@ -99,258 +99,258 @@ extern "C" * Macro defines for Macro defines for UART interrupt enable register **********************************************************************/ /** RBR Interrupt enable*/ -#define UART_IER_RBRINT_EN ((uint32_t)(1<<0)) +#define UART_IER_RBRINT_EN ((uint32_t)(1<<0)) /** THR Interrupt enable*/ -#define UART_IER_THREINT_EN ((uint32_t)(1<<1)) +#define UART_IER_THREINT_EN ((uint32_t)(1<<1)) /** RX line status interrupt enable*/ -#define UART_IER_RLSINT_EN ((uint32_t)(1<<2)) +#define UART_IER_RLSINT_EN ((uint32_t)(1<<2)) /** Modem status interrupt enable */ -#define UART1_IER_MSINT_EN ((uint32_t)(1<<3)) +#define UART1_IER_MSINT_EN ((uint32_t)(1<<3)) /** CTS1 signal transition interrupt enable */ -#define UART1_IER_CTSINT_EN ((uint32_t)(1<<7)) +#define UART1_IER_CTSINT_EN ((uint32_t)(1<<7)) /** Enables the end of auto-baud interrupt */ -#define UART_IER_ABEOINT_EN ((uint32_t)(1<<8)) +#define UART_IER_ABEOINT_EN ((uint32_t)(1<<8)) /** Enables the auto-baud time-out interrupt */ -#define UART_IER_ABTOINT_EN ((uint32_t)(1<<9)) +#define UART_IER_ABTOINT_EN ((uint32_t)(1<<9)) /** UART interrupt enable register bit mask */ -#define UART_IER_BITMASK ((uint32_t)(0x307)) +#define UART_IER_BITMASK ((uint32_t)(0x307)) /** UART1 interrupt enable register bit mask */ -#define UART1_IER_BITMASK ((uint32_t)(0x38F)) +#define UART1_IER_BITMASK ((uint32_t)(0x38F)) /*********************************************************************//** * Macro defines for Macro defines for UART interrupt identification register **********************************************************************/ /** Interrupt Status - Active low */ -#define UART_IIR_INTSTAT_PEND ((uint32_t)(1<<0)) +#define UART_IIR_INTSTAT_PEND ((uint32_t)(1<<0)) /** Interrupt identification: Receive line status*/ -#define UART_IIR_INTID_RLS ((uint32_t)(3<<1)) +#define UART_IIR_INTID_RLS ((uint32_t)(3<<1)) /** Interrupt identification: Receive data available*/ -#define UART_IIR_INTID_RDA ((uint32_t)(2<<1)) +#define UART_IIR_INTID_RDA ((uint32_t)(2<<1)) /** Interrupt identification: Character time-out indicator*/ -#define UART_IIR_INTID_CTI ((uint32_t)(6<<1)) +#define UART_IIR_INTID_CTI ((uint32_t)(6<<1)) /** Interrupt identification: THRE interrupt*/ -#define UART_IIR_INTID_THRE ((uint32_t)(1<<1)) +#define UART_IIR_INTID_THRE ((uint32_t)(1<<1)) /** Interrupt identification: Modem interrupt*/ -#define UART1_IIR_INTID_MODEM ((uint32_t)(0<<1)) +#define UART1_IIR_INTID_MODEM ((uint32_t)(0<<1)) /** Interrupt identification: Interrupt ID mask */ -#define UART_IIR_INTID_MASK ((uint32_t)(7<<1)) +#define UART_IIR_INTID_MASK ((uint32_t)(7<<1)) /** These bits are equivalent to UnFCR[0] */ -#define UART_IIR_FIFO_EN ((uint32_t)(3<<6)) +#define UART_IIR_FIFO_EN ((uint32_t)(3<<6)) /** End of auto-baud interrupt */ -#define UART_IIR_ABEO_INT ((uint32_t)(1<<8)) +#define UART_IIR_ABEO_INT ((uint32_t)(1<<8)) /** Auto-baud time-out interrupt */ -#define UART_IIR_ABTO_INT ((uint32_t)(1<<9)) +#define UART_IIR_ABTO_INT ((uint32_t)(1<<9)) /** UART interrupt identification register bit mask */ -#define UART_IIR_BITMASK ((uint32_t)(0x3CF)) +#define UART_IIR_BITMASK ((uint32_t)(0x3CF)) /*********************************************************************//** * Macro defines for Macro defines for UART FIFO control register **********************************************************************/ /** UART FIFO enable */ -#define UART_FCR_FIFO_EN ((uint8_t)(1<<0)) +#define UART_FCR_FIFO_EN ((uint8_t)(1<<0)) /** UART FIFO RX reset */ -#define UART_FCR_RX_RS ((uint8_t)(1<<1)) +#define UART_FCR_RX_RS ((uint8_t)(1<<1)) /** UART FIFO TX reset */ -#define UART_FCR_TX_RS ((uint8_t)(1<<2)) +#define UART_FCR_TX_RS ((uint8_t)(1<<2)) /** UART DMA mode selection */ -#define UART_FCR_DMAMODE_SEL ((uint8_t)(1<<3)) +#define UART_FCR_DMAMODE_SEL ((uint8_t)(1<<3)) /** UART FIFO trigger level 0: 1 character */ -#define UART_FCR_TRG_LEV0 ((uint8_t)(0)) +#define UART_FCR_TRG_LEV0 ((uint8_t)(0)) /** UART FIFO trigger level 1: 4 character */ -#define UART_FCR_TRG_LEV1 ((uint8_t)(1<<6)) +#define UART_FCR_TRG_LEV1 ((uint8_t)(1<<6)) /** UART FIFO trigger level 2: 8 character */ -#define UART_FCR_TRG_LEV2 ((uint8_t)(2<<6)) +#define UART_FCR_TRG_LEV2 ((uint8_t)(2<<6)) /** UART FIFO trigger level 3: 14 character */ -#define UART_FCR_TRG_LEV3 ((uint8_t)(3<<6)) +#define UART_FCR_TRG_LEV3 ((uint8_t)(3<<6)) /** UART FIFO control bit mask */ -#define UART_FCR_BITMASK ((uint8_t)(0xCF)) +#define UART_FCR_BITMASK ((uint8_t)(0xCF)) -#define UART_TX_FIFO_SIZE (16) +#define UART_TX_FIFO_SIZE (16) /*********************************************************************//** * Macro defines for Macro defines for UART line control register **********************************************************************/ /** UART 5 bit data mode */ -#define UART_LCR_WLEN5 ((uint8_t)(0)) +#define UART_LCR_WLEN5 ((uint8_t)(0)) /** UART 6 bit data mode */ -#define UART_LCR_WLEN6 ((uint8_t)(1<<0)) +#define UART_LCR_WLEN6 ((uint8_t)(1<<0)) /** UART 7 bit data mode */ -#define UART_LCR_WLEN7 ((uint8_t)(2<<0)) +#define UART_LCR_WLEN7 ((uint8_t)(2<<0)) /** UART 8 bit data mode */ -#define UART_LCR_WLEN8 ((uint8_t)(3<<0)) +#define UART_LCR_WLEN8 ((uint8_t)(3<<0)) /** UART Two Stop Bits Select */ -#define UART_LCR_STOPBIT_SEL ((uint8_t)(1<<2)) +#define UART_LCR_STOPBIT_SEL ((uint8_t)(1<<2)) /** UART Parity Enable */ -#define UART_LCR_PARITY_EN ((uint8_t)(1<<3)) +#define UART_LCR_PARITY_EN ((uint8_t)(1<<3)) /** UART Odd Parity Select */ -#define UART_LCR_PARITY_ODD ((uint8_t)(0)) +#define UART_LCR_PARITY_ODD ((uint8_t)(0)) /** UART Even Parity Select */ -#define UART_LCR_PARITY_EVEN ((uint8_t)(1<<4)) +#define UART_LCR_PARITY_EVEN ((uint8_t)(1<<4)) /** UART force 1 stick parity */ -#define UART_LCR_PARITY_F_1 ((uint8_t)(2<<4)) +#define UART_LCR_PARITY_F_1 ((uint8_t)(2<<4)) /** UART force 0 stick parity */ -#define UART_LCR_PARITY_F_0 ((uint8_t)(3<<4)) +#define UART_LCR_PARITY_F_0 ((uint8_t)(3<<4)) /** UART Transmission Break enable */ -#define UART_LCR_BREAK_EN ((uint8_t)(1<<6)) +#define UART_LCR_BREAK_EN ((uint8_t)(1<<6)) /** UART Divisor Latches Access bit enable */ -#define UART_LCR_DLAB_EN ((uint8_t)(1<<7)) +#define UART_LCR_DLAB_EN ((uint8_t)(1<<7)) /** UART line control bit mask */ -#define UART_LCR_BITMASK ((uint8_t)(0xFF)) +#define UART_LCR_BITMASK ((uint8_t)(0xFF)) /*********************************************************************//** * Macro defines for Macro defines for UART1 Modem Control Register **********************************************************************/ /** Source for modem output pin DTR */ -#define UART1_MCR_DTR_CTRL ((uint8_t)(1<<0)) +#define UART1_MCR_DTR_CTRL ((uint8_t)(1<<0)) /** Source for modem output pin RTS */ -#define UART1_MCR_RTS_CTRL ((uint8_t)(1<<1)) +#define UART1_MCR_RTS_CTRL ((uint8_t)(1<<1)) /** Loop back mode select */ -#define UART1_MCR_LOOPB_EN ((uint8_t)(1<<4)) +#define UART1_MCR_LOOPB_EN ((uint8_t)(1<<4)) /** Enable Auto RTS flow-control */ -#define UART1_MCR_AUTO_RTS_EN ((uint8_t)(1<<6)) +#define UART1_MCR_AUTO_RTS_EN ((uint8_t)(1<<6)) /** Enable Auto CTS flow-control */ -#define UART1_MCR_AUTO_CTS_EN ((uint8_t)(1<<7)) +#define UART1_MCR_AUTO_CTS_EN ((uint8_t)(1<<7)) /** UART1 bit mask value */ -#define UART1_MCR_BITMASK ((uint8_t)(0x0F3)) +#define UART1_MCR_BITMASK ((uint8_t)(0x0F3)) /*********************************************************************//** * Macro defines for Macro defines for UART line status register **********************************************************************/ /** Line status register: Receive data ready*/ -#define UART_LSR_RDR ((uint8_t)(1<<0)) +#define UART_LSR_RDR ((uint8_t)(1<<0)) /** Line status register: Overrun error*/ -#define UART_LSR_OE ((uint8_t)(1<<1)) +#define UART_LSR_OE ((uint8_t)(1<<1)) /** Line status register: Parity error*/ -#define UART_LSR_PE ((uint8_t)(1<<2)) +#define UART_LSR_PE ((uint8_t)(1<<2)) /** Line status register: Framing error*/ -#define UART_LSR_FE ((uint8_t)(1<<3)) +#define UART_LSR_FE ((uint8_t)(1<<3)) /** Line status register: Break interrupt*/ -#define UART_LSR_BI ((uint8_t)(1<<4)) +#define UART_LSR_BI ((uint8_t)(1<<4)) /** Line status register: Transmit holding register empty*/ -#define UART_LSR_THRE ((uint8_t)(1<<5)) +#define UART_LSR_THRE ((uint8_t)(1<<5)) /** Line status register: Transmitter empty*/ -#define UART_LSR_TEMT ((uint8_t)(1<<6)) +#define UART_LSR_TEMT ((uint8_t)(1<<6)) /** Error in RX FIFO*/ -#define UART_LSR_RXFE ((uint8_t)(1<<7)) +#define UART_LSR_RXFE ((uint8_t)(1<<7)) /** UART Line status bit mask */ -#define UART_LSR_BITMASK ((uint8_t)(0xFF)) +#define UART_LSR_BITMASK ((uint8_t)(0xFF)) /*********************************************************************//** * Macro defines for Macro defines for UART Modem (UART1 only) status register **********************************************************************/ /** Set upon state change of input CTS */ -#define UART1_MSR_DELTA_CTS ((uint8_t)(1<<0)) +#define UART1_MSR_DELTA_CTS ((uint8_t)(1<<0)) /** Set upon state change of input DSR */ -#define UART1_MSR_DELTA_DSR ((uint8_t)(1<<1)) +#define UART1_MSR_DELTA_DSR ((uint8_t)(1<<1)) /** Set upon low to high transition of input RI */ -#define UART1_MSR_LO2HI_RI ((uint8_t)(1<<2)) +#define UART1_MSR_LO2HI_RI ((uint8_t)(1<<2)) /** Set upon state change of input DCD */ -#define UART1_MSR_DELTA_DCD ((uint8_t)(1<<3)) +#define UART1_MSR_DELTA_DCD ((uint8_t)(1<<3)) /** Clear To Send State */ -#define UART1_MSR_CTS ((uint8_t)(1<<4)) +#define UART1_MSR_CTS ((uint8_t)(1<<4)) /** Data Set Ready State */ -#define UART1_MSR_DSR ((uint8_t)(1<<5)) +#define UART1_MSR_DSR ((uint8_t)(1<<5)) /** Ring Indicator State */ -#define UART1_MSR_RI ((uint8_t)(1<<6)) +#define UART1_MSR_RI ((uint8_t)(1<<6)) /** Data Carrier Detect State */ -#define UART1_MSR_DCD ((uint8_t)(1<<7)) +#define UART1_MSR_DCD ((uint8_t)(1<<7)) /** MSR register bit-mask value */ -#define UART1_MSR_BITMASK ((uint8_t)(0xFF)) +#define UART1_MSR_BITMASK ((uint8_t)(0xFF)) /*********************************************************************//** * Macro defines for Macro defines for UART Scratch Pad Register **********************************************************************/ /** UART Scratch Pad bit mask */ -#define UART_SCR_BIMASK ((uint8_t)(0xFF)) +#define UART_SCR_BIMASK ((uint8_t)(0xFF)) /*********************************************************************//** * Macro defines for Macro defines for UART Auto baudrate control register **********************************************************************/ /** UART Auto-baud start */ -#define UART_ACR_START ((uint32_t)(1<<0)) +#define UART_ACR_START ((uint32_t)(1<<0)) /** UART Auto baudrate Mode 1 */ -#define UART_ACR_MODE ((uint32_t)(1<<1)) +#define UART_ACR_MODE ((uint32_t)(1<<1)) /** UART Auto baudrate restart */ -#define UART_ACR_AUTO_RESTART ((uint32_t)(1<<2)) +#define UART_ACR_AUTO_RESTART ((uint32_t)(1<<2)) /** UART End of auto-baud interrupt clear */ -#define UART_ACR_ABEOINT_CLR ((uint32_t)(1<<8)) +#define UART_ACR_ABEOINT_CLR ((uint32_t)(1<<8)) /** UART Auto-baud time-out interrupt clear */ -#define UART_ACR_ABTOINT_CLR ((uint32_t)(1<<9)) +#define UART_ACR_ABTOINT_CLR ((uint32_t)(1<<9)) /** UART Auto Baudrate register bit mask */ -#define UART_ACR_BITMASK ((uint32_t)(0x307)) +#define UART_ACR_BITMASK ((uint32_t)(0x307)) /*********************************************************************//** * Macro defines for Macro defines for UART IrDA control register **********************************************************************/ /** IrDA mode enable */ -#define UART_ICR_IRDAEN ((uint32_t)(1<<0)) +#define UART_ICR_IRDAEN ((uint32_t)(1<<0)) /** IrDA serial input inverted */ -#define UART_ICR_IRDAINV ((uint32_t)(1<<1)) +#define UART_ICR_IRDAINV ((uint32_t)(1<<1)) /** IrDA fixed pulse width mode */ -#define UART_ICR_FIXPULSE_EN ((uint32_t)(1<<2)) +#define UART_ICR_FIXPULSE_EN ((uint32_t)(1<<2)) /** PulseDiv - Configures the pulse when FixPulseEn = 1 */ -#define UART_ICR_PULSEDIV(n) ((uint32_t)((n&0x07)<<3)) +#define UART_ICR_PULSEDIV(n) ((uint32_t)((n&0x07)<<3)) /** UART IRDA bit mask */ -#define UART_ICR_BITMASK ((uint32_t)(0x3F)) +#define UART_ICR_BITMASK ((uint32_t)(0x3F)) /*********************************************************************//** * Macro defines for Macro defines for UART Fractional divider register **********************************************************************/ /** Baud-rate generation pre-scaler divisor */ -#define UART_FDR_DIVADDVAL(n) ((uint32_t)(n&0x0F)) +#define UART_FDR_DIVADDVAL(n) ((uint32_t)(n&0x0F)) /** Baud-rate pre-scaler multiplier value */ -#define UART_FDR_MULVAL(n) ((uint32_t)((n<<4)&0xF0)) +#define UART_FDR_MULVAL(n) ((uint32_t)((n<<4)&0xF0)) /** UART Fractional Divider register bit mask */ -#define UART_FDR_BITMASK ((uint32_t)(0xFF)) +#define UART_FDR_BITMASK ((uint32_t)(0xFF)) /*********************************************************************//** * Macro defines for Macro defines for UART Tx Enable register **********************************************************************/ /** Transmit enable bit */ -#define UART_TER_TXEN ((uint8_t)(1<<7)) +#define UART_TER_TXEN ((uint8_t)(1<<7)) /** UART Transmit Enable Register bit mask */ -#define UART_TER_BITMASK ((uint8_t)(0x80)) +#define UART_TER_BITMASK ((uint8_t)(0x80)) /*********************************************************************//** * Macro defines for Macro defines for UART1 RS485 Control register **********************************************************************/ /** RS-485/EIA-485 Normal Multi-drop Mode (NMM) is disabled */ -#define UART1_RS485CTRL_NMM_EN ((uint32_t)(1<<0)) +#define UART1_RS485CTRL_NMM_EN ((uint32_t)(1<<0)) /** The receiver is disabled */ -#define UART1_RS485CTRL_RX_DIS ((uint32_t)(1<<1)) +#define UART1_RS485CTRL_RX_DIS ((uint32_t)(1<<1)) /** Auto Address Detect (AAD) is enabled */ -#define UART1_RS485CTRL_AADEN ((uint32_t)(1<<2)) +#define UART1_RS485CTRL_AADEN ((uint32_t)(1<<2)) /** If direction control is enabled (bit DCTRL = 1), pin DTR is used for direction control */ -#define UART1_RS485CTRL_SEL_DTR ((uint32_t)(1<<3)) +#define UART1_RS485CTRL_SEL_DTR ((uint32_t)(1<<3)) /** Enable Auto Direction Control */ -#define UART1_RS485CTRL_DCTRL_EN ((uint32_t)(1<<4)) -/** This bit reverses the polarity of the direction control signal on the RTS (or DTR) pin. +#define UART1_RS485CTRL_DCTRL_EN ((uint32_t)(1<<4)) +/** This bit reverses the polarity of the direction control signal on the RTS (or DTR) pin. The direction control pin will be driven to logic "1" when the transmitter has data to be sent */ -#define UART1_RS485CTRL_OINV_1 ((uint32_t)(1<<5)) +#define UART1_RS485CTRL_OINV_1 ((uint32_t)(1<<5)) /** RS485 control bit-mask value */ -#define UART1_RS485CTRL_BITMASK ((uint32_t)(0x3F)) +#define UART1_RS485CTRL_BITMASK ((uint32_t)(0x3F)) /*********************************************************************//** * Macro defines for Macro defines for UART1 RS-485 Address Match register **********************************************************************/ -#define UART1_RS485ADRMATCH_BITMASK ((uint8_t)(0xFF)) /**< Bit mask value */ +#define UART1_RS485ADRMATCH_BITMASK ((uint8_t)(0xFF)) /**< Bit mask value */ /*********************************************************************//** * Macro defines for Macro defines for UART1 RS-485 Delay value register **********************************************************************/ /* Macro defines for UART1 RS-485 Delay value register */ -#define UART1_RS485DLY_BITMASK ((uint8_t)(0xFF)) /** Bit mask value */ +#define UART1_RS485DLY_BITMASK ((uint8_t)(0xFF)) /** Bit mask value */ /*********************************************************************//** * Macro defines for Macro defines for UART FIFO Level register **********************************************************************/ /** Reflects the current level of the UART receiver FIFO */ -#define UART_FIFOLVL_RXFIFOLVL(n) ((uint32_t)(n&0x0F)) +#define UART_FIFOLVL_RXFIFOLVL(n) ((uint32_t)(n&0x0F)) /** Reflects the current level of the UART transmitter FIFO */ -#define UART_FIFOLVL_TXFIFOLVL(n) ((uint32_t)((n>>8)&0x0F)) +#define UART_FIFOLVL_TXFIFOLVL(n) ((uint32_t)((n>>8)&0x0F)) /** UART FIFO Level Register bit mask */ -#define UART_FIFOLVL_BITMASK ((uint32_t)(0x0F0F)) +#define UART_FIFOLVL_BITMASK ((uint32_t)(0x0F0F)) /** @@ -367,199 +367,199 @@ The direction control pin will be driven to logic "1" when the transmitter has d * @brief UART Databit type definitions */ typedef enum { - UART_DATABIT_5 = 0, /*!< UART 5 bit data mode */ - UART_DATABIT_6, /*!< UART 6 bit data mode */ - UART_DATABIT_7, /*!< UART 7 bit data mode */ - UART_DATABIT_8 /*!< UART 8 bit data mode */ + UART_DATABIT_5 = 0, /*!< UART 5 bit data mode */ + UART_DATABIT_6, /*!< UART 6 bit data mode */ + UART_DATABIT_7, /*!< UART 7 bit data mode */ + UART_DATABIT_8 /*!< UART 8 bit data mode */ } UART_DATABIT_Type; /** * @brief UART Stop bit type definitions */ typedef enum { - UART_STOPBIT_1 = (0), /*!< UART 1 Stop Bits Select */ - UART_STOPBIT_2, /*!< UART Two Stop Bits Select */ + UART_STOPBIT_1 = (0), /*!< UART 1 Stop Bits Select */ + UART_STOPBIT_2, /*!< UART Two Stop Bits Select */ } UART_STOPBIT_Type; /** * @brief UART Parity type definitions */ typedef enum { - UART_PARITY_NONE = 0, /*!< No parity */ - UART_PARITY_ODD, /*!< Odd parity */ - UART_PARITY_EVEN, /*!< Even parity */ - UART_PARITY_SP_1, /*!< Forced "1" stick parity */ - UART_PARITY_SP_0 /*!< Forced "0" stick parity */ + UART_PARITY_NONE = 0, /*!< No parity */ + UART_PARITY_ODD, /*!< Odd parity */ + UART_PARITY_EVEN, /*!< Even parity */ + UART_PARITY_SP_1, /*!< Forced "1" stick parity */ + UART_PARITY_SP_0 /*!< Forced "0" stick parity */ } UART_PARITY_Type; /** * @brief FIFO Level type definitions */ typedef enum { - UART_FIFO_TRGLEV0 = 0, /*!< UART FIFO trigger level 0: 1 character */ - UART_FIFO_TRGLEV1, /*!< UART FIFO trigger level 1: 4 character */ - UART_FIFO_TRGLEV2, /*!< UART FIFO trigger level 2: 8 character */ - UART_FIFO_TRGLEV3 /*!< UART FIFO trigger level 3: 14 character */ + UART_FIFO_TRGLEV0 = 0, /*!< UART FIFO trigger level 0: 1 character */ + UART_FIFO_TRGLEV1, /*!< UART FIFO trigger level 1: 4 character */ + UART_FIFO_TRGLEV2, /*!< UART FIFO trigger level 2: 8 character */ + UART_FIFO_TRGLEV3 /*!< UART FIFO trigger level 3: 14 character */ } UART_FITO_LEVEL_Type; /********************************************************************//** * @brief UART Interrupt Type definitions **********************************************************************/ typedef enum { - UART_INTCFG_RBR = 0, /*!< RBR Interrupt enable*/ - UART_INTCFG_THRE, /*!< THR Interrupt enable*/ - UART_INTCFG_RLS, /*!< RX line status interrupt enable*/ - UART1_INTCFG_MS, /*!< Modem status interrupt enable (UART1 only) */ - UART1_INTCFG_CTS, /*!< CTS1 signal transition interrupt enable (UART1 only) */ - UART_INTCFG_ABEO, /*!< Enables the end of auto-baud interrupt */ - UART_INTCFG_ABTO /*!< Enables the auto-baud time-out interrupt */ + UART_INTCFG_RBR = 0, /*!< RBR Interrupt enable*/ + UART_INTCFG_THRE, /*!< THR Interrupt enable*/ + UART_INTCFG_RLS, /*!< RX line status interrupt enable*/ + UART1_INTCFG_MS, /*!< Modem status interrupt enable (UART1 only) */ + UART1_INTCFG_CTS, /*!< CTS1 signal transition interrupt enable (UART1 only) */ + UART_INTCFG_ABEO, /*!< Enables the end of auto-baud interrupt */ + UART_INTCFG_ABTO /*!< Enables the auto-baud time-out interrupt */ } UART_INT_Type; /** * @brief UART Line Status Type definition */ typedef enum { - UART_LINESTAT_RDR = UART_LSR_RDR, /*!DIR |= 1<<4; - LPC_GPIO5->CLR = 1<<4; - LPC_GPIO5->SET = 1<<4; - - /*Disable LCD controller*/ - GLCD_Ctrl (FALSE); - /*Init LCD and copy picture in video RAM*/ - GLCD_Init (_lcd_info.framebuffer); - /*Enable LCD*/ - GLCD_Ctrl (TRUE); - - return RT_EOK; + LPC_GPIO5->DIR |= 1<<4; + LPC_GPIO5->CLR = 1<<4; + LPC_GPIO5->SET = 1<<4; + + /*Disable LCD controller*/ + GLCD_Ctrl (FALSE); + /*Init LCD and copy picture in video RAM*/ + GLCD_Init (_lcd_info.framebuffer); + /*Enable LCD*/ + GLCD_Ctrl (TRUE); + + return RT_EOK; } static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args) { - switch (cmd) - { - case RTGRAPHIC_CTRL_RECT_UPDATE: - break; - case RTGRAPHIC_CTRL_POWERON: - break; - case RTGRAPHIC_CTRL_POWEROFF: - break; - case RTGRAPHIC_CTRL_GET_INFO: - rt_memcpy(args, &_lcd_info, sizeof(_lcd_info)); - break; - case RTGRAPHIC_CTRL_SET_MODE: - break; - } - - return RT_EOK; + switch (cmd) + { + case RTGRAPHIC_CTRL_RECT_UPDATE: + break; + case RTGRAPHIC_CTRL_POWERON: + break; + case RTGRAPHIC_CTRL_POWEROFF: + break; + case RTGRAPHIC_CTRL_GET_INFO: + rt_memcpy(args, &_lcd_info, sizeof(_lcd_info)); + break; + case RTGRAPHIC_CTRL_SET_MODE: + break; + } + + return RT_EOK; } @@ -63,27 +63,27 @@ void rt_hw_lcd_init(void) { rt_uint16_t * _rt_framebuffer = RT_NULL; - // _rt_framebuffer = rt_malloc_align(sizeof(rt_uint16_t)*RT_HW_LCD_HEIGHT*RT_HW_LCD_WIDTH, 8); - // if (_rt_framebuffer == RT_NULL) return; /* no memory yet */ + // _rt_framebuffer = rt_malloc_align(sizeof(rt_uint16_t)*RT_HW_LCD_HEIGHT*RT_HW_LCD_WIDTH, 8); + // if (_rt_framebuffer == RT_NULL) return; /* no memory yet */ - _rt_framebuffer = (rt_uint16_t *)0xA0000000; + _rt_framebuffer = (rt_uint16_t *)0xA0000000; - _lcd_info.bits_per_pixel = 16; - _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565; - _lcd_info.framebuffer = (void*)_rt_framebuffer; - _lcd_info.width = RT_HW_LCD_WIDTH; - _lcd_info.height = RT_HW_LCD_HEIGHT; + _lcd_info.bits_per_pixel = 16; + _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565; + _lcd_info.framebuffer = (void*)_rt_framebuffer; + _lcd_info.width = RT_HW_LCD_WIDTH; + _lcd_info.height = RT_HW_LCD_HEIGHT; - /* init device structure */ - lcd.type = RT_Device_Class_Graphic; - lcd.init = rt_lcd_init; - lcd.open = RT_NULL; - lcd.close = RT_NULL; - lcd.control = rt_lcd_control; - lcd.user_data = (void*)&_lcd_info; + /* init device structure */ + lcd.type = RT_Device_Class_Graphic; + lcd.init = rt_lcd_init; + lcd.open = RT_NULL; + lcd.close = RT_NULL; + lcd.control = rt_lcd_control; + lcd.user_data = (void*)&_lcd_info; - /* register lcd device to RT-Thread */ - rt_device_register(&lcd, "lcd", RT_DEVICE_FLAG_RDWR); + /* register lcd device to RT-Thread */ + rt_device_register(&lcd, "lcd", RT_DEVICE_FLAG_RDWR); } void lcd_fill(uint8_t * start, uint8_t * end, uint8_t pixel) diff --git a/bsp/lpc178x/drivers/lpc_types.h b/bsp/lpc178x/drivers/lpc_types.h index 9cc511a135..a36624baf4 100644 --- a/bsp/lpc178x/drivers/lpc_types.h +++ b/bsp/lpc178x/drivers/lpc_types.h @@ -1,15 +1,15 @@ /********************************************************************** -* $Id$ lpc_types.h 2011-06-02 +* $Id$ lpc_types.h 2011-06-02 *//** -* @file lpc_types.h -* @brief Contains the NXP ABL typedefs for C standard types. -* It is intended to be used in ISO C conforming development -* environments and checks for this insofar as it is possible -* to do so. -* @version 1.0 -* @date 02. June. 2011 -* @author NXP MCU SW Application Team -* +* @file lpc_types.h +* @brief Contains the NXP ABL typedefs for C standard types. +* It is intended to be used in ISO C conforming development +* environments and checks for this insofar as it is possible +* to do so. +* @version 1.0 +* @date 02. June. 2011 +* @author NXP MCU SW Application Team +* * Copyright(C) 2011, NXP Semiconductor * All rights reserved. * @@ -37,7 +37,7 @@ * @ingroup LPC177x_8xCMSIS_FwLib_Drivers * @{ */ - + /* Public Types --------------------------------------------------------------- */ /** @defgroup LPC_Types_Public_Types Basic Public Data Types * @{ @@ -71,8 +71,8 @@ typedef enum {ERROR = 0, SUCCESS = !ERROR} Status; */ typedef enum { - NONE_BLOCKING = 0, /**< None Blocking type */ - BLOCKING, /**< Blocking type */ + NONE_BLOCKING = 0, /**< None Blocking type */ + BLOCKING, /**< Blocking type */ } TRANSFER_BLOCK_Type; @@ -98,7 +98,7 @@ typedef int32_t(*PFI)(); */ #undef _BIT /** Set bit macro */ -#define _BIT(n) (1<TCR = 0x02; /* reset timer */ -// LPC_TIM0->PR = 0x00; /* set prescaler to zero */ -// LPC_TIM0->MR0 = delayInMs * (PeripheralClock / 1000 - 1); -// LPC_TIM0->IR = 0xff; /* reset all interrrupts */ -// LPC_TIM0->MCR = 0x04; /* stop timer on match */ -// LPC_TIM0->TCR = 0x01; /* start timer */ +// LPC_TIM0->TCR = 0x02; /* reset timer */ +// LPC_TIM0->PR = 0x00; /* set prescaler to zero */ +// LPC_TIM0->MR0 = delayInMs * (PeripheralClock / 1000 - 1); +// LPC_TIM0->IR = 0xff; /* reset all interrrupts */ +// LPC_TIM0->MCR = 0x04; /* stop timer on match */ +// LPC_TIM0->TCR = 0x01; /* start timer */ // -// /* wait until delay time has elapsed */ -// while (LPC_TIM0->TCR & 0x01); +// /* wait until delay time has elapsed */ +// while (LPC_TIM0->TCR & 0x01); // } // else if ( timer_num == 1 ) // { -// LPC_TIM1->TCR = 0x02; /* reset timer */ -// LPC_TIM1->PR = 0x00; /* set prescaler to zero */ -// LPC_TIM1->MR0 = delayInMs * (PeripheralClock / 1000 - 1); -// LPC_TIM1->IR = 0xff; /* reset all interrrupts */ -// LPC_TIM1->MCR = 0x04; /* stop timer on match */ -// LPC_TIM1->TCR = 0x01; /* start timer */ +// LPC_TIM1->TCR = 0x02; /* reset timer */ +// LPC_TIM1->PR = 0x00; /* set prescaler to zero */ +// LPC_TIM1->MR0 = delayInMs * (PeripheralClock / 1000 - 1); +// LPC_TIM1->IR = 0xff; /* reset all interrrupts */ +// LPC_TIM1->MCR = 0x04; /* stop timer on match */ +// LPC_TIM1->TCR = 0x01; /* start timer */ // -// /* wait until delay time has elapsed */ -// while (LPC_TIM1->TCR & 0x01); +// /* wait until delay time has elapsed */ +// while (LPC_TIM1->TCR & 0x01); // } // else if ( timer_num == 2 ) // { -// LPC_TIM2->TCR = 0x02; /* reset timer */ -// LPC_TIM2->PR = 0x00; /* set prescaler to zero */ -// LPC_TIM2->MR0 = delayInMs * (PeripheralClock / 1000 - 1); -// LPC_TIM2->IR = 0xff; /* reset all interrrupts */ -// LPC_TIM2->MCR = 0x04; /* stop timer on match */ -// LPC_TIM2->TCR = 0x01; /* start timer */ +// LPC_TIM2->TCR = 0x02; /* reset timer */ +// LPC_TIM2->PR = 0x00; /* set prescaler to zero */ +// LPC_TIM2->MR0 = delayInMs * (PeripheralClock / 1000 - 1); +// LPC_TIM2->IR = 0xff; /* reset all interrrupts */ +// LPC_TIM2->MCR = 0x04; /* stop timer on match */ +// LPC_TIM2->TCR = 0x01; /* start timer */ // -// /* wait until delay time has elapsed */ -// while (LPC_TIM2->TCR & 0x01); +// /* wait until delay time has elapsed */ +// while (LPC_TIM2->TCR & 0x01); // } // else if ( timer_num == 3 ) // { -// LPC_TIM3->TCR = 0x02; /* reset timer */ -// LPC_TIM3->PR = 0x00; /* set prescaler to zero */ -// LPC_TIM3->MR0 = delayInMs * (PeripheralClock / 1000 - 1); -// LPC_TIM3->IR = 0xff; /* reset all interrrupts */ -// LPC_TIM3->MCR = 0x04; /* stop timer on match */ -// LPC_TIM3->TCR = 0x01; /* start timer */ +// LPC_TIM3->TCR = 0x02; /* reset timer */ +// LPC_TIM3->PR = 0x00; /* set prescaler to zero */ +// LPC_TIM3->MR0 = delayInMs * (PeripheralClock / 1000 - 1); +// LPC_TIM3->IR = 0xff; /* reset all interrrupts */ +// LPC_TIM3->MCR = 0x04; /* stop timer on match */ +// LPC_TIM3->TCR = 0x01; /* start timer */ // -// /* wait until delay time has elapsed */ -// while (LPC_TIM3->TCR & 0x01); +// /* wait until delay time has elapsed */ +// while (LPC_TIM3->TCR & 0x01); // } // return; //} @@ -204,7 +204,7 @@ void SDRAM_Init (void) { uint32_t i, dwtemp = dwtemp; uint16_t wtemp = wtemp; - uint32_t mhz, nsPerClk; + uint32_t mhz, nsPerClk; /* Enable External Memory Controller power/clock */ LPC_SC->PCONP |= 0x00000800; LPC_SC->EMCDLYCTL = 0x00001010; @@ -213,10 +213,10 @@ void SDRAM_Init (void) EMC_GPIO_Init(); - mhz = SystemCoreClock / 1000000; - if (LPC_SC->EMCCLKSEL) - mhz >>= 1; - nsPerClk = 1000 / mhz; + mhz = SystemCoreClock / 1000000; + if (LPC_SC->EMCCLKSEL) + mhz >>= 1; + nsPerClk = 1000 / mhz; LPC_EMC->DynamicRP = EMC_NS2CLK(20, nsPerClk); /* 20ns, */ LPC_EMC->DynamicRAS = /*EMC_NS2CLK(42, nsPerClk);*/ 15; /* 42ns to 100K ns, */ LPC_EMC->DynamicSREX = 1 - 1; /* tSRE, 1clk, */ @@ -225,7 +225,7 @@ void SDRAM_Init (void) LPC_EMC->DynamicWR = 2 - 1; /* 2CLK, */ LPC_EMC->DynamicRC = EMC_NS2CLK(63, nsPerClk); /* H57V2562GTR-75C tRC=63ns(min)*/ LPC_EMC->DynamicRFC = EMC_NS2CLK(63, nsPerClk); /* H57V2562GTR-75C tRFC=tRC */ - LPC_EMC->DynamicXSR = 0x0000000F; /* exit self-refresh to active, ²»ÖªµÀ£¬ÉèΪ×î¾Ã */ + LPC_EMC->DynamicXSR = 0x0000000F; /* exit self-refresh to active, ä¸çŸ¥é“,设为最久 */ LPC_EMC->DynamicRRD = EMC_NS2CLK(63, nsPerClk); /* 3clk, tRRD=15ns(min) */ LPC_EMC->DynamicMRD = 2 - 1; /* 2clk, tMRD=2clk(min) */ @@ -249,22 +249,22 @@ void SDRAM_Init (void) #ifdef SDRAM_CONFIG_16BIT LPC_EMC->DynamicConfig0 = 0x680; /* 256Mb, 16Mx16, 4 banks, row=13, column=9, RBC */ #elif defined SDRAM_CONFIG_32BIT - LPC_EMC->DynamicConfig0 = 0x4680; /* 256Mb, 16Mx16, 4 banks, row=13, column=9, RBC */ + LPC_EMC->DynamicConfig0 = 0x4680; /* 256Mb, 16Mx16, 4 banks, row=13, column=9, RBC */ #endif delayMs(0, 100); LPC_EMC->DynamicControl = 0x00000183; /* Issue NOP command */ - delayMs(0, 200); /* wait 200ms */ + delayMs(0, 200); /* wait 200ms */ LPC_EMC->DynamicControl = 0x00000103; /* Issue PALL command */ LPC_EMC->DynamicRefresh = 0x00000002; /* ( n * 16 ) -> 32 clock cycles */ - for(i = 0; i < 0x80; i++); /* wait 128 AHB clock cycles */ + for(i = 0; i < 0x80; i++); /* wait 128 AHB clock cycles */ /* 64ms/8192=7.8125us, nx16x8.33ns<7.8125us, n<58.6*/ - wtemp = 64000000 / (1 << 13); - wtemp -= 16; - wtemp >>= 4; - wtemp = wtemp * mhz / 1000; + wtemp = 64000000 / (1 << 13); + wtemp -= 16; + wtemp >>= 4; + wtemp = wtemp * mhz / 1000; LPC_EMC->DynamicRefresh = wtemp; LPC_EMC->DynamicControl = 0x00000083; /* Issue MODE command */ @@ -273,7 +273,7 @@ void SDRAM_Init (void) wtemp = *((volatile uint16_t *)(SDRAM_BASE | (0x33<<12))); /* 8 burst, 3 CAS latency */ #elif defined SDRAM_CONFIG_32BIT - dwtemp = *((volatile uint32_t *)(SDRAM_BASE | (0x32<<13))); /* 4 burst, 3 CAS latency */ + dwtemp = *((volatile uint32_t *)(SDRAM_BASE | (0x32<<13))); /* 4 burst, 3 CAS latency */ #endif LPC_EMC->DynamicControl = 0x00000000; /* Issue NORMAL command */ diff --git a/bsp/lpc178x/drivers/sdram.h b/bsp/lpc178x/drivers/sdram.h index d89e515ebb..b627bed75e 100644 --- a/bsp/lpc178x/drivers/sdram.h +++ b/bsp/lpc178x/drivers/sdram.h @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #ifndef SDRAM_H_INCLUDED #define SDRAM_H_INCLUDED diff --git a/bsp/lpc178x/drivers/uart.c b/bsp/lpc178x/drivers/uart.c index 0d92eb1fca..cb8e68d30c 100644 --- a/bsp/lpc178x/drivers/uart.c +++ b/bsp/lpc178x/drivers/uart.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -25,14 +25,14 @@ struct rt_uart_lpc { - struct rt_device parent; + struct rt_device parent; - LPC_UART_TypeDef * UART; - IRQn_Type UART_IRQn; + LPC_UART_TypeDef * UART; + IRQn_Type UART_IRQn; - /* buffer for reception */ - rt_uint8_t read_index, save_index; - rt_uint8_t rx_buffer[RT_UART_RX_BUFFER_SIZE]; + /* buffer for reception */ + rt_uint8_t read_index, save_index; + rt_uint8_t rx_buffer[RT_UART_RX_BUFFER_SIZE]; }; #ifdef RT_USING_UART0 @@ -45,96 +45,96 @@ struct rt_uart_lpc uart1_device; #ifdef RT_USING_UART0 void UART0_IRQHandler(void) { - rt_ubase_t level, iir; + rt_ubase_t level, iir; struct rt_uart_lpc* uart = &uart0_device; - /* enter interrupt */ - rt_interrupt_enter(); + /* enter interrupt */ + rt_interrupt_enter(); /* read IIR and clear it */ - iir = uart->UART->IIR; + iir = uart->UART->IIR; - if (iir == UART_IIR_INTID_RDA) /* Receive Data Available */ - { - /* Receive Data Available */ + if (iir == UART_IIR_INTID_RDA) /* Receive Data Available */ + { + /* Receive Data Available */ uart->rx_buffer[uart->save_index] = uart->UART->RBR; level = rt_hw_interrupt_disable(); - uart->save_index ++; + uart->save_index ++; if (uart->save_index >= RT_UART_RX_BUFFER_SIZE) uart->save_index = 0; rt_hw_interrupt_enable(level); - /* invoke callback */ - if(uart->parent.rx_indicate != RT_NULL) - { - rt_size_t length; - if (uart->read_index > uart->save_index) + /* invoke callback */ + if(uart->parent.rx_indicate != RT_NULL) + { + rt_size_t length; + if (uart->read_index > uart->save_index) length = RT_UART_RX_BUFFER_SIZE - uart->read_index + uart->save_index; else length = uart->save_index - uart->read_index; uart->parent.rx_indicate(&uart->parent, length); - } - } + } + } - /* leave interrupt */ - rt_interrupt_leave(); + /* leave interrupt */ + rt_interrupt_leave(); - return; + return; } #endif #ifdef RT_USING_UART1 void UART1_IRQHandler(void) { - rt_ubase_t level, iir; + rt_ubase_t level, iir; struct rt_uart_lpc* uart = &uart1_device; - /* enter interrupt */ - rt_interrupt_enter(); + /* enter interrupt */ + rt_interrupt_enter(); /* read IIR and clear it */ - iir = uart->UART->IIR; + iir = uart->UART->IIR; - if (iir == UART_IIR_INTID_RDA) /* Receive Data Available */ - { - /* Receive Data Available */ + if (iir == UART_IIR_INTID_RDA) /* Receive Data Available */ + { + /* Receive Data Available */ uart->rx_buffer[uart->save_index] = uart->UART->RBR; level = rt_hw_interrupt_disable(); - uart->save_index ++; + uart->save_index ++; if (uart->save_index >= RT_UART_RX_BUFFER_SIZE) uart->save_index = 0; rt_hw_interrupt_enable(level); - /* invoke callback */ - if(uart->parent.rx_indicate != RT_NULL) - { - rt_size_t length; - if (uart->read_index > uart->save_index) + /* invoke callback */ + if(uart->parent.rx_indicate != RT_NULL) + { + rt_size_t length; + if (uart->read_index > uart->save_index) length = RT_UART_RX_BUFFER_SIZE - uart->read_index + uart->save_index; else length = uart->save_index - uart->read_index; uart->parent.rx_indicate(&uart->parent, length); - } - } + } + } - /* leave interrupt */ - rt_interrupt_leave(); + /* leave interrupt */ + rt_interrupt_leave(); - return; + return; } #endif static rt_err_t rt_uart_init (rt_device_t dev) { - struct rt_uart_lpc *uart = (struct rt_uart_lpc*)dev; - UART_CFG_Type UART_ConfigStruct; + struct rt_uart_lpc *uart = (struct rt_uart_lpc*)dev; + UART_CFG_Type UART_ConfigStruct; #ifdef RT_USING_UART0 - if( uart->UART == LPC_UART0 ) + if( uart->UART == LPC_UART0 ) { /* * Initialize UART0 pin connect @@ -184,170 +184,170 @@ static rt_err_t rt_uart_init (rt_device_t dev) #endif #ifdef RT_USING_UART2 - if( uart->UART == LPC_UART2 ) + if( uart->UART == LPC_UART2 ) { } #endif - return RT_EOK; + return RT_EOK; } static rt_err_t rt_uart_open(rt_device_t dev, rt_uint16_t oflag) { struct rt_uart_lpc *uart = (struct rt_uart_lpc*)dev; - RT_ASSERT(dev != RT_NULL); - if (dev->flag & RT_DEVICE_FLAG_INT_RX) - { - /* Enable the UART Interrupt */ - NVIC_EnableIRQ( uart->UART_IRQn ); - } + RT_ASSERT(dev != RT_NULL); + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + /* Enable the UART Interrupt */ + NVIC_EnableIRQ( uart->UART_IRQn ); + } - return RT_EOK; + return RT_EOK; } static rt_err_t rt_uart_close(rt_device_t dev) { struct rt_uart_lpc *uart = (struct rt_uart_lpc*)dev; - RT_ASSERT(dev != RT_NULL); - if (dev->flag & RT_DEVICE_FLAG_INT_RX) - { - /* Disable the UART Interrupt */ - NVIC_DisableIRQ( uart->UART_IRQn ); - } + RT_ASSERT(dev != RT_NULL); + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + /* Disable the UART Interrupt */ + NVIC_DisableIRQ( uart->UART_IRQn ); + } - return RT_EOK; + return RT_EOK; } 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_ASSERT(uart != RT_NULL); - - /* point to buffer */ - ptr = (rt_uint8_t*) buffer; - if (dev->flag & RT_DEVICE_FLAG_INT_RX) - { - while (size) - { - /* interrupt receive */ - rt_base_t level; - - /* disable interrupt */ - level = rt_hw_interrupt_disable(); - if (uart->read_index != uart->save_index) - { - *ptr = uart->rx_buffer[uart->read_index]; - - uart->read_index ++; - if (uart->read_index >= RT_UART_RX_BUFFER_SIZE) - uart->read_index = 0; - } - else - { - /* no data in rx buffer */ - - /* enable interrupt */ - rt_hw_interrupt_enable(level); - break; - } - - /* enable interrupt */ - rt_hw_interrupt_enable(level); - - ptr ++; - size --; - } - - return (rt_uint32_t)ptr - (rt_uint32_t)buffer; - } - - return 0; + 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; + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + while (size) + { + /* interrupt receive */ + rt_base_t level; + + /* disable interrupt */ + level = rt_hw_interrupt_disable(); + if (uart->read_index != uart->save_index) + { + *ptr = uart->rx_buffer[uart->read_index]; + + uart->read_index ++; + if (uart->read_index >= RT_UART_RX_BUFFER_SIZE) + uart->read_index = 0; + } + else + { + /* no data in rx buffer */ + + /* enable interrupt */ + rt_hw_interrupt_enable(level); + break; + } + + /* enable interrupt */ + rt_hw_interrupt_enable(level); + + ptr ++; + size --; + } + + return (rt_uint32_t)ptr - (rt_uint32_t)buffer; + } + + return 0; } static rt_size_t rt_uart_write(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) { - struct rt_uart_lpc *uart = (struct rt_uart_lpc*)dev; - char *ptr; - ptr = (char*)buffer; - - if (dev->flag & RT_DEVICE_FLAG_STREAM) - { - /* stream mode */ - while (size) - { - if (*ptr == '\n') - { - while (!(uart->UART->LSR & UART_LSR_THRE)); + struct rt_uart_lpc *uart = (struct rt_uart_lpc*)dev; + char *ptr; + ptr = (char*)buffer; + + if (dev->flag & RT_DEVICE_FLAG_STREAM) + { + /* stream mode */ + while (size) + { + if (*ptr == '\n') + { + while (!(uart->UART->LSR & UART_LSR_THRE)); UART_SendByte( uart->UART,'\r'); - } - - while (!(uart->UART->LSR & UART_LSR_THRE)); - UART_SendByte( uart->UART,*ptr); - ptr ++; - size --; - } - } - else - { + } + + while (!(uart->UART->LSR & UART_LSR_THRE)); + UART_SendByte( uart->UART,*ptr); + ptr ++; + size --; + } + } + else + { UART_Send( uart->UART, (uint8_t *)buffer, size, BLOCKING); } - return (rt_size_t) ptr - (rt_size_t) buffer; + return (rt_size_t) ptr - (rt_size_t) buffer; } void rt_hw_uart_init(void) { - struct rt_uart_lpc* uart; + struct rt_uart_lpc* uart; #ifdef RT_USING_UART0 - /* get uart device */ - uart = &uart0_device; - uart0_device.UART = LPC_UART0; - uart0_device.UART_IRQn = UART0_IRQn; - - /* device initialization */ - uart->parent.type = RT_Device_Class_Char; - rt_memset(uart->rx_buffer, 0, sizeof(uart->rx_buffer)); - uart->read_index = uart->save_index = 0; - - /* device interface */ - uart->parent.init = rt_uart_init; - uart->parent.open = rt_uart_open; - uart->parent.close = rt_uart_close; - uart->parent.read = rt_uart_read; - uart->parent.write = rt_uart_write; - uart->parent.control = RT_NULL; - uart->parent.user_data = RT_NULL; - - rt_device_register(&uart->parent, - "uart0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX); + /* get uart device */ + uart = &uart0_device; + uart0_device.UART = LPC_UART0; + uart0_device.UART_IRQn = UART0_IRQn; + + /* device initialization */ + uart->parent.type = RT_Device_Class_Char; + rt_memset(uart->rx_buffer, 0, sizeof(uart->rx_buffer)); + uart->read_index = uart->save_index = 0; + + /* device interface */ + uart->parent.init = rt_uart_init; + uart->parent.open = rt_uart_open; + uart->parent.close = rt_uart_close; + uart->parent.read = rt_uart_read; + uart->parent.write = rt_uart_write; + uart->parent.control = RT_NULL; + uart->parent.user_data = RT_NULL; + + rt_device_register(&uart->parent, + "uart0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX); #endif #ifdef RT_USING_UART1 - /* get uart device */ - uart = &uart1_device; - uart1_device.UART = (LPC_UART_TypeDef *)LPC_UART1; - uart1_device.UART_IRQn = UART1_IRQn; - - /* device initialization */ - uart->parent.type = RT_Device_Class_Char; - rt_memset(uart->rx_buffer, 0, sizeof(uart->rx_buffer)); - uart->read_index = uart->save_index = 0; - - /* device interface */ - uart->parent.init = rt_uart_init; - uart->parent.open = rt_uart_open; - uart->parent.close = rt_uart_close; - uart->parent.read = rt_uart_read; - uart->parent.write = rt_uart_write; - uart->parent.control = RT_NULL; - uart->parent.user_data = RT_NULL; - - rt_device_register(&uart->parent, - "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX); + /* get uart device */ + uart = &uart1_device; + uart1_device.UART = (LPC_UART_TypeDef *)LPC_UART1; + uart1_device.UART_IRQn = UART1_IRQn; + + /* device initialization */ + uart->parent.type = RT_Device_Class_Char; + rt_memset(uart->rx_buffer, 0, sizeof(uart->rx_buffer)); + uart->read_index = uart->save_index = 0; + + /* device interface */ + uart->parent.init = rt_uart_init; + uart->parent.open = rt_uart_open; + uart->parent.close = rt_uart_close; + uart->parent.read = rt_uart_read; + uart->parent.write = rt_uart_write; + uart->parent.control = RT_NULL; + uart->parent.user_data = RT_NULL; + + rt_device_register(&uart->parent, + "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX); #endif } diff --git a/bsp/lpc178x/rtconfig.h b/bsp/lpc178x/rtconfig.h index 25f99888f7..ce51ba355f 100644 --- a/bsp/lpc178x/rtconfig.h +++ b/bsp/lpc178x/rtconfig.h @@ -5,17 +5,17 @@ // // -#define RT_NAME_MAX 6 +#define RT_NAME_MAX 6 // -#define RT_ALIGN_SIZE 4 +#define RT_ALIGN_SIZE 4 // // 8 // 32 // 256 // -#define RT_THREAD_PRIORITY_MAX 32 +#define RT_THREAD_PRIORITY_MAX 32 // -#define RT_TICK_PER_SECOND 100 +#define RT_TICK_PER_SECOND 100 //
#define RT_DEBUG #define RT_DEBUG_COLOR @@ -30,11 +30,11 @@ //
// #define RT_USING_TIMER_SOFT // -#define RT_TIMER_THREAD_PRIO 4 +#define RT_TIMER_THREAD_PRIO 4 // -#define RT_TIMER_THREAD_STACK_SIZE 512 +#define RT_TIMER_THREAD_STACK_SIZE 512 // -#define RT_TIMER_TICK_PER_SECOND 10 +#define RT_TIMER_TICK_PER_SECOND 10 //
//
@@ -66,13 +66,13 @@ //
#define RT_USING_DEVICE // -#define RT_UART_RX_BUFFER_SIZE 64 +#define RT_UART_RX_BUFFER_SIZE 64 //
//
#define RT_USING_CONSOLE // -#define RT_CONSOLEBUF_SIZE 128 +#define RT_CONSOLEBUF_SIZE 128 //
// @@ -84,7 +84,7 @@ // #define FINSH_USING_DESCRIPTION // -#define FINSH_THREAD_STACK_SIZE 4096 +#define FINSH_THREAD_STACK_SIZE 4096 //
//
@@ -99,18 +99,18 @@ // // #define DFS_USING_WORKDIR // -#define DFS_FILESYSTEMS_MAX 2 +#define DFS_FILESYSTEMS_MAX 2 // -#define DFS_FD_MAX 4 +#define DFS_FD_MAX 4 // #define RT_USING_DFS_ELMFAT // // 1 // 2 // -#define RT_DFS_ELM_USE_LFN 1 +#define RT_DFS_ELM_USE_LFN 1 // -#define RT_DFS_ELM_MAX_LFN 64 +#define RT_DFS_ELM_MAX_LFN 64 // // #define RT_USING_DFS_YAFFS2 // @@ -120,7 +120,7 @@ // // #define RT_USING_DFS_NFS // -#define RT_NFS_HOST_EXPORT "192.168.1.5:/" +#define RT_NFS_HOST_EXPORT "192.168.1.5:/" //
//
@@ -136,31 +136,31 @@ // #define RT_LWIP_DNS // -#define RT_LWIP_PBUF_NUM 4 +#define RT_LWIP_PBUF_NUM 4 // -#define RT_LWIP_TCP_PCB_NUM 3 +#define RT_LWIP_TCP_PCB_NUM 3 // -#define RT_LWIP_TCP_SND_BUF 2048 +#define RT_LWIP_TCP_SND_BUF 2048 // -#define RT_LWIP_TCP_WND 2048 +#define RT_LWIP_TCP_WND 2048 // // #define RT_LWIP_SNMP // // #define RT_LWIP_DHCP // -#define RT_LWIP_TCP_SEG_NUM 4 +#define RT_LWIP_TCP_SEG_NUM 4 // -#define RT_LWIP_TCPTHREAD_PRIORITY 12 +#define RT_LWIP_TCPTHREAD_PRIORITY 12 // -#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8 +#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8 // -#define RT_LWIP_TCPTHREAD_STACKSIZE 4096 +#define RT_LWIP_TCPTHREAD_STACKSIZE 4096 // -#define RT_LWIP_ETHTHREAD_PRIORITY 14 +#define RT_LWIP_ETHTHREAD_PRIORITY 14 // -#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8 +#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8 // -#define RT_LWIP_ETHTHREAD_STACKSIZE 512 +#define RT_LWIP_ETHTHREAD_STACKSIZE 512 // #define RT_LWIP_IPADDR0 192 #define RT_LWIP_IPADDR1 168 @@ -181,7 +181,7 @@ //
// #define RT_USING_RTGUI // -#define RTGUI_NAME_MAX 12 +#define RTGUI_NAME_MAX 12 // #define RTGUI_USING_SMALL_SIZE // @@ -191,7 +191,7 @@ // #define RTGUI_USING_FONTHZ // -#define RTGUI_DEFAULT_FONT_SIZE 16 +#define RTGUI_DEFAULT_FONT_SIZE 16 // // #define RTGUI_USING_DFS_FILERW // diff --git a/bsp/lpc2148/applications/application.c b/bsp/lpc2148/applications/application.c index fd07f22f05..731b30a510 100644 --- a/bsp/lpc2148/applications/application.c +++ b/bsp/lpc2148/applications/application.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc2148/applications/startup.c b/bsp/lpc2148/applications/startup.c index cc16a5c12b..a3229083ac 100644 --- a/bsp/lpc2148/applications/startup.c +++ b/bsp/lpc2148/applications/startup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc2148/drivers/board.c b/bsp/lpc2148/drivers/board.c index 96a4aa62f4..757e1cb8f0 100644 --- a/bsp/lpc2148/drivers/board.c +++ b/bsp/lpc2148/drivers/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -25,13 +25,13 @@ */ void rt_hw_timer_handler(int vector, void *param) { - rt_tick_increase(); + rt_tick_increase(); - /* clear interrupt flag */ - T0IR |= 0x01; + /* clear interrupt flag */ + T0IR |= 0x01; - /* acknowledge Interrupt */ - VICVectAddr = 0; + /* acknowledge Interrupt */ + VICVectAddr = 0; } /** @@ -42,37 +42,37 @@ void rt_hw_timer_handler(int vector, void *param) */ void rt_hw_console_output(const char* str) { - while (*str) - { - if (*str=='\n') - { - while (!(U0LSR & 0x20)); - U0THR = '\r'; - } - - while (!(U0LSR & 0x20)); - U0THR = *str; - - str ++; - } + while (*str) + { + if (*str=='\n') + { + while (!(U0LSR & 0x20)); + U0THR = '\r'; + } + + while (!(U0LSR & 0x20)); + U0THR = *str; + + str ++; + } } -#define BAUD_RATE 115200 -#define U0PINS 0x05 +#define BAUD_RATE 115200 +#define U0PINS 0x05 void rt_hw_console_init() { - /* Enable RxD and TxD pins */ - PINSEL0 = U0PINS; + /* Enable RxD and TxD pins */ + PINSEL0 = U0PINS; - /* 8 bits, no Parity, 1 Stop bit */ - U0LCR = 0x83; + /* 8 bits, no Parity, 1 Stop bit */ + U0LCR = 0x83; - /* Setup Baudrate */ - U0DLL = (PCLK/16/BAUD_RATE) & 0xFF; - U0DLM = ((PCLK/16/BAUD_RATE) >> 8) & 0xFF; + /* Setup Baudrate */ + U0DLL = (PCLK/16/BAUD_RATE) & 0xFF; + U0DLM = ((PCLK/16/BAUD_RATE) >> 8) & 0xFF; - /* DLAB = 0 */ - U0LCR = 0x03; + /* DLAB = 0 */ + U0LCR = 0x03; } /** @@ -80,23 +80,23 @@ void rt_hw_console_init() */ void rt_hw_board_init(void) { - /* console init */ - rt_hw_console_init(); + /* console init */ + rt_hw_console_init(); - /* prescaler = 0*/ - T0PR = 0; - T0PC = 0; + /* prescaler = 0*/ + T0PR = 0; + T0PC = 0; - /* reset and enable MR0 interrupt */ - T0MCR = 0x3; - T0MR0 = PCLK / RT_TICK_PER_SECOND; + /* reset and enable MR0 interrupt */ + T0MCR = 0x3; + T0MR0 = PCLK / RT_TICK_PER_SECOND; - /* enable timer 0 */ - T0TCR = 1; + /* enable timer 0 */ + T0TCR = 1; - /* install timer handler */ - rt_hw_interrupt_install(TIMER0_INT, rt_hw_timer_handler, RT_NULL, "TIMER0"); - rt_hw_interrupt_umask(TIMER0_INT); + /* install timer handler */ + rt_hw_interrupt_install(TIMER0_INT, rt_hw_timer_handler, RT_NULL, "TIMER0"); + rt_hw_interrupt_umask(TIMER0_INT); } /*@}*/ diff --git a/bsp/lpc2148/drivers/board.h b/bsp/lpc2148/drivers/board.h index 346f10182f..957f360652 100644 --- a/bsp/lpc2148/drivers/board.h +++ b/bsp/lpc2148/drivers/board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -12,13 +12,13 @@ #define __BOARD_H__ #include -#define CCLK 60000000 /* Fosc = 12MHz, M = 5 */ -#define PCLK 15000000 /* CCLK/4, use default */ +#define CCLK 60000000 /* Fosc = 12MHz, M = 5 */ +#define PCLK 15000000 /* CCLK/4, use default */ /* RT_USING_UART */ #define RT_USING_UART1 #define RT_USING_UART2 -#define RT_UART_RX_BUFFER_SIZE 64 +#define RT_UART_RX_BUFFER_SIZE 64 void rt_hw_board_init(void); diff --git a/bsp/lpc2148/drivers/dm9000.c b/bsp/lpc2148/drivers/dm9000.c index 169be59f12..9bc8d445f9 100644 --- a/bsp/lpc2148/drivers/dm9000.c +++ b/bsp/lpc2148/drivers/dm9000.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -15,11 +15,11 @@ #define MAX_ADDR_LEN 6 struct rt_dm9000_eth { - /* inherit from ethernet device */ - struct eth_device parent; + /* inherit from ethernet device */ + struct eth_device parent; - /* interface address info. */ - rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* hw address */ + /* interface address info. */ + rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* hw address */ }; static struct rt_dm9000_eth dm9000_device; @@ -52,67 +52,67 @@ static rt_err_t rt_dm9000_init(rt_device_t dev) static rt_err_t rt_dm9000_open(rt_device_t dev, rt_uint16_t oflag) { - return RT_EOK; + return RT_EOK; } static rt_err_t rt_dm9000_close(rt_device_t dev) { - return RT_EOK; + return RT_EOK; } static rt_size_t rt_dm9000_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) { - rt_set_errno(-RT_ENOSYS); - return 0; + rt_set_errno(-RT_ENOSYS); + return 0; } static rt_size_t rt_dm9000_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) { - rt_set_errno(-RT_ENOSYS); - return 0; + rt_set_errno(-RT_ENOSYS); + return 0; } static rt_err_t rt_dm9000_control(rt_device_t dev, int cmd, void *args) { - switch(cmd) - { - case NIOCTL_GADDR: - /* get mac address */ - if(args) rt_memcpy(args, dm9000_device.dev_addr, 6); - else return -RT_ERROR; - break; - - default : - break; - } - - return RT_EOK; + switch(cmd) + { + case NIOCTL_GADDR: + /* get mac address */ + if(args) rt_memcpy(args, dm9000_device.dev_addr, 6); + else return -RT_ERROR; + break; + + default : + break; + } + + return RT_EOK; } /* ethernet device interface */ /* transmit packet. */ rt_err_t rt_dm9000_tx( rt_device_t dev, struct pbuf* p) { - struct pbuf* q; - rt_uint32_t len; - rt_uint8_t* ptr; + struct pbuf* q; + rt_uint32_t len; + rt_uint8_t* ptr; - for (q = p; q != NULL; q = q->next) - { - len = q->len; - ptr = q->payload; + for (q = p; q != NULL; q = q->next) + { + len = q->len; + ptr = q->payload; - /* write data to device */ - } + /* write data to device */ + } - return RT_EOK; + return RT_EOK; } /* reception packet. */ struct pbuf *rt_dm9000_rx(rt_device_t dev) { struct pbuf* p; - rt_uint32_t len; + rt_uint32_t len; /* init p pointer */ p = RT_NULL; @@ -149,17 +149,17 @@ struct pbuf *rt_dm9000_rx(rt_device_t dev) void rt_hw_dm9000_init() { - dm9000_device.parent.parent.init = rt_dm9000_init; - dm9000_device.parent.parent.open = rt_dm9000_open; - dm9000_device.parent.parent.close = rt_dm9000_close; - dm9000_device.parent.parent.read = rt_dm9000_read; - dm9000_device.parent.parent.write = rt_dm9000_write; - dm9000_device.parent.parent.control = rt_dm9000_control; - dm9000_device.parent.parent.user_data = RT_NULL; - - dm9000_device.parent.eth_rx = rt_dm9000_rx; - dm9000_device.parent.eth_tx = rt_dm9000_tx; - - rt_device_register((rt_device_t)&dm9000_device, - "E0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX); + dm9000_device.parent.parent.init = rt_dm9000_init; + dm9000_device.parent.parent.open = rt_dm9000_open; + dm9000_device.parent.parent.close = rt_dm9000_close; + dm9000_device.parent.parent.read = rt_dm9000_read; + dm9000_device.parent.parent.write = rt_dm9000_write; + dm9000_device.parent.parent.control = rt_dm9000_control; + dm9000_device.parent.parent.user_data = RT_NULL; + + dm9000_device.parent.eth_rx = rt_dm9000_rx; + dm9000_device.parent.eth_tx = rt_dm9000_tx; + + rt_device_register((rt_device_t)&dm9000_device, + "E0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX); } diff --git a/bsp/lpc2148/drivers/sd.c b/bsp/lpc2148/drivers/sd.c index d7b6769621..144c9f2ff5 100644 --- a/bsp/lpc2148/drivers/sd.c +++ b/bsp/lpc2148/drivers/sd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -22,12 +22,12 @@ static rt_err_t rt_sdcard_init(rt_device_t dev) static rt_err_t rt_sdcard_open(rt_device_t dev, rt_uint16_t oflag) { - return RT_EOK; + return RT_EOK; } static rt_err_t rt_sdcard_close(rt_device_t dev) { - return RT_EOK; + return RT_EOK; } static rt_size_t rt_sdcard_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) @@ -48,54 +48,54 @@ static rt_size_t rt_sdcard_write (rt_device_t dev, rt_off_t pos, const void* buf static rt_err_t rt_sdcard_control(rt_device_t dev, int cmd, void *args) { - return RT_EOK; + return RT_EOK; } void rt_hw_sdcard_init() { rt_size_t length; - rt_uint8_t* sector; + rt_uint8_t* sector; /* sdcard hardware init */ - sd.type = RT_Device_Class_Block; - sd.init = rt_sdcard_init; - sd.open = rt_sdcard_open; - sd.close = rt_sdcard_close; - sd.read = rt_sdcard_read; - sd.write = rt_sdcard_write; - sd.control = rt_sdcard_control; - sd.user_data = RT_NULL; - - /* get the first sector to read partition table */ - sector = (rt_uint8_t*) rt_malloc (512); - if (sector == RT_NULL) - { - rt_kprintf("allocate partition sector buffer failed\n"); - return; - } - - length = rt_sdcard_read((rt_device_t)&sd, 0, sector, 512); - if (length == 512) - { - rt_err_t status; - - /* get the first partition */ - status = dfs_filesystem_get_partition(&part, sector, 0); - if (status != RT_EOK) - { - /* there is no partition table */ - part.offset = 0; - part.size = 0; - } - } - else - { - /* there is no partition table */ - part.offset = 0; - part.size = 0; - } - - rt_device_register(&sd, - "sd", RT_DEVICE_FLAG_RDWR); + sd.type = RT_Device_Class_Block; + sd.init = rt_sdcard_init; + sd.open = rt_sdcard_open; + sd.close = rt_sdcard_close; + sd.read = rt_sdcard_read; + sd.write = rt_sdcard_write; + sd.control = rt_sdcard_control; + sd.user_data = RT_NULL; + + /* get the first sector to read partition table */ + sector = (rt_uint8_t*) rt_malloc (512); + if (sector == RT_NULL) + { + rt_kprintf("allocate partition sector buffer failed\n"); + return; + } + + length = rt_sdcard_read((rt_device_t)&sd, 0, sector, 512); + if (length == 512) + { + rt_err_t status; + + /* get the first partition */ + status = dfs_filesystem_get_partition(&part, sector, 0); + if (status != RT_EOK) + { + /* there is no partition table */ + part.offset = 0; + part.size = 0; + } + } + else + { + /* there is no partition table */ + part.offset = 0; + part.size = 0; + } + + rt_device_register(&sd, + "sd", RT_DEVICE_FLAG_RDWR); } diff --git a/bsp/lpc2148/drivers/serial.c b/bsp/lpc2148/drivers/serial.c index 0c78ecc026..36bbcbd608 100644 --- a/bsp/lpc2148/drivers/serial.c +++ b/bsp/lpc2148/drivers/serial.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -15,8 +15,8 @@ #include "board.h" /* serial hardware register */ -#define REG8(d) (*((volatile unsigned char *)(d))) -#define REG32(d) (*((volatile unsigned long *)(d))) +#define REG8(d) (*((volatile unsigned char *)(d))) +#define REG32(d) (*((volatile unsigned long *)(d))) #define UART_RBR(base) REG8(base + 0x00) #define UART_THR(base) REG8(base + 0x00) @@ -37,16 +37,16 @@ /* LPC serial device */ struct rt_lpcserial { - /* inherit from device */ - struct rt_device parent; + /* inherit from device */ + struct rt_device parent; - rt_uint32_t hw_base; - rt_uint32_t irqno; - rt_uint32_t baudrate; + rt_uint32_t hw_base; + rt_uint32_t irqno; + rt_uint32_t baudrate; - /* reception field */ - rt_uint16_t save_index, read_index; - rt_uint8_t rx_buffer[RT_UART_RX_BUFFER_SIZE]; + /* reception field */ + rt_uint16_t save_index, read_index; + rt_uint8_t rx_buffer[RT_UART_RX_BUFFER_SIZE]; }; #ifdef RT_USING_UART1 @@ -58,70 +58,70 @@ struct rt_lpcserial serial2; void rt_hw_serial_init(void); -#define U0PINS 0x00000005 +#define U0PINS 0x00000005 void rt_hw_uart_isr(struct rt_lpcserial* lpc_serial) { - RT_UNUSED rt_uint32_t iir; - - RT_ASSERT(lpc_serial != RT_NULL) - - if (UART_LSR(lpc_serial->hw_base) & 0x01) - { - rt_base_t level; - - while (UART_LSR(lpc_serial->hw_base) & 0x01) - { - /* disable interrupt */ - level = rt_hw_interrupt_disable(); - - /* read character */ - lpc_serial->rx_buffer[lpc_serial->save_index] = - UART_RBR(lpc_serial->hw_base); - lpc_serial->save_index ++; - if (lpc_serial->save_index >= RT_UART_RX_BUFFER_SIZE) - lpc_serial->save_index = 0; - - /* if the next position is read index, discard this 'read char' */ - if (lpc_serial->save_index == lpc_serial->read_index) - { - lpc_serial->read_index ++; - if (lpc_serial->read_index >= RT_UART_RX_BUFFER_SIZE) - lpc_serial->read_index = 0; - } - - /* enable interrupt */ - rt_hw_interrupt_enable(level); - } - - /* invoke callback */ - if(lpc_serial->parent.rx_indicate != RT_NULL) - { - lpc_serial->parent.rx_indicate(&lpc_serial->parent, 1); - } - } - - /* clear interrupt source */ - iir = UART_IIR(lpc_serial->hw_base); - - /* acknowledge Interrupt */ - VICVectAddr = 0; + RT_UNUSED rt_uint32_t iir; + + RT_ASSERT(lpc_serial != RT_NULL) + + if (UART_LSR(lpc_serial->hw_base) & 0x01) + { + rt_base_t level; + + while (UART_LSR(lpc_serial->hw_base) & 0x01) + { + /* disable interrupt */ + level = rt_hw_interrupt_disable(); + + /* read character */ + lpc_serial->rx_buffer[lpc_serial->save_index] = + UART_RBR(lpc_serial->hw_base); + lpc_serial->save_index ++; + if (lpc_serial->save_index >= RT_UART_RX_BUFFER_SIZE) + lpc_serial->save_index = 0; + + /* if the next position is read index, discard this 'read char' */ + if (lpc_serial->save_index == lpc_serial->read_index) + { + lpc_serial->read_index ++; + if (lpc_serial->read_index >= RT_UART_RX_BUFFER_SIZE) + lpc_serial->read_index = 0; + } + + /* enable interrupt */ + rt_hw_interrupt_enable(level); + } + + /* invoke callback */ + if(lpc_serial->parent.rx_indicate != RT_NULL) + { + lpc_serial->parent.rx_indicate(&lpc_serial->parent, 1); + } + } + + /* clear interrupt source */ + iir = UART_IIR(lpc_serial->hw_base); + + /* acknowledge Interrupt */ + VICVectAddr = 0; } #ifdef RT_USING_UART1 void rt_hw_uart_isr_1(int irqno, void *param) { - /* get lpc serial device */ - rt_hw_uart_isr(&serial1); -} + /* get lpc serial device */ + rt_hw_uart_isr(&serial1); +} #endif #ifdef RT_USING_UART2 void rt_hw_uart_isr_2(int irqno, void *param) { - /* get lpc serial device */ - rt_hw_uart_isr(&serial2); -} + /* get lpc serial device */ + rt_hw_uart_isr(&serial2); +} #endif /** @@ -131,256 +131,256 @@ void rt_hw_uart_isr_2(int irqno, void *param) static rt_err_t rt_serial_init (rt_device_t dev) { - return RT_EOK; + return RT_EOK; } static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag) { - struct rt_lpcserial* lpc_serial; - lpc_serial = (struct rt_lpcserial*) dev; - - RT_ASSERT(lpc_serial != RT_NULL); - if (dev->flag & RT_DEVICE_FLAG_INT_RX) - { - /* init UART rx interrupt */ - UART_IER(lpc_serial->hw_base) = 0x01; - - /* install ISR */ - if (lpc_serial->irqno == UART0_INT) - { + struct rt_lpcserial* lpc_serial; + lpc_serial = (struct rt_lpcserial*) dev; + + RT_ASSERT(lpc_serial != RT_NULL); + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + /* init UART rx interrupt */ + UART_IER(lpc_serial->hw_base) = 0x01; + + /* install ISR */ + if (lpc_serial->irqno == UART0_INT) + { #ifdef RT_USING_UART1 - rt_hw_interrupt_install(lpc_serial->irqno, + rt_hw_interrupt_install(lpc_serial->irqno, rt_hw_uart_isr_1, &serial1, "UART1"); #endif - } - else - { + } + else + { #ifdef RT_USING_UART2 - rt_hw_interrupt_install(lpc_serial->irqno, + rt_hw_interrupt_install(lpc_serial->irqno, rt_hw_uart_isr_2, &serial2, "UART2"); #endif - } + } - rt_hw_interrupt_umask(lpc_serial->irqno); - } + rt_hw_interrupt_umask(lpc_serial->irqno); + } - return RT_EOK; + return RT_EOK; } static rt_err_t rt_serial_close(rt_device_t dev) { - struct rt_lpcserial* lpc_serial; - lpc_serial = (struct rt_lpcserial*) dev; + struct rt_lpcserial* lpc_serial; + lpc_serial = (struct rt_lpcserial*) dev; - RT_ASSERT(lpc_serial != RT_NULL); + RT_ASSERT(lpc_serial != RT_NULL); - if (dev->flag & RT_DEVICE_FLAG_INT_RX) - { - /* disable UART rx interrupt */ - UART_IER(lpc_serial->hw_base) = 0x00; - } + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + /* disable UART rx interrupt */ + UART_IER(lpc_serial->hw_base) = 0x00; + } - return RT_EOK; + return RT_EOK; } static rt_err_t rt_serial_control(rt_device_t dev, int cmd, void *args) { - return RT_EOK; + return RT_EOK; } static rt_size_t rt_serial_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) { - rt_uint8_t* ptr; - struct rt_lpcserial *lpc_serial = (struct rt_lpcserial*)dev; - RT_ASSERT(lpc_serial != RT_NULL); - - /* point to buffer */ - ptr = (rt_uint8_t*) buffer; - - if (dev->flag & RT_DEVICE_FLAG_INT_RX) - { - while (size) - { - /* interrupt receive */ - rt_base_t level; - - /* disable interrupt */ - level = rt_hw_interrupt_disable(); - if (lpc_serial->read_index != lpc_serial->save_index) - { - *ptr = lpc_serial->rx_buffer[lpc_serial->read_index]; - - lpc_serial->read_index ++; - if (lpc_serial->read_index >= RT_UART_RX_BUFFER_SIZE) - lpc_serial->read_index = 0; - } - else - { - /* no data in rx buffer */ - - /* enable interrupt */ - rt_hw_interrupt_enable(level); - break; - } - - /* enable interrupt */ - rt_hw_interrupt_enable(level); - - ptr ++; size --; - } - - return (rt_uint32_t)ptr - (rt_uint32_t)buffer; - } - else if (dev->flag & RT_DEVICE_FLAG_DMA_RX) - { - /* not support right now */ - RT_ASSERT(0); - } - - /* polling mode */ - while (size && (UART_LSR(lpc_serial->hw_base) & 0x01)) - { - /* Read Character */ - *ptr = UART_RBR(lpc_serial->hw_base); - - ptr ++; - size --; - } - - return (rt_size_t)ptr - (rt_size_t)buffer; + rt_uint8_t* ptr; + struct rt_lpcserial *lpc_serial = (struct rt_lpcserial*)dev; + RT_ASSERT(lpc_serial != RT_NULL); + + /* point to buffer */ + ptr = (rt_uint8_t*) buffer; + + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + while (size) + { + /* interrupt receive */ + rt_base_t level; + + /* disable interrupt */ + level = rt_hw_interrupt_disable(); + if (lpc_serial->read_index != lpc_serial->save_index) + { + *ptr = lpc_serial->rx_buffer[lpc_serial->read_index]; + + lpc_serial->read_index ++; + if (lpc_serial->read_index >= RT_UART_RX_BUFFER_SIZE) + lpc_serial->read_index = 0; + } + else + { + /* no data in rx buffer */ + + /* enable interrupt */ + rt_hw_interrupt_enable(level); + break; + } + + /* enable interrupt */ + rt_hw_interrupt_enable(level); + + ptr ++; size --; + } + + return (rt_uint32_t)ptr - (rt_uint32_t)buffer; + } + else if (dev->flag & RT_DEVICE_FLAG_DMA_RX) + { + /* not support right now */ + RT_ASSERT(0); + } + + /* polling mode */ + while (size && (UART_LSR(lpc_serial->hw_base) & 0x01)) + { + /* Read Character */ + *ptr = UART_RBR(lpc_serial->hw_base); + + ptr ++; + size --; + } + + return (rt_size_t)ptr - (rt_size_t)buffer; } static rt_size_t rt_serial_write(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) { - struct rt_lpcserial* lpc_serial; - char *ptr; - - lpc_serial = (struct rt_lpcserial*) dev; - if (dev->flag & RT_DEVICE_FLAG_INT_TX) - { - /* not support */ - RT_ASSERT(0); - } - else if (dev->flag & RT_DEVICE_FLAG_DMA_TX) - { - /* not support */ - RT_ASSERT(0); - } - - /* polling write */ - ptr = (char *)buffer; - - if (dev->flag & RT_DEVICE_FLAG_STREAM) - { - /* stream mode */ - while (size) - { - if (*ptr == '\n') - { - while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); - UART_THR(lpc_serial->hw_base) = '\r'; - } - - while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); - UART_THR(lpc_serial->hw_base) = *ptr; - - ptr ++; - size --; - } - } - else - { - while (size) - { - while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); - UART_THR(lpc_serial->hw_base) = *ptr; - - ptr ++; - size --; - } - } - - return (rt_size_t) ptr - (rt_size_t) buffer; + struct rt_lpcserial* lpc_serial; + char *ptr; + + lpc_serial = (struct rt_lpcserial*) dev; + if (dev->flag & RT_DEVICE_FLAG_INT_TX) + { + /* not support */ + RT_ASSERT(0); + } + else if (dev->flag & RT_DEVICE_FLAG_DMA_TX) + { + /* not support */ + RT_ASSERT(0); + } + + /* polling write */ + ptr = (char *)buffer; + + if (dev->flag & RT_DEVICE_FLAG_STREAM) + { + /* stream mode */ + while (size) + { + if (*ptr == '\n') + { + while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); + UART_THR(lpc_serial->hw_base) = '\r'; + } + + while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); + UART_THR(lpc_serial->hw_base) = *ptr; + + ptr ++; + size --; + } + } + else + { + while (size) + { + while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); + UART_THR(lpc_serial->hw_base) = *ptr; + + ptr ++; + size --; + } + } + + return (rt_size_t) ptr - (rt_size_t) buffer; } void rt_hw_serial_init(void) { - struct rt_lpcserial* lpc_serial; + struct rt_lpcserial* lpc_serial; #ifdef RT_USING_UART1 - lpc_serial = &serial1; + lpc_serial = &serial1; - lpc_serial->parent.type = RT_Device_Class_Char; + lpc_serial->parent.type = RT_Device_Class_Char; - lpc_serial->hw_base = 0xE000C000; - lpc_serial->baudrate = 115200; - lpc_serial->irqno = UART0_INT; + lpc_serial->hw_base = 0xE000C000; + lpc_serial->baudrate = 115200; + lpc_serial->irqno = UART0_INT; - rt_memset(lpc_serial->rx_buffer, 0, sizeof(lpc_serial->rx_buffer)); - lpc_serial->read_index = lpc_serial->save_index = 0; + rt_memset(lpc_serial->rx_buffer, 0, sizeof(lpc_serial->rx_buffer)); + lpc_serial->read_index = lpc_serial->save_index = 0; - /* Enable UART0 RxD and TxD pins */ + /* Enable UART0 RxD and TxD pins */ PINSEL0 |= 0x05; - /* 8 bits, no Parity, 1 Stop bit */ - UART_LCR(lpc_serial->hw_base) = 0x83; + /* 8 bits, no Parity, 1 Stop bit */ + UART_LCR(lpc_serial->hw_base) = 0x83; - /* Setup Baudrate */ - UART_DLL(lpc_serial->hw_base) = (PCLK/16/lpc_serial->baudrate) & 0xFF; - UART_DLM(lpc_serial->hw_base) = ((PCLK/16/lpc_serial->baudrate) >> 8) & 0xFF; + /* Setup Baudrate */ + UART_DLL(lpc_serial->hw_base) = (PCLK/16/lpc_serial->baudrate) & 0xFF; + UART_DLM(lpc_serial->hw_base) = ((PCLK/16/lpc_serial->baudrate) >> 8) & 0xFF; - /* DLAB = 0 */ - UART_LCR(lpc_serial->hw_base) = 0x03; + /* DLAB = 0 */ + UART_LCR(lpc_serial->hw_base) = 0x03; - lpc_serial->parent.type = RT_Device_Class_Char; - lpc_serial->parent.init = rt_serial_init; - lpc_serial->parent.open = rt_serial_open; - lpc_serial->parent.close = rt_serial_close; - lpc_serial->parent.read = rt_serial_read; - lpc_serial->parent.write = rt_serial_write; - lpc_serial->parent.control = rt_serial_control; - lpc_serial->parent.user_data = RT_NULL; + lpc_serial->parent.type = RT_Device_Class_Char; + lpc_serial->parent.init = rt_serial_init; + lpc_serial->parent.open = rt_serial_open; + lpc_serial->parent.close = rt_serial_close; + lpc_serial->parent.read = rt_serial_read; + lpc_serial->parent.write = rt_serial_write; + lpc_serial->parent.control = rt_serial_control; + lpc_serial->parent.user_data = RT_NULL; - rt_device_register(&lpc_serial->parent, - "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX); + rt_device_register(&lpc_serial->parent, + "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX); #endif #ifdef RT_USING_UART2 - lpc_serial = &serial2; + lpc_serial = &serial2; - lpc_serial->parent.type = RT_Device_Class_Char; + lpc_serial->parent.type = RT_Device_Class_Char; - lpc_serial->hw_base = 0xE0010000; - lpc_serial->baudrate = 115200; - lpc_serial->irqno = UART1_INT; + lpc_serial->hw_base = 0xE0010000; + lpc_serial->baudrate = 115200; + lpc_serial->irqno = UART1_INT; - rt_memset(lpc_serial->rx_buffer, 0, sizeof(lpc_serial->rx_buffer)); - lpc_serial->read_index = lpc_serial->save_index = 0; + rt_memset(lpc_serial->rx_buffer, 0, sizeof(lpc_serial->rx_buffer)); + lpc_serial->read_index = lpc_serial->save_index = 0; - /* Enable UART1 RxD and TxD pins */ - PINSEL0 |= 0x05 << 16; + /* Enable UART1 RxD and TxD pins */ + PINSEL0 |= 0x05 << 16; - /* 8 bits, no Parity, 1 Stop bit */ - UART_LCR(lpc_serial->hw_base) = 0x83; + /* 8 bits, no Parity, 1 Stop bit */ + UART_LCR(lpc_serial->hw_base) = 0x83; - /* Setup Baudrate */ - UART_DLL(lpc_serial->hw_base) = (PCLK/16/lpc_serial->baudrate) & 0xFF; - UART_DLM(lpc_serial->hw_base) = ((PCLK/16/lpc_serial->baudrate) >> 8) & 0xFF; + /* Setup Baudrate */ + UART_DLL(lpc_serial->hw_base) = (PCLK/16/lpc_serial->baudrate) & 0xFF; + UART_DLM(lpc_serial->hw_base) = ((PCLK/16/lpc_serial->baudrate) >> 8) & 0xFF; - /* DLAB = 0 */ - UART_LCR(lpc_serial->hw_base) = 0x03; + /* DLAB = 0 */ + UART_LCR(lpc_serial->hw_base) = 0x03; - lpc_serial->parent.type = RT_Device_Class_Char; - lpc_serial->parent.init = rt_serial_init; - lpc_serial->parent.open = rt_serial_open; - lpc_serial->parent.close = rt_serial_close; - lpc_serial->parent.read = rt_serial_read; - lpc_serial->parent.write = rt_serial_write; - lpc_serial->parent.control = rt_serial_control; - lpc_serial->parent.user_data = RT_NULL; + lpc_serial->parent.type = RT_Device_Class_Char; + lpc_serial->parent.init = rt_serial_init; + lpc_serial->parent.open = rt_serial_open; + lpc_serial->parent.close = rt_serial_close; + lpc_serial->parent.read = rt_serial_read; + lpc_serial->parent.write = rt_serial_write; + lpc_serial->parent.control = rt_serial_control; + lpc_serial->parent.user_data = RT_NULL; - rt_device_register(&lpc_serial->parent, - "uart2", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX); + rt_device_register(&lpc_serial->parent, + "uart2", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX); #endif } diff --git a/bsp/lpc2148/rtconfig.h b/bsp/lpc2148/rtconfig.h index 60887daac1..220742ce41 100644 --- a/bsp/lpc2148/rtconfig.h +++ b/bsp/lpc2148/rtconfig.h @@ -3,16 +3,16 @@ #define __RTTHREAD_CFG_H__ /* RT_NAME_MAX*/ -#define RT_NAME_MAX 8 +#define RT_NAME_MAX 8 /* RT_ALIGN_SIZE*/ -#define RT_ALIGN_SIZE 4 +#define RT_ALIGN_SIZE 4 /* PRIORITY_MAX*/ -#define RT_THREAD_PRIORITY_MAX 32 +#define RT_THREAD_PRIORITY_MAX 32 /* Tick per Second*/ -#define RT_TICK_PER_SECOND 100 +#define RT_TICK_PER_SECOND 100 /* SECTION: RT_DEBUG */ /* Thread Debug */ @@ -62,12 +62,12 @@ #define RT_USING_DEVICE #define RT_USING_UART1 #define RT_USING_UART2 -#define RT_UART_RX_BUFFER_SIZE 64 +#define RT_UART_RX_BUFFER_SIZE 64 /* SECTION: Console options */ #define RT_USING_CONSOLE /* the buffer size of console*/ -#define RT_CONSOLEBUF_SIZE 128 +#define RT_CONSOLEBUF_SIZE 128 /* SECTION: FinSH shell options */ /* Using FinSH as Shell*/ @@ -87,11 +87,11 @@ /* SECTION: DFS options */ /* #define RT_USING_DFS */ /* the max number of mounted filesystem */ -#define DFS_FILESYSTEMS_MAX 2 -/* the max number of opened files */ -#define DFS_FD_MAX 4 -/* the max number of cached sector */ -#define DFS_CACHE_MAX_NUM 8 +#define DFS_FILESYSTEMS_MAX 2 +/* the max number of opened files */ +#define DFS_FD_MAX 4 +/* the max number of cached sector */ +#define DFS_CACHE_MAX_NUM 8 /* SECTION: lwip, a lighwight TCP/IP protocol stack */ /* Using lighweight TCP/IP protocol stack*/ @@ -119,21 +119,21 @@ /* #define RT_LWIP_DHCP */ /* ip address of target*/ -#define RT_LWIP_IPADDR0 192 -#define RT_LWIP_IPADDR1 168 -#define RT_LWIP_IPADDR2 0 -#define RT_LWIP_IPADDR3 30 +#define RT_LWIP_IPADDR0 192 +#define RT_LWIP_IPADDR1 168 +#define RT_LWIP_IPADDR2 0 +#define RT_LWIP_IPADDR3 30 /* gateway address of target*/ -#define RT_LWIP_GWADDR0 192 -#define RT_LWIP_GWADDR1 168 -#define RT_LWIP_GWADDR2 0 -#define RT_LWIP_GWADDR3 1 +#define RT_LWIP_GWADDR0 192 +#define RT_LWIP_GWADDR1 168 +#define RT_LWIP_GWADDR2 0 +#define RT_LWIP_GWADDR3 1 /* mask address of target*/ -#define RT_LWIP_MSKADDR0 255 -#define RT_LWIP_MSKADDR1 255 -#define RT_LWIP_MSKADDR2 255 -#define RT_LWIP_MSKADDR3 0 +#define RT_LWIP_MSKADDR0 255 +#define RT_LWIP_MSKADDR1 255 +#define RT_LWIP_MSKADDR2 255 +#define RT_LWIP_MSKADDR3 0 #endif diff --git a/bsp/lpc2478/applications/application.c b/bsp/lpc2478/applications/application.c index 64dbf3c807..fa10f80d56 100644 --- a/bsp/lpc2478/applications/application.c +++ b/bsp/lpc2478/applications/application.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc2478/applications/startup.c b/bsp/lpc2478/applications/startup.c index 0b961e4f94..05dee0ef8e 100644 --- a/bsp/lpc2478/applications/startup.c +++ b/bsp/lpc2478/applications/startup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc2478/drivers/board.c b/bsp/lpc2478/drivers/board.c index 65ff918711..956ec5c03f 100644 --- a/bsp/lpc2478/drivers/board.c +++ b/bsp/lpc2478/drivers/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -14,7 +14,7 @@ #include #include "board.h" -#define DATA_COUNT 14400000/RT_TICK_PER_SECOND /* T0MR0 = delayInMs * (Fpclk / 1000); */ +#define DATA_COUNT 14400000/RT_TICK_PER_SECOND /* T0MR0 = delayInMs * (Fpclk / 1000); */ extern void rt_hw_serial_init(void); @@ -25,9 +25,9 @@ extern void rt_hw_serial_init(void); void rt_timer_handler(int vector, void* param) { - T0IR |= 0x01; /* clear interrupt flag */ - rt_tick_increase(); - VICVectAddr = 0; /* Acknowledge Interrupt */ + T0IR |= 0x01; /* clear interrupt flag */ + rt_tick_increase(); + VICVectAddr = 0; /* Acknowledge Interrupt */ } /** @@ -36,19 +36,19 @@ void rt_timer_handler(int vector, void* param) void rt_hw_board_init(void) { #if defined(RT_USING_DEVICE) && defined(RT_USING_UART1) - rt_hw_serial_init(); - rt_console_set_device("uart1"); + rt_hw_serial_init(); + rt_console_set_device("uart1"); #endif - T0IR = 0xff; - T0TC = 0; - T0MCR = 0x03; - T0MR0 = (DATA_COUNT); + T0IR = 0xff; + T0TC = 0; + T0MCR = 0x03; + T0MR0 = (DATA_COUNT); - rt_hw_interrupt_install(TIMER0_INT, rt_timer_handler, RT_NULL, "tick"); - rt_hw_interrupt_umask(TIMER0_INT); + rt_hw_interrupt_install(TIMER0_INT, rt_timer_handler, RT_NULL, "tick"); + rt_hw_interrupt_umask(TIMER0_INT); - T0TCR = 0x01; //enable timer0 counter + T0TCR = 0x01; //enable timer0 counter } /*@}*/ diff --git a/bsp/lpc2478/drivers/board.h b/bsp/lpc2478/drivers/board.h index 6386c19ba8..075fe354b8 100644 --- a/bsp/lpc2478/drivers/board.h +++ b/bsp/lpc2478/drivers/board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -14,7 +14,7 @@ /* RT_USING_UART */ #define RT_USING_UART1 #define RT_USING_UART2 -#define RT_UART_RX_BUFFER_SIZE 64 +#define RT_UART_RX_BUFFER_SIZE 64 void rt_hw_board_init(void); void rt_hw_led_set(rt_uint32_t led); void rt_hw_led_flash(void); @@ -23,93 +23,93 @@ void rt_hw_led_flash(void); void rt_hw_finsh_init(void); #endif -#define USE_USB 0 +#define USE_USB 0 -#if USE_USB /* 1 is USB, 0 is non-USB related */ -#define PLL_MValue 11 -#define PLL_NValue 0 -#define CCLKDivValue 4 -#define USBCLKDivValue 5 +#if USE_USB /* 1 is USB, 0 is non-USB related */ +#define PLL_MValue 11 +#define PLL_NValue 0 +#define CCLKDivValue 4 +#define USBCLKDivValue 5 -#define Fosc 12000000 -#define Fcclk 57600000 -#define Fcco 288000000 +#define Fosc 12000000 +#define Fcclk 57600000 +#define Fcco 288000000 #else -#define PLL_MValue 12 -#define PLL_NValue 1 -#define CCLKDivValue 5 +#define PLL_MValue 12 +#define PLL_NValue 1 +#define CCLKDivValue 5 -#define Fosc 12000000 -#define Fcclk 72000000 -#define Fcco 360000000 +#define Fosc 12000000 +#define Fcclk 72000000 +#define Fcco 360000000 #endif #if USE_USB -#define Fpclk (Fcclk / 2) +#define Fpclk (Fcclk / 2) #else -#define Fpclk (Fcclk / 4) +#define Fpclk (Fcclk / 4) #endif /* IRQ define */ -#define SYS32Mode 0x1F -#define IRQ32Mode 0x12 -#define FIQ32Mode 0x11 - -#define HIGHEST_PRIORITY 0x01 -#define LOWEST_PRIORITY 0x0F - -#define WDT_INT 0 -#define SWI_INT 1 -#define ARM_CORE0_INT 2 -#define ARM_CORE1_INT 3 -#define TIMER0_INT 4 -#define TIMER1_INT 5 -#define UART0_INT 6 -#define UART1_INT 7 -#define PWM0_1_INT 8 -#define I2C0_INT 9 -#define SPI0_INT 10 /* SPI and SSP0 share VIC slot */ -#define SSP0_INT 10 -#define SSP1_INT 11 -#define PLL_INT 12 -#define RTC_INT 13 -#define EINT0_INT 14 -#define EINT1_INT 15 -#define EINT2_INT 16 -#define EINT3_INT 17 -#define ADC0_INT 18 -#define I2C1_INT 19 -#define BOD_INT 20 -#define EMAC_INT 21 -#define USB_INT 22 -#define CAN_INT 23 -#define MCI_INT 24 -#define GPDMA_INT 25 -#define TIMER2_INT 26 -#define TIMER3_INT 27 -#define UART2_INT 28 -#define UART3_INT 29 -#define I2C2_INT 30 -#define I2S_INT 31 - -#define VIC_SIZE 32 - -#define VECT_ADDR_INDEX 0x100 +#define SYS32Mode 0x1F +#define IRQ32Mode 0x12 +#define FIQ32Mode 0x11 + +#define HIGHEST_PRIORITY 0x01 +#define LOWEST_PRIORITY 0x0F + +#define WDT_INT 0 +#define SWI_INT 1 +#define ARM_CORE0_INT 2 +#define ARM_CORE1_INT 3 +#define TIMER0_INT 4 +#define TIMER1_INT 5 +#define UART0_INT 6 +#define UART1_INT 7 +#define PWM0_1_INT 8 +#define I2C0_INT 9 +#define SPI0_INT 10 /* SPI and SSP0 share VIC slot */ +#define SSP0_INT 10 +#define SSP1_INT 11 +#define PLL_INT 12 +#define RTC_INT 13 +#define EINT0_INT 14 +#define EINT1_INT 15 +#define EINT2_INT 16 +#define EINT3_INT 17 +#define ADC0_INT 18 +#define I2C1_INT 19 +#define BOD_INT 20 +#define EMAC_INT 21 +#define USB_INT 22 +#define CAN_INT 23 +#define MCI_INT 24 +#define GPDMA_INT 25 +#define TIMER2_INT 26 +#define TIMER3_INT 27 +#define UART2_INT 28 +#define UART3_INT 29 +#define I2C2_INT 30 +#define I2S_INT 31 + +#define VIC_SIZE 32 + +#define VECT_ADDR_INDEX 0x100 #define VECT_CNTL_INDEX 0x200 -#define CCLK 60000000 /* Fosc = 12MHz, M = 5 */ -#define PCLK 15000000 /* CCLK/4, use default */ +#define CCLK 60000000 /* Fosc = 12MHz, M = 5 */ +#define PCLK 15000000 /* CCLK/4, use default */ /****************************************************************************** -** Function name: TargetInit +** Function name: TargetInit ** -** Descriptions: Initialize the target board; it is called in a -** necessary place, change it as needed +** Descriptions: Initialize the target board; it is called in a +** necessary place, change it as needed ** -** parameters: None -** Returned value: None +** parameters: None +** Returned value: None ** ******************************************************************************/ extern void TargetInit(void); diff --git a/bsp/lpc2478/drivers/serial.c b/bsp/lpc2478/drivers/serial.c index dff575c7cc..8e1fe1f91f 100644 --- a/bsp/lpc2478/drivers/serial.c +++ b/bsp/lpc2478/drivers/serial.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -15,8 +15,8 @@ #include "board.h" /* serial hardware register */ -#define REG8(d) (*((volatile unsigned char *)(d))) -#define REG32(d) (*((volatile unsigned long *)(d))) +#define REG8(d) (*((volatile unsigned char *)(d))) +#define REG32(d) (*((volatile unsigned long *)(d))) #define UART_RBR(base) REG8(base + 0x00) #define UART_THR(base) REG8(base + 0x00) @@ -37,16 +37,16 @@ /* LPC serial device */ struct rt_lpcserial { - /* inherit from device */ - struct rt_device parent; + /* inherit from device */ + struct rt_device parent; - rt_uint32_t hw_base; - rt_uint32_t irqno; - rt_uint32_t baudrate; + rt_uint32_t hw_base; + rt_uint32_t irqno; + rt_uint32_t baudrate; - /* reception field */ - rt_uint16_t save_index, read_index; - rt_uint8_t rx_buffer[RT_UART_RX_BUFFER_SIZE]; + /* reception field */ + rt_uint16_t save_index, read_index; + rt_uint8_t rx_buffer[RT_UART_RX_BUFFER_SIZE]; }; #ifdef RT_USING_UART1 @@ -58,55 +58,55 @@ struct rt_lpcserial serial2; void rt_hw_serial_init(void); -#define U0PINS 0x00000005 +#define U0PINS 0x00000005 void rt_hw_uart_isr(int irqno, void *param) { - RT_UNUSED rt_uint32_t iir; - struct rt_lpcserial* lpc_serial = (struct rt_lpcserial*)param; - - RT_ASSERT(lpc_serial != RT_NULL) - - if (UART_LSR(lpc_serial->hw_base) & 0x01) - { - rt_base_t level; - - while (UART_LSR(lpc_serial->hw_base) & 0x01) - { - /* disable interrupt */ - level = rt_hw_interrupt_disable(); - - /* read character */ - lpc_serial->rx_buffer[lpc_serial->save_index] = - UART_RBR(lpc_serial->hw_base); - lpc_serial->save_index ++; - if (lpc_serial->save_index >= RT_UART_RX_BUFFER_SIZE) - lpc_serial->save_index = 0; - - /* if the next position is read index, discard this 'read char' */ - if (lpc_serial->save_index == lpc_serial->read_index) - { - lpc_serial->read_index ++; - if (lpc_serial->read_index >= RT_UART_RX_BUFFER_SIZE) - lpc_serial->read_index = 0; - } - - /* enable interrupt */ - rt_hw_interrupt_enable(level); - } - - /* invoke callback */ - if(lpc_serial->parent.rx_indicate != RT_NULL) - { - lpc_serial->parent.rx_indicate(&lpc_serial->parent, 1); - } - } - - /* clear interrupt source */ - iir = UART_IIR(lpc_serial->hw_base); - - /* acknowledge Interrupt */ - VICVectAddr = 0; + RT_UNUSED rt_uint32_t iir; + struct rt_lpcserial* lpc_serial = (struct rt_lpcserial*)param; + + RT_ASSERT(lpc_serial != RT_NULL) + + if (UART_LSR(lpc_serial->hw_base) & 0x01) + { + rt_base_t level; + + while (UART_LSR(lpc_serial->hw_base) & 0x01) + { + /* disable interrupt */ + level = rt_hw_interrupt_disable(); + + /* read character */ + lpc_serial->rx_buffer[lpc_serial->save_index] = + UART_RBR(lpc_serial->hw_base); + lpc_serial->save_index ++; + if (lpc_serial->save_index >= RT_UART_RX_BUFFER_SIZE) + lpc_serial->save_index = 0; + + /* if the next position is read index, discard this 'read char' */ + if (lpc_serial->save_index == lpc_serial->read_index) + { + lpc_serial->read_index ++; + if (lpc_serial->read_index >= RT_UART_RX_BUFFER_SIZE) + lpc_serial->read_index = 0; + } + + /* enable interrupt */ + rt_hw_interrupt_enable(level); + } + + /* invoke callback */ + if(lpc_serial->parent.rx_indicate != RT_NULL) + { + lpc_serial->parent.rx_indicate(&lpc_serial->parent, 1); + } + } + + /* clear interrupt source */ + iir = UART_IIR(lpc_serial->hw_base); + + /* acknowledge Interrupt */ + VICVectAddr = 0; } @@ -117,243 +117,243 @@ void rt_hw_uart_isr(int irqno, void *param) static rt_err_t rt_serial_init (rt_device_t dev) { - return RT_EOK; + return RT_EOK; } static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag) { - struct rt_lpcserial* lpc_serial; - lpc_serial = (struct rt_lpcserial*) dev; - - RT_ASSERT(lpc_serial != RT_NULL); - if (dev->flag & RT_DEVICE_FLAG_INT_RX) - { - /* init UART rx interrupt */ - UART_IER(lpc_serial->hw_base) = 0x01; - - /* install ISR */ - rt_hw_interrupt_install(lpc_serial->irqno, + struct rt_lpcserial* lpc_serial; + lpc_serial = (struct rt_lpcserial*) dev; + + RT_ASSERT(lpc_serial != RT_NULL); + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + /* init UART rx interrupt */ + UART_IER(lpc_serial->hw_base) = 0x01; + + /* install ISR */ + rt_hw_interrupt_install(lpc_serial->irqno, rt_hw_uart_isr, lpc_serial, RT_NULL); - rt_hw_interrupt_umask(lpc_serial->irqno); - } + rt_hw_interrupt_umask(lpc_serial->irqno); + } - return RT_EOK; + return RT_EOK; } static rt_err_t rt_serial_close(rt_device_t dev) { - struct rt_lpcserial* lpc_serial; - lpc_serial = (struct rt_lpcserial*) dev; - - RT_ASSERT(lpc_serial != RT_NULL); - - if (dev->flag & RT_DEVICE_FLAG_INT_RX) - { - /* disable UART rx interrupt */ - UART_IER(lpc_serial->hw_base) = 0x00; - } - - return RT_EOK; + struct rt_lpcserial* lpc_serial; + lpc_serial = (struct rt_lpcserial*) dev; + + RT_ASSERT(lpc_serial != RT_NULL); + + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + /* disable UART rx interrupt */ + UART_IER(lpc_serial->hw_base) = 0x00; + } + + return RT_EOK; } static rt_err_t rt_serial_control(rt_device_t dev, int cmd, void *args) { - return RT_EOK; + return RT_EOK; } static rt_size_t rt_serial_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) { - rt_uint8_t* ptr; - struct rt_lpcserial *lpc_serial = (struct rt_lpcserial*)dev; - RT_ASSERT(lpc_serial != RT_NULL); - - /* point to buffer */ - ptr = (rt_uint8_t*) buffer; - - if (dev->flag & RT_DEVICE_FLAG_INT_RX) - { - while (size) - { - /* interrupt receive */ - rt_base_t level; - - /* disable interrupt */ - level = rt_hw_interrupt_disable(); - if (lpc_serial->read_index != lpc_serial->save_index) - { - *ptr = lpc_serial->rx_buffer[lpc_serial->read_index]; - - lpc_serial->read_index ++; - if (lpc_serial->read_index >= RT_UART_RX_BUFFER_SIZE) - lpc_serial->read_index = 0; - } - else - { - /* no data in rx buffer */ - - /* enable interrupt */ - rt_hw_interrupt_enable(level); - break; - } - - /* enable interrupt */ - rt_hw_interrupt_enable(level); - - ptr ++; size --; - } - - return (rt_uint32_t)ptr - (rt_uint32_t)buffer; - } - else if (dev->flag & RT_DEVICE_FLAG_DMA_RX) - { - /* not support right now */ - RT_ASSERT(0); - } - - /* polling mode */ - while (size && (UART_LSR(lpc_serial->hw_base) & 0x01)) - { - /* Read Character */ - *ptr = UART_RBR(lpc_serial->hw_base); - - ptr ++; - size --; - } - - return (rt_size_t)ptr - (rt_size_t)buffer; + rt_uint8_t* ptr; + struct rt_lpcserial *lpc_serial = (struct rt_lpcserial*)dev; + RT_ASSERT(lpc_serial != RT_NULL); + + /* point to buffer */ + ptr = (rt_uint8_t*) buffer; + + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + while (size) + { + /* interrupt receive */ + rt_base_t level; + + /* disable interrupt */ + level = rt_hw_interrupt_disable(); + if (lpc_serial->read_index != lpc_serial->save_index) + { + *ptr = lpc_serial->rx_buffer[lpc_serial->read_index]; + + lpc_serial->read_index ++; + if (lpc_serial->read_index >= RT_UART_RX_BUFFER_SIZE) + lpc_serial->read_index = 0; + } + else + { + /* no data in rx buffer */ + + /* enable interrupt */ + rt_hw_interrupt_enable(level); + break; + } + + /* enable interrupt */ + rt_hw_interrupt_enable(level); + + ptr ++; size --; + } + + return (rt_uint32_t)ptr - (rt_uint32_t)buffer; + } + else if (dev->flag & RT_DEVICE_FLAG_DMA_RX) + { + /* not support right now */ + RT_ASSERT(0); + } + + /* polling mode */ + while (size && (UART_LSR(lpc_serial->hw_base) & 0x01)) + { + /* Read Character */ + *ptr = UART_RBR(lpc_serial->hw_base); + + ptr ++; + size --; + } + + return (rt_size_t)ptr - (rt_size_t)buffer; } static rt_size_t rt_serial_write(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) { - struct rt_lpcserial* lpc_serial; - char *ptr; - - lpc_serial = (struct rt_lpcserial*) dev; - if (dev->flag & RT_DEVICE_FLAG_INT_TX) - { - /* not support */ - RT_ASSERT(0); - } - else if (dev->flag & RT_DEVICE_FLAG_DMA_TX) - { - /* not support */ - RT_ASSERT(0); - } - - /* polling write */ - ptr = (char *)buffer; - - if (dev->flag & RT_DEVICE_FLAG_STREAM) - { - /* stream mode */ - while (size) - { - if (*ptr == '\n') - { - while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); - UART_THR(lpc_serial->hw_base) = '\r'; - } - - while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); - UART_THR(lpc_serial->hw_base) = *ptr; - - ptr ++; - size --; - } - } - else - { - while (size) - { - while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); - UART_THR(lpc_serial->hw_base) = *ptr; - - ptr ++; - size --; - } - } - - return (rt_size_t) ptr - (rt_size_t) buffer; + struct rt_lpcserial* lpc_serial; + char *ptr; + + lpc_serial = (struct rt_lpcserial*) dev; + if (dev->flag & RT_DEVICE_FLAG_INT_TX) + { + /* not support */ + RT_ASSERT(0); + } + else if (dev->flag & RT_DEVICE_FLAG_DMA_TX) + { + /* not support */ + RT_ASSERT(0); + } + + /* polling write */ + ptr = (char *)buffer; + + if (dev->flag & RT_DEVICE_FLAG_STREAM) + { + /* stream mode */ + while (size) + { + if (*ptr == '\n') + { + while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); + UART_THR(lpc_serial->hw_base) = '\r'; + } + + while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); + UART_THR(lpc_serial->hw_base) = *ptr; + + ptr ++; + size --; + } + } + else + { + while (size) + { + while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); + UART_THR(lpc_serial->hw_base) = *ptr; + + ptr ++; + size --; + } + } + + return (rt_size_t) ptr - (rt_size_t) buffer; } void rt_hw_serial_init(void) { - struct rt_lpcserial* lpc_serial; - + struct rt_lpcserial* lpc_serial; + #ifdef RT_USING_UART1 - lpc_serial = &serial1; - - lpc_serial->parent.type = RT_Device_Class_Char; - - lpc_serial->hw_base = 0xE000C000; - lpc_serial->baudrate = 115200; - lpc_serial->irqno = UART0_INT; - - rt_memset(lpc_serial->rx_buffer, 0, sizeof(lpc_serial->rx_buffer)); - lpc_serial->read_index = lpc_serial->save_index = 0; - - /* Enable UART0 RxD and TxD pins */ - PINSEL0 |= 0x50; - - /* 8 bits, no Parity, 1 Stop bit */ - UART_LCR(lpc_serial->hw_base) = 0x83; - - /* Setup Baudrate */ - UART_DLL(lpc_serial->hw_base) = (PCLK/16/lpc_serial->baudrate) & 0xFF; - UART_DLM(lpc_serial->hw_base) = ((PCLK/16/lpc_serial->baudrate) >> 8) & 0xFF; - - /* DLAB = 0 */ - UART_LCR(lpc_serial->hw_base) = 0x03; - - lpc_serial->parent.type = RT_Device_Class_Char; - lpc_serial->parent.init = rt_serial_init; - lpc_serial->parent.open = rt_serial_open; - lpc_serial->parent.close = rt_serial_close; - lpc_serial->parent.read = rt_serial_read; - lpc_serial->parent.write = rt_serial_write; - lpc_serial->parent.control = rt_serial_control; - lpc_serial->parent.user_data = RT_NULL; - - rt_device_register(&lpc_serial->parent, - "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM); + lpc_serial = &serial1; + + lpc_serial->parent.type = RT_Device_Class_Char; + + lpc_serial->hw_base = 0xE000C000; + lpc_serial->baudrate = 115200; + lpc_serial->irqno = UART0_INT; + + rt_memset(lpc_serial->rx_buffer, 0, sizeof(lpc_serial->rx_buffer)); + lpc_serial->read_index = lpc_serial->save_index = 0; + + /* Enable UART0 RxD and TxD pins */ + PINSEL0 |= 0x50; + + /* 8 bits, no Parity, 1 Stop bit */ + UART_LCR(lpc_serial->hw_base) = 0x83; + + /* Setup Baudrate */ + UART_DLL(lpc_serial->hw_base) = (PCLK/16/lpc_serial->baudrate) & 0xFF; + UART_DLM(lpc_serial->hw_base) = ((PCLK/16/lpc_serial->baudrate) >> 8) & 0xFF; + + /* DLAB = 0 */ + UART_LCR(lpc_serial->hw_base) = 0x03; + + lpc_serial->parent.type = RT_Device_Class_Char; + lpc_serial->parent.init = rt_serial_init; + lpc_serial->parent.open = rt_serial_open; + lpc_serial->parent.close = rt_serial_close; + lpc_serial->parent.read = rt_serial_read; + lpc_serial->parent.write = rt_serial_write; + lpc_serial->parent.control = rt_serial_control; + lpc_serial->parent.user_data = RT_NULL; + + rt_device_register(&lpc_serial->parent, + "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM); #endif #ifdef RT_USING_UART2 - lpc_serial = &serial2; - - lpc_serial->parent.type = RT_Device_Class_Char; - - lpc_serial->hw_base = 0xE0010000; - lpc_serial->baudrate = 115200; - lpc_serial->irqno = UART1_INT; - - rt_memset(lpc_serial->rx_buffer, 0, sizeof(lpc_serial->rx_buffer)); - lpc_serial->read_index = lpc_serial->save_index = 0; - - /* Enable UART1 RxD and TxD pins */ - PINSEL0 |= 0x05 << 16; - - /* 8 bits, no Parity, 1 Stop bit */ - UART_LCR(lpc_serial->hw_base) = 0x83; - - /* Setup Baudrate */ - UART_DLL(lpc_serial->hw_base) = (PCLK/16/lpc_serial->baudrate) & 0xFF; - UART_DLM(lpc_serial->hw_base) = ((PCLK/16/lpc_serial->baudrate) >> 8) & 0xFF; - - /* DLAB = 0 */ - UART_LCR(lpc_serial->hw_base) = 0x03; - - lpc_serial->parent.type = RT_Device_Class_Char; - lpc_serial->parent.init = rt_serial_init; - lpc_serial->parent.open = rt_serial_open; - lpc_serial->parent.close = rt_serial_close; - lpc_serial->parent.read = rt_serial_read; - lpc_serial->parent.write = rt_serial_write; - lpc_serial->parent.control = rt_serial_control; - lpc_serial->parent.user_data = RT_NULL; - - rt_device_register(&lpc_serial->parent, - "uart2", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX); + lpc_serial = &serial2; + + lpc_serial->parent.type = RT_Device_Class_Char; + + lpc_serial->hw_base = 0xE0010000; + lpc_serial->baudrate = 115200; + lpc_serial->irqno = UART1_INT; + + rt_memset(lpc_serial->rx_buffer, 0, sizeof(lpc_serial->rx_buffer)); + lpc_serial->read_index = lpc_serial->save_index = 0; + + /* Enable UART1 RxD and TxD pins */ + PINSEL0 |= 0x05 << 16; + + /* 8 bits, no Parity, 1 Stop bit */ + UART_LCR(lpc_serial->hw_base) = 0x83; + + /* Setup Baudrate */ + UART_DLL(lpc_serial->hw_base) = (PCLK/16/lpc_serial->baudrate) & 0xFF; + UART_DLM(lpc_serial->hw_base) = ((PCLK/16/lpc_serial->baudrate) >> 8) & 0xFF; + + /* DLAB = 0 */ + UART_LCR(lpc_serial->hw_base) = 0x03; + + lpc_serial->parent.type = RT_Device_Class_Char; + lpc_serial->parent.init = rt_serial_init; + lpc_serial->parent.open = rt_serial_open; + lpc_serial->parent.close = rt_serial_close; + lpc_serial->parent.read = rt_serial_read; + lpc_serial->parent.write = rt_serial_write; + lpc_serial->parent.control = rt_serial_control; + lpc_serial->parent.user_data = RT_NULL; + + rt_device_register(&lpc_serial->parent, + "uart2", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX); #endif } diff --git a/bsp/lpc2478/rtconfig.h b/bsp/lpc2478/rtconfig.h index c35691aa80..d0c419d9ff 100644 --- a/bsp/lpc2478/rtconfig.h +++ b/bsp/lpc2478/rtconfig.h @@ -3,22 +3,22 @@ #define __RTTHREAD_CFG_H__ /* RT_NAME_MAX*/ -#define RT_NAME_MAX 8 +#define RT_NAME_MAX 8 /* RT_ALIGN_SIZE*/ -#define RT_ALIGN_SIZE 4 +#define RT_ALIGN_SIZE 4 /* PRIORITY_MAX*/ -#define RT_THREAD_PRIORITY_MAX 256 +#define RT_THREAD_PRIORITY_MAX 256 /* Tick per Second*/ -#define RT_TICK_PER_SECOND 100 +#define RT_TICK_PER_SECOND 100 -#define RT_TIMER_THREAD_STACK_SIZE 512 +#define RT_TIMER_THREAD_STACK_SIZE 512 #define RT_TIMER_THREAD_PRIO 1 /* Rate at which timer management task runs (Hz) */ -#define RT_TIMER_EX_TICKS_PER_SEC 10 +#define RT_TIMER_EX_TICKS_PER_SEC 10 /* SECTION: RT_DEBUG */ @@ -67,7 +67,7 @@ /* SECTION: Console options */ #define RT_USING_CONSOLE /* the buffer size of console*/ -#define RT_CONSOLEBUF_SIZE 128 +#define RT_CONSOLEBUF_SIZE 128 /* SECTION: FinSH shell options */ /* Using FinSH as Shell*/ @@ -102,21 +102,21 @@ /* #define RT_LWIP_DHCP */ /* ip address of target*/ -#define RT_LWIP_IPADDR0 192 -#define RT_LWIP_IPADDR1 168 -#define RT_LWIP_IPADDR2 0 -#define RT_LWIP_IPADDR3 30 +#define RT_LWIP_IPADDR0 192 +#define RT_LWIP_IPADDR1 168 +#define RT_LWIP_IPADDR2 0 +#define RT_LWIP_IPADDR3 30 /* gateway address of target*/ -#define RT_LWIP_GWADDR0 192 -#define RT_LWIP_GWADDR1 168 -#define RT_LWIP_GWADDR2 0 -#define RT_LWIP_GWADDR3 1 +#define RT_LWIP_GWADDR0 192 +#define RT_LWIP_GWADDR1 168 +#define RT_LWIP_GWADDR2 0 +#define RT_LWIP_GWADDR3 1 /* mask address of target*/ -#define RT_LWIP_MSKADDR0 255 -#define RT_LWIP_MSKADDR1 255 -#define RT_LWIP_MSKADDR2 255 -#define RT_LWIP_MSKADDR3 0 +#define RT_LWIP_MSKADDR0 255 +#define RT_LWIP_MSKADDR1 255 +#define RT_LWIP_MSKADDR2 255 +#define RT_LWIP_MSKADDR3 0 #endif diff --git a/bsp/lpc408x/applications/main.c b/bsp/lpc408x/applications/main.c index 7874a25073..93495ce8c0 100644 --- a/bsp/lpc408x/applications/main.c +++ b/bsp/lpc408x/applications/main.c @@ -1,11 +1,11 @@ /* - * Copyright (c) 2006-2018, Synwit Technology Co.,Ltd. + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes - * 2018-12-10 armink first version + * 2018-12-10 armink first version */ #include @@ -14,6 +14,6 @@ int main(void) { rt_kprintf("Hello RT-Thread!\n"); - + return RT_EOK; -} +} diff --git a/bsp/lpc408x/drivers/board.c b/bsp/lpc408x/drivers/board.c index 8db9473876..23e0ec07ac 100644 --- a/bsp/lpc408x/drivers/board.c +++ b/bsp/lpc408x/drivers/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc408x/drivers/board.h b/bsp/lpc408x/drivers/board.h index 1cc74d0fd6..0b4946ced7 100644 --- a/bsp/lpc408x/drivers/board.h +++ b/bsp/lpc408x/drivers/board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc408x/drivers/drv_emac.c b/bsp/lpc408x/drivers/drv_emac.c index 7ea47d52ed..0bae0f1456 100644 --- a/bsp/lpc408x/drivers/drv_emac.c +++ b/bsp/lpc408x/drivers/drv_emac.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc408x/drivers/drv_emac.h b/bsp/lpc408x/drivers/drv_emac.h index 7d67eae178..ce5ca7d9e3 100644 --- a/bsp/lpc408x/drivers/drv_emac.h +++ b/bsp/lpc408x/drivers/drv_emac.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc408x/drivers/drv_hwtimer.c b/bsp/lpc408x/drivers/drv_hwtimer.c index fa09f87d76..0357c2c1f9 100644 --- a/bsp/lpc408x/drivers/drv_hwtimer.c +++ b/bsp/lpc408x/drivers/drv_hwtimer.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc408x/drivers/drv_hwtimer.h b/bsp/lpc408x/drivers/drv_hwtimer.h index 21c5a25eeb..ca34816a77 100644 --- a/bsp/lpc408x/drivers/drv_hwtimer.h +++ b/bsp/lpc408x/drivers/drv_hwtimer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc408x/drivers/drv_led.c b/bsp/lpc408x/drivers/drv_led.c index d7df12ba82..29c74af1af 100644 --- a/bsp/lpc408x/drivers/drv_led.c +++ b/bsp/lpc408x/drivers/drv_led.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc408x/drivers/drv_led.h b/bsp/lpc408x/drivers/drv_led.h index f3a958c9b5..d006ac7ee6 100644 --- a/bsp/lpc408x/drivers/drv_led.h +++ b/bsp/lpc408x/drivers/drv_led.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc408x/drivers/drv_sdram.c b/bsp/lpc408x/drivers/drv_sdram.c index 0bb9ec6eb3..a0473bae01 100644 --- a/bsp/lpc408x/drivers/drv_sdram.c +++ b/bsp/lpc408x/drivers/drv_sdram.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc408x/drivers/drv_sdram.h b/bsp/lpc408x/drivers/drv_sdram.h index 74ceab2d18..0722e02d9d 100644 --- a/bsp/lpc408x/drivers/drv_sdram.h +++ b/bsp/lpc408x/drivers/drv_sdram.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc408x/drivers/drv_uart.c b/bsp/lpc408x/drivers/drv_uart.c index 09a518f4ab..3b11a851db 100644 --- a/bsp/lpc408x/drivers/drv_uart.c +++ b/bsp/lpc408x/drivers/drv_uart.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc408x/drivers/drv_uart.h b/bsp/lpc408x/drivers/drv_uart.h index 6fbe0535a5..3d8988e3ac 100644 --- a/bsp/lpc408x/drivers/drv_uart.h +++ b/bsp/lpc408x/drivers/drv_uart.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc43xx/M0/applications/application.c b/bsp/lpc43xx/M0/applications/application.c index 2a9cec5103..1b14f82cd7 100644 --- a/bsp/lpc43xx/M0/applications/application.c +++ b/bsp/lpc43xx/M0/applications/application.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc43xx/M0/applications/board.c b/bsp/lpc43xx/M0/applications/board.c index cd1cf62df0..26d9cd404c 100644 --- a/bsp/lpc43xx/M0/applications/board.c +++ b/bsp/lpc43xx/M0/applications/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc43xx/M0/applications/board.h b/bsp/lpc43xx/M0/applications/board.h index 24dfee67d4..8462dad0f6 100644 --- a/bsp/lpc43xx/M0/applications/board.h +++ b/bsp/lpc43xx/M0/applications/board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc43xx/M0/applications/startup.c b/bsp/lpc43xx/M0/applications/startup.c index df9cb7a211..65d430d64a 100644 --- a/bsp/lpc43xx/M0/applications/startup.c +++ b/bsp/lpc43xx/M0/applications/startup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc43xx/M0/applications/vbus_drv.c b/bsp/lpc43xx/M0/applications/vbus_drv.c index 696535247f..8d90d72bfb 100644 --- a/bsp/lpc43xx/M0/applications/vbus_drv.c +++ b/bsp/lpc43xx/M0/applications/vbus_drv.c @@ -1,6 +1,6 @@ /* - * COPYRIGHT (C) 2018, Real-Thread Information Technology Ltd - * + * Copyright (c) 2006-2021, RT-Thread Development Team + * * SPDX-License-Identifier: Apache-2.0 * Change Logs: * Date Author Notes diff --git a/bsp/lpc43xx/M0/applications/vbus_hw.h b/bsp/lpc43xx/M0/applications/vbus_hw.h index 850466cc45..d269a7c907 100644 --- a/bsp/lpc43xx/M0/applications/vbus_hw.h +++ b/bsp/lpc43xx/M0/applications/vbus_hw.h @@ -1,6 +1,6 @@ /* - * COPYRIGHT (C) 2018, Real-Thread Information Technology Ltd - * + * Copyright (c) 2006-2021, RT-Thread Development Team + * * SPDX-License-Identifier: Apache-2.0 * Change Logs: * Date Author Notes diff --git a/bsp/lpc43xx/M4/applications/application.c b/bsp/lpc43xx/M4/applications/application.c index 8fb1a4ae83..03e56fa955 100644 --- a/bsp/lpc43xx/M4/applications/application.c +++ b/bsp/lpc43xx/M4/applications/application.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -32,10 +32,10 @@ static void _boot_M0(void) LPC_CREG->M0APPMEMMAP = (uint32_t)&_M0_CODE[0]; - // Release Slave from reset, first read status + // Release Slave from reset, first read status u32REG = LPC_RGU->RESET_ACTIVE_STATUS1; - // If the M0 is being held in reset, release it... + // If the M0 is being held in reset, release it... // 1 = no reset, 0 = reset while(!(u32REG & (1u << 24))) { diff --git a/bsp/lpc43xx/M4/applications/board.c b/bsp/lpc43xx/M4/applications/board.c index c6bfa10574..2f815060d5 100644 --- a/bsp/lpc43xx/M4/applications/board.c +++ b/bsp/lpc43xx/M4/applications/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc43xx/M4/applications/board.h b/bsp/lpc43xx/M4/applications/board.h index 0450724e53..faf2930854 100644 --- a/bsp/lpc43xx/M4/applications/board.h +++ b/bsp/lpc43xx/M4/applications/board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc43xx/M4/applications/startup.c b/bsp/lpc43xx/M4/applications/startup.c index df9cb7a211..65d430d64a 100644 --- a/bsp/lpc43xx/M4/applications/startup.c +++ b/bsp/lpc43xx/M4/applications/startup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc43xx/M4/applications/vbus_drv.c b/bsp/lpc43xx/M4/applications/vbus_drv.c index 09fd2373c4..4a3ee9dda6 100644 --- a/bsp/lpc43xx/M4/applications/vbus_drv.c +++ b/bsp/lpc43xx/M4/applications/vbus_drv.c @@ -1,6 +1,6 @@ /* - * COPYRIGHT (C) 2018, Real-Thread Information Technology Ltd - * + * Copyright (c) 2006-2021, RT-Thread Development Team + * * SPDX-License-Identifier: Apache-2.0 * Change Logs: * Date Author Notes diff --git a/bsp/lpc43xx/M4/applications/vbus_hw.h b/bsp/lpc43xx/M4/applications/vbus_hw.h index 850466cc45..d269a7c907 100644 --- a/bsp/lpc43xx/M4/applications/vbus_hw.h +++ b/bsp/lpc43xx/M4/applications/vbus_hw.h @@ -1,6 +1,6 @@ /* - * COPYRIGHT (C) 2018, Real-Thread Information Technology Ltd - * + * Copyright (c) 2006-2021, RT-Thread Development Team + * * SPDX-License-Identifier: Apache-2.0 * Change Logs: * Date Author Notes diff --git a/bsp/lpc43xx/drivers/drv_emac.c b/bsp/lpc43xx/drivers/drv_emac.c index b8875c340c..a2df5dfd4d 100644 --- a/bsp/lpc43xx/drivers/drv_emac.c +++ b/bsp/lpc43xx/drivers/drv_emac.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc43xx/drivers/drv_emac.h b/bsp/lpc43xx/drivers/drv_emac.h index efaa0ac8e3..cde6d2742e 100644 --- a/bsp/lpc43xx/drivers/drv_emac.h +++ b/bsp/lpc43xx/drivers/drv_emac.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc43xx/drivers/drv_led.c b/bsp/lpc43xx/drivers/drv_led.c index 73128c243c..464ddb4f9f 100644 --- a/bsp/lpc43xx/drivers/drv_led.c +++ b/bsp/lpc43xx/drivers/drv_led.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc43xx/drivers/drv_uart.c b/bsp/lpc43xx/drivers/drv_uart.c index e1b203a359..f15f6fb760 100644 --- a/bsp/lpc43xx/drivers/drv_uart.c +++ b/bsp/lpc43xx/drivers/drv_uart.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -179,7 +179,7 @@ void rt_hw_uart_init(void) config.parity = PARITY_NONE; config.stop_bits = STOP_BITS_1; config.invert = NRZ_NORMAL; - config.bufsz = RT_SERIAL_RB_BUFSZ; + config.bufsz = RT_SERIAL_RB_BUFSZ; serial0.ops = &lpc_uart_ops; serial0.config = config; @@ -230,7 +230,7 @@ void rt_hw_uart_init(void) config.parity = PARITY_NONE; config.stop_bits = STOP_BITS_1; config.invert = NRZ_NORMAL; - config.bufsz = RT_SERIAL_RB_BUFSZ; + config.bufsz = RT_SERIAL_RB_BUFSZ; serial2.ops = &lpc_uart_ops; serial2.config = config; @@ -282,7 +282,7 @@ void rt_hw_uart_init(void) config.parity = PARITY_NONE; config.stop_bits = STOP_BITS_1; config.invert = NRZ_NORMAL; - config.bufsz = RT_SERIAL_RB_BUFSZ; + config.bufsz = RT_SERIAL_RB_BUFSZ; serial3.ops = &lpc_uart_ops; serial3.config = config; diff --git a/bsp/lpc5410x/applications/application.c b/bsp/lpc5410x/applications/application.c index bad0922693..b99155b09d 100644 --- a/bsp/lpc5410x/applications/application.c +++ b/bsp/lpc5410x/applications/application.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc5410x/applications/board.c b/bsp/lpc5410x/applications/board.c index 0fb09e6574..ff451b2f1c 100644 --- a/bsp/lpc5410x/applications/board.c +++ b/bsp/lpc5410x/applications/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -46,7 +46,7 @@ void rt_hw_board_init() SCB->VTOR = (0x00000000 & NVIC_VTOR_MASK); #endif SystemCoreClockUpdate(); - /* init systick 1 systick = 1/(100M / 100) 100¸ösystick = 1s*/ + /* init systick 1 systick = 1/(100M / 100) 100个systick = 1s*/ SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); /* set pend exception priority */ NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); diff --git a/bsp/lpc5410x/applications/board.h b/bsp/lpc5410x/applications/board.h index 5bbf8bc235..03f6a284e7 100644 --- a/bsp/lpc5410x/applications/board.h +++ b/bsp/lpc5410x/applications/board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc5410x/applications/demo_thread.c b/bsp/lpc5410x/applications/demo_thread.c index 6acb8ae0ef..0d7ce2d2b8 100644 --- a/bsp/lpc5410x/applications/demo_thread.c +++ b/bsp/lpc5410x/applications/demo_thread.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -10,47 +10,47 @@ #include "drv_led.h" #include "drv_uart.h" -static void thread1_entry(void* parameter) +static void thread1_entry(void* parameter) { while(1) { - Led_Control(0,1); - rt_thread_delay(RT_TICK_PER_SECOND); - Led_Control(0,0); - rt_thread_delay(RT_TICK_PER_SECOND); + Led_Control(0,1); + rt_thread_delay(RT_TICK_PER_SECOND); + Led_Control(0,0); + rt_thread_delay(RT_TICK_PER_SECOND); } } -static void thread2_entry(void* parameter) +static void thread2_entry(void* parameter) { while(1) { - Led_Control(1,1); - rt_thread_delay(RT_TICK_PER_SECOND); - Led_Control(1,0); - rt_thread_delay(RT_TICK_PER_SECOND); - } + Led_Control(1,1); + rt_thread_delay(RT_TICK_PER_SECOND); + Led_Control(1,0); + rt_thread_delay(RT_TICK_PER_SECOND); + } } int demo_init(void) { - rt_thread_t thread1 = RT_NULL; - rt_thread_t thread2 = RT_NULL; - - - rt_led_hw_init(); - - - thread1 = rt_thread_create("t1",thread1_entry, RT_NULL,512,10,5); - if (thread1 != RT_NULL) - rt_thread_startup(thread1); - - thread2 = rt_thread_create("t2",thread2_entry, RT_NULL,512,10,5); - if (thread2 != RT_NULL) - rt_thread_startup(thread2); - - - return 0; - + rt_thread_t thread1 = RT_NULL; + rt_thread_t thread2 = RT_NULL; + + + rt_led_hw_init(); + + + thread1 = rt_thread_create("t1",thread1_entry, RT_NULL,512,10,5); + if (thread1 != RT_NULL) + rt_thread_startup(thread1); + + thread2 = rt_thread_create("t2",thread2_entry, RT_NULL,512,10,5); + if (thread2 != RT_NULL) + rt_thread_startup(thread2); + + + return 0; + } diff --git a/bsp/lpc5410x/applications/startup.c b/bsp/lpc5410x/applications/startup.c index 6f4ab94e82..0f50596ab1 100644 --- a/bsp/lpc5410x/applications/startup.c +++ b/bsp/lpc5410x/applications/startup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc5410x/drivers/drv_led.c b/bsp/lpc5410x/drivers/drv_led.c index 8923e3fda4..108707aee1 100644 --- a/bsp/lpc5410x/drivers/drv_led.c +++ b/bsp/lpc5410x/drivers/drv_led.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc5410x/drivers/drv_led.h b/bsp/lpc5410x/drivers/drv_led.h index 9ce2fea7be..87208c0e99 100644 --- a/bsp/lpc5410x/drivers/drv_led.h +++ b/bsp/lpc5410x/drivers/drv_led.h @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #ifndef __DRV_LED_H__ #define __DRV_LED_H__ diff --git a/bsp/lpc5410x/drivers/drv_uart.c b/bsp/lpc5410x/drivers/drv_uart.c index d348921740..826e659eb4 100644 --- a/bsp/lpc5410x/drivers/drv_uart.c +++ b/bsp/lpc5410x/drivers/drv_uart.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc5410x/drivers/drv_uart.h b/bsp/lpc5410x/drivers/drv_uart.h index 4ff948e746..6fa6e193d8 100644 --- a/bsp/lpc5410x/drivers/drv_uart.h +++ b/bsp/lpc5410x/drivers/drv_uart.h @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #ifndef __DRV_UART_H_ #define __DRV_UART_H_ diff --git a/bsp/lpc5410x/rtconfig.h b/bsp/lpc5410x/rtconfig.h index 387f1e75e6..c45f7094f6 100644 --- a/bsp/lpc5410x/rtconfig.h +++ b/bsp/lpc5410x/rtconfig.h @@ -5,17 +5,17 @@ // // -#define RT_NAME_MAX 8 +#define RT_NAME_MAX 8 // -#define RT_ALIGN_SIZE 4 +#define RT_ALIGN_SIZE 4 // // 8 // 32 // 256 // -#define RT_THREAD_PRIORITY_MAX 32 +#define RT_THREAD_PRIORITY_MAX 32 // -#define RT_TICK_PER_SECOND 100 +#define RT_TICK_PER_SECOND 100 //
#define RT_DEBUG #define RT_DEBUG_COLOR @@ -30,11 +30,11 @@ //
// #define RT_USING_TIMER_SOFT // -#define RT_TIMER_THREAD_PRIO 4 +#define RT_TIMER_THREAD_PRIO 4 // -#define RT_TIMER_THREAD_STACK_SIZE 512 +#define RT_TIMER_THREAD_STACK_SIZE 512 // -#define RT_TIMER_TICK_PER_SECOND 10 +#define RT_TIMER_TICK_PER_SECOND 10 //
//
@@ -75,7 +75,7 @@ //
#define RT_USING_CONSOLE // -#define RT_CONSOLEBUF_SIZE 128 +#define RT_CONSOLEBUF_SIZE 128 //
// @@ -87,7 +87,7 @@ // #define FINSH_USING_DESCRIPTION // -#define FINSH_THREAD_STACK_SIZE 4096 +#define FINSH_THREAD_STACK_SIZE 4096 //
//
@@ -102,18 +102,18 @@ // // #define DFS_USING_WORKDIR // -#define DFS_FILESYSTEMS_MAX 2 +#define DFS_FILESYSTEMS_MAX 2 // -#define DFS_FD_MAX 4 +#define DFS_FD_MAX 4 // #define RT_USING_DFS_ELMFAT // // 1 // 2 // -#define RT_DFS_ELM_USE_LFN 1 +#define RT_DFS_ELM_USE_LFN 1 // -#define RT_DFS_ELM_MAX_LFN 64 +#define RT_DFS_ELM_MAX_LFN 64 // // #define RT_USING_DFS_YAFFS2 // @@ -123,7 +123,7 @@ // // #define RT_USING_DFS_NFS // -#define RT_NFS_HOST_EXPORT "192.168.1.5:/" +#define RT_NFS_HOST_EXPORT "192.168.1.5:/" //
//
@@ -139,29 +139,29 @@ // #define RT_LWIP_DNS // -#define RT_LWIP_PBUF_NUM 4 +#define RT_LWIP_PBUF_NUM 4 // -#define RT_LWIP_TCP_PCB_NUM 3 +#define RT_LWIP_TCP_PCB_NUM 3 // -#define RT_LWIP_TCP_SND_BUF 2048 +#define RT_LWIP_TCP_SND_BUF 2048 // -#define RT_LWIP_TCP_WND 2048 +#define RT_LWIP_TCP_WND 2048 // // #define RT_LWIP_SNMP // // #define RT_LWIP_DHCP // -#define RT_LWIP_TCPTHREAD_PRIORITY 12 +#define RT_LWIP_TCPTHREAD_PRIORITY 12 // -#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8 +#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8 // -#define RT_LWIP_TCPTHREAD_STACKSIZE 4096 +#define RT_LWIP_TCPTHREAD_STACKSIZE 4096 // -#define RT_LWIP_ETHTHREAD_PRIORITY 14 +#define RT_LWIP_ETHTHREAD_PRIORITY 14 // -#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8 +#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8 // -#define RT_LWIP_ETHTHREAD_STACKSIZE 512 +#define RT_LWIP_ETHTHREAD_STACKSIZE 512 // #define RT_LWIP_IPADDR0 192 #define RT_LWIP_IPADDR1 168 @@ -182,7 +182,7 @@ //
// #define RT_USING_RTGUI // -#define RTGUI_NAME_MAX 12 +#define RTGUI_NAME_MAX 12 // #define RTGUI_USING_SMALL_SIZE // @@ -192,7 +192,7 @@ // #define RTGUI_USING_FONTHZ // -#define RTGUI_DEFAULT_FONT_SIZE 16 +#define RTGUI_DEFAULT_FONT_SIZE 16 // // #define RTGUI_USING_DFS_FILERW // diff --git a/bsp/lpc54114-lite/applications/main.c b/bsp/lpc54114-lite/applications/main.c index 5c13ff5166..f3490dd40b 100644 --- a/bsp/lpc54114-lite/applications/main.c +++ b/bsp/lpc54114-lite/applications/main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -14,9 +14,9 @@ int main(void) { - /* user app entry */ + /* user app entry */ rt_pin_mode(LED4_PIN, PIN_MODE_OUTPUT); - + while (1) { rt_pin_write(LED4_PIN, !rt_pin_read(LED4_PIN)); diff --git a/bsp/lpc54114-lite/applications/mnt.c b/bsp/lpc54114-lite/applications/mnt.c index 7942e159ed..49852b2025 100644 --- a/bsp/lpc54114-lite/applications/mnt.c +++ b/bsp/lpc54114-lite/applications/mnt.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -24,15 +24,15 @@ int mnt_init(void) { rt_kprintf("spi flash mount '%s' failed.\n", BSP_FLASH_MOUNT_PATH); } -#endif - +#endif + #if defined(BSP_USING_SDCARD) if(dfs_mount("sd0", BSP_SDCARD_MOUNT_PATH, "elm", 0, 0) != 0) { rt_kprintf("sdcard mount '%s' failed.\n", BSP_SDCARD_MOUNT_PATH); } -#endif +#endif return 0; } -INIT_APP_EXPORT(mnt_init); +INIT_APP_EXPORT(mnt_init); diff --git a/bsp/lpc54114-lite/drivers/audio/drv_mic.c b/bsp/lpc54114-lite/drivers/audio/drv_mic.c index d8219b504d..37bab8e125 100644 --- a/bsp/lpc54114-lite/drivers/audio/drv_mic.c +++ b/bsp/lpc54114-lite/drivers/audio/drv_mic.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -160,4 +160,4 @@ int rt_hw_mic_init(void) return RT_EOK; } -INIT_DEVICE_EXPORT(rt_hw_mic_init); \ No newline at end of file +INIT_DEVICE_EXPORT(rt_hw_mic_init); diff --git a/bsp/lpc54114-lite/drivers/audio/drv_mic.h b/bsp/lpc54114-lite/drivers/audio/drv_mic.h index 1ce777d87d..7364999df5 100644 --- a/bsp/lpc54114-lite/drivers/audio/drv_mic.h +++ b/bsp/lpc54114-lite/drivers/audio/drv_mic.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc54114-lite/drivers/audio/drv_sound.c b/bsp/lpc54114-lite/drivers/audio/drv_sound.c index b6cf0ca2f0..409403facb 100644 --- a/bsp/lpc54114-lite/drivers/audio/drv_sound.c +++ b/bsp/lpc54114-lite/drivers/audio/drv_sound.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -358,4 +358,4 @@ int rt_hw_sound_init(void) rt_audio_register(&snd_dev.audio, "sound0", RT_DEVICE_FLAG_WRONLY, &snd_dev); return RT_EOK; } -INIT_DEVICE_EXPORT(rt_hw_sound_init); \ No newline at end of file +INIT_DEVICE_EXPORT(rt_hw_sound_init); diff --git a/bsp/lpc54114-lite/drivers/audio/drv_sound.h b/bsp/lpc54114-lite/drivers/audio/drv_sound.h index aa997983ae..b50fe66593 100644 --- a/bsp/lpc54114-lite/drivers/audio/drv_sound.h +++ b/bsp/lpc54114-lite/drivers/audio/drv_sound.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc54114-lite/drivers/board.c b/bsp/lpc54114-lite/drivers/board.c index 61652d1c78..f8dc23a34b 100644 --- a/bsp/lpc54114-lite/drivers/board.c +++ b/bsp/lpc54114-lite/drivers/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -57,15 +57,15 @@ void rt_hw_board_init() SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); /* set pend exception priority */ NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); - + #ifdef RT_USING_HEAP rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END); #endif #ifdef RT_USING_COMPONENTS_INIT /* initialization board with RT-Thread Components */ rt_components_board_init(); -#endif -#ifdef RT_USING_CONSOLE +#endif +#ifdef RT_USING_CONSOLE rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #endif } diff --git a/bsp/lpc54114-lite/drivers/board.h b/bsp/lpc54114-lite/drivers/board.h index 78c6d7c8c3..4e07415919 100644 --- a/bsp/lpc54114-lite/drivers/board.h +++ b/bsp/lpc54114-lite/drivers/board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc54114-lite/drivers/drv_gpio.c b/bsp/lpc54114-lite/drivers/drv_gpio.c index 978fa2898e..9b8b4d5da4 100644 --- a/bsp/lpc54114-lite/drivers/drv_gpio.c +++ b/bsp/lpc54114-lite/drivers/drv_gpio.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -35,7 +35,7 @@ struct rt_pin_irq_hdr pin_irq_hdr_tab[] = {-1, 0, RT_NULL, RT_NULL}, {-1, 0, RT_NULL, RT_NULL}, {-1, 0, RT_NULL, RT_NULL}, - {-1, 0, RT_NULL, RT_NULL}, + {-1, 0, RT_NULL, RT_NULL}, }; static rt_base_t lpc_pin_get(const char *name) @@ -85,46 +85,46 @@ static void lpc_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode) { int portx, piny, dir; uint32_t pin_cfg; - + if(pin > PIN_MAX_VAL) return; - + portx = get_port(pin); - piny = get_pin(pin); - + piny = get_pin(pin); + switch(mode) { - case PIN_MODE_OUTPUT: + case PIN_MODE_OUTPUT: dir = kGPIO_DigitalOutput; pin_cfg = IOCON_FUNC0 | IOCON_DIGITAL_EN; break; case PIN_MODE_OUTPUT_OD: - dir = kGPIO_DigitalOutput; - pin_cfg = IOCON_FUNC0 | IOCON_OPENDRAIN_EN | IOCON_DIGITAL_EN; + dir = kGPIO_DigitalOutput; + pin_cfg = IOCON_FUNC0 | IOCON_OPENDRAIN_EN | IOCON_DIGITAL_EN; break; - - case PIN_MODE_INPUT: + + case PIN_MODE_INPUT: dir = kGPIO_DigitalInput; pin_cfg = IOCON_FUNC0 | IOCON_INPFILT_OFF | IOCON_DIGITAL_EN; - break; + break; case PIN_MODE_INPUT_PULLUP: - dir = kGPIO_DigitalInput; + dir = kGPIO_DigitalInput; pin_cfg = IOCON_FUNC0 | IOCON_INPFILT_OFF | IOCON_DIGITAL_EN | IOCON_MODE_PULLUP; break; - case PIN_MODE_INPUT_PULLDOWN: + case PIN_MODE_INPUT_PULLDOWN: dir = kGPIO_DigitalInput; - pin_cfg = IOCON_FUNC0 | IOCON_INPFILT_OFF | IOCON_DIGITAL_EN | IOCON_MODE_PULLDOWN; + pin_cfg = IOCON_FUNC0 | IOCON_INPFILT_OFF | IOCON_DIGITAL_EN | IOCON_MODE_PULLDOWN; break; default: break; - } - - CLOCK_EnableClock(kCLOCK_Iocon); - - IOCON_PinMuxSet(IOCON, portx, piny, pin_cfg); - GPIO_PortInit(GPIO, portx); - + } + + CLOCK_EnableClock(kCLOCK_Iocon); + + IOCON_PinMuxSet(IOCON, portx, piny, pin_cfg); + GPIO_PortInit(GPIO, portx); + gpio_pin_config_t pin_config = {(gpio_pin_direction_t)dir, 0}; - GPIO_PinInit(GPIO, portx, piny, &pin_config); + GPIO_PinInit(GPIO, portx, piny, &pin_config); CLOCK_DisableClock(kCLOCK_Iocon); } @@ -133,27 +133,27 @@ static void lpc_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value) { int portx, piny; portx = get_port(pin); - piny = get_pin(pin); + piny = get_pin(pin); if(pin > PIN_MAX_VAL) return; - GPIO_PinWrite(GPIO, portx, piny, value); + GPIO_PinWrite(GPIO, portx, piny, value); } static int lpc_pin_read(rt_device_t dev, rt_base_t pin) { - int portx, piny, value; - + int portx, piny, value; + if(pin > PIN_MAX_VAL) - return RT_ERROR; - + return RT_ERROR; + portx = get_port(pin); - piny = get_pin(pin); - + piny = get_pin(pin); + value = (int)(GPIO_PinRead(GPIO, portx, piny)); - - return value; + + return value; } static void pin_irq_hdr(pint_pin_int_t pintr, uint32_t pmatch_status) @@ -166,10 +166,10 @@ static void pin_irq_hdr(pint_pin_int_t pintr, uint32_t pmatch_status) break; } } - + if(irqno >= IRQ_MAX_VAL) return; - + if (pin_irq_hdr_tab[irqno].hdr) { pin_irq_hdr_tab[irqno].hdr(pin_irq_hdr_tab[irqno].args); @@ -184,14 +184,14 @@ void callback(pint_pin_int_t pintr, uint32_t pmatch_status) static rt_err_t lpc_pin_attach_irq(struct rt_device *device, rt_int32_t pin, rt_uint32_t mode, void (*hdr)(void *args), void *args) { - int portx, piny, trigger_mode, pin_initx, pintsel, pin_cfg, i; - + int portx, piny, trigger_mode, pin_initx, pintsel, pin_cfg, i; + if(pin > PIN_MAX_VAL) - return RT_ERROR; - + return RT_ERROR; + portx = get_port(pin); - piny = get_pin(pin); - + piny = get_pin(pin); + switch (mode) { case PIN_IRQ_MODE_RISING: @@ -210,10 +210,10 @@ static rt_err_t lpc_pin_attach_irq(struct rt_device *device, rt_int32_t pin, trigger_mode = kPINT_PinIntEnableLowLevel; break; } - - /* Get inputmux_connection_t */ + + /* Get inputmux_connection_t */ pintsel = (pin + (0xC0U << 20)); - + for(i = 0; i < IRQ_MAX_VAL; i++) { if(pin_irq_hdr_tab[i].pin == -1) @@ -226,40 +226,40 @@ static rt_err_t lpc_pin_attach_irq(struct rt_device *device, rt_int32_t pin, break; } } - + if(i >= IRQ_MAX_VAL) return RT_ERROR; - + /* open clk */ CLOCK_EnableClock(kCLOCK_InputMux); CLOCK_EnableClock(kCLOCK_Iocon); - - /* AttachSignal */ + + /* AttachSignal */ INPUTMUX_AttachSignal(INPUTMUX, i, (inputmux_connection_t)pintsel); pin_cfg = ((IOCON->PIO[portx][piny] & (~(IOCON_PIO_FUNC_MASK | IOCON_PIO_DIGIMODE_MASK | IOCON_PIO_FILTEROFF_MASK))) /* Mask bits to zero which are setting */ | IOCON_PIO_FUNC(0) /* Selects pin function.: PORT18 (pin 28) is configured as PIO1_8 */ | IOCON_PIO_DIGIMODE(1) /* Select Analog/Digital mode.: Digital mode. */ | IOCON_PIO_FILTEROFF(0)); /* Controls input glitch filter.: Filter enabled. Noise pulses below approximately 10 ns are filtered out. */ - - IOCON_PinMuxSet(IOCON, portx, piny, pin_cfg); - + + IOCON_PinMuxSet(IOCON, portx, piny, pin_cfg); + /* PINT_PinInterruptConfig */ - PINT_PinInterruptConfig(PINT, (pint_pin_int_t)pin_initx, (pint_pin_enable_t)(pin_irq_hdr_tab[i].mode), callback); - + PINT_PinInterruptConfig(PINT, (pint_pin_int_t)pin_initx, (pint_pin_enable_t)(pin_irq_hdr_tab[i].mode), callback); + CLOCK_DisableClock(kCLOCK_InputMux); CLOCK_DisableClock(kCLOCK_Iocon); - + return RT_EOK; } static rt_err_t lpc_pin_detach_irq(struct rt_device *device, rt_int32_t pin) { - int i; - + int i; + if(pin > PIN_MAX_VAL) - return RT_ERROR; - + return RT_ERROR; + for(i = 0; i < IRQ_MAX_VAL; i++) { if(pin_irq_hdr_tab[i].pin == pin) @@ -270,18 +270,18 @@ static rt_err_t lpc_pin_detach_irq(struct rt_device *device, rt_int32_t pin) pin_irq_hdr_tab[i].args = RT_NULL; break; } - } + } return RT_EOK; } static rt_err_t lpc_pin_irq_enable(struct rt_device *device, rt_base_t pin, rt_uint32_t enabled) -{ +{ int irqn_type, i; - + if(pin > PIN_MAX_VAL) - return RT_ERROR; - + return RT_ERROR; + for(i = 0; i < IRQ_MAX_VAL; i++) { if(pin_irq_hdr_tab[i].pin == pin) @@ -315,8 +315,8 @@ static rt_err_t lpc_pin_irq_enable(struct rt_device *device, rt_base_t pin, } break; } - } - + } + if(i >= IRQ_MAX_VAL) return RT_ERROR; diff --git a/bsp/lpc54114-lite/drivers/drv_gpio.h b/bsp/lpc54114-lite/drivers/drv_gpio.h index 0c98e82298..41e4c45724 100644 --- a/bsp/lpc54114-lite/drivers/drv_gpio.h +++ b/bsp/lpc54114-lite/drivers/drv_gpio.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -13,4 +13,4 @@ extern int rt_hw_pin_init(void); -#endif +#endif diff --git a/bsp/lpc54114-lite/drivers/drv_i2c.c b/bsp/lpc54114-lite/drivers/drv_i2c.c index 81be945067..cba87c8aec 100644 --- a/bsp/lpc54114-lite/drivers/drv_i2c.c +++ b/bsp/lpc54114-lite/drivers/drv_i2c.c @@ -1,21 +1,21 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 */ - -#include "drv_i2c.h" -#include "fsl_common.h" +#include "drv_i2c.h" + +#include "fsl_common.h" #include "fsl_iocon.h" #include "fsl_i2c.h" struct lpc_i2c { - struct rt_i2c_bus_device bus; - + struct rt_i2c_bus_device bus; + I2C_Type *base; - + char *device_name; }; @@ -28,9 +28,9 @@ static uint32_t get_i2c_freq(I2C_Type *base) { freq = CLOCK_GetFreq(kCLOCK_Flexcomm4); } -#endif +#endif - return freq; + return freq; } static rt_size_t master_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num) @@ -43,7 +43,7 @@ static rt_size_t master_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg ms i2c_direction_t direction; status_t result = kStatus_Success; - RT_ASSERT(bus != RT_NULL); + RT_ASSERT(bus != RT_NULL); lpc_i2c = (struct lpc_i2c *)bus; @@ -94,13 +94,13 @@ static rt_err_t i2c_bus_control(struct rt_i2c_bus_device *bus, rt_uint32_t cmd, static const struct rt_i2c_bus_device_ops ops = { - master_xfer, + master_xfer, slave_xfer, i2c_bus_control, -}; +}; #if defined(BSP_USING_I2C4) -static struct lpc_i2c i2c4 = {0}; +static struct lpc_i2c i2c4 = {0}; #endif int rt_hw_i2c_init(void) @@ -110,11 +110,11 @@ int rt_hw_i2c_init(void) #if defined(BSP_USING_I2C4) CLOCK_AttachClk(kFRO12M_to_FLEXCOMM4); RESET_PeripheralReset(kFC4_RST_SHIFT_RSTn); - + i2c4.base = I2C4; - i2c4.device_name = "i2c4"; - i2c4.bus.ops = &ops; - + i2c4.device_name = "i2c4"; + i2c4.bus.ops = &ops; + IOCON_PinMuxSet(IOCON, 1, 1, IOCON_MODE_PULLUP | IOCON_FUNC5 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF); IOCON_PinMuxSet(IOCON, 1, 2, IOCON_MODE_PULLUP | IOCON_FUNC5 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF); @@ -122,12 +122,12 @@ int rt_hw_i2c_init(void) I2C_MasterGetDefaultConfig(&masterConfig); masterConfig.baudRate_Bps = 100*1000U; - + I2C_MasterInit(I2C4, &masterConfig, get_i2c_freq(I2C4)); rt_i2c_bus_device_register(&i2c4.bus, i2c4.device_name); #endif - return RT_EOK; + return RT_EOK; } -INIT_BOARD_EXPORT(rt_hw_i2c_init); +INIT_BOARD_EXPORT(rt_hw_i2c_init); diff --git a/bsp/lpc54114-lite/drivers/drv_i2c.h b/bsp/lpc54114-lite/drivers/drv_i2c.h index 468ac3c0dc..c5073237a8 100644 --- a/bsp/lpc54114-lite/drivers/drv_i2c.h +++ b/bsp/lpc54114-lite/drivers/drv_i2c.h @@ -1,14 +1,14 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 */ - -#ifndef __DRV_I2C_H__ -#define __DRV_I2C_H__ -#include -#include +#ifndef __DRV_I2C_H__ +#define __DRV_I2C_H__ + +#include +#include int rt_hw_i2c_init(void); diff --git a/bsp/lpc54114-lite/drivers/drv_romfs.c b/bsp/lpc54114-lite/drivers/drv_romfs.c index 7c444af03f..d488b163fc 100644 --- a/bsp/lpc54114-lite/drivers/drv_romfs.c +++ b/bsp/lpc54114-lite/drivers/drv_romfs.c @@ -2,49 +2,49 @@ #include #include -static const rt_uint8_t _romfs_root_license[] = +static const rt_uint8_t _romfs_root_license[] = { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x41, 0x70, 0x61, 0x63, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x32, 0x2e, 0x30, 0x2c, 0x20, 0x4a, 0x61, 0x6e, 0x75, 0x61, 0x72, 0x79, 0x20, 0x32, 0x30, 0x30, 0x34, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x61, 0x70, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x73, 0x2f, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x54, 0x45, 0x52, 0x4d, 0x53, 0x20, 0x41, 0x4e, 0x44, 0x20, 0x43, 0x4f, 0x4e, 0x44, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0x20, 0x46, 0x4f, 0x52, 0x20, 0x55, 0x53, 0x45, 0x2c, 0x20, 0x52, 0x45, 0x50, 0x52, 0x4f, 0x44, 0x55, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x2c, 0x20, 0x41, 0x4e, 0x44, 0x20, 0x44, 0x49, 0x53, 0x54, 0x52, 0x49, 0x42, 0x55, 0x54, 0x49, 0x4f, 0x4e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x31, 0x2e, 0x20, 0x44, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x22, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x6d, 0x65, 0x61, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x75, 0x73, 0x65, 0x2c, 0x20, 0x72, 0x65, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x73, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x53, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x31, 0x20, 0x74, 0x68, 0x72, 0x6f, 0x75, 0x67, 0x68, 0x20, 0x39, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x22, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x6d, 0x65, 0x61, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x20, 0x6f, 0x72, 0x20, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x20, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x64, 0x20, 0x62, 0x79, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x69, 0x73, 0x20, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x4c, 0x65, 0x67, 0x61, 0x6c, 0x20, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x22, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x6d, 0x65, 0x61, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x63, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x61, 0x6c, 0x6c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2c, 0x20, 0x61, 0x72, 0x65, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x62, 0x79, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x61, 0x72, 0x65, 0x20, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x20, 0x46, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70, 0x6f, 0x73, 0x65, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x22, 0x20, 0x6d, 0x65, 0x61, 0x6e, 0x73, 0x20, 0x28, 0x69, 0x29, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x2c, 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x20, 0x6f, 0x72, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x2c, 0x20, 0x74, 0x6f, 0x20, 0x63, 0x61, 0x75, 0x73, 0x65, 0x20, 0x74, 0x68, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x72, 0x20, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2c, 0x20, 0x77, 0x68, 0x65, 0x74, 0x68, 0x65, 0x72, 0x20, 0x62, 0x79, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x20, 0x6f, 0x72, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x77, 0x69, 0x73, 0x65, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x28, 0x69, 0x69, 0x29, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x20, 0x6f, 0x66, 0x20, 0x66, 0x69, 0x66, 0x74, 0x79, 0x20, 0x70, 0x65, 0x72, 0x63, 0x65, 0x6e, 0x74, 0x20, 0x28, 0x35, 0x30, 0x25, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x73, 0x74, 0x61, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x68, 0x61, 0x72, 0x65, 0x73, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x28, 0x69, 0x69, 0x69, 0x29, 0x20, 0x62, 0x65, 0x6e, 0x65, 0x66, 0x69, 0x63, 0x69, 0x61, 0x6c, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x20, 0x6f, 0x66, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x59, 0x6f, 0x75, 0x22, 0x20, 0x28, 0x6f, 0x72, 0x20, 0x22, 0x59, 0x6f, 0x75, 0x72, 0x22, 0x29, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x6d, 0x65, 0x61, 0x6e, 0x20, 0x61, 0x6e, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x76, 0x69, 0x64, 0x75, 0x61, 0x6c, 0x20, 0x6f, 0x72, 0x20, 0x4c, 0x65, 0x67, 0x61, 0x6c, 0x20, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x78, 0x65, 0x72, 0x63, 0x69, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x70, 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x6d, 0x65, 0x61, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x72, 0x65, 0x66, 0x65, 0x72, 0x72, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x62, 0x75, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x6d, 0x65, 0x61, 0x6e, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x6d, 0x65, 0x63, 0x68, 0x61, 0x6e, 0x69, 0x63, 0x61, 0x6c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x20, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x2c, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x62, 0x75, 0x74, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x74, 0x6f, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x20, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x57, 0x6f, 0x72, 0x6b, 0x22, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x6d, 0x65, 0x61, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x73, 0x68, 0x69, 0x70, 0x2c, 0x20, 0x77, 0x68, 0x65, 0x74, 0x68, 0x65, 0x72, 0x20, 0x69, 0x6e, 0x20, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x6f, 0x72, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x2c, 0x20, 0x6d, 0x61, 0x64, 0x65, 0x20, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c, 0x20, 0x61, 0x73, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x63, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x61, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x69, 0x73, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20, 0x6f, 0x72, 0x20, 0x61, 0x74, 0x74, 0x61, 0x63, 0x68, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x77, 0x6f, 0x72, 0x6b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x28, 0x61, 0x6e, 0x20, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x41, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x69, 0x78, 0x20, 0x62, 0x65, 0x6c, 0x6f, 0x77, 0x29, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x22, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x6d, 0x65, 0x61, 0x6e, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x77, 0x6f, 0x72, 0x6b, 0x2c, 0x20, 0x77, 0x68, 0x65, 0x74, 0x68, 0x65, 0x72, 0x20, 0x69, 0x6e, 0x20, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x2c, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x69, 0x73, 0x20, 0x62, 0x61, 0x73, 0x65, 0x64, 0x20, 0x6f, 0x6e, 0x20, 0x28, 0x6f, 0x72, 0x20, 0x64, 0x65, 0x72, 0x69, 0x76, 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x29, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x77, 0x68, 0x69, 0x63, 0x68, 0x20, 0x74, 0x68, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x64, 0x69, 0x74, 0x6f, 0x72, 0x69, 0x61, 0x6c, 0x20, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x20, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x20, 0x65, 0x6c, 0x61, 0x62, 0x6f, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x2c, 0x20, 0x61, 0x73, 0x20, 0x61, 0x20, 0x77, 0x68, 0x6f, 0x6c, 0x65, 0x2c, 0x20, 0x61, 0x6e, 0x20, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x20, 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x73, 0x68, 0x69, 0x70, 0x2e, 0x20, 0x46, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70, 0x6f, 0x73, 0x65, 0x73, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x72, 0x65, 0x6d, 0x61, 0x69, 0x6e, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x65, 0x70, 0x61, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x6d, 0x65, 0x72, 0x65, 0x6c, 0x79, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0x20, 0x28, 0x6f, 0x72, 0x20, 0x62, 0x69, 0x6e, 0x64, 0x20, 0x62, 0x79, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x20, 0x6f, 0x66, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x20, 0x74, 0x68, 0x65, 0x72, 0x65, 0x6f, 0x66, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x6d, 0x65, 0x61, 0x6e, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x73, 0x68, 0x69, 0x70, 0x2c, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x69, 0x6e, 0x67, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x6f, 0x72, 0x20, 0x61, 0x64, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x6f, 0x72, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x20, 0x74, 0x68, 0x65, 0x72, 0x65, 0x6f, 0x66, 0x2c, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x69, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x6c, 0x79, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x74, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x62, 0x79, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x72, 0x20, 0x62, 0x79, 0x20, 0x61, 0x6e, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x76, 0x69, 0x64, 0x75, 0x61, 0x6c, 0x20, 0x6f, 0x72, 0x20, 0x4c, 0x65, 0x67, 0x61, 0x6c, 0x20, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x20, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x20, 0x6f, 0x6e, 0x20, 0x62, 0x65, 0x68, 0x61, 0x6c, 0x66, 0x20, 0x6f, 0x66, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x2e, 0x20, 0x46, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70, 0x6f, 0x73, 0x65, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x74, 0x65, 0x64, 0x22, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6d, 0x65, 0x61, 0x6e, 0x73, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x6f, 0x66, 0x20, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x72, 0x6f, 0x6e, 0x69, 0x63, 0x2c, 0x20, 0x76, 0x65, 0x72, 0x62, 0x61, 0x6c, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x77, 0x72, 0x69, 0x74, 0x74, 0x65, 0x6e, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x75, 0x6e, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x65, 0x6e, 0x74, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x20, 0x6f, 0x72, 0x20, 0x69, 0x74, 0x73, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x76, 0x65, 0x73, 0x2c, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x62, 0x75, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x75, 0x6e, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x6e, 0x20, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x72, 0x6f, 0x6e, 0x69, 0x63, 0x20, 0x6d, 0x61, 0x69, 0x6c, 0x69, 0x6e, 0x67, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x73, 0x2c, 0x20, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x69, 0x73, 0x73, 0x75, 0x65, 0x20, 0x74, 0x72, 0x61, 0x63, 0x6b, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x61, 0x72, 0x65, 0x20, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x64, 0x20, 0x62, 0x79, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, 0x62, 0x65, 0x68, 0x61, 0x6c, 0x66, 0x20, 0x6f, 0x66, 0x2c, 0x20, 0x74, 0x68, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70, 0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x64, 0x69, 0x73, 0x63, 0x75, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x69, 0x6d, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x2c, 0x20, 0x62, 0x75, 0x74, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x78, 0x63, 0x6c, 0x75, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x75, 0x6e, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x69, 0x73, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x70, 0x69, 0x63, 0x75, 0x6f, 0x75, 0x73, 0x6c, 0x79, 0x20, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x64, 0x20, 0x6f, 0x72, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x77, 0x69, 0x73, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64, 0x65, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20, 0x77, 0x72, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x62, 0x79, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x20, 0x61, 0x73, 0x20, 0x22, 0x4e, 0x6f, 0x74, 0x20, 0x61, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x22, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x22, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x6d, 0x65, 0x61, 0x6e, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x76, 0x69, 0x64, 0x75, 0x61, 0x6c, 0x20, 0x6f, 0x72, 0x20, 0x4c, 0x65, 0x67, 0x61, 0x6c, 0x20, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x6e, 0x20, 0x62, 0x65, 0x68, 0x61, 0x6c, 0x66, 0x20, 0x6f, 0x66, 0x20, 0x77, 0x68, 0x6f, 0x6d, 0x20, 0x61, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x68, 0x61, 0x73, 0x20, 0x62, 0x65, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x20, 0x61, 0x6e, 0x64, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x75, 0x62, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x6c, 0x79, 0x20, 0x69, 0x6e, 0x63, 0x6f, 0x72, 0x70, 0x6f, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x32, 0x2e, 0x20, 0x47, 0x72, 0x61, 0x6e, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x20, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x6f, 0x66, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c, 0x20, 0x65, 0x61, 0x63, 0x68, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x20, 0x68, 0x65, 0x72, 0x65, 0x62, 0x79, 0x20, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x73, 0x20, 0x74, 0x6f, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x61, 0x20, 0x70, 0x65, 0x72, 0x70, 0x65, 0x74, 0x75, 0x61, 0x6c, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x77, 0x69, 0x64, 0x65, 0x2c, 0x20, 0x6e, 0x6f, 0x6e, 0x2d, 0x65, 0x78, 0x63, 0x6c, 0x75, 0x73, 0x69, 0x76, 0x65, 0x2c, 0x20, 0x6e, 0x6f, 0x2d, 0x63, 0x68, 0x61, 0x72, 0x67, 0x65, 0x2c, 0x20, 0x72, 0x6f, 0x79, 0x61, 0x6c, 0x74, 0x79, 0x2d, 0x66, 0x72, 0x65, 0x65, 0x2c, 0x20, 0x69, 0x72, 0x72, 0x65, 0x76, 0x6f, 0x63, 0x61, 0x62, 0x6c, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x72, 0x65, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x2c, 0x20, 0x70, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x20, 0x6f, 0x66, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x6c, 0x79, 0x20, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x2c, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x6c, 0x79, 0x20, 0x70, 0x65, 0x72, 0x66, 0x6f, 0x72, 0x6d, 0x2c, 0x20, 0x73, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x74, 0x68, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x20, 0x69, 0x6e, 0x20, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x33, 0x2e, 0x20, 0x47, 0x72, 0x61, 0x6e, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x50, 0x61, 0x74, 0x65, 0x6e, 0x74, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x20, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x6f, 0x66, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c, 0x20, 0x65, 0x61, 0x63, 0x68, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x20, 0x68, 0x65, 0x72, 0x65, 0x62, 0x79, 0x20, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x73, 0x20, 0x74, 0x6f, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x61, 0x20, 0x70, 0x65, 0x72, 0x70, 0x65, 0x74, 0x75, 0x61, 0x6c, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x77, 0x69, 0x64, 0x65, 0x2c, 0x20, 0x6e, 0x6f, 0x6e, 0x2d, 0x65, 0x78, 0x63, 0x6c, 0x75, 0x73, 0x69, 0x76, 0x65, 0x2c, 0x20, 0x6e, 0x6f, 0x2d, 0x63, 0x68, 0x61, 0x72, 0x67, 0x65, 0x2c, 0x20, 0x72, 0x6f, 0x79, 0x61, 0x6c, 0x74, 0x79, 0x2d, 0x66, 0x72, 0x65, 0x65, 0x2c, 0x20, 0x69, 0x72, 0x72, 0x65, 0x76, 0x6f, 0x63, 0x61, 0x62, 0x6c, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x28, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74, 0x20, 0x61, 0x73, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x73, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x29, 0x20, 0x70, 0x61, 0x74, 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x2c, 0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x6d, 0x61, 0x64, 0x65, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x75, 0x73, 0x65, 0x2c, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x20, 0x74, 0x6f, 0x20, 0x73, 0x65, 0x6c, 0x6c, 0x2c, 0x20, 0x73, 0x65, 0x6c, 0x6c, 0x2c, 0x20, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x77, 0x69, 0x73, 0x65, 0x20, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x77, 0x68, 0x65, 0x72, 0x65, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x20, 0x6f, 0x6e, 0x6c, 0x79, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65, 0x20, 0x70, 0x61, 0x74, 0x65, 0x6e, 0x74, 0x20, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x73, 0x20, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x79, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x61, 0x72, 0x65, 0x20, 0x6e, 0x65, 0x63, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x6c, 0x79, 0x20, 0x69, 0x6e, 0x66, 0x72, 0x69, 0x6e, 0x67, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74, 0x68, 0x65, 0x69, 0x72, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x73, 0x29, 0x20, 0x61, 0x6c, 0x6f, 0x6e, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x62, 0x79, 0x20, 0x63, 0x6f, 0x6d, 0x62, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x69, 0x72, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x73, 0x29, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x74, 0x6f, 0x20, 0x77, 0x68, 0x69, 0x63, 0x68, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x73, 0x29, 0x20, 0x77, 0x61, 0x73, 0x20, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x49, 0x66, 0x20, 0x59, 0x6f, 0x75, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x6e, 0x73, 0x74, 0x69, 0x74, 0x75, 0x74, 0x65, 0x20, 0x70, 0x61, 0x74, 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x69, 0x74, 0x69, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x67, 0x61, 0x69, 0x6e, 0x73, 0x74, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x20, 0x28, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x72, 0x6f, 0x73, 0x73, 0x2d, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x20, 0x6f, 0x72, 0x20, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x20, 0x69, 0x6e, 0x20, 0x61, 0x20, 0x6c, 0x61, 0x77, 0x73, 0x75, 0x69, 0x74, 0x29, 0x20, 0x61, 0x6c, 0x6c, 0x65, 0x67, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x72, 0x20, 0x61, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x6e, 0x63, 0x6f, 0x72, 0x70, 0x6f, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x69, 0x74, 0x75, 0x74, 0x65, 0x73, 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x72, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x79, 0x20, 0x70, 0x61, 0x74, 0x65, 0x6e, 0x74, 0x20, 0x69, 0x6e, 0x66, 0x72, 0x69, 0x6e, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x70, 0x61, 0x74, 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x73, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x61, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x64, 0x61, 0x74, 0x65, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x6c, 0x69, 0x74, 0x69, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x64, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x34, 0x2e, 0x20, 0x52, 0x65, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x72, 0x65, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x63, 0x6f, 0x70, 0x69, 0x65, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x6f, 0x72, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x20, 0x74, 0x68, 0x65, 0x72, 0x65, 0x6f, 0x66, 0x20, 0x69, 0x6e, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x6d, 0x65, 0x64, 0x69, 0x75, 0x6d, 0x2c, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x6f, 0x72, 0x20, 0x77, 0x69, 0x74, 0x68, 0x6f, 0x75, 0x74, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x69, 0x6e, 0x20, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x2c, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x64, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x59, 0x6f, 0x75, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6d, 0x65, 0x65, 0x74, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x20, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x28, 0x61, 0x29, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x67, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20, 0x72, 0x65, 0x63, 0x69, 0x70, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x6f, 0x72, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x70, 0x79, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x3b, 0x20, 0x61, 0x6e, 0x64, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x28, 0x62, 0x29, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x63, 0x61, 0x75, 0x73, 0x65, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x20, 0x74, 0x6f, 0x20, 0x63, 0x61, 0x72, 0x72, 0x79, 0x20, 0x70, 0x72, 0x6f, 0x6d, 0x69, 0x6e, 0x65, 0x6e, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x73, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x3b, 0x20, 0x61, 0x6e, 0x64, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x28, 0x63, 0x29, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x72, 0x65, 0x74, 0x61, 0x69, 0x6e, 0x2c, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x63, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x2c, 0x20, 0x70, 0x61, 0x74, 0x65, 0x6e, 0x74, 0x2c, 0x20, 0x74, 0x72, 0x61, 0x64, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x73, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x78, 0x63, 0x6c, 0x75, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65, 0x20, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x73, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x70, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x70, 0x61, 0x72, 0x74, 0x20, 0x6f, 0x66, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x65, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x3b, 0x20, 0x61, 0x6e, 0x64, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x28, 0x64, 0x29, 0x20, 0x49, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x73, 0x20, 0x61, 0x20, 0x22, 0x4e, 0x4f, 0x54, 0x49, 0x43, 0x45, 0x22, 0x20, 0x74, 0x65, 0x78, 0x74, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x61, 0x73, 0x20, 0x70, 0x61, 0x72, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x69, 0x74, 0x73, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x61, 0x20, 0x72, 0x65, 0x61, 0x64, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x63, 0x6f, 0x70, 0x79, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x73, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x64, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x77, 0x69, 0x74, 0x68, 0x69, 0x6e, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x4e, 0x4f, 0x54, 0x49, 0x43, 0x45, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2c, 0x20, 0x65, 0x78, 0x63, 0x6c, 0x75, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65, 0x20, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x73, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20, 0x6e, 0x6f, 0x74, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x70, 0x61, 0x72, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x2c, 0x20, 0x69, 0x6e, 0x20, 0x61, 0x74, 0x20, 0x6c, 0x65, 0x61, 0x73, 0x74, 0x20, 0x6f, 0x6e, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x73, 0x3a, 0x20, 0x77, 0x69, 0x74, 0x68, 0x69, 0x6e, 0x20, 0x61, 0x20, 0x4e, 0x4f, 0x54, 0x49, 0x43, 0x45, 0x20, 0x74, 0x65, 0x78, 0x74, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x61, 0x73, 0x20, 0x70, 0x61, 0x72, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x3b, 0x20, 0x77, 0x69, 0x74, 0x68, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x6f, 0x72, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x69, 0x66, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x64, 0x20, 0x61, 0x6c, 0x6f, 0x6e, 0x67, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x3b, 0x20, 0x6f, 0x72, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x77, 0x69, 0x74, 0x68, 0x69, 0x6e, 0x20, 0x61, 0x20, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x20, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74, 0x68, 0x65, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x2c, 0x20, 0x69, 0x66, 0x20, 0x61, 0x6e, 0x64, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x77, 0x68, 0x65, 0x72, 0x65, 0x76, 0x65, 0x72, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64, 0x2d, 0x70, 0x61, 0x72, 0x74, 0x79, 0x20, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x73, 0x20, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x6c, 0x79, 0x20, 0x61, 0x70, 0x70, 0x65, 0x61, 0x72, 0x2e, 0x20, 0x54, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4e, 0x4f, 0x54, 0x49, 0x43, 0x45, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x61, 0x72, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x70, 0x75, 0x72, 0x70, 0x6f, 0x73, 0x65, 0x73, 0x20, 0x6f, 0x6e, 0x6c, 0x79, 0x20, 0x61, 0x6e, 0x64, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64, 0x6f, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x61, 0x64, 0x64, 0x20, 0x59, 0x6f, 0x75, 0x72, 0x20, 0x6f, 0x77, 0x6e, 0x20, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x73, 0x20, 0x77, 0x69, 0x74, 0x68, 0x69, 0x6e, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x61, 0x6c, 0x6f, 0x6e, 0x67, 0x73, 0x69, 0x64, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x72, 0x20, 0x61, 0x73, 0x20, 0x61, 0x6e, 0x20, 0x61, 0x64, 0x64, 0x65, 0x6e, 0x64, 0x75, 0x6d, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4e, 0x4f, 0x54, 0x49, 0x43, 0x45, 0x20, 0x74, 0x65, 0x78, 0x74, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x2c, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x64, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x61, 0x64, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x73, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x65, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x65, 0x64, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x61, 0x73, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x61, 0x64, 0x64, 0x20, 0x59, 0x6f, 0x75, 0x72, 0x20, 0x6f, 0x77, 0x6e, 0x20, 0x63, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x59, 0x6f, 0x75, 0x72, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x20, 0x61, 0x64, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x6f, 0x72, 0x20, 0x64, 0x69, 0x66, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x75, 0x73, 0x65, 0x2c, 0x20, 0x72, 0x65, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x59, 0x6f, 0x75, 0x72, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x20, 0x6f, 0x72, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x20, 0x61, 0x73, 0x20, 0x61, 0x20, 0x77, 0x68, 0x6f, 0x6c, 0x65, 0x2c, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x64, 0x20, 0x59, 0x6f, 0x75, 0x72, 0x20, 0x75, 0x73, 0x65, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x77, 0x69, 0x73, 0x65, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x20, 0x77, 0x69, 0x74, 0x68, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x35, 0x2e, 0x20, 0x53, 0x75, 0x62, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x20, 0x55, 0x6e, 0x6c, 0x65, 0x73, 0x73, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x65, 0x78, 0x70, 0x6c, 0x69, 0x63, 0x69, 0x74, 0x6c, 0x79, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x77, 0x69, 0x73, 0x65, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x6c, 0x79, 0x20, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x74, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x79, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x62, 0x65, 0x20, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x6f, 0x66, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c, 0x20, 0x77, 0x69, 0x74, 0x68, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x61, 0x64, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x6f, 0x72, 0x20, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x4e, 0x6f, 0x74, 0x77, 0x69, 0x74, 0x68, 0x73, 0x74, 0x61, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x62, 0x6f, 0x76, 0x65, 0x2c, 0x20, 0x6e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x65, 0x72, 0x65, 0x69, 0x6e, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x73, 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x64, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x73, 0x65, 0x70, 0x61, 0x72, 0x61, 0x74, 0x65, 0x20, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x61, 0x67, 0x72, 0x65, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x64, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x67, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x36, 0x2e, 0x20, 0x54, 0x72, 0x61, 0x64, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x73, 0x2e, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x64, 0x6f, 0x65, 0x73, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x20, 0x70, 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x75, 0x73, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x72, 0x61, 0x64, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x2c, 0x20, 0x74, 0x72, 0x61, 0x64, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x73, 0x2c, 0x20, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x20, 0x6d, 0x61, 0x72, 0x6b, 0x73, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74, 0x20, 0x61, 0x73, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x61, 0x72, 0x79, 0x20, 0x75, 0x73, 0x65, 0x20, 0x69, 0x6e, 0x20, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x72, 0x65, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4e, 0x4f, 0x54, 0x49, 0x43, 0x45, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x37, 0x2e, 0x20, 0x44, 0x69, 0x73, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x65, 0x72, 0x20, 0x6f, 0x66, 0x20, 0x57, 0x61, 0x72, 0x72, 0x61, 0x6e, 0x74, 0x79, 0x2e, 0x20, 0x55, 0x6e, 0x6c, 0x65, 0x73, 0x73, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x6c, 0x61, 0x77, 0x20, 0x6f, 0x72, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x61, 0x67, 0x72, 0x65, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x69, 0x6e, 0x20, 0x77, 0x72, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x2c, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x28, 0x61, 0x6e, 0x64, 0x20, 0x65, 0x61, 0x63, 0x68, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x73, 0x20, 0x69, 0x74, 0x73, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x29, 0x20, 0x6f, 0x6e, 0x20, 0x61, 0x6e, 0x20, 0x22, 0x41, 0x53, 0x20, 0x49, 0x53, 0x22, 0x20, 0x42, 0x41, 0x53, 0x49, 0x53, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x57, 0x49, 0x54, 0x48, 0x4f, 0x55, 0x54, 0x20, 0x57, 0x41, 0x52, 0x52, 0x41, 0x4e, 0x54, 0x49, 0x45, 0x53, 0x20, 0x4f, 0x52, 0x20, 0x43, 0x4f, 0x4e, 0x44, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0x20, 0x4f, 0x46, 0x20, 0x41, 0x4e, 0x59, 0x20, 0x4b, 0x49, 0x4e, 0x44, 0x2c, 0x20, 0x65, 0x69, 0x74, 0x68, 0x65, 0x72, 0x20, 0x65, 0x78, 0x70, 0x72, 0x65, 0x73, 0x73, 0x20, 0x6f, 0x72, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x69, 0x65, 0x64, 0x2c, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x69, 0x6e, 0x67, 0x2c, 0x20, 0x77, 0x69, 0x74, 0x68, 0x6f, 0x75, 0x74, 0x20, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x77, 0x61, 0x72, 0x72, 0x61, 0x6e, 0x74, 0x69, 0x65, 0x73, 0x20, 0x6f, 0x72, 0x20, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x66, 0x20, 0x54, 0x49, 0x54, 0x4c, 0x45, 0x2c, 0x20, 0x4e, 0x4f, 0x4e, 0x2d, 0x49, 0x4e, 0x46, 0x52, 0x49, 0x4e, 0x47, 0x45, 0x4d, 0x45, 0x4e, 0x54, 0x2c, 0x20, 0x4d, 0x45, 0x52, 0x43, 0x48, 0x41, 0x4e, 0x54, 0x41, 0x42, 0x49, 0x4c, 0x49, 0x54, 0x59, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x46, 0x49, 0x54, 0x4e, 0x45, 0x53, 0x53, 0x20, 0x46, 0x4f, 0x52, 0x20, 0x41, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x50, 0x41, 0x52, 0x54, 0x49, 0x43, 0x55, 0x4c, 0x41, 0x52, 0x20, 0x50, 0x55, 0x52, 0x50, 0x4f, 0x53, 0x45, 0x2e, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x61, 0x72, 0x65, 0x20, 0x73, 0x6f, 0x6c, 0x65, 0x6c, 0x79, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x64, 0x65, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x70, 0x72, 0x69, 0x61, 0x74, 0x65, 0x6e, 0x65, 0x73, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x61, 0x73, 0x73, 0x75, 0x6d, 0x65, 0x20, 0x61, 0x6e, 0x79, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x69, 0x73, 0x6b, 0x73, 0x20, 0x61, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x59, 0x6f, 0x75, 0x72, 0x20, 0x65, 0x78, 0x65, 0x72, 0x63, 0x69, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x70, 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x38, 0x2e, 0x20, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x4c, 0x69, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x20, 0x49, 0x6e, 0x20, 0x6e, 0x6f, 0x20, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x20, 0x6e, 0x6f, 0x20, 0x6c, 0x65, 0x67, 0x61, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6f, 0x72, 0x79, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x77, 0x68, 0x65, 0x74, 0x68, 0x65, 0x72, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x6f, 0x72, 0x74, 0x20, 0x28, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x65, 0x67, 0x6c, 0x69, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x29, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x77, 0x69, 0x73, 0x65, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x75, 0x6e, 0x6c, 0x65, 0x73, 0x73, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x6c, 0x61, 0x77, 0x20, 0x28, 0x73, 0x75, 0x63, 0x68, 0x20, 0x61, 0x73, 0x20, 0x64, 0x65, 0x6c, 0x69, 0x62, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x67, 0x72, 0x6f, 0x73, 0x73, 0x6c, 0x79, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x65, 0x67, 0x6c, 0x69, 0x67, 0x65, 0x6e, 0x74, 0x20, 0x61, 0x63, 0x74, 0x73, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x61, 0x67, 0x72, 0x65, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x69, 0x6e, 0x20, 0x77, 0x72, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x2c, 0x20, 0x73, 0x68, 0x61, 0x6c, 0x6c, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x20, 0x62, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6c, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x64, 0x61, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x2c, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x2c, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x2c, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x61, 0x6c, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x6e, 0x63, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x20, 0x64, 0x61, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x63, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x20, 0x61, 0x72, 0x69, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x73, 0x20, 0x61, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x75, 0x73, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x69, 0x6e, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x20, 0x74, 0x6f, 0x20, 0x75, 0x73, 0x65, 0x20, 0x74, 0x68, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x28, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x62, 0x75, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x64, 0x61, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x73, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x67, 0x6f, 0x6f, 0x64, 0x77, 0x69, 0x6c, 0x6c, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x73, 0x74, 0x6f, 0x70, 0x70, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, 0x20, 0x66, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x6d, 0x61, 0x6c, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x61, 0x6c, 0x6c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x72, 0x63, 0x69, 0x61, 0x6c, 0x20, 0x64, 0x61, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x20, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x73, 0x73, 0x65, 0x73, 0x29, 0x2c, 0x20, 0x65, 0x76, 0x65, 0x6e, 0x20, 0x69, 0x66, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x68, 0x61, 0x73, 0x20, 0x62, 0x65, 0x65, 0x6e, 0x20, 0x61, 0x64, 0x76, 0x69, 0x73, 0x65, 0x64, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x6f, 0x73, 0x73, 0x69, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x20, 0x6f, 0x66, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x64, 0x61, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x39, 0x2e, 0x20, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x57, 0x61, 0x72, 0x72, 0x61, 0x6e, 0x74, 0x79, 0x20, 0x6f, 0x72, 0x20, 0x41, 0x64, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x4c, 0x69, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x20, 0x57, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6e, 0x67, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x20, 0x6f, 0x72, 0x20, 0x44, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x20, 0x74, 0x68, 0x65, 0x72, 0x65, 0x6f, 0x66, 0x2c, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x63, 0x68, 0x6f, 0x6f, 0x73, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 0x68, 0x61, 0x72, 0x67, 0x65, 0x20, 0x61, 0x20, 0x66, 0x65, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x2c, 0x20, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2c, 0x20, 0x77, 0x61, 0x72, 0x72, 0x61, 0x6e, 0x74, 0x79, 0x2c, 0x20, 0x69, 0x6e, 0x64, 0x65, 0x6d, 0x6e, 0x69, 0x74, 0x79, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x72, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20, 0x6c, 0x69, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x20, 0x6f, 0x62, 0x6c, 0x69, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, 0x72, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x73, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, 0x69, 0x73, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x20, 0x48, 0x6f, 0x77, 0x65, 0x76, 0x65, 0x72, 0x2c, 0x20, 0x69, 0x6e, 0x20, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x6f, 0x62, 0x6c, 0x69, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x61, 0x63, 0x74, 0x20, 0x6f, 0x6e, 0x6c, 0x79, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x6e, 0x20, 0x59, 0x6f, 0x75, 0x72, 0x20, 0x6f, 0x77, 0x6e, 0x20, 0x62, 0x65, 0x68, 0x61, 0x6c, 0x66, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6f, 0x6e, 0x20, 0x59, 0x6f, 0x75, 0x72, 0x20, 0x73, 0x6f, 0x6c, 0x65, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x69, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2c, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6f, 0x6e, 0x20, 0x62, 0x65, 0x68, 0x61, 0x6c, 0x66, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6f, 0x6e, 0x6c, 0x79, 0x20, 0x69, 0x66, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x61, 0x67, 0x72, 0x65, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x69, 0x6e, 0x64, 0x65, 0x6d, 0x6e, 0x69, 0x66, 0x79, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64, 0x65, 0x66, 0x65, 0x6e, 0x64, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x68, 0x6f, 0x6c, 0x64, 0x20, 0x65, 0x61, 0x63, 0x68, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x20, 0x68, 0x61, 0x72, 0x6d, 0x6c, 0x65, 0x73, 0x73, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x6c, 0x69, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x6e, 0x63, 0x75, 0x72, 0x72, 0x65, 0x64, 0x20, 0x62, 0x79, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x73, 0x20, 0x61, 0x73, 0x73, 0x65, 0x72, 0x74, 0x65, 0x64, 0x20, 0x61, 0x67, 0x61, 0x69, 0x6e, 0x73, 0x74, 0x2c, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x20, 0x62, 0x79, 0x20, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x66, 0x20, 0x79, 0x6f, 0x75, 0x72, 0x20, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x73, 0x75, 0x63, 0x68, 0x20, 0x77, 0x61, 0x72, 0x72, 0x61, 0x6e, 0x74, 0x79, 0x20, 0x6f, 0x72, 0x20, 0x61, 0x64, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x6c, 0x69, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x45, 0x4e, 0x44, 0x20, 0x4f, 0x46, 0x20, 0x54, 0x45, 0x52, 0x4d, 0x53, 0x20, 0x41, 0x4e, 0x44, 0x20, 0x43, 0x4f, 0x4e, 0x44, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x41, 0x50, 0x50, 0x45, 0x4e, 0x44, 0x49, 0x58, 0x3a, 0x20, 0x48, 0x6f, 0x77, 0x20, 0x74, 0x6f, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x20, 0x74, 0x68, 0x65, 0x20, 0x41, 0x70, 0x61, 0x63, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x79, 0x6f, 0x75, 0x72, 0x20, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x54, 0x6f, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x20, 0x74, 0x68, 0x65, 0x20, 0x41, 0x70, 0x61, 0x63, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x79, 0x6f, 0x75, 0x72, 0x20, 0x77, 0x6f, 0x72, 0x6b, 0x2c, 0x20, 0x61, 0x74, 0x74, 0x61, 0x63, 0x68, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x6f, 0x69, 0x6c, 0x65, 0x72, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x20, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x2c, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x20, 0x65, 0x6e, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x62, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x73, 0x20, 0x22, 0x5b, 0x5d, 0x22, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x79, 0x6f, 0x75, 0x72, 0x20, 0x6f, 0x77, 0x6e, 0x20, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x69, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x20, 0x28, 0x44, 0x6f, 0x6e, 0x27, 0x74, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x65, 0x20, 0x62, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x73, 0x21, 0x29, 0x20, 0x20, 0x54, 0x68, 0x65, 0x20, 0x74, 0x65, 0x78, 0x74, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x65, 0x6e, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x70, 0x72, 0x69, 0x61, 0x74, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x73, 0x79, 0x6e, 0x74, 0x61, 0x78, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x2e, 0x20, 0x57, 0x65, 0x20, 0x61, 0x6c, 0x73, 0x6f, 0x20, 0x72, 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x61, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x70, 0x75, 0x72, 0x70, 0x6f, 0x73, 0x65, 0x20, 0x62, 0x65, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x64, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x61, 0x6d, 0x65, 0x20, 0x22, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x65, 0x64, 0x20, 0x70, 0x61, 0x67, 0x65, 0x22, 0x20, 0x61, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x65, 0x61, 0x73, 0x69, 0x65, 0x72, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x77, 0x69, 0x74, 0x68, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64, 0x2d, 0x70, 0x61, 0x72, 0x74, 0x79, 0x20, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x73, 0x2e, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x5b, 0x79, 0x79, 0x79, 0x79, 0x5d, 0x20, 0x5b, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x63, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x5d, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x64, 0x20, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x41, 0x70, 0x61, 0x63, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c, 0x20, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x32, 0x2e, 0x30, 0x20, 0x28, 0x74, 0x68, 0x65, 0x20, 0x22, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x22, 0x29, 0x3b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x75, 0x73, 0x65, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74, 0x20, 0x69, 0x6e, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x59, 0x6f, 0x75, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x6f, 0x62, 0x74, 0x61, 0x69, 0x6e, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x70, 0x79, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x61, 0x74, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x61, 0x70, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x73, 0x2f, 0x4c, 0x49, 0x43, 0x45, 0x4e, 0x53, 0x45, 0x2d, 0x32, 0x2e, 0x30, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x55, 0x6e, 0x6c, 0x65, 0x73, 0x73, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x6c, 0x61, 0x77, 0x20, 0x6f, 0x72, 0x20, 0x61, 0x67, 0x72, 0x65, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x69, 0x6e, 0x20, 0x77, 0x72, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x2c, 0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x20, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x69, 0x73, 0x20, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x20, 0x6f, 0x6e, 0x20, 0x61, 0x6e, 0x20, 0x22, 0x41, 0x53, 0x20, 0x49, 0x53, 0x22, 0x20, 0x42, 0x41, 0x53, 0x49, 0x53, 0x2c, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x57, 0x49, 0x54, 0x48, 0x4f, 0x55, 0x54, 0x20, 0x57, 0x41, 0x52, 0x52, 0x41, 0x4e, 0x54, 0x49, 0x45, 0x53, 0x20, 0x4f, 0x52, 0x20, 0x43, 0x4f, 0x4e, 0x44, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0x20, 0x4f, 0x46, 0x20, 0x41, 0x4e, 0x59, 0x20, 0x4b, 0x49, 0x4e, 0x44, 0x2c, 0x20, 0x65, 0x69, 0x74, 0x68, 0x65, 0x72, 0x20, 0x65, 0x78, 0x70, 0x72, 0x65, 0x73, 0x73, 0x20, 0x6f, 0x72, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x69, 0x65, 0x64, 0x2e, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x53, 0x65, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x20, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x20, 0x67, 0x6f, 0x76, 0x65, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x70, 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x0d, 0x0a }; -static const rt_uint8_t _romfs_root_mnt_flash__keep[] = +static const rt_uint8_t _romfs_root_mnt_flash__keep[] = { 0x2e, 0x6b, 0x65, 0x65, 0x70, 0x20, 0x0d, 0x0a }; -static const struct romfs_dirent _romfs_root_mnt_flash[] = +static const struct romfs_dirent _romfs_root_mnt_flash[] = { {ROMFS_DIRENT_FILE, ".keep", (rt_uint8_t *)_romfs_root_mnt_flash__keep, sizeof(_romfs_root_mnt_flash__keep) / sizeof(_romfs_root_mnt_flash__keep[0])} }; -static const rt_uint8_t _romfs_root_mnt_sd__keep[] = +static const rt_uint8_t _romfs_root_mnt_sd__keep[] = { 0x2e, 0x6b, 0x65, 0x65, 0x70, 0x20, 0x0d, 0x0a }; -static const struct romfs_dirent _romfs_root_mnt_sd[] = +static const struct romfs_dirent _romfs_root_mnt_sd[] = { {ROMFS_DIRENT_FILE, ".keep", (rt_uint8_t *)_romfs_root_mnt_sd__keep, sizeof(_romfs_root_mnt_sd__keep) / sizeof(_romfs_root_mnt_sd__keep[0])} }; -static const rt_uint8_t _romfs_root_mnt_tmp__keep[] = +static const rt_uint8_t _romfs_root_mnt_tmp__keep[] = { 0x2e, 0x6b, 0x65, 0x65, 0x70, 0x20, 0x0d, 0x0a }; -static const struct romfs_dirent _romfs_root_mnt_tmp[] = +static const struct romfs_dirent _romfs_root_mnt_tmp[] = { {ROMFS_DIRENT_FILE, ".keep", (rt_uint8_t *)_romfs_root_mnt_tmp__keep, sizeof(_romfs_root_mnt_tmp__keep) / sizeof(_romfs_root_mnt_tmp__keep[0])} }; -static const struct romfs_dirent _romfs_root_mnt[] = +static const struct romfs_dirent _romfs_root_mnt[] = { {ROMFS_DIRENT_DIR, "flash", (rt_uint8_t *)_romfs_root_mnt_flash, sizeof(_romfs_root_mnt_flash) / sizeof(_romfs_root_mnt_flash[0])}, {ROMFS_DIRENT_DIR, "sd", (rt_uint8_t *)_romfs_root_mnt_sd, sizeof(_romfs_root_mnt_sd) / sizeof(_romfs_root_mnt_sd[0])}, {ROMFS_DIRENT_DIR, "tmp", (rt_uint8_t *)_romfs_root_mnt_tmp, sizeof(_romfs_root_mnt_tmp) / sizeof(_romfs_root_mnt_tmp[0])} }; -static const struct romfs_dirent _romfs_root[] = +static const struct romfs_dirent _romfs_root[] = { {ROMFS_DIRENT_FILE, "license", (rt_uint8_t *)_romfs_root_license, sizeof(_romfs_root_license) / sizeof(_romfs_root_license[0])}, {ROMFS_DIRENT_DIR, "mnt", (rt_uint8_t *)_romfs_root_mnt, sizeof(_romfs_root_mnt) / sizeof(_romfs_root_mnt[0])} diff --git a/bsp/lpc54114-lite/drivers/drv_sdcard.c b/bsp/lpc54114-lite/drivers/drv_sdcard.c index 3ef5081aa7..7ca47a1932 100644 --- a/bsp/lpc54114-lite/drivers/drv_sdcard.c +++ b/bsp/lpc54114-lite/drivers/drv_sdcard.c @@ -1,27 +1,27 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 */ - + #include "drv_sdcard.h" -#include "drv_spi.h" +#include "drv_spi.h" #include "spi_msd.h" #define RT_SDCARD_CS_PIN (3) int rt_hw_sdcard_init(void) { - rt_err_t ret; - - ret = lpc_spi_bus_attach_device("spi2", "spi21", RT_SDCARD_CS_PIN); - if(ret != RT_EOK) + rt_err_t ret; + + ret = lpc_spi_bus_attach_device("spi2", "spi21", RT_SDCARD_CS_PIN); + if(ret != RT_EOK) { - return ret; + return ret; } - + ret = msd_init("sd0", "spi21"); - return ret; + return ret; } -INIT_DEVICE_EXPORT(rt_hw_sdcard_init); +INIT_DEVICE_EXPORT(rt_hw_sdcard_init); diff --git a/bsp/lpc54114-lite/drivers/drv_sdcard.h b/bsp/lpc54114-lite/drivers/drv_sdcard.h index 1ba77cf2b2..a225433b15 100644 --- a/bsp/lpc54114-lite/drivers/drv_sdcard.h +++ b/bsp/lpc54114-lite/drivers/drv_sdcard.h @@ -1,14 +1,14 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 */ - -#ifndef __DRV_SDCARD_H__ -#define __DRV_SDCARD_H__ -#include -#include +#ifndef __DRV_SDCARD_H__ +#define __DRV_SDCARD_H__ + +#include +#include int rt_hw_sdcard_init(void); diff --git a/bsp/lpc54114-lite/drivers/drv_spi.c b/bsp/lpc54114-lite/drivers/drv_spi.c index 0843e0baab..c83aaf03ee 100644 --- a/bsp/lpc54114-lite/drivers/drv_spi.c +++ b/bsp/lpc54114-lite/drivers/drv_spi.c @@ -1,12 +1,12 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 */ #include "drv_spi.h" -#include "fsl_common.h" +#include "fsl_common.h" #include "fsl_iocon.h" #include "fsl_spi.h" @@ -25,23 +25,23 @@ static uint32_t get_spi_freq(SPI_Type *base) { freq = CLOCK_GetFreq(kCLOCK_Flexcomm2); } -#endif +#endif - return freq; + return freq; } static rt_err_t spi_init(SPI_Type *base, struct rt_spi_configuration *cfg) { spi_master_config_t masterConfig = {0}; - RT_ASSERT(cfg != RT_NULL); + RT_ASSERT(cfg != RT_NULL); if(cfg->data_width != 8 && cfg->data_width != 16) { - return (-RT_EINVAL); + return (-RT_EINVAL); } - SPI_MasterGetDefaultConfig(&masterConfig); + SPI_MasterGetDefaultConfig(&masterConfig); if(cfg->max_hz > 12*1000*1000) { @@ -51,124 +51,124 @@ static rt_err_t spi_init(SPI_Type *base, struct rt_spi_configuration *cfg) if(cfg->data_width == 8) { - masterConfig.dataWidth = kSPI_Data8Bits; + masterConfig.dataWidth = kSPI_Data8Bits; } else if(cfg->data_width == 16) { - masterConfig.dataWidth = kSPI_Data16Bits; + masterConfig.dataWidth = kSPI_Data16Bits; } if(cfg->mode & RT_SPI_MSB) { - masterConfig.direction = kSPI_MsbFirst; + masterConfig.direction = kSPI_MsbFirst; } else { - masterConfig.direction = kSPI_LsbFirst; + masterConfig.direction = kSPI_LsbFirst; } if(cfg->mode & RT_SPI_CPHA) { - masterConfig.phase = kSPI_ClockPhaseSecondEdge; + masterConfig.phase = kSPI_ClockPhaseSecondEdge; } else { - masterConfig.phase = kSPI_ClockPhaseFirstEdge; + masterConfig.phase = kSPI_ClockPhaseFirstEdge; } if(cfg->mode & RT_SPI_CPOL) { - masterConfig.polarity = kSPI_ClockPolarityActiveLow; + masterConfig.polarity = kSPI_ClockPolarityActiveLow; } else { - masterConfig.polarity = kSPI_ClockPolarityActiveHigh; + masterConfig.polarity = kSPI_ClockPolarityActiveHigh; } - masterConfig.txWatermark = kSPI_TxFifo0, - masterConfig.rxWatermark = kSPI_RxFifo1, - - // masterConfig.sselNum = kSPI_Ssel3; - SPI_MasterInit(base, &masterConfig, get_spi_freq(base)); + masterConfig.txWatermark = kSPI_TxFifo0, + masterConfig.rxWatermark = kSPI_RxFifo1, + + // masterConfig.sselNum = kSPI_Ssel3; + SPI_MasterInit(base, &masterConfig, get_spi_freq(base)); - return RT_EOK; + return RT_EOK; } rt_err_t lpc_spi_bus_attach_device(const char *bus_name, const char *device_name, rt_uint32_t pin) { - rt_err_t ret = RT_EOK; - - struct rt_spi_device *spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device)); - RT_ASSERT(spi_device != RT_NULL); - - struct lpc_sw_spi_cs *cs_pin = (struct lpc_sw_spi_cs *)rt_malloc(sizeof(struct lpc_sw_spi_cs)); + rt_err_t ret = RT_EOK; + + struct rt_spi_device *spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device)); + RT_ASSERT(spi_device != RT_NULL); + + struct lpc_sw_spi_cs *cs_pin = (struct lpc_sw_spi_cs *)rt_malloc(sizeof(struct lpc_sw_spi_cs)); RT_ASSERT(cs_pin != RT_NULL); - + cs_pin->pin = pin; - rt_pin_mode(pin, PIN_MODE_OUTPUT); - rt_pin_write(pin, PIN_HIGH); - - ret = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin); - - return ret; + rt_pin_mode(pin, PIN_MODE_OUTPUT); + rt_pin_write(pin, PIN_HIGH); + + ret = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin); + + return ret; } static rt_err_t configure(struct rt_spi_device *device, struct rt_spi_configuration *cfg) { - rt_err_t ret = RT_EOK; - struct lpc_spi *spi = RT_NULL; - + rt_err_t ret = RT_EOK; + struct lpc_spi *spi = RT_NULL; + RT_ASSERT(cfg != RT_NULL); RT_ASSERT(device != RT_NULL); - - spi = (struct lpc_spi *)(device->bus->parent.user_data); - spi->cfg = cfg; - ret = spi_init(spi->base, cfg); - + + spi = (struct lpc_spi *)(device->bus->parent.user_data); + spi->cfg = cfg; + ret = spi_init(spi->base, cfg); + return ret; } static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *message) { - spi_transfer_t transfer = {0}; - + spi_transfer_t transfer = {0}; + RT_ASSERT(device != RT_NULL); RT_ASSERT(device->bus != RT_NULL); RT_ASSERT(device->bus->parent.user_data != RT_NULL); - - struct lpc_spi *spi = (struct lpc_spi *)(device->bus->parent.user_data); - struct lpc_sw_spi_cs *cs = device->parent.user_data; - + + struct lpc_spi *spi = (struct lpc_spi *)(device->bus->parent.user_data); + struct lpc_sw_spi_cs *cs = device->parent.user_data; + if(message->cs_take) { rt_pin_write(cs->pin, PIN_LOW); } - - transfer.dataSize = message->length; - transfer.rxData = (uint8_t *)(message->recv_buf); - transfer.txData = (uint8_t *)(message->send_buf); + + transfer.dataSize = message->length; + transfer.rxData = (uint8_t *)(message->recv_buf); + transfer.txData = (uint8_t *)(message->send_buf); transfer.configFlags |= kSPI_FrameAssert; - - SPI_MasterTransferBlocking(spi->base, &transfer); - + + SPI_MasterTransferBlocking(spi->base, &transfer); + if(message->cs_release) { rt_pin_write(cs->pin, PIN_HIGH); } - - return message->length; + + return message->length; } #if defined(BSP_USING_SPI2) -static struct lpc_spi spi2 = {0}; -static struct rt_spi_bus spi2_bus = {0}; +static struct lpc_spi spi2 = {0}; +static struct rt_spi_bus spi2_bus = {0}; #endif -static struct rt_spi_ops lpc_spi_ops = +static struct rt_spi_ops lpc_spi_ops = { - configure, + configure, spixfer -}; +}; int rt_hw_spi_init(void) { @@ -178,17 +178,17 @@ int rt_hw_spi_init(void) CLOCK_AttachClk(kFRO12M_to_FLEXCOMM2); RESET_PeripheralReset(kFC2_RST_SHIFT_RSTn); - spi2.base = SPI2; - spi2.cfg = RT_NULL; - spi2_bus.parent.user_data = &spi2; - + spi2.base = SPI2; + spi2.cfg = RT_NULL; + spi2_bus.parent.user_data = &spi2; + IOCON_PinMuxSet(IOCON, 0, 8, (IOCON_FUNC1 | IOCON_MODE_PULLUP | IOCON_GPIO_MODE | IOCON_DIGITAL_EN)); /* SPI2_MOSI */ IOCON_PinMuxSet(IOCON, 0, 9, (IOCON_FUNC1 | IOCON_MODE_PULLUP | IOCON_GPIO_MODE | IOCON_DIGITAL_EN)); /* SPI2_MISO */ IOCON_PinMuxSet(IOCON, 0, 10, (IOCON_FUNC1 | IOCON_MODE_PULLUP | IOCON_GPIO_MODE | IOCON_DIGITAL_EN)); /* SPI2_SCK */ - rt_spi_bus_register(&spi2_bus, "spi2", &lpc_spi_ops); + rt_spi_bus_register(&spi2_bus, "spi2", &lpc_spi_ops); #endif - return RT_EOK; + return RT_EOK; } -INIT_BOARD_EXPORT(rt_hw_spi_init); +INIT_BOARD_EXPORT(rt_hw_spi_init); diff --git a/bsp/lpc54114-lite/drivers/drv_spi.h b/bsp/lpc54114-lite/drivers/drv_spi.h index c269cb9892..2938716aa4 100644 --- a/bsp/lpc54114-lite/drivers/drv_spi.h +++ b/bsp/lpc54114-lite/drivers/drv_spi.h @@ -1,21 +1,21 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 */ - -#ifndef __DRV_SPI_H__ -#define __DRV_SPI_H__ -#include -#include +#ifndef __DRV_SPI_H__ +#define __DRV_SPI_H__ + +#include +#include struct lpc_sw_spi_cs { rt_uint32_t pin; -}; +}; int rt_hw_spi_init(void); -rt_err_t lpc_spi_bus_attach_device(const char *bus_name, const char *device_name, rt_uint32_t pin); +rt_err_t lpc_spi_bus_attach_device(const char *bus_name, const char *device_name, rt_uint32_t pin); #endif diff --git a/bsp/lpc54114-lite/drivers/drv_spi_flash.c b/bsp/lpc54114-lite/drivers/drv_spi_flash.c index 65433ce30c..11098636f9 100644 --- a/bsp/lpc54114-lite/drivers/drv_spi_flash.c +++ b/bsp/lpc54114-lite/drivers/drv_spi_flash.c @@ -1,14 +1,14 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 */ - -#include "drv_spi.h" + +#include "drv_spi.h" #include "drv_spi_flash.h" -#include "rtthread.h" -#include "rtdevice.h" +#include "rtthread.h" +#include "rtdevice.h" #include "spi_flash.h" #include "spi_flash_sfud.h" @@ -16,19 +16,19 @@ int rt_hw_flash_init(void) { - rt_err_t result; - - result = lpc_spi_bus_attach_device("spi2", "spi20", RT_SPI_FLASH_CS_PIN); - if(result != RT_EOK) + rt_err_t result; + + result = lpc_spi_bus_attach_device("spi2", "spi20", RT_SPI_FLASH_CS_PIN); + if(result != RT_EOK) { - return result; + return result; } - - if(rt_sfud_flash_probe("flash0", "spi20") == RT_NULL) + + if(rt_sfud_flash_probe("flash0", "spi20") == RT_NULL) { return RT_ERROR; } - return RT_EOK; + return RT_EOK; } -INIT_DEVICE_EXPORT(rt_hw_flash_init); +INIT_DEVICE_EXPORT(rt_hw_flash_init); diff --git a/bsp/lpc54114-lite/drivers/drv_spi_flash.h b/bsp/lpc54114-lite/drivers/drv_spi_flash.h index f3c71e06c2..50b941449e 100644 --- a/bsp/lpc54114-lite/drivers/drv_spi_flash.h +++ b/bsp/lpc54114-lite/drivers/drv_spi_flash.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -10,6 +10,6 @@ #ifndef __DRV_SPI_FLASH_H_ #define __DRV_SPI_FLASH_H_ -int rt_hw_w25qxx_init(void); +int rt_hw_w25qxx_init(void); #endif diff --git a/bsp/lpc54114-lite/drivers/drv_uart.c b/bsp/lpc54114-lite/drivers/drv_uart.c index fc0999d4a4..0ccce7632c 100644 --- a/bsp/lpc54114-lite/drivers/drv_uart.c +++ b/bsp/lpc54114-lite/drivers/drv_uart.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -42,14 +42,14 @@ static rt_err_t lpc_configure(struct rt_serial_device *serial, struct serial_con * config.enableRx = false; */ USART_GetDefaultConfig(&u0_config); - - u0_config.baudRate_Bps = cfg->baud_rate; + + u0_config.baudRate_Bps = cfg->baud_rate; u0_config.parityMode = kUSART_ParityDisabled, u0_config.stopBitCount = kUSART_OneStopBit, u0_config.bitCountPerChar = kUSART_8BitsPerChar, u0_config.loopback = false, u0_config.txWatermark = kUSART_TxFifo0, - u0_config.rxWatermark = kUSART_RxFifo1, + u0_config.rxWatermark = kUSART_RxFifo1, u0_config.enableTx = true; u0_config.enableRx = true; @@ -143,7 +143,7 @@ int rt_hw_uart_init(void) struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; #ifdef BSP_USING_UART0 - + uart = &uart0; serial0.ops = &lpc_uart_ops; @@ -152,40 +152,40 @@ int rt_hw_uart_init(void) /* attach 12 MHz clock to FLEXCOMM0 (debug console) */ CLOCK_AttachClk(kFRO12M_to_FLEXCOMM0); - + /* reset FLEXCOMM for USART */ RESET_PeripheralReset(kFC0_RST_SHIFT_RSTn); - + /* Enables the clock for the IOCON block. 0 = Disable; 1 = Enable.: 0x01u */ CLOCK_EnableClock(kCLOCK_Iocon); - + const uint32_t port0_pin0_config = ((IOCON->PIO[PORT0_IDX][PIN0_IDX] & - (~(IOCON_PIO_FUNC_MASK | IOCON_PIO_DIGIMODE_MASK))) /* Mask bits to zero which are setting */ - | IOCON_PIO_FUNC(1) /* Selects pin function: PORT00 (pin 31) is configured as FC0_RXD_SDA_MOSI. */ - | IOCON_PIO_DIGIMODE(1)); /* Select Analog/Digital mode : Digital mode. */ - + (~(IOCON_PIO_FUNC_MASK | IOCON_PIO_DIGIMODE_MASK))) /* Mask bits to zero which are setting */ + | IOCON_PIO_FUNC(1) /* Selects pin function: PORT00 (pin 31) is configured as FC0_RXD_SDA_MOSI. */ + | IOCON_PIO_DIGIMODE(1)); /* Select Analog/Digital mode : Digital mode. */ + IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN0_IDX, port0_pin0_config); /* PORT0 PIN0 (coords: 31) is configured as FC0_RXD_SDA_MOSI */ - - const uint32_t port0_pin1_config = ((IOCON->PIO[PORT0_IDX][PIN1_IDX] & - (~(IOCON_PIO_FUNC_MASK | IOCON_PIO_DIGIMODE_MASK))) /* Mask bits to zero which are setting */ - | IOCON_PIO_FUNC(1) /* Selects pin function: PORT01 (pin 32) is configured as FC0_TXD_SCL_MISO. */ + + const uint32_t port0_pin1_config = ((IOCON->PIO[PORT0_IDX][PIN1_IDX] & + (~(IOCON_PIO_FUNC_MASK | IOCON_PIO_DIGIMODE_MASK))) /* Mask bits to zero which are setting */ + | IOCON_PIO_FUNC(1) /* Selects pin function: PORT01 (pin 32) is configured as FC0_TXD_SCL_MISO. */ | IOCON_PIO_DIGIMODE(1)); /* Select Analog/Digital mode : Digital mode. */ - + IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN1_IDX, port0_pin1_config); /* PORT0 PIN1 (coords: 32) is configured as FC0_TXD_SCL_MISO */ - + /* Enable RX interrupt. */ USART_EnableInterrupts(uart->UART, kUSART_RxLevelInterruptEnable | kUSART_RxErrorInterruptEnable); EnableIRQ(uart->UART_IRQn); - - CLOCK_DisableClock(kCLOCK_Iocon); - + + CLOCK_DisableClock(kCLOCK_Iocon); + /* register UART0 device */ rt_hw_serial_register(&serial0, "uart0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM, uart); -#endif - +#endif + return 0; } INIT_BOARD_EXPORT(rt_hw_uart_init); diff --git a/bsp/lpc54114-lite/drivers/drv_uart.h b/bsp/lpc54114-lite/drivers/drv_uart.h index e066448d24..1bef2e50a6 100644 --- a/bsp/lpc54114-lite/drivers/drv_uart.h +++ b/bsp/lpc54114-lite/drivers/drv_uart.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -13,4 +13,4 @@ extern int rt_hw_uart_init(void); -#endif +#endif diff --git a/bsp/lpc54608-LPCXpresso/applications/application.c b/bsp/lpc54608-LPCXpresso/applications/application.c index b85de95df6..bfb039472d 100644 --- a/bsp/lpc54608-LPCXpresso/applications/application.c +++ b/bsp/lpc54608-LPCXpresso/applications/application.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -47,10 +47,10 @@ void link_dump(void) extern unsigned int _sbss; extern unsigned int _ebss; - + #define DUMP_VAR(__VAR) \ rt_kprintf("%-20s %p\n", #__VAR, &__VAR) - + DUMP_VAR(_sdata); DUMP_VAR(_edata); DUMP_VAR(_sidata); @@ -62,10 +62,10 @@ void link_dump(void) int rt_application_init(void) { rt_thread_t tid; - + build_dump(); link_dump(); - + tid = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 2048, RT_THREAD_PRIORITY_MAX / 3, 20); diff --git a/bsp/lpc54608-LPCXpresso/applications/mnt.c b/bsp/lpc54608-LPCXpresso/applications/mnt.c index dd1f862ea5..4a865340d9 100644 --- a/bsp/lpc54608-LPCXpresso/applications/mnt.c +++ b/bsp/lpc54608-LPCXpresso/applications/mnt.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -33,7 +33,7 @@ int mnt_init(void) dfs_romfs_init(); /* mount rom file system */ - if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) == 0) + if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) == 0) { rt_kprintf("ROM file system initializated!\n"); } @@ -44,14 +44,14 @@ int mnt_init(void) mci_hw_init("sd0"); #endif -#ifdef RT_DFS_ELM_REENTRANT +#ifdef RT_DFS_ELM_REENTRANT /* mount sd card fat partition 1 as root directory */ if (dfs_mount("sd0", SD_ROOT, "elm", 0, 0) == 0) rt_kprintf("File System initialized!\n"); else rt_kprintf("File System init failed!\n"); #endif - + return 0; } INIT_ENV_EXPORT(mnt_init); diff --git a/bsp/lpc54608-LPCXpresso/applications/startup.c b/bsp/lpc54608-LPCXpresso/applications/startup.c index 687cc0f864..fcd836cdac 100644 --- a/bsp/lpc54608-LPCXpresso/applications/startup.c +++ b/bsp/lpc54608-LPCXpresso/applications/startup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -39,10 +39,10 @@ void rtthread_startup(void) /* initialize scheduler system */ rt_system_scheduler_init(); - + /* initialize system timer*/ rt_system_timer_init(); - + /* initialize application */ rt_application_init(); diff --git a/bsp/lpc54608-LPCXpresso/drivers/board.c b/bsp/lpc54608-LPCXpresso/drivers/board.c index 51c72ec3f5..decd9adfa3 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/board.c +++ b/bsp/lpc54608-LPCXpresso/drivers/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -41,7 +41,7 @@ void rt_hw_board_init() { /* Hardware Initialization */ CLOCK_EnableClock(kCLOCK_InputMux); - CLOCK_EnableClock(kCLOCK_Iocon); + CLOCK_EnableClock(kCLOCK_Iocon); /* NVIC Configuration */ #define NVIC_VTOR_MASK 0x3FFFFF80 @@ -54,15 +54,15 @@ void rt_hw_board_init() #endif BOARD_BootClockFROHF48M(); - /* init systick 1 systick = 1/(100M / 100) 100¸ösystick = 1s*/ + /* init systick 1 systick = 1/(100M / 100) 100个systick = 1s*/ SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); /* set pend exception priority */ NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); /*init uart device*/ rt_hw_uart_init(); - -#ifdef RT_USING_CONSOLE + +#ifdef RT_USING_CONSOLE rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #endif diff --git a/bsp/lpc54608-LPCXpresso/drivers/board.h b/bsp/lpc54608-LPCXpresso/drivers/board.h index 679f33682f..db2ac831c5 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/board.h +++ b/bsp/lpc54608-LPCXpresso/drivers/board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc54608-LPCXpresso/drivers/drt_mpu.c b/bsp/lpc54608-LPCXpresso/drivers/drt_mpu.c index c6c5d114e4..7e220327cb 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/drt_mpu.c +++ b/bsp/lpc54608-LPCXpresso/drivers/drt_mpu.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -26,9 +26,9 @@ int rt_hw_mpu_init(void) { uint32_t rbar; uint32_t rasr; - + MPU_PRINT("\nnumber of regions: %d\n", (MPU->TYPE & MPU_TYPE_DREGION_Msk) >> MPU_TYPE_DREGION_Pos); - + /* Disable MPU */ ARM_MPU_Disable(); diff --git a/bsp/lpc54608-LPCXpresso/drivers/drt_mpu.h b/bsp/lpc54608-LPCXpresso/drivers/drt_mpu.h index ff34c225e7..782f6fce08 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/drt_mpu.h +++ b/bsp/lpc54608-LPCXpresso/drivers/drt_mpu.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc54608-LPCXpresso/drivers/drv_emac.c b/bsp/lpc54608-LPCXpresso/drivers/drv_emac.c index b432aea70e..394ad22cca 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/drv_emac.c +++ b/bsp/lpc54608-LPCXpresso/drivers/drv_emac.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -73,14 +73,14 @@ struct lpc_emac /* inherit from ethernet device */ struct eth_device parent; struct rt_semaphore tx_wait; - + ENET_Type *base; enet_handle_t handle; - + /* interface address info. */ rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* hw address */ uint32_t phyAddr; - + uint8_t RxBuffDescrip[ENET_RXBD_NUM * sizeof(enet_rx_bd_struct_t) + ENET_BUFF_ALIGNMENT]; uint8_t TxBuffDescrip[ENET_TXBD_NUM * sizeof(enet_tx_bd_struct_t) + ENET_BUFF_ALIGNMENT]; uint8_t RxDataBuff[ENET_RXBD_NUM * ENET_ALIGN(ENET_RXBUFF_SIZE) + ENET_BUFF_ALIGNMENT]; @@ -273,7 +273,7 @@ static rt_err_t lpc_emac_phy_init(phy_speed_t * speed, phy_duplex_t * duplex) { bool link = false; int32_t status; - + RT_ASSERT(speed != NULL); RT_ASSERT(duplex != NULL); @@ -284,9 +284,9 @@ static rt_err_t lpc_emac_phy_init(phy_speed_t * speed, phy_duplex_t * duplex) *duplex = kPHY_HalfDuplex; /* 10M speed. */ *speed = kPHY_Speed10M; - + eth_device_linkchange(&lpc_emac_device.parent, RT_FALSE); - + ETH_PRINTF("PHY_Init failed!\n"); return RT_ERROR; } @@ -305,7 +305,7 @@ static rt_err_t lpc_emac_phy_init(phy_speed_t * speed, phy_duplex_t * duplex) } PHY_GetLinkSpeedDuplex(lpc_emac_device.base, lpc_emac_device.phyAddr, speed, duplex); - + eth_device_linkchange(&lpc_emac_device.parent, RT_TRUE); return RT_EOK; @@ -338,19 +338,19 @@ static rt_err_t lpc_emac_init(rt_device_t dev) buffCfg.rxDescTailAddrAlign = get_rx_desc(ENET_RXBD_NUM); buffCfg.rxBufferStartAddr = rxBufferStartAddr; buffCfg.rxBuffSizeAlign = ENET_ALIGN(ENET_RXBUFF_SIZE); - + /* Get default configuration 100M RMII. */ ENET_GetDefaultConfig(&config); /* Use the actual speed and duplex when phy success to finish the autonegotiation. */ config.miiSpeed = (enet_mii_speed_t)speed; config.miiDuplex = (enet_mii_duplex_t)duplex; - + ETH_PRINTF("Auto negotiation, Speed: "); if (config.miiSpeed == kENET_MiiSpeed100M) ETH_PRINTF("100M"); else ETH_PRINTF("10M"); - + ETH_PRINTF(", Duplex: "); if (config.miiSpeed == kENET_MiiSpeed100M) ETH_PRINTF("Full\n"); @@ -363,10 +363,10 @@ static rt_err_t lpc_emac_init(rt_device_t dev) /* Enable the tx/rx interrupt. */ ENET_EnableInterrupts(lpc_emac_device.base, (kENET_DmaTx | kENET_DmaRx)); ENET_CreateHandler(lpc_emac_device.base, &lpc_emac_device.handle, &config, &buffCfg, ethernet_callback, NULL); - + /* Initialize Descriptor. */ ENET_DescriptorInit(lpc_emac_device.base, &config, &buffCfg); - + /* Active TX/RX. */ ENET_StartRxTx(lpc_emac_device.base, 1, 1); @@ -416,23 +416,23 @@ static rt_err_t lpc_emac_control(rt_device_t dev, int cmd, void *args) /* transmit packet. */ rt_err_t lpc_emac_tx(rt_device_t dev, struct pbuf *p) { - rt_err_t result = RT_EOK; - enet_handle_t * enet_handle = &lpc_emac_device.handle; + rt_err_t result = RT_EOK; + enet_handle_t * enet_handle = &lpc_emac_device.handle; ENET_Type *enet_base = lpc_emac_device.base; uint8_t * data; - - uint16_t len; - RT_ASSERT(p != NULL); + uint16_t len; + + RT_ASSERT(p != NULL); RT_ASSERT(enet_handle != RT_NULL); if (p->tot_len > ENET_TXBUFF_SIZE) { return RT_ERROR; } - + packet_dump("TX dump", p); - + /* get free tx buffer */ { rt_err_t result; @@ -442,18 +442,18 @@ rt_err_t lpc_emac_tx(rt_device_t dev, struct pbuf *p) return RT_ERROR; } } - - // fix RxDataBuff -> TxDataBuff, ENET_RXBUFF_SIZE -> ENET_TXBUFF_SIZE + + // fix RxDataBuff -> TxDataBuff, ENET_RXBUFF_SIZE -> ENET_TXBUFF_SIZE data = (uint8_t *)ENET_ALIGN(&lpc_emac_device.TxDataBuff[lpc_emac_device.txIdx * ENET_ALIGN(ENET_TXBUFF_SIZE)]); len = pbuf_copy_partial(p, data, p->tot_len, 0); lpc_emac_device.txIdx = (lpc_emac_device.txIdx + 1) / ENET_TXBD_NUM; - - // fix 'p->len' to 'len', avoid send wrong partial packet. + + // fix 'p->len' to 'len', avoid send wrong partial packet. result = ENET_SendFrame(enet_base, enet_handle, data, len); - + if ((result == kStatus_ENET_TxFrameFail) || (result == kStatus_ENET_TxFrameOverLen) || (result == kStatus_ENET_TxFrameBusy)) { - return RT_ERROR; + return RT_ERROR; } return RT_EOK; @@ -462,22 +462,22 @@ rt_err_t lpc_emac_tx(rt_device_t dev, struct pbuf *p) /* reception packet. */ struct pbuf *lpc_emac_rx(rt_device_t dev) { - uint32_t length = 0; - status_t status; - - struct pbuf* p = RT_NULL; - enet_handle_t * enet_handle = &lpc_emac_device.handle; + uint32_t length = 0; + status_t status; + + struct pbuf* p = RT_NULL; + enet_handle_t * enet_handle = &lpc_emac_device.handle; ENET_Type *enet_base = lpc_emac_device.base; - - /* Get the Frame size */ - status = ENET_GetRxFrameSize(enet_base, enet_handle, &length, 0); - - /* Call ENET_ReadFrame when there is a received frame. */ - if (length != 0) - { - /* Received valid frame. Deliver the rx buffer with the size equal to length. */ - p = pbuf_alloc(PBUF_RAW, length, PBUF_POOL); - + + /* Get the Frame size */ + status = ENET_GetRxFrameSize(enet_base, enet_handle, &length, 0); + + /* Call ENET_ReadFrame when there is a received frame. */ + if (length != 0) + { + /* Received valid frame. Deliver the rx buffer with the size equal to length. */ + p = pbuf_alloc(PBUF_RAW, length, PBUF_POOL); + if (p != NULL) { status = ENET_ReadFrame(enet_base, enet_handle, p->payload, length, 0); @@ -496,12 +496,12 @@ struct pbuf *lpc_emac_rx(rt_device_t dev) { ETH_PRINTF(" pbuf_alloc faild\n"); } - } - else if (status == kStatus_ENET_RxFrameError) - { - ETH_PRINTF("ENET_GetRxFrameSize: kStatus_ENET_RxFrameError\n"); - ENET_ReadFrame(enet_base, enet_handle, NULL, 0, 0); - } + } + else if (status == kStatus_ENET_RxFrameError) + { + ETH_PRINTF("ENET_GetRxFrameSize: kStatus_ENET_RxFrameError\n"); + ENET_ReadFrame(enet_base, enet_handle, NULL, 0, 0); + } return NULL; } @@ -510,11 +510,11 @@ int lpc_emac_hw_init(void) { /* init tx semaphore */ rt_sem_init(&lpc_emac_device.tx_wait, "tx_wait", ENET_TXBD_NUM, RT_IPC_FLAG_FIFO); - + lpc_emac_device.phyAddr = 0; lpc_emac_device.txIdx = 0; lpc_emac_device.base = ENET; - + // OUI 00-60-37 NXP Semiconductors lpc_emac_device.dev_addr[0] = 0x00; lpc_emac_device.dev_addr[1] = 0x60; @@ -536,7 +536,7 @@ int lpc_emac_hw_init(void) lpc_emac_device.parent.eth_tx = lpc_emac_tx; eth_device_init(&(lpc_emac_device.parent), "e0"); - + return 0; } INIT_DEVICE_EXPORT(lpc_emac_hw_init); @@ -546,7 +546,7 @@ int emac_stat(void) { rt_kprintf("enter rx isr coutner : %d\n", isr_rx_counter); rt_kprintf("enter tx isr coutner : %d\n", isr_tx_counter); - + return 0; } #endif @@ -556,14 +556,14 @@ void phy_dump(void) status_t PHY_Read(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, uint32_t *dataPtr); int i; - + for (i = 0; i < 31; i++) { status_t result = kStatus_Success; uint32_t reg; - + result = PHY_Read(lpc_emac_device.base, lpc_emac_device.phyAddr, i, ®); - + if (result == kStatus_Success) { rt_kprintf("%02d: %08d\n", i, reg); @@ -630,7 +630,7 @@ void emac_dump(void) DUMP_REG(DMA_SYSBUS_MODE); DUMP_REG(DMA_INTR_STAT); DUMP_REG(DMA_DBG_STAT); - + DUMP_REG(MTL_QUEUE[0].MTL_TXQX_OP_MODE); DUMP_REG(MTL_QUEUE[0].MTL_TXQX_UNDRFLW); DUMP_REG(MTL_QUEUE[0].MTL_TXQX_DBG); @@ -660,7 +660,7 @@ void emac_dump(void) DUMP_REG(MTL_QUEUE[1].MTL_RXQX_MISSPKT_OVRFLW_CNT); DUMP_REG(MTL_QUEUE[1].MTL_RXQX_DBG); DUMP_REG(MTL_QUEUE[1].MTL_RXQX_CTRL); - + DUMP_REG(DMA_CH[0].DMA_CHX_CTRL); DUMP_REG(DMA_CH[0].DMA_CHX_TX_CTRL); DUMP_REG(DMA_CH[0].DMA_CHX_RX_CTRL); @@ -678,7 +678,7 @@ void emac_dump(void) DUMP_REG(DMA_CH[0].DMA_CHX_CUR_HST_TXBUF); DUMP_REG(DMA_CH[0].DMA_CHX_CUR_HST_RXBUF); DUMP_REG(DMA_CH[0].DMA_CHX_STAT); - + DUMP_REG(DMA_CH[1].DMA_CHX_CTRL); DUMP_REG(DMA_CH[1].DMA_CHX_TX_CTRL); DUMP_REG(DMA_CH[1].DMA_CHX_RX_CTRL); @@ -701,23 +701,23 @@ void emac_dump(void) void emac_bd_dump(void) { int i; - + rt_kprintf("rx bd dump: \n"); for (i = 0; i < ENET_RXBD_NUM; i++) { enet_rx_bd_struct_t * rx_bd = get_rx_desc(i); - rt_kprintf("buf1: %p, buf2: %p, ctrl: %08x\n", - rx_bd->buff1Addr, + rt_kprintf("buf1: %p, buf2: %p, ctrl: %08x\n", + rx_bd->buff1Addr, rx_bd->buff2Addr, rx_bd->control); } - + rt_kprintf("tx bd dump: \n"); for (i = 0; i < ENET_TXBD_NUM; i++) { enet_tx_bd_struct_t * tx_bd = get_tx_desc(i); - rt_kprintf("buf1: %p, buf2: %p, len: %08x, ctrl: %08x\n", - tx_bd->buff1Addr, + rt_kprintf("buf1: %p, buf2: %p, len: %08x, ctrl: %08x\n", + tx_bd->buff1Addr, tx_bd->buff2Addr, tx_bd->buffLen, tx_bd->controlStat); diff --git a/bsp/lpc54608-LPCXpresso/drivers/drv_emac.h b/bsp/lpc54608-LPCXpresso/drivers/drv_emac.h index efaa0ac8e3..cde6d2742e 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/drv_emac.h +++ b/bsp/lpc54608-LPCXpresso/drivers/drv_emac.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc54608-LPCXpresso/drivers/drv_ft5406.c b/bsp/lpc54608-LPCXpresso/drivers/drv_ft5406.c index fd46a199c0..c87d2039f3 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/drv_ft5406.c +++ b/bsp/lpc54608-LPCXpresso/drivers/drv_ft5406.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -7,7 +7,7 @@ * Date Author Notes * 2017-08-08 Yang the first version */ - + #include #include #include diff --git a/bsp/lpc54608-LPCXpresso/drivers/drv_i2c.c b/bsp/lpc54608-LPCXpresso/drivers/drv_i2c.c index 39e08af2d3..1a6b5ff3b8 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/drv_i2c.c +++ b/bsp/lpc54608-LPCXpresso/drivers/drv_i2c.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -7,7 +7,7 @@ * Date Author Notes * 2017-08-08 Yang the first version */ - + #include #include #include "board.h" diff --git a/bsp/lpc54608-LPCXpresso/drivers/drv_lcd.c b/bsp/lpc54608-LPCXpresso/drivers/drv_lcd.c index c1a6660819..260fb09f0e 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/drv_lcd.c +++ b/bsp/lpc54608-LPCXpresso/drivers/drv_lcd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -7,7 +7,7 @@ * Date Author Notes * 2017-08-08 Yang the first version */ - + #include #include #include @@ -427,7 +427,7 @@ void rt_hw_lcd_init(void) _rt_framebuffer = rt_malloc_align(sizeof(rt_uint16_t) * RT_HW_LCD_HEIGHT * RT_HW_LCD_WIDTH, 32); if (_rt_framebuffer == RT_NULL) return; /* no memory yet */ _lcd_info.bits_per_pixel = LCD_BITS_PER_PIXEL; - _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565; // RTGRAPHIC_PIXEL_FORMAT_ARGB888 + _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565; // RTGRAPHIC_PIXEL_FORMAT_ARGB888 _lcd_info.framebuffer = (void *)_rt_framebuffer; _lcd_info.width = RT_HW_LCD_WIDTH; _lcd_info.height = RT_HW_LCD_HEIGHT; diff --git a/bsp/lpc54608-LPCXpresso/drivers/drv_sd.c b/bsp/lpc54608-LPCXpresso/drivers/drv_sd.c index e1239b7899..f5efc2a9d7 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/drv_sd.c +++ b/bsp/lpc54608-LPCXpresso/drivers/drv_sd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -394,22 +394,22 @@ rt_err_t mci_hw_init(const char *device_name) rt_kprintf("SD_Init failed!\n"); return -RT_ERROR; } - - /* - follow the page: https://community.nxp.com/thread/454769 - - The issue concerns sdmmc library bug (I finally solved) in SD_Init() in the file sdmmc/src/fsl_sd.c:SD_SelectBusTiming() - calls SD_SwitchFunction() which sets block size to 64bytes (512bits).Therefore SD_SetBlockSize(card, FSL_SDMMC_DEFAULT_BLOCK_SIZE) - should be called again before SD_Init() exits. - */ - - if (kStatus_Success != SDMMC_SetBlockSize(_mci_device->card.host.base, _mci_device->card.host.transfer, FSL_SDMMC_DEFAULT_BLOCK_SIZE)) - { + + /* + follow the page: https://community.nxp.com/thread/454769 + + The issue concerns sdmmc library bug (I finally solved) in SD_Init() in the file sdmmc/src/fsl_sd.c:SD_SelectBusTiming() + calls SD_SwitchFunction() which sets block size to 64bytes (512bits).Therefore SD_SetBlockSize(card, FSL_SDMMC_DEFAULT_BLOCK_SIZE) + should be called again before SD_Init() exits. + */ + + if (kStatus_Success != SDMMC_SetBlockSize(_mci_device->card.host.base, _mci_device->card.host.transfer, FSL_SDMMC_DEFAULT_BLOCK_SIZE)) + { SD_Deinit(&_mci_device->card); memset(&_mci_device->card, 0U, sizeof(_mci_device->card)); rt_kprintf("SD_Init failed!\n"); - return -RT_ERROR; - } + return -RT_ERROR; + } /* initialize mutex lock */ rt_mutex_init(&_mci_device->lock, device_name, RT_IPC_FLAG_FIFO); diff --git a/bsp/lpc54608-LPCXpresso/drivers/drv_sd.h b/bsp/lpc54608-LPCXpresso/drivers/drv_sd.h index d36134eaa4..1fc53a7459 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/drv_sd.h +++ b/bsp/lpc54608-LPCXpresso/drivers/drv_sd.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -50,7 +50,7 @@ struct mci_device { struct rt_device parent; /**< RT-Thread device struct */ struct rt_device_blk_geometry geometry; /**< sector size, sector count */ - sd_card_t card; /**< Card descriptor */ + sd_card_t card; /**< Card descriptor */ rt_event_t finish_event; /**< data send finish event*/ rt_bool_t data_error; /**< data send error*/ struct rt_mutex lock; diff --git a/bsp/lpc54608-LPCXpresso/drivers/drv_sdram.c b/bsp/lpc54608-LPCXpresso/drivers/drv_sdram.c index 9b6438c4d2..2270e7ed72 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/drv_sdram.c +++ b/bsp/lpc54608-LPCXpresso/drivers/drv_sdram.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -7,7 +7,7 @@ * Date Author Notes * 2017-08-02 Yang the first version */ - + #include "drv_sdram.h" #include @@ -15,10 +15,10 @@ /******************************************************************************************* -* @º¯ÊýÃû£ºsdram_gpio_config() -* @²ÎÊý £ºvoid -* @·µ»ØÖµ£ºvoid -* @ÃèÊö £ºSDRAM¹Ü½ÅÅäÖú¯Êý£¬ÄÚ²¿µ÷Óà +* @函数å:sdram_gpio_config() +* @å‚æ•° :void +* @返回值:void +* @æè¿° :SDRAM管脚é…置函数,内部调用 *********************************************************************************************/ static void sdram_gpio_config(void) { diff --git a/bsp/lpc54608-LPCXpresso/drivers/drv_sdram.h b/bsp/lpc54608-LPCXpresso/drivers/drv_sdram.h index 4de79410b0..1d9a9db4aa 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/drv_sdram.h +++ b/bsp/lpc54608-LPCXpresso/drivers/drv_sdram.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc54608-LPCXpresso/drivers/drv_sram.c b/bsp/lpc54608-LPCXpresso/drivers/drv_sram.c index 81f4ba6e9c..4b27d23fa1 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/drv_sram.c +++ b/bsp/lpc54608-LPCXpresso/drivers/drv_sram.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc54608-LPCXpresso/drivers/drv_sram.h b/bsp/lpc54608-LPCXpresso/drivers/drv_sram.h index 14c87054ff..7abc19420f 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/drv_sram.h +++ b/bsp/lpc54608-LPCXpresso/drivers/drv_sram.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc54608-LPCXpresso/drivers/drv_uart.c b/bsp/lpc54608-LPCXpresso/drivers/drv_uart.c index 7c9bd9fc7f..ce9e48fdad 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/drv_uart.c +++ b/bsp/lpc54608-LPCXpresso/drivers/drv_uart.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -146,7 +146,7 @@ void rt_hw_uart_init(void) struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; #ifdef RT_USING_UART0 - + uart = &uart0; serial0.ops = &lpc_uart_ops; @@ -188,5 +188,5 @@ void rt_hw_uart_init(void) rt_hw_serial_register(&serial0, "uart0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM, uart); -#endif +#endif } diff --git a/bsp/lpc54608-LPCXpresso/drivers/fsl_phy.c b/bsp/lpc54608-LPCXpresso/drivers/fsl_phy.c index 70fa7b3dc8..6a522d7ad7 100644 --- a/bsp/lpc54608-LPCXpresso/drivers/fsl_phy.c +++ b/bsp/lpc54608-LPCXpresso/drivers/fsl_phy.c @@ -87,7 +87,7 @@ status_t PHY_Init(ENET_Type *base, uint32_t phyAddr, uint32_t srcClock_Hz) while ((idReg != PHY_CONTROL_ID1) && (delay != 0)) { PHY_Read(base, phyAddr, PHY_ID1_REG, &idReg); - delay --; + delay --; } if (!delay) @@ -224,7 +224,7 @@ status_t PHY_GetLinkStatus(ENET_Type *base, uint32_t phyAddr, bool *status) else { *status = false; - } + } } return result; } @@ -260,7 +260,7 @@ status_t PHY_GetLinkSpeedDuplex(ENET_Type *base, uint32_t phyAddr, phy_speed_t * else { /* 10M speed. */ *speed = kPHY_Speed10M; - } + } } return result; } diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_adc.c b/bsp/lpc55sxx/Libraries/drivers/drv_adc.c index e1f79c2429..d7d29f0728 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_adc.c +++ b/bsp/lpc55sxx/Libraries/drivers/drv_adc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -34,7 +34,7 @@ static rt_err_t lpc_lpadc_convert(struct rt_adc_device *device, rt_uint32_t chan lpadc_conv_trigger_config_t mLpadcTriggerConfigStruct; lpadc_conv_command_config_t mLpadcCommandConfigStruct; lpadc_conv_result_t mLpadcResultConfigStruct; - + ADC_Type *base; base = (ADC_Type *)(device->parent.user_data); @@ -42,13 +42,13 @@ static rt_err_t lpc_lpadc_convert(struct rt_adc_device *device, rt_uint32_t chan LPADC_GetDefaultConvCommandConfig(&mLpadcCommandConfigStruct); mLpadcCommandConfigStruct.channelNumber = channel; LPADC_SetConvCommandConfig(base, 1U, &mLpadcCommandConfigStruct); - + /* Set trigger configuration. */ LPADC_GetDefaultConvTriggerConfig(&mLpadcTriggerConfigStruct); mLpadcTriggerConfigStruct.targetCommandId = 1U; mLpadcTriggerConfigStruct.enableHardwareTrigger = false; LPADC_SetConvTriggerConfig(base, 0U, &mLpadcTriggerConfigStruct); /* Configurate the trigger0. */ - + LPADC_DoSoftwareTrigger(base, 1U); /* 1U is trigger0 mask. */ while (!LPADC_GetConvResult(base, &mLpadcResultConfigStruct, 0U)); @@ -74,12 +74,12 @@ int rt_hw_adc_init(void) #if defined(BSP_USING_ADC0_CH0) lpadc_config_t mLpadcConfigStruct; - + CLOCK_SetClkDiv(kCLOCK_DivAdcAsyncClk, 16U, true); CLOCK_AttachClk(kMAIN_CLK_to_ADC_CLK); /* Disable LDOGPADC power down */ POWER_DisablePD(kPDRUNCFG_PD_LDOGPADC); - + LPADC_GetDefaultConfig(&mLpadcConfigStruct); mLpadcConfigStruct.enableAnalogPreliminary = true; mLpadcConfigStruct.referenceVoltageSource = kLPADC_ReferenceVoltageAlt2; @@ -91,7 +91,7 @@ int rt_hw_adc_init(void) LPADC_SetOffsetValue(ADC0, 10U, 10U); /* Request gain calibration. */ LPADC_DoAutoCalibration(ADC0); - + result = rt_hw_adc_register(&adc0_device, "adc0", &lpc_adc_ops, ADC0); if (result != RT_EOK) diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_adc.h b/bsp/lpc55sxx/Libraries/drivers/drv_adc.h index 0113b54f3e..412b5f3cd2 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_adc.h +++ b/bsp/lpc55sxx/Libraries/drivers/drv_adc.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_hwtimer.c b/bsp/lpc55sxx/Libraries/drivers/drv_hwtimer.c index bbaf2d6704..6014317b63 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_hwtimer.c +++ b/bsp/lpc55sxx/Libraries/drivers/drv_hwtimer.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -31,15 +31,15 @@ static void NVIC_Configuration(void) #ifdef BSP_USING_CTIMER1 EnableIRQ(CTIMER1_IRQn); #endif - + #ifdef BSP_USING_CTIMER2 EnableIRQ(CTIMER2_IRQn); #endif - + #ifdef BSP_USING_CTIMER3 EnableIRQ(CTIMER3_IRQn); #endif - + #ifdef BSP_USING_CTIMER4 EnableIRQ(CTIMER4_IRQn); #endif @@ -64,9 +64,9 @@ static rt_err_t lpc_ctimer_control(rt_hwtimer_t *timer, rt_uint32_t cmd, void *a if(hwtimer_dev == CTIMER2) clk = CLOCK_GetFreq(kCLOCK_CTimer2); if(hwtimer_dev == CTIMER3) clk = CLOCK_GetFreq(kCLOCK_CTimer3); if(hwtimer_dev == CTIMER4) clk = CLOCK_GetFreq(kCLOCK_CTimer4); - + pre = clk / *((uint32_t *)args) - 1; - + hwtimer_dev->PR = pre; } break; @@ -97,16 +97,16 @@ static void lpc_ctimer_init(rt_hwtimer_t *timer, rt_uint32_t state) hwtimer_dev = (CTIMER_Type *)timer->parent.user_data; RT_ASSERT(timer != RT_NULL); - + /* Use Main clock for some of the Ctimers */ if(hwtimer_dev == CTIMER0) CLOCK_AttachClk(kMAIN_CLK_to_CTIMER0); if(hwtimer_dev == CTIMER1) CLOCK_AttachClk(kMAIN_CLK_to_CTIMER1); if(hwtimer_dev == CTIMER2) CLOCK_AttachClk(kMAIN_CLK_to_CTIMER2); if(hwtimer_dev == CTIMER3) CLOCK_AttachClk(kMAIN_CLK_to_CTIMER3); if(hwtimer_dev == CTIMER4) CLOCK_AttachClk(kMAIN_CLK_to_CTIMER4); - + CTIMER_Deinit(hwtimer_dev); - + if (state == 1) { NVIC_Configuration(); @@ -121,7 +121,7 @@ static rt_err_t lpc_ctimer_start(rt_hwtimer_t *timer, rt_uint32_t cnt, rt_hwtime hwtimer_dev = (CTIMER_Type *)timer->parent.user_data; /* Match Configuration for Channel 0 */ ctimer_match_config_t matchCfg; - + RT_ASSERT(timer != RT_NULL); /* Configuration*/ @@ -131,13 +131,13 @@ static rt_err_t lpc_ctimer_start(rt_hwtimer_t *timer, rt_uint32_t cnt, rt_hwtime matchCfg.outControl = kCTIMER_Output_NoAction; matchCfg.outPinInitState = false; matchCfg.enableInterrupt = true; - + CTIMER_SetupMatch(hwtimer_dev, kCTIMER_Match_1, &matchCfg); - + NVIC_Configuration(); CTIMER_StartTimer(hwtimer_dev); - + return RT_EOK; } @@ -213,7 +213,7 @@ int rt_hw_hwtimer_init(void) LOG_E("CTIMER1 register failed\n"); } #endif - + #ifdef BSP_USING_CTIMER2 CTimer2.info = &lpc_hwtimer_info; CTimer2.ops = &lpc_hwtimer_ops; @@ -224,7 +224,7 @@ int rt_hw_hwtimer_init(void) LOG_E("CTIMER2 register failed\n"); } #endif - + #ifdef BSP_USING_CTIMER3 CTimer3.info = &lpc_hwtimer_info; CTimer3.ops = &lpc_hwtimer_ops; @@ -235,7 +235,7 @@ int rt_hw_hwtimer_init(void) LOG_E("CTIMER3 register failed\n"); } #endif - + #ifdef BSP_USING_CTIMER4 CTimer4.info = &lpc_hwtimer_info; CTimer4.ops = &lpc_hwtimer_ops; @@ -246,7 +246,7 @@ int rt_hw_hwtimer_init(void) LOG_E("CTIMER4 register failed\n"); } #endif - + return ret; } diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_hwtimer.h b/bsp/lpc55sxx/Libraries/drivers/drv_hwtimer.h index 441665c6e8..04d64d79e4 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_hwtimer.h +++ b/bsp/lpc55sxx/Libraries/drivers/drv_hwtimer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_i2c.c b/bsp/lpc55sxx/Libraries/drivers/drv_i2c.c index 45273f1552..53361bdd40 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_i2c.c +++ b/bsp/lpc55sxx/Libraries/drivers/drv_i2c.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -7,7 +7,7 @@ * Date Author Notes * 2019-07-15 Magicoe The first version for LPC55S6x */ - + #include #include #include "board.h" @@ -86,7 +86,7 @@ out: } static const struct rt_i2c_bus_device_ops i2c_ops = -{ +{ lpc_i2c_xfer, RT_NULL, @@ -115,7 +115,7 @@ int rt_hw_i2c_init(void) lpc_i2c1.device_name = "LPC Flexcomm1 as I2C"; rt_i2c_bus_device_register(&lpc_i2c1.parent, "i2c1"); #endif /* BSP_USING_I2C1 */ - + #ifdef BSP_USING_I2C4 static struct lpc_i2c_bus lpc_i2c4; /* attach 12 MHz clock to FLEXCOMM2 (I2C master for touch controller) */ diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_i2c.h b/bsp/lpc55sxx/Libraries/drivers/drv_i2c.h index ac303c7367..87b576f30d 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_i2c.h +++ b/bsp/lpc55sxx/Libraries/drivers/drv_i2c.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -8,12 +8,12 @@ * 2018-03-15 Liuguang the first version. * 2019-07-19 Magicoe The first version for LPC55S6x */ - + #ifndef __DRV_RTC_H__ #define __DRV_RTC_H__ -#include -#include +#include +#include extern int rt_hw_i2c_init(void); diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_key.c b/bsp/lpc55sxx/Libraries/drivers/drv_key.c index 3f8188febe..930c2c706b 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_key.c +++ b/bsp/lpc55sxx/Libraries/drivers/drv_key.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -47,11 +47,11 @@ int my_button_register(struct my_button *button) { rt_pin_mode(button->pin, PIN_MODE_INPUT_PULLDOWN); } - + button->cnt = 0; button->event = BUTTON_EVENT_NONE; button_manage.button_list[button_manage.num++] = button; - + return 0; } @@ -100,7 +100,7 @@ static void my_button_scan(void *param) else if (cnt_old >= MY_BUTTON_HOLD_MS / MY_BUTTON_SCAN_SPACE_MS) /* BUTTON_HOLD_UP */ { LOG_D("BUTTON_HOLD_UP"); - button_manage.button_list[i]->event = BUTTON_EVENT_HOLD_UP; + button_manage.button_list[i]->event = BUTTON_EVENT_HOLD_UP; MY_BUTTON_CALL(button_manage.button_list[i]->cb, (button_manage.button_list[i])); } } @@ -117,7 +117,7 @@ int my_button_start(void) my_button_scan, /* Timeout callback func */ RT_NULL, /* Timeout func entry */ RT_TICK_PER_SECOND * MY_BUTTON_SCAN_SPACE_MS / 1000, - RT_TIMER_FLAG_PERIODIC | RT_TIMER_FLAG_SOFT_TIMER); + RT_TIMER_FLAG_PERIODIC | RT_TIMER_FLAG_SOFT_TIMER); /* Start Timer */ if (button_manage.timer != RT_NULL) rt_timer_start(button_manage.timer); @@ -159,7 +159,7 @@ void key_test(rt_uint32_t led_num, rt_uint32_t value) key.pin = KEY_PIN; my_button_register(&key); - + my_button_start(); } MSH_CMD_EXPORT(key_test, key_test); diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_key.h b/bsp/lpc55sxx/Libraries/drivers/drv_key.h index b0fb9d4095..f8a65370f0 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_key.h +++ b/bsp/lpc55sxx/Libraries/drivers/drv_key.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -7,12 +7,12 @@ * Date Author Notes * 2019-07-19 Magicoe The first version for LPC55S6x, refered github.com/Guozhanxin/RTT-BeepPlayer-pkg */ - + #ifndef __DRV_KEY_H__ #define __DRV_KEY_H__ -#include -#include +#include +#include #define MY_BUTTON_DOWN_MS 50 #define MY_BUTTON_HOLD_MS 700 diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_led.c b/bsp/lpc55sxx/Libraries/drivers/drv_led.c index d7c5a32ef7..922982f654 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_led.c +++ b/bsp/lpc55sxx/Libraries/drivers/drv_led.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_led.h b/bsp/lpc55sxx/Libraries/drivers/drv_led.h index de45db9063..65f55668b6 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_led.h +++ b/bsp/lpc55sxx/Libraries/drivers/drv_led.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -7,12 +7,12 @@ * Date Author Notes * 2019-07-19 Magicoe The first version for LPC55S6x */ - + #ifndef __DRV_LED_H__ #define __DRV_LED_H__ -#include -#include +#include +#include int rt_hw_led_init(void); diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_log.h b/bsp/lpc55sxx/Libraries/drivers/drv_log.h index 7e0bfee5b4..3fe511789b 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_log.h +++ b/bsp/lpc55sxx/Libraries/drivers/drv_log.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_mma8562.c b/bsp/lpc55sxx/Libraries/drivers/drv_mma8562.c index e009c86842..80b3b2671b 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_mma8562.c +++ b/bsp/lpc55sxx/Libraries/drivers/drv_mma8562.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -35,7 +35,7 @@ rt_err_t mma8562_read_reg(rt_uint8_t reg, rt_uint8_t len, rt_uint8_t *buf) struct rt_i2c_msg msgs[2]; msgs[0].addr = kMMA8562_ADDR; - msgs[0].flags = RT_I2C_WR; + msgs[0].flags = RT_I2C_WR; msgs[0].buf = ® msgs[0].len = 1; @@ -60,7 +60,7 @@ rt_err_t mma8562_write_reg(rt_uint8_t reg, rt_uint8_t data) buf[0] = reg; buf[1] = data; - + if (rt_i2c_master_send(mma8562_i2c_bus, kMMA8562_ADDR, 0, buf ,2) == 2) { return RT_EOK; @@ -78,15 +78,15 @@ rt_err_t mma8562_write_reg(rt_uint8_t reg, rt_uint8_t data) void get_mma8562(uint8_t data) { volatile acceleration_t accel; - + uint8_t ucVal1 = 0; uint8_t ucVal2 = 0; uint8_t ucStatus = 0; - + do { mma8562_read_reg(kMMA8562_STATUS, 1, &ucStatus); } while (!(ucStatus & 0x08)); - + mma8562_read_reg(kMMA8562_OUT_X_MSB, 1, &ucVal1); mma8562_read_reg(kMMA8562_OUT_X_LSB, 1, &ucVal2); @@ -150,7 +150,7 @@ int mma8562_hw_init(void) /* databyte = 0x0D; */ val = 0x0D; mma8562_write_reg(kMMA8562_CTRL_REG1, val); - + return 0; } diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_pin.c b/bsp/lpc55sxx/Libraries/drivers/drv_pin.c index 48d26a5825..d38a7ead9a 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_pin.c +++ b/bsp/lpc55sxx/Libraries/drivers/drv_pin.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -83,8 +83,8 @@ static struct lpc_pin lpc_pin_map[] = __LPC55S69_PIN(30, GPIO, 0, 29), /* PIO0_29 */ __LPC55S69_PIN(31, GPIO, 0, 30), /* PIO0_30 */ __LPC55S69_PIN(32, GPIO, 0, 31), /* PIO0_31 */ - - + + /* PIO1 / GPIO, 1 */ __LPC55S69_PIN(33, GPIO, 1, 0), /* PIO1_00 */ __LPC55S69_PIN(34, GPIO, 1, 1), /* PIO1_01 */ @@ -129,7 +129,7 @@ struct rt_pin_irq_hdr pin_irq_hdr_tab[] = {-1, 0, RT_NULL, RT_NULL}, {-1, 0, RT_NULL, RT_NULL}, {-1, 0, RT_NULL, RT_NULL}, - {-1, 0, RT_NULL, RT_NULL}, + {-1, 0, RT_NULL, RT_NULL}, }; static void lpc_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode) @@ -179,15 +179,15 @@ static void lpc_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode) } break; } - + /* Enable IOCON Clock */ CLOCK_EnableClock(kCLOCK_Iocon); - IOCON->PIO[lpc_pin_map[pin].gpio_port][lpc_pin_map[pin].gpio_pin] = pin_cfg; + IOCON->PIO[lpc_pin_map[pin].gpio_port][lpc_pin_map[pin].gpio_pin] = pin_cfg; /* Disable IOCON Clock -- To Save Power */ CLOCK_DisableClock(kCLOCK_Iocon); - + gpio_pin_config_t pin_config = {(gpio_pin_direction_t)dir, 1}; - GPIO_PinInit(GPIO, lpc_pin_map[pin].gpio_port, lpc_pin_map[pin].gpio_pin, &pin_config); + GPIO_PinInit(GPIO, lpc_pin_map[pin].gpio_port, lpc_pin_map[pin].gpio_pin, &pin_config); } @@ -197,20 +197,20 @@ static void lpc_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value) { return; } - + GPIO_PinWrite(lpc_pin_map[pin].gpio, lpc_pin_map[pin].gpio_port, lpc_pin_map[pin].gpio_pin, value); } static int lpc_pin_read(rt_device_t dev, rt_base_t pin) { - int value; + int value; if ((pin > __ARRAY_LEN(lpc_pin_map)) || (pin == 0)) { return RT_ERROR; } value = GPIO_PinRead(lpc_pin_map[pin].gpio, lpc_pin_map[pin].gpio_port, lpc_pin_map[pin].gpio_pin); - + return value; } @@ -225,10 +225,10 @@ static void pin_irq_hdr(pint_pin_int_t pintr, uint32_t pmatch_status) break; } } - + if(irqno >= IRQ_MAX_VAL) return; - + if (pin_irq_hdr_tab[irqno].hdr) { pin_irq_hdr_tab[irqno].hdr(pin_irq_hdr_tab[irqno].args); @@ -250,7 +250,7 @@ void PIN_INT0_IRQHandler(void) pmstatus = PINT_PatternMatchResetDetectLogic(PINT); pin_irq_hdr(kPINT_PinInt0, pmstatus); - + if ((PINT->ISEL & 0x1U) == 0x0U) { /* Edge sensitive: clear Pin interrupt after callback */ @@ -264,8 +264,8 @@ static rt_err_t lpc_pin_attach_irq(struct rt_device *device, void (*hdr)(void *args), void *args) { - int trigger_mode, pin_initx, pintsel, pin_cfg, i; - + int trigger_mode, pin_initx, pintsel, pin_cfg, i; + if ((pin > __ARRAY_LEN(lpc_pin_map)) || (pin == 0)) { return RT_ERROR; @@ -289,10 +289,10 @@ static rt_err_t lpc_pin_attach_irq(struct rt_device *device, trigger_mode = kPINT_PinIntEnableLowLevel; break; } - - /* Get inputmux_connection_t */ + + /* Get inputmux_connection_t */ pintsel = (pin - 1 + (0xC0U << 20)); - + for(i = 0; i < IRQ_MAX_VAL; i++) { if(pin_irq_hdr_tab[i].pin == -1) @@ -308,43 +308,43 @@ static rt_err_t lpc_pin_attach_irq(struct rt_device *device, if(i >= IRQ_MAX_VAL) return RT_ERROR; - + /* Initialize PINT */ PINT_Init(PINT); - + /* Enable Input and IOCon clk */ - /* AttachSignal */ + /* AttachSignal */ /* Connect trigger sources to PINT */ INPUTMUX_Init(INPUTMUX); INPUTMUX_AttachSignal(INPUTMUX, i, (inputmux_connection_t)pintsel); /* Turnoff clock to inputmux to save power. Clock is only needed to make changes */ INPUTMUX_Deinit(INPUTMUX); - + pin_cfg = ((IOCON->PIO[lpc_pin_map[pin].gpio_port][lpc_pin_map[pin].gpio_pin] & (~(IOCON_PIO_FUNC_MASK | IOCON_PIO_DIGIMODE_MASK | IOCON_PIO_FILTEROFF_MASK))) /* Mask bits to zero which are setting */ | IOCON_PIO_FUNC(0) /* Selects pin function.: PORT18 (pin 28) is configured as PIO1_8 */ | IOCON_PIO_DIGIMODE(1) /* Select Analog/Digital mode.: Digital mode. */ | IOCON_PIO_FILTEROFF(0)); /* Controls input glitch filter.: Filter enabled. Noise pulses below approximately 10 ns are filtered out. */ - - IOCON_PinMuxSet(IOCON, lpc_pin_map[pin].gpio_port, lpc_pin_map[pin].gpio_pin, pin_cfg); - + + IOCON_PinMuxSet(IOCON, lpc_pin_map[pin].gpio_port, lpc_pin_map[pin].gpio_pin, pin_cfg); + /* PINT_PinInterruptConfig */ - PINT_PinInterruptConfig(PINT, (pint_pin_int_t)pin_initx, (pint_pin_enable_t)(pin_irq_hdr_tab[i].mode), callback); + PINT_PinInterruptConfig(PINT, (pint_pin_int_t)pin_initx, (pint_pin_enable_t)(pin_irq_hdr_tab[i].mode), callback); /* Enable callbacks for PINTx by Index */ PINT_EnableCallbackByIndex(PINT, (pint_pin_int_t)pin_initx); - + return RT_EOK; } static rt_err_t lpc_pin_detach_irq(struct rt_device *device, rt_int32_t pin) { - int i; + int i; if ((pin > __ARRAY_LEN(lpc_pin_map)) || (pin == 0)) { return RT_ERROR; } - + for(i = 0; i < IRQ_MAX_VAL; i++) { if(pin_irq_hdr_tab[i].pin == pin) @@ -355,19 +355,19 @@ static rt_err_t lpc_pin_detach_irq(struct rt_device *device, rt_int32_t pin) pin_irq_hdr_tab[i].args = RT_NULL; break; } - } + } return RT_EOK; } static rt_err_t lpc_pin_irq_enable(struct rt_device *device, rt_base_t pin, rt_uint32_t enabled) { int irqn_type, i; - + if ((pin > __ARRAY_LEN(lpc_pin_map)) || (pin == 0)) { return RT_ERROR; } - + for(i = 0; i < IRQ_MAX_VAL; i++) { if(pin_irq_hdr_tab[i].pin == pin) @@ -401,8 +401,8 @@ static rt_err_t lpc_pin_irq_enable(struct rt_device *device, rt_base_t pin, rt_u } break; } - } - + } + if(i >= IRQ_MAX_VAL) return RT_ERROR; diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_pin.h b/bsp/lpc55sxx/Libraries/drivers/drv_pin.h index 0c69698e67..21ebf56051 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_pin.h +++ b/bsp/lpc55sxx/Libraries/drivers/drv_pin.h @@ -1,19 +1,19 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes - * 2018-03-13 Liuguang the first version. + * 2018-03-13 Liuguang the first version. * 2018-03-19 Liuguang add GPIO interrupt mode support. * 2019-07-15 Magicoe The first version for LPC55S6x */ - + #ifndef __DRV_PIN_H__ #define __DRV_PIN_H__ -#include +#include #include #define GET_PINS(PORTx, PINx) (32 * PORTx + PINx + 1) /* PORTx:0,1, PINx:0,1...31 */ diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_pwm.c b/bsp/lpc55sxx/Libraries/drivers/drv_pwm.c index 64d6cfd00a..e2fa7f05b6 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_pwm.c +++ b/bsp/lpc55sxx/Libraries/drivers/drv_pwm.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -40,7 +40,7 @@ static struct rt_pwm_ops lpc_drv_ops = static rt_err_t lpc_drv_pwm_enable(struct rt_device_pwm *device, struct rt_pwm_configuration *configuration, rt_bool_t enable) { CTIMER_Type *base; - + base = (CTIMER_Type *)device->parent.user_data; if (!enable) @@ -63,14 +63,14 @@ static rt_err_t lpc_drv_pwm_get(struct rt_device_pwm *device, struct rt_pwm_conf uint32_t get_frequence; uint32_t pwmClock = 0; CTIMER_Type *base; - + base = (CTIMER_Type *)device->parent.user_data; - + #ifdef BSP_USING_CTIMER2 /* get frequence */ pwmClock = CLOCK_GetFreq(kCLOCK_CTimer2) ; #endif - + get_frequence = pwmClock / (base->MR[kCTIMER_Match_3] + 1); if(configuration->channel == 1) @@ -85,7 +85,7 @@ static rt_err_t lpc_drv_pwm_get(struct rt_device_pwm *device, struct rt_pwm_conf configuration->pulse = get_duty * configuration->period / 100; rt_kprintf("*** PWM period %d, pulse %d\r\n", configuration->period, configuration->pulse); - + return RT_EOK; } @@ -97,7 +97,7 @@ static rt_err_t lpc_drv_pwm_set(struct rt_device_pwm *device, struct rt_pwm_conf ctimer_config_t config; CTIMER_Type *base; base = (CTIMER_Type *)device->parent.user_data; - + uint32_t pwmPeriod, pulsePeriod; /* Run as a timer */ config.mode = kCTIMER_TimerMode; @@ -105,7 +105,7 @@ static rt_err_t lpc_drv_pwm_set(struct rt_device_pwm *device, struct rt_pwm_conf config.input = kCTIMER_Capture_0; /* Timer counter is incremented on every APB bus clock */ config.prescale = 0; - + if(configuration->channel == 1) { /* Get the PWM period match value and pulse width match value of DEFAULT_FREQ PWM signal with DEFAULT_DUTY dutycycle */ @@ -159,17 +159,17 @@ int rt_hw_pwm_init(void) static struct rt_device_pwm pwm1_device; ctimer_config_t config; uint32_t pwmPeriod, pulsePeriod; - + /* Use 12 MHz clock for some of the Ctimers */ CLOCK_AttachClk(kMAIN_CLK_to_CTIMER2); - + /* Run as a timer */ config.mode = kCTIMER_TimerMode; /* This field is ignored when mode is timer */ config.input = kCTIMER_Capture_0; /* Timer counter is incremented on every APB bus clock */ config.prescale = 0; - + CTIMER_Init(CTIMER2, &config); #ifdef BSP_USING_CTIMER2_MAT1 @@ -243,7 +243,7 @@ static int pwm_get(int argc, char **argv) result = -RT_EIO; goto _exit; } - + result = rt_pwm_get(device, atoi(argv[2])); _exit: diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_pwm.h b/bsp/lpc55sxx/Libraries/drivers/drv_pwm.h index 7260c0c587..47e50a435b 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_pwm.h +++ b/bsp/lpc55sxx/Libraries/drivers/drv_pwm.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_rtc.c b/bsp/lpc55sxx/Libraries/drivers/drv_rtc.c index c277d82079..fc49389566 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_rtc.c +++ b/bsp/lpc55sxx/Libraries/drivers/drv_rtc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -8,12 +8,12 @@ * 2018-03-15 Liuguang the first version. * 2019-07-19 Magicoe The first version for LPC55S6x */ - + #include #include #include -#include "drv_rtc.h" -#include "fsl_common.h" +#include "drv_rtc.h" +#include "fsl_common.h" #include "fsl_rtc.h" #ifdef RT_USING_RTC @@ -22,21 +22,21 @@ #error "Please don't define 'FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL'!" #endif -static time_t get_timestamp(void) +static time_t get_timestamp(void) { - struct tm tm_new = {0}; - rtc_datetime_t rtcDate; - + struct tm tm_new = {0}; + rtc_datetime_t rtcDate; + /* Get date time */ RTC_GetDatetime(RTC, &rtcDate); - - tm_new.tm_sec = rtcDate.second; - tm_new.tm_min = rtcDate.minute; + + tm_new.tm_sec = rtcDate.second; + tm_new.tm_min = rtcDate.minute; tm_new.tm_hour = rtcDate.hour; - - tm_new.tm_mday = rtcDate.day; - tm_new.tm_mon = rtcDate.month - 1; - tm_new.tm_year = rtcDate.year - 1900; + + tm_new.tm_mday = rtcDate.day; + tm_new.tm_mon = rtcDate.month - 1; + tm_new.tm_year = rtcDate.year - 1900; return timegm(&tm_new); } @@ -44,27 +44,27 @@ static time_t get_timestamp(void) static int set_timestamp(time_t timestamp) { struct tm *p_tm; - rtc_datetime_t rtcDate; - + rtc_datetime_t rtcDate; + p_tm = gmtime(×tamp); - - rtcDate.second = p_tm->tm_sec ; - rtcDate.minute = p_tm->tm_min ; - rtcDate.hour = p_tm->tm_hour; - - rtcDate.day = p_tm->tm_mday; - rtcDate.month = p_tm->tm_mon + 1; - rtcDate.year = p_tm->tm_year + 1900; - + + rtcDate.second = p_tm->tm_sec ; + rtcDate.minute = p_tm->tm_min ; + rtcDate.hour = p_tm->tm_hour; + + rtcDate.day = p_tm->tm_mday; + rtcDate.month = p_tm->tm_mon + 1; + rtcDate.year = p_tm->tm_year + 1900; + /* RTC time counter has to be stopped before setting the date & time in the TSR register */ RTC_StopTimer(RTC); - + /* Set RTC time to default */ RTC_SetDatetime(RTC, &rtcDate); /* Start the RTC time counter */ RTC_StartTimer(RTC); - + return RT_EOK; } @@ -72,83 +72,83 @@ static rt_err_t lpc_rtc_init(rt_device_t dev) { /* Init RTC */ RTC_Init(RTC); - + /* Start the RTC time counter */ RTC_StartTimer(RTC); - - return RT_EOK; + + return RT_EOK; } static rt_err_t lpc_rtc_open(rt_device_t dev, rt_uint16_t oflag) { - return RT_EOK; + return RT_EOK; } -static rt_err_t lpc_rtc_close(rt_device_t dev) +static rt_err_t lpc_rtc_close(rt_device_t dev) { - return RT_EOK; -} + return RT_EOK; +} static rt_size_t lpc_rtc_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) { - return 0; + return 0; } static rt_size_t lpc_rtc_write(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) { - return 0; + return 0; } static rt_err_t lpc_rtc_control(rt_device_t dev, int cmd, void *args) { RT_ASSERT(dev != RT_NULL); - + switch(cmd) { - case RT_DEVICE_CTRL_RTC_GET_TIME: + case RT_DEVICE_CTRL_RTC_GET_TIME: { - *(uint32_t *)args = get_timestamp(); + *(uint32_t *)args = get_timestamp(); } break; - - case RT_DEVICE_CTRL_RTC_SET_TIME: + + case RT_DEVICE_CTRL_RTC_SET_TIME: { - set_timestamp(*(time_t *)args); + set_timestamp(*(time_t *)args); } break; - + default: - return RT_EINVAL; + return RT_EINVAL; } - - return RT_EOK; + + return RT_EOK; } -static struct rt_device device = +static struct rt_device device = { - .type = RT_Device_Class_RTC, - .init = lpc_rtc_init, - .open = lpc_rtc_open, - .close = lpc_rtc_close, + .type = RT_Device_Class_RTC, + .init = lpc_rtc_init, + .open = lpc_rtc_open, + .close = lpc_rtc_close, .read = lpc_rtc_read, .write = lpc_rtc_write, - .control = lpc_rtc_control, + .control = lpc_rtc_control, }; int rt_hw_rtc_init(void) { rt_err_t ret = RT_EOK; - - ret = rt_device_register(&device, "rtc", RT_DEVICE_FLAG_RDWR); + + ret = rt_device_register(&device, "rtc", RT_DEVICE_FLAG_RDWR); if(ret != RT_EOK) { - return ret; + return ret; } - - rt_device_open(&device, RT_DEVICE_OFLAG_RDWR); - - return RT_EOK; + + rt_device_open(&device, RT_DEVICE_OFLAG_RDWR); + + return RT_EOK; } -INIT_DEVICE_EXPORT(rt_hw_rtc_init); +INIT_DEVICE_EXPORT(rt_hw_rtc_init); #endif /*RT_USING_RTC */ diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_rtc.h b/bsp/lpc55sxx/Libraries/drivers/drv_rtc.h index a0623308ad..a905b177ae 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_rtc.h +++ b/bsp/lpc55sxx/Libraries/drivers/drv_rtc.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -8,12 +8,12 @@ * 2018-03-15 Liuguang the first version. * 2019-07-19 Magicoe The first version for LPC55S6x */ - + #ifndef __DRV_RTC_H__ #define __DRV_RTC_H__ -#include -#include +#include +#include int rt_hw_rtc_init(void); diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_sd.c b/bsp/lpc55sxx/Libraries/drivers/drv_sd.c index 66385a7056..597e49aa7b 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_sd.c +++ b/bsp/lpc55sxx/Libraries/drivers/drv_sd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -12,7 +12,7 @@ #include #include -#include "fsl_common.h" +#include "fsl_common.h" #include "fsl_iocon.h" #include "fsl_sdif.h" @@ -177,14 +177,14 @@ int rt_hw_mci_init(void) return -RT_ERROR; } rt_memset(_mci_device, 0, sizeof(struct mci_device)); - + /* attach main clock to SDIF */ CLOCK_AttachClk(kMAIN_CLK_to_SDIO_CLK); /* need call this function to clear the halt bit in clock divider register */ CLOCK_SetClkDiv(kCLOCK_DivSdioClk, (uint32_t)(SystemCoreClock / FSL_FEATURE_SDIF_MAX_SOURCE_CLOCK + 1U), true); _mci_device->card = g_sd; - + /* Save host information. */ _mci_device->card.host.base = SDIF; _mci_device->card.host.sourceClock_Hz = CLOCK_GetFreq(kCLOCK_SDio); @@ -202,14 +202,14 @@ int rt_hw_mci_init(void) /* power off card */ SD_PowerOffCard(_mci_device->card.host.base, _mci_device->card.usrParam.pwr); - + /* check SD card insert */ if(BOARD_SDIF_CD_STATUS() == true) { rt_kprintf("\r\nCard detect fail.\r\n"); return kStatus_Fail; } - + /* wait card insert */ if (SD_WaitCardDetectStatus(_mci_device->card.host.base, &s_sdCardDetect, true) == kStatus_Success) { @@ -223,7 +223,7 @@ int rt_hw_mci_init(void) rt_kprintf("\r\nCard detect fail.\r\n"); return kStatus_Fail; } - + /* Init card. */ if (SD_CardInit(&_mci_device->card)) { diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_sd.h b/bsp/lpc55sxx/Libraries/drivers/drv_sd.h index 125f2b9a47..e604787c16 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_sd.h +++ b/bsp/lpc55sxx/Libraries/drivers/drv_sd.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -18,7 +18,7 @@ struct mci_device { struct rt_device parent; /**< RT-Thread device struct */ struct rt_device_blk_geometry geometry; /**< sector size, sector count */ - sd_card_t card; /**< Card descriptor */ + sd_card_t card; /**< Card descriptor */ rt_event_t finish_event; /**< data send finish event*/ rt_bool_t data_error; /**< data send error*/ struct rt_mutex lock; diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_spi.c b/bsp/lpc55sxx/Libraries/drivers/drv_spi.c index 53c4c3730f..332b20ac5e 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_spi.c +++ b/bsp/lpc55sxx/Libraries/drivers/drv_spi.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -9,7 +9,7 @@ */ #include "drv_spi.h" -#include "fsl_common.h" +#include "fsl_common.h" #include "fsl_iocon.h" #include "fsl_spi.h" @@ -23,7 +23,7 @@ defined(BSP_USING_SPIBUS6) || \ defined(BSP_USING_SPIBUS7) || \ defined(BSP_USING_SPIBUS8) - + #if defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL #error "Please don't define 'FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL'!" #endif @@ -44,14 +44,14 @@ struct lpc_sw_spi_cs static uint32_t lpc_get_spi_freq(SPI_Type *base) { uint32_t freq = 0; - + #if defined(BSP_USING_SPIBUS0) if(base == SPI0) { freq = CLOCK_GetFreq(kCLOCK_Flexcomm0); } -#endif - +#endif + #if defined(BSP_USING_SPIBUS1) if(base == SPI1) { @@ -72,7 +72,7 @@ static uint32_t lpc_get_spi_freq(SPI_Type *base) freq = CLOCK_GetFreq(kCLOCK_Flexcomm3); } #endif - + #if defined(BSP_USING_SPIBUS4) if(base == SPI4) { @@ -116,15 +116,15 @@ static rt_err_t lpc_spi_init(SPI_Type *base, struct rt_spi_configuration *cfg) { spi_master_config_t masterConfig = {0}; - RT_ASSERT(cfg != RT_NULL); + RT_ASSERT(cfg != RT_NULL); if(cfg->data_width != 8 && cfg->data_width != 16) { - return (-RT_EINVAL); + return (-RT_EINVAL); } - - SPI_MasterGetDefaultConfig(&masterConfig); + + SPI_MasterGetDefaultConfig(&masterConfig); #if defined(BSP_USING_SPIBUS8) if(base == SPI8) @@ -140,81 +140,81 @@ static rt_err_t lpc_spi_init(SPI_Type *base, struct rt_spi_configuration *cfg) cfg->max_hz = 12*1000*1000; } #endif - + masterConfig.baudRate_Bps = cfg->max_hz; if(cfg->data_width == 8) { - masterConfig.dataWidth = kSPI_Data8Bits; + masterConfig.dataWidth = kSPI_Data8Bits; } else if(cfg->data_width == 16) { - masterConfig.dataWidth = kSPI_Data16Bits; + masterConfig.dataWidth = kSPI_Data16Bits; } if(cfg->mode & RT_SPI_MSB) { - masterConfig.direction = kSPI_MsbFirst; + masterConfig.direction = kSPI_MsbFirst; } else { - masterConfig.direction = kSPI_LsbFirst; + masterConfig.direction = kSPI_LsbFirst; } if(cfg->mode & RT_SPI_CPHA) { - masterConfig.phase = kSPI_ClockPhaseSecondEdge; + masterConfig.phase = kSPI_ClockPhaseSecondEdge; } else { - masterConfig.phase = kSPI_ClockPhaseFirstEdge; + masterConfig.phase = kSPI_ClockPhaseFirstEdge; } if(cfg->mode & RT_SPI_CPOL) { - masterConfig.polarity = kSPI_ClockPolarityActiveLow; + masterConfig.polarity = kSPI_ClockPolarityActiveLow; } else { - masterConfig.polarity = kSPI_ClockPolarityActiveHigh; + masterConfig.polarity = kSPI_ClockPolarityActiveHigh; } - SPI_MasterInit(base, &masterConfig, lpc_get_spi_freq(base)); + SPI_MasterInit(base, &masterConfig, lpc_get_spi_freq(base)); - return RT_EOK; + return RT_EOK; } rt_err_t lpc_spi_bus_attach_device(const char *bus_name, const char *device_name, rt_uint32_t pin) { - rt_err_t ret = RT_EOK; - - struct rt_spi_device *spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device)); - RT_ASSERT(spi_device != RT_NULL); - - struct lpc_sw_spi_cs *cs_pin = (struct lpc_sw_spi_cs *)rt_malloc(sizeof(struct lpc_sw_spi_cs)); + rt_err_t ret = RT_EOK; + + struct rt_spi_device *spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device)); + RT_ASSERT(spi_device != RT_NULL); + + struct lpc_sw_spi_cs *cs_pin = (struct lpc_sw_spi_cs *)rt_malloc(sizeof(struct lpc_sw_spi_cs)); RT_ASSERT(cs_pin != RT_NULL); - + cs_pin->pin = pin; - rt_pin_mode(pin, PIN_MODE_OUTPUT); - rt_pin_write(pin, PIN_HIGH); - - ret = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin); - - return ret; + rt_pin_mode(pin, PIN_MODE_OUTPUT); + rt_pin_write(pin, PIN_HIGH); + + ret = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin); + + return ret; } static rt_err_t spi_configure(struct rt_spi_device *device, struct rt_spi_configuration *cfg) { - rt_err_t ret = RT_EOK; - struct lpc_spi *spi = RT_NULL; - + rt_err_t ret = RT_EOK; + struct lpc_spi *spi = RT_NULL; + RT_ASSERT(cfg != RT_NULL); RT_ASSERT(device != RT_NULL); - - spi = (struct lpc_spi *)(device->bus->parent.user_data); - spi->cfg = cfg; - ret = lpc_spi_init(spi->base, cfg); - + + spi = (struct lpc_spi *)(device->bus->parent.user_data); + spi->cfg = cfg; + ret = lpc_spi_init(spi->base, cfg); + return ret; } @@ -222,23 +222,23 @@ static rt_err_t spi_configure(struct rt_spi_device *device, struct rt_spi_config static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *message) { uint32_t length; - + RT_ASSERT(device != RT_NULL); RT_ASSERT(device->bus != RT_NULL); RT_ASSERT(device->bus->parent.user_data != RT_NULL); - - struct lpc_spi *spi = (struct lpc_spi *)(device->bus->parent.user_data); - struct lpc_sw_spi_cs *cs = device->parent.user_data; - + + struct lpc_spi *spi = (struct lpc_spi *)(device->bus->parent.user_data); + struct lpc_sw_spi_cs *cs = device->parent.user_data; + if(message->cs_take) { rt_pin_write(cs->pin, PIN_LOW); } - + length = message->length; - const rt_uint8_t *txData = (uint8_t *)(message->send_buf); - rt_uint8_t *rxData = (uint8_t *)(message->recv_buf); - + const rt_uint8_t *txData = (uint8_t *)(message->send_buf); + rt_uint8_t *rxData = (uint8_t *)(message->recv_buf); + rt_kprintf("*** spi send %d\r\n", length); while (length) @@ -257,181 +257,181 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message * } txData += SPISTEP(spi->cfg->data_width);; length--; - } - + } + if(message->cs_release) { rt_pin_write(cs->pin, PIN_HIGH); } - - return (message->length - length); + + return (message->length - length); } #if defined(BSP_USING_SPIBUS0) -static struct lpc_spi spi0 = +static struct lpc_spi spi0 = { .base = SPI0 -}; -static struct rt_spi_bus spi0_bus = +}; +static struct rt_spi_bus spi0_bus = { .parent.user_data = &spi0 -}; +}; #endif #if defined(BSP_USING_SPIBUS1) -static struct lpc_spi spi1 = +static struct lpc_spi spi1 = { .base = SPI1 -}; -static struct rt_spi_bus spi1_bus = +}; +static struct rt_spi_bus spi1_bus = { .parent.user_data = &spi1 -}; +}; #endif #if defined(BSP_USING_SPIBUS2) -static struct lpc_spi spi2 = +static struct lpc_spi spi2 = { .base = SPI2 -}; -static struct rt_spi_bus spi2_bus = +}; +static struct rt_spi_bus spi2_bus = { .parent.user_data = &spi2 -}; +}; #endif #if defined(BSP_USING_SPIBUS3) -static struct lpc_spi spi3 = +static struct lpc_spi spi3 = { .base = SPI3 -}; -static struct rt_spi_bus spi3_bus = +}; +static struct rt_spi_bus spi3_bus = { .parent.user_data = &spi3 -}; +}; #endif #if defined(BSP_USING_SPIBUS4) -static struct lpc_spi spi4 = +static struct lpc_spi spi4 = { .base = SPI4 -}; -static struct rt_spi_bus spi4_bus = +}; +static struct rt_spi_bus spi4_bus = { .parent.user_data = &spi4 -}; +}; #endif #if defined(BSP_USING_SPIBUS5) -static struct lpc_spi spi5 = +static struct lpc_spi spi5 = { .base = SPI5 -}; -static struct rt_spi_bus spi5_bus = +}; +static struct rt_spi_bus spi5_bus = { .parent.user_data = &spi5 -}; +}; #endif #if defined(BSP_USING_SPIBUS6) -static struct lpc_spi spi6 = +static struct lpc_spi spi6 = { .base = SPI6 -}; -static struct rt_spi_bus spi6_bus = +}; +static struct rt_spi_bus spi6_bus = { .parent.user_data = &spi6 -}; +}; #endif #if defined(BSP_USING_SPIBUS7) -static struct lpc_spi spi7 = +static struct lpc_spi spi7 = { .base = SPI7 -}; -static struct rt_spi_bus spi7_bus = +}; +static struct rt_spi_bus spi7_bus = { .parent.user_data = &spi7 -}; +}; #endif #if defined(BSP_USING_SPIBUS8) -static struct lpc_spi spi8 = +static struct lpc_spi spi8 = { .base = SPI8 -}; -static struct rt_spi_bus spi8_bus = +}; +static struct rt_spi_bus spi8_bus = { .parent.user_data = &spi8 -}; +}; #endif -static struct rt_spi_ops lpc_spi_ops = +static struct rt_spi_ops lpc_spi_ops = { - .configure = spi_configure, + .configure = spi_configure, .xfer = spixfer -}; +}; int rt_hw_spi_init(void) { #if defined(BSP_USING_SPIBUS0) CLOCK_AttachClk(kFRO12M_to_FLEXCOMM0); RESET_PeripheralReset(kFC0_RST_SHIFT_RSTn); - spi0.cfg = RT_NULL; - rt_spi_bus_register(&spi0_bus, "spi0", &lpc_spi_ops); + spi0.cfg = RT_NULL; + rt_spi_bus_register(&spi0_bus, "spi0", &lpc_spi_ops); #endif #if defined(BSP_USING_SPIBUS1) CLOCK_AttachClk(kFRO12M_to_FLEXCOMM1); RESET_PeripheralReset(kFC1_RST_SHIFT_RSTn); - spi1.cfg = RT_NULL; - rt_spi_bus_register(&spi1_bus, "spi1", &lpc_spi_ops); + spi1.cfg = RT_NULL; + rt_spi_bus_register(&spi1_bus, "spi1", &lpc_spi_ops); #endif #if defined(BSP_USING_SPIBUS2) CLOCK_AttachClk(kFRO12M_to_FLEXCOMM2); RESET_PeripheralReset(kFC2_RST_SHIFT_RSTn); - spi2.cfg = RT_NULL; - rt_spi_bus_register(&spi2_bus, "spi2", &lpc_spi_ops); + spi2.cfg = RT_NULL; + rt_spi_bus_register(&spi2_bus, "spi2", &lpc_spi_ops); #endif #if defined(BSP_USING_SPIBUS3) CLOCK_AttachClk(kFRO12M_to_FLEXCOMM3); RESET_PeripheralReset(kFC3_RST_SHIFT_RSTn); - spi3.cfg = RT_NULL; - rt_spi_bus_register(&spi3_bus, "spi3", &lpc_spi_ops); + spi3.cfg = RT_NULL; + rt_spi_bus_register(&spi3_bus, "spi3", &lpc_spi_ops); #endif #if defined(BSP_USING_SPIBUS4) CLOCK_AttachClk(kFRO12M_to_FLEXCOMM4); RESET_PeripheralReset(kFC4_RST_SHIFT_RSTn); - spi4.cfg = RT_NULL; - rt_spi_bus_register(&spi4_bus, "spi4", &lpc_spi_ops); + spi4.cfg = RT_NULL; + rt_spi_bus_register(&spi4_bus, "spi4", &lpc_spi_ops); #endif - + #if defined(BSP_USING_SPIBUS5) CLOCK_AttachClk(kFRO12M_to_FLEXCOMM5); RESET_PeripheralReset(kFC5_RST_SHIFT_RSTn); - spi5.cfg = RT_NULL; - rt_spi_bus_register(&spi5_bus, "spi5", &lpc_spi_ops); + spi5.cfg = RT_NULL; + rt_spi_bus_register(&spi5_bus, "spi5", &lpc_spi_ops); #endif #if defined(BSP_USING_SPIBUS6) CLOCK_AttachClk(kFRO12M_to_FLEXCOMM6); RESET_PeripheralReset(kFC6_RST_SHIFT_RSTn); - spi6.cfg = RT_NULL; - rt_spi_bus_register(&spi6_bus, "spi6", &lpc_spi_ops); + spi6.cfg = RT_NULL; + rt_spi_bus_register(&spi6_bus, "spi6", &lpc_spi_ops); #endif #if defined(BSP_USING_SPIBUS7) CLOCK_AttachClk(kFRO12M_to_FLEXCOMM7); RESET_PeripheralReset(kFC7_RST_SHIFT_RSTn); - spi7.cfg = RT_NULL; - rt_spi_bus_register(&spi7_bus, "spi7", &lpc_spi_ops); + spi7.cfg = RT_NULL; + rt_spi_bus_register(&spi7_bus, "spi7", &lpc_spi_ops); #endif - + #if defined(BSP_USING_SPIBUS8) CLOCK_AttachClk(kMAIN_CLK_to_HSLSPI); RESET_PeripheralReset(kHSLSPI_RST_SHIFT_RSTn); @@ -440,7 +440,7 @@ int rt_hw_spi_init(void) rt_spi_bus_register(&spi8_bus, "spi8", &lpc_spi_ops); #endif - return RT_EOK; + return RT_EOK; } INIT_BOARD_EXPORT(rt_hw_spi_init); diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_spi.h b/bsp/lpc55sxx/Libraries/drivers/drv_spi.h index 6aeb91256e..d361637c60 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_spi.h +++ b/bsp/lpc55sxx/Libraries/drivers/drv_spi.h @@ -1,16 +1,16 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 */ - -#ifndef __DRV_SPI_H__ -#define __DRV_SPI_H__ -#include -#include +#ifndef __DRV_SPI_H__ +#define __DRV_SPI_H__ + +#include +#include int rt_hw_spi_init(void); -rt_err_t lpc_spi_bus_attach_device(const char *bus_name, const char *device_name, rt_uint32_t pin); +rt_err_t lpc_spi_bus_attach_device(const char *bus_name, const char *device_name, rt_uint32_t pin); #endif diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_uart.c b/bsp/lpc55sxx/Libraries/drivers/drv_uart.c index d9c325971f..c9bf72eb8d 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_uart.c +++ b/bsp/lpc55sxx/Libraries/drivers/drv_uart.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -40,7 +40,7 @@ struct lpc_uart USART_Type *uart_base; IRQn_Type irqn; clock_name_t clock_src; - + struct rt_serial_device *serial; char *device_name; }; @@ -133,7 +133,7 @@ static const struct lpc_uart uarts[] = USART0, FLEXCOMM0_IRQn, kCLOCK_Flexcomm0, - + &serial0, "uart", }, @@ -143,7 +143,7 @@ static const struct lpc_uart uarts[] = USART1, FLEXCOMM1_IRQn, kCLOCK_Flexcomm1, - + &serial1, "uart1", }, @@ -153,7 +153,7 @@ static const struct lpc_uart uarts[] = USART2, FLEXCOMM2_IRQn, kCLOCK_Flexcomm2, - + &serial2, "uart2", }, @@ -163,7 +163,7 @@ static const struct lpc_uart uarts[] = USART3, FLEXCOMM3_IRQn, kCLOCK_Flexcomm3, - + &serial3, "uart3", }, @@ -173,7 +173,7 @@ static const struct lpc_uart uarts[] = USART4, FLEXCOMM4_IRQn, kCLOCK_Flexcomm4, - + &serial4, "uart4", }, @@ -183,7 +183,7 @@ static const struct lpc_uart uarts[] = USART5, FLEXCOMM5_IRQn, kCLOCK_Flexcomm5, - + &serial5, "uart5", }, @@ -193,7 +193,7 @@ static const struct lpc_uart uarts[] = USART6, FLEXCOMM6_IRQn, kCLOCK_Flexcomm6, - + &serial6, "uart6", }, @@ -203,7 +203,7 @@ static const struct lpc_uart uarts[] = USART7, FLEXCOMM7_IRQn, kCLOCK_Flexcomm7, - + &serial7, "uart7", }, @@ -270,11 +270,11 @@ static rt_err_t lpc_configure(struct rt_serial_device *serial, struct serial_con RT_ASSERT(serial != RT_NULL); RT_ASSERT(cfg != RT_NULL); - + uart = (struct lpc_uart *)serial->parent.user_data; lpc_uart_gpio_init(uart); - + /* * config.baudRate_Bps = 115200U; * config.parityMode = kUSART_ParityDisabled; @@ -285,7 +285,7 @@ static rt_err_t lpc_configure(struct rt_serial_device *serial, struct serial_con */ USART_GetDefaultConfig(&config); config.baudRate_Bps = cfg->baud_rate; - + switch (cfg->data_bits) { case DATA_BITS_7: @@ -296,7 +296,7 @@ static rt_err_t lpc_configure(struct rt_serial_device *serial, struct serial_con config.bitCountPerChar = kUSART_8BitsPerChar; break; } - + switch (cfg->stop_bits) { case STOP_BITS_2: @@ -306,7 +306,7 @@ static rt_err_t lpc_configure(struct rt_serial_device *serial, struct serial_con config.stopBitCount = kUSART_OneStopBit; break; } - + switch (cfg->parity) { case PARITY_ODD: @@ -319,7 +319,7 @@ static rt_err_t lpc_configure(struct rt_serial_device *serial, struct serial_con config.parityMode = kUSART_ParityDisabled; break; } - + config.enableTx = true; config.enableRx = true; @@ -399,7 +399,7 @@ static void uart_isr(struct rt_serial_device *serial) /* UART in mode Receiver -------------------------------------------------*/ rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND); - + /* leave interrupt */ rt_interrupt_leave(); } @@ -416,7 +416,7 @@ int rt_hw_uart_init(void) { struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; int i; - + for (i = 0; i < sizeof(uarts) / sizeof(uarts[0]); i++) { uarts[i].serial->ops = &lpc_uart_ops; diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_uart.h b/bsp/lpc55sxx/Libraries/drivers/drv_uart.h index 603e2a248b..b0dffa8e70 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_uart.h +++ b/bsp/lpc55sxx/Libraries/drivers/drv_uart.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_wdt.c b/bsp/lpc55sxx/Libraries/drivers/drv_wdt.c index 65150a42fb..095c3f0665 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_wdt.c +++ b/bsp/lpc55sxx/Libraries/drivers/drv_wdt.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -43,7 +43,7 @@ static wwdt_config_t WWDT1_config = /* No warning is provided */ .warningValue = 0, /* Set clock frequency. */ - .clockFreq_Hz = 0U, + .clockFreq_Hz = 0U, }; void WDT_BOD_IRQHandler(void) @@ -109,9 +109,9 @@ static rt_err_t lpc_wwdt_init(rt_watchdog_t *wdt) SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_FRO1MHZ_CLK_ENA_MASK; /* Set clock divider for WWDT clock source. */ CLOCK_SetClkDiv(kCLOCK_DivWdtClk, 1U, true); - + WWDT_GetDefaultConfig(&WWDT1_config); - + /* * Set watchdog feed time constant to approximately 4s * Set watchdog warning time to 512 ticks after feed time constant @@ -125,7 +125,7 @@ static rt_err_t lpc_wwdt_init(rt_watchdog_t *wdt) WWDT1_config.enableWatchdogReset = true; /* Setup watchdog clock frequency(Hz). */ WWDT1_config.clockFreq_Hz = CLOCK_GetFreq(kCLOCK_WdtClk); - + WWDT_Init(base, &WWDT1_config); lpc_wwdt_close(wdt); @@ -175,11 +175,11 @@ static rt_err_t lpc_wwdt_control(rt_watchdog_t *wdt, int cmd, void *args) case RT_DEVICE_CTRL_WDT_SET_TIMEOUT: { RT_ASSERT(*(uint16_t *)args != 0); - + WWDT1_config.timeoutValue = (CLOCK_GetFreq(kCLOCK_WdtClk) / 4) * (*(uint16_t *)args) * 2; WWDT1_config.warningValue = 512; WWDT1_config.windowValue = (CLOCK_GetFreq(kCLOCK_WdtClk) / 4) * (*(uint16_t *)args) * 2 / 4; - + base->TC = WWDT_TC_COUNT(WWDT1_config.timeoutValue); base->WINDOW = WWDT_WINDOW_WINDOW(WWDT1_config.windowValue); base->WARNINT = WWDT_WARNINT_WARNINT(WWDT1_config.warningValue); diff --git a/bsp/lpc55sxx/Libraries/drivers/drv_wdt.h b/bsp/lpc55sxx/Libraries/drivers/drv_wdt.h index 2517fb81d9..1b34934cf2 100644 --- a/bsp/lpc55sxx/Libraries/drivers/drv_wdt.h +++ b/bsp/lpc55sxx/Libraries/drivers/drv_wdt.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc55sxx/Libraries/template/lpc55s6xxxx/applications/main.c b/bsp/lpc55sxx/Libraries/template/lpc55s6xxxx/applications/main.c index e03a8c6336..ef4393ba39 100644 --- a/bsp/lpc55sxx/Libraries/template/lpc55s6xxxx/applications/main.c +++ b/bsp/lpc55sxx/Libraries/template/lpc55s6xxxx/applications/main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -27,7 +27,7 @@ int main(void) #elif defined(__GNUC__) rt_kprintf("using gcc, version: %d.%d\n", __GNUC__, __GNUC_MINOR__); #endif - + rt_pin_mode(LEDB_PIN, PIN_MODE_OUTPUT); /* Set GPIO as Output */ while (1) { diff --git a/bsp/lpc55sxx/Libraries/template/lpc55s6xxxx/board/board.c b/bsp/lpc55sxx/Libraries/template/lpc55s6xxxx/board/board.c index 4a7fb3f885..42a08bcb34 100644 --- a/bsp/lpc55sxx/Libraries/template/lpc55s6xxxx/board/board.c +++ b/bsp/lpc55sxx/Libraries/template/lpc55s6xxxx/board/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -41,15 +41,15 @@ void rt_hw_board_init() { /* Hardware Initialization */ BOARD_InitPins(); - + CLOCK_EnableClock(kCLOCK_InputMux); - + CLOCK_EnableClock(kCLOCK_Gpio0); CLOCK_EnableClock(kCLOCK_Gpio1); - + GPIO_PortInit(GPIO, 0); GPIO_PortInit(GPIO, 1); - + /* NVIC Configuration */ #define NVIC_VTOR_MASK 0x3FFFFF80 #ifdef VECT_TAB_RAM @@ -62,16 +62,16 @@ void rt_hw_board_init() BOARD_BootClockPLL150M(); //BOARD_BootClockFROHF96M(); - - /* init systick 1 systick = 1/(100M / 100) 100¸ösystick = 1s*/ + + /* init systick 1 systick = 1/(100M / 100) 100个systick = 1s*/ SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); /* set pend exception priority */ NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); /*init uart device*/ rt_hw_uart_init(); - -#ifdef RT_USING_CONSOLE + +#ifdef RT_USING_CONSOLE rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #endif diff --git a/bsp/lpc55sxx/Libraries/template/lpc55s6xxxx/board/board.h b/bsp/lpc55sxx/Libraries/template/lpc55s6xxxx/board/board.h index f2fce5c093..1899798c13 100644 --- a/bsp/lpc55sxx/Libraries/template/lpc55s6xxxx/board/board.h +++ b/bsp/lpc55sxx/Libraries/template/lpc55s6xxxx/board/board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc55sxx/lpc55s69_nxp_evk/applications/main.c b/bsp/lpc55sxx/lpc55s69_nxp_evk/applications/main.c index e0a2e3171f..64689741de 100644 --- a/bsp/lpc55sxx/lpc55s69_nxp_evk/applications/main.c +++ b/bsp/lpc55sxx/lpc55s69_nxp_evk/applications/main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * Copyright (c) 2019-2020, Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 diff --git a/bsp/lpc55sxx/lpc55s69_nxp_evk/board/board.c b/bsp/lpc55sxx/lpc55s69_nxp_evk/board/board.c index b81bc8e616..0b71b508e7 100644 --- a/bsp/lpc55sxx/lpc55s69_nxp_evk/board/board.c +++ b/bsp/lpc55sxx/lpc55s69_nxp_evk/board/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * Copyright (c) 2019-2020, Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 @@ -43,15 +43,15 @@ void rt_hw_board_init() { /* Hardware Initialization */ BOARD_InitPins(); - + CLOCK_EnableClock(kCLOCK_InputMux); - + CLOCK_EnableClock(kCLOCK_Gpio0); CLOCK_EnableClock(kCLOCK_Gpio1); - + GPIO_PortInit(GPIO, 0); GPIO_PortInit(GPIO, 1); - + /* NVIC Configuration */ #define NVIC_VTOR_MASK 0x3FFFFF80 #ifdef VECT_TAB_RAM @@ -73,16 +73,16 @@ void rt_hw_board_init() BOARD_BootClockPLL150M(); #endif //BOARD_BootClockFROHF96M(); - - /* init systick 1 systick = 1/(100M / 100) 100¸ösystick = 1s*/ + + /* init systick 1 systick = 1/(100M / 100) 100个systick = 1s*/ SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); /* set pend exception priority */ NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); /*init uart device*/ rt_hw_uart_init(); - -#ifdef RT_USING_CONSOLE + +#ifdef RT_USING_CONSOLE rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #endif diff --git a/bsp/lpc55sxx/lpc55s69_nxp_evk/board/board.h b/bsp/lpc55sxx/lpc55s69_nxp_evk/board/board.h index 32afed7da3..d2deccda88 100644 --- a/bsp/lpc55sxx/lpc55s69_nxp_evk/board/board.h +++ b/bsp/lpc55sxx/lpc55s69_nxp_evk/board/board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc824/applications/application.c b/bsp/lpc824/applications/application.c index f8ef7f40e3..ed7972b4d2 100644 --- a/bsp/lpc824/applications/application.c +++ b/bsp/lpc824/applications/application.c @@ -1,12 +1,12 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2009-01-05 Bernard the first version - * 2014-04-27 Bernard make code cleanup. + * 2014-04-27 Bernard make code cleanup. */ #include @@ -29,26 +29,26 @@ static struct rt_thread led_thread; #endif void rt_init_thread_entry(void* parameter) -{ +{ /* initialization RT-Thread Components */ #ifdef RT_USING_COMPONENTS_INIT rt_components_init(); #endif - + } void rt_led_thread_entry(void *parameter) { /* Initialize GPIO */ - Chip_GPIO_Init(LPC_GPIO_PORT); + Chip_GPIO_Init(LPC_GPIO_PORT); Chip_GPIO_PinSetDIR(LPC_GPIO_PORT, 0, 7, 1); Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 7, true); - + while (1) { Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 7, true); rt_thread_delay(RT_TICK_PER_SECOND / 2); - + Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 7, false); rt_thread_delay(RT_TICK_PER_SECOND / 2); } @@ -64,7 +64,7 @@ int rt_application_init() INIT_STACK_SIZE, RT_THREAD_PRIORITY_MAX/3, 20); #else { - + rt_err_t result; tid = &init_thread; @@ -75,14 +75,14 @@ int rt_application_init() #endif if (tid != RT_NULL) rt_thread_startup(tid); - + #ifdef RT_USING_HEAP tid = rt_thread_create("led", rt_led_thread_entry, RT_NULL, LED_STACK_SIZE, RT_THREAD_PRIORITY_MAX/3, 20); #else { - + rt_err_t result; tid = &led_thread; diff --git a/bsp/lpc824/applications/startup.c b/bsp/lpc824/applications/startup.c index e165242f86..d25c76e723 100644 --- a/bsp/lpc824/applications/startup.c +++ b/bsp/lpc824/applications/startup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -58,7 +58,7 @@ void rtthread_startup(void) #ifdef RT_USING_HEAP rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END); #endif - + /* init scheduler system */ rt_system_scheduler_init(); diff --git a/bsp/lpc824/drivers/board.c b/bsp/lpc824/drivers/board.c index 51656718b8..0817a3b7e8 100644 --- a/bsp/lpc824/drivers/board.c +++ b/bsp/lpc824/drivers/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -62,7 +62,7 @@ void rt_hw_board_init() #ifdef RT_USING_COMPONENTS_INIT rt_components_board_init(); #endif - + #ifdef RT_USING_CONSOLE rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #endif diff --git a/bsp/lpc824/drivers/board.h b/bsp/lpc824/drivers/board.h index c8d21d94b5..d86369ce31 100644 --- a/bsp/lpc824/drivers/board.h +++ b/bsp/lpc824/drivers/board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc824/drivers/usart.c b/bsp/lpc824/drivers/usart.c index 5109164a9a..54a56501c9 100644 --- a/bsp/lpc824/drivers/usart.c +++ b/bsp/lpc824/drivers/usart.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -28,7 +28,7 @@ struct lpc8xx_uart LPC_USART_T * uart_base; IRQn_Type uart_irq; rt_uint8_t rx_buffer[UART_RX_BUFSZ]; - + }; #ifdef RT_USING_UART0 struct lpc8xx_uart uart0_device; @@ -45,10 +45,10 @@ struct lpc8xx_uart uart2_device; void uart_irq_handler(struct lpc8xx_uart* uart) { uint32_t status; - + /* enter interrupt */ rt_interrupt_enter(); - + status = Chip_UART_GetStatus(uart->uart_base); if(status & UART_STAT_RXRDY) // RXIRQ { @@ -57,9 +57,9 @@ void uart_irq_handler(struct lpc8xx_uart* uart) if(uart->parent.rx_indicate != RT_NULL) { uart->parent.rx_indicate(&uart->parent, rt_ringbuffer_data_len(&uart->rx_rb)); - } + } } - + /* leave interrupt */ rt_interrupt_leave(); } @@ -88,15 +88,15 @@ void UART2_IRQHandler(void) static void uart1_io_init(LPC_USART_T * uart_base) { /* Enable the clock to the Switch Matrix */ - Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); - + Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); + Chip_Clock_SetUARTClockDiv(1); - + #ifdef RT_USING_UART0 if (uart_base == LPC_USART0) { - Chip_SWM_MovablePinAssign(SWM_U0_TXD_O, 4); - Chip_SWM_MovablePinAssign(SWM_U0_RXD_I, 0); + Chip_SWM_MovablePinAssign(SWM_U0_TXD_O, 4); + Chip_SWM_MovablePinAssign(SWM_U0_RXD_I, 0); } else #endif @@ -104,8 +104,8 @@ static void uart1_io_init(LPC_USART_T * uart_base) #ifdef RT_USING_UART1 if (uart_base == LPC_USART1) { - Chip_SWM_MovablePinAssign(SWM_U1_TXD_O, 4); - Chip_SWM_MovablePinAssign(SWM_U1_RXD_I, 0); + Chip_SWM_MovablePinAssign(SWM_U1_TXD_O, 4); + Chip_SWM_MovablePinAssign(SWM_U1_RXD_I, 0); } else #endif @@ -113,32 +113,32 @@ static void uart1_io_init(LPC_USART_T * uart_base) #ifdef RT_USING_UART2 if (uart_base == LPC_USART2) { - Chip_SWM_MovablePinAssign(SWM_U2_TXD_O, 4); - Chip_SWM_MovablePinAssign(SWM_U2_RXD_I, 0); + Chip_SWM_MovablePinAssign(SWM_U2_TXD_O, 4); + Chip_SWM_MovablePinAssign(SWM_U2_RXD_I, 0); } else #endif { RT_ASSERT((uart_base == USART0) || (uart_base == USART2) || (uart_base == USART2)); } - - /* Disable the clock to the Switch Matrix to save power */ - Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); + + /* Disable the clock to the Switch Matrix to save power */ + Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); } static void uart_ll_init(LPC_USART_T * uart) { Chip_UART_Init(uart); Chip_UART_ConfigData(uart, UART_CFG_DATALEN_8 | UART_CFG_PARITY_NONE | UART_CFG_STOPLEN_1); - Chip_Clock_SetUSARTNBaseClockRate((115200 * 6 * 16), true); - Chip_UART_SetBaud(uart, 115200); - Chip_UART_Enable(uart); - Chip_UART_TXEnable(uart); - - // we must NOT enable TX ready/idle IRQ before we want to write data - // otherwise the IRQs will happen as soon as Uart IRQ is enabled in NVIC - Chip_UART_IntDisable(uart, UART_INTEN_TXRDY | UART_INTEN_TXIDLE); - Chip_UART_IntEnable(uart, UART_INTEN_RXRDY); + Chip_Clock_SetUSARTNBaseClockRate((115200 * 6 * 16), true); + Chip_UART_SetBaud(uart, 115200); + Chip_UART_Enable(uart); + Chip_UART_TXEnable(uart); + + // we must NOT enable TX ready/idle IRQ before we want to write data + // otherwise the IRQs will happen as soon as Uart IRQ is enabled in NVIC + Chip_UART_IntDisable(uart, UART_INTEN_TXRDY | UART_INTEN_TXIDLE); + Chip_UART_IntEnable(uart, UART_INTEN_RXRDY); } static rt_err_t rt_uart_init (rt_device_t dev) @@ -146,7 +146,7 @@ static rt_err_t rt_uart_init (rt_device_t dev) struct lpc8xx_uart* uart; RT_ASSERT(dev != RT_NULL); uart = (struct lpc8xx_uart *)dev; - + uart1_io_init(uart->uart_base); uart_ll_init(uart->uart_base); @@ -220,11 +220,11 @@ static rt_size_t rt_uart_write(rt_device_t dev, rt_off_t pos, const void* buffer if (*ptr == '\n') { while (!(Chip_UART_GetStatus(uart->uart_base) & UART_STAT_TXRDY)); - Chip_UART_SendByte(uart->uart_base, '\r'); + Chip_UART_SendByte(uart->uart_base, '\r'); } while (!(Chip_UART_GetStatus(uart->uart_base) & UART_STAT_TXRDY)); - Chip_UART_SendByte(uart->uart_base, *ptr); + Chip_UART_SendByte(uart->uart_base, *ptr); ptr ++; size --; @@ -235,7 +235,7 @@ static rt_size_t rt_uart_write(rt_device_t dev, rt_off_t pos, const void* buffer while (size) { while (!(Chip_UART_GetStatus(uart->uart_base) & UART_STAT_TXRDY)); - Chip_UART_SendByte(uart->uart_base, *ptr); + Chip_UART_SendByte(uart->uart_base, *ptr); ptr++; size--; @@ -258,14 +258,14 @@ int rt_hw_usart_init(void) uart->parent.type = RT_Device_Class_Char; uart->uart_base = LPC_USART0; uart->uart_irq = UART0_IRQn; - + rt_ringbuffer_init(&(uart->rx_rb), uart->rx_buffer, sizeof(uart->rx_buffer)); /* device interface */ - uart->parent.init = rt_uart_init; - uart->parent.open = rt_uart_open; + uart->parent.init = rt_uart_init; + uart->parent.open = rt_uart_open; uart->parent.close = rt_uart_close; - uart->parent.read = rt_uart_read; + uart->parent.read = rt_uart_read; uart->parent.write = rt_uart_write; uart->parent.control = RT_NULL; uart->parent.user_data = RT_NULL; @@ -273,7 +273,7 @@ int rt_hw_usart_init(void) rt_device_register(&uart->parent, "uart0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX); } #endif - + #ifdef RT_USING_UART1 { struct lpc8xx_uart* uart; @@ -285,14 +285,14 @@ int rt_hw_usart_init(void) uart->parent.type = RT_Device_Class_Char; uart->uart_base = LPC_USART1; uart->uart_irq = UART1_IRQn; - + rt_ringbuffer_init(&(uart->rx_rb), uart->rx_buffer, sizeof(uart->rx_buffer)); /* device interface */ - uart->parent.init = rt_uart_init; - uart->parent.open = rt_uart_open; + uart->parent.init = rt_uart_init; + uart->parent.open = rt_uart_open; uart->parent.close = rt_uart_close; - uart->parent.read = rt_uart_read; + uart->parent.read = rt_uart_read; uart->parent.write = rt_uart_write; uart->parent.control = RT_NULL; uart->parent.user_data = RT_NULL; @@ -315,10 +315,10 @@ int rt_hw_usart_init(void) rt_ringbuffer_init(&(uart->rx_rb), uart->rx_buffer, sizeof(uart->rx_buffer)); /* device interface */ - uart->parent.init = rt_uart_init; - uart->parent.open = rt_uart_open; + uart->parent.init = rt_uart_init; + uart->parent.open = rt_uart_open; uart->parent.close = rt_uart_close; - uart->parent.read = rt_uart_read; + uart->parent.read = rt_uart_read; uart->parent.write = rt_uart_write; uart->parent.control = RT_NULL; uart->parent.user_data = RT_NULL; diff --git a/bsp/lpc824/drivers/usart.h b/bsp/lpc824/drivers/usart.h index 1db28e9385..7298cdab8b 100644 --- a/bsp/lpc824/drivers/usart.h +++ b/bsp/lpc824/drivers/usart.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/bsp/lpc824/rtconfig.h b/bsp/lpc824/rtconfig.h index e8a551c2a3..d7c9608e28 100644 --- a/bsp/lpc824/rtconfig.h +++ b/bsp/lpc824/rtconfig.h @@ -6,17 +6,17 @@ // <<< Use Configuration Wizard in Context Menu >>> // Basic Configuration // Maximal level of thread priority <8-256> -// Default: 32 +// Default: 32 #define RT_THREAD_PRIORITY_MAX 8 // OS tick per second // Default: 1000 (1ms) -#define RT_TICK_PER_SECOND 100 +#define RT_TICK_PER_SECOND 100 // Alignment size for CPU architecture data access -// Default: 4 +// Default: 4 #define RT_ALIGN_SIZE 4 // the max length of object name<2-16> -// Default: 8 -#define RT_NAME_MAX 8 +// Default: 8 +#define RT_NAME_MAX 8 // Using RT-Thread components initialization // Using RT-Thread components initialization #define RT_USING_COMPONENTS_INIT @@ -26,7 +26,7 @@ //#define RT_USING_USER_MAIN // // the size of main thread<1-4086> -// Default: 512 +// Default: 512 #define RT_MAIN_THREAD_STACK_SIZE 256 // @@ -64,13 +64,13 @@ #endif // The priority level of timer thread <0-31> // Default: 4 -#define RT_TIMER_THREAD_PRIO 4 +#define RT_TIMER_THREAD_PRIO 4 // The stack size of timer thread <0-8192> // Default: 512 -#define RT_TIMER_THREAD_STACK_SIZE 512 +#define RT_TIMER_THREAD_STACK_SIZE 512 // The soft-timer tick per second <0-1000> // Default: 100 -#define RT_TIMER_TICK_PER_SECOND 100 +#define RT_TIMER_TICK_PER_SECOND 100 // // IPC(Inter-process communication) Configuration @@ -164,7 +164,7 @@ // the history lines of finsh thread <1-32> // the history lines of finsh thread // Default: 5 -#define FINSH_HISTORY_LINES 1 +#define FINSH_HISTORY_LINES 1 // Using symbol table in finsh shell // Using symbol table in finsh shell #define FINSH_USING_SYMTAB -- GitLab