Systick ISR

Status
Not open for further replies.

TelephoneBill

Well-known member
Can anyone point me to the Teensy 3.1 core folder/file where the systick_isr is defined? I have looked without success.

Should I wish to replace it with my own version, how would I "undefine" the current routine before adding my own in a sketch? Or is this bad practice?
 
My editor shows me this:
Code:
T:\arduino_1.8.5_142\hardware\teensy\avr\cores\teensy3\EventResponder.cpp:
  323  
  324  // Long ago you could install your own systick interrupt handler by just
  325: // creating your own systick_isr() function.  No longer.  But if you
  326  // *really* want to commandeer systick, you can still do so by writing
  327  // your function into the RAM-based vector table.
  ...
  336  
  337  extern "C" volatile uint32_t systick_millis_count;
  338: void systick_isr(void)
  339  {
  340  	systick_millis_count++;
 
... at least until the systick_isr(void) will be declared as "weak" in one of the next Teensyduino releases, so that it could become easier to override it... ;)
 
I note that this is an old thread.

I posted a question yesterday, related to interrupts and interrupt response time.

I am worried that my critical (edge triggered I/O pin) interrupt to measure timing is being impacted by some other interrupt, possibly "systick".

NOTE: I am using a Teensy 3.0

In the ...\Arduino\hardware\teensy\avr\cores\teensy3 folder I have searched for code that might help. I have found references to systick, but the code makes no sense to me. I can see that systick is some built in CPU feature and is used for the milliseconds timer by default. I am guessing that it is setup to interrupt every millisecond?

What is the default priority and what code do I use to set it to a lower priority?

Can I just disable and re-enable this particular interrupt? I was using the delay() function, but I assume it won't work without systick interrupt enabled, however I can use another I/O pin interrupt to signal the end of data collection period.

In my own code I use

Code:
...
const byte fromFDDreadPin  = 21; // PORT-D IRQ #43
...
const byte fromFDDreadPinIRQ  = 43; // IRQ_PORTD = 43,   // kinetis.h (Teensy 3.0)
...
NVIC_SET_PRIORITY(fromFDDreadPinIRQ, 0);   // HIGHEST priority
...

but I don't think that NVIC_SET_PRIORITY can be used for systick?

regards...

--badsector
 
Systick priority defaults to 32.

Just sent your interrupt to 16 or 0.

OK Paul, thanks for that. The teensy system code takes a while to digest and understand.

As I understand it, "systick" is built into the ARM CPU and has special registers associated with it, so it is not quite a normal interrupt.

It took a while to find this code, so I am trying..

Code:
  SYST_CSR = SYST_CSR_CLKSOURCE; // disable SYSTICK interrupts

as a temporary way to disable the "systick" interrupt, so as to not disturb my floppy data stream.

At the end of the track capture I re-enable the "systick" interrupt. Just freezing "systick" probably does the same.

Code:
  SYST_CSR = SYST_CSR_CLKSOURCE | SYST_CSR_TICKINT | SYST_CSR_ENABLE; // re-enable SYSTICK

It took me a while to understand interrupts. For my PORTD I/O pin, I worked out the IRQ number. Here's how to
1) change the priority
2) disable the interrupt
3) enable the interrupt
4) clear any pending interrupts

Code:
const byte fromFDDreadPin  = 21; // PORT-D IRQ #43
const byte fromFDDreadPinIRQ  = 43; // IRQ_PORTD = 43,   // kinetis.h (Teensy 3.0)

NVIC_SET_PRIORITY(fromFDDreadPinIRQ, 0);   // 0 is the HIGHEST priority
NVIC_DISABLE_IRQ(fromFDDreadPinIRQ);
NVIC_ENABLE_IRQ(fromFDDreadPinIRQ);
NVIC_CLEAR_PENDING(fromFDDreadPinIRQ);

I post the above in case anyone else was looking for information about interrupts. These macros can be found in ...\Arduino\hardware\teensy\avr\cores\teensy3\kinetis.h . I haven't seen any reference to them elsewhere.

Also in the afore mentioned file, look for "enum IRQ_NUMBER_t" to find out which IRQ number to use. For Teensy3.0 you will find the relevant line " IRQ_PORTD = 43,". My I/O pin 21 is found on PORT D.

NOTE that they go from 0 to 45. There also appears to be 16 other special CPU interrupts, of which "systick" is one. At least in one posting there was an offset of "+16" added, but in that posting I think it was incorrect, however that's where the 16 came from just in case you see this and are puzzled, like I was. There also appears to be a set of interrupt vector RAM locations which go from 0 to whatever, the first 16 are the CPU special and the rest of the interrupts from the enum. In another posting I saw that you can change number 15 which holds the vector for "systick" (but I haven't tried or confirmed this). I hope this helps! :)

regards...

--badsector
 
These ARM architecture details are documented on ARM's website, and also in Joseph Yiu's "Definitive Guide..." book.

https://www.amazon.com/dp/0124080820

To find ARM's free (much not nearly as approachable) architecture document, Google search for "DDI0403E".

Many thanks Paul. Looks like the book would be a good buy to help me understand this "new" architecture. Pity I didn't know of this before Xmas, because I could have put this book on my "wish list" :)

Luckily for most of us teensy users a lot of utilities are hidden behind libraries, but every now and again we have to venture into the world of low level register access :). Ironically I was already thinking "wouldn't it be great if someone would do a technical book on the teensy family, explaining in more detail the hardware peripherals and how to use them". Compared to the AVR the ARM based teensy and peripherals are much more sophisticated, but also take more time to understand.

I found that googling the register names brought me to a site called "ARM Developer" (infocenter.arm.com) which was quite readable and had a good search.

regards...

--badsector
 
Status
Not open for further replies.
Back
Top