Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codebase cleanup #917

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion crt1/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@
EXTRA_DIST = gcrt1.S
SUBDIRS = iosym
DIST_SUBDIRS = iosym

4 changes: 2 additions & 2 deletions crt1/gcrt1.S
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ __do_copy_data:
.balign 4

/* Set REGION_LENGTH symbol values for well known memory regions.
The default linker script uses these symbols to set MEMORY
The default linker script uses these symbols to set MEMORY
region lengths, and by defining these here, the linker can detect
memory overflows accurately on a per device basis, since the
memory overflows accurately on a per device basis, since the
values are picked up from the device header file.
*/

Expand Down
2 changes: 1 addition & 1 deletion include/alloca.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
\return alloca() returns a pointer to the beginning of the allocated
space. If the allocation causes stack overflow, program behaviour is
undefined.

\warning Avoid use alloca() inside the list of arguments of a function
call.
*/
Expand Down
38 changes: 19 additions & 19 deletions include/avr/boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
macros are designed to work with all sizes of flash memory.

Global interrupts are not automatically disabled for these macros. It
is left up to the programmer to do this. See the code example below.
Also see the processor datasheet for caveats on having global interrupts
is left up to the programmer to do this. See the code example below.
Also see the processor datasheet for caveats on having global interrupts
enabled during writing of the Flash.

\note Not all AVR processors provide bootloader support. See your
Expand All @@ -62,7 +62,7 @@
#include <inttypes.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>

void boot_program_page (uint32_t page, uint8_t *buf)
{
uint16_t i;
Expand All @@ -72,7 +72,7 @@

sreg = SREG;
cli();

eeprom_busy_wait ();

boot_page_erase (page);
Expand All @@ -84,7 +84,7 @@

uint16_t w = *buf++;
w += (*buf++) << 8;

boot_page_fill (page + i, w);
}

Expand Down Expand Up @@ -388,11 +388,11 @@

If bits 5..2 in R0 are cleared (zero), the corresponding Boot Lock bit
will be programmed if an SPM instruction is executed within four cycles
after BLBSET and SPMEN (or SELFPRGEN) are set in SPMCR. The Z-pointer is
don't care during this operation, but for future compatibility it is
recommended to load the Z-pointer with $0001 (same as used for reading the
Lock bits). For future compatibility It is also recommended to set bits 7,
6, 1, and 0 in R0 to 1 when writing the Lock bits. When programming the
after BLBSET and SPMEN (or SELFPRGEN) are set in SPMCR. The Z-pointer is
don't care during this operation, but for future compatibility it is
recommended to load the Z-pointer with $0001 (same as used for reading the
Lock bits). For future compatibility It is also recommended to set bits 7,
6, 1, and 0 in R0 to 1 when writing the Lock bits. When programming the
Lock bits the entire Flash can be read during the operation. */

#define __boot_lock_bits_set(lock_bits) \
Expand Down Expand Up @@ -437,8 +437,8 @@
/*
Reading lock and fuse bits:

Similarly to writing the lock bits above, set BLBSET and SPMEN (or
SELFPRGEN) bits in __SPMREG, and then (within four clock cycles) issue an
Similarly to writing the lock bits above, set BLBSET and SPMEN (or
SELFPRGEN) bits in __SPMREG, and then (within four clock cycles) issue an
LPM instruction.

Z address: contents:
Expand Down Expand Up @@ -533,13 +533,13 @@
/** \ingroup avr_boot
\def boot_page_fill(address, data)

Fill the bootloader temporary page buffer for flash
address with data word.
Fill the bootloader temporary page buffer for flash
address with data word.

\note The address is a byte address. The data is a word. The AVR
\note The address is a byte address. The data is a word. The AVR
writes data to the buffer a word at a time, but addresses the buffer
per byte! So, increment your address by 2 between calls, and send 2
data bytes in a word format! The LSB of the data is written to the lower
data bytes in a word format! The LSB of the data is written to the lower
address; the MSB of the data is written to the higher address.*/

