task_man.h

  name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-5572165936844014&dt=1194442938015&lmt=1194190197&format=336x280_as&output=html&correlator=1194442937843&url=file%3A%2F%2F%2FC%3A%2FDocuments%2520and%2520Settings%2Flhh1%2F%E6%A1%8C%E9%9D%A2%2FCLanguage.htm&color_bg=FFFFFF&color_text=000000&color_link=000000&color_url=FFFFFF&color_border=FFFFFF&ad_type=text&ga_vid=583001034.1194442938&ga_sid=1194442938&ga_hid=1942779085&flash=9&u_h=768&u_w=1024&u_ah=740&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="336" scrolling="no" height="280" allowtransparency="allowtransparency"> #define IDM_EXIT           100
#define IDM_TEST           200
#define IDM_ABOUT          301

LRESULT CALLBACK WndProc  (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About    (HWND, UINT, WPARAM, LPARAM);

// SPDX-License-Identifier: GPL-2.0 #include <linux/syscalls.h> #include <linux/pid.h> #include <linux/perf_event.h> #include <linux/hw_breakpoint.h> #include <linux/sched.h> #include <linux/slab.h> #include <asm/fpsimd.h> #include <linux/thread_info.h> #include <linux/uaccess.h> // 新增用户态访问头文件 static struct perf_event *bp; static void hit_handler(struct perf_event *bp, struct perf_sample_data *data, struct pt_regs *regs) { int i; struct user_fpsimd_state fp; struct task_struct *current_task = current; pr_info("=== HWBP hit @%p ===\n", (void *)regs->pc); /* 通用寄存器 */ for (i = 0; i < 31; ++i) pr_info("X%-2d = 0x%016llx\n", i, regs->regs[i]); pr_info("SP = 0x%016llx\n", regs->sp); pr_info("PC = 0x%016llx\n", regs->pc); pr_info("LR = 0x%016llx\n", regs->regs[30]); /* 浮点寄存器:5.15+ 正确方式 */ if (!user_mode(regs)) { fpsimd_save_state(&fp); // 内核态直接保存 } else { // 用户态需通过线程信息访问 memcpy(&fp, &current_task->thread.uw.fpsimd_state, sizeof(fp)); } pr_info("【浮点寄存器 S0-S31 (32-bit)】\n"); for (i = 0; i < 32; ++i) pr_info("S%-2d = 0x%08x\n", i, (u32)(fp.vregs[i] & 0xFFFFFFFF)); pr_info("【浮点寄存器 D0-D31 (64-bit)】\n"); for (i = 0; i < 32; ++i) pr_info("D%-2d = 0x%016llx\n", i, fp.vregs[i]); pr_info("【命中地址】PC = 0x%016llx\n", regs->pc); pr_info("【返回地址】LR = 0x%016llx\n", regs->regs[30]); } SYSCALL_DEFINE4(process_vm_writev, int, pid, unsigned long long, addr, int, len, int, type) { struct perf_event_attr attr = {}; struct pid *pid_struct; struct task_struct *tsk; if (bp && !IS_ERR(bp)) { unregister_hw_breakpoint(bp); bp = NULL; } pid_struct = find_get_pid(pid); if (!pid_struct) return -ESRCH; tsk = get_pid_task(pid_struct, PIDTYPE_PID); put_pid(pid_struct); if (!tsk) return -ESRCH; attr.type = PERF_TYPE_BREAKPOINT; attr.size = sizeof(attr); attr.bp_addr = addr; attr.bp_len = (len == 8) ? HW_BREAKPOINT_LEN_8 : HW_BREAKPOINT_LEN_4; switch (type) { case 0: attr.bp_type = HW_BREAKPOINT_R; break; case 1: attr.bp_type = HW_BREAKPOINT_W; break; case 2: attr.bp_type = HW_BREAKPOINT_RW; break; case 3: attr.bp_type = HW_BREAKPOINT_X; break; default: return -EINVAL; } // 5.15+ 正确参数顺序(新增 group 参数) bp = register_wide_hw_breakpoint(&attr, hit_handler, NULL, tsk, NULL); return IS_ERR(bp) ? PTR_ERR(bp) : 0; }报错:root@localhost:~/5.15-13# tools/bazel run //common:kernel_aarch64_dist --config=fast INFO: Analyzed target //common:kernel_aarch64_dist (0 packages loaded, 0 targets configured). INFO: Found 1 target... ERROR: /root/5.15-13/common/BUILD.bazel:52:22: Building kernel kernel_aarch64 failed: (Exit 2): bash failed: error executing command (from target //common:kernel_aarch64) /bin/bash -c ... (remaining 1 argument skipped) /root/5.15-13/common/kernel/sys.c:3032:60: error: too many arguments to function call, expected 3, have 5 bp = register_wide_hw_breakpoint(&attr, hit_handler, NULL, tsk, NULL); ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~ /root/5.15-13/common/include/linux/hw_breakpoint.h:70:1: note: 'register_wide_hw_breakpoint' declared here register_wide_hw_breakpoint(struct perf_event_attr *attr, ^ 1 error generated. make[2]: *** [/root/5.15-13/common/scripts/Makefile.build:287: kernel/sys.o] Error 1 make[1]: *** [/root/5.15-13/common/Makefile:1953: kernel] Error 2 make: *** [Makefile:244: __sub-make] Error 2 Target //common:kernel_aarch64_dist failed to build Use --verbose_failures to see the command lines of failed build steps. ERROR: /root/5.15-13/common/BUILD.bazel:52:22 Middleman _middlemen/common_Skernel_Uaarch64_Udist-runfiles failed: (Exit 2): bash failed: error executing command (from target //common:kernel_aarch64) /bin/bash -c ... (remaining 1 argument skipped) INFO: Elapsed time: 39.149s, Critical Path: 38.07s INFO: 4 processes: 4 internal. FAILED: Build did NOT complete successfully FAILED: Build did NOT complete successfully root@localhost:~/5.15-13# 修复好完整发给我 要求可以给任意进程硬件断点 中文注释
最新发布
07-20
/** ******************************************************************************************************** * @file key.c * @author qiyiqi * @brief 按键驱动代码 * MCU: STM32F103ZE开发板 * 按键原理: 设置一个1ms定时器定时扫描几个按键的状态,并分别记录按下的持续时间,通过时间可以判断是长按还是 * 短按。 * 注意事项: 此代码只是作为一个参考例程,如果不使用STM32的标准库,移植到其他MCU或者HAL库之类的,主要修改的 * 地方在初始化函数key_init(),按键读取函数read_key_state(),定时器初始化以及中断服务函数等。 ******************************************************************************************************** */ #include "key.h" #include "stdio.h" // 按键列表 key_gpio_t key_list[] = {// 端口号,引脚号,有效电平 {KEY1_PORT, KEY1_PIN, 0}, // 按下为0,松开为1 {KEY2_PORT, KEY2_PIN, 0}, {KEY3_PORT, KEY3_PIN, 0}, // 按下为1,松开为0 {KEY4_PORT, KEY4_PIN, 1}, /* 可以继续往下添加更多按键 */ }; // 按键数量 #define KEY_NUM_MAX (sizeof(key_list)/sizeof(key_list[0])) #define CONFIRM_TIME 20 // 消抖时间 ms #define LONG_PRESS_TIME 2000 // 长按时间 ms // 按键配置 #define SHORT_RELEASE_VALID 1 // 0:短按按下时即刻生效,1:短按释放时生效,注意:如果配成0的话,长按的时候就一定会先触发短按 #define LONG_RELEASE_VALID 1 // 0:长按按下时即刻生效,1:长按释放时生效 key_param_t key_param[KEY_NUM_MAX]; // 保存所有按键的状态 // 读取按键状态 uint8_t read_key_state(uint8_t index) { if(GPIO_ReadInputDataBit(key_list[index].port, key_list[index].pin) == key_list[index].pressed_state) {// 按键按下 return 1; } return 0; } // 扫描单个按键状态(需要按1ms频率扫描) uint8_t key_scan(void) { uint8_t key_press; uint8_t index; for(index = 0; index < KEY_NUM_MAX; index++) {// 根据按键列表依次扫描 key_press = read_key_state(index); // 读取按键状态 switch (key_param[index].current_state) {// 按键状态机 case KEY_RELEASE:{// 释放状态 if(key_press) {// 按键按下 key_param[index].current_state = KEY_CONFIRM; } else {// 按键松开 key_param[index].pressed_time = 0; } break; } case KEY_CONFIRM:{// 按键消抖 if(key_press) {// 按键保持按下 if(++key_param[index].pressed_time > CONFIRM_TIME) // 10ms {// 完成消抖 key_param[index].current_state = KEY_SHORT_PRESSED; #if (SHORT_RELEASE_VALID == 0) // 短按按下立马生效 key_param[index].key_event = EVENT_SHORT_PRESSED; // 短按事件生效 #endif } } else {// 按键松开 key_param[index].current_state = KEY_RELEASE; } break; } case KEY_SHORT_PRESSED:{// 短按 if(key_press) {// 按键保持按下 if(++key_param[index].pressed_time > LONG_PRESS_TIME) // 2000ms {// 长按 key_param[index].current_state = KEY_LONG_PRESSED; #if (LONG_RELEASE_VALID == 0) // 长按按下立马生效 key_param[index].key_event = EVENT_LONG_PRESSED; // 长按事件生效 #endif } } else {// 按键松开 key_param[index].current_state = KEY_RELEASE; #if (SHORT_RELEASE_VALID == 1) // 短按释放才生效 key_param[index].key_event = EVENT_SHORT_PRESSED; // 短按事件生效 #endif } break; } case KEY_LONG_PRESSED:{// 长按 if(!key_press) {// 按键松开 key_param[index].current_state = KEY_RELEASE; #if (LONG_RELEASE_VALID == 1) // 长按释放才生效 key_param[index].key_event = EVENT_LONG_PRESSED; // 长按事件生效 #endif } break; } default:{ key_param[index].current_state = KEY_RELEASE; } } } return 0; } // 按键处理函数 void key_handle(void) { uint8_t index; for (index = 0; index < KEY_NUM_MAX; index++) {// 检查有无按键按下 if(key_param[index].key_event != 0) {// 有按键按下 switch (index) { case 0:{// 按键1 if(key_param[index].key_event == EVENT_SHORT_PRESSED) {// 短按 printf("KEY1 SHORT PRESSED\n"); } else if(key_param[index].key_event == EVENT_LONG_PRESSED) {// 长按 printf("KEY1 LONG PRESSED\n"); } break; } case 1:{// 按键2 if(key_param[index].key_event == EVENT_SHORT_PRESSED) {// 短按 printf("KEY2 SHORT PRESSED\n"); } else if(key_param[index].key_event == EVENT_LONG_PRESSED) {// 长按 printf("KEY2 LONG PRESSED\n"); } break; } case 2:{// 按键3 if(key_param[index].key_event == EVENT_SHORT_PRESSED) {// 短按 printf("KEY3 SHORT PRESSED\n"); } else if(key_param[index].key_event == EVENT_LONG_PRESSED) {// 长按 printf("KEY3 LONG PRESSED\n"); } break; } case 3:{// 按键4 if(key_param[index].key_event == EVENT_SHORT_PRESSED) {// 短按 printf("KEY4 SHORT PRESSED\n"); } else if(key_param[index].key_event == EVENT_LONG_PRESSED) {// 长按 printf("KEY4 LONG PRESSED\n"); } break; } default:{ break; } } key_param[index].key_event = EVENT_NULL; // 清除该事件 } } } // 定时器中断服务程序(用于定时扫描按键) void TIM3_IRQHandler(void) { if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) // 检查TIM3更新中断发生与否 { key_scan(); // 扫描按键 TIM_ClearITPendingBit(TIM3, TIM_IT_Update); // 清除TIMx更新中断标志 } } // 定时器初始化(定时1ms) void key_timer_init(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //时钟使能 //定时器TIM3初始化 TIM_TimeBaseStructure.TIM_Period = 1000 - 1; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值 TIM_TimeBaseStructure.TIM_Prescaler = SystemCoreClock / 1000000 - 1; //设置用来作为TIMx时钟频率除数的预分频值 TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //设置时钟分割:TDTS = Tck_tim TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上计数模式 TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //根据指定的参数初始化TIMx的时间基数单位 TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE ); //使能指定的TIM3中断,允许更新中断 //中断优先级NVIC设置 NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3中断 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //先占优先级0级 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //从优先级3级 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能 NVIC_Init(&NVIC_InitStructure); //初始化NVIC寄存器 TIM_Cmd(TIM3, ENABLE); //使能TIMx } // 按键引脚初始化 void key_gpio_init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOE, ENABLE); GPIO_InitStructure.GPIO_Pin = KEY1_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(KEY1_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = KEY2_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(KEY2_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = KEY3_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(KEY3_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = KEY4_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(KEY4_PORT, &GPIO_InitStructure); } // 按键初始化 void key_init(void) { key_gpio_init(); key_timer_init(); } 修改上面的代码,用RTX的软件定时器进行消抖和区分长短压
07-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值