Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-dsp mbed-rtos mbed
Dependents: MAE433_Library_Tester RobotBalancerv2
FixedRefresh.hpp
- Committer:
- Electrotiger
- Date:
- 2016-06-29
- Revision:
- 6:076fcae78bac
File content as of revision 6:076fcae78bac:
/**
* @file FixedRefresh.hpp
* @author Weimen Li
* @date June 26th, 2016
* @class FixedRefresh
* @brief This class is used in an RTOS to ensure that iterations of a loop happen at fixed time intervals,
* regardless of how long other code in the loop takes. In doing so, it waits the thread that is currently
* running to allow other threads to run.
*/
/*
* FixedRefresh.hpp
*
* Created on: Jun 26, 2016
* Author: Developer
*/
#ifndef FIXEDREFRESH_HPP_
#define FIXEDREFRESH_HPP_
#include "mbed.h"
#include "rtos.h"
class FixedRefresh {
public:
/// Constructor for the FixedRefresh class.
FixedRefresh();
/// Destructor for the FixedRefresh class.
virtual ~FixedRefresh();
/*
* @brief Function which ensures as much as possible that micros microseconds elapses
* between successive calls, no matter how long the computation beforehand took.
* @args micros The number of microseconds that should elapse between successive calls.
* @returns false if waiting will not occur because greater than micros microseconds has
* elapsed since the previous calls. If the function does return false, then your computation
* is taking too much time.
*/
bool refresh_us(uint32_t micros);
private:
/// The number of microseconds to wait.
uint32_t wait_us;
Timer elapsedTime;
Timeout waitTimer;
/**
* @brief Mutex that is locked
*/
Semaphore waitSemaphore;
void timerCallback();
};
#endif /* FIXEDREFRESH_HPP_ */