/** \ingroup avr_boot
Expand All @@ -552,9 +552,9 @@
/** \ingroup avr_boot
\def boot_page_write(address)

Write the bootloader temporary page buffer
Write the bootloader temporary page buffer
to flash page that contains address.

\note address is a byte address in flash, not a word address. */

/** \ingroup avr_boot
Expand Down Expand Up @@ -589,7 +589,7 @@
instruction sequences after LPM.

FLASHEND is defined in the ioXXXX.h file.
USHRT_MAX is defined in <limits.h>. */
USHRT_MAX is defined in <limits.h>. */

#if defined(__AVR_ATmega161__) || defined(__AVR_ATmega163__) \
|| defined(__AVR_ATmega323__)
Expand Down
14 changes: 7 additions & 7 deletions include/avr/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@

#include <avr/sfr_defs.h>

/*
This purpose of this header is to define registers that have not been
previously defined in the individual device IO header files, and to define
/*
This purpose of this header is to define registers that have not been
previously defined in the individual device IO header files, and to define
other symbols that are common across AVR device families.

This file is designed to be included in <avr/io.h> after the individual
Expand All @@ -48,7 +48,7 @@ device IO header files, and after <avr/sfr_defs.h>

/*------------ Registers Not Previously Defined ------------*/

/*
/*
These are registers that are not previously defined in the individual
IO header files, OR they are defined here because they are used in parts of
avr-libc even if a device is not selected but a general architecture has
Expand All @@ -59,7 +59,7 @@ been selected.
/*
Stack pointer register.

AVR architecture 1 has no RAM, thus no stack pointer.
AVR architecture 1 has no RAM, thus no stack pointer.

All other architectures do have a stack pointer. Some devices have only
less than 256 bytes of possible RAM locations (128 Bytes of SRAM
Expand All @@ -76,7 +76,7 @@ for them.
# ifndef SP
# define SP _SFR_MEM16(0x3D)
# endif
#elif __AVR_ARCH__ != 1
#elif __AVR_ARCH__ != 1
# ifndef SPL
# define SPL _SFR_IO8(0x3D)
# endif
Expand Down Expand Up @@ -205,7 +205,7 @@ keep the EEPROM-related definitions here.

/*------------ Common Symbols ------------*/

/*
/*
Generic definitions for registers that are common across multiple AVR devices
and families.
*/
Expand Down
4 changes: 2 additions & 2 deletions include/avr/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
them).

- All write functions force erase_and_write programming mode.

