当前位置:网站首页>【sylixos】NEW_1 型字符驱动示例
【sylixos】NEW_1 型字符驱动示例
2022-06-27 23:57:00 【zhaqonianzhu】
SylixOS下的驱动分为ORIG 和 NEW_1 两种类型,本次分享的是NEW_1 型驱动示例
字符驱动框架
字符驱动就是驱动先写好代码用结构体进行保存函数,并用全局年变量来标识这个驱动,后面添加设备时候,设备可用这个全局变量找打驱动,设备的参数作为参数进入到函数运行。
分为几个步骤:
- 安装驱动
- 注册设备
- 使用设备
安装驱动
static LONG __Open (PLW_DEV_HDR pDevHdr, PCHAR pcName, INT iFlags, INT iMode)
{
PLW_FD_NODE pFdNode;
BOOL bIsNew;
DEV* pdev = (DEV*)pDevHdr;
if (LW_NULL == pcName) {
_ErrorHandle(ERROR_IO_NO_DEVICE_NAME_IN_PATH);
return (PX_ERROR);
} else {
pFdNode = API_IosFdNodeAdd(&pdev ->fdNodeHeader, (dev_t)pdev , 0,
iFlags, iMode, 0, 0, 0, LW_NULL, &bIsNew);
if (LW_NULL == pFdNode) {
return (PX_ERROR);
}
if (1 == LW_DEV_INC_USE_COUNT(&pdev ->devHdr)) {
return ((LONG)pFdNode);
}
}
/* * 如果设备打开失败进行如下操作 */
if (pFdNode) {
API_IosFdNodeDec(&pdev ->fdNodeHeader, pFdNode, LW_NULL);
pFdNode = LW_NULL;
}
LW_DEV_DEC_USE_COUNT(&pdev ->devHdr);
return (PX_ERROR);
}
static INT __Close (PLW_FD_ENTRY pFdEntry)
{
DEV* pdev = (PEMC14_CHAN)pFdEntry->FDENTRY_pdevhdrHdr;
PLW_FD_NODE pFdNode = (PLW_FD_NODE)pFdEntry->FDENTRY_pfdnode;
if (pFdEntry && pFdNode) {
API_IosFdNodeDec(&pdev ->fdNodeHeader, pFdNode, LW_NULL);
LW_DEV_DEC_USE_COUNT(&pdev ->devHdr);
return (ERROR_NONE);
}
return (PX_ERROR);
}
static INT __Ioctl (PLW_FD_ENTRY pFdEntry, INT iCmd, LONG lArg)
{
return (ERROR_NONE);
}
INT DrvInstall (VOID)
{
struct file_operations fileop;
if (_G_DrvNum > 0) {
return (ERROR_NONE);
}
lib_memset(&fileop, 0, sizeof(struct file_operations));
fileop.owner = THIS_MODULE;
fileop.fo_create = __Open;
fileop.fo_open = __Open;
fileop.fo_close = __Close;
fileop.fo_ioctl = __Ioctl;
_G_DrvNum = iosDrvInstallEx2(&fileop, LW_DRV_TYPE_NEW_1);
DRIVER_LICENSE(_G_DrvNum, "xxx");
DRIVER_AUTHOR(_G_DrvNum, "xxx");
DRIVER_DESCRIPTION(_G_DrvNum, "xxx driver.");
return ((_G_DrvNum > 0) ? (ERROR_NONE) : PX_ERROR));
}
_G_DrvNum 用来记录驱动号,设备使用时候用这个获取操作集的函数
注册设备
typedef struct {
LW_DEV_HDR devHdr;
LW_LIST_LINE_HEADER fdNodeHeader;
LW_OBJECT_HANDLE hDevLock;
PCHAR pcIoDevName;
} DEV;
DEV dev;
DEV* pdev;
iosDevAddEx(&pdev->devHdr, pdev->pcIoDevName, _G_DrvNum, DT_CHR))
边栏推荐
- 怎样能低成本构建一个电商平台
- Ai+ clinical trial patient recruitment | massive bio completed round a financing of $9million
- The practice of dual process guard and keeping alive in IM instant messaging development
- I/o limit process and CPU limit process
- TIA botu_ Concrete method of making analog input and output Global Library Based on SCL language
- Overview of drug discovery-01 overview of drug discovery
- What problems should be evaluated before implementing MES management system
- Set集合用法
- Drug interaction prediction based on learning size adaptive molecular substructure
- 零基础多图详解图神经网络
猜你喜欢

Adobe Premiere Basics - common video effects (corner positioning, mosaic, blur, sharpen, handwriting tools, effect control hierarchy) (16)

LMSOC:一种对社会敏感的预训练方法

1382. 将二叉搜索树变平衡-常规方法

机器学习笔记 - 时间序列作为特征

Implementation of timed tasks in laravel framework

Adobe Premiere Basics - common video effects (cropping, black and white, clip speed, mirroring, lens halo) (XV)

Evaluation - rank sum ratio comprehensive evaluation

面试官问:JS的继承

Import the data table in MySQL into Excel

The research group of Xuyong and duanwenhui of Tsinghua University has developed an efficient and accurate first principles electronic structure deep learning method and program
随机推荐
. Mp4 video test address
Can you open an account for stock trading in flush? Is it safe?
Qu'est - ce que la numérisation? Qu'est - ce que la transformation numérique? Pourquoi les entreprises choisissent - elles la transformation numérique?
Review of drug discovery-02-prediction of molecular properties
Neural network of zero basis multi map detailed map
万字长文看懂商业智能(BI)|推荐收藏
Lodash realizes anti shake and throttling functions and native implementation
I/o limit process and CPU limit process
Réseau neuronal pour la solution détaillée Multi - diagrammes de fondation zéro
Implementation of timed tasks in laravel framework
Set集合用法
Li Kou today's question -522 Longest special sequence
Adobe Premiere Basics - common video effects (cropping, black and white, clip speed, mirroring, lens halo) (XV)
DeepMind | 通过去噪来进行分子性质预测的预训练
Lmsoc: a socially sensitive pre training method
完全二叉树的节点个数[非O(n)求法 -> 抽象二分]
有监督、无监督与半监督学习
[embedded foundation] memory (cache, ram, ROM, flash)
pytorch_ lightning. utilities. exceptions. MisconfigurationException: You requested GPUs: [1] But...
PV操作原语