所以我正在尝试编写一个使用linux/timer.h文件的内核模块.我让它在模块内部工作,现在我试图让它从用户程序开始工作.
这是我的内核模块:
//Necessary Includes For Device Drivers.
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/proc_fs.h>
#include <asm/uaccess.h>
#include <linux/timer.h>
#include <linux/ioctl.h>
#define DEVICE_NAME "mytimer"
#define DEVICE_FILE_NAME "mytimer"
#define MAJOR_NUM 61
#define MINOR_NUM 0
MODULE_LICENSE("Dual BSD/GPL");
static struct timer_list my_timer;
struct file_operations FileOps =
{
//No File Operations for this timer.
};
//Function to perform when timer expires.
void TimerExpire(int data)
{
printk("Timer Data: %d\n", data);
}
//Function to set up timers.
void TimerSetup(void)
{
setup_timer(&my_timer, TimerExpire, …
Run Code Online (Sandbox Code Playgroud) 我需要对1 us水平进行精确定时,以计算pwm波的占空比变化.
背景
我正在使用Gumstix Over Water COM(https://www.gumstix.com/store/app.php/products/265/),它有一个运行在499.92 BogoMIPS的单核ARM Cortex-A8处理器(Gumstix页面声称根据/ proc/cpuinfo,推荐使用800Mhz的1Ghz.操作系统是基于内核版本2.6.34的Linux的Angstrom Image版本,它在Gumstix Water COM上有库存.
问题
我已经对Linux中的精确计时做了相当多的阅读(并且已经尝试了大部分计划)并且共识似乎是使用clock_gettime()并引用CLOCK_MONOTONIC是最好的方法.(我本来希望使用RDTSC寄存器进行定时,因为我有一个具有最小省电能力的内核,但这不是Intel处理器.)所以这里是奇数部分,而clock_getres()返回1,表明分辨率为1 ns实际的时序测试表明,最小分辨率为30517ns或(它不能重合)恰好是32.768KHz时钟周期之间的时间.这就是我的意思:
// Stackoverflow example
#include <stdio.h>
#include <time.h>
#define SEC2NANOSEC 1000000000
int main( int argc, const char* argv[] )
{
// //////////////// Min resolution test //////////////////////
struct timespec resStart, resEnd, ts;
ts.tv_sec = 0; // s
ts.tv_nsec = 1; // ns
int iters = 100;
double resTime,sum = 0;
int i;
for (i = 0; i<iters; i++)
{
clock_gettime(CLOCK_MONOTONIC, &resStart); // start timer …
Run Code Online (Sandbox Code Playgroud) 我试图在我的Ubuntu笔记本电脑上用以下命令在qemu中运行Yocto Image.
qemu-system-arm -M overo -m 256 -sd ./test.img -clock unix -serial stdio -device usb-mouse -device usb-kbd
Run Code Online (Sandbox Code Playgroud)
Qemu工作正常,图像启动很干净,但我无法使用键盘和鼠标.在任何按键上我都会收到此警告.
usb-kbd: warning: key event queue full
Run Code Online (Sandbox Code Playgroud)
这个没有响应的键盘的任何解决方法?