⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chdev.c

📁 Bycore是一个嵌入式操作系统内核。Bycore包括内存管理、任务管理、中断管理、任务互斥、同步与通信管理等功能。Bycore全部由C语言完成
💻 C
字号:
/** *  chdev.c - Related calls for char device driver * *  Copyright (C) 2008  ZhangHu *  All rights reserved. *  E-MAIL: anmnmnly@gmail.com * *  This program is free software: you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation, either version 3 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program.  If not, see <http://www.gnu.org/licenses/>. */#include "include/types.h"#include "include/list.h"#include "include/mem.h"#include "include/irq.h"#include "drivers/chdev.h"#include "common/string.h"/** * chdevRegister - Register a device to Bycore. * @Mid: Main ID. * @Sid: Secondary ID. * @Name: Device name. * @Operation: Pointer to operations of device. * @return: DEV_OK if successful, otherwise reasons about failure. * * @notes: */word_t chdevRegister(char_t Mid, char_t Sid,                     const char_t *Name,                     struct chdev_operations *Operation) {    chdev_t *pchdev;    if(Mid >= DEVICE_NR) {        return DEV_FALSE;    }    if((pchdev = (chdev_t*)kmalloc(sizeof(chdev_t))) == NULL) {        return DEV_NO_MEM;    }    pchdev->op = Operation;    pchdev->loff = 0;    return char_device_register(&pchdev->dev, Name, Mid, Sid);}/** * chdevUnRegister - Unregister a device from Bycore. * @Mid: Main ID. * @Sid: Secondary ID. * @return: DEV_OK if successful, otherwise DEV_FALSE. * * @notes: */word_t chdevUnRegister(uword_t chdevMID, uword_t chdevSID) {    chdev_t *pchdev;    device_t *dev;    if((dev = device_delete(chdevMID, chdevSID)) == NULL) {        return DEV_FALSE;    }    pchdev = (chdev_t*)dev;    if(pchdev->op->release != NULL)    {        pchdev->op->release();    }    kfree(pchdev);    return DEV_OK;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -