Newbird到EventLoop和Thread。需要帮忙。我的fall_hanlder和rise_hanlder正在同一个线程上运行,但我的outside_isr()正在事件线程上运行。为了确保事件线程只运行一次且仅在调用fall_handler时,我该怎么办?
AnalogIn ain(PA_0); //Pin A0 //
EventQueue queue;
Thread thread, thread1;
Timer timer;
int count = 0;
void outside_isr() {
count = count + 1;
pc.printf("%.3f seconds\n", timer.read());
pc.printf("%d pulse\n", count);
}
void rise_handler() {
timer.reset();
timer.start();
}
void fall_handler() {
timer.stop();
queue.call(outside_isr);
}
void signal() {
bool flag = false;
while(1) {
if (ain > 0.93f) {
if (flag == false) {
flag = true;
rise_handler();
}
}
if (ain < 0.93f) {
if (flag == true) {
flag = false;
fall_handler();
}
}
}
}
int main () {
thread1.start(callback(signal));
thread.start(callback(&queue, &EventQueue::dispatch_forever));
while(1) {}
}