随笔分类 -  代码层面

Talk is cheap, show me the code. 
浅谈CMakeLists.txt 增加软件版本信息(很方便)
摘要:1. 从一个CMakeLists.txt下手,如下:include_directories (${CMAKE_CURRENT_BINARY_DIR}) 应该放在最后,但是在引用lib前。 # @warning here : add the variables we need and set vers 阅读全文
posted @ 2022-12-15 15:41 real-watson 阅读(290) 评论(0) 推荐(0) 编辑
内核定时器以及应用
摘要:1. 内核定时器的作用 当中断触发时,修改定时器时间间隔,进入定时器回调函数,待完成回调则恢复。 2. 定时器嵌入其他数据结构 struct timer_list timer, 这个结构体作为定时器的数据结构,通过jiffies进行时间间隔的配置: mod_timer(&timer,jiffies 阅读全文
posted @ 2022-10-22 15:17 real-watson 阅读(102) 评论(0) 推荐(0) 编辑
共享内存的实现
摘要:1. 共享内存作为进程间通讯的高效方式,在多进程通讯机制中,有信号量、消息队列、套接字和共享内存等方式,但提倡共享内存。 2. 共享内存是一个对内存的读写操作,但其需要增加通讯同步方式,例如通过信号量或者线程锁进行同步,因为读写内存都是两个进程或者一个进程内部的两个线程 进行通讯。谈谈线程锁的目的, 阅读全文
posted @ 2022-10-22 09:30 real-watson 阅读(367) 评论(0) 推荐(0) 编辑
GPIO寄存器读写浅谈
摘要:,1. io 命令的操作 io 进行读取指定地址的数据,从物理地址直接读取,因为该命令是经过虚拟地址转换的,所以可以直接使用, 但在驱动程序中,应当经过ioremap重新偏移正确的虚拟地址,方可读取数据。 2. DS的理解 DataSheet通常都是 Address Mapping 解析一堆寄存器的 阅读全文
posted @ 2022-10-20 14:16 real-watson 阅读(503) 评论(0) 推荐(0) 编辑
设备树浅谈
摘要:1、 话不多说,直奔主题 设备树是Linux系统比较重要的一部分,可谓核心也它,细节也它。从大方面看,简单配置设备树,驱动则起来;从小方面看,配置设备树以及修改驱动程序,驱动挂载起来。 以前的NXP、三星6410以及龙芯开发平台,也结合代理商的协助,都是被驱动化的开发,设备树基本不碰,最多也就是编译 阅读全文
posted @ 2022-10-20 10:20 real-watson 阅读(201) 评论(0) 推荐(0) 编辑
解决curl下载夹带中文的文件
摘要:1. 提供代码 重点关注curl_escape API #include <stdlib.h> #include <stdio.h> #include <sys/stat.h> #include <curl/curl.h> size_t getcontentlengthfunc(void *ptr, 阅读全文
posted @ 2022-10-09 17:51 real-watson 阅读(278) 评论(0) 推荐(0) 编辑
fb的驱动实现
摘要:本博客目的是熟悉fb的原理和驱动实现,只有模仿才有行动。 1. 框架图 此处省略10000字........ 2. 设备树 3. 驱动代码 a 配置这个结构体fbtft_device_display b 在编译kernel需要加入FB的CONFIG 4. 点亮 echo !!!!! > /dev/f 阅读全文
posted @ 2022-08-05 16:50 real-watson 阅读(436) 评论(0) 推荐(0) 编辑
结构体和指针
摘要:1. 结构体地址: #include <stdio.h> #include <stdlib.h> #include <string.h> struct son { int money; }; struct dah { int money; }; struct father { struct son 阅读全文
posted @ 2022-05-12 18:22 real-watson 阅读(43) 评论(0) 推荐(0) 编辑
深入分析链表实现队列流程(看图)
摘要: 阅读全文
posted @ 2022-05-09 15:15 real-watson 阅读(21) 评论(0) 推荐(0) 编辑
浅谈malloc free “机制”(1)
摘要:该情况出现如下error,并且crash进程: 在by bike 过程中,进行内存分配,由于线程没有优先,乱序的启动running, 在by bus 过程中,进行内存分配,此时才进行双方的exits free,导致double free。 时许发生动态的调度变化,按逻辑可以实现单一线程free后再下 阅读全文
posted @ 2022-04-25 13:33 real-watson 阅读(18) 评论(0) 推荐(0) 编辑
vim 实用技巧
摘要:每一个字母都是有特殊的意义,字母的组合更是体现效率, vim作为“丑陋的编辑器”并非不好用,简单而高效。 1. x,u,. 在光标下按下x,则 按下u则撤回上一步操作,按下 . 又恢复操作。 2. yy,p,5 yy,p 左边5 yy, 右边直接空行p,则可以实现完美的复制,附带格式和该死的spac 阅读全文
posted @ 2022-04-13 17:12 real-watson 阅读(110) 评论(0) 推荐(0) 编辑
rockchip 增加uartx的实现
摘要:一、 谈谈驱动实现。(说的轻松) 针对uart,首先想到是驱动程序的实现,什么uart_driver,uart_port和uart_ops,都是一堆初始化的结构体,研究kernel driver的代码: 得到如下的基本流程实现driver: 1. 针对uart_driver,实现uart_regis 阅读全文
posted @ 2022-04-01 11:15 real-watson 阅读(135) 评论(0) 推荐(0) 编辑
浅谈systemd原理和应用
摘要:多不说,直接上代码(可谓配置): [Unit] Description=demo app After=network-is-online.target [Service] Type=Simple ExecStart=/usr/bin/demo [Install] WantedBy=multi-use 阅读全文
posted @ 2022-03-27 10:42 real-watson 阅读(445) 评论(0) 推荐(0) 编辑
浅析memcmp 和 strcmp
摘要:eg: #include <stdio.h> #include <string.h> int main(void) { char string[7] = "ABCDEFG"; char copy[4] = "ABCD"; int ret; ret = memcmp(string,copy,7); p 阅读全文
posted @ 2021-12-21 16:08 real-watson 阅读(66) 评论(0) 推荐(0) 编辑
利用多个sem信号量在线程通讯
摘要:直接上代码,主要用到sem_trywait & sem_post #include<stdio.h> #include<pthread.h> #include<stdlib.h> #include<string.h> #include<semaphore.h> #include<time.h> se 阅读全文
posted @ 2021-12-17 13:47 real-watson 阅读(46) 评论(0) 推荐(0) 编辑
sem信号量与死锁的边缘
摘要:1. 演示一个例子,出现死锁,用strace debug得到 #include<stdio.h> #include<pthread.h> #include<stdlib.h> #include<string.h> #include<semaphore.h> sem_t sem; typedef st 阅读全文
posted @ 2021-12-17 11:33 real-watson 阅读(366) 评论(0) 推荐(0) 编辑
研究一种表驱动法的编程方式
摘要:#include <stdio.h> #include <string.h> typedef void (*func_evt_hdl)(); /*ptr*/ typedef struct _task_list_ { int flag; func_evt_hdl handler; }EVT_HDL_N 阅读全文
posted @ 2021-12-16 22:00 real-watson 阅读(49) 评论(0) 推荐(0) 编辑
select 中的timeout
摘要:1. select 相关man 资料 /* According to POSIX.1-2001 */ #include <sys/select.h> /* According to earlier standards */ #include <sys/time.h> #include <sys/ty 阅读全文
posted @ 2021-12-16 10:50 real-watson 阅读(480) 评论(0) 推荐(0) 编辑
用strace处理程序异常挂死情况
摘要:1. 环境: ubuntu 系统 + strace + vim 2.编写挂死程序:(参考博客) #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <string.h> int main(int argc, c 阅读全文
posted @ 2021-12-08 16:37 real-watson 阅读(159) 评论(0) 推荐(0) 编辑
深入分析地铁优惠公式
摘要:地铁优惠公式(随地转圈): 假设40次地铁次数,原价最低2元,设行程单价为p元。 问题:求p为多少时没有任何优惠。 int original_total_price(unsigned char cnt, unsigned int pirce) { int total; total = (cnt - 阅读全文
posted @ 2021-11-29 16:58 real-watson 阅读(125) 评论(0) 推荐(0) 编辑

 

点击右上角即可分享
微信分享提示