From: Dean Camera Date: Thu, 15 Apr 2010 11:04:24 +0000 (+0000) Subject: Rename FunctionAttributes.h to Attributes.h, as some attributes are applicable to... X-Git-Tag: LUFA-110528-BETA~517 X-Git-Url: http://git.linex4red.de/pub/USBasp.git/commitdiff_plain/3eb81df998349e90c3d973e6301f19382c5b2e84 Rename FunctionAttributes.h to Attributes.h, as some attributes are applicable to variables also. Add new ATTR_NOINIT attribute for global variables. Add the beginnings of a SDP implentation to the incomplete BluetoothHost demo. Add const attribute to the Mass Storage Host driver functions where it was applicable, but missing. --- diff --git a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c index df9f663e3..8dd5f91eb 100644 --- a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c +++ b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c @@ -251,7 +251,7 @@ void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t* { case CHANNEL_PSM_SDP: /* Service Discovery Protocol packet */ - ServiceDiscovery_ProcessPacket(Data, DataLen, Channel); + ServiceDiscovery_ProcessPacket(Data, Channel); break; default: /* Unknown Protocol packet */ diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c index d18e643b4..f96e10c37 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c @@ -694,7 +694,7 @@ static inline void Bluetooth_Signal_InformationReq(BT_Signal_Header_t* SignalCom struct { - BT_Signal_Header_t SignalCommandHeader; + BT_Signal_Header_t SignalCommandHeader; BT_Signal_InformationResp_t InformationResponse; uint8_t Data[4]; diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c index 1ee4c842e..124b129a0 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c @@ -28,14 +28,98 @@ this software. */ +#define INCLUDE_FROM_SERVICEDISCOVERYPROTOCOL_C #include "ServiceDiscoveryProtocol.h" -void ServiceDiscovery_ProcessPacket(void* Data, uint16_t Length, Bluetooth_Channel_t* Channel) +void ServiceDiscovery_ProcessPacket(void* Data, Bluetooth_Channel_t* Channel) { SDP_PDUHeader_t* SDPHeader = (SDP_PDUHeader_t*)Data; SDPHeader->ParameterLength = SwapEndian_16(SDPHeader->ParameterLength); - BT_SDP_DEBUG(1, "<< Service Discovery Packet", NULL); + BT_SDP_DEBUG(1, "SDP Packet Received", NULL); BT_SDP_DEBUG(2, "-- PDU ID: 0x%02X", SDPHeader->PDU); BT_SDP_DEBUG(2, "-- Param Length: 0x%04X", SDPHeader->ParameterLength); + + switch (SDPHeader->PDU) + { + case SDP_PDU_SERVICESEARCHREQUEST: + ServiceDiscovery_ProcessServiceSearch(SDPHeader); + break; + case SDP_PDU_SERVICEATTRIBUTEREQUEST: + ServiceDiscovery_ProcessServiceAttribute(SDPHeader); + break; + case SDP_PDU_SERVICESEARCHATTRIBUTEREQUEST: + ServiceDiscovery_ProcessServiceSearchAttribute(SDPHeader); + break; + } +} + +static void ServiceDiscovery_ProcessServiceSearch(SDP_PDUHeader_t* SDPHeader) +{ + BT_SDP_DEBUG(1, "<< Service Search", NULL); +} + +static void ServiceDiscovery_ProcessServiceAttribute(SDP_PDUHeader_t* SDPHeader) +{ + BT_SDP_DEBUG(1, "<< Service Attribute", NULL); +} + +static void ServiceDiscovery_ProcessServiceSearchAttribute(SDP_PDUHeader_t* SDPHeader) +{ + uint8_t* CurrentParameter = ((uint8_t*)SDPHeader + sizeof(SDP_PDUHeader_t)); + + BT_SDP_DEBUG(1, "<< Service Search Attribute", NULL); + + uint8_t ServicePatternLength = ServiceDiscovery_GetDataElementSize(CurrentParameter); + while (ServicePatternLength) + { + uint8_t UUIDLength = ServiceDiscovery_GetDataElementSize(CurrentParameter); + uint8_t UUID[16]; + + memset(UUID, 0x00, sizeof(UUID)); + memcpy(&UUID[sizeof(UUID) - UUIDLength], CurrentParameter, UUIDLength); + + BT_SDP_DEBUG(2, "-- UUID: 0x%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", + UUID[0], UUID[1], UUID[2], UUID[3], UUID[4], UUID[5], UUID[6], UUID[7], + UUID[8], UUID[9], UUID[10], UUID[11], UUID[12], UUID[13], UUID[14], UUID[15]); + + ServicePatternLength -= UUIDLength; + } + + uint16_t MaxAttributeSize = ServiceDiscovery_Read16BitParameter(CurrentParameter); + + uint8_t AttributeIDListLength = ServiceDiscovery_GetDataElementSize(CurrentParameter); + while (AttributeIDListLength) + { + uint8_t AttributeLength = ServiceDiscovery_GetDataElementSize(CurrentParameter); + + BT_SDP_DEBUG(2, "-- Attribute Length: 0x%04X", AttributeLength); + + AttributeIDListLength -= AttributeLength; + } +} + +static uint32_t ServiceDiscovery_GetDataElementSize(void* DataElementHeader) +{ + uint8_t SizeIndex = (*((uint8_t*)DataElementHeader++) & 0x07); + + switch (SizeIndex) + { + case 0: + return 1; + case 1: + return 2; + case 2: + return 4; + case 3: + return 8; + case 4: + return 16; + case 5: + return *((uint8_t*)DataElementHeader++); + case 6: + return *((uint16_t*)DataElementHeader++); + default: + return *((uint32_t*)DataElementHeader++); + } } diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h index ed528e93f..b17cc2b1d 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h @@ -63,6 +63,19 @@ } SDP_PDUHeader_t; /* Function Prototypes: */ - void ServiceDiscovery_ProcessPacket(void* Data, uint16_t Length, Bluetooth_Channel_t* Channel); + void ServiceDiscovery_ProcessPacket(void* Data, Bluetooth_Channel_t* Channel); + + #if defined(INCLUDE_FROM_SERVICEDISCOVERYPROTOCOL_C) + static void ServiceDiscovery_ProcessServiceSearch(SDP_PDUHeader_t* SDPHeader); + static void ServiceDiscovery_ProcessServiceAttribute(SDP_PDUHeader_t* SDPHeader); + static void ServiceDiscovery_ProcessServiceSearchAttribute(SDP_PDUHeader_t* SDPHeader); + + static inline uint16_t ServiceDiscovery_Read16BitParameter(void* AttributeHeader) + { + return *((uint16_t*)AttributeHeader++); + } + + static uint32_t ServiceDiscovery_GetDataElementSize(void* AttributeHeader); + #endif #endif diff --git a/LUFA.pnproj b/LUFA.pnproj index f8a4f22c8..9631abd8b 100644 --- a/LUFA.pnproj +++ b/LUFA.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/LUFA/Common/Attributes.h b/LUFA/Common/Attributes.h new file mode 100644 index 000000000..62d40734a --- /dev/null +++ b/LUFA/Common/Attributes.h @@ -0,0 +1,134 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2010. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief AVR-GCC special function/variable attribute macros. + * + * This file contains macros for applying GCC specific attributes to functions and variables to control various + * optimizer and code generation features of the compiler. Attributes may be placed in the function prototype + * or variable declaration in any order, and multiple attributes can be specified for a single item via a space + * separated list. + * + * On incompatible versions of GCC or on other compilers, these macros evaluate to nothing unless they are + * critical to the code's function and thus must throw a compiler error when used. + * + * \note Do not include this file directly, rather include the Common.h header file instead to gain this file's + * functionality. + */ + +/** \ingroup Group_Common + * @defgroup Group_GCCAttr Function/Variable Attributes + * + * Macros for easy access GCC function and variable attributes, which can be applied to function prototypes or + * variable attributes. + * + * @{ + */ + +#ifndef __FUNCATTR_H__ +#define __FUNCATTR_H__ + + /* Preprocessor Checks: */ + #if !defined(__COMMON_H__) + #error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + #if (__GNUC__ >= 3) || defined(__DOXYGEN__) + /** Indicates to the compiler that the function can not ever return, so that any stack restoring or + * return code may be omitted by the compiler in the resulting binary. + */ + #define ATTR_NO_RETURN __attribute__ ((noreturn)) + + /** Indicates that the function returns a value which should not be ignored by the user code. When + * applied, any ignored return value from calling the function will produce a compiler warning. + */ + #define ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) + + /** Indicates that the specified parameters of the function are pointers which should never be NULL. + * When applied as a 1-based comma separated list the compiler will emit a warning if the specified + * parameters are known at compiler time to be NULL at the point of calling the function. + */ + #define ATTR_NON_NULL_PTR_ARG(...) __attribute__ ((nonnull (__VA_ARGS__))) + + /** Removes any preamble or postamble from the function. When used, the function will not have any + * register or stack saving code. This should be used with caution, and when used the programmer + * is responsible for maintaining stack and register integrity. + */ + #define ATTR_NAKED __attribute__ ((naked)) + + /** Prevents the compiler from considering a specified function for inlining. When applied, the given + * function will not be inlined under any circumstances. + */ + #define ATTR_NO_INLINE __attribute__ ((noinline)) + + /** Forces the compiler to inline the specified function. When applied, the given function will be + * inlined under all circumstances. + */ + #define ATTR_ALWAYS_INLINE __attribute__ ((always_inline)) + + /** Indicates that the specified function is pure, in that it has no side-effects other than global + * or parameter variable access. + */ + #define ATTR_PURE __attribute__ ((pure)) + + /** Indicates that the specified function is constant, in that it has no side effects other than + * parameter access. + */ + #define ATTR_CONST __attribute__ ((const)) + + /** Marks a given function as deprecated, which produces a warning if the function is called. */ + #define ATTR_DEPRECATED __attribute__ ((deprecated)) + + /** Marks a function as a weak reference, which can be overridden by other functions with an + * identical name (in which case the weak reference is discarded at link time). + */ + #define ATTR_WEAK __attribute__ ((weak)) + + /** Forces the compiler to not automatically zero the given global variable on startup, so that the + * current RAM contents is retained. Under most conditions this value will be random due to the + * behaviour of volatile memory once power is removed, but may be used in some specific circumstances, + * like the passing of values back after a system watchdog reset. + */ + #define ATTR_NO_INIT __attribute__ ((section (".noinit"))) + #endif + + /** Places the function in one of the initialization sections, which execute before the main function + * of the application. The init function number can be specified as "x", as an integer. Refer to the + * avr-libc manual for more information on the initialization sections. + */ + #define ATTR_INIT_SECTION(x) __attribute__ ((naked, section (".init" #x ))) + + /** Marks a function as an alias for another function of name "x". */ + #define ATTR_ALIAS(x) __attribute__ ((alias( #x ))) +#endif + +/** @} */ diff --git a/LUFA/Common/Common.h b/LUFA/Common/Common.h index f64de8ff8..5f1b2eae5 100644 --- a/LUFA/Common/Common.h +++ b/LUFA/Common/Common.h @@ -32,7 +32,7 @@ * \brief Common library convenience macros and functions. * * This file contains macros which are common to all library elements, and which may be useful in user code. It - * also includes other common headers, such as Atomic.h, FunctionAttributes.h and BoardTypes.h. + * also includes other common headers, such as Atomic.h, Attributes.h and BoardTypes.h. */ /** @defgroup Group_Common Common Utility Headers - LUFA/Drivers/Common/Common.h @@ -59,7 +59,7 @@ /* Includes: */ #include - #include "FunctionAttributes.h" + #include "Attributes.h" #include "BoardTypes.h" /* Public Interface - May be used in end-application: */ diff --git a/LUFA/Common/FunctionAttributes.h b/LUFA/Common/FunctionAttributes.h deleted file mode 100644 index a3c9a8a3a..000000000 --- a/LUFA/Common/FunctionAttributes.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2010. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief AVR-GCC special function attribute macros. - * - * This file contains macros for applying GCC specific attributes to functions to control various optimizer - * and code generation features of the compiler. Attributes may be placed in the function prototype in any - * order, and multiple attributes can be specified for a single function via a space separated list. - * - * On incompatible versions of GCC or on other compilers, these macros evaluate to nothing unless they are - * critical to the code's function and thus must throw a compiler error when used. - * - * \note Do not include this file directly, rather include the Common.h header file instead to gain this file's - * functionality. - */ - -/** \ingroup Group_Common - * @defgroup Group_FuncAttr Function Attributes - * - * Macros for easy access GCC function attributes, which can be applied to function prototypes. - * - * @{ - */ - -#ifndef __FUNCATTR_H__ -#define __FUNCATTR_H__ - - /* Preprocessor Checks: */ - #if !defined(__COMMON_H__) - #error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality. - #endif - - /* Public Interface - May be used in end-application: */ - /* Macros: */ - #if (__GNUC__ >= 3) || defined(__DOXYGEN__) - /** Indicates to the compiler that the function can not ever return, so that any stack restoring or - * return code may be omitted by the compiler in the resulting binary. - */ - #define ATTR_NO_RETURN __attribute__ ((noreturn)) - - /** Indicates that the function returns a value which should not be ignored by the user code. When - * applied, any ignored return value from calling the function will produce a compiler warning. - */ - #define ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) - - /** Indicates that the specified parameters of the function are pointers which should never be NULL. - * When applied as a 1-based comma separated list the compiler will emit a warning if the specified - * parameters are known at compiler time to be NULL at the point of calling the function. - */ - #define ATTR_NON_NULL_PTR_ARG(...) __attribute__ ((nonnull (__VA_ARGS__))) - - /** Removes any preamble or postamble from the function. When used, the function will not have any - * register or stack saving code. This should be used with caution, and when used the programmer - * is responsible for maintaining stack and register integrity. - */ - #define ATTR_NAKED __attribute__ ((naked)) - - /** Prevents the compiler from considering a specified function for inlining. When applied, the given - * function will not be inlined under any circumstances. - */ - #define ATTR_NO_INLINE __attribute__ ((noinline)) - - /** Forces the compiler to inline the specified function. When applied, the given function will be - * inlined under all circumstances. - */ - #define ATTR_ALWAYS_INLINE __attribute__ ((always_inline)) - - /** Indicates that the specified function is pure, in that it has no side-effects other than global - * or parameter variable access. - */ - #define ATTR_PURE __attribute__ ((pure)) - - /** Indicates that the specified function is constant, in that it has no side effects other than - * parameter access. - */ - #define ATTR_CONST __attribute__ ((const)) - - /** Marks a given function as deprecated, which produces a warning if the function is called. */ - #define ATTR_DEPRECATED __attribute__ ((deprecated)) - - /** Marks a function as a weak reference, which can be overridden by other functions with an - * identical name (in which case the weak reference is discarded at link time). - */ - #define ATTR_WEAK __attribute__ ((weak)) - #endif - - /** Places the function in one of the initialization sections, which execute before the main function - * of the application. The init function number can be specified as "x", as an integer. Refer to the - * avr-libc manual for more information on the initialization sections. - */ - #define ATTR_INIT_SECTION(x) __attribute__ ((naked, section (".init" #x ))) - - /** Marks a function as an alias for another function of name "x". */ - #define ATTR_ALIAS(x) __attribute__ ((alias( #x ))) -#endif - -/** @} */ diff --git a/LUFA/Drivers/USB/Class/Host/MassStorage.c b/LUFA/Drivers/USB/Class/Host/MassStorage.c index 1b67ba2c3..4ec0b244f 100644 --- a/LUFA/Drivers/USB/Class/Host/MassStorage.c +++ b/LUFA/Drivers/USB/Class/Host/MassStorage.c @@ -130,7 +130,7 @@ static uint8_t DComp_NextMSInterfaceEndpoint(void* const CurrentDescriptor) } static uint8_t MS_Host_SendCommand(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, MS_CommandBlockWrapper_t* const SCSICommandBlock, - void* BufferPtr) + const void* const BufferPtr) { uint8_t ErrorCode = PIPE_RWSTREAM_NoError; @@ -152,7 +152,7 @@ static uint8_t MS_Host_SendCommand(USB_ClassInfo_MS_Host_t* const MSInterfaceInf Pipe_Freeze(); if ((BufferPtr != NULL) && - ((ErrorCode = MS_Host_SendReceiveData(MSInterfaceInfo, SCSICommandBlock, BufferPtr)) != PIPE_RWSTREAM_NoError)) + ((ErrorCode = MS_Host_SendReceiveData(MSInterfaceInfo, SCSICommandBlock, (void*)BufferPtr)) != PIPE_RWSTREAM_NoError)) { Pipe_Freeze(); return ErrorCode; @@ -557,7 +557,7 @@ uint8_t MS_Host_ReadDeviceBlocks(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, } uint8_t MS_Host_WriteDeviceBlocks(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, const uint8_t LUNIndex, const uint32_t BlockAddress, - const uint8_t Blocks, const uint16_t BlockSize, void* BlockBuffer) + const uint8_t Blocks, const uint16_t BlockSize, const void* BlockBuffer) { if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.IsActive)) return HOST_SENDCONTROL_DeviceDisconnected; diff --git a/LUFA/Drivers/USB/Class/Host/MassStorage.h b/LUFA/Drivers/USB/Class/Host/MassStorage.h index 3dbf64940..d2ab97009 100644 --- a/LUFA/Drivers/USB/Class/Host/MassStorage.h +++ b/LUFA/Drivers/USB/Class/Host/MassStorage.h @@ -277,7 +277,7 @@ */ uint8_t MS_Host_WriteDeviceBlocks(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, const uint8_t LUNIndex, const uint32_t BlockAddress, const uint8_t Blocks, const uint16_t BlockSize, - void* BlockBuffer) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(6); + const void* BlockBuffer) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(6); /* Inline Functions: */ /** General management task for a given Mass Storage host class interface, required for the correct operation of @@ -320,7 +320,7 @@ static uint8_t MS_Host_SendCommand(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, MS_CommandBlockWrapper_t* const SCSICommandBlock, - void* BufferPtr); + const void* const BufferPtr); static uint8_t MS_Host_WaitForDataReceived(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo); static uint8_t MS_Host_SendReceiveData(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, MS_CommandBlockWrapper_t* const SCSICommandBlock, void* BufferPtr); diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt index 57093aeb6..f4c995f17 100644 --- a/LUFA/ManPages/ChangeLog.txt +++ b/LUFA/ManPages/ChangeLog.txt @@ -12,6 +12,7 @@ * - Added incomplete MIDIToneGenerator project * - Added new Relay Controller Board project (thanks to OBinou) * - Added board hardware driver support for the Teensy, USBTINY MKII, Benito and JM-DB-U2 lines of third party USB AVR boards + * - Added new ATTR_NO_INIT variable attribute * * Changed: * - AVRISP programmer project now has a more robust timeout system, allowing for an increase of the software USART speed diff --git a/LUFA/ManPages/DevelopingWithLUFA.txt b/LUFA/ManPages/DevelopingWithLUFA.txt index 66c1ed4c6..eb079baab 100644 --- a/LUFA/ManPages/DevelopingWithLUFA.txt +++ b/LUFA/ManPages/DevelopingWithLUFA.txt @@ -16,6 +16,7 @@ * - \subpage Page_VIDPID Allocated USB VID and PID Values * - \subpage Page_BuildLibrary Building as a Linkable Library * - \subpage Page_WritingBoardDrivers How to Write Custom Board Drivers + * - \subpage Page_SoftwareBootloaderStart How to jump to the bootloader in software * - \subpage Page_SchedulerOverview Overview of the Simple LUFA Scheduler (DEPRECATED) */ \ No newline at end of file diff --git a/LUFA/ManPages/SoftwareBootloaderJump.txt b/LUFA/ManPages/SoftwareBootloaderJump.txt new file mode 100644 index 000000000..afdc0b32a --- /dev/null +++ b/LUFA/ManPages/SoftwareBootloaderJump.txt @@ -0,0 +1,63 @@ +/** \file + * + * This file contains special DoxyGen information for the generation of the main page and other special + * documentation pages. It is not a project source file. + */ + +/** + * \page Page_SoftwareBootloaderStart Entering the Bootloader via Software + * + * A common requirement of many applications is the ability to jump to the programmed bootloader of a chip + * on demand, via the code's firmware (i.e. not as a result of any physical user interaction with the + * hardware). This might be required because the device does not have any physical user input, or simply + * just to streamline the device upgrade process on the host PC. + * + * The following C code snippet may be used to enter the bootloader upon request by the user application. + * By using the watchdog to physically reset the controller, it is ensured that all system hardware is + * completely reset to their defaults before the bootloader is run. This is important; since bootloaders + * are written to occupy a very limited space, they usually make assumptions about the register states based + * on the default values after a hard-reset of the chip. + * + * \code + * #include + * #include + * #include + * + * #include + * #include + * + * uint32_t Boot_Key ATTR_NO_INIT; + * + * #define MAGIC_BOOT_KEY 0xDC42ACCA + * #define BOOTLOADER_START_ADDRESS ({FLASH_SIZE_BYTES} - {BOOTLOADER_SEC_SIZE_BYTES}) + * + * int Bootloader_Jump_Check(void) ATTR_INIT_SECTION(3); + * int Bootloader_Jump_Check(void) + * { + * // If the bootloader key is correct, clear it and jump to the bootloader + * if (Boot_Key == MAGIC_BOOT_KEY) + * { + * Boot_Key = 0; + * ((void (*)(void))BOOTLOADER_START_ADDRESS)(); + * } + * } + * + * void Jump_To_Bootloader(void) + * { + * // If USB is used, detatch from the bus and wait 2 seconds for the host to register it + * USB_ShutDown(); + * for (uint8_t i = 0; i < 128; i++) + * _delay_ms(16); + * + * // Set the bootloader key to the magic value and force a reset + * Boot_Key = MAGIC_BOOT_KEY; + * wdt_enable(WDTO_250MS); + * for (;;); + * } + * \endcode + * + * Note that the bootloader magic key can be any arbitrary value. The {FLASH_SIZE_BYTES} and + * {BOOTLOADER_SEC_SIZE_BYTES} tokens should be replaced with the total flash size of the AVR + * in bytes, and the allocated size of the bootloader section for the target AVR. + * + */ \ No newline at end of file