Internal Structure of Arduino Software

Introduction

I am analyzing the implementation and internal structure of the Arduino AVR core. The goal is to clarify the Arduino AVR Boards 1.8.6.

I checked the code for Arduino Uno where #if is used. It means Arduino Mega or Leonardo may have different behavior.

If you have any comments, suggestions, corrections or anything, please contact to ‘garretlab at gmail.com’ by e-mail. Note that I am a Japanese, please use plain English.

Arduino

wiring_digital.c
function to configure the port as an input or an output.
returns if the specified pin is HIGH or LOW.
sets the specified digital pin to HIHG or LOW.
stops PWM output of a specified timer.
wiring_analog.c
sets the reference voltage for analog input.
reads the value from analog pin using analog-digital(AD) converter.
outputs PWM(Pulse Width Modulation) wave.
Tone.cpp
generates square wave with specified frequency.
manages the relation of pin and timer.
stops the output of square wave.
initializes the timer/counter set by tone().
interrupt handler which is called when the timer/counter2(TCNT2) becomes the same value of compare register(OCR2A).
wiring.c
initializes the timer counter, AD converter and serial communication of ATmega328P.
returns the number of milliseconds since the board has booted.
returns the number of microseconds since the board has booted.
interrupt handler that is executed when the Timer/Counter0(TCNT0) overflows.
WInterrupts.c
function to sets a function to be called when an external interrupt occurs.
function to resets a function to be called when an external interrupt occurs.
wiring_shift.c
gets 8 bit of data and assembles them into 1 byte of data.
sends a byte of data bit by bit.
wiring_pulse.c
measures the time of input pulse.
wiring_pulse.S
assembler code to count the pulse length.
hooks.c
function to relinquish the CPU.
HardwareSerial0.cpp
definition of Serial object.
an interrupt handler that is called when a data is received using serial communication.
an interrupt handler that is called when a data can be transmitted using serial communication.
HardwareSerial.cpp
Registers for serial communication.
sets theg communication speed and other settings.
ends the serial communication and sets RX and TX pins to normal input/output mode.
reads data from receive buffer.
reads data from receive buffer without modifying the buffer.
returns how many bytes can be written to receive buffer of serial communication.
sends all data in the serial transmit buffer.
wites binary data to serial port.
returns how many bytes can be written to transmit buffer of serial communication.
copies data from Arduino serial communication transmit buffer to ATmega328P data transmit register.
HardwareSerial_private.h
constractor of HardwareSerial.
copies data from the receive buffer of ATmega328P to the receive buffer of Arduino.
HardwareSerial.h
definition of HardwareSerial.
checks if the serial port is available or not.
wiring_private.h
macro to set the bit(the second argument) of the address(the first argument) to 1.
macro to set the bit(the second argument) of the address(the first argument) to 0.
Arduino.h
macro that returns the bitmask of a specified pin.
macro that returns the port of a specified pin.
macro that returns the timer of a specified pin.
macro that returns a mode register that controlls the mode of the specified port.
macro that returns an output port register of the specified port.
macro that returns an input port register of the specified port.
read and write a bit from/to in the variable.
convert the number of clocks and time(in microsecond).
enables or disables the interrupts.

AVR-GCC

pgmspace.h
macro that read a word of data stored in a specified address(PROGMEM area).
macro that reads a byte of data stored in a specified address(PROGMEM area).
macro that reads a byte of data stored in a specified address(PROGMEM area).
assembler code that reads a byte of data stored in a specified address(PROGMEM area).
macro that read a word of data stored in a specified address(PROGMEM area).
macro that reads a word of data stored in a specified address(PROGMEM area).
macro that reads a word of data stored in a specified address(PROGMEM area).
macro that reads a byte of data stored in a specified address(PROGMEM area).
common.h
Status register of ATmega328P.
sfr_defs.h
macro that checks if the second argumen-th bit of the first argument is 1.
macro that returns the address of the argument.
macro that returns the address of the argument.
macro that returns a byte of data of the specified address.
macro that returns two bytes of data of the specified address.
converts the I/O address to the memory address.
macro to return a byte of data of the specified address.
macro to return two bytes of data of the specified address.
macro that dereferences a byte of data at the specified address.
macro that dereferences two bytes of data at the specified address.
macro that checks if the second argumen-th bit of the first argument is 1.
macro that checks if the second argument-th bit of the first argument is 0.
macro to convert an interrupt vector number to a real address.
iom328p.h
registers which determine if the digital pin is output mode or input mode.
registers to control digital I/O.
registers for bi-directional I/O.
register that controls the reference voltage, the presentation of the ADC conversion and analog channel selection.
register to control AD conversion.
registers which store the result of AD conversion.
macro to read ADCL/ADCH registers.
registers to control timers and counters.
registers to set the duty ratio for PWM output.
registers related to timer interruption.
Definitions of the interrupt vectors.
registers incremented by each timer clock.
registers to control timer interruption.
registers to control external interrupts.
registers related to Universal Synchronous and Asynchronous serial Receiver and Transmitter.
interrupt.h
macro that executes an assembler instruction to disable interrupts.
macro that executes an assembler instruction to enable interrupts.
macro that executes an assembler instruction to disable interrupts.
macro to define a function to register to interrupt vectors.

Last update

March 21, 2023

inserted by FC2 system