application.c 4.4 KB
Newer Older
O
onelife.real 已提交
1 2 3
/******************************************************************//**
 * @file 		application.c
 * @brief 	application tasks
O
onelife.real@gmail.com 已提交
4
 * 	COPYRIGHT (C) 2011, RT-Thread Development Team
O
onelife.real 已提交
5 6 7 8 9 10 11 12 13 14 15
 * @author 	Bernard, onelife
 * @version 	0.4 beta
 **********************************************************************
 * @section License
 * 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
 **********************************************************************
 * @section Change Logs
 * Date			Author		Notes
 * 2009-01-05 	Bernard 		first version
 * 2010-12-29	onelife		Modify for EFM32
O
onelife.real 已提交
16
 * 2011-05-06	onelife		Add SPI Flash DEMO
O
onelife.real 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
 *********************************************************************/
 
/******************************************************************//**
* @addtogroup cortex-m3
* @{
*********************************************************************/

/* Includes -------------------------------------------------------------------*/
#include <board.h>

#ifdef RT_USING_DFS
/* dfs init */
#include <dfs_init.h>
/* dfs filesystem:ELM filesystem init */
#include <dfs_elm.h>
/* dfs Filesystem APIs */
#include <dfs_fs.h>
#endif

O
onelife.real 已提交
36 37 38
#include "dev_led.h"
#ifdef EFM32_USING_SFLASH
#include "dev_sflash.h"
O
onelife.real 已提交
39 40 41 42 43 44
#endif

/* Private typedef -------------------------------------------------------------*/
/* Private define --------------------------------------------------------------*/
/* Private macro --------------------------------------------------------------*/
/* Private variables ------------------------------------------------------------*/
O
onelife.real@gmail.com 已提交
45
rt_uint32_t	rt_system_status = 0;
O
onelife.real 已提交
46 47 48

/* Private function prototypes ---------------------------------------------------*/
/* Private functions ------------------------------------------------------------*/
O
onelife.real 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
void rt_demo_thread_entry(void* parameter)
{
#ifdef EFM32_USING_SFLASH
	rt_uint8_t i;
	rt_uint8_t test[] = "123456789ABCDEF";
	rt_uint8_t buf[30], buf2[30];

	efm_spiFash_cmd(sflash_inst_rdid_l, EFM32_NO_DATA, buf, sizeof(buf));
	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]);

	efm_spiFash_cmd(sflash_inst_wren, EFM32_NO_DATA, EFM32_NO_POINTER, EFM32_NO_DATA);
	do
	{
		efm_spiFash_cmd(sflash_inst_rdsr, EFM32_NO_DATA, buf2, sizeof(buf2));
		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);

	efm_spiFash_cmd(sflash_inst_rdsr, EFM32_NO_DATA, buf2, sizeof(buf2));
	rt_kprintf("Status: %x\n", buf2[0]);
	
	efm_spiFash_cmd(sflash_inst_read, 0x00000300, buf, sizeof(buf));
	rt_kprintf("READ: \n");
	for (i = 0; i < sizeof(buf); i++)
	{
		rt_kprintf("%c\n", buf[i]);
	}

	//efm_spiFash_deinit();
#endif
}

O
onelife.real 已提交
87 88
void rt_led_thread_entry(void* parameter)
{
O
onelife.real 已提交
89 90
	rt_uint8_t n = 0;

O
onelife.real 已提交
91 92 93 94
	rt_hw_led_on(0);
	rt_hw_led_on(1);
	rt_hw_led_on(2);
	rt_hw_led_on(3);
O
onelife.real 已提交
95 96 97 98 99 100 101 102 103 104 105

	while(1)
	{
		/* Toggle a led per second */
		rt_hw_led_toggle(n++);
		if (n == LEDS_MAX_NUMBER)
		{
			n =0;
		}
		rt_thread_delay(100);
	}
O
onelife.real 已提交
106 107 108 109
}

int rt_application_init()
{
O
onelife.real 已提交
110 111 112 113 114 115 116
	rt_thread_t demo_thread, led_thread;

#if (defined(EFM32_G290_DK) && defined(EFM32_USING_SFLASH))
	/* Enable SPI access to Flash */
	DVK_writeRegister(BC_SPI_CFG, 0);
	efm_spiFash_init();
#endif
O
onelife.real@gmail.com 已提交
117 118 119 120 121 122 123 124 125 126 127 128

	/* Initialize all device drivers (dev_?.c) */
	if (rt_hw_led_init() != RT_EOK)
	{
		rt_kprintf("*** Failed to initialize LED driver!");
		while(1); //Or do something?
	}
	if (rt_hw_misc_init() != RT_EOK)
	{
		rt_kprintf("*** Failed to miscellaneous driver!");
		while(1); //Or do something?
	}
O
onelife.real 已提交
129 130

#if (RT_THREAD_PRIORITY_MAX == 32)
O
onelife.real 已提交
131 132 133 134 135 136 137 138
	demo_thread = rt_thread_create(
		"demo",
		rt_demo_thread_entry, 
		RT_NULL,
		2048, 
		3, 
		20);

O
onelife.real 已提交
139 140 141 142
	led_thread = rt_thread_create(
		"led",
		rt_led_thread_entry, 
		RT_NULL,
O
onelife.real 已提交
143
		256,
O
onelife.real 已提交
144 145 146 147 148
		3, 
		20);
#else
#endif

O
onelife.real 已提交
149 150 151 152 153 154
	if(demo_thread != RT_NULL)
	{
		rt_kprintf("demo sp:%x\n", demo_thread->sp);
		rt_thread_startup(demo_thread);
	}

O
onelife.real 已提交
155 156 157 158 159 160 161 162 163 164 165
	if(led_thread != RT_NULL)
	{
		rt_thread_startup(led_thread);
	}

	return 0;
}

/******************************************************************//**
 * @}
*********************************************************************/