format code style with astyle in bsp/simulator
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2535 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
2e1de690f2
commit
1b274d996f
|
@ -26,10 +26,10 @@
|
|||
extern int rt_application_init(void);
|
||||
#ifdef RT_USING_FINSH
|
||||
extern void finsh_system_init(void);
|
||||
extern void finsh_set_device(const char* device);
|
||||
extern void finsh_set_device(const char *device);
|
||||
#endif
|
||||
|
||||
extern rt_uint8_t * heap;
|
||||
extern rt_uint8_t *heap;
|
||||
/**
|
||||
* This function will startup RT-Thread RTOS.
|
||||
*/
|
||||
|
@ -52,7 +52,7 @@ void rtthread_startup(void)
|
|||
|
||||
#ifdef RT_USING_HEAP
|
||||
/* init memory system */
|
||||
rt_system_heap_init((void*)heap, (void*)&heap[HEAP_SIZE-1]);
|
||||
rt_system_heap_init((void *)heap, (void *)&heap[HEAP_SIZE - 1]);
|
||||
#endif
|
||||
|
||||
/* init scheduler system */
|
||||
|
|
|
@ -21,11 +21,11 @@
|
|||
/**
|
||||
* @addtogroup simulator on win32
|
||||
*/
|
||||
rt_uint8_t * heap;
|
||||
rt_uint8_t *heap;
|
||||
|
||||
rt_uint8_t * rt_hw_sram_init(void)
|
||||
rt_uint8_t *rt_hw_sram_init(void)
|
||||
{
|
||||
rt_uint8_t * heap;
|
||||
rt_uint8_t *heap;
|
||||
heap = malloc(HEAP_SIZE);
|
||||
if (heap == RT_NULL)
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ void rt_hw_exit(void)
|
|||
rt_kprintf("RT-Thread, bye\n");
|
||||
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 */
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#ifndef __BOARD_H__
|
||||
#define __BOARD_H__
|
||||
void rt_hw_board_init(void);
|
||||
rt_uint8_t * rt_hw_sram_init(void);
|
||||
rt_uint8_t *rt_hw_sram_init(void);
|
||||
|
||||
/* SD Card init function */
|
||||
void rt_hw_sdcard_init(void);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
static unsigned char block_data[BLOCK_SIZE];
|
||||
static struct rt_mtd_nand_device _nanddrv_file_device;
|
||||
static FILE* file = NULL;
|
||||
static FILE *file = NULL;
|
||||
|
||||
static rt_uint8_t CountBitsInByte(rt_uint8_t byte)
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ static void Compute256(const rt_uint8_t *data, rt_uint8_t *code)
|
|||
|
||||
// Xor all bytes together to get the column sum;
|
||||
// At the same time, calculate the even and odd line codes
|
||||
for (i=0; i < 256; i++)
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
columnSum ^= data[i];
|
||||
|
||||
|
@ -93,7 +93,7 @@ static void Compute256(const rt_uint8_t *data, rt_uint8_t *code)
|
|||
|
||||
// At this point, we have the line parities, and the column sum. First, We
|
||||
// must caculate the parity group values on the column sum.
|
||||
for (i=0; i < 8; i++)
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
if (columnSum & 1)
|
||||
{
|
||||
|
@ -113,7 +113,7 @@ static void Compute256(const rt_uint8_t *data, rt_uint8_t *code)
|
|||
code[1] = 0;
|
||||
code[2] = 0;
|
||||
|
||||
for (i=0; i < 4; i++)
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
code[0] <<= 2;
|
||||
code[1] <<= 2;
|
||||
|
@ -164,11 +164,11 @@ static void Compute256(const rt_uint8_t *data, rt_uint8_t *code)
|
|||
code[2] = (~(rt_uint32_t)code[2]);
|
||||
}
|
||||
|
||||
void ecc_hamming_compute256x(const rt_uint8_t *pucData, rt_uint32_t dwSize, rt_uint8_t* puCode )
|
||||
void ecc_hamming_compute256x(const rt_uint8_t *pucData, rt_uint32_t dwSize, rt_uint8_t *puCode)
|
||||
{
|
||||
while ( dwSize > 0 )
|
||||
while (dwSize > 0)
|
||||
{
|
||||
Compute256( pucData, puCode ) ;
|
||||
Compute256(pucData, puCode) ;
|
||||
|
||||
pucData += 256;
|
||||
puCode += 3;
|
||||
|
@ -177,13 +177,13 @@ void ecc_hamming_compute256x(const rt_uint8_t *pucData, rt_uint32_t dwSize, rt_u
|
|||
}
|
||||
|
||||
/* read chip id */
|
||||
static rt_uint32_t nanddrv_file_read_id(struct rt_mtd_nand_device* device)
|
||||
static rt_uint32_t nanddrv_file_read_id(struct rt_mtd_nand_device *device)
|
||||
{
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
/* read/write/move page */
|
||||
static rt_err_t nanddrv_file_read_page(struct rt_mtd_nand_device* device,
|
||||
static rt_err_t nanddrv_file_read_page(struct rt_mtd_nand_device *device,
|
||||
rt_off_t page,
|
||||
rt_uint8_t *data, rt_uint32_t data_len,
|
||||
rt_uint8_t *spare, rt_uint32_t spare_len)
|
||||
|
@ -194,7 +194,7 @@ static rt_err_t nanddrv_file_read_page(struct rt_mtd_nand_device* device,
|
|||
|
||||
page = page + device->block_start * device->pages_per_block;
|
||||
|
||||
if (page/device->pages_per_block > device->block_end)
|
||||
if (page / device->pages_per_block > device->block_end)
|
||||
{
|
||||
return -RT_EIO;
|
||||
}
|
||||
|
@ -225,16 +225,16 @@ static rt_err_t nanddrv_file_read_page(struct rt_mtd_nand_device* device,
|
|||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t nanddrv_file_write_page(struct rt_mtd_nand_device* device,
|
||||
static rt_err_t nanddrv_file_write_page(struct rt_mtd_nand_device *device,
|
||||
rt_off_t page,
|
||||
const rt_uint8_t* data, rt_uint32_t data_len,
|
||||
const rt_uint8_t* oob, rt_uint32_t spare_len)
|
||||
const rt_uint8_t *data, rt_uint32_t data_len,
|
||||
const rt_uint8_t *oob, rt_uint32_t spare_len)
|
||||
{
|
||||
rt_uint32_t offset;
|
||||
rt_uint8_t oob_buffer[OOB_SIZE];
|
||||
|
||||
page = page + device->block_start * device->pages_per_block;
|
||||
if (page/device->pages_per_block > device->block_end)
|
||||
if (page / device->pages_per_block > device->block_end)
|
||||
{
|
||||
return -RT_EIO;
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ static rt_err_t nanddrv_file_write_page(struct rt_mtd_nand_device* device,
|
|||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t nanddrv_file_move_page(struct rt_mtd_nand_device* device, rt_off_t from, rt_off_t to)
|
||||
static rt_err_t nanddrv_file_move_page(struct rt_mtd_nand_device *device, rt_off_t from, rt_off_t to)
|
||||
{
|
||||
rt_uint32_t offset;
|
||||
rt_uint8_t page_buffer[PAGE_SIZE - OOB_SIZE];
|
||||
|
@ -272,8 +272,8 @@ static rt_err_t nanddrv_file_move_page(struct rt_mtd_nand_device* device, rt_off
|
|||
from = from + device->block_start * device->pages_per_block;
|
||||
to = to + device->block_start * device->pages_per_block;
|
||||
|
||||
if (from/device->pages_per_block > device->block_end ||
|
||||
to/device->pages_per_block > device->block_end)
|
||||
if (from / device->pages_per_block > device->block_end ||
|
||||
to / device->pages_per_block > device->block_end)
|
||||
{
|
||||
return -RT_EIO;
|
||||
}
|
||||
|
@ -310,14 +310,14 @@ static rt_err_t nanddrv_file_move_page(struct rt_mtd_nand_device* device, rt_off
|
|||
}
|
||||
|
||||
/* erase block */
|
||||
static rt_err_t nanddrv_file_erase_block(struct rt_mtd_nand_device* device, rt_uint32_t block)
|
||||
static rt_err_t nanddrv_file_erase_block(struct rt_mtd_nand_device *device, rt_uint32_t block)
|
||||
{
|
||||
if (block > BLOCK_NUM) return -RT_EIO;
|
||||
|
||||
/* add the start blocks */
|
||||
block = block + device->block_start * device->pages_per_block;
|
||||
|
||||
fseek(file, block * BLOCK_SIZE, SEEK_SET );
|
||||
fseek(file, block * BLOCK_SIZE, SEEK_SET);
|
||||
fwrite(block_data, sizeof(block_data), 1, file);
|
||||
|
||||
return RT_EOK;
|
||||
|
@ -349,26 +349,26 @@ void rt_hw_mtd_nand_init(void)
|
|||
fseek(file, 0, SEEK_END);
|
||||
size = ftell(file);
|
||||
|
||||
fseek(file, 0, SEEK_SET );
|
||||
fseek(file, 0, SEEK_SET);
|
||||
if (size < BLOCK_NUM * BLOCK_SIZE)
|
||||
{
|
||||
rt_uint32_t index;
|
||||
fseek(file, 0, SEEK_SET );
|
||||
fseek(file, 0, SEEK_SET);
|
||||
for (index = 0; index < BLOCK_NUM; index ++)
|
||||
{
|
||||
fwrite(block_data, sizeof(block_data), 1, file);
|
||||
}
|
||||
}
|
||||
fseek(file, 0, SEEK_SET );
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
ecc_size = (PAGE_SIZE - OOB_SIZE) * 3/256;
|
||||
ecc_size = (PAGE_SIZE - OOB_SIZE) * 3 / 256;
|
||||
_nanddrv_file_device.plane_num = 2;
|
||||
_nanddrv_file_device.oob_size = OOB_SIZE;
|
||||
_nanddrv_file_device.oob_free = OOB_SIZE - ecc_size;
|
||||
_nanddrv_file_device.page_size = PAGE_SIZE - OOB_SIZE;
|
||||
_nanddrv_file_device.pages_per_block = PAGE_PER_BLOCK;
|
||||
_nanddrv_file_device.block_start = 0;
|
||||
_nanddrv_file_device.block_end = BLOCK_NUM/2;
|
||||
_nanddrv_file_device.block_end = BLOCK_NUM / 2;
|
||||
_nanddrv_file_device.block_total = _nanddrv_file_device.block_end - _nanddrv_file_device.block_start;
|
||||
_nanddrv_file_device.ops = &_ops;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
struct sdcard_device
|
||||
{
|
||||
struct rt_device parent;
|
||||
FILE* file;
|
||||
FILE *file;
|
||||
};
|
||||
static struct sdcard_device _sdcard;
|
||||
|
||||
|
@ -43,9 +43,9 @@ static rt_err_t rt_sdcard_close(rt_device_t dev)
|
|||
* buffer:
|
||||
* size : how many blocks
|
||||
*/
|
||||
static rt_size_t rt_sdcard_read(rt_device_t device, rt_off_t position, void* buffer, rt_size_t size)
|
||||
static rt_size_t rt_sdcard_read(rt_device_t device, rt_off_t position, void *buffer, rt_size_t size)
|
||||
{
|
||||
struct sdcard_device * sd;
|
||||
struct sdcard_device *sd;
|
||||
int result = 0;
|
||||
|
||||
SD_TRACE("sd read: pos %d, size %d\n", position, size);
|
||||
|
@ -71,9 +71,9 @@ _err:
|
|||
* buffer:
|
||||
* size : how many blocks
|
||||
*/
|
||||
static rt_size_t rt_sdcard_write(rt_device_t device, rt_off_t position, const void* buffer, rt_size_t size)
|
||||
static rt_size_t rt_sdcard_write(rt_device_t device, rt_off_t position, const void *buffer, rt_size_t size)
|
||||
{
|
||||
struct sdcard_device * sd;
|
||||
struct sdcard_device *sd;
|
||||
int result = 0;
|
||||
|
||||
SD_TRACE("sst write: pos %d, size %d\n", position, size);
|
||||
|
@ -97,7 +97,7 @@ _err:
|
|||
|
||||
static rt_err_t rt_sdcard_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
{
|
||||
struct sdcard_device * sd;
|
||||
struct sdcard_device *sd;
|
||||
unsigned int size;
|
||||
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
|
@ -117,18 +117,18 @@ static rt_err_t rt_sdcard_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
|||
fseek(sd->file, 0, SEEK_END);
|
||||
size = ftell(sd->file);
|
||||
|
||||
geometry->sector_count = size/SECTOR_SIZE;
|
||||
geometry->sector_count = size / SECTOR_SIZE;
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
|
||||
rt_err_t rt_hw_sdcard_init(const char * spi_device_name)
|
||||
rt_err_t rt_hw_sdcard_init(const char *spi_device_name)
|
||||
{
|
||||
int size;
|
||||
rt_uint32_t id, total_block;
|
||||
struct sdcard_device * sd;
|
||||
struct rt_device * device;
|
||||
struct sdcard_device *sd;
|
||||
struct rt_device *device;
|
||||
|
||||
sd = &_sdcard;
|
||||
device = &(sd->parent);
|
||||
|
@ -145,13 +145,13 @@ rt_err_t rt_hw_sdcard_init(const char * spi_device_name)
|
|||
fseek(sd->file, 0, SEEK_END);
|
||||
size = ftell(sd->file);
|
||||
|
||||
fseek(sd->file, 0, SEEK_SET );
|
||||
fseek(sd->file, 0, SEEK_SET);
|
||||
if (size < SDCARD_SIZE)
|
||||
{
|
||||
int i;
|
||||
unsigned char* ptr;
|
||||
unsigned char *ptr;
|
||||
|
||||
ptr = (unsigned char*) malloc (1024 * 1024);
|
||||
ptr = (unsigned char *) malloc(1024 * 1024);
|
||||
if (ptr == NULL)
|
||||
{
|
||||
SD_TRACE("malloc error, no memory!\n");
|
||||
|
@ -161,7 +161,7 @@ rt_err_t rt_hw_sdcard_init(const char * spi_device_name)
|
|||
|
||||
fseek(sd->file, 0, SEEK_SET);
|
||||
|
||||
for(i=0; i<(SDCARD_SIZE / (1024*1024)); i++)
|
||||
for (i = 0; i < (SDCARD_SIZE / (1024 * 1024)); i++)
|
||||
fwrite(ptr, 1024 * 1024, 1, sd->file);
|
||||
|
||||
free(ptr);
|
||||
|
|
|
@ -38,7 +38,7 @@ static rt_err_t sdlfb_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
|||
struct sdlfb_device *device;
|
||||
|
||||
rt_mutex_take(sdllock, RT_WAITING_FOREVER);
|
||||
device = (struct sdlfb_device*)dev;
|
||||
device = (struct sdlfb_device *)dev;
|
||||
RT_ASSERT(device != RT_NULL);
|
||||
RT_ASSERT(device->screen != RT_NULL);
|
||||
|
||||
|
@ -48,7 +48,7 @@ static rt_err_t sdlfb_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
|||
{
|
||||
struct rt_device_graphic_info *info;
|
||||
|
||||
info = (struct rt_device_graphic_info*) args;
|
||||
info = (struct rt_device_graphic_info *) args;
|
||||
info->bits_per_pixel = 16;
|
||||
info->pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
|
||||
info->framebuffer = device->screen->pixels;
|
||||
|
@ -59,7 +59,7 @@ static rt_err_t sdlfb_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
|||
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
||||
{
|
||||
struct rt_device_rect_info *rect;
|
||||
rect = (struct rt_device_rect_info*)args;
|
||||
rect = (struct rt_device_rect_info *)args;
|
||||
|
||||
/* SDL_UpdateRect(_device.screen, rect->x, rect->y, rect->x + rect->w, rect->y + rect->h); */
|
||||
SDL_UpdateRect(_device.screen, 0, 0, device->width, device->height);
|
||||
|
@ -68,9 +68,9 @@ static rt_err_t sdlfb_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
|||
case RTGRAPHIC_CTRL_SET_MODE:
|
||||
{
|
||||
#if 0
|
||||
struct rt_device_rect_info* rect;
|
||||
struct rt_device_rect_info *rect;
|
||||
|
||||
rect = (struct rt_device_rect_info*)args;
|
||||
rect = (struct rt_device_rect_info *)args;
|
||||
if ((_device.width == rect->width) && (_device.height == rect->height)) return -RT_ERROR;
|
||||
|
||||
_device.width = rect->width;
|
||||
|
@ -82,13 +82,13 @@ static rt_err_t sdlfb_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
|||
|
||||
/* re-create screen surface */
|
||||
_device.screen = SDL_SetVideoMode(_device.width, _device.height, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);
|
||||
if ( _device.screen == NULL )
|
||||
if (_device.screen == NULL)
|
||||
{
|
||||
fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
SDL_WM_SetCaption ("RT-Thread/GUI Simulator", NULL);
|
||||
SDL_WM_SetCaption("RT-Thread/GUI Simulator", NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -126,10 +126,10 @@ static void sdlfb_hw_init(void)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
SDL_WM_SetCaption ("RT-Thread/GUI Simulator", NULL);
|
||||
SDL_WM_SetCaption("RT-Thread/GUI Simulator", NULL);
|
||||
rt_device_register(RT_DEVICE(&_device), "sdl", RT_DEVICE_FLAG_RDWR);
|
||||
|
||||
sdllock = rt_mutex_create("fb",RT_IPC_FLAG_FIFO);
|
||||
sdllock = rt_mutex_create("fb", RT_IPC_FLAG_FIFO);
|
||||
}
|
||||
|
||||
#include <windows.h>
|
||||
|
@ -154,7 +154,7 @@ static DWORD WINAPI sdl_loop(LPVOID lpParam)
|
|||
rtgui_graphic_set_device(device);
|
||||
|
||||
/* handle SDL event */
|
||||
while(!quit)
|
||||
while (!quit)
|
||||
{
|
||||
SDL_WaitEvent(&event);
|
||||
|
||||
|
@ -168,8 +168,8 @@ static DWORD WINAPI sdl_loop(LPVOID lpParam)
|
|||
emouse.parent.sender = RT_NULL;
|
||||
emouse.wid = RT_NULL;
|
||||
|
||||
emouse.x = ((SDL_MouseMotionEvent*)&event)->x;
|
||||
emouse.y = ((SDL_MouseMotionEvent*)&event)->y;
|
||||
emouse.x = ((SDL_MouseMotionEvent *)&event)->x;
|
||||
emouse.y = ((SDL_MouseMotionEvent *)&event)->y;
|
||||
|
||||
/* init mouse button */
|
||||
emouse.button = button_state;
|
||||
|
@ -184,13 +184,13 @@ static DWORD WINAPI sdl_loop(LPVOID lpParam)
|
|||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
struct rtgui_event_mouse emouse;
|
||||
SDL_MouseButtonEvent* mb;
|
||||
SDL_MouseButtonEvent *mb;
|
||||
|
||||
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
|
||||
emouse.parent.sender = RT_NULL;
|
||||
emouse.wid = RT_NULL;
|
||||
|
||||
mb = (SDL_MouseButtonEvent*)&event;
|
||||
mb = (SDL_MouseButtonEvent *)&event;
|
||||
|
||||
emouse.x = mb->x;
|
||||
emouse.y = mb->y;
|
||||
|
@ -199,7 +199,7 @@ static DWORD WINAPI sdl_loop(LPVOID lpParam)
|
|||
emouse.button = 0;
|
||||
|
||||
/* set emouse button */
|
||||
if (mb->button & (1 << (SDL_BUTTON_LEFT - 1)) )
|
||||
if (mb->button & (1 << (SDL_BUTTON_LEFT - 1)))
|
||||
{
|
||||
emouse.button |= RTGUI_MOUSE_BUTTON_LEFT;
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ void rt_hw_sdl_start(void)
|
|||
0,
|
||||
CREATE_SUSPENDED,
|
||||
&thread_id);
|
||||
if(thread == NULL)
|
||||
if (thread == NULL)
|
||||
{
|
||||
//Display Error Message
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ extern struct serial_int_rx serial_rx;
|
|||
/**
|
||||
* This function initializes serial
|
||||
*/
|
||||
static rt_err_t rt_serial_init (rt_device_t dev)
|
||||
static rt_err_t rt_serial_init(rt_device_t dev)
|
||||
{
|
||||
if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
|
||||
{
|
||||
|
@ -37,7 +37,8 @@ static rt_err_t rt_serial_init (rt_device_t dev)
|
|||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag){
|
||||
static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag)
|
||||
{
|
||||
#if _DEBUG_SERIAL==1
|
||||
printf("in rt_serial_open()\n");
|
||||
#endif
|
||||
|
@ -51,9 +52,9 @@ static rt_err_t rt_serial_close(rt_device_t dev)
|
|||
#endif
|
||||
return RT_EOK;
|
||||
}
|
||||
static rt_size_t rt_serial_read (rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
|
||||
static rt_size_t rt_serial_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
|
||||
{
|
||||
rt_uint8_t* ptr;
|
||||
rt_uint8_t *ptr;
|
||||
rt_err_t err_code;
|
||||
|
||||
ptr = buffer;
|
||||
|
@ -101,20 +102,21 @@ static rt_size_t rt_serial_read (rt_device_t dev, rt_off_t pos, void* buffer, rt
|
|||
return (rt_uint32_t)ptr - (rt_uint32_t)buffer;
|
||||
}
|
||||
|
||||
static rt_size_t rt_serial_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
|
||||
static rt_size_t rt_serial_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
|
||||
{
|
||||
#if _DEBUG_SERIAL==1
|
||||
printf("in rt_serial_write()\n");
|
||||
#endif
|
||||
printf("%s",(char*)buffer);
|
||||
printf("%s", (char *)buffer);
|
||||
return size;
|
||||
}
|
||||
|
||||
static rt_err_t rt_serial_control (rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t rt_serial_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
{
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
|
||||
switch (cmd){
|
||||
switch (cmd)
|
||||
{
|
||||
case RT_DEVICE_CTRL_SUSPEND:
|
||||
/* suspend device */
|
||||
dev->flag |= RT_DEVICE_FLAG_SUSPENDED;
|
||||
|
@ -132,7 +134,7 @@ static rt_err_t rt_serial_control (rt_device_t dev, rt_uint8_t cmd, void *args)
|
|||
/*
|
||||
* serial register
|
||||
*/
|
||||
static rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t flag)
|
||||
static rt_err_t rt_hw_serial_register(rt_device_t device, const char *name, rt_uint32_t flag)
|
||||
{
|
||||
RT_ASSERT(device != RT_NULL);
|
||||
#if _DEBUG_SERIAL==1
|
||||
|
@ -155,6 +157,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)
|
||||
{
|
||||
return rt_hw_serial_register(&serial_device,RT_CONSOLE_DEVICE_NAME,
|
||||
return rt_hw_serial_register(&serial_device, RT_CONSOLE_DEVICE_NAME,
|
||||
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM);
|
||||
}
|
|
@ -36,21 +36,21 @@
|
|||
struct sst25_mtd
|
||||
{
|
||||
struct rt_mtd_nor_device parent;
|
||||
FILE * file;
|
||||
FILE *file;
|
||||
};
|
||||
static struct sst25_mtd _sst25_mtd;
|
||||
|
||||
static struct rt_mutex flash_lock;
|
||||
|
||||
/* RT-Thread MTD device interface */
|
||||
static rt_uint32_t sst25vfxx_read_id(struct rt_mtd_nor_device* device)
|
||||
static rt_uint32_t sst25vfxx_read_id(struct rt_mtd_nor_device *device)
|
||||
{
|
||||
rt_uint8_t id_recv[3] = {MF_ID, MT_ID, MC_ID_SST25VF016};
|
||||
|
||||
return (id_recv[0] << 16) | (id_recv[1] << 8) | id_recv[2];
|
||||
}
|
||||
|
||||
static int sst25vfxx_read(struct rt_mtd_nor_device* device, rt_off_t position, rt_uint8_t *data, rt_size_t size)
|
||||
static int sst25vfxx_read(struct rt_mtd_nor_device *device, rt_off_t position, rt_uint8_t *data, rt_size_t size)
|
||||
{
|
||||
struct sst25_mtd *sst25;
|
||||
int result;
|
||||
|
@ -69,7 +69,7 @@ static int sst25vfxx_read(struct rt_mtd_nor_device* device, rt_off_t position, r
|
|||
return size;
|
||||
}
|
||||
|
||||
static int sst25vfxx_write(struct rt_mtd_nor_device* device, rt_off_t position,
|
||||
static int sst25vfxx_write(struct rt_mtd_nor_device *device, rt_off_t position,
|
||||
const rt_uint8_t *data, rt_size_t size)
|
||||
{
|
||||
struct sst25_mtd *sst25;
|
||||
|
@ -91,7 +91,7 @@ static int sst25vfxx_write(struct rt_mtd_nor_device* device, rt_off_t position,
|
|||
|
||||
static char block_buffer[BLOCK_SIZE];
|
||||
|
||||
static rt_err_t sst25vfxx_erase_block(struct rt_mtd_nor_device* device, rt_uint32_t block)
|
||||
static rt_err_t sst25vfxx_erase_block(struct rt_mtd_nor_device *device, rt_uint32_t block)
|
||||
{
|
||||
struct sst25_mtd *sst25;
|
||||
int result;
|
||||
|
@ -129,12 +129,12 @@ static rt_err_t sst25vfxx_hw_init(struct sst25_mtd *mtd)
|
|||
/**
|
||||
* SST25vfxx API
|
||||
*/
|
||||
rt_err_t sst25vfxx_mtd_init(const char * nor_name,
|
||||
rt_err_t sst25vfxx_mtd_init(const char *nor_name,
|
||||
rt_uint32_t block_start,
|
||||
rt_uint32_t block_end)
|
||||
{
|
||||
rt_uint32_t id, total_block;
|
||||
struct sst25_mtd * sst25;
|
||||
struct sst25_mtd *sst25;
|
||||
struct rt_mtd_nor_device *mtd;
|
||||
|
||||
|
||||
|
@ -191,7 +191,7 @@ rt_err_t sst25vfxx_mtd_init(const char * nor_name,
|
|||
sst25->file = fopen(NOR_SIM, "wb+");
|
||||
|
||||
memset(block_buffer, 0xFF, sizeof(block_buffer));
|
||||
for(i=0; i<total_block; i++)
|
||||
for (i = 0; i < total_block; i++)
|
||||
{
|
||||
fseek(sst25->file, i * BLOCK_SIZE, SEEK_SET);
|
||||
fwrite(block_buffer, BLOCK_SIZE, 1, sst25->file);
|
||||
|
|
|
@ -27,7 +27,7 @@ void rt_hw_usart_init(void)
|
|||
0,
|
||||
CREATE_SUSPENDED,
|
||||
&OSKey_ThreadID);
|
||||
if(OSKey_Thread == NULL)
|
||||
if (OSKey_Thread == NULL)
|
||||
{
|
||||
//Display Error Message
|
||||
|
||||
|
@ -103,7 +103,7 @@ static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam)
|
|||
|
||||
(void)lpParam; //prevent compiler warnings
|
||||
|
||||
for(;;)
|
||||
for (;;)
|
||||
{
|
||||
key = _getch();//getchar();
|
||||
if (key == 0xE0)
|
||||
|
|
|
@ -14,7 +14,7 @@ SNAKE_DIR prevdir, newdir;
|
|||
|
||||
static SNAKE_DIR dir_adjust(SNAKE_DIR dir)
|
||||
{
|
||||
if ( (SNAKE_DIR_UP == prevdir && SNAKE_DIR_DOWN != dir)
|
||||
if ((SNAKE_DIR_UP == prevdir && SNAKE_DIR_DOWN != dir)
|
||||
|| (SNAKE_DIR_DOWN == prevdir && SNAKE_DIR_UP != dir)
|
||||
|| (SNAKE_DIR_LEFT == prevdir && SNAKE_DIR_RIGHT != dir)
|
||||
|| (SNAKE_DIR_RIGHT == prevdir && SNAKE_DIR_LEFT != dir)
|
||||
|
@ -55,7 +55,7 @@ static SYS_STE node_update(snake_t *tail, const point_t *node, map_t *map)
|
|||
if (FOOD == map->range[node->y * map->width + node->x])
|
||||
{
|
||||
// 吃一个食物增加一个节点
|
||||
snake_t *new = (snake_t*)rt_malloc(sizeof(snake_t));
|
||||
snake_t *new = (snake_t *)rt_malloc(sizeof(snake_t));
|
||||
if (!new)
|
||||
return NORMAL;
|
||||
|
||||
|
@ -85,7 +85,7 @@ static SYS_STE node_update(snake_t *tail, const point_t *node, map_t *map)
|
|||
}
|
||||
|
||||
|
||||
map_t* map_init(rt_uint32_t width, rt_uint32_t heigth)
|
||||
map_t *map_init(rt_uint32_t width, rt_uint32_t heigth)
|
||||
{
|
||||
map_t *map = rt_malloc(sizeof(map_t));
|
||||
|
||||
|
@ -139,9 +139,9 @@ rt_bool_t snake_init(const point_t *start, const int length, const SNAKE_DIR dir
|
|||
old.x -= inc_x;
|
||||
}
|
||||
|
||||
for (i=0; i<length; i++)
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
snake_t *new = (snake_t*)rt_malloc(sizeof(snake_t));
|
||||
snake_t *new = (snake_t *)rt_malloc(sizeof(snake_t));
|
||||
if (!new)
|
||||
return RT_FALSE;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
typedef struct
|
||||
{
|
||||
rt_int32_t x, y;
|
||||
}point_t;
|
||||
} point_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ typedef struct
|
|||
rt_uint8_t *range; // map, map->range[y * map->width + x]
|
||||
point_t snake_flush[2];
|
||||
point_t food_flush[1];
|
||||
}map_t;
|
||||
} map_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -31,23 +31,23 @@ typedef enum
|
|||
SNAKE_DIR_DOWN,
|
||||
SNAKE_DIR_LEFT,
|
||||
SNAKE_DIR_RIGHT
|
||||
}SNAKE_DIR;
|
||||
} SNAKE_DIR;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FOOD, // 吃到水果
|
||||
OVER, // 咬到自身
|
||||
NORMAL // 正常行动
|
||||
}SYS_STE;
|
||||
} SYS_STE;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
point_t body;
|
||||
rt_list_t list;
|
||||
}snake_t;
|
||||
} snake_t;
|
||||
|
||||
// 构造一个地图
|
||||
map_t* map_init(rt_uint32_t width, rt_uint32_t heigth);
|
||||
map_t *map_init(rt_uint32_t width, rt_uint32_t heigth);
|
||||
|
||||
// 构造一条指定长度的蛇在指定点
|
||||
rt_bool_t snake_init(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map);
|
||||
|
|
|
@ -24,7 +24,7 @@ static rt_size_t room_size_x, room_size_y;
|
|||
static rt_size_t lattice_size_x, lattice_size_y;
|
||||
static struct rtgui_rect room_rect, lattice_rect;
|
||||
|
||||
map_t* map;
|
||||
map_t *map;
|
||||
SNAKE_DIR run_state;
|
||||
rt_int32_t snake_len;
|
||||
rt_int32_t food_num;
|
||||
|
@ -67,7 +67,7 @@ static void snake_draw(struct rtgui_widget *widget)
|
|||
}
|
||||
|
||||
/* get room size, run once frist. */
|
||||
if((room_size_x == 0) || (room_size_y == 0))
|
||||
if ((room_size_x == 0) || (room_size_y == 0))
|
||||
{
|
||||
rt_size_t tmp;
|
||||
|
||||
|
@ -133,7 +133,7 @@ static void snake_draw(struct rtgui_widget *widget)
|
|||
RTGUI_DC_FC(dc) = WALL_COLOR;
|
||||
rtgui_dc_draw_rect(dc, &rect);
|
||||
|
||||
for(i=1; i<lattice_size_y; i++)
|
||||
for (i = 1; i < lattice_size_y; i++)
|
||||
{
|
||||
memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect));
|
||||
rect.x1 += 1;
|
||||
|
@ -142,7 +142,7 @@ static void snake_draw(struct rtgui_widget *widget)
|
|||
rect.y1 + (LATTICE_SIZE * i));
|
||||
}
|
||||
|
||||
for(i=1; i<lattice_size_x; i++)
|
||||
for (i = 1; i < lattice_size_x; i++)
|
||||
{
|
||||
memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect));
|
||||
rect.y1 += 1;
|
||||
|
@ -156,9 +156,9 @@ static void snake_draw(struct rtgui_widget *widget)
|
|||
rt_uint32_t x, y;
|
||||
rt_bool_t first_node = RT_TRUE;
|
||||
|
||||
for (y=0; y<map->height; y++)
|
||||
for (y = 0; y < map->height; y++)
|
||||
{
|
||||
for (x=0; x<map->width; x++)
|
||||
for (x = 0; x < map->width; x++)
|
||||
{
|
||||
switch (map->range[y * map->width + x])
|
||||
{
|
||||
|
@ -207,9 +207,9 @@ static void snake_update(struct rtgui_widget *widget)
|
|||
snake_fill_lattice(dc, second_node.x, second_node.y, SNAKE_COLOR);
|
||||
second_node = map->snake_flush[0];
|
||||
|
||||
for(i=0; i<3; i++)
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if(i < 2)
|
||||
if (i < 2)
|
||||
{
|
||||
x = map->snake_flush[i].x;
|
||||
y = map->snake_flush[i].y;
|
||||
|
@ -220,7 +220,7 @@ static void snake_update(struct rtgui_widget *widget)
|
|||
y = map->food_flush[0].y;
|
||||
}
|
||||
|
||||
if((x >= 0) && (y >= 0))
|
||||
if ((x >= 0) && (y >= 0))
|
||||
{
|
||||
switch (map->range[(map->width * y) + x])
|
||||
{
|
||||
|
@ -246,9 +246,9 @@ static void snake_update(struct rtgui_widget *widget)
|
|||
|
||||
static void snake_handler(struct rtgui_widget *widget, rtgui_event_t *event)
|
||||
{
|
||||
struct rtgui_event_kbd* ekbd;
|
||||
struct rtgui_event_kbd *ekbd;
|
||||
|
||||
ekbd = (struct rtgui_event_kbd*) event;
|
||||
ekbd = (struct rtgui_event_kbd *) event;
|
||||
if (ekbd->type == RTGUI_KEYDOWN)
|
||||
{
|
||||
switch (ekbd->key)
|
||||
|
@ -284,38 +284,38 @@ static rt_bool_t event_handler(struct rtgui_object *object, rtgui_event_t *event
|
|||
if (event->type == RTGUI_EVENT_PAINT)
|
||||
{
|
||||
rt_kprintf("RTGUI_EVENT_PAINT\r\n");
|
||||
rtgui_win_event_handler((struct rtgui_object*)object, event);
|
||||
rtgui_win_event_handler((struct rtgui_object *)object, event);
|
||||
snake_draw(widget);
|
||||
rtgui_timer_start(timer);
|
||||
}
|
||||
else if (event->type == RTGUI_EVENT_SHOW)
|
||||
{
|
||||
rt_kprintf("RTGUI_EVENT_SHOW\r\n");
|
||||
rtgui_win_event_handler((struct rtgui_object*)object, event);
|
||||
rtgui_win_event_handler((struct rtgui_object *)object, event);
|
||||
snake_draw(widget);
|
||||
rtgui_timer_start(timer);
|
||||
}
|
||||
else if (event->type == RTGUI_EVENT_HIDE)
|
||||
{
|
||||
rt_kprintf("RTGUI_EVENT_HIDE\r\n");
|
||||
rtgui_win_event_handler((struct rtgui_object*)object, event);
|
||||
rtgui_win_event_handler((struct rtgui_object *)object, event);
|
||||
rtgui_timer_stop(timer);
|
||||
}
|
||||
else if (event->type == RTGUI_EVENT_WIN_DEACTIVATE)
|
||||
{
|
||||
rt_kprintf("RTGUI_EVENT_WIN_DEACTIVATE\r\n");
|
||||
rtgui_win_event_handler((struct rtgui_object*)object, event);
|
||||
rtgui_win_event_handler((struct rtgui_object *)object, event);
|
||||
rtgui_timer_stop(timer);
|
||||
}
|
||||
else if (event->type == RTGUI_EVENT_KBD)
|
||||
{
|
||||
rtgui_win_event_handler((struct rtgui_object*)object, event);
|
||||
rtgui_win_event_handler((struct rtgui_object *)object, event);
|
||||
snake_handler(widget, event);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("event->type:%d\r\n", event->type);
|
||||
return rtgui_win_event_handler((struct rtgui_object*)object, event);
|
||||
return rtgui_win_event_handler((struct rtgui_object *)object, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
|
@ -362,8 +362,8 @@ static void timeout(struct rtgui_timer *timer, void *parameter)
|
|||
|
||||
void snake_main(void)
|
||||
{
|
||||
struct rtgui_app* application;
|
||||
struct rtgui_win* win;
|
||||
struct rtgui_app *application;
|
||||
struct rtgui_win *win;
|
||||
rtgui_rect_t rect;
|
||||
|
||||
application = rtgui_app_create(rt_thread_self(), "sanke_app");
|
||||
|
@ -374,7 +374,7 @@ void snake_main(void)
|
|||
win = rtgui_mainwin_create(RT_NULL,
|
||||
"sanke_win",
|
||||
RTGUI_WIN_STYLE_MAINWIN | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
|
||||
if(win == RT_NULL)
|
||||
if (win == RT_NULL)
|
||||
{
|
||||
rt_kprintf("sanke_win create fail!\r\n");
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue