初始提交
This commit is contained in:
		
							
								
								
									
										61
									
								
								Project/Src/lib/libc.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								Project/Src/lib/libc.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | ||||
| #ifndef libc_h__ | ||||
| #define libc_h__ | ||||
|  | ||||
|  | ||||
|  | ||||
| // 定义设备文件 | ||||
| typedef struct | ||||
| { | ||||
|   const char *name; | ||||
|   int (*open)(void); | ||||
|   int (*close)(void); | ||||
|   int (*putc)(int); | ||||
|   int (*getc)(void); | ||||
|   int (*write)(const void *,int); | ||||
|   int (*read)(void *,int); | ||||
|    | ||||
| }libc_device_file; | ||||
|  | ||||
|  | ||||
| // 使用这个宏用于初始化 | ||||
| #define extern_device(name_,putc_,getc_,write_,read_)\ | ||||
|   const char __libc_##name_[] __attribute__((section("name"))) = #name_;\ | ||||
|   __attribute__((used)) const libc_device_file __libc_dev_##name_ __attribute__((section("libc_dev")))=\ | ||||
|   {\ | ||||
|     .name=__libc_##name_,\ | ||||
|     .putc=putc_,\ | ||||
|     .getc=getc_,\ | ||||
|     .write=write_,\ | ||||
|     .read=read_,\ | ||||
|   }; | ||||
|    | ||||
|    | ||||
| // 使用这个宏用于初始化,包括打开关闭函数 | ||||
| #define extern_device2(name_,open_,close_,putc_,getc_,write_,read_)\ | ||||
|   const char __libc_##name_[] __attribute__((section("name"))) = #name_;\ | ||||
|   __attribute__((used)) const libc_device_file __libc_dev_##name_ __attribute__((section("libc_dev")))=\ | ||||
|   {\ | ||||
|     .name=__libc_##name_,\ | ||||
|     .open=open_,\ | ||||
|     .close=close_,\ | ||||
|     .putc=putc_,\ | ||||
|     .getc=getc_,\ | ||||
|     .write=write_,\ | ||||
|     .read=read_,\ | ||||
|   }; | ||||
|  | ||||
|  | ||||
| #define dev(name_) __libc_dev_##name_ | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| #endif | ||||
|  | ||||
		Reference in New Issue
	
	Block a user