Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
aa6164-EventQueue/src/main.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
36 lines (31 sloc)
854 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2020 Arm Limited and affiliates. | |
* SPDX-License-Identifier: Apache-2.0 | |
*/ | |
#include "mbed.h" | |
DigitalOut led1(LED1); | |
InterruptIn sw(USER_BUTTON); | |
EventQueue queue(32 * EVENTS_EVENT_SIZE); | |
Thread t; | |
void rise_handler(void) | |
{ | |
queue.call(printf, "rise_handler in context %p\n", ThisThread::get_id()); | |
// Toggle LED | |
led1 = !led1; | |
} | |
void fall_handler(void) | |
{ | |
printf("rise_handler in context %p\n", ThisThread::get_id()); | |
// Toggle LED | |
led1 = !led1; | |
} | |
int main() | |
{ | |
// Start the event queue | |
t.start(callback(&queue, &EventQueue::dispatch_forever)); | |
printf("Starting in context %p\r\n", ThisThread::get_id()); | |
// The 'rise' handler will execute in IRQ context | |
sw.rise(rise_handler); | |
// The 'fall' handler will execute in the context of thread 't' | |
sw.fall(queue.event(fall_handler)); | |
} |