mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-01 02:40:12 +08:00
Merge pull request #4498 from mysterywolf/mb9bf500r
[mb9bf500r] manual & auto formatted
This commit is contained in:
17 files changed
+950
-976
No files matched your search
+49
-53
@@ -1,17 +1,13 @@
|
||||
/*
|
||||
* File : adc.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 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
|
||||
* 2011-03-03 lgnq
|
||||
* 2011-03-03 lgnq First version
|
||||
*/
|
||||
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
#include "mb9bf506r.h"
|
||||
@@ -33,45 +29,45 @@ static rt_err_t rt_adc_init(rt_device_t dev)
|
||||
|
||||
if(!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
|
||||
{
|
||||
/* I/O setting AN08 - P18 */
|
||||
/* I/O setting AN08 - P18 */
|
||||
FM3_GPIO->ADE |= 0x100;
|
||||
FM3_GPIO->PFR1 = 0x100;
|
||||
|
||||
/* A/DC setting */
|
||||
FM3_ADC0->SCIS1 = 0x01;
|
||||
FM3_ADC0->ADSS1 = 0x00; /* sampling timming ADST0 */
|
||||
FM3_ADC0->ADST1 = 0x43;
|
||||
FM3_ADC0->ADCT = 0x02;
|
||||
FM3_ADC0->SCCR = 0x10; /* FIFO clear,single mode */
|
||||
FM3_ADC0->CMPCR = 0x00; /* disable comparator */
|
||||
|
||||
/* starting A/DC */
|
||||
FM3_ADC0->SCCR |= 0x01; /* A/DC start */
|
||||
|
||||
FM3_GPIO->PFR1 = 0x100;
|
||||
|
||||
/* A/DC setting */
|
||||
FM3_ADC0->SCIS1 = 0x01;
|
||||
FM3_ADC0->ADSS1 = 0x00; /* sampling timming ADST0 */
|
||||
FM3_ADC0->ADST1 = 0x43;
|
||||
FM3_ADC0->ADCT = 0x02;
|
||||
FM3_ADC0->SCCR = 0x10; /* FIFO clear,single mode */
|
||||
FM3_ADC0->CMPCR = 0x00; /* disable comparator */
|
||||
|
||||
/* starting A/DC */
|
||||
FM3_ADC0->SCCR |= 0x01; /* A/DC start */
|
||||
|
||||
dev->flag |= RT_DEVICE_FLAG_ACTIVATED;
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t rt_adc_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case RT_DEVICE_CTRL_ADC_START:
|
||||
switch (cmd)
|
||||
{
|
||||
case RT_DEVICE_CTRL_ADC_START:
|
||||
FM3_ADC0->SCCR |= 0x1;
|
||||
break;
|
||||
|
||||
case RT_DEVICE_CTRL_ADC_RESULT:
|
||||
break;
|
||||
|
||||
case RT_DEVICE_CTRL_ADC_RESULT:
|
||||
while(FM3_ADC0->ADSR & 0x1)
|
||||
;
|
||||
*((rt_uint16_t*)args) = FM3_ADC0->SCFD;
|
||||
*((rt_uint16_t*)args) = *((rt_uint16_t*)args) >> 6;
|
||||
*((rt_uint16_t*)args) = (*((rt_uint16_t*)args)*3300)/1024;
|
||||
break;
|
||||
}
|
||||
return RT_EOK;
|
||||
break;
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
extern struct rt_messagequeue mq;
|
||||
@@ -80,29 +76,29 @@ rt_uint16_t adc_value;
|
||||
static void adc_thread_entry(void *parameter)
|
||||
{
|
||||
rt_device_t device;
|
||||
|
||||
|
||||
#ifdef RT_USING_RTGUI
|
||||
struct rtgui_event_command ecmd;
|
||||
|
||||
|
||||
RTGUI_EVENT_COMMAND_INIT(&ecmd);
|
||||
ecmd.type = RTGUI_CMD_USER_INT;
|
||||
ecmd.command_id = ADC_UPDATE;
|
||||
#else
|
||||
struct lcd_msg msg;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
device = rt_device_find("adc");
|
||||
|
||||
while(1)
|
||||
{
|
||||
rt_device_control(device, RT_DEVICE_CTRL_ADC_START, RT_NULL);
|
||||
rt_device_control(device, RT_DEVICE_CTRL_ADC_START, RT_NULL);
|
||||
rt_device_control(device, RT_DEVICE_CTRL_ADC_RESULT, &adc_value);
|
||||
pwm_update(adc_value/3);
|
||||
#ifdef RT_USING_RTGUI
|
||||
rtgui_thread_send(info_tid, &ecmd.parent, sizeof(ecmd));
|
||||
#else
|
||||
msg.type = ADC_MSG;
|
||||
msg.adc_value = adc_value;
|
||||
msg.adc_value = adc_value;
|
||||
rt_mq_send(&mq, &msg, sizeof(msg));
|
||||
#endif
|
||||
rt_thread_delay(20);
|
||||
@@ -112,22 +108,22 @@ static void adc_thread_entry(void *parameter)
|
||||
static rt_thread_t adc_thread;
|
||||
void rt_hw_adc_init(void)
|
||||
{
|
||||
adc.type = RT_Device_Class_Char;
|
||||
adc.rx_indicate = RT_NULL;
|
||||
adc.tx_complete = RT_NULL;
|
||||
adc.init = rt_adc_init;
|
||||
adc.open = RT_NULL;
|
||||
adc.close = RT_NULL;
|
||||
adc.read = RT_NULL;
|
||||
adc.write = RT_NULL;
|
||||
adc.control = rt_adc_control;
|
||||
adc.user_data = RT_NULL;
|
||||
adc.type = RT_Device_Class_Char;
|
||||
adc.rx_indicate = RT_NULL;
|
||||
adc.tx_complete = RT_NULL;
|
||||
adc.init = rt_adc_init;
|
||||
adc.open = RT_NULL;
|
||||
adc.close = RT_NULL;
|
||||
adc.read = RT_NULL;
|
||||
adc.write = RT_NULL;
|
||||
adc.control = rt_adc_control;
|
||||
adc.user_data = RT_NULL;
|
||||
|
||||
adc_thread = rt_thread_create("adc", adc_thread_entry, RT_NULL, 384, 26, 5);
|
||||
if(adc_thread != RT_NULL)
|
||||
if(adc_thread != RT_NULL)
|
||||
rt_thread_startup(adc_thread);
|
||||
|
||||
/* register a character device */
|
||||
rt_device_register(&adc, "adc", RT_DEVICE_FLAG_RDWR);
|
||||
|
||||
/* register a character device */
|
||||
rt_device_register(&adc, "adc", RT_DEVICE_FLAG_RDWR);
|
||||
}
|
||||
|
||||
+7
-11
@@ -1,28 +1,24 @@
|
||||
/*
|
||||
* File : adc.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 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
|
||||
* 2011-03-03 lgnq
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __ADC_H__
|
||||
#define __ADC_H__
|
||||
|
||||
/* Exported constants ---------------------------------------------------------*/
|
||||
/* Exported macro -------------------------------------------------------------*/
|
||||
#define ADC_MODE_SINGLE 0x00UL
|
||||
#define ADC_MODE_SCAN 0x01UL
|
||||
#define ADC_MODE_TAILGATE 0x02UL
|
||||
#define ADC_MODE_SINGLE 0x00UL
|
||||
#define ADC_MODE_SCAN 0x01UL
|
||||
#define ADC_MODE_TAILGATE 0x02UL
|
||||
|
||||
#define RT_DEVICE_CTRL_ADC_START 0xF1 /* start ADC conversion */
|
||||
#define RT_DEVICE_CTRL_ADC_RESULT 0xF2 /* get ADC result */
|
||||
#define RT_DEVICE_CTRL_ADC_RESULT 0xF2 /* get ADC result */
|
||||
|
||||
#define ADC_UPDATE 0
|
||||
|
||||
|
||||
+81
-85
File diff suppressed because it is too large.
Load diff
+7
-11
@@ -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
|
||||
@@ -33,13 +29,13 @@ extern const uint32_t SystemFrequency;
|
||||
*/
|
||||
void SysTick_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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
+63
-54
@@ -1,3 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
#include "cpuusage.h"
|
||||
@@ -9,73 +18,73 @@
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#endif
|
||||
|
||||
#define CPU_USAGE_CALC_TICK 10
|
||||
#define CPU_USAGE_LOOP 100
|
||||
#define CPU_USAGE_CALC_TICK 10
|
||||
#define CPU_USAGE_LOOP 100
|
||||
|
||||
static rt_uint8_t cpu_usage_major = 0, cpu_usage_minor= 0;
|
||||
static rt_uint32_t total_count = 0;
|
||||
|
||||
static void cpu_usage_idle_hook()
|
||||
{
|
||||
rt_tick_t tick;
|
||||
rt_uint32_t count;
|
||||
volatile rt_uint32_t loop;
|
||||
rt_tick_t tick;
|
||||
rt_uint32_t count;
|
||||
volatile rt_uint32_t loop;
|
||||
|
||||
if (total_count == 0)
|
||||
{
|
||||
loop = 0;
|
||||
if (total_count == 0)
|
||||
{
|
||||
loop = 0;
|
||||
|
||||
/* get total count */
|
||||
rt_enter_critical();
|
||||
tick = rt_tick_get();
|
||||
while(rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
|
||||
{
|
||||
total_count ++;
|
||||
while (loop < CPU_USAGE_LOOP) loop ++;
|
||||
}
|
||||
rt_exit_critical();
|
||||
}
|
||||
/* get total count */
|
||||
rt_enter_critical();
|
||||
tick = rt_tick_get();
|
||||
while(rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
|
||||
{
|
||||
total_count ++;
|
||||
while (loop < CPU_USAGE_LOOP) loop ++;
|
||||
}
|
||||
rt_exit_critical();
|
||||
}
|
||||
|
||||
count = 0;
|
||||
loop = 0;
|
||||
/* get CPU usage */
|
||||
tick = rt_tick_get();
|
||||
while (rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
|
||||
{
|
||||
count ++;
|
||||
while (loop < CPU_USAGE_LOOP) loop ++;
|
||||
}
|
||||
count = 0;
|
||||
loop = 0;
|
||||
/* get CPU usage */
|
||||
tick = rt_tick_get();
|
||||
while (rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
|
||||
{
|
||||
count ++;
|
||||
while (loop < CPU_USAGE_LOOP) loop ++;
|
||||
}
|
||||
|
||||
/* calculate major and minor */
|
||||
if (count < total_count)
|
||||
{
|
||||
count = total_count - count;
|
||||
cpu_usage_major = (count * 100) / total_count;
|
||||
cpu_usage_minor = ((count * 100) % total_count) * 100 / total_count;
|
||||
}
|
||||
else
|
||||
{
|
||||
total_count = count;
|
||||
/* calculate major and minor */
|
||||
if (count < total_count)
|
||||
{
|
||||
count = total_count - count;
|
||||
cpu_usage_major = (count * 100) / total_count;
|
||||
cpu_usage_minor = ((count * 100) % total_count) * 100 / total_count;
|
||||
}
|
||||
else
|
||||
{
|
||||
total_count = count;
|
||||
|
||||
/* no CPU usage */
|
||||
cpu_usage_major = 0;
|
||||
cpu_usage_minor = 0;
|
||||
}
|
||||
/* no CPU usage */
|
||||
cpu_usage_major = 0;
|
||||
cpu_usage_minor = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void cpu_usage_get(rt_uint8_t *major, rt_uint8_t *minor)
|
||||
{
|
||||
RT_ASSERT(major != RT_NULL);
|
||||
RT_ASSERT(minor != RT_NULL);
|
||||
RT_ASSERT(major != RT_NULL);
|
||||
RT_ASSERT(minor != RT_NULL);
|
||||
|
||||
*major = cpu_usage_major;
|
||||
*minor = cpu_usage_minor;
|
||||
*major = cpu_usage_major;
|
||||
*minor = cpu_usage_minor;
|
||||
}
|
||||
|
||||
void cpu_usage_init()
|
||||
{
|
||||
/* set idle thread hook */
|
||||
rt_thread_idle_sethook(cpu_usage_idle_hook);
|
||||
/* set idle thread hook */
|
||||
rt_thread_idle_sethook(cpu_usage_idle_hook);
|
||||
}
|
||||
extern struct rt_messagequeue mq;
|
||||
extern rt_thread_t info_tid;
|
||||
@@ -83,12 +92,12 @@ static void cpu_thread_entry(void *parameter)
|
||||
{
|
||||
#ifdef RT_USING_RTGUI
|
||||
struct rtgui_event_command ecmd;
|
||||
|
||||
|
||||
RTGUI_EVENT_COMMAND_INIT(&ecmd);
|
||||
ecmd.type = RTGUI_CMD_USER_INT;
|
||||
ecmd.command_id = CPU_UPDATE;
|
||||
#else
|
||||
struct lcd_msg msg;
|
||||
struct lcd_msg msg;
|
||||
#endif
|
||||
|
||||
while (1)
|
||||
@@ -96,10 +105,10 @@ static void cpu_thread_entry(void *parameter)
|
||||
#ifdef RT_USING_RTGUI
|
||||
rtgui_thread_send(info_tid, &ecmd.parent, sizeof(ecmd));
|
||||
#else
|
||||
msg.type = CPU_MSG;
|
||||
msg.major = cpu_usage_major;
|
||||
msg.minor = cpu_usage_minor;
|
||||
rt_mq_send(&mq, &msg, sizeof(msg));
|
||||
msg.type = CPU_MSG;
|
||||
msg.major = cpu_usage_major;
|
||||
msg.minor = cpu_usage_minor;
|
||||
rt_mq_send(&mq, &msg, sizeof(msg));
|
||||
#endif
|
||||
rt_thread_delay(20);
|
||||
}
|
||||
@@ -110,6 +119,6 @@ void rt_hw_cpu_init(void)
|
||||
{
|
||||
cpu_usage_init();
|
||||
cpu_thread = rt_thread_create("cpu", cpu_thread_entry, RT_NULL, 384, 27, 5);
|
||||
if(cpu_thread != RT_NULL)
|
||||
if(cpu_thread != RT_NULL)
|
||||
rt_thread_startup(cpu_thread);
|
||||
}
|
||||
@@ -1,17 +1,13 @@
|
||||
/*
|
||||
* File : cpuusage.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 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
|
||||
* 2011-03-03 lgnq
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __CPUUSAGE_H__
|
||||
#define __CPUUSAGE_H__
|
||||
|
||||
|
||||
+329
-320
File diff suppressed because it is too large.
Load diff
+80
-72
File diff suppressed because it is too large.
Load diff
+49
-53
@@ -1,15 +1,11 @@
|
||||
/*
|
||||
* File : key.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 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
|
||||
* 2011-03-03 lgnq
|
||||
* 2011-03-03 lgnq
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
@@ -25,7 +21,7 @@ static void key_io_init(void)
|
||||
{
|
||||
/*Select CPIO function*/
|
||||
KEY_PFR &= ~KEY_MASK;
|
||||
/*Set CPIO Pull-Up function*/
|
||||
/*Set CPIO Pull-Up function*/
|
||||
KEY_PCR |= KEY_MASK;
|
||||
/*Make button pins inputs*/
|
||||
KEY_DDR &= ~KEY_MASK;
|
||||
@@ -38,7 +34,7 @@ static void key_thread_entry(void *parameter)
|
||||
rt_uint8_t i;
|
||||
|
||||
struct rtgui_event_kbd kbd_event;
|
||||
|
||||
|
||||
key_io_init();
|
||||
|
||||
/* init keyboard event */
|
||||
@@ -109,49 +105,49 @@ static void key_thread_entry(void *parameter)
|
||||
rt_thread_delay(next_delay);
|
||||
}
|
||||
#else
|
||||
extern struct rt_messagequeue mq;
|
||||
rt_time_t next_delay;
|
||||
struct lcd_msg msg;
|
||||
msg.type = KEY_MSG;
|
||||
|
||||
key_io_init();
|
||||
|
||||
while (1)
|
||||
{
|
||||
msg.key = NO_KEY;
|
||||
|
||||
next_delay = RT_TICK_PER_SECOND/10;
|
||||
|
||||
if (KEY_ENTER_GETVALUE() == 0 )
|
||||
{
|
||||
msg.key = KEY_ENTER;
|
||||
}
|
||||
|
||||
if (KEY_DOWN_GETVALUE() == 0)
|
||||
{
|
||||
msg.key = KEY_DOWN;
|
||||
}
|
||||
|
||||
if (KEY_UP_GETVALUE() == 0)
|
||||
{
|
||||
msg.key = KEY_UP;
|
||||
}
|
||||
|
||||
if (KEY_RIGHT_GETVALUE() == 0)
|
||||
{
|
||||
msg.key = KEY_RIGHT;
|
||||
}
|
||||
|
||||
if (KEY_LEFT_GETVALUE() == 0)
|
||||
{
|
||||
msg.key = KEY_LEFT;
|
||||
}
|
||||
|
||||
rt_mq_send(&mq, &msg, sizeof(msg));
|
||||
|
||||
/* wait next key press */
|
||||
rt_thread_delay(next_delay);
|
||||
}
|
||||
extern struct rt_messagequeue mq;
|
||||
rt_time_t next_delay;
|
||||
struct lcd_msg msg;
|
||||
msg.type = KEY_MSG;
|
||||
|
||||
key_io_init();
|
||||
|
||||
while (1)
|
||||
{
|
||||
msg.key = NO_KEY;
|
||||
|
||||
next_delay = RT_TICK_PER_SECOND/10;
|
||||
|
||||
if (KEY_ENTER_GETVALUE() == 0 )
|
||||
{
|
||||
msg.key = KEY_ENTER;
|
||||
}
|
||||
|
||||
if (KEY_DOWN_GETVALUE() == 0)
|
||||
{
|
||||
msg.key = KEY_DOWN;
|
||||
}
|
||||
|
||||
if (KEY_UP_GETVALUE() == 0)
|
||||
{
|
||||
msg.key = KEY_UP;
|
||||
}
|
||||
|
||||
if (KEY_RIGHT_GETVALUE() == 0)
|
||||
{
|
||||
msg.key = KEY_RIGHT;
|
||||
}
|
||||
|
||||
if (KEY_LEFT_GETVALUE() == 0)
|
||||
{
|
||||
msg.key = KEY_LEFT;
|
||||
}
|
||||
|
||||
rt_mq_send(&mq, &msg, sizeof(msg));
|
||||
|
||||
/* wait next key press */
|
||||
rt_thread_delay(next_delay);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -159,6 +155,6 @@ static rt_thread_t key_thread;
|
||||
void rt_hw_key_init(void)
|
||||
{
|
||||
key_thread = rt_thread_create("key", key_thread_entry, RT_NULL, 384, 28, 5);
|
||||
if (key_thread != RT_NULL)
|
||||
if (key_thread != RT_NULL)
|
||||
rt_thread_startup(key_thread);
|
||||
}
|
||||
+2
-6
@@ -1,11 +1,7 @@
|
||||
/*
|
||||
* File : key.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 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
|
||||
|
||||
+89
-93
File diff suppressed because it is too large.
Load diff
+117
-121
File diff suppressed because it is too large.
Load diff
+24
-28
@@ -1,17 +1,13 @@
|
||||
/*
|
||||
* File : led.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 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
|
||||
* 2011-03-03 lgnq
|
||||
*/
|
||||
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
|
||||
@@ -20,8 +16,8 @@
|
||||
|
||||
void rt_hw_led_on(rt_uint8_t num)
|
||||
{
|
||||
RT_ASSERT(num < LEDS_MAX_NUMBER);
|
||||
|
||||
RT_ASSERT(num < LEDS_MAX_NUMBER);
|
||||
|
||||
switch (num)
|
||||
{
|
||||
case 1:
|
||||
@@ -31,16 +27,16 @@ void rt_hw_led_on(rt_uint8_t num)
|
||||
LED_PDOR &= ~LED2;
|
||||
break;
|
||||
case 3:
|
||||
LED_PDOR &= ~LED3;
|
||||
LED_PDOR &= ~LED3;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rt_hw_led_off(rt_uint8_t num)
|
||||
{
|
||||
RT_ASSERT(num < LEDS_MAX_NUMBER);
|
||||
RT_ASSERT(num < LEDS_MAX_NUMBER);
|
||||
|
||||
switch (num)
|
||||
{
|
||||
@@ -51,17 +47,17 @@ void rt_hw_led_off(rt_uint8_t num)
|
||||
LED_PDOR |= LED2;
|
||||
break;
|
||||
case 3:
|
||||
LED_PDOR |= LED3;
|
||||
LED_PDOR |= LED3;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rt_hw_led_toggle(rt_uint8_t num)
|
||||
{
|
||||
RT_ASSERT(num < LEDS_MAX_NUMBER);
|
||||
|
||||
RT_ASSERT(num < LEDS_MAX_NUMBER);
|
||||
|
||||
switch (num)
|
||||
{
|
||||
case 1:
|
||||
@@ -80,11 +76,11 @@ void rt_hw_led_toggle(rt_uint8_t num)
|
||||
if (LED_PDOR&LED3)
|
||||
LED_PDOR &= ~LED3;
|
||||
else
|
||||
LED_PDOR |= LED3;
|
||||
LED_PDOR |= LED3;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static rt_err_t led_io_init(void)
|
||||
@@ -95,23 +91,23 @@ static rt_err_t led_io_init(void)
|
||||
LED_PDOR |= LED_MASK;
|
||||
/*Make led pins outputs*/
|
||||
LED_DDR |= LED_MASK;
|
||||
|
||||
|
||||
//LED3 is controled by PWM
|
||||
FM3_GPIO->PFR3 = 0x1000;
|
||||
FM3_GPIO->EPFR04 = 0x00080000;
|
||||
FM3_BT2_PWM->TMCR = 0x0018;
|
||||
FM3_BT2_PWM->TMCR2 = 0x01; /* cks=0b1000 count clk 1/512 */
|
||||
FM3_BT2_PWM->TMCR2 = 0x01; /* cks=0b1000 count clk 1/512 */
|
||||
FM3_BT2_PWM->STC = 0x00;
|
||||
FM3_BT2_PWM->PCSR = 0x61A; /* Down count = 1562 */
|
||||
FM3_BT2_PWM->PDUT = 0x0; /* Duty count = 16/1562=10% */
|
||||
|
||||
FM3_BT2_PWM->TMCR |= 0x03; /* start base timer(softwere TRG) */
|
||||
FM3_BT2_PWM->PCSR = 0x61A; /* Down count = 1562 */
|
||||
FM3_BT2_PWM->PDUT = 0x0; /* Duty count = 16/1562=10% */
|
||||
|
||||
FM3_BT2_PWM->TMCR |= 0x03; /* start base timer(softwere TRG) */
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
void pwm_update(rt_uint16_t value)
|
||||
{
|
||||
FM3_BT2_PWM->PDUT = value;
|
||||
FM3_BT2_PWM->PDUT = value;
|
||||
}
|
||||
|
||||
static void led1_thread_entry(void *parameter)
|
||||
@@ -139,11 +135,11 @@ void rt_hw_led_init(void)
|
||||
led_io_init();
|
||||
|
||||
led1_thread = rt_thread_create("led1", led1_thread_entry, RT_NULL, 384, 29, 5);
|
||||
if (led1_thread != RT_NULL)
|
||||
if (led1_thread != RT_NULL)
|
||||
rt_thread_startup(led1_thread);
|
||||
|
||||
|
||||
led2_thread = rt_thread_create("led2", led2_thread_entry, RT_NULL, 384, 30, 5);
|
||||
if (led2_thread != RT_NULL)
|
||||
if (led2_thread != RT_NULL)
|
||||
rt_thread_startup(led2_thread);
|
||||
}
|
||||
|
||||
|
||||
+7
-11
@@ -1,23 +1,19 @@
|
||||
/*
|
||||
* File : led.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 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
|
||||
* 2011-03-03 lgnq
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __LED_H__
|
||||
#define __LED_H__
|
||||
|
||||
#include "mb9bf506r.h"
|
||||
|
||||
#define LEDS_MAX_NUMBER 4
|
||||
#define LEDS_MAX_NUMBER 4
|
||||
|
||||
/*LEDs*/
|
||||
#define LED1 (1UL<<10)
|
||||
@@ -29,9 +25,9 @@
|
||||
#define LED_DDR (FM3_GPIO->DDR3)
|
||||
#define LED_PDOR (FM3_GPIO->PDOR3)
|
||||
|
||||
#define RT_DEVICE_CTRL_LED_ON 0
|
||||
#define RT_DEVICE_CTRL_LED_OFF 1
|
||||
#define RT_DEVICE_CTRL_LED_TOGGLE 2
|
||||
#define RT_DEVICE_CTRL_LED_ON 0
|
||||
#define RT_DEVICE_CTRL_LED_OFF 1
|
||||
#define RT_DEVICE_CTRL_LED_TOGGLE 2
|
||||
|
||||
void rt_hw_led_init(void);
|
||||
void rt_hw_led_on(rt_uint8_t num);
|
||||
|
||||
@@ -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 */
|
||||
@@ -53,20 +53,20 @@
|
||||
#define RT_USING_DEVICE
|
||||
/* RT_USING_UART */
|
||||
#define RT_USING_UART0
|
||||
#define RT_UART_RX_BUFFER_SIZE 64
|
||||
#define RT_UART_RX_BUFFER_SIZE 64
|
||||
|
||||
/* SECTION: Console options */
|
||||
#define RT_TINY_SIZE
|
||||
#define RT_USING_CONSOLE
|
||||
/* the buffer size of console */
|
||||
#define RT_CONSOLEBUF_SIZE 128
|
||||
#define RT_CONSOLEBUF_SIZE 128
|
||||
|
||||
/* SECTION: RTGUI support */
|
||||
/* using RTGUI support */
|
||||
/* #define RT_USING_RTGUI */
|
||||
|
||||
/* name length of RTGUI object */
|
||||
#define RTGUI_NAME_MAX 16
|
||||
#define RTGUI_NAME_MAX 16
|
||||
/* support 16 weight font */
|
||||
//#define RTGUI_USING_FONT16
|
||||
/* support 12 weight font */
|
||||
|
||||
+34
-38
@@ -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
|
||||
@@ -38,57 +34,57 @@ extern int __bss_end;
|
||||
*/
|
||||
void rtthread_startup(void)
|
||||
{
|
||||
/* init board */
|
||||
rt_hw_board_init();
|
||||
/* init board */
|
||||
rt_hw_board_init();
|
||||
|
||||
/* show version */
|
||||
rt_show_version();
|
||||
/* show version */
|
||||
rt_show_version();
|
||||
|
||||
/* init timer system */
|
||||
rt_system_timer_init();
|
||||
/* init timer system */
|
||||
rt_system_timer_init();
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
#ifdef __CC_ARM
|
||||
rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)FM3_SRAM_END);
|
||||
#elif __ICCARM__
|
||||
rt_system_heap_init(__segment_end("HEAP"), (void*)FM3_SRAM_END);
|
||||
#else
|
||||
/* init memory system */
|
||||
rt_system_heap_init((void*)&__bss_end, (void*)FM3_SRAM_END);
|
||||
#endif
|
||||
#ifdef __CC_ARM
|
||||
rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)FM3_SRAM_END);
|
||||
#elif __ICCARM__
|
||||
rt_system_heap_init(__segment_end("HEAP"), (void*)FM3_SRAM_END);
|
||||
#else
|
||||
/* init memory system */
|
||||
rt_system_heap_init((void*)&__bss_end, (void*)FM3_SRAM_END);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* init scheduler system */
|
||||
rt_system_scheduler_init();
|
||||
/* init scheduler system */
|
||||
rt_system_scheduler_init();
|
||||
|
||||
/* init application */
|
||||
rt_application_init();
|
||||
/* init application */
|
||||
rt_application_init();
|
||||
|
||||
/* init timer thread */
|
||||
rt_system_timer_thread_init();
|
||||
|
||||
/* init idle thread */
|
||||
rt_thread_idle_init();
|
||||
/* init 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();
|
||||
|
||||
/* init system setting */
|
||||
SystemInit();
|
||||
|
||||
/* startup RT-Thread RTOS */
|
||||
rtthread_startup();
|
||||
/* init system setting */
|
||||
SystemInit();
|
||||
|
||||
return 0;
|
||||
/* startup RT-Thread RTOS */
|
||||
rtthread_startup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*@}*/
|
||||
Reference in new issue
Block a user