rusefi-1/firmware/controllers/system/signal_executor_sleep.cpp

93 lines
2.9 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file signal_executor_sleep.cpp
* @brief Asynchronous output signal code
*
* Here we have the simplest, thread-based implementation of signal executor.
* TODO: https://sourceforge.net/p/rusefi/tickets/6/
*
* @date Feb 10, 2013
2017-01-03 03:05:22 -08:00
* @author Andrey Belomutskiy, (c) 2012-2017
2015-07-10 06:01:56 -07:00
*
* This file is part of rusEfi - see http://rusefi.com
*
* rusEfi is free software; you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "main.h"
#include "scheduler.h"
#include "signal_executor.h"
2016-09-26 19:02:53 -07:00
#include "main_trigger_callback.h"
2015-07-10 06:01:56 -07:00
2016-09-25 20:02:28 -07:00
#if EFI_SIMULATOR || defined(__DOXYGEN__)
// this is about debugging
#include "efiGpio.h"
#endif /* EFI_SIMULATOR */
2015-07-10 06:01:56 -07:00
#if EFI_SIGNAL_EXECUTOR_SLEEP || defined(__DOXYGEN__)
2016-10-02 13:03:12 -07:00
void scheduleByTime(const bool monitorReuse, const char *prefix, scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, void *param) {
scheduleTask(monitorReuse, prefix, scheduling, time - getTimeNowUs(), callback, param);
2015-07-10 06:01:56 -07:00
}
2016-09-25 20:02:28 -07:00
static void timerCallback(scheduling_s *scheduling) {
2016-09-25 21:03:15 -07:00
#if EFI_PRINTF_FUEL_DETAILS || defined(__DOXYGEN__)
2016-09-25 20:02:28 -07:00
if (scheduling->callback == (schfunc_t)&seTurnPinLow) {
printf("executing cb=seTurnPinLow p=%d sch=%d now=%d\r\n", (int)scheduling->param, (int)scheduling,
(int)getTimeNowUs());
} else {
// printf("exec cb=%d p=%d\r\n", (int)scheduling->callback, (int)scheduling->param);
}
#endif /* EFI_SIMULATOR */
scheduling->callback(scheduling->param);
}
2016-10-02 08:02:09 -07:00
void scheduleTask(const bool monitorReuse, const char *prefix, scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) {
2015-07-10 06:01:56 -07:00
int delaySt = MY_US2ST(delayUs);
if (delaySt <= 0) {
/**
* in case of zero delay, we should invoke the callback
*/
callback(param);
return;
}
lockAnyContext();
2016-09-25 20:02:28 -07:00
scheduling->callback = callback;
scheduling->param = param;
2015-07-10 06:01:56 -07:00
int isArmed = chVTIsArmedI(&scheduling->timer);
2016-10-02 09:02:42 -07:00
if (isArmed) {
2017-03-03 19:58:30 -08:00
/**
* timer reuse is normal for example in case of sudden RPM increase
*/
2015-07-10 06:01:56 -07:00
chVTResetI(&scheduling->timer);
2016-09-25 20:02:28 -07:00
}
#if EFI_SIMULATOR || defined(__DOXYGEN__)
if (callback == (schfunc_t)&seTurnPinLow) {
printf("setTime cb=seTurnPinLow p=%d\r\n", (int)param);
} else {
// printf("setTime cb=%d p=%d\r\n", (int)callback, (int)param);
}
#endif /* EFI_SIMULATOR */
2015-07-10 06:01:56 -07:00
2016-09-25 20:02:28 -07:00
chVTSetI(&scheduling->timer, delaySt, (vtfunc_t)timerCallback, scheduling);
2015-07-10 06:01:56 -07:00
unlockAnyContext();
}
void initSignalExecutorImpl(void) {
}
#endif /* EFI_SIGNAL_EXECUTOR_SLEEP */