1
0
Эх сурвалжийг харах

update the led_examples_project

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@123 bbd45198-f89e-11dd-88c7-29a3b14d5316
wuyangyong 16 жил өмнө
parent
commit
8bae291939

+ 96 - 70
bsp/stm3210/led.c

@@ -1,70 +1,96 @@
-#include <rtthread.h>
-#include <stm32f10x.h>
-
-#define RCC_APB2Periph_GPIO_LED		RCC_APB2Periph_GPIOF
-#define GPIO_LED					GPIOF
-#define GPIO_Pin_LED				GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9
-
-static const rt_uint16_t led_map[] = {GPIO_Pin_6, GPIO_Pin_7, GPIO_Pin_8, GPIO_Pin_9};
-static rt_uint8_t led_inited = 0;
-
-static void GPIO_Configuration(void)
-{
-	GPIO_InitTypeDef GPIO_InitStructure;
-
-	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_LED;
-	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
-	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-	GPIO_Init(GPIO_LED, &GPIO_InitStructure);
-}
-
-void LED_Configuration(void)
-{
-	/* enable led clock */
-	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_LED, ENABLE);
-
-	GPIO_Configuration();
-}
-
-void rt_hw_led_init()
-{
-	/* init led configuration if it's not inited. */
-	if (!led_inited) 
-	{
-		LED_Configuration();
-		led_inited = 1;
-	}
-}
-
-void rt_hw_led_on(rt_uint32_t led)
-{
-	if (led < sizeof(led_map)/sizeof(rt_uint16_t))
-		GPIO_SetBits(GPIO_LED, led_map[led]);
-}
-
-void rt_hw_led_off(rt_uint32_t led)
-{
-	if (led < sizeof(led_map)/sizeof(rt_uint16_t))
-		GPIO_ResetBits(GPIO_LED, led_map[led]);
-}
-
-#ifdef RT_USING_FINSH
-#include <finsh.h>
-void led(rt_uint32_t led, rt_uint32_t value)
-{
-	/* init led configuration if it's not inited. */
-	if (!led_inited) 
-	{
-		LED_Configuration();
-		led_inited = 1;
-	}
-
-	/* set led status */
-	if (value)
-		rt_hw_led_on(led);
-	else
-		rt_hw_led_off(led);
-}
-FINSH_FUNCTION_EXPORT(led, set led[0 - 3] on[1] or off[0].)
-#endif
-
+#include <rtthread.h>
+#include <stm32f10x.h>
+
+#define led1_rcc                    RCC_APB2Periph_GPIOF
+#define led1_gpio                   GPIOF
+#define led1_pin                    (GPIO_Pin_6 | GPIO_Pin_7)
+
+#define led2_rcc                    RCC_APB2Periph_GPIOF
+#define led2_gpio                   GPIOF
+#define led2_pin                    (GPIO_Pin_8)
+
+void rt_hw_led_init(void)
+{
+    GPIO_InitTypeDef GPIO_InitStructure;
+
+    RCC_APB2PeriphClockCmd(led1_rcc|led2_rcc,ENABLE);
+
+    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
+    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+
+    GPIO_InitStructure.GPIO_Pin   = led1_pin;
+    GPIO_Init(led1_gpio, &GPIO_InitStructure);
+
+    GPIO_InitStructure.GPIO_Pin   = led2_pin;
+    GPIO_Init(led2_gpio, &GPIO_InitStructure);
+}
+
+void rt_hw_led_on(rt_uint32_t n)
+{
+    switch (n)
+    {
+    case 0:
+        GPIO_SetBits(led1_gpio, led1_pin);
+        break;
+    case 1:
+        GPIO_SetBits(led2_gpio, led2_pin);
+        break;
+    default:
+        break;
+    }
+}
+
+void rt_hw_led_off(rt_uint32_t n)
+{
+    switch (n)
+    {
+    case 0:
+        GPIO_ResetBits(led1_gpio, led1_pin);
+        break;
+    case 1:
+        GPIO_ResetBits(led2_gpio, led2_pin);
+        break;
+    default:
+        break;
+    }
+}
+
+#ifdef RT_USING_FINSH
+#include <finsh.h>
+void led(rt_uint32_t led, rt_uint32_t value)
+{
+    if ( led == 0 )
+    {
+        /* set led status */
+        switch (value)
+        {
+        case 0:
+            rt_hw_led_off(0);
+            break;
+        case 1:
+            rt_hw_led_on(0);
+            break;
+        default:
+            break;
+        }
+    }
+
+    if ( led == 1 )
+    {
+        /* set led status */
+        switch (value)
+        {
+        case 0:
+            rt_hw_led_off(1);
+            break;
+        case 1:
+            rt_hw_led_on(1);
+            break;
+        default:
+            break;
+        }
+    }
+}
+FINSH_FUNCTION_EXPORT(led, set led[0 - 1] on[1] or off[0].)
+#endif
+

+ 86 - 55
bsp/stm3210/project_led/application.c

@@ -1,55 +1,86 @@
-/*
- * File      : application.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006, 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
- *
- * Change Logs:
- * Date           Author       Notes
- * 2009-01-05     Bernard      the first version
- */
-
-/**
- * @addtogroup STM32
- */
-/*@{*/
-
-#include <rtthread.h>
-#include "led.h"
-
-void led(void* parameter)
-{
-	/* init led configuration */
-	rt_hw_led_init();
-	
-	while (1)
-	{
-		/* led on */
-		rt_hw_led_on(0);
-		rt_thread_delay(50); /* sleep 0.5 second and switch to other thread */
-		
-		/* led off */
-		rt_hw_led_off(0);
-		rt_thread_delay(50);
-	}
-}
-
-int rt_application_init()
-{
-	rt_thread_t thread;
-	
-	/* create led thread */
-	thread = rt_thread_create("led", 
-		led, RT_NULL,
-		512,
-		20, 5);
-	if (thread != RT_NULL)
-		rt_thread_startup(thread);
-
-	return 0;
-}
-
-/*@}*/
+/*
+ * File      : application.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006, 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
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2009-01-05     Bernard      the first version
+ */
+
+/**
+ * @addtogroup STM32
+ */
+/*@{*/
+
+#include <rtthread.h>
+#include "led.h"
+
+static void rt_thread_entry_led1(void* parameter)
+{
+    /* init led configuration */
+    rt_hw_led_init();
+
+    while (1)
+    {
+        /* led on */
+        rt_kprintf("led1 on\r\n");
+        rt_hw_led_on(0);
+        rt_thread_delay(50); /* sleep 0.5 second and switch to other thread */
+
+        /* led off */
+        rt_kprintf("led1 off\r\n");
+        rt_hw_led_off(0);
+        rt_thread_delay(50);
+    }
+}
+
+char thread_led2_stack[1024];
+struct rt_thread thread_led2;
+void rt_thread_entry_led2(void* parameter)
+{
+    unsigned int count=0;
+    while (1)
+    {
+        /* led on */
+        rt_kprintf("led2 on,count : %d\r\n",count);
+        count++;
+        rt_hw_led_on(1);
+        rt_thread_delay(RT_TICK_PER_SECOND);
+
+        /* led off */
+        rt_kprintf("led2 off\r\n");
+        rt_hw_led_off(1);
+        rt_thread_delay(RT_TICK_PER_SECOND);
+    }
+}
+
+int rt_application_init()
+{
+    rt_thread_t thread;
+
+    /* create led1 thread */
+    thread = rt_thread_create("led1",
+                              rt_thread_entry_led1, RT_NULL,
+                              512,
+                              20, 5);
+    if (thread != RT_NULL)
+        rt_thread_startup(thread);
+
+    //------- init led2 thread
+    rt_thread_init(&thread_led2,
+                   "led2",
+                   rt_thread_entry_led2,
+                   RT_NULL,
+                   &thread_led2_stack[0],
+                   sizeof(thread_led2_stack),10,10);
+    rt_thread_startup(&thread_led2);
+
+    return 0;
+}
+
+/*@}*/