目标
我正在开发一个运行Linux的简单设备.它具有BLE功能,我目前正在使用bluez 5.8.
我想使用iPhone触发此设备上的操作.
什么有效:
我在linux上设置了这样的蓝牙设备(感谢这个问题):
# activate bluetooth
hciconfig hci0 up
# set advertise data: "hello world"
hcitool -i hci0 cmd 0x08 0x0008 48 45 4c 4c 4f 57 4f 52 4c 44
# start advertising as connectable
hciconfig hci0 leadv 0
Run Code Online (Sandbox Code Playgroud)
iOS代码很简单:
- (int) scanForPeripherals
{
if (self->centralManager.state != CBCentralManagerStatePoweredOn) {
return -1;
}
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
[self.centralManager scanForPeripheralsWithServices:nil options:options];
return 0;
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
if (central.state …Run Code Online (Sandbox Code Playgroud) 我正在尝试为linux内核中的GPIO编写一个简单的中断处理程序.我request_threaded_irq用来获取一个中断上下文处理程序和一个线程处理程序.
我的问题是线程处理程序完成的工作对调用中断处理程序的时间有很大影响.
设置中断的代码是:
gpio_request(93, "test")
gpio_direction_input(93);
gpio_request(33, "mirror");
gpio_direction_output(33, 1);
request_threaded_irq(gpio_to_irq(93),
interrupt_handler,
threaded_interrupt_handler,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_TIMER,
"test", NULL);
Run Code Online (Sandbox Code Playgroud)
在这里,我只是要求gpio 93在上升沿和下降沿触发中断.我还要求gpio 33用作镜子,见下文.
(在我的设置中,我在gpio 93上放了一个时钟源).
中断处理程序的代码是这样的:
static irqreturn_t interrupt_handler(int irq, void *data)
{
int state = gpio_get_value(93);
gpio_set_value(33, state);
return IRQ_WAKE_THREAD;
}
Run Code Online (Sandbox Code Playgroud)
这里,中断处理程序只是将gpio 93输入值镜像为gpio 33的输出值.这使我可以监视调用的有效速率interrupt_handler.
最后,线程处理程序:
static irqreturn_t threaded_interrupt_handler(int irq, void *data)
{
/* doing msleep here is apparently problematic... */
msleep(1);
return IRQ_HANDLED;
}
Run Code Online (Sandbox Code Playgroud)
在线程中断处理程序中,调用msleep(或实际执行工作)是有问题的:通过在gpio输出33处查看范围,我可以看到interrupt_handler当threaded_interrupt_handler休眠或执行太多工作时回调率急剧变化.
我如何设置/使用,request_threaded_irq()以便中断处理程序始终被称为"按时",即使线程处理程序作为一些大工作要做?