diff --git a/sbs.conf b/sbs.conf index efcc119d5177d196899b3eb0a89bfd031234c7a6..41484140ab5ac591f63ea183b8ea7c535c939177 100644 --- a/sbs.conf +++ b/sbs.conf @@ -69,7 +69,6 @@ Files: src/shared/canbus/CanManager.cpp Type: srcfiles Files: src/shared/events/Scheduler.cpp src/shared/DMA/DMA.cpp - src/shared/Leds.cpp [i2c] Type: srcfiles @@ -91,6 +90,7 @@ Files: src/shared/math/Stats.cpp [anakin-data] Type: srcfiles Files: src/shared/boards/AnakinBoard.cpp + src/shared/Leds.cpp # Boards [discovery-canbus-test] @@ -105,7 +105,7 @@ Main: canbus-test Type: board BoardId: stm32f429zi_skyward_anakin BinName: anakin-test-suite -Include: %canbus %shared +Include: %canbus %shared %anakin-data Defines: Main: anakin-test-suite @@ -113,7 +113,7 @@ Main: anakin-test-suite Type: board BoardId: stm32f429zi_skyward_anakin BinName: anakin-demo-board -Include: %shared %i2c %ethernet %math +Include: %shared %i2c %ethernet %math %anakin-data Defines: Main: anakin-demo-board diff --git a/scripts/linter.sh b/scripts/linter.sh index cd5a8c6bfe3f21bdcaa3c2cd2ee9dbf9391a9702..2140f27f5a51e708c85dd4f00eaafc9131b1051a 100755 --- a/scripts/linter.sh +++ b/scripts/linter.sh @@ -25,5 +25,6 @@ check OUT "Checking for files not having the copyright" "grep -rL '* Permission check OUT "Checking for tabulations instead of spaces" "grep -Pr '\t' src" check OUT "MMP wants his full name" "grep -rl 'Matteo Piazzolla' src/" check OUT "Launching cppcheck" "cppcheck -q --suppress=unusedFunction --suppress=missingInclude --std=c++11 --enable=all src/ 2>&1" +check OUT "Checking for using namespace in header files" "grep -rl 'using namespace' src | egrep '.h(pp)?$'" exit 0 diff --git a/src/entrypoints/dma-lowlevel-test.cpp b/src/entrypoints/dma-lowlevel-test.cpp index 9b6befc633b87077a3e9f11db1cf601e47be55ac..b508b9d23266e3230bfc90c70a32c5ffd16a5e8b 100644 --- a/src/entrypoints/dma-lowlevel-test.cpp +++ b/src/entrypoints/dma-lowlevel-test.cpp @@ -1,3 +1,24 @@ +/* Copyright (c) 2015-2017 Skyward Experimental Rocketry + * Authors: Federico Terraneo + * + * 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 <sensors/iNemo.h> @@ -32,10 +53,16 @@ int main() spiINEMOG::init(); auto& spi=SPIDriver::instance(); - inemo_t inemo(inemo_t::ACC_FS_16G,inemo_t::GYRO_FS_245,inemo_t::COMPASS_FS_2); - if(inemo.init()==false) puts("init failed"); + inemo_t inemo (inemo_t::ACC_FS_16G, + inemo_t::GYRO_FS_245, + inemo_t::COMPASS_FS_2); + + if(inemo.init()==false) + { + puts("init failed"); + } + auto req=inemo.buildDMARequest(); - auto sample=[&]() { if(spi.transaction(req)==false) puts("DMA error"); diff --git a/src/entrypoints/test-busfault.cpp b/src/entrypoints/test-busfault.cpp index d537de76e9d608efe046ab9cfcb0e9deb4ed02e3..20bb12255183f12e83d948cb2072fe25ac2d53e9 100644 --- a/src/entrypoints/test-busfault.cpp +++ b/src/entrypoints/test-busfault.cpp @@ -1,3 +1,25 @@ +/* Copyright (c) 2015-2017 Skyward Experimental Rocketry + * Authors: Alain Carlucci + * + * 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 <Common.h> using namespace miosix; diff --git a/src/shared/boards/AnakinBoard.cpp b/src/shared/boards/AnakinBoard.cpp index 4a0a5be177b870a76e3cabfe6f566f8c2f374f96..abcf58d503ec30d21f4a91bab80ca20a19e5bb15 100644 --- a/src/shared/boards/AnakinBoard.cpp +++ b/src/shared/boards/AnakinBoard.cpp @@ -1,3 +1,25 @@ +/* Copyright (c) 2015-2017 Skyward Experimental Rocketry + * Authors: Alain Carlucci, Federico Terraneo + * + * 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 "AnakinBoard.h" #define INIT_AND_CHECK(x) do { \ diff --git a/src/shared/boards/AnakinBoard.h b/src/shared/boards/AnakinBoard.h index 388f617b943a3524932395af0d3348f4723614d6..5bb9c39f6b63268f3601f31211ff550344dc5e9b 100644 --- a/src/shared/boards/AnakinBoard.h +++ b/src/shared/boards/AnakinBoard.h @@ -1,3 +1,25 @@ +/* Copyright (c) 2015-2017 Skyward Experimental Rocketry + * Authors: Alain Carlucci + * + * 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. + */ + #ifndef BOARDS_ANAKINBOARD_H #define BOARDS_ANAKINBOARD_H diff --git a/src/shared/diagnostic/Log.h b/src/shared/diagnostic/Log.h index 6e691edf4c30814b28adff5fd2e728c757e6dbf3..5ee8c80610f73b93ed5e8819fb78a6e84d144b7e 100644 --- a/src/shared/diagnostic/Log.h +++ b/src/shared/diagnostic/Log.h @@ -1,3 +1,25 @@ +/* Copyright (c) 2015-2017 Skyward Experimental Rocketry + * Authors: Alain Carlucci + * + * 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. + */ + #ifndef SHARED_LOG_H #define SHARED_LOG_H diff --git a/src/shared/events/Scheduler.cpp b/src/shared/events/Scheduler.cpp index 350f8a8de2f0191142bb74b3dff190617ffa3ac2..a41e70ff4005aa6bb502232f5820c0c9a7ee726a 100644 --- a/src/shared/events/Scheduler.cpp +++ b/src/shared/events/Scheduler.cpp @@ -41,12 +41,14 @@ std::ostream& operator<<(std::ostream& os, const TaskStatResult& sr) // void EventScheduler::add(function_t func, uint32_t intervalMs, - const string& name, int64_t start) { + const string& name, int64_t start) +{ task_t task = { func, intervalMs, name, false, -1 }; addTask(task, start); } -void EventScheduler::addOnce(function_t func, uint32_t delayMs, int64_t start) { +void EventScheduler::addOnce(function_t func, uint32_t delayMs, int64_t start) +{ task_t task = { func, delayMs, "", true, -1 }; addTask(task, start); } @@ -65,49 +67,65 @@ vector<TaskStatResult> EventScheduler::getTaskStats() it.activationStats.getStats(), it.periodStats.getStats(), it.workloadStats.getStats(), - }); + } + ); } return result; } -void EventScheduler::run() { +void EventScheduler::run() +{ Lock<FastMutex> l(mutex); - for(;;) { - while(agenda.size() == 0) condvar.wait(mutex); + for(;;) + { + while(agenda.size() == 0) + condvar.wait(mutex); int64_t now = getTick(); int64_t nextTick = agenda.top().nextTick; - if(nextTick <= now) { + if(nextTick <= now) + { event_t e = agenda.top(); agenda.pop(); { Unlock<FastMutex> u(l); #ifndef __NO_EXCEPTIONS - try { + try + { #endif e.task->function(); #ifndef __NO_EXCEPTIONS - } catch(...) { + } + catch(...) + { //TODO: can't propagate exception or the event scheduler //will stop working, but we may want to log it } #endif } - if(e.task->once==false) { + if(e.task->once==false) + { updateStats(e,now,getTick()); //NOTE: enqueue writes in nextTick, so has to be called after enqueue(e); - } else tasks.erase(e.task); - } else { + } + else + { + tasks.erase(e.task); + } + } + else + { Unlock<FastMutex> u(l); Thread::sleepUntil(nextTick); } } } -void EventScheduler::addTask(const EventScheduler::task_t& task, int64_t start) { +void EventScheduler::addTask(const EventScheduler::task_t& task, int64_t start) +{ Lock<FastMutex> l(mutex); tasks.push_back(task); if(task.once==false) permanentTasks++; @@ -118,13 +136,15 @@ void EventScheduler::addTask(const EventScheduler::task_t& task, int64_t start) enqueue(event); } -void EventScheduler::enqueue(event_t& event) { +void EventScheduler::enqueue(event_t& event) +{ event.nextTick += event.task->intervalMs * TICK_FREQ / 1000; agenda.push(event); condvar.broadcast(); } -void EventScheduler::updateStats(event_t& e, int64_t startTime, int64_t endTime) +void EventScheduler::updateStats(event_t& e, int64_t startTime, + int64_t endTime) { const float tickToMs = 1000.f / TICK_FREQ; @@ -145,4 +165,9 @@ void EventScheduler::updateStats(event_t& e, int64_t startTime, int64_t endTime) e.task->workloadStats.add(endTime - startTime); } -EventScheduler::EventScheduler() : ActiveObject(1024,PRIORITY_MAX-1), permanentTasks(0) {} +EventScheduler::EventScheduler() : + ActiveObject(1024,PRIORITY_MAX-1), permanentTasks(0) +{ + +} +