FreeRTOS how to change the callback function of a software timer - c

I'm using the software timer API from FreeRTOS to create a timer
xTimer = xTimerCreate("Timer", 100, 0, (void *) 0, vTimerCallback0);
Is there a way to change to callback of the timer to another function?

Another way to do it could be that the callback that you register when the timer gets created (vTimerCallback0) calls one from a set of other functions after some decision making in your code. It depends on what exactly you are trying to do.

I don't think there is one - the software timer API is here - https://www.freertos.org/FreeRTOS-Software-Timer-API-Functions.html . Curiously nobody has ever requested that before but I can add a function to do it easily enough - if you subscribe to check-in notifications you will see when it gets added.

Related

Call back function to be called whenever hardware timer elapses a specified elapse time in STM32F101

Hi I want to toggle LED with timing as follows
100ms ON1, 250ms Off1
1250ms ON2, 1500ms off2
and this cycle gets repeated (Both ON1 off1 and ON2 off2 pair repeats)
For this I have planned to utilize hardware timer with elapsing timings as 100,250,1250 and 1500 and this will repeat.
I am pretty new to the embedded field,
My questions are as follows
How to trigger this using a hardware timer? (How to enable and alternate the timings dynamically?)
How to set a call back function that toggles LED based on the timer elapse ?
Note : This is not a standalone code but an application will
Be running .From OS the callback will be triggered in the background so that other normal application is not affected during this process
Use the OS's software timer service. Create four software timers with the specified periods. The timers should be configured to count once and then stop each time they are started (i.e., they should be "one-shot", not "auto-reloading" nor "continuous" or whatever terminology your OS uses). Each software timer will have a unique callback function that you specify when you create the software timer.
From main, or wherever is appropriate, start the first timer once to get things started. Then start the second timer from the first timer's callback function. And start the third timer from the second timer's callback function. And so on until the last timer's callback function restarts the first timer and the circle of timers repeats.
Use timer interrupt for it.
You have the ready example here:
https://www.diymat.co.uk/arm-blinking-led-driver/
It does what you need and a bit more as well :)

Linux Timers in C

I am working on some Linux applications that uses timers.I need to change the timer interval during runtime.So is there any API that could detect whether any previous timer is running or not.My idea is like i will detect any previous running timer and will delete it and then will re-create the timer with new time value.
I am using timer_create(),timer_settime() for timer creation and timer starting.
Thanks&Regards
Amit Kumar
From the man page:
(If the timer was already armed, then the previous settings are overwritten.)
Seems like the function already does what you are looking for.

Dbus structure and method calls in C

I am starting to create a dbus application in C to interface with bluez. I am new to dbus and I am a little confused as how to correctly structure my application with dbus.
The first question is related to the Service, Interface, and Object path in dbus. Bluez Adapter API has the org.bluez service, a org.bluez.Adapter1 interface, and a number of methods and properties. If I wanted to call the void StopDiscovery() method, would the following be the correct call?
DBusPendingCall * pending;
// create a new method call and check for errors
msg = dbus_message_new_method_call("org.bluez",
"/", // object to call on
"org.bluez.Adapter1", // interface to call on
"StopDiscovery"); // method name
// send message and get a handle for a reply
if (!dbus_connection_send_with_reply (m_dbus_conn, msg, &pending, -1))
{
//err
}
If this is the case, when does the object path come into play?
The follow on to this is how to go about receiving information back from dbus. I've seen a few examples with a DBusPendingCall * however the function has dbus_pending_call_block() so the function blocks until the data is returned. If I wanted to do multiple calls and not block I would need to make a list of DBPendingCall pointers and check each one? Are there any callbacks?
Thanks
I did create an example showing the non-blocking call based on the dbus watch and timeout mechanism, in response to the SO question dbus watch and timeout examples. Basically you run a unix select() loop and everything is dispatched around it.
And I did not touch the multiple outstanding pending-call part. I assume one way is to check each pending-call to see whether it is completed when the watched event is received. Checking pending complete is non-blocking. If you keep a small number of outstanding pending calls it should be ok, though that is not an efficient solution if the number becomes big.
It looks like according to the API document, a better solution is to use dbus_pending_call_set_notify() to register a callback to a pending call.
So it appears that both the object path and the interface are required when talking to bluez over dbus.
// create a new method call for the adapter
msg = dbus_message_new_method_call("org.bluez",
"/org/bluez/hci0", // object to call on
"org.bluez.Adapter1", // interface to call on
"StopDiscovery"); // method name
// create a new method call for a characteristic on
// a given service
msg = dbus_message_new_method_call("org.bluez",
"/org/bluez/hci0/dev_12_34_56_78_9A_BC/service0010/char0011",
"org.bluez.GattCharacteristic1",
"StartNotify");
The select on Unix sockets for pending looks like a solid, scaleable way to go, I will consider this architecture as the application grows

need timerStartDate of timer and timerconfig ejb3.0

I have a TimerConfig and a Timer Object and use EJB 3.0. All works well, but "onTimeout" I want to get the information, when the timer was initialized. I cannot find a method such as timerStartDate.
Should I use timerConfig.setInfo and put the date when timer is initialized? Is this the only way?
Yes, if you want to know when createTimer was called, then you'll have to store it in setInfo. There is no builtin mechanism.

Is it possible to Hook into any time retrieving function

I need to hook any function that tries to retrieve the system time in order to generate "time independent" replays for different applications. Some events like pseudorandom number generation depend on calls to time(), but for example some others call timeGetTime() or _time64().
What is the minimum set of functions that I would need to hook (in Windows) to catch all time retrieving functions. Is it actually possible to hook on these functions? I am trying to do it on time(), but my hook is being ignored. I have had success hooking to other functions (like rand) but my time() hook seems to be ignored.
I am using Detours, but I am open to use any other API interception tool.
For game 'speedhacks', the 3 APIs which are usually hooked are:
timeGetTime()
GetTickCount()
QueryPerformanceCounter()
Most of these functions return a time since the system started or something similar. In your hook, you need to decide what you want to do. You could:
Always return a static time
Do the common approach for 'slowing down' or 'speeding up' time:
When your DLL is injected, take an initial time (say init_time)
Each time the target calls your time function, you can call a trampolined version of the real function which gets you a real_time
The value you return would be something like init_time + 0.5*(real_time-init_time) which would slow time down by half for example
You probably want to hook the time system call. Ugh, I don't know why I'm even suggesting that. But reverse engineering GetSystemTime in kernel32.dll would detail how that system call is made.
The minimum set of (preferably) kernel APIs that you want to hook are NtQuerySystemTime and NtGetTickCount. Kernel hooks are recommended since there's too many user-land apis to hook and you never know whether the application is directly accessing the time data using those two functions.
Of course you should filter out the process by calling PsGetCurrentProcess() and comparing the *(eprocess->UniqueProcessID) with your target process id.

Resources