2011-07-08 15:13:20 +08:00
|
|
|
/***************************************************************************//**
|
|
|
|
* @file application.c
|
2011-02-17 11:33:15 +08:00
|
|
|
* @brief application tasks
|
2011-02-28 12:47:50 +08:00
|
|
|
* COPYRIGHT (C) 2011, RT-Thread Development Team
|
2011-02-17 11:33:15 +08:00
|
|
|
* @author Bernard, onelife
|
2011-07-08 15:13:20 +08:00
|
|
|
* @version 0.4 beta
|
|
|
|
*******************************************************************************
|
2011-02-17 11:33:15 +08:00
|
|
|
* @section License
|
2011-12-16 09:05:50 +08:00
|
|
|
* The license and distribution terms for this file may be found in the file
|
2011-07-08 15:13:20 +08:00
|
|
|
* LICENSE in this distribution or at http://www.rt-thread.org/license/LICENSE
|
|
|
|
*******************************************************************************
|
2011-02-17 11:33:15 +08:00
|
|
|
* @section Change Logs
|
|
|
|
* Date Author Notes
|
2011-07-08 15:13:20 +08:00
|
|
|
* 2009-01-05 Bernard first version
|
2011-02-17 11:33:15 +08:00
|
|
|
* 2010-12-29 onelife Modify for EFM32
|
2011-05-12 15:19:37 +08:00
|
|
|
* 2011-05-06 onelife Add SPI Flash DEMO
|
2011-07-29 10:47:37 +08:00
|
|
|
* 2011-07-15 onelife Add accelerometer DEMO
|
|
|
|
* 2011-07-27 onelife Modify Ethernet DEMO
|
2011-12-16 09:05:50 +08:00
|
|
|
* 2011-08-23 onelife Modify Ethernet DEMO according to the changes of
|
|
|
|
* lwIP API in reversion 1668
|
2011-07-08 15:13:20 +08:00
|
|
|
******************************************************************************/
|
2011-12-16 09:05:50 +08:00
|
|
|
|
2011-07-08 15:13:20 +08:00
|
|
|
/***************************************************************************//**
|
|
|
|
* @addtogroup efm32
|
|
|
|
* @{
|
|
|
|
******************************************************************************/
|
2011-02-17 11:33:15 +08:00
|
|
|
|
2011-07-08 15:13:20 +08:00
|
|
|
/* Includes ------------------------------------------------------------------*/
|
2011-02-17 11:33:15 +08:00
|
|
|
#include <board.h>
|
|
|
|
|
2011-07-08 15:13:20 +08:00
|
|
|
#if defined(RT_USING_DFS)
|
2011-02-17 11:33:15 +08:00
|
|
|
/* dfs init */
|
|
|
|
#include <dfs_init.h>
|
|
|
|
/* dfs filesystem:ELM filesystem init */
|
|
|
|
#include <dfs_elm.h>
|
|
|
|
/* dfs Filesystem APIs */
|
|
|
|
#include <dfs_fs.h>
|
|
|
|
#endif
|
|
|
|
|
2011-05-12 15:19:37 +08:00
|
|
|
#include "dev_led.h"
|
2011-07-29 10:47:37 +08:00
|
|
|
#if defined(EFM32_USING_ACCEL)
|
|
|
|
#include "dev_accel.h"
|
|
|
|
#endif
|
2011-07-08 15:13:20 +08:00
|
|
|
#if defined(EFM32_USING_SFLASH)
|
2011-05-12 15:19:37 +08:00
|
|
|
#include "dev_sflash.h"
|
2011-02-17 11:33:15 +08:00
|
|
|
#endif
|
2011-07-08 15:13:20 +08:00
|
|
|
#if defined(EFM32_USING_SPISD)
|
2011-06-20 09:56:28 +08:00
|
|
|
#include "drv_sdcard.h"
|
|
|
|
#endif
|
2011-07-08 15:13:20 +08:00
|
|
|
#if defined(EFM32_USING_ETHERNET)
|
|
|
|
#include "drv_ethernet.h"
|
|
|
|
#endif
|
2011-06-20 09:56:28 +08:00
|
|
|
|
2011-07-08 15:13:20 +08:00
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
|
|
/* Private macro -------------------------------------------------------------*/
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
2011-07-29 10:47:37 +08:00
|
|
|
volatile rt_uint32_t rt_system_status = 0;
|
2011-02-17 11:33:15 +08:00
|
|
|
|
2011-07-08 15:13:20 +08:00
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
/* Private functions ---------------------------------------------------------*/
|
2011-05-12 15:19:37 +08:00
|
|
|
void rt_demo_thread_entry(void* parameter)
|
|
|
|
{
|
2011-07-29 10:47:37 +08:00
|
|
|
#if 0 //defined(EFM32_USING_ACCEL)
|
|
|
|
struct efm32_accel_result_t result;
|
|
|
|
|
|
|
|
rt_kprintf(">>> waiting\n");
|
|
|
|
rt_thread_sleep(6000);
|
|
|
|
rt_kprintf(">>> start\n");
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
efm_accel_get_data(&result);
|
|
|
|
rt_kprintf("Accel x: %x\n", result.x);
|
|
|
|
rt_kprintf("Accel y: %x\n", result.y);
|
|
|
|
rt_kprintf("Accel z: %x\n\n", result.z);
|
|
|
|
rt_thread_sleep(200);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-06-20 09:56:28 +08:00
|
|
|
#if defined(RT_USING_DFS)
|
|
|
|
/* Filesystem Initialization */
|
|
|
|
dfs_init();
|
|
|
|
|
2011-07-08 15:13:20 +08:00
|
|
|
#if defined(RT_USING_DFS_ELMFAT)
|
2011-06-20 09:56:28 +08:00
|
|
|
/* init the elm chan FatFs filesystam*/
|
|
|
|
elm_init();
|
|
|
|
|
2011-07-08 15:13:20 +08:00
|
|
|
#if defined(EFM32_USING_SPISD)
|
2011-06-20 09:56:28 +08:00
|
|
|
/* mount sd card fat partition 1 as root directory */
|
|
|
|
if (dfs_mount(SPISD_DEVICE_NAME, "/", "elm", 0, 0) == 0)
|
|
|
|
{
|
|
|
|
rt_kprintf("FatFs init OK\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rt_kprintf("FatFs init failed!\n");
|
|
|
|
}
|
2011-07-08 15:13:20 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
2011-06-20 09:56:28 +08:00
|
|
|
#endif
|
|
|
|
|
2011-05-12 15:19:37 +08:00
|
|
|
#ifdef EFM32_USING_SFLASH
|
2011-06-20 09:56:28 +08:00
|
|
|
{
|
2011-05-12 15:19:37 +08:00
|
|
|
rt_uint8_t i;
|
|
|
|
rt_uint8_t test[] = "123456789ABCDEF";
|
|
|
|
rt_uint8_t buf[30], buf2[30];
|
|
|
|
|
2011-06-20 09:56:28 +08:00
|
|
|
efm_spiFlash_cmd(sflash_inst_rdid_l, EFM32_NO_DATA, buf, sizeof(buf));
|
2011-05-12 15:19:37 +08:00
|
|
|
rt_kprintf("Manuf ID: %x\n", buf[0]);
|
|
|
|
rt_kprintf("Memory type: %x\n", buf[1]);
|
|
|
|
rt_kprintf("Memory capacity: %x\n", buf[2]);
|
|
|
|
rt_kprintf("CFD length: %x\n", buf[3]);
|
|
|
|
rt_kprintf("CFD: %x%x%x...%x%x\n", buf[4], buf[5], buf[6], buf[18], buf[19]);
|
|
|
|
|
2011-06-20 09:56:28 +08:00
|
|
|
efm_spiFlash_cmd(sflash_inst_wren, EFM32_NO_DATA, EFM32_NO_POINTER, EFM32_NO_DATA);
|
2011-05-12 15:19:37 +08:00
|
|
|
do
|
|
|
|
{
|
2011-06-20 09:56:28 +08:00
|
|
|
efm_spiFlash_cmd(sflash_inst_rdsr, EFM32_NO_DATA, buf2, sizeof(buf2));
|
2011-05-12 15:19:37 +08:00
|
|
|
rt_kprintf("Status: %x\n", buf2[0]);
|
|
|
|
} while (buf2[0] == 0xFF);
|
|
|
|
rt_kprintf("Status: %x\n", buf2[0]);
|
|
|
|
|
|
|
|
//efm_spiFash_cmd(sflash_inst_pp, 0x000003F8, test, sizeof(test) - 1);
|
|
|
|
|
2011-06-20 09:56:28 +08:00
|
|
|
efm_spiFlash_cmd(sflash_inst_rdsr, EFM32_NO_DATA, buf2, sizeof(buf2));
|
2011-05-12 15:19:37 +08:00
|
|
|
rt_kprintf("Status: %x\n", buf2[0]);
|
2011-12-16 09:05:50 +08:00
|
|
|
|
2011-06-20 09:56:28 +08:00
|
|
|
efm_spiFlash_cmd(sflash_inst_read, 0x00000300, buf, sizeof(buf));
|
2011-05-12 15:19:37 +08:00
|
|
|
rt_kprintf("READ: \n");
|
|
|
|
for (i = 0; i < sizeof(buf); i++)
|
|
|
|
{
|
|
|
|
rt_kprintf("%c\n", buf[i]);
|
|
|
|
}
|
|
|
|
|
2011-06-20 09:56:28 +08:00
|
|
|
//efm_spiFlash_deinit();
|
|
|
|
}
|
2011-07-08 15:13:20 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(EFM32_USING_ETHERNET)
|
2011-07-29 10:47:37 +08:00
|
|
|
extern void lwip_sys_init(void);
|
2011-08-23 12:36:33 +08:00
|
|
|
/* init lwip system */
|
|
|
|
lwip_sys_init();
|
|
|
|
rt_kprintf("TCP/IP stack init OK!\n");
|
2011-07-08 15:13:20 +08:00
|
|
|
|
2011-08-23 12:36:33 +08:00
|
|
|
#if defined(EFM32_USING_ETH_HTTPD)
|
|
|
|
extern void httpd_init(void);
|
|
|
|
/* init http server */
|
|
|
|
httpd_init();
|
|
|
|
rt_kprintf("Http service init OK!\n");
|
|
|
|
#endif /* defined(EFM32_USING_ETH_HTTPD) */
|
2011-07-29 10:47:37 +08:00
|
|
|
#endif /* defined(EFM32_USING_ETHERNET) */
|
2011-06-20 09:56:28 +08:00
|
|
|
rt_kprintf("Demo End\n");
|
2011-07-29 10:47:37 +08:00
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
rt_thread_sleep(10);
|
|
|
|
}
|
2011-05-12 15:19:37 +08:00
|
|
|
}
|
|
|
|
|
2011-02-17 11:33:15 +08:00
|
|
|
void rt_led_thread_entry(void* parameter)
|
|
|
|
{
|
2011-05-12 15:19:37 +08:00
|
|
|
rt_uint8_t n = 0;
|
|
|
|
|
2011-02-17 11:33:15 +08:00
|
|
|
rt_hw_led_on(0);
|
|
|
|
rt_hw_led_on(1);
|
|
|
|
rt_hw_led_on(2);
|
|
|
|
rt_hw_led_on(3);
|
2011-05-12 15:19:37 +08:00
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
/* Toggle a led per second */
|
|
|
|
rt_hw_led_toggle(n++);
|
|
|
|
if (n == LEDS_MAX_NUMBER)
|
|
|
|
{
|
|
|
|
n =0;
|
|
|
|
}
|
|
|
|
rt_thread_delay(100);
|
|
|
|
}
|
2011-02-17 11:33:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int rt_application_init()
|
|
|
|
{
|
2011-05-12 15:19:37 +08:00
|
|
|
rt_thread_t demo_thread, led_thread;
|
|
|
|
|
2011-07-29 10:47:37 +08:00
|
|
|
#if defined(EFM32_USING_ACCEL)
|
|
|
|
if (efm_accel_init() != RT_EOK)
|
|
|
|
{
|
|
|
|
rt_kprintf("*** Init accelerometer driver failed!");
|
|
|
|
while(1); //Or do something?
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-06-20 09:56:28 +08:00
|
|
|
#if defined(EFM32_USING_SFLASH)
|
2011-07-08 15:13:20 +08:00
|
|
|
if (efm_spiFlash_init() != RT_EOK)
|
|
|
|
{
|
|
|
|
rt_kprintf("*** Init SPI Flash driver failed!");
|
|
|
|
while(1); //Or do something?
|
|
|
|
}
|
2011-06-20 09:56:28 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(EFM32_USING_SPISD)
|
2011-07-08 15:13:20 +08:00
|
|
|
if (efm_spiSd_init() != RT_EOK)
|
|
|
|
{
|
|
|
|
rt_kprintf("*** Init SD card driver failed!");
|
|
|
|
while(1); //Or do something?
|
|
|
|
}
|
2011-05-12 15:19:37 +08:00
|
|
|
#endif
|
2011-02-28 12:47:50 +08:00
|
|
|
|
|
|
|
/* Initialize all device drivers (dev_?.c) */
|
|
|
|
if (rt_hw_led_init() != RT_EOK)
|
|
|
|
{
|
2011-07-08 15:13:20 +08:00
|
|
|
rt_kprintf("*** Init LED driver failed!");
|
2011-02-28 12:47:50 +08:00
|
|
|
while(1); //Or do something?
|
|
|
|
}
|
2011-07-29 10:47:37 +08:00
|
|
|
#if defined(RT_USING_MISC)
|
2011-02-28 12:47:50 +08:00
|
|
|
if (rt_hw_misc_init() != RT_EOK)
|
|
|
|
{
|
2011-07-08 15:13:20 +08:00
|
|
|
rt_kprintf("*** Init miscellaneous driver failed!");
|
2011-02-28 12:47:50 +08:00
|
|
|
while(1); //Or do something?
|
|
|
|
}
|
2011-06-20 09:56:28 +08:00
|
|
|
#endif
|
2011-02-17 11:33:15 +08:00
|
|
|
|
2011-07-08 15:13:20 +08:00
|
|
|
#if defined(RT_USING_LWIP)
|
|
|
|
{
|
|
|
|
/* Create Ethernet Threads */
|
|
|
|
if (eth_system_device_init() != RT_EOK)
|
|
|
|
{
|
|
|
|
rt_kprintf("*** Create Ethernet threads failed!");
|
|
|
|
while(1); //Or do something?
|
|
|
|
}
|
|
|
|
#if defined(EFM32_USING_ETHERNET)
|
|
|
|
if (efm_hw_eth_init() != RT_EOK)
|
|
|
|
{
|
|
|
|
rt_kprintf("*** Init Ethernet driver failed!");
|
|
|
|
while(1); //Or do something?
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-02-17 11:33:15 +08:00
|
|
|
#if (RT_THREAD_PRIORITY_MAX == 32)
|
2011-05-12 15:19:37 +08:00
|
|
|
demo_thread = rt_thread_create(
|
|
|
|
"demo",
|
2011-12-16 09:05:50 +08:00
|
|
|
rt_demo_thread_entry,
|
2011-05-12 15:19:37 +08:00
|
|
|
RT_NULL,
|
2011-12-16 09:05:50 +08:00
|
|
|
1024,
|
|
|
|
5,
|
2011-05-12 15:19:37 +08:00
|
|
|
20);
|
|
|
|
|
2011-02-17 11:33:15 +08:00
|
|
|
led_thread = rt_thread_create(
|
|
|
|
"led",
|
2011-12-16 09:05:50 +08:00
|
|
|
rt_led_thread_entry,
|
2011-02-17 11:33:15 +08:00
|
|
|
RT_NULL,
|
2011-05-12 15:19:37 +08:00
|
|
|
256,
|
2011-12-16 09:05:50 +08:00
|
|
|
5,
|
2011-02-17 11:33:15 +08:00
|
|
|
20);
|
|
|
|
#else
|
|
|
|
#endif
|
|
|
|
|
2011-05-12 15:19:37 +08:00
|
|
|
if(demo_thread != RT_NULL)
|
|
|
|
{
|
|
|
|
rt_kprintf("demo sp:%x\n", demo_thread->sp);
|
|
|
|
rt_thread_startup(demo_thread);
|
|
|
|
}
|
|
|
|
|
2011-02-17 11:33:15 +08:00
|
|
|
if(led_thread != RT_NULL)
|
|
|
|
{
|
|
|
|
rt_thread_startup(led_thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-08 15:13:20 +08:00
|
|
|
/***************************************************************************//**
|
2011-02-17 11:33:15 +08:00
|
|
|
* @}
|
2011-07-08 15:13:20 +08:00
|
|
|
******************************************************************************/
|