[mb9bf568r] 手动-自动格式整理
This commit is contained in:
parent
061182271f
commit
6ca82399f4
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
此demo用于演示动态线程创建
|
||||
*/
|
||||
#include <rtthread.h>
|
||||
#include "board.h"
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
#include <finsh.h>
|
||||
#include <shell.h>
|
||||
#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;
|
||||
}
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#include <rtthread.h>
|
||||
#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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
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;
|
||||
/* 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);
|
||||
|
|
Loading…
Reference in New Issue