Where do I find reference documentation for library calls I find in posted code?

Hi there,

I am new to Atmel MCUs but have been programming other MCUs for years (Freescale). I am working on a PWM interrupt and found some Arduino code snippets with references to library calls like:

PWMC_ConfigureChannel( PWMC_SetPeriod( NVIC_EnableIRQ(

These are not native Arduino reserved words in the IDE, like 'pinMode' yet there is no header include for them. So where are these defined in Arduino 1.6.13?

How do I learn about how these write to the actual registers listed in the SAM3X data sheet (like PWM Enable Register, PWM_ENA.)?

Also, I see 'PWM_Handler(void)' in the code - is this predefined somewhere to tie out to the ISR vector for PWM? In other words, how does the Arduino compiler know that the function my source code called 'PWM_Handler(void)' is actually an ISR and not just any old function? Seems like magic.

All over the forum I see code snippets with references to library calls like this, but have not come across any clues to digging into them. I found something about a libsam on a google search, but not finding it in the arduino directory (Arduino 1.6.13).

Where is a good source of info on the details of these magical libraries? I am truly stumped.

BTW, below is the code I am looking at from stack overflow which works at producing a 192KHZ 50% duty cycle pulse on pin 8 of my Due.

http://stackoverflow.com/questions/35962894/how-do-i-configure-an-interrupt-for-the-hardware-pwm-on-the-arduino-due#36705124

uint32_t totalTime = 0; // total elapsed time

uint32_t pwmPin = 8; // PWM output pin uint32_t irqPin = 5; // interrupt test pin uint32_t channel = g_APinDescription[pwmPin].ulPWMChannel; // set channel for PWM out uint32_t sampFreq = 192000ul; // sampling frequency (Hz) uint16_t maxDutyCount = 255; uint32_t clkAFreq = 42000000ul; // clock frequency (Hz) uint32_t pwmFreq = (clkAFreq * 2)/sampFreq; // calculate PWM frequency uint16_t dutyPercent = 128; // starting duty percent uint16_t dutyAct = pwmFreq * (maxDutyCount-dutyPercent) / maxDutyCount; //

void setup() { // put your setup code here, to run once: pinMode(irqPin, OUTPUT);

pmc_enable_periph_clk(PWM_INTERFACE_ID); PWMC_ConfigureClocks(clkAFreq, 0, VARIANT_MCK);

PIO_Configure( g_APinDescription[pwmPin].pPort, g_APinDescription[pwmPin].ulPinType, g_APinDescription[pwmPin].ulPin, g_APinDescription[pwmPin].ulPinConfiguration);

channel = g_APinDescription[pwmPin].ulPWMChannel; // channel 5 PWMC_ConfigureChannel(PWM_INTERFACE, channel, clkAFreq, 0, 0); PWMC_SetPeriod(PWM_INTERFACE, channel, pwmFreq); PWMC_EnableChannel(PWM_INTERFACE, channel); PWMC_SetDutyCycle(PWM_INTERFACE, channel, dutyAct); PWM_INTERFACE->PWM_IER1 = 0x20; //enable interrupt on channel 5 PWM_INTERFACE->PWM_IDR1 = 0xFFFFFFDF; //enable interrupt on channel 5 PWM_INTERFACE->PWM_IER2 = 0x00002001; //enable interrupt on channel 5 PWM_INTERFACE->PWM_IDR2 = 0xFFFFDFFE; //enable interrupt on channel 5

NVIC_DisableIRQ(PWM_IRQn); // set up interrupt NVIC_ClearPendingIRQ(PWM_IRQn); NVIC_SetPriority(PWM_IRQn, 0); NVIC_EnableIRQ((IRQn_Type)36); //NVIC_EnableIRQ(PWM_IRQn); PWMC_EnableChannel(PWM_INTERFACE, channel); //Enable of the Interrupts (writing CHIDx and FCHIDx //in PWM_IER1 register, and writing WRDYE, ENDTXE, //TXBUFE, UNRE, CMPMx and CMPUx in PWM_IER2 register) }

void loop() { }

void PWM_Handler(void) // PWM interrupt handler { volatile long dummy = PWM_INTERFACE->PWM_ISR1; // clear interrupt flag dummy = PWM_INTERFACE->PWM_ISR2; // clear interrupt flag //your code here! }

These are Atmel-defined functions from "libsam" (which pre-dates the current "ASF" libraries.) You can find the source code in .../packages/arduino/hardware/sam/1.6.9/system/libsam/source/ (whereever that happens to live in your IDE install.)

Last time I looked, I couldn't find libsam documentation :-( https://forum.arduino.cc/index.php?topic=399524.0

Thank you - I finally found it with your help. For some reason it was in my AppData folder and not in the IDE install folder. I turned on verbose compile and it was looking there for it.

Here is a convenient github link:

https://github.com/arduino/Arduino/tree/master/hardware/arduino/sam/system/libsam/source

If I happen to come across any further libsam docs in my quest, I will post their location.