-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shivam: Timers Wrapper Code Review #49
Closed
Closed
Changes from all commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
4a3299b
Initial Implementation of Core Objects
cjchanx b81b769
Pull README.md changes from Chris/AndromedaC++
cjchanx e6a86c6
Attempt to Implement FlightTask
cjchanx 5859a4a
Add VS2022 .gitignore
cjchanx f8e6031
Update Project Compilation and Refactoring
cjchanx 8ebf752
Implement wrapper for RTOS Mutex
cjchanx 67f7b7f
Implement wrapper for RTOS Mutex (#46)
cjchanx f8c99cd
Merge branch 'StudentOrganisationForAerospaceResearch:Chris/Ouroboros…
cjchanx a86f9b7
Start UARTTask
cjchanx d4fffcd
Merge branch 'Chris/OuroborosC++' of https://github.com/StudentOrgani…
cjchanx 6f06ea6
Add clarification on _IDE README.md
cjchanx fd89a05
Begin Implementing RTOS Timer Wrapper
cjchanx cfe977b
Add UARTTask to VS2022
cjchanx f45eb7b
Start File for UARTTask
cjchanx 13e820d
Add Notes
cjchanx 5e851fd
Update README.md
cjchanx 6ae14a0
Update README.md
cjchanx b983ffa
Begin implementation of UARTTask::Init
cjchanx 08b1593
Merge branch 'Chris/OuroborosC++' of https://github.com/cjchanx/Avion…
cjchanx 9f29238
Implement basic single-task activity on FlightBoard
cjchanx 8846a44
Merge with remote
cjchanx d7f69da
Implement VA List mutex for SOAR_ASSERT
cjchanx efa70a5
Add process for changing .ioc file
cjchanx 739417f
Initial debug and soar assert implementation
cjchanx 8a9b687
Try to add NVIC_SystemReset() to the HF Handler
cjchanx 44ffa32
Update README.md
cjchanx b4061d3
Update README.md
cjchanx c365c39
Create README.md
cjchanx 0fa797a
Merge branch 'Chris/OuroborosC++' of https://github.com/cjchanx/Avion…
cjchanx 782de39
Initial Implementation of SOAR_PRINT, Redesign Task Inst Dependency
cjchanx 86d18c1
Cleanup UARTTask Object Routing, Use SOAR_PRINT
cjchanx 84df2dd
Remove unused mutex
cjchanx 6fa8678
Add reset of packet after Handling command
cjchanx d343b71
Code Review Fixes
cjchanx 5740f3c
Get SOAR_PRINT working
cjchanx c56ea4d
Documentation and Debug Print Changes
cjchanx 62656cd
Add condition to SOAR_ASSERT so we don't need to wait if the assert h…
cjchanx d26c170
Format Improvements and Note
cjchanx be21745
Revert: Add condition to SOAR_ASSERT
cjchanx fe872ee
Add extra endline
cjchanx 1ec1f96
Add comments for clarification
cjchanx 2d3ea29
Add double instantiation guard to FlightTask
cjchanx 0421815
Add IDE Instructions
cjchanx 4ba5eea
Add new Constructor to Command
cjchanx f632126
Command:: Object Improvements
cjchanx 57267b7
Change FlightTask:: to Instance Run Style
cjchanx 226dc10
Add defines for ASSERT constants
cjchanx e8fd4cf
Codegen for UART 5 DMA
cjchanx ad53020
Fix DMA Handle Ref
cjchanx 0d1474d
Initial Definition for DebugTask::
cjchanx c7926f8
Init DebugTask
cjchanx 4dc9ac0
Rename Malloc and Free to soar_malloc and soar_free for consistency
cjchanx 342433b
Refactor to nullptr
cjchanx b13c98c
Update .ioc to Andromeda V3.3
cjchanx 31f6cfa
Remove unused CMake files
cjchanx 62e4b36
Code review fixes for SystemDefines.hpp
cjchanx 95b702f
Code review fixes for Mutex.hpp
cjchanx 701913d
Specify CRC Comments
cjchanx 2169f30
Merge branch 'Chris/OuroborosC++' of https://github.com/StudentOrgani…
cjchanx c975b74
Refactoring, Utils, Conversions
cjchanx 16ec0ca
Change statAllocationCounter to std::atomic (TODO: TEST THIS)
cjchanx 85a9e3e
Refactoring, DMA Stub
cjchanx 38fa2cb
Move Utils to root
cjchanx 19e07c1
Project Linker, Release, Settings Improvements
cjchanx 2a3d930
Update README.md
cjchanx 739230a
Increase FreeRTOS Heap size to 24KiB
cjchanx ff1abe3
added timer states and functions to get state
shivamdesai04 3bbae48
completed funstion removed and other functions have been updated
shivamdesai04 c0ef82f
added ChangePeriodAndStart function
shivamdesai04 c5f025f
added new functions and implemented changes stated in code review
shivamdesai04 04fae0d
added print statement to deconstructor
shivamdesai04 080bceb
Enabled software timers in ioc file
shivamdesai04 6c170c9
GetState test code
shivamdesai04 7a2032d
getstate and destructor testing functions added
shivamdesai04 acd98d5
added timer test functions
shivamdesai04 ff2e80c
finished testing functions
shivamdesai04 7ac5697
Timer test moved to filghttask.cpp
shivamdesai04 5ba92b6
Test code partly corrected
shivamdesai04 dd36e61
Merge branch 'master' of https://github.com/StudentOrganisationForAer…
cjchanx c8145bb
implemeted completed state
shivamdesai04 9916469
Code Dubugged and Comments added
shivamdesai04 b0e5e6d
Documentation added
shivamdesai04 d726bb6
TEST CODE
shivamdesai04 2498acb
merge conflict resolved
shivamdesai04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,226 @@ | ||
#include "SystemDefines.hpp" | ||
#include "Timer.hpp" | ||
|
||
/** | ||
****************************************************************************** | ||
* File Name : Timer.cpp | ||
* Description : FreeRTOS Timer Wrapper | ||
****************************************************************************** | ||
*/ | ||
#include "SystemDefines.hpp" | ||
#include "Timer.hpp" | ||
|
||
/** | ||
* @brief Empty callback function, used internally for default polling timers | ||
*/ | ||
void empty_callback(TimerHandle_t rtTimerHandle) {}; | ||
|
||
/** | ||
* @brief Default constructor makes a timer that can only be polled for state | ||
* Default constructor makes a timer that can only be polled for state | ||
* Default behaviour : ->Autoreload is set to false (One shot Timer) | ||
* ->Timer Period is 1000ms | ||
* ->The Callback function simply changes state to COMPLETE and has no other functionality | ||
*/ | ||
Timer::Timer() | ||
{ | ||
// We make a timer named "Timer" with a callback function that does nothing, Autoreload false, and the default period of 1s. | ||
// The timer ID is specified as (void *)this to provide a unique ID for each timer object - however this is not necessary for polling timers. | ||
// The timer is created in the dormant state. | ||
rtTimerHandle = xTimerCreate("Timer", DEFAULT_TIMER_PERIOD, pdFALSE, (void *)this, empty_callback); | ||
rtTimerHandle = xTimerCreate("Timer", DEFAULT_TIMER_PERIOD, pdFALSE, (void *)this, CallbackFunction); | ||
SOAR_ASSERT(rtTimerHandle, "Error Occurred, Timer not created"); | ||
timerState = UNINITIALIZED; | ||
} | ||
|
||
/** | ||
* Constructor for callback enabled timer | ||
* ! User has to add "Timer::CallbackFunction(rtTimerHandle);" in the callback function for accurate functioning of Timer States | ||
* Default behaviour : ->Autoreload is set to false (One shot Timer) | ||
* ->Timer Period is 1000ms | ||
* ->The Callback function will be provided by the user while making sure to follow instruction above | ||
*/ | ||
Timer::Timer(void (*TimerCallbackFunction_t)( TimerHandle_t xTimer )) | ||
{ | ||
rtTimerHandle = xTimerCreate("Timer", DEFAULT_TIMER_PERIOD, pdFALSE, (void *)this, TimerCallbackFunction_t); | ||
SOAR_ASSERT(rtTimerHandle, "Error Occurred, Timer not created"); | ||
timerState = UNINITIALIZED; | ||
} | ||
|
||
/** | ||
* @brief Default de-constructor makes a timer that can only be polled for state | ||
*/ | ||
Timer::~Timer() | ||
{ | ||
if (xTimerDelete(rtTimerHandle, DEFAULT_TIMER_COMMAND_WAIT_PERIOD*2) == pdPASS) { | ||
SOAR_PRINT("Timer has been deleted \n\n"); | ||
} | ||
} | ||
|
||
/** | ||
* @brief Callback function for polling timers | ||
*/ | ||
void Timer::CallbackFunction(TimerHandle_t xTimer){ | ||
Timer* ptrTimer = (Timer*)pvTimerGetTimerID(xTimer); | ||
ptrTimer->timerState = COMPLETE; | ||
} | ||
|
||
/** | ||
* @brief Changes this timer object's RTOS timer period, returns true on success, returns false on failure (timer command queue full) | ||
* @brief Changes timer period, Sets timer state back to uninitialized and stops timer | ||
*/ | ||
bool Timer::ChangePeriod(const uint32_t period_ms) | ||
{ | ||
if (xTimerChangePeriod(rtTimerHandle, MS_TO_TICKS(period_ms), DEFAULT_TIMER_COMMAND_WAIT_PERIOD) == pdTRUE) | ||
if (xTimerChangePeriod(rtTimerHandle, MS_TO_TICKS(period_ms), DEFAULT_TIMER_COMMAND_WAIT_PERIOD) == pdTRUE) { | ||
if (xTimerStop(rtTimerHandle, DEFAULT_TIMER_COMMAND_WAIT_PERIOD) == pdPASS) { | ||
timerState = UNINITIALIZED; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @brief Changes timer period, Sets timer state back to counting and starts timer | ||
*/ | ||
bool Timer::ChangePeriodAndStart(const uint32_t period_ms) | ||
{ | ||
if (xTimerChangePeriod(rtTimerHandle, MS_TO_TICKS(period_ms), DEFAULT_TIMER_COMMAND_WAIT_PERIOD) == pdTRUE) { | ||
timerState = COUNTING; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @brief Starts the timer | ||
*/ | ||
bool Timer::Start() | ||
{ | ||
if ((timerState == COMPLETE) || (timerState == COUNTING)) { | ||
cjchanx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return false; | ||
} | ||
else if (timerState == PAUSED) { | ||
ChangePeriod(remainingTimeBetweenPauses); | ||
} | ||
if (xTimerStart(rtTimerHandle, DEFAULT_TIMER_COMMAND_WAIT_PERIOD) == pdPASS) { | ||
timerState = COUNTING; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docs |
||
/** | ||
* @brief Stops the timer | ||
*/ | ||
bool Timer::Stop() | ||
{ | ||
// Checks if timer is in counting state because it cannot be stopped in any other state | ||
if (timerState != COUNTING) { | ||
return false; | ||
} | ||
// Calculates the time left on the timer before it is paused | ||
remainingTimeBetweenPauses = rtosTimeRemaning(); | ||
if (xTimerStop(rtTimerHandle, DEFAULT_TIMER_COMMAND_WAIT_PERIOD) == pdPASS) { | ||
timerState = PAUSED; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @brief Restarts timer without starting to count | ||
*/ | ||
bool Timer::ResetTimer() | ||
{ | ||
if (timerState == UNINITIALIZED) { | ||
return false; | ||
} | ||
if (xTimerReset(rtTimerHandle, DEFAULT_TIMER_COMMAND_WAIT_PERIOD) == pdPASS) { | ||
if (xTimerStop(rtTimerHandle, DEFAULT_TIMER_COMMAND_WAIT_PERIOD) == pdPASS) { | ||
timerState = UNINITIALIZED; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @brief Restarts Timer and starts counting | ||
*/ | ||
bool Timer::ResetTimerAndStart() | ||
{ | ||
if (timerState == UNINITIALIZED) { | ||
return false; | ||
} | ||
if (xTimerReset(rtTimerHandle, DEFAULT_TIMER_COMMAND_WAIT_PERIOD) == pdPASS) { | ||
timerState = COUNTING; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @brief Sets timer to auto-reload if parameter is set to true, Sets timer to one shot if parameter is set to false | ||
*/ | ||
void Timer::SetAutoReload(bool setReloadOn) | ||
{ | ||
if (setReloadOn == true){ | ||
vTimerSetReloadMode(rtTimerHandle, pdTRUE); | ||
//Testing purposes | ||
SOAR_PRINT("Set to Auto Reload\n\n"); | ||
} | ||
if (setReloadOn == false){ | ||
vTimerSetReloadMode(rtTimerHandle, pdFALSE); | ||
//Testing purposes | ||
SOAR_PRINT("Set to One Shot\n\n"); | ||
} | ||
} | ||
|
||
/** | ||
* @brief Returns true if the timer is set to autoreload and false if it is set to one-shot | ||
*/ | ||
bool Timer::GetAutoReload() | ||
{ | ||
if ((uxTimerGetReloadMode(rtTimerHandle)) == (( UBaseType_t ) pdTRUE)) { | ||
return true; | ||
} | ||
if ((uxTimerGetReloadMode(rtTimerHandle)) == (( UBaseType_t ) pdFALSE)) { | ||
return false; | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docs |
||
/** | ||
* @brief Returns timer state enum | ||
*/ | ||
TimerState Timer::GetState() | ||
{ | ||
return timerState; | ||
} | ||
|
||
/** | ||
* @brief Returns the timers' period | ||
*/ | ||
const uint32_t Timer::GetPeriod() | ||
{ | ||
return (TICKS_TO_MS(xTimerGetPeriod(rtTimerHandle))); | ||
} | ||
|
||
/** | ||
* @brief Returns remaining time on timer based on current state | ||
*/ | ||
const uint32_t Timer::GetRemainingTime() | ||
{ | ||
if (timerState == UNINITIALIZED){ | ||
return (GetPeriod()); | ||
} | ||
else if (timerState == COUNTING){ | ||
return rtosTimeRemaning(); | ||
} | ||
else if (timerState == PAUSED){ | ||
return remainingTimeBetweenPauses; | ||
} | ||
else { | ||
return 0; | ||
} | ||
} | ||
|
||
cjchanx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* @brief Calculates remaining time on timer in counting state | ||
*/ | ||
uint32_t Timer::rtosTimeRemaning() | ||
{ | ||
remainingTime = (TICKS_TO_MS(xTimerGetExpiryTime(rtTimerHandle) - xTaskGetTickCount())); | ||
return remainingTime; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add an else here to account for if we failed xTimerStop (for whatever reason)