clean code in bsp/simulator
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2533 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
2bae33a381
commit
10892ce762
@ -21,7 +21,7 @@
|
|||||||
void rt_init_thread_entry(void *parameter)
|
void rt_init_thread_entry(void *parameter)
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_LWIP
|
#ifdef RT_USING_LWIP
|
||||||
extern void pcap_netif_hw_init(void);
|
|
||||||
pcap_netif_hw_init();
|
pcap_netif_hw_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ void rt_platform_init(void)
|
|||||||
#endif /* RT_USING_DFS */
|
#endif /* RT_USING_DFS */
|
||||||
|
|
||||||
#ifdef RT_USING_RTGUI
|
#ifdef RT_USING_RTGUI
|
||||||
/* initilize sdl */
|
/* start sdl thread to simulate an LCD */
|
||||||
sdl_start();
|
rt_hw_sdl_start();
|
||||||
#endif /* RT_USING_RTGUI */
|
#endif /* RT_USING_RTGUI */
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@ -20,15 +20,7 @@
|
|||||||
/**
|
/**
|
||||||
* @addtogroup win32
|
* @addtogroup win32
|
||||||
*/
|
*/
|
||||||
#define HEAP_SIZE (1024*1024*10)
|
|
||||||
static rt_uint8_t * heap;
|
|
||||||
|
|
||||||
void vs_heap_init(void)
|
|
||||||
{
|
|
||||||
heap = malloc(HEAP_SIZE);
|
|
||||||
if (heap == RT_NULL)
|
|
||||||
rt_kprintf("there is no memory in pc.");
|
|
||||||
}
|
|
||||||
/*@{*/
|
/*@{*/
|
||||||
|
|
||||||
extern int rt_application_init(void);
|
extern int rt_application_init(void);
|
||||||
@ -37,6 +29,7 @@ extern void finsh_system_init(void);
|
|||||||
extern void finsh_set_device(const char* device);
|
extern void finsh_set_device(const char* device);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern rt_uint8_t * heap;
|
||||||
/**
|
/**
|
||||||
* This function will startup RT-Thread RTOS.
|
* This function will startup RT-Thread RTOS.
|
||||||
*/
|
*/
|
||||||
@ -59,9 +52,6 @@ void rtthread_startup(void)
|
|||||||
|
|
||||||
#ifdef RT_USING_HEAP
|
#ifdef RT_USING_HEAP
|
||||||
/* init memory system */
|
/* init memory system */
|
||||||
#if (MSVC)
|
|
||||||
vs_heap_init();
|
|
||||||
#endif
|
|
||||||
rt_system_heap_init((void*)heap, (void*)&heap[HEAP_SIZE-1]);
|
rt_system_heap_init((void*)heap, (void*)&heap[HEAP_SIZE-1]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -14,28 +14,27 @@
|
|||||||
|
|
||||||
#include <rthw.h>
|
#include <rthw.h>
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup simulator on win32
|
* @addtogroup simulator on win32
|
||||||
*/
|
*/
|
||||||
|
rt_uint8_t * heap;
|
||||||
|
|
||||||
/**
|
rt_uint8_t * rt_hw_sram_init(void)
|
||||||
* This function will initial win32
|
|
||||||
*/
|
|
||||||
void rt_hw_board_init()
|
|
||||||
{
|
{
|
||||||
#if defined(RT_USING_CONSOLE)
|
rt_uint8_t * heap;
|
||||||
rt_hw_usart_init();
|
heap = malloc(HEAP_SIZE);
|
||||||
rt_hw_serial_init();
|
if (heap == RT_NULL)
|
||||||
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
{
|
||||||
#endif
|
rt_kprintf("there is no memory in pc.");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
return heap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fix the compile errors for redefiniton of lwip_htonl in win socket */
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
void rt_hw_win32_low_cpu(void)
|
void rt_hw_win32_low_cpu(void)
|
||||||
{
|
{
|
||||||
Sleep(1000);
|
Sleep(1000);
|
||||||
@ -57,8 +56,20 @@ void rt_hw_exit(void)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, exit, exit rt-thread);
|
FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, exit, exit rt-thread);
|
||||||
|
|
||||||
#endif /* RT_USING_FINSH */
|
#endif /* RT_USING_FINSH */
|
||||||
|
|
||||||
#endif /* WIN32 */
|
/**
|
||||||
|
* This function will initial win32
|
||||||
|
*/
|
||||||
|
void rt_hw_board_init()
|
||||||
|
{
|
||||||
|
/* init system memory */
|
||||||
|
heap = rt_hw_sram_init();
|
||||||
|
|
||||||
|
#if defined(RT_USING_CONSOLE)
|
||||||
|
rt_hw_usart_init();
|
||||||
|
rt_hw_serial_init();
|
||||||
|
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
@ -14,21 +14,20 @@
|
|||||||
|
|
||||||
#ifndef __BOARD_H__
|
#ifndef __BOARD_H__
|
||||||
#define __BOARD_H__
|
#define __BOARD_H__
|
||||||
|
|
||||||
void rt_hw_board_led_on(int n);
|
|
||||||
void rt_hw_board_led_off(int n);
|
|
||||||
void rt_hw_board_init(void);
|
void rt_hw_board_init(void);
|
||||||
|
rt_uint8_t * rt_hw_sram_init(void);
|
||||||
void rt_hw_serial_init(void);
|
|
||||||
|
|
||||||
/* SD Card init function */
|
/* SD Card init function */
|
||||||
void rt_hw_sdcard_init(void);
|
void rt_hw_sdcard_init(void);
|
||||||
|
|
||||||
int rt_hw_mtd_nand_init(void);
|
int rt_hw_mtd_nand_init(void);
|
||||||
|
int sst25vfxx_mtd_init(const char *, unsigned int , unsigned int);
|
||||||
int sst25vfxx_mtd_init(const char * nor_name, unsigned int block_start, unsigned int block_end);
|
void pcap_netif_hw_init(void);
|
||||||
|
|
||||||
void rt_platform_init(void);
|
void rt_platform_init(void);
|
||||||
|
void rt_hw_usart_init(void);
|
||||||
|
void rt_hw_serial_init(void);
|
||||||
|
void rt_hw_sdl_start(void);
|
||||||
void rt_hw_win32_low_cpu(void);
|
void rt_hw_win32_low_cpu(void);
|
||||||
|
|
||||||
|
void rt_hw_exit(void);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,234 +0,0 @@
|
|||||||
#include <rtdevice.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dfs_def.h>
|
|
||||||
|
|
||||||
// #define NAND_TRACE rt_kprintf
|
|
||||||
#define NAND_TRACE(...)
|
|
||||||
|
|
||||||
#define NAND_SIM "nand.bin"
|
|
||||||
|
|
||||||
struct nand_device
|
|
||||||
{
|
|
||||||
struct rt_mtd_nand_device parent;
|
|
||||||
FILE * file;
|
|
||||||
};
|
|
||||||
static struct nand_device _nand;
|
|
||||||
|
|
||||||
#define NAND_DEVICE(device) (( struct nand_device*)(device))
|
|
||||||
|
|
||||||
#define PAGE_DATA_SIZE 2048 /* page data size in bytes */
|
|
||||||
#define PAGE_SPARE_SIZE 64 /* oob size in bytes */
|
|
||||||
#define BLOCK_PAGES 64 /* the number of pages in a block */
|
|
||||||
#define BLOCK_SIZE ((PAGE_DATA_SIZE + PAGE_SPARE_SIZE) * BLOCK_PAGES)
|
|
||||||
|
|
||||||
#define BLOCK_COUNT 128 /* 128 blocks == 16M */
|
|
||||||
#define BLOCK_MARK_SPARE_OFFSET 4
|
|
||||||
|
|
||||||
static rt_mutex_t lock;
|
|
||||||
|
|
||||||
/* RT-Thread device interface */
|
|
||||||
|
|
||||||
static rt_err_t k9f1g08_mtd_check_block(
|
|
||||||
struct rt_mtd_nand_device* device,
|
|
||||||
rt_uint32_t block)
|
|
||||||
{
|
|
||||||
rt_uint8_t block_status;
|
|
||||||
int result;
|
|
||||||
|
|
||||||
struct nand_device * nand;
|
|
||||||
nand = NAND_DEVICE(device);
|
|
||||||
|
|
||||||
fseek(nand->file, block * device->pages_per_block *
|
|
||||||
(device->page_size + device->oob_size) +
|
|
||||||
device->page_size + BLOCK_MARK_SPARE_OFFSET,
|
|
||||||
SEEK_SET);
|
|
||||||
result = fread(&block_status, 1, 1, nand->file);
|
|
||||||
if (result < 0)
|
|
||||||
{
|
|
||||||
NAND_TRACE("nand fread error\n");
|
|
||||||
return -RT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return block_status == 0xFF ? RT_EOK : -RT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
static rt_err_t k9f1g08_mtd_mark_bad_block(
|
|
||||||
struct rt_mtd_nand_device* device,
|
|
||||||
rt_uint32_t block)
|
|
||||||
{
|
|
||||||
rt_uint8_t block_status;
|
|
||||||
int result;
|
|
||||||
|
|
||||||
struct nand_device * nand;
|
|
||||||
nand = NAND_DEVICE(device);
|
|
||||||
|
|
||||||
fseek(nand->file, block * device->pages_per_block *
|
|
||||||
(device->page_size + device->oob_size) +
|
|
||||||
device->page_size + BLOCK_MARK_SPARE_OFFSET,
|
|
||||||
SEEK_SET);
|
|
||||||
|
|
||||||
block_status = 0x00;
|
|
||||||
result = fwrite(&block_status, 1, 1, nand->file);
|
|
||||||
if (result < 0)
|
|
||||||
{
|
|
||||||
NAND_TRACE("nand fwrite error\n");
|
|
||||||
return -RT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return RT_EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char block_buffer[BLOCK_SIZE];
|
|
||||||
|
|
||||||
static rt_err_t k9f1g08_mtd_erase_block(
|
|
||||||
struct rt_mtd_nand_device* device,
|
|
||||||
rt_uint32_t block)
|
|
||||||
{
|
|
||||||
int result;
|
|
||||||
|
|
||||||
struct nand_device * nand;
|
|
||||||
nand = NAND_DEVICE(device);
|
|
||||||
|
|
||||||
fseek(nand->file, block * device->pages_per_block *
|
|
||||||
(device->page_size + device->oob_size),
|
|
||||||
SEEK_SET);
|
|
||||||
|
|
||||||
memset(block_buffer, 0xFF, sizeof(BLOCK_SIZE));
|
|
||||||
result = fwrite(block_buffer, BLOCK_SIZE, 1, nand->file);
|
|
||||||
if (result < 0)
|
|
||||||
{
|
|
||||||
NAND_TRACE("nand fwrite error\n");
|
|
||||||
return -RT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return RT_EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* return 0, ecc ok, 1, can be fixed , -1 can not be fixed */
|
|
||||||
static rt_err_t k9f1g08_mtd_read(
|
|
||||||
struct rt_mtd_nand_device * device,
|
|
||||||
rt_off_t page,
|
|
||||||
rt_uint8_t * data, rt_uint32_t data_len, //may not always be 2048
|
|
||||||
rt_uint8_t * spare, rt_uint32_t spare_len)
|
|
||||||
{
|
|
||||||
int result;
|
|
||||||
int ecc_status = 0;
|
|
||||||
|
|
||||||
struct nand_device * nand;
|
|
||||||
nand = NAND_DEVICE(device);
|
|
||||||
|
|
||||||
if (data != RT_NULL && data_len != 0)
|
|
||||||
{
|
|
||||||
fseek(nand->file, page * (device->page_size + device->oob_size),
|
|
||||||
SEEK_SET);
|
|
||||||
result = fread(data, data_len, 1, nand->file);
|
|
||||||
if (result < 0)
|
|
||||||
ecc_status = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (spare != RT_NULL && spare_len != 0)
|
|
||||||
{
|
|
||||||
fseek(nand->file, page * (device->page_size + device->oob_size)
|
|
||||||
+device->page_size,
|
|
||||||
SEEK_SET);
|
|
||||||
result = fread(spare, spare_len, 1, nand->file);
|
|
||||||
if (result < 0)
|
|
||||||
ecc_status = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ecc_status;
|
|
||||||
}
|
|
||||||
|
|
||||||
static rt_err_t k9f1g08_mtd_write (
|
|
||||||
struct rt_mtd_nand_device * device,
|
|
||||||
rt_off_t page,
|
|
||||||
const rt_uint8_t * data, rt_uint32_t data_len,//will be 2048 always!
|
|
||||||
const rt_uint8_t * spare, rt_uint32_t spare_len)
|
|
||||||
{
|
|
||||||
int result;
|
|
||||||
int ecc_status = 0;
|
|
||||||
|
|
||||||
struct nand_device * nand;
|
|
||||||
nand = NAND_DEVICE(device);
|
|
||||||
|
|
||||||
if (data != RT_NULL && data_len != 0)
|
|
||||||
{
|
|
||||||
fseek(nand->file, page * (device->page_size + device->oob_size),
|
|
||||||
SEEK_SET);
|
|
||||||
result = fwrite(data, data_len, 1, nand->file);
|
|
||||||
if (result < 0)
|
|
||||||
ecc_status = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (spare != RT_NULL && spare_len != 0)
|
|
||||||
{
|
|
||||||
fseek(nand->file, page * (device->page_size + device->oob_size)
|
|
||||||
+device->page_size,
|
|
||||||
SEEK_SET);
|
|
||||||
result = fwrite(spare, spare_len, 1, nand->file);
|
|
||||||
if (result < 0)
|
|
||||||
ecc_status = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ecc_status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const static struct rt_mtd_nand_driver_ops k9f1g08_mtd_ops =
|
|
||||||
{
|
|
||||||
RT_NULL,
|
|
||||||
k9f1g08_mtd_read,
|
|
||||||
k9f1g08_mtd_write,
|
|
||||||
k9f1g08_mtd_erase_block,
|
|
||||||
k9f1g08_mtd_check_block,
|
|
||||||
k9f1g08_mtd_mark_bad_block,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* interface of nand and rt-thread device */
|
|
||||||
static struct rt_mtd_nand_device nand_part[2];
|
|
||||||
|
|
||||||
int rt_hw_mtd_nand_init(void)
|
|
||||||
{
|
|
||||||
int size;
|
|
||||||
rt_uint32_t id, total_block;
|
|
||||||
struct nand_device * nand;
|
|
||||||
struct rt_mtd_nand_device * nand_part;
|
|
||||||
|
|
||||||
nand = &_nand;
|
|
||||||
nand_part = &(nand->parent);
|
|
||||||
|
|
||||||
lock = rt_mutex_create("nand", RT_IPC_FLAG_FIFO);
|
|
||||||
|
|
||||||
/* open sd card file, if not exist, then create it */
|
|
||||||
nand->file = fopen(NAND_SIM, "rb+");
|
|
||||||
if (nand->file == NULL)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
/* create a file to simulate sd card */
|
|
||||||
nand->file = fopen(NAND_SIM, "wb+");
|
|
||||||
|
|
||||||
memset(block_buffer, 0xFF, sizeof(block_buffer));
|
|
||||||
for(i=0; i<BLOCK_COUNT; i++)
|
|
||||||
{
|
|
||||||
fseek(nand->file, i * BLOCK_SIZE, SEEK_SET);
|
|
||||||
fwrite(block_buffer, BLOCK_SIZE, 1, nand->file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fseek(nand->file, 0, SEEK_SET);
|
|
||||||
|
|
||||||
/* the first partition of nand */
|
|
||||||
nand_part->page_size = PAGE_DATA_SIZE;
|
|
||||||
nand_part->pages_per_block = BLOCK_PAGES;//don't caculate oob size
|
|
||||||
nand_part->block_start = 0;
|
|
||||||
nand_part->block_end = BLOCK_COUNT -1;
|
|
||||||
nand_part->oob_size = PAGE_SPARE_SIZE;
|
|
||||||
nand_part->ops = &k9f1g08_mtd_ops;
|
|
||||||
rt_mtd_nand_register_device("nand0", nand_part);
|
|
||||||
return RT_EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef RT_USING_FINSH
|
|
||||||
#include <finsh.h>
|
|
||||||
#endif
|
|
@ -281,7 +281,8 @@ static DWORD WINAPI sdl_loop(LPVOID lpParam)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sdl_start(void)
|
/* start sdl thread */
|
||||||
|
void rt_hw_sdl_start(void)
|
||||||
{
|
{
|
||||||
HANDLE thread;
|
HANDLE thread;
|
||||||
DWORD thread_id;
|
DWORD thread_id;
|
||||||
|
@ -155,7 +155,6 @@ static rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_u
|
|||||||
|
|
||||||
rt_err_t rt_hw_serial_init(void)
|
rt_err_t rt_hw_serial_init(void)
|
||||||
{
|
{
|
||||||
return rt_hw_serial_register(&serial_device,"sci0",
|
return rt_hw_serial_register(&serial_device,RT_CONSOLE_DEVICE_NAME,
|
||||||
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM);
|
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM);
|
||||||
}
|
}
|
||||||
|
|
@ -8,6 +8,8 @@
|
|||||||
#undef RT_USING_MINILIBC
|
#undef RT_USING_MINILIBC
|
||||||
#define NORESOURCE //RT_VESRION in winuser.h
|
#define NORESOURCE //RT_VESRION in winuser.h
|
||||||
#define _CRT_ERRNO_DEFINED //errno macro redefinition
|
#define _CRT_ERRNO_DEFINED //errno macro redefinition
|
||||||
|
|
||||||
|
#define HEAP_SIZE (1024*1024*2)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* SECTION: basic kernel options */
|
/* SECTION: basic kernel options */
|
||||||
@ -69,7 +71,6 @@
|
|||||||
/* SECTION: Device System */
|
/* SECTION: Device System */
|
||||||
/* Using Device System */
|
/* Using Device System */
|
||||||
#define RT_USING_DEVICE
|
#define RT_USING_DEVICE
|
||||||
/* #define RT_USING_SERIAL */
|
|
||||||
/* #define RT_USING_UART1 */
|
/* #define RT_USING_UART1 */
|
||||||
|
|
||||||
/* SECTION: Console options */
|
/* SECTION: Console options */
|
||||||
@ -132,7 +133,7 @@
|
|||||||
#define DFS_FD_MAX 4
|
#define DFS_FD_MAX 4
|
||||||
|
|
||||||
/* SECTION: lwip, a lighwight TCP/IP protocol stack */
|
/* SECTION: lwip, a lighwight TCP/IP protocol stack */
|
||||||
#define RT_USING_LWIP
|
/* #define RT_USING_LWIP */
|
||||||
/* LwIP uses RT-Thread Memory Management */
|
/* LwIP uses RT-Thread Memory Management */
|
||||||
#define RT_LWIP_USING_RT_MEM
|
#define RT_LWIP_USING_RT_MEM
|
||||||
/* Enable ICMP protocol*/
|
/* Enable ICMP protocol*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user