- For Xmega the EEPROM start address is 0, like other architectures.
The reading functions add the 0x2000 value to use EEPROM mapping into
data space.
Expand Down Expand Up @@ -129,7 +129,7 @@ extern "C" {
\ingroup avr_eeprom
Loops until the eeprom is no longer busy.
\returns Nothing.
*/
*/
#define eeprom_busy_wait() do {} while (!eeprom_is_ready())


Expand Down
80 changes: 40 additions & 40 deletions include/avr/fuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,37 +54,37 @@
the ELF file, by extracting this information and determining if the fuses
need to be programmed before programming the Flash and EEPROM memories.
This also allows a single ELF file to contain all the
information needed to program an AVR.
information needed to program an AVR.

To use the Fuse API, include the <avr/io.h> header file, which in turn
automatically includes the individual I/O header file and the <avr/fuse.h>
file. These other two files provides everything necessary to set the AVR
fuses.

\par Fuse API

Each I/O header file must define the FUSE_MEMORY_SIZE macro which is
defined to the number of fuse bytes that exist in the AVR device.
A new type, __fuse_t, is defined as a structure. The number of fields in
this structure are determined by the number of fuse bytes in the

A new type, __fuse_t, is defined as a structure. The number of fields in
this structure are determined by the number of fuse bytes in the
FUSE_MEMORY_SIZE macro.

If FUSE_MEMORY_SIZE == 1, there is only a single field: byte, of type
unsigned char.

If FUSE_MEMORY_SIZE == 2, there are two fields: low, and high, of type
unsigned char.

If FUSE_MEMORY_SIZE == 3, there are three fields: low, high, and extended,
of type unsigned char.

If FUSE_MEMORY_SIZE > 3, there is a single field: byte, which is an array
of unsigned char with the size of the array being FUSE_MEMORY_SIZE.
A convenience macro, FUSEMEM, is defined as a GCC attribute for a

A convenience macro, FUSEMEM, is defined as a GCC attribute for a
custom-named section of ".fuse".

A convenience macro, FUSES, is defined that declares a variable, __fuse, of
type __fuse_t with the attribute defined by FUSEMEM. This variable
allows the end user to easily set the fuse data.
Expand All @@ -102,20 +102,20 @@
\code
#define FUSE_EESAVE ~_BV(3)
\endcode
\note The _BV macro creates a bit mask from a bit number. It is then
\note The _BV macro creates a bit mask from a bit number. It is then
inverted to represent logical values for a fuse memory byte.

To combine the fuse bits macros together to represent a whole fuse byte,
use the bitwise AND operator, like so:
\code
(FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN)
\endcode

Each device I/O header file also defines macros that provide default values
for each fuse byte that is available. LFUSE_DEFAULT is defined for a Low
Fuse byte. HFUSE_DEFAULT is defined for a High Fuse byte. EFUSE_DEFAULT
is defined for an Extended Fuse byte.

If FUSE_MEMORY_SIZE > 3, then the I/O header file defines macros that
provide default values for each fuse byte like so:
FUSE0_DEFAULT
Expand All @@ -124,15 +124,15 @@
FUSE3_DEFAULT
FUSE4_DEFAULT
....

\par API Usage Example

Putting all of this together is easy. Using C99's designated initializers:

\code
#include <avr/io.h>

FUSES =
FUSES =
{
.low = LFUSE_DEFAULT,
.high = (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN),
Expand All @@ -144,13 +144,13 @@
return 0;
}
\endcode

Or, using the variable directly instead of the FUSES macro,

\code
#include <avr/io.h>

__fuse_t __fuse __attribute__((section (".fuse"))) =
__fuse_t __fuse __attribute__((section (".fuse"))) =
{
.low = LFUSE_DEFAULT,
.high = (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN),
Expand All @@ -162,14 +162,14 @@
return 0;
}
\endcode

If you are compiling in C++, you cannot use the designated intializers so
you must do:

\code
#include <avr/io.h>

FUSES =
FUSES =
{
LFUSE_DEFAULT, // .low
(FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN), // .high
Expand All @@ -181,33 +181,33 @@
return 0;
}
\endcode


However there are a number of caveats that you need to be aware of to
use this API properly.

Be sure to include <avr/io.h> to get all of the definitions for the API.
The FUSES macro defines a global variable to store the fuse data. This
variable is assigned to its own linker section. Assign the desired fuse
The FUSES macro defines a global variable to store the fuse data. This
variable is assigned to its own linker section. Assign the desired fuse
values immediately in the variable initialization.
The .fuse section in the ELF file will get its values from the initial
variable assignment ONLY. This means that you can NOT assign values to

The .fuse section in the ELF file will get its values from the initial
variable assignment ONLY. This means that you can NOT assign values to
this variable in functions and the new values will not be put into the
ELF .fuse section.
The global variable is declared in the FUSES macro has two leading

The global variable is declared in the FUSES macro has two leading
underscores, which means that it is reserved for the "implementation",
meaning the library, so it will not conflict with a user-named variable.

You must initialize ALL fields in the __fuse_t structure. This is because
the fuse bits in all bytes default to a logical 1, meaning unprogrammed.
the fuse bits in all bytes default to a logical 1, meaning unprogrammed.
Normal uninitialized data defaults to all locgial zeros. So it is vital that
all fuse bytes are initialized, even with default data. If they are not,
then the fuse bits may not programmed to the desired settings.

Be sure to have the -mmcu=<em>device</em> flag in your compile command line and
your linker command line to have the correct device selected and to have
your linker command line to have the correct device selected and to have
the correct I/O header file included when you include <avr/io.h>.

You can print out the contents of the .fuse section in the ELF file by
Expand Down
Loading