Access to the SystemTick interrupt

Discussion to talk about software related topics only.
Post Reply
Lachlanp
Posts: 91
Joined: Tue Jan 29, 2013 4:44 am

Access to the SystemTick interrupt

Post by Lachlanp »

I wish to create a number of timers, each with a resolution of the system tick. Is it possible to access the SystemTick interrupt so it can drive my timer module?

The code i wish to access has very low overhead:

Code: Select all

    for (uint8_t timer=0; timer < TMR_MAX; timer++){
        if ((timer_status>>timer) & 0x01)                                  // Is Timer enabled ?
            if ( (--timer_count[timer]) == 0){				// If Timer timed-out, activate flag
                if ((timer_reset >> timer) & 0x01)		                // If auto reset on
                    timer_count[timer] = timer_value[timer];		// re-initiate timer
                else
                    timer_status &= ~(1 << timer);			// else Clear Timer enable flag
                time_out |= 1 << timer;					// Set Time_out Flag
               }
        }
The alternative is setting up an entire Task just to handle this timer, which seems a lot of overhead for a simple timer module.

Thanks
Lachlan
User avatar
dciliske
Posts: 624
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: Access to the SystemTick interrupt

Post by dciliske »

That's... an interesting thought, but I can't help but wonder if you're prescribing a solution to a problem that doesn't exist. Basically, it sounds like you have a state machine that you're trying to determine *when* it should wake up based on the next event to occur. We have several of these within the core library, and all are done without running in the SysTick ISR.

Basically, if you're not running these events in the ISR, then you have a task *somewhere* that's handling them. Your goal is to wake up that task and execute when these events occur/timer rolls over. From the OS perspective, this means that your goal is to determine the next timeout and set the right delay.

Oh. Wow. I think I may actually add a 'OSDelayUntil' function... That would make life sooo much easier.
Dan Ciliske
Project Engineer
Netburner, Inc
Lachlanp
Posts: 91
Joined: Tue Jan 29, 2013 4:44 am

Re: Access to the SystemTick interrupt

Post by Lachlanp »

I have a multitude of timers for different purposes.
I use a timer to schedule the RF transceiver to repeat the transmission of a packet if it has not been responded to within a specific duration, I need to poll the RS485 line to request data at timed intervals, I need to flush data queues if there is no response to a command within a prescribed time, I need to allow my zigbee devices time to respond before timing out and moving onto the next command and in parallel schedule new discovery event, and the list goes on. Rather than using a separate task for each activity that blocks, I use timers to schedule activities. I have setup a task using the PIT timer to update all my timers every tick, but that just consumes resources. A hook into the tick timer would be ideal, although I can understand why you would not want that to occur.


If you already have solutions to this type of problem, can you please point out where they may be described. The resolution of the timers need to be around 0.1s and the accuracy does not need to be precise as the timers simply set flags that are checked by other processes.

Regards
Lachlan
User avatar
TomNB
Posts: 576
Joined: Tue May 10, 2016 8:22 am

Re: Access to the SystemTick interrupt

Post by TomNB »

I would consider using one of the free system timers and making your own, rather than using the system clock. That way everything is self-contained in your own application code and you do not need to modify the system libs each time you update the tools.
Lachlanp
Posts: 91
Joined: Tue Jan 29, 2013 4:44 am

Re: Access to the SystemTick interrupt

Post by Lachlanp »

Thanks. ill stick to using the PIT timer then.
Lachlan
Post Reply