Interruptions coding in ATMEL STUDIO 7

Hi there, my first thread in arduino forums so sorry if I make any mess.

I've programmed the Arduino Nano (AVR328p) a lot in the ATMEL STUDIO 7 and all I needed was the datasheet. Now im trying to program a Arduino Due (AT91SAM3X8E) and I cant find ANY reference online or in the datasheet how to do the basic stuff. Im using the ASF already to do the startup of the chip, and I think i know how to operate the GPIO's only using the registers. Thats all great. Now I need to use simple timed interruptions and I cant find how. How do I program interruptions, what function do I use, etc?
Thanks

All you need to get started with the DUE is the Sam3x datasheet plus the Greynomad pinout diagram.

An example sketch to trigger an interrupt at a 20 KHz frequency :

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  tc_setup();
}

void loop() {
}

void tc_setup() {

  PMC->PMC_PCER0 |= PMC_PCER0_PID29;                       // TC2 power ON : Timer Counter 0 channel 2 IS TC2

  TC0->TC_CHANNEL[2].TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1   // MCK/2, clk on rising edge
                              | TC_CMR_WAVE                // Waveform mode
                              | TC_CMR_WAVSEL_UP_RC;       // UP mode with automatic trigger on RC Compare

  TC0->TC_CHANNEL[2].TC_RC = 2100;                         // Frequency = (Mck/2)/TC_RC  Hz = 20 KHz

  TC0->TC_CHANNEL[2].TC_IER = TC_IER_CPCS;                 //Interrupt on RC compare match
  NVIC_EnableIRQ(TC2_IRQn);                                // Enable interrupts

  TC0->TC_CHANNEL[2].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN; // Software trigger TC2 counter and enable
}

void TC2_Handler() {

  static uint32_t Count;

  TC0->TC_CHANNEL[2].TC_SR;         // Read and clear status register;

  if (Count++ == 20000) {
    PIOB->PIO_ODSR ^= PIO_ODSR_P27; // Toggle LED_BUILTIN every 1 Hz
    Count = 0;
  }
  // Some stuff, as short as possible
}

Well thank you so much for the code, gonna start working on it right now. The problem is: Where the hell did you take that from? I searched all datasheet and couldn't find anything close to the "void TC2_Handler()" or the "NVIC_EnableIRQ(TC2_IRQn)". Am I looking at the wrong place? Thank you so much again.

In the IDE window, select File> Preferences. At the bottom of this new window, click in the URL:
C:\Users...\AppData\Local\Arduino15\preferences.txt, select the following path:

packages/arduino/hardware/sam/(your sam compiler version)/cores/arduino/cortex_handlers

Plus you can find CMSIS functions for NVIC control page 164 of Sam3x datasheet.

I do appreciate all the help. Its working flawlessly. One last question:
This type of coding "TC0->TC_CHANNEL[2].TC_RC = 2100;" using pointers, structs and vectors to registers is really odd to me. I understand the you are accessing TC_RC of the channel 2 of the timer 0 and writing but it's really weird for me.
I'm used to call the registers directly by their defined names. Would you please tell me where can I read more about this type of sintax so I could not only read your code but learn how to write it as well? Thank you so much for the help.

Sam3x datasheet page 31, plus:
https://android.googlesource.com/platform/external/arduino-ide/+/f876b2abdebd02acfa4ba21e607327be4f9668d4/hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/include/component

This type of coding "TC0->TC_CHANNEL[2].TC_RC = 2100;" using pointers, structs and vectors to registers is really odd to me.

It's a relatively standard practice of overlaying C structure definitions on hardware registers of a peripheral (and you can google that, although I didn't find any really stellar explanations. https://www.edn.com/print/4438698 is pretty good, I guess.
In addition to being common, this method of defining access to peripheral registers is made STANDARD for ARM Cortext processors by ARM's CMSIS specification. (this is REALLY important for defining the registers that are standard to the ARM Core, so they don't wind up with different methods from different vendors, but they also say that it should be done for all the vendor-specific peripherals.)
It also works out to be more efficient in many cases. ARM doesn't have an instruction equivalent to LDS on AVR (load a variable from an absolute memory address) - once you load the base address of a SET of peripheral registers, they can be accessed more easily via the relatively small offsets than they could be accessed individually.