From 6ca82399f4a0655ca3ebbe4cafe73921721fd092 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 22 Mar 2021 00:00:13 +0800 Subject: [PATCH] =?UTF-8?q?[mb9bf568r]=20=E6=89=8B=E5=8A=A8-=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=A0=BC=E5=BC=8F=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/mb9bf568r/applications/application.c | 12 ++--- bsp/mb9bf568r/applications/demo.c | 69 ------------------------ bsp/mb9bf568r/applications/startup.c | 10 ++-- bsp/mb9bf568r/drivers/board.c | 10 ++-- bsp/mb9bf568r/drivers/board.h | 8 +-- bsp/mb9bf568r/drivers/led.c | 26 +++++---- bsp/mb9bf568r/drivers/mcu.h | 8 +-- bsp/mb9bf568r/drivers/serial.c | 54 +++++++++---------- bsp/mb9bf568r/drivers/serial.h | 42 +++++++-------- 9 files changed, 77 insertions(+), 162 deletions(-) delete mode 100644 bsp/mb9bf568r/applications/demo.c diff --git a/bsp/mb9bf568r/applications/application.c b/bsp/mb9bf568r/applications/application.c index 462207672e..17a6707814 100644 --- a/bsp/mb9bf568r/applications/application.c +++ b/bsp/mb9bf568r/applications/application.c @@ -1,11 +1,7 @@ /* - * File : application.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2009 - 2011, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE + * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes @@ -28,7 +24,7 @@ void rt_init_thread_entry(void *parameter) #endif - //finsh_system_init(); + //finsh_system_init(); finsh_set_device(RT_CONSOLE_DEVICE_NAME); @@ -37,7 +33,7 @@ void rt_init_thread_entry(void *parameter) extern void rt_led_hw_init(void); rt_led_hw_init(); } - { + { extern int demo_init(void); demo_init(); } diff --git a/bsp/mb9bf568r/applications/demo.c b/bsp/mb9bf568r/applications/demo.c deleted file mode 100644 index d43ce2f5a4..0000000000 --- a/bsp/mb9bf568r/applications/demo.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - 此demo用于演示动态线程创建 - */ -#include -#include "board.h" - -#ifdef RT_USING_FINSH -#include -#include -#endif - - -static rt_thread_t tid1 = RT_NULL; -static rt_thread_t tid2 = RT_NULL; - - -static void thread1_entry(void* parameter) -{ - rt_uint32_t count = 0; - - rt_kprintf("thread1 dynamicly created ok\n"); - while (1) - { - rt_kprintf("thread1 count: %d\n",count++); - rt_thread_delay(RT_TICK_PER_SECOND); - } -} - -static void thread2_entry(void* parameter) -{ - rt_uint32_t count = 0; - rt_kprintf("thread2 dynamicly created ok\n"); - - while(1) - { - if(count == 3) - break; - rt_kprintf("thread2 count: %d\n",count++); - rt_thread_delay(RT_TICK_PER_SECOND); - - } - rt_thread_delay(RT_TICK_PER_SECOND * 4); - - rt_thread_delete(tid1); - rt_kprintf("thread1 deleted ok\n"); -} - - -int demo_init(void) -{ - - tid1 = rt_thread_create("thread1", - thread1_entry, - RT_NULL, - 512, 6, 10); - - if (tid1 != RT_NULL) - rt_thread_startup(tid1); - - tid2 = rt_thread_create("thread2", - thread2_entry, - RT_NULL, - 512, 6, 10); - - if (tid2 != RT_NULL) - rt_thread_startup(tid2); - - return 0; -} diff --git a/bsp/mb9bf568r/applications/startup.c b/bsp/mb9bf568r/applications/startup.c index 1ad95dbce8..263bd20a28 100644 --- a/bsp/mb9bf568r/applications/startup.c +++ b/bsp/mb9bf568r/applications/startup.c @@ -1,11 +1,7 @@ /* - * File : startup.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2009 - 2011, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE + * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes @@ -43,7 +39,7 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - + /* init timer system */ rt_system_timer_init(); diff --git a/bsp/mb9bf568r/drivers/board.c b/bsp/mb9bf568r/drivers/board.c index 2dbc219f28..bd44ad80b1 100644 --- a/bsp/mb9bf568r/drivers/board.c +++ b/bsp/mb9bf568r/drivers/board.c @@ -1,11 +1,7 @@ /* - * File : board.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2009 - 2011 RT-Thread Develop Team + * Copyright (c) 2006-2021, RT-Thread Development Team * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE + * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes @@ -64,7 +60,7 @@ rt_uint32_t rt_hw_tick_get_microsecond(void) rt_tick_t tick; rt_uint32_t value; -#define TICK_US (1000000/RT_TICK_PER_SECOND) +#define TICK_US (1000000/RT_TICK_PER_SECOND) tick = rt_tick_get(); value = tick * TICK_US + (SysTick->LOAD - SysTick->VAL) * TICK_US / SysTick->LOAD; diff --git a/bsp/mb9bf568r/drivers/board.h b/bsp/mb9bf568r/drivers/board.h index 1b784810bf..ed258f82a0 100644 --- a/bsp/mb9bf568r/drivers/board.h +++ b/bsp/mb9bf568r/drivers/board.h @@ -1,11 +1,7 @@ /* - * File : board.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2009, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE + * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes diff --git a/bsp/mb9bf568r/drivers/led.c b/bsp/mb9bf568r/drivers/led.c index 20e015cdc9..db80b56fd0 100644 --- a/bsp/mb9bf568r/drivers/led.c +++ b/bsp/mb9bf568r/drivers/led.c @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ #include #include "board.h" @@ -28,9 +36,9 @@ static rt_err_t rt_led_init (rt_device_t dev) /* led0-1-2 : P27-P38-PE0 */ FM4_GPIO->PFR2 &= ~((1<<7) ); /* set P27 fuction is GPIO. */ FM4_GPIO->DDR2 |= (1<<7) ; /* set P27 output. */ - FM4_GPIO->PFR3 &= ~((1<<8) ); /* set P38 fuction is GPIO. */ + FM4_GPIO->PFR3 &= ~((1<<8) ); /* set P38 fuction is GPIO. */ FM4_GPIO->DDR3 |= (1<<8) ; /* set P38 output. */ - FM4_GPIO->PFRE &= ~((1<<0) ); /* set PE0 fuction is GPIO. */ + FM4_GPIO->PFRE &= ~((1<<0) ); /* set PE0 fuction is GPIO. */ FM4_GPIO->DDRE |= (1<<0) ; /* set PE0 output. */ /* LED0 */ @@ -127,16 +135,16 @@ static rt_err_t rt_led_control (rt_device_t dev, int cmd, void *args) void rt_led_hw_init(void) { - fm4_led.parent.type = RT_Device_Class_Char; + fm4_led.parent.type = RT_Device_Class_Char; fm4_led.parent.rx_indicate = RT_NULL; fm4_led.parent.tx_complete = RT_NULL; - fm4_led.parent.init = rt_led_init; - fm4_led.parent.open = rt_led_open; - fm4_led.parent.close = rt_led_close; + fm4_led.parent.init = rt_led_init; + fm4_led.parent.open = rt_led_open; + fm4_led.parent.close = rt_led_close; fm4_led.parent.read = rt_led_read; - fm4_led.parent.write = rt_led_write; - fm4_led.parent.control = rt_led_control; - fm4_led.parent.user_data = RT_NULL; + fm4_led.parent.write = rt_led_write; + fm4_led.parent.control = rt_led_control; + fm4_led.parent.user_data = RT_NULL; /* register a character device */ rt_device_register(&fm4_led.parent, "led", RT_DEVICE_FLAG_RDWR); diff --git a/bsp/mb9bf568r/drivers/mcu.h b/bsp/mb9bf568r/drivers/mcu.h index 6ee4e1fe7e..5717ff37cc 100644 --- a/bsp/mb9bf568r/drivers/mcu.h +++ b/bsp/mb9bf568r/drivers/mcu.h @@ -41,8 +41,8 @@ ** ******************************************************************************/ -#define PDL_INT_TYPE_C 1 -#define PDL_INT_TYPE_A 2 +#define PDL_INT_TYPE_C 1 +#define PDL_INT_TYPE_A 2 #define PDL_MCU_INT_TYPE PDL_INT_TYPE_A @@ -50,7 +50,7 @@ ****************************************************************************** ** \brief MCU header file include ** - ******************************************************************************/ + ******************************************************************************/ #ifndef _MB9B560R_H_ #include "mb9b560r.h" #endif @@ -59,7 +59,7 @@ ****************************************************************************** ** \brief MCU system start-up header file include ** - ******************************************************************************/ + ******************************************************************************/ #ifndef _SYSTEM_MB9ABXXX_H_ #include "system_mb9bf56xr.h" #endif diff --git a/bsp/mb9bf568r/drivers/serial.c b/bsp/mb9bf568r/drivers/serial.c index b4d42d510b..6c3a132216 100644 --- a/bsp/mb9bf568r/drivers/serial.c +++ b/bsp/mb9bf568r/drivers/serial.c @@ -1,11 +1,7 @@ /* - * File : serial.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE + * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes @@ -258,16 +254,16 @@ rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, { RT_ASSERT(device != RT_NULL); - device->type = RT_Device_Class_Char; + device->type = RT_Device_Class_Char; device->rx_indicate = RT_NULL; device->tx_complete = RT_NULL; - device->init = rt_serial_init; - device->open = rt_serial_open; - device->close = rt_serial_close; - device->read = rt_serial_read; - device->write = rt_serial_write; - device->control = rt_serial_control; - device->user_data = serial; + device->init = rt_serial_init; + device->open = rt_serial_open; + device->close = rt_serial_close; + device->read = rt_serial_read; + device->write = rt_serial_write; + device->control = rt_serial_control; + device->user_data = serial; /* register a character device */ return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR | flag); @@ -303,7 +299,7 @@ void rt_hw_serial_isr(rt_device_t device) #ifdef RT_USING_UART0 /* UART0 device driver structure */ -#define UART0 FM4_MFS0 +#define UART0 FM4_MFS0 struct serial_int_rx uart0_int_rx; struct serial_device uart0 = { @@ -316,8 +312,8 @@ struct serial_device uart0 = struct rt_device uart0_device; void MFS0_RX_IRQHandler(void) -{ - /* enter interrupt */ +{ + /* enter interrupt */ rt_interrupt_enter(); rt_hw_serial_isr(&uart0_device); /* leave interrupt */ @@ -330,28 +326,28 @@ void MFS0_RX_IRQHandler(void) void rt_hw_serial_init(void) { - uint32_t APB2_clock = (SystemCoreClock >> (APBC2_PSR_Val & 0x03)); - + uint32_t APB2_clock = (SystemCoreClock >> (APBC2_PSR_Val & 0x03)); + #ifdef RT_USING_UART0 // Initialize ports for MFS0 - FM4_GPIO->PFR2 = 0x06u; // P21>SIN0_0, P22>SOT0_0 - FM4_GPIO->EPFR07 &= 0xFFFFFF0Ful; - FM4_GPIO->EPFR07 |= 0x00000040ul; - - // Initialize MFS to UART asynchronous mode - - uart0.uart_device->SMR = SMR_MD_UART | SMR_SOE;; + FM4_GPIO->PFR2 = 0x06u; // P21>SIN0_0, P22>SOT0_0 + FM4_GPIO->EPFR07 &= 0xFFFFFF0Ful; + FM4_GPIO->EPFR07 |= 0x00000040ul; + + // Initialize MFS to UART asynchronous mode + + uart0.uart_device->SMR = SMR_MD_UART | SMR_SOE;; uart0.uart_device->BGR = (APB2_clock + (BPS/2))/BPS - 1; /* round */ uart0.uart_device->ESCR = ESCR_DATABITS_8; uart0.uart_device->SCR = SCR_RXE | SCR_TXE | SCR_RIE; - + /* register UART0 device */ rt_hw_serial_register(&uart0_device, "uart0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM, &uart0); - - + + #endif /**< #ifdef RT_USING_UART0 */ } diff --git a/bsp/mb9bf568r/drivers/serial.h b/bsp/mb9bf568r/drivers/serial.h index b057a811dd..776b2a3877 100644 --- a/bsp/mb9bf568r/drivers/serial.h +++ b/bsp/mb9bf568r/drivers/serial.h @@ -1,16 +1,12 @@ /* - * File : serial.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE + * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2006-03-13 Bernard first version - * 2011-05-15 lgnq modified according bernard's implementaion. + * 2011-05-15 lgnq modified according bernard's implementaion. */ #ifndef __RT_HW_SERIAL_H__ @@ -57,21 +53,21 @@ #define ESCR_DATABITS_7 0x03U #define ESCR_DATABITS_9 0x04U -#define BPS 115200 /* serial baudrate */ +#define BPS 115200 /* serial baudrate */ -#define UART_RX_BUFFER_SIZE 128 -#define UART_TX_BUFFER_SIZE 128 +#define UART_RX_BUFFER_SIZE 128 +#define UART_TX_BUFFER_SIZE 128 struct serial_int_rx { - rt_uint8_t rx_buffer[UART_RX_BUFFER_SIZE]; - rt_uint32_t read_index, save_index; + rt_uint8_t rx_buffer[UART_RX_BUFFER_SIZE]; + rt_uint32_t read_index, save_index; }; struct serial_int_tx { - rt_uint8_t tx_buffer[UART_TX_BUFFER_SIZE]; - rt_uint32_t write_index, save_index; + rt_uint8_t tx_buffer[UART_TX_BUFFER_SIZE]; + rt_uint32_t write_index, save_index; }; /* @@ -83,15 +79,15 @@ struct serial_int_tx struct serial_device { - FM4_MFS_TypeDef* uart_device; - /* irq number */ - IRQn_Type rx_irq; - IRQn_Type tx_irq; - - /* rx structure */ - struct serial_int_rx* int_rx; - /* tx structure */ - struct serial_int_tx* int_tx; + FM4_MFS_TypeDef* uart_device; + /* irq number */ + IRQn_Type rx_irq; + IRQn_Type tx_irq; + + /* rx structure */ + struct serial_int_rx* int_rx; + /* tx structure */ + struct serial_int_tx* int_tx; }; void rt_hw_serial_isr(rt_device_t device); -- GitLab