You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
5.5 KiB
Groff
121 lines
5.5 KiB
Groff
.TH "<avr/lock.h>: Lockbit Support" 3 "24 Jun 2019" "Version 2.0.0" "avr-libc" \" -*- nroff -*-
|
|
.ad l
|
|
.nh
|
|
.SH NAME
|
|
<avr/lock.h>: Lockbit Support \- \fBIntroduction\fP.RS 4
|
|
|
|
.RE
|
|
.PP
|
|
The Lockbit API allows a user to specify the lockbit settings for the specific AVR device they are compiling for. These lockbit settings will be placed in a special section in the ELF output file, after linking.
|
|
.PP
|
|
Programming tools can take advantage of the lockbit information embedded in the ELF file, by extracting this information and determining if the lockbits need to be programmed after programming the Flash and EEPROM memories. This also allows a single ELF file to contain all the information needed to program an AVR.
|
|
.PP
|
|
To use the Lockbit API, include the <\fBavr/io.h\fP> header file, which in turn automatically includes the individual I/O header file and the <\fBavr/lock.h\fP> file. These other two files provides everything necessary to set the AVR lockbits.
|
|
.PP
|
|
\fBLockbit API\fP.RS 4
|
|
|
|
.RE
|
|
.PP
|
|
Each I/O header file may define up to 3 macros that controls what kinds of lockbits are available to the user.
|
|
.PP
|
|
If __LOCK_BITS_EXIST is defined, then two lock bits are available to the user and 3 mode settings are defined for these two bits.
|
|
.PP
|
|
If __BOOT_LOCK_BITS_0_EXIST is defined, then the two BLB0 lock bits are available to the user and 4 mode settings are defined for these two bits.
|
|
.PP
|
|
If __BOOT_LOCK_BITS_1_EXIST is defined, then the two BLB1 lock bits are available to the user and 4 mode settings are defined for these two bits.
|
|
.PP
|
|
If __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST is defined then two lock bits are available to set the locking mode for the Application Table Section (which is used in the XMEGA family).
|
|
.PP
|
|
If __BOOT_LOCK_APPLICATION_BITS_EXIST is defined then two lock bits are available to set the locking mode for the Application Section (which is used in the XMEGA family).
|
|
.PP
|
|
If __BOOT_LOCK_BOOT_BITS_EXIST is defined then two lock bits are available to set the locking mode for the Boot Loader Section (which is used in the XMEGA family).
|
|
.PP
|
|
The AVR lockbit modes have inverted values, logical 1 for an unprogrammed (disabled) bit and logical 0 for a programmed (enabled) bit. The defined macros for each individual lock bit represent this in their definition by a bit-wise inversion of a mask. For example, the LB_MODE_3 macro is defined as:
|
|
.PP
|
|
.nf
|
|
#define LB_MODE_3 (0xFC)
|
|
`
|
|
|
|
.fi
|
|
.PP
|
|
.PP
|
|
To combine the lockbit mode macros together to represent a whole byte, use the bitwise AND operator, like so:
|
|
.PP
|
|
.nf
|
|
(LB_MODE_3 & BLB0_MODE_2)
|
|
|
|
.fi
|
|
.PP
|
|
.PP
|
|
<\fBavr/lock.h\fP> also defines a macro that provides a default lockbit value: LOCKBITS_DEFAULT which is defined to be 0xFF.
|
|
.PP
|
|
See the AVR device specific datasheet for more details about these lock bits and the available mode settings.
|
|
.PP
|
|
A convenience macro, LOCKMEM, is defined as a GCC attribute for a custom-named section of '.lock'.
|
|
.PP
|
|
A convenience macro, LOCKBITS, is defined that declares a variable, __lock, of type unsigned char with the attribute defined by LOCKMEM. This variable allows the end user to easily set the lockbit data.
|
|
.PP
|
|
\fBNote:\fP
|
|
.RS 4
|
|
If a device-specific I/O header file has previously defined LOCKMEM, then LOCKMEM is not redefined. If a device-specific I/O header file has previously defined LOCKBITS, then LOCKBITS is not redefined. LOCKBITS is currently known to be defined in the I/O header files for the XMEGA devices.
|
|
.RE
|
|
.PP
|
|
\fBAPI Usage Example\fP.RS 4
|
|
|
|
.RE
|
|
.PP
|
|
Putting all of this together is easy:
|
|
.PP
|
|
.PP
|
|
.nf
|
|
#include <avr/io.h>
|
|
|
|
LOCKBITS = (LB_MODE_1 & BLB0_MODE_3 & BLB1_MODE_4);
|
|
|
|
int main(void)
|
|
{
|
|
return 0;
|
|
}
|
|
.fi
|
|
.PP
|
|
.PP
|
|
Or:
|
|
.PP
|
|
.PP
|
|
.nf
|
|
#include <avr/io.h>
|
|
|
|
unsigned char __lock __attribute__((section ('.lock'))) =
|
|
(LB_MODE_1 & BLB0_MODE_3 & BLB1_MODE_4);
|
|
|
|
int main(void)
|
|
{
|
|
return 0;
|
|
}
|
|
.fi
|
|
.PP
|
|
.PP
|
|
However there are a number of caveats that you need to be aware of to use this API properly.
|
|
.PP
|
|
Be sure to include <\fBavr/io.h\fP> to get all of the definitions for the API. The LOCKBITS macro defines a global variable to store the lockbit data. This variable is assigned to its own linker section. Assign the desired lockbit values immediately in the variable initialization.
|
|
.PP
|
|
The .lock 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 .lock section.
|
|
.PP
|
|
The global variable is declared in the LOCKBITS 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.
|
|
.PP
|
|
You must initialize the lockbit variable to some meaningful value, even if it is the default value. This is because the lockbits default to a logical 1, meaning unprogrammed. Normal uninitialized data defaults to all locgial zeros. So it is vital that all lockbits are initialized, even with default data. If they are not, then the lockbits may not programmed to the desired settings and can possibly put your device into an unrecoverable state.
|
|
.PP
|
|
Be sure to have the -mmcu=\fIdevice\fP flag in your compile command line and your linker command line to have the correct device selected and to have the correct I/O header file included when you include <\fBavr/io.h\fP>.
|
|
.PP
|
|
You can print out the contents of the .lock section in the ELF file by using this command line:
|
|
.PP
|
|
.nf
|
|
avr-objdump -s -j .lock <ELF file>
|
|
|
|
.fi
|
|
.PP
|
|
|
|
.SH "Author"
|
|
.PP
|
|
Generated automatically by Doxygen for avr-libc from the source code.
|