2011-10-27 10:31:34 +08:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
/*@{*/
|
|
|
|
|
2012-01-01 05:42:12 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2011-10-27 10:31:34 +08:00
|
|
|
#include "stm32f4xx.h"
|
|
|
|
#include <board.h>
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
|
|
|
#ifdef RT_USING_LWIP
|
|
|
|
#include <lwip/sys.h>
|
|
|
|
#include <lwip/api.h>
|
|
|
|
#include <netif/ethernetif.h>
|
|
|
|
#include "stm32_eth.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void rt_init_thread_entry(void* parameter)
|
|
|
|
{
|
|
|
|
/* LwIP Initialization */
|
|
|
|
#ifdef RT_USING_LWIP
|
|
|
|
{
|
|
|
|
extern void lwip_sys_init(void);
|
|
|
|
|
|
|
|
/* register ethernetif device */
|
|
|
|
eth_system_device_init();
|
|
|
|
|
|
|
|
rt_hw_stm32_eth_init();
|
|
|
|
/* re-init device driver */
|
|
|
|
rt_device_init_all();
|
|
|
|
|
|
|
|
/* init lwip system */
|
|
|
|
lwip_sys_init();
|
|
|
|
rt_kprintf("TCP/IP initialized!\n");
|
|
|
|
}
|
|
|
|
#endif
|
2012-01-01 05:42:12 +08:00
|
|
|
|
|
|
|
//FS
|
|
|
|
|
|
|
|
//GUI
|
2011-10-27 10:31:34 +08:00
|
|
|
}
|
|
|
|
|
2012-01-01 05:42:12 +08:00
|
|
|
float f_var1;
|
|
|
|
float f_var2;
|
|
|
|
float f_var3;
|
|
|
|
float f_var4;
|
|
|
|
|
2011-10-27 10:31:34 +08:00
|
|
|
ALIGN(RT_ALIGN_SIZE)
|
2012-01-01 05:42:12 +08:00
|
|
|
static char thread_led1_stack[1024];
|
|
|
|
struct rt_thread thread_led1;
|
|
|
|
static void rt_thread_entry_led1(void* parameter)
|
2011-10-27 10:31:34 +08:00
|
|
|
{
|
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
|
2012-01-01 05:42:12 +08:00
|
|
|
/* GPIOD Periph clock enable */
|
|
|
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
|
|
|
|
|
|
|
|
/* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
|
|
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
|
|
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
|
|
|
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
2011-10-27 10:31:34 +08:00
|
|
|
|
2012-01-01 05:42:12 +08:00
|
|
|
f_var1 = 3.141592653;
|
|
|
|
f_var2 = 123.456;
|
|
|
|
f_var3 = 0.123456789;
|
|
|
|
f_var4 = 1.00001;
|
2011-10-27 10:31:34 +08:00
|
|
|
|
2012-01-01 05:42:12 +08:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
/* PD12 to be toggled */
|
|
|
|
GPIO_SetBits(GPIOD, GPIO_Pin_12);
|
2011-10-27 10:31:34 +08:00
|
|
|
|
2012-01-01 05:42:12 +08:00
|
|
|
/* Insert delay */
|
|
|
|
rt_thread_delay(RT_TICK_PER_SECOND/2);
|
|
|
|
f_var3 += f_var4;
|
|
|
|
f_var4 = f_var4 * f_var4;
|
2011-10-27 10:31:34 +08:00
|
|
|
|
2012-01-01 05:42:12 +08:00
|
|
|
/* PD13 to be toggled */
|
|
|
|
GPIO_SetBits(GPIOD, GPIO_Pin_13);
|
2011-10-27 10:31:34 +08:00
|
|
|
|
2012-01-01 05:42:12 +08:00
|
|
|
/* Insert delay */
|
|
|
|
rt_thread_delay(RT_TICK_PER_SECOND/2);
|
|
|
|
f_var3 += f_var4;
|
|
|
|
f_var4 = f_var4 * f_var4;
|
2011-10-27 10:31:34 +08:00
|
|
|
|
2012-01-01 05:42:12 +08:00
|
|
|
/* PD14 to be toggled */
|
|
|
|
GPIO_SetBits(GPIOD, GPIO_Pin_14);
|
2011-10-27 10:31:34 +08:00
|
|
|
|
2012-01-01 05:42:12 +08:00
|
|
|
/* Insert delay */
|
|
|
|
rt_thread_delay(RT_TICK_PER_SECOND/2);
|
|
|
|
f_var3 += f_var4;
|
|
|
|
f_var4 = f_var4 * f_var4;
|
2011-10-27 10:31:34 +08:00
|
|
|
|
2012-01-01 05:42:12 +08:00
|
|
|
/* PD15 to be toggled */
|
|
|
|
GPIO_SetBits(GPIOD, GPIO_Pin_15);
|
2011-10-27 10:31:34 +08:00
|
|
|
|
2012-01-01 05:42:12 +08:00
|
|
|
/* Insert delay */
|
|
|
|
rt_thread_delay(RT_TICK_PER_SECOND*2);
|
|
|
|
f_var3 += f_var4;
|
|
|
|
f_var4 = f_var4 * f_var4;
|
2011-10-27 10:31:34 +08:00
|
|
|
|
2012-01-01 05:42:12 +08:00
|
|
|
GPIO_ResetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
|
2011-10-27 10:31:34 +08:00
|
|
|
|
2012-01-01 05:42:12 +08:00
|
|
|
/* Insert delay */
|
|
|
|
rt_thread_delay(RT_TICK_PER_SECOND);
|
|
|
|
f_var3 += f_var4;
|
|
|
|
f_var4 = f_var4 * f_var4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ALIGN(RT_ALIGN_SIZE)
|
|
|
|
static char thread_led2_stack[1024];
|
|
|
|
struct rt_thread thread_led2;
|
|
|
|
static void rt_thread_entry_led2(void* parameter)
|
|
|
|
{
|
|
|
|
float f_var_me;
|
|
|
|
|
|
|
|
char str_buffer[256];
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
f_var_me = f_var1 * f_var2 + f_var3;
|
|
|
|
sprintf(str_buffer, "%f", f_var_me);
|
|
|
|
rt_kprintf("thread1 %s\r\n", str_buffer);
|
|
|
|
rt_thread_delay(RT_TICK_PER_SECOND);
|
|
|
|
}
|
2011-10-27 10:31:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int rt_application_init()
|
|
|
|
{
|
2012-01-01 05:42:12 +08:00
|
|
|
rt_thread_t init_thread;
|
|
|
|
|
|
|
|
#if (RT_THREAD_PRIORITY_MAX == 32)
|
|
|
|
init_thread = rt_thread_create("init",
|
|
|
|
rt_init_thread_entry, RT_NULL,
|
|
|
|
2048, 8, 20);
|
|
|
|
#else
|
|
|
|
init_thread = rt_thread_create("init",
|
|
|
|
rt_init_thread_entry, RT_NULL,
|
|
|
|
2048, 80, 20);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (init_thread != RT_NULL)
|
|
|
|
rt_thread_startup(init_thread);
|
2011-10-27 10:31:34 +08:00
|
|
|
|
|
|
|
//------- init led1 thread
|
2012-01-01 05:42:12 +08:00
|
|
|
rt_thread_init(&thread_led1,
|
|
|
|
"led1",
|
|
|
|
rt_thread_entry_led1,
|
|
|
|
RT_NULL,
|
|
|
|
&thread_led1_stack[0],
|
|
|
|
sizeof(thread_led1_stack),11,5);
|
|
|
|
rt_thread_startup(&thread_led1);
|
|
|
|
|
|
|
|
//------- init led2 thread
|
|
|
|
rt_thread_init(&thread_led2,
|
|
|
|
"led2",
|
|
|
|
rt_thread_entry_led2,
|
2011-10-27 10:31:34 +08:00
|
|
|
RT_NULL,
|
2012-01-01 05:42:12 +08:00
|
|
|
&thread_led2_stack[0],
|
|
|
|
sizeof(thread_led2_stack),11,5);
|
|
|
|
rt_thread_startup(&thread_led2);
|
2011-10-27 10:31:34 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*@}*/
|