You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

70 lines
1.7 KiB

#ifndef __KERNEL_h
#define __KERNEL_h
#include "common.h"
#define kernel_section_name "kernel_xjm"
#define KERNEL_TYPE static
#define K_SUCCESS 0
#define K_FAIL -1 //执行错误
#define K_NOFOUND -2 //未找到
#define k_OPEN_FAIL -3 //设备存在,但打开失败
#define K_PARAM_ERR -4 //输入参数错误
#define K_UNOPEN -5 //设备未打开
#define K_OPS_NULL -6 //设备接口未实现
#define K_TIMEOUT -7 //执行超时
#define KERNEL_DEVICE_INIT(device_name) \
KERNEL_TYPE const char kernel_device_name[] = device_name; \
KERNEL_TYPE int kernel_device_status = FALSE;
#define KERNEL_CHECK_OPEN \
if (kernel_device_status == FALSE) return K_UNOPEN; \
//内核框架
typedef struct
{
int (*f_open)(int flags);
int (*f_write)(unsigned char *buff, unsigned int len, void *param);
int (*f_read)(unsigned char *buff, unsigned int len, void *param);
int (*f_ioctl)(unsigned int cmd, unsigned long arg);
int (*f_close)(void);
int (*f_isopen)(void);
} file_operations;
typedef struct
{
char *filename;
file_operations *ops;
} KENERAL_NODE;
#define register_driver(ops) \
static const KENERAL_NODE kernel_node = {(char *)kernel_device_name, (file_operations *)&ops}; \
static const int kernel_mem_node __attribute__((used, section(kernel_section_name))) = (int)&kernel_node;
int open(char *filename, int flags);
int write(int handle, unsigned char *buff, unsigned int len, void *param);
int read(int handle, unsigned char *buff, unsigned int len, void *param);
int ioctl(int handle, unsigned int cmd, unsigned long arg);
int close(int handle);
int isopen(int handle);
#endif