Android各代码层获取系统时间的方法 获取链接 Facebook X Pinterest 电子邮件 其他应用 八月 07, 2017 在Android系统里,各代码层如何去获取系统时间呢?可分别调用如下函数来获取: 在java层,可以使用方法:long now = SystemClock.uptimeMillis(); 在native层,可以使用方法:nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); 在驱动层,可以使用方法:s64 time = ktime_to_us(ktime_get()); 获取链接 Facebook X Pinterest 电子邮件 其他应用 评论
I/O映射之I/O端口 七月 29, 2018 对于外设,操作系统会采用端口映射和内存映射两种方式来对其进行控制,其中端口映射就是操作系统规定好一段地址给指定换上设,其与外设的寄存器按顺序一一对应上。 在Linux内核源码include/asm-generic/io.h头文件里有如下我们对I/O port进行操作的函数: static inline u8 inb(unsigned long addr) { return readb(addr + PCI_IOBASE); } static inline u16 inw(unsigned long addr) { return readw(addr + PCI_IOBASE); } static inline u32 inl(unsigned long addr) { return readl(addr + PCI_IOBASE); } static inline void outb(u8 b, unsigned long addr) { writeb(b, addr + PCI_IOBASE); } static inline void outw(u16 b, unsigned long addr) { writew(b, addr + PCI_IOBASE); } static inline void outl(u32 b, unsigned long addr) { writel(b, addr + PCI_IOBASE); } #define inb_p(addr) inb(addr) #define inw_p(addr) inw(addr) #define inl_p(addr) inl(addr) #define outb_p(x, addr) outb((x), (addr)) #define outw_p(x, addr) outw((x), (addr)) #define outl_p(x, addr) outl((x), (addr)) 分别对应对端口进行读取或写入字节、字、双字大小数据的操作。 该头文件中还有其他的操作函数及宏定义,请自行深入了解。 我们可通过读取/proc/ioports文件来了解Linux里I/O端口的映射... 阅读全文
内核线程之User-Mode Helpers 八月 02, 2018 这次学习下如何在Linux内核态执行用户态程序,这就要用到User-Mode Helpers,为什么要这么“逆操作”呢?有些与平常用户态系统调用内核态反着来,其实在U盘热插拔时,就需要用到该功能了,当U盘插入时,驱动识别到U盘设备,最终需要调用用户态的程序和设定好的规则来将其挂载起来,还有其他的应用场景也需要这样的操作,自己好好探索下吧。 接下来说说关于User-Mode Helpers,下面是相关的函数(在kernel/kmod.c文件中有定义,下面只给出函数头和函数体较少的代码): 1.call_usermodehelper_setup struct subprocess_info *call_usermodehelper_setup(char *path, char **argv, char **envp, gfp_t gfp_mask, int (*init)(struct subprocess_info *info, struct cred *new), void (*cleanup)(struct subprocess_info *info), void *data) ; 2.call_usermodehelper_exec int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait) ; 3.call_usermodehelper int call_usermodehelper(char *path, char **argv, char **envp, int wait) { struct subprocess_info *info; gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL; info = call_usermodehelper_setup(path, argv, envp, gfp_mask, NULL, NULL, NULL); if (info == NULL) re... 阅读全文
HomeAssistant无法运行解决方法 七月 17, 2018 按照https://www.hachina.io/docs/355.html安装Home Assistant后,执行hass --open-ui命令,提示如下: Home Assistant requires at least Python 3.5.3 查了资料,参考了https://community.home-assistant.io/t/python-3-5-3-on-synology/46372/2,执行如下命令重新安装指定版本的Home Assistant: python3 -m pip install homeassistant==0.64.3 阅读全文
评论
发表评论