Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Program to test callCoreTimerServiceNow() function.
- We set up a callback that shedules itself every 10ms to run. But what if we need it to run sooner than the next
- scheduled time? We use callCoreTimerServiceNow().
- The code below sets up a callback that just incriments a global value every 10ms. We print out the global value
- every 1ms using the delay(1) function, and we see that for the first four ms, the RunCount only incriments once
- or so. But then we start calling callCoreTimerServiceNow() and we see that the RunCount is incrimented for
- every call. If callCoreTimerServiceNow() is not working, the RunCount will only be incrimented every 10ms.
- The code should print out:
- 0ms : 1
- 1ms : 1
- 2ms : 1
- 3ms : 1
- 4ms : 2
- 5ms : 3
- 6ms : 9
- This example code is in the public domain. */
- volatile int RunCount = 0;
- void setup() {
- Serial.begin(115200);
- delay(2000); // Wait for slow human to get serial monitor running
- }
- void loop() {
- delay(1);
- attachCoreTimerService(MyCallback);
- Serial.print(" 0ms : ");
- Serial.println(RunCount);
- delay(1);
- Serial.print(" 1ms : ");
- Serial.println(RunCount);
- delay(1);
- Serial.print(" 2ms : ");
- Serial.println(RunCount);
- delay(1);
- Serial.print(" 3ms : ");
- Serial.println(RunCount);
- callCoreTimerServiceNow(MyCallback);
- delay(1);
- Serial.print(" 4ms : ");
- Serial.println(RunCount);
- callCoreTimerServiceNow(MyCallback);
- delay(1);
- Serial.print(" 5ms : ");
- Serial.println(RunCount);
- callCoreTimerServiceNow(MyCallback);
- callCoreTimerServiceNow(MyCallback);
- callCoreTimerServiceNow(MyCallback);
- callCoreTimerServiceNow(MyCallback);
- callCoreTimerServiceNow(MyCallback);
- callCoreTimerServiceNow(MyCallback);
- delay(1);
- Serial.print(" 6ms : ");
- Serial.println(RunCount);
- while(1);
- }
- // For the core timer callback, just toggle the output high and low
- // and schedule us for another 100uS in the future. CORE_TICK_RATE
- // is the number of core timer counts in 1 millisecond. So if we
- // want this callback to be called every 100uS, we just divide
- // the CORE_TICK_RATE by 10, and add it to the current time.
- uint32_t MyCallback(uint32_t currentTime) {
- RunCount++;
- return (currentTime + (CORE_TICK_RATE*10));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement