Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • avn/swd/skyward-boardcore
  • emilio.corigliano/skyward-boardcore
  • ettore.pane/skyward-boardcore
  • giulia.facchi/skyward-boardcore
  • valerio.flamminii/skyward-boardcore
  • nicolo.caruso/skyward-boardcore
6 results
Select Git revision
Show changes
Commits on Source (2)
......@@ -392,6 +392,15 @@ sbs_target(test-vn100 stm32f407vg_stm32f4discovery)
add_executable(test-lis2mdl src/tests/sensors/test-lis2mdl.cpp)
sbs_target(test-lis2mdl stm32f429zi_stm32f4discovery)
#-----------------------------------------------------------------------------#
# Tests - Utils #
#-----------------------------------------------------------------------------#
add_executable(test-threadtimedwait src/tests/timedwait/test-threadtimedwait.cpp)
sbs_target(test-threadtimedwait stm32f407vg_stm32f4discovery)
add_executable(test-condtimedwait src/tests/timedwait/test-condtimedwait.cpp)
sbs_target(test-condtimedwait stm32f407vg_stm32f4discovery)
#-----------------------------------------------------------------------------#
# Tests - Utils #
......
Subproject commit ca9c636f88fb58243847d9dca9cc1c000dcadeb5
Subproject commit d336eeaac2ee1fcf51c2e57da09b20a02719c593
/* Copyright (c) 2023 Skyward Experimental Rocketry
* Author: Niccolò Betto
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <miosix.h>
#include <functional>
using namespace miosix;
namespace
{
GpioPin button =
GpioPin(GPIOA_BASE, 0); // PA0 for the stm32f407 discovery board
FastMutex mutex{};
ConditionVariable condvar{};
void blinkLed(int times)
{
for (int i = 0; i < times; i++)
{
ledOn();
Thread::sleep(100);
ledOff();
Thread::sleep(75);
}
}
bool wasPressed = false;
void buttonPollingThread(void *argv)
{
while (true)
{
bool isNowPressed = !button.value();
if (isNowPressed && !wasPressed)
{
condvar.signal();
}
wasPressed = isNowPressed;
// 10Hz polling
Thread::sleep(100);
}
}
} // namespace
int main()
{
printf("TEST: ConditionVariable::timedWaitFor - No Boardcore dependencies\n");
button.mode(Mode::INPUT);
Thread::create(buttonPollingThread, STACK_MIN, 0, nullptr,
Thread::JOINABLE);
while (true)
{
Lock<FastMutex> lock{mutex};
printf("[%lld] Waiting...\n", getTick());
if (condvar.timedWaitFor(lock, 3000) == TimedWaitResult::Timeout)
{
printf("[%lld] Timed out, 3 seconds elapsed\n", getTick());
blinkLed(1);
}
else
{
printf("[%lld] Waken up, user button pressed\n", getTick());
blinkLed(2);
}
}
}
/* Copyright (c) 2023 Skyward Experimental Rocketry
* Author: Niccolò Betto
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <miosix.h>
#include <functional>
using namespace miosix;
namespace
{
GpioPin button =
GpioPin(GPIOA_BASE, 0); // PA0 for the stm32f407 discovery board
Thread *mainThread = nullptr;
void blinkLed(int times)
{
for (int i = 0; i < times; i++)
{
ledOn();
Thread::sleep(100);
ledOff();
Thread::sleep(75);
}
}
bool wasPressed = false;
void buttonPollingThread(void *argv)
{
while (true)
{
printf("[%lld] buttonPollingThread: (%p) Polling button...\n",
getTick(), (void *)Thread::getCurrentThread());
bool isNowPressed = !button.value();
if (isNowPressed && !wasPressed)
{
printf("[%lld] buttonPollingThread: (%p) Button pressed\n",
getTick(), (void *)Thread::getCurrentThread());
mainThread->wakeup();
}
wasPressed = isNowPressed;
// 10Hz polling
Thread::sleep(100);
}
}
} // namespace
int main()
{
printf("TEST: Thread::timedWait\n");
button.mode(Mode::INPUT);
Thread *poller =
Thread::create(buttonPollingThread, 1024, 0, nullptr, Thread::JOINABLE);
mainThread = Thread::getCurrentThread();
printf(
"SUMMARY:\n"
"* mainThread: thread ID (%p)\n"
"* buttonPollingThread: thread ID (%p)\n",
(void *)mainThread, (void *)poller);
while (true)
{
printf("[%lld] main: (%p) Waiting for button press...\n", getTick(),
(void *)Thread::getCurrentThread());
if (Thread::timedWaitFor(3000) == TimedWaitResult::Timeout)
{
printf("[%lld] main: (%p) Timed out, 3 seconds elapsed\n",
getTick(), (void *)Thread::getCurrentThread());
blinkLed(1);
}
else
{
printf("[%lld] main: (%p) Waken up, user button pressed\n",
getTick(), (void *)Thread::getCurrentThread());
blinkLed(2);
}
}
}