hal_flash_inf.c
来自「基于ARM和uC/OS-II实现的串口控制台」· C语言 代码 · 共 116 行
C
116 行
/******************************************************************
* File name : hal_flash_dev.c *
* Description : Functions to register a flash device to the *
* "generic" flash interface *
* Others : * *
* Function List : *
* 1. hal_flash_open_dev() *
* 2. hal_flash_close_dev() *
* *
* History: *
* *
* 1. Date : 2006.11.12 *
* Author : Zhijie Zeng *
* Version : 1.0 *
* Description: Created *
******************************************************************/
#include "../../inc/pub/hal_errno.h"
#include "../../inc/pub/hal_llist.h"
#include "../../inc/dev/hal_flash_dev.h"
#include "../../inc/dev/hal_file.h"
HAL_LLIST_HEAD(hal_flash_dev_list);
hal_flash_fd* hal_flash_dev_open(const char* name)
{
hal_flash_dev* dev = (hal_flash_dev*)hal_find_dev(name, &hal_flash_dev_list);
if ((dev) && dev->open)
{
return dev->open(dev, name);
}
return dev;
}
void hal_flash_dev_close(hal_flash_fd* fd)
{
if (fd && fd->close)
{
fd->close(fd);
}
return;
}
int hal_write_flash(
hal_flash_fd* fd,
int offset,
hal_u8* src_addr,
int length )
{
if (fd && fd->write)
{
return fd->write( fd, offset, src_addr, length );
}else
{
return -1;
}
}
/*
* hal_read_flash
*
* 提供本函数的目的是使串行FLASH也能统一到同一个框架中
*/
int hal_read_flash(
hal_flash_fd* fd, int offset,
hal_u8* dest_addr, int length )
{
if (fd && fd->read)
{
return fd->read( fd, offset, dest_addr, length );
}else
{
return -1;
}
}
/*
* hal_get_flash_info
*
* 返回FLASH扇区的信息
*/
int hal_get_flash_info(
hal_flash_fd* fd, flash_region* info,
int* number_of_regions)
{
if (fd && fd->get_info)
{
return fd->get_info( fd, info, number_of_regions);
}else
{
return -1;
}
}
/*
* hal_erase_flash_block
*
* 擦除指定的块或扇区
*/
int hal_erase_flash_block(
hal_flash_fd* fd, int block)
{
int ret_code;
if (fd && fd->erase_block)
{
ret_code = fd->erase_block( fd, block );
return ret_code;
}else
{
return -1;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?