Skip to content

Commit

Permalink
Rename FunctionAttributes.h to Attributes.h, as some attributes are a…
Browse files Browse the repository at this point in the history
…pplicable 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.

git-svn-id: http://lufa-lib.googlecode.com/svn@1209 d5102386-fcda-11dd-9fdb-3debd5008f28
  • Loading branch information
Dean authored and Dean committed Apr 15, 2010
1 parent d0ea04b commit bbb96af
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 19 deletions.
2 changes: 1 addition & 1 deletion trunk/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion trunk/LUFA.pnproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
*/

/** \file
* \brief AVR-GCC special function attribute macros.
* \brief AVR-GCC special function/variable 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.
* 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.
Expand All @@ -43,9 +44,10 @@
*/

/** \ingroup Group_Common
* @defgroup Group_FuncAttr Function Attributes
* @defgroup Group_GCCAttr Function/Variable Attributes
*
* Macros for easy access GCC function attributes, which can be applied to function prototypes.
* Macros for easy access GCC function and variable attributes, which can be applied to function prototypes or
* variable attributes.
*
* @{
*/
Expand Down Expand Up @@ -110,6 +112,13 @@
* 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
Expand Down
4 changes: 2 additions & 2 deletions trunk/LUFA/Common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,7 +59,7 @@
/* Includes: */
#include <avr/io.h>

#include "FunctionAttributes.h"
#include "Attributes.h"
#include "BoardTypes.h"

/* Public Interface - May be used in end-application: */
Expand Down
6 changes: 3 additions & 3 deletions trunk/LUFA/Drivers/USB/Class/Host/MassStorage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions trunk/LUFA/Drivers/USB/Class/Host/MassStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions trunk/LUFA/ManPages/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
* <b>Changed:</b>
* - AVRISP programmer project now has a more robust timeout system, allowing for an increase of the software USART speed
Expand Down
1 change: 1 addition & 0 deletions trunk/LUFA/ManPages/DevelopingWithLUFA.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/

63 changes: 63 additions & 0 deletions trunk/LUFA/ManPages/SoftwareBootloaderJump.txt
Original file line number Diff line number Diff line change
@@ -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 <avr/wdt.h>
* #include <avr/io.h>
* #include <util/delay.h>
*
* #include <LUFA/Common/Common.h>
* #include <LUFA/Drivers/USB/USB.h>
*
* 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.
*
*/

0 comments on commit bbb96af

Please sign in to comment.