Review line ending handling (#4820)
* New line end handling rules * Normalize all the line endings
This commit is contained in:
+7012
-7012
File diff suppressed because it is too large
Load Diff
+7113
-7113
File diff suppressed because it is too large
Load Diff
+246
-246
@@ -1,246 +1,246 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <string.h>
|
||||
#include "debug.h"
|
||||
#include "diskio.h"
|
||||
#include "board_lowlevel.h"
|
||||
#include "Media.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Constants
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Number of SD Slots
|
||||
#define NUM_SD_SLOTS 1
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Checks if the device is write protected.
|
||||
/// \return 1 if protected.
|
||||
//------------------------------------------------------------------------------
|
||||
#if 0
|
||||
static unsigned char CardIsProtected(unsigned char slot)
|
||||
{
|
||||
if (slot == 0) {
|
||||
#ifdef BOARD_SD_PIN_WP
|
||||
PIO_Configure(&pinMciWriteProtect, 1);
|
||||
return (PIO_Get(&pinMciWriteProtect) != 0);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (slot == 1) {
|
||||
#ifdef BOARD_SD_MCI1_PIN_WP
|
||||
PIO_Configure(&pinMciWriteProtect1, 1);
|
||||
return (PIO_Get(&pinMciWriteProtect1) != 0);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Configure the PIO for SD
|
||||
//------------------------------------------------------------------------------
|
||||
#if 0
|
||||
static void ConfigurePIO(unsigned char mciID)
|
||||
{
|
||||
#ifdef BOARD_SD_PINS
|
||||
const Pin pinSd0[] = {BOARD_SD_PINS};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_SD_MCI1_PINS
|
||||
const Pin pinSd1[] = {BOARD_SD_MCI1_PINS};
|
||||
#endif
|
||||
|
||||
if(mciID == 0) {
|
||||
#ifdef BOARD_SD_PINS
|
||||
PIO_Configure(pinSd0, PIO_LISTSIZE(pinSd0));
|
||||
#endif
|
||||
} else {
|
||||
#ifdef BOARD_SD_MCI1_PINS
|
||||
PIO_Configure(pinSd1, PIO_LISTSIZE(pinSd1));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Reads a specified amount of data from a SDCARD memory
|
||||
//! \param media Pointer to a Media instance
|
||||
//! \param address Address of the data to read
|
||||
//! \param data Pointer to the buffer in which to store the retrieved
|
||||
//! data
|
||||
//! \param length Length of the buffer
|
||||
//! \param callback Optional pointer to a callback function to invoke when
|
||||
//! the operation is finished
|
||||
//! \param argument Optional pointer to an argument for the callback
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
static unsigned char MEDSdcard_Read(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
TRACE_DEBUG("MEDSdcard_Read(address=%d length=%d)\n\r", address, length);
|
||||
|
||||
// Check that the media is ready
|
||||
if (media->state != MED_STATE_READY) {
|
||||
|
||||
TRACE_INFO("Media busy\n\r");
|
||||
return MED_STATUS_BUSY;
|
||||
}
|
||||
|
||||
// Check that the data to read is not too big
|
||||
if ((length + address) > media->size) {
|
||||
|
||||
TRACE_WARNING("MEDSdcard_Read: Data too big: %d, %d\n\r",
|
||||
(int)length, (int)address);
|
||||
return MED_STATUS_ERROR;
|
||||
}
|
||||
|
||||
// Enter Busy state
|
||||
media->state = MED_STATE_BUSY;
|
||||
|
||||
disk_read (0, data, address, length);
|
||||
|
||||
// Leave the Busy state
|
||||
media->state = MED_STATE_READY;
|
||||
|
||||
// Invoke callback
|
||||
if (callback != 0) {
|
||||
|
||||
callback(argument, MED_STATUS_SUCCESS, 0, 0);
|
||||
}
|
||||
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Writes data on a SDRAM media
|
||||
//! \param media Pointer to a Media instance
|
||||
//! \param address Address at which to write
|
||||
//! \param data Pointer to the data to write
|
||||
//! \param length Size of the data buffer
|
||||
//! \param callback Optional pointer to a callback function to invoke when
|
||||
//! the write operation terminates
|
||||
//! \param argument Optional argument for the callback function
|
||||
//! \return Operation result code
|
||||
//! \see Media
|
||||
//! \see MediaCallback
|
||||
//------------------------------------------------------------------------------
|
||||
static unsigned char MEDSdcard_Write(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
|
||||
TRACE_DEBUG("MEDSdcard_Write(address=%d length=%d)\n\r", address, length);
|
||||
|
||||
// Check that the media if ready
|
||||
if (media->state != MED_STATE_READY) {
|
||||
|
||||
TRACE_WARNING("MEDSdcard_Write: Media is busy\n\r");
|
||||
return MED_STATUS_BUSY;
|
||||
}
|
||||
|
||||
// Check that the data to write is not too big
|
||||
if ((length + address) > media->size) {
|
||||
|
||||
TRACE_WARNING("MEDSdcard_Write: Data too big\n\r");
|
||||
return MED_STATUS_ERROR;
|
||||
}
|
||||
|
||||
// Put the media in Busy state
|
||||
media->state = MED_STATE_BUSY;
|
||||
|
||||
disk_write(0, data, address, length);
|
||||
|
||||
// Leave the Busy state
|
||||
media->state = MED_STATE_READY;
|
||||
|
||||
// Invoke the callback if it exists
|
||||
if (callback != 0) {
|
||||
|
||||
callback(argument, MED_STATUS_SUCCESS, 0, 0);
|
||||
}
|
||||
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Initializes a Media instance and the associated physical interface
|
||||
/// \param media Pointer to the Media instance to initialize
|
||||
/// \return 1 if success.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
unsigned char MEDSdcard_Initialize(Media *media, unsigned char mciID)
|
||||
{
|
||||
TRACE_INFO("MEDSdcard init\n\r");
|
||||
|
||||
// Initialize SDcard
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
if ( !SD_CARD_PRESENT( ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
media->write = MEDSdcard_Write;
|
||||
media->read = MEDSdcard_Read;
|
||||
media->lock = 0;
|
||||
media->unlock = 0;
|
||||
media->handler = 0;
|
||||
media->flush = 0;
|
||||
|
||||
media->blockSize = BLOCK_SIZE;
|
||||
media->baseAddress = 0;
|
||||
|
||||
media->size = SD_GET_BLOCKNR();
|
||||
|
||||
media->mappedRD = 0;
|
||||
media->mappedWR = 0;
|
||||
media->protected = 0;
|
||||
media->removable = 1;
|
||||
|
||||
media->state = MED_STATE_READY;
|
||||
|
||||
media->transfer.data = 0;
|
||||
media->transfer.address = 0;
|
||||
media->transfer.length = 0;
|
||||
media->transfer.callback = 0;
|
||||
media->transfer.argument = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <string.h>
|
||||
#include "debug.h"
|
||||
#include "diskio.h"
|
||||
#include "board_lowlevel.h"
|
||||
#include "Media.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Constants
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Number of SD Slots
|
||||
#define NUM_SD_SLOTS 1
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Checks if the device is write protected.
|
||||
/// \return 1 if protected.
|
||||
//------------------------------------------------------------------------------
|
||||
#if 0
|
||||
static unsigned char CardIsProtected(unsigned char slot)
|
||||
{
|
||||
if (slot == 0) {
|
||||
#ifdef BOARD_SD_PIN_WP
|
||||
PIO_Configure(&pinMciWriteProtect, 1);
|
||||
return (PIO_Get(&pinMciWriteProtect) != 0);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (slot == 1) {
|
||||
#ifdef BOARD_SD_MCI1_PIN_WP
|
||||
PIO_Configure(&pinMciWriteProtect1, 1);
|
||||
return (PIO_Get(&pinMciWriteProtect1) != 0);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Configure the PIO for SD
|
||||
//------------------------------------------------------------------------------
|
||||
#if 0
|
||||
static void ConfigurePIO(unsigned char mciID)
|
||||
{
|
||||
#ifdef BOARD_SD_PINS
|
||||
const Pin pinSd0[] = {BOARD_SD_PINS};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_SD_MCI1_PINS
|
||||
const Pin pinSd1[] = {BOARD_SD_MCI1_PINS};
|
||||
#endif
|
||||
|
||||
if(mciID == 0) {
|
||||
#ifdef BOARD_SD_PINS
|
||||
PIO_Configure(pinSd0, PIO_LISTSIZE(pinSd0));
|
||||
#endif
|
||||
} else {
|
||||
#ifdef BOARD_SD_MCI1_PINS
|
||||
PIO_Configure(pinSd1, PIO_LISTSIZE(pinSd1));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Reads a specified amount of data from a SDCARD memory
|
||||
//! \param media Pointer to a Media instance
|
||||
//! \param address Address of the data to read
|
||||
//! \param data Pointer to the buffer in which to store the retrieved
|
||||
//! data
|
||||
//! \param length Length of the buffer
|
||||
//! \param callback Optional pointer to a callback function to invoke when
|
||||
//! the operation is finished
|
||||
//! \param argument Optional pointer to an argument for the callback
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
static unsigned char MEDSdcard_Read(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
TRACE_DEBUG("MEDSdcard_Read(address=%d length=%d)\n\r", address, length);
|
||||
|
||||
// Check that the media is ready
|
||||
if (media->state != MED_STATE_READY) {
|
||||
|
||||
TRACE_INFO("Media busy\n\r");
|
||||
return MED_STATUS_BUSY;
|
||||
}
|
||||
|
||||
// Check that the data to read is not too big
|
||||
if ((length + address) > media->size) {
|
||||
|
||||
TRACE_WARNING("MEDSdcard_Read: Data too big: %d, %d\n\r",
|
||||
(int)length, (int)address);
|
||||
return MED_STATUS_ERROR;
|
||||
}
|
||||
|
||||
// Enter Busy state
|
||||
media->state = MED_STATE_BUSY;
|
||||
|
||||
disk_read (0, data, address, length);
|
||||
|
||||
// Leave the Busy state
|
||||
media->state = MED_STATE_READY;
|
||||
|
||||
// Invoke callback
|
||||
if (callback != 0) {
|
||||
|
||||
callback(argument, MED_STATUS_SUCCESS, 0, 0);
|
||||
}
|
||||
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Writes data on a SDRAM media
|
||||
//! \param media Pointer to a Media instance
|
||||
//! \param address Address at which to write
|
||||
//! \param data Pointer to the data to write
|
||||
//! \param length Size of the data buffer
|
||||
//! \param callback Optional pointer to a callback function to invoke when
|
||||
//! the write operation terminates
|
||||
//! \param argument Optional argument for the callback function
|
||||
//! \return Operation result code
|
||||
//! \see Media
|
||||
//! \see MediaCallback
|
||||
//------------------------------------------------------------------------------
|
||||
static unsigned char MEDSdcard_Write(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
|
||||
TRACE_DEBUG("MEDSdcard_Write(address=%d length=%d)\n\r", address, length);
|
||||
|
||||
// Check that the media if ready
|
||||
if (media->state != MED_STATE_READY) {
|
||||
|
||||
TRACE_WARNING("MEDSdcard_Write: Media is busy\n\r");
|
||||
return MED_STATUS_BUSY;
|
||||
}
|
||||
|
||||
// Check that the data to write is not too big
|
||||
if ((length + address) > media->size) {
|
||||
|
||||
TRACE_WARNING("MEDSdcard_Write: Data too big\n\r");
|
||||
return MED_STATUS_ERROR;
|
||||
}
|
||||
|
||||
// Put the media in Busy state
|
||||
media->state = MED_STATE_BUSY;
|
||||
|
||||
disk_write(0, data, address, length);
|
||||
|
||||
// Leave the Busy state
|
||||
media->state = MED_STATE_READY;
|
||||
|
||||
// Invoke the callback if it exists
|
||||
if (callback != 0) {
|
||||
|
||||
callback(argument, MED_STATUS_SUCCESS, 0, 0);
|
||||
}
|
||||
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Initializes a Media instance and the associated physical interface
|
||||
/// \param media Pointer to the Media instance to initialize
|
||||
/// \return 1 if success.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
unsigned char MEDSdcard_Initialize(Media *media, unsigned char mciID)
|
||||
{
|
||||
TRACE_INFO("MEDSdcard init\n\r");
|
||||
|
||||
// Initialize SDcard
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
if ( !SD_CARD_PRESENT( ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
media->write = MEDSdcard_Write;
|
||||
media->read = MEDSdcard_Read;
|
||||
media->lock = 0;
|
||||
media->unlock = 0;
|
||||
media->handler = 0;
|
||||
media->flush = 0;
|
||||
|
||||
media->blockSize = BLOCK_SIZE;
|
||||
media->baseAddress = 0;
|
||||
|
||||
media->size = SD_GET_BLOCKNR();
|
||||
|
||||
media->mappedRD = 0;
|
||||
media->mappedWR = 0;
|
||||
media->protected = 0;
|
||||
media->removable = 1;
|
||||
|
||||
media->state = MED_STATE_READY;
|
||||
|
||||
media->transfer.data = 0;
|
||||
media->transfer.address = 0;
|
||||
media->transfer.length = 0;
|
||||
media->transfer.callback = 0;
|
||||
media->transfer.argument = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
+256
-256
@@ -18,262 +18,262 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Generic Media type, which provides transparent access to all types of
|
||||
/// memories.
|
||||
///
|
||||
/// \note The physical or HW related media operations (physical device
|
||||
/// connection & protection detecting, PIO configurations and interface
|
||||
/// driver initialization) are excluded.
|
||||
///
|
||||
/// !Usage
|
||||
/// -# Do PIO initialization for peripheral interfaces.
|
||||
/// -# Initialize peripheral interface driver & device driver.
|
||||
/// -# Initialize specific media interface and link to this initialized driver.
|
||||
///
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Generic Media type, which provides transparent access to all types of
|
||||
/// memories.
|
||||
///
|
||||
/// \note The physical or HW related media operations (physical device
|
||||
/// connection & protection detecting, PIO configurations and interface
|
||||
/// driver initialization) are excluded.
|
||||
///
|
||||
/// !Usage
|
||||
/// -# Do PIO initialization for peripheral interfaces.
|
||||
/// -# Initialize peripheral interface driver & device driver.
|
||||
/// -# Initialize specific media interface and link to this initialized driver.
|
||||
///
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _MEDIA_H_
|
||||
#define _MEDIA_H_
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//! \brief Operation result code returned by media methods
|
||||
#define MED_STATUS_SUCCESS 0x00
|
||||
#define MED_STATUS_ERROR 0x01
|
||||
#define MED_STATUS_BUSY 0x02
|
||||
#define MED_STATUS_PROTECTED 0x04
|
||||
|
||||
//! \brief Media statuses
|
||||
#define MED_STATE_READY 0x00 /// Media is ready for access
|
||||
#define MED_STATE_BUSY 0x01 /// Media is busy
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct _Media Media;
|
||||
|
||||
typedef void (*MediaCallback)(void *argument,
|
||||
unsigned char status,
|
||||
unsigned int transferred,
|
||||
unsigned int remaining);
|
||||
|
||||
typedef unsigned char (*Media_write)(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument);
|
||||
|
||||
typedef unsigned char (*Media_read)(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument);
|
||||
|
||||
typedef unsigned char (*Media_cancelIo)(Media *media);
|
||||
|
||||
typedef unsigned char (*Media_lock)(Media *media,
|
||||
unsigned int start,
|
||||
unsigned int end,
|
||||
unsigned int *pActualStart,
|
||||
unsigned int *pActualEnd);
|
||||
|
||||
typedef unsigned char (*Media_unlock)(Media *media,
|
||||
unsigned int start,
|
||||
unsigned int end,
|
||||
unsigned int *pActualStart,
|
||||
unsigned int *pActualEnd);
|
||||
|
||||
typedef unsigned char (*Media_ioctl)(Media *media,
|
||||
unsigned char ctrl,
|
||||
void *buff);
|
||||
|
||||
typedef unsigned char (*Media_flush)(Media *media);
|
||||
|
||||
typedef void (*Media_handler)(Media *media);
|
||||
|
||||
//! \brief Media transfer
|
||||
//! \see TransferCallback
|
||||
typedef struct {
|
||||
|
||||
void *data; //!< Pointer to the data buffer
|
||||
unsigned int address; //!< Address where to read/write the data
|
||||
unsigned int length; //!< Size of the data to read/write
|
||||
MediaCallback callback; //!< Callback to invoke when the transfer done
|
||||
void *argument; //!< Callback argument
|
||||
|
||||
} MEDTransfer;
|
||||
|
||||
//! \brief Media object
|
||||
//! \see MEDTransfer
|
||||
struct _Media {
|
||||
|
||||
Media_write write; //!< Write method
|
||||
Media_read read; //!< Read method
|
||||
Media_cancelIo cancelIo; //!< Cancel pending IO method
|
||||
Media_lock lock; //!< lock method if possible
|
||||
Media_unlock unlock; //!< unlock method if possible
|
||||
Media_flush flush; //!< Flush method
|
||||
Media_handler handler; //!< Interrupt handler
|
||||
unsigned int blockSize; //!< Block size in bytes (1, 512, 1K, 2K ...)
|
||||
unsigned int baseAddress; //!< Base address of media in number of blocks
|
||||
unsigned int size; //!< Size of media in number of blocks
|
||||
MEDTransfer transfer; //!< Current transfer operation
|
||||
void *interface; //!< Pointer to the physical interface used
|
||||
unsigned char bReserved:4,
|
||||
mappedRD:1, //!< Mapped to memory space to read
|
||||
mappedWR:1, //!< Mapped to memory space to write
|
||||
#ifdef __cplusplus
|
||||
protectd:1, //!< Protected media?
|
||||
#else
|
||||
protected:1, //!< Protected media?
|
||||
#endif
|
||||
removable:1; //!< Removable/Fixed media?
|
||||
unsigned char state; //!< Status of media
|
||||
unsigned short reserved;
|
||||
};
|
||||
|
||||
/// Available medias.
|
||||
extern Media medias[];
|
||||
|
||||
/// Number of medias which are effectively used.
|
||||
/// Defined by Media, shared usage by USB MSD & FS ...
|
||||
extern unsigned int numMedias;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Inline Functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Writes data on a media
|
||||
//! \param media Pointer to a Media instance
|
||||
//! \param address Address at which to write
|
||||
//! \param data Pointer to the data to write
|
||||
//! \param length Size of the data buffer
|
||||
//! \param callback Optional pointer to a callback function to invoke when
|
||||
//! the write operation terminates
|
||||
//! \param argument Optional argument for the callback function
|
||||
//! \return Operation result code
|
||||
//! \see TransferCallback
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Write(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
return media->write(media, address, data, length, callback, argument);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Reads a specified amount of data from a media
|
||||
//! \param media Pointer to a Media instance
|
||||
//! \param address Address of the data to read
|
||||
//! \param data Pointer to the buffer in which to store the retrieved
|
||||
//! data
|
||||
//! \param length Length of the buffer
|
||||
//! \param callback Optional pointer to a callback function to invoke when
|
||||
//! the operation is finished
|
||||
//! \param argument Optional pointer to an argument for the callback
|
||||
//! \return Operation result code
|
||||
//! \see TransferCallback
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Read(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
return media->read(media, address, data, length, callback, argument);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Locks all the regions in the given address range.
|
||||
//! \param media Pointer to a Media instance
|
||||
/// \param start Start address of lock range.
|
||||
/// \param end End address of lock range.
|
||||
/// \param pActualStart Start address of the actual lock range (optional).
|
||||
/// \param pActualEnd End address of the actual lock range (optional).
|
||||
/// \return 0 if successful; otherwise returns an error code.
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Lock(Media *media,
|
||||
unsigned int start,
|
||||
unsigned int end,
|
||||
unsigned int *pActualStart,
|
||||
unsigned int *pActualEnd)
|
||||
{
|
||||
if( media->lock ) {
|
||||
return media->lock(media, start, end, pActualStart, pActualEnd);
|
||||
}
|
||||
else {
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Unlocks all the regions in the given address range
|
||||
//! \param media Pointer to a Media instance
|
||||
/// \param start Start address of unlock range.
|
||||
/// \param end End address of unlock range.
|
||||
/// \param pActualStart Start address of the actual unlock range (optional).
|
||||
/// \param pActualEnd End address of the actual unlock range (optional).
|
||||
/// \return 0 if successful; otherwise returns an error code.
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Unlock(Media *media,
|
||||
unsigned int start,
|
||||
unsigned int end,
|
||||
unsigned int *pActualStart,
|
||||
unsigned int *pActualEnd)
|
||||
{
|
||||
if( media->unlock ) {
|
||||
return media->unlock(media, start, end, pActualStart, pActualEnd);
|
||||
}
|
||||
else {
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief
|
||||
//! \param media Pointer to the Media instance to use
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Flush(Media *media)
|
||||
{
|
||||
if (media->flush) {
|
||||
|
||||
return media->flush(media);
|
||||
}
|
||||
else {
|
||||
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Invokes the interrupt handler of the specified media
|
||||
//! \param media Pointer to the Media instance to use
|
||||
//------------------------------------------------------------------------------
|
||||
static inline void MED_Handler(Media *media)
|
||||
{
|
||||
if (media->handler) {
|
||||
|
||||
media->handler(media);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void MED_HandleAll(Media *medias, unsigned char numMedias);
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//! \brief Operation result code returned by media methods
|
||||
#define MED_STATUS_SUCCESS 0x00
|
||||
#define MED_STATUS_ERROR 0x01
|
||||
#define MED_STATUS_BUSY 0x02
|
||||
#define MED_STATUS_PROTECTED 0x04
|
||||
|
||||
//! \brief Media statuses
|
||||
#define MED_STATE_READY 0x00 /// Media is ready for access
|
||||
#define MED_STATE_BUSY 0x01 /// Media is busy
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct _Media Media;
|
||||
|
||||
typedef void (*MediaCallback)(void *argument,
|
||||
unsigned char status,
|
||||
unsigned int transferred,
|
||||
unsigned int remaining);
|
||||
|
||||
typedef unsigned char (*Media_write)(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument);
|
||||
|
||||
typedef unsigned char (*Media_read)(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument);
|
||||
|
||||
typedef unsigned char (*Media_cancelIo)(Media *media);
|
||||
|
||||
typedef unsigned char (*Media_lock)(Media *media,
|
||||
unsigned int start,
|
||||
unsigned int end,
|
||||
unsigned int *pActualStart,
|
||||
unsigned int *pActualEnd);
|
||||
|
||||
typedef unsigned char (*Media_unlock)(Media *media,
|
||||
unsigned int start,
|
||||
unsigned int end,
|
||||
unsigned int *pActualStart,
|
||||
unsigned int *pActualEnd);
|
||||
|
||||
typedef unsigned char (*Media_ioctl)(Media *media,
|
||||
unsigned char ctrl,
|
||||
void *buff);
|
||||
|
||||
typedef unsigned char (*Media_flush)(Media *media);
|
||||
|
||||
typedef void (*Media_handler)(Media *media);
|
||||
|
||||
//! \brief Media transfer
|
||||
//! \see TransferCallback
|
||||
typedef struct {
|
||||
|
||||
void *data; //!< Pointer to the data buffer
|
||||
unsigned int address; //!< Address where to read/write the data
|
||||
unsigned int length; //!< Size of the data to read/write
|
||||
MediaCallback callback; //!< Callback to invoke when the transfer done
|
||||
void *argument; //!< Callback argument
|
||||
|
||||
} MEDTransfer;
|
||||
|
||||
//! \brief Media object
|
||||
//! \see MEDTransfer
|
||||
struct _Media {
|
||||
|
||||
Media_write write; //!< Write method
|
||||
Media_read read; //!< Read method
|
||||
Media_cancelIo cancelIo; //!< Cancel pending IO method
|
||||
Media_lock lock; //!< lock method if possible
|
||||
Media_unlock unlock; //!< unlock method if possible
|
||||
Media_flush flush; //!< Flush method
|
||||
Media_handler handler; //!< Interrupt handler
|
||||
unsigned int blockSize; //!< Block size in bytes (1, 512, 1K, 2K ...)
|
||||
unsigned int baseAddress; //!< Base address of media in number of blocks
|
||||
unsigned int size; //!< Size of media in number of blocks
|
||||
MEDTransfer transfer; //!< Current transfer operation
|
||||
void *interface; //!< Pointer to the physical interface used
|
||||
unsigned char bReserved:4,
|
||||
mappedRD:1, //!< Mapped to memory space to read
|
||||
mappedWR:1, //!< Mapped to memory space to write
|
||||
#ifdef __cplusplus
|
||||
protectd:1, //!< Protected media?
|
||||
#else
|
||||
protected:1, //!< Protected media?
|
||||
#endif
|
||||
removable:1; //!< Removable/Fixed media?
|
||||
unsigned char state; //!< Status of media
|
||||
unsigned short reserved;
|
||||
};
|
||||
|
||||
/// Available medias.
|
||||
extern Media medias[];
|
||||
|
||||
/// Number of medias which are effectively used.
|
||||
/// Defined by Media, shared usage by USB MSD & FS ...
|
||||
extern unsigned int numMedias;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Inline Functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Writes data on a media
|
||||
//! \param media Pointer to a Media instance
|
||||
//! \param address Address at which to write
|
||||
//! \param data Pointer to the data to write
|
||||
//! \param length Size of the data buffer
|
||||
//! \param callback Optional pointer to a callback function to invoke when
|
||||
//! the write operation terminates
|
||||
//! \param argument Optional argument for the callback function
|
||||
//! \return Operation result code
|
||||
//! \see TransferCallback
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Write(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
return media->write(media, address, data, length, callback, argument);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Reads a specified amount of data from a media
|
||||
//! \param media Pointer to a Media instance
|
||||
//! \param address Address of the data to read
|
||||
//! \param data Pointer to the buffer in which to store the retrieved
|
||||
//! data
|
||||
//! \param length Length of the buffer
|
||||
//! \param callback Optional pointer to a callback function to invoke when
|
||||
//! the operation is finished
|
||||
//! \param argument Optional pointer to an argument for the callback
|
||||
//! \return Operation result code
|
||||
//! \see TransferCallback
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Read(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
return media->read(media, address, data, length, callback, argument);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Locks all the regions in the given address range.
|
||||
//! \param media Pointer to a Media instance
|
||||
/// \param start Start address of lock range.
|
||||
/// \param end End address of lock range.
|
||||
/// \param pActualStart Start address of the actual lock range (optional).
|
||||
/// \param pActualEnd End address of the actual lock range (optional).
|
||||
/// \return 0 if successful; otherwise returns an error code.
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Lock(Media *media,
|
||||
unsigned int start,
|
||||
unsigned int end,
|
||||
unsigned int *pActualStart,
|
||||
unsigned int *pActualEnd)
|
||||
{
|
||||
if( media->lock ) {
|
||||
return media->lock(media, start, end, pActualStart, pActualEnd);
|
||||
}
|
||||
else {
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Unlocks all the regions in the given address range
|
||||
//! \param media Pointer to a Media instance
|
||||
/// \param start Start address of unlock range.
|
||||
/// \param end End address of unlock range.
|
||||
/// \param pActualStart Start address of the actual unlock range (optional).
|
||||
/// \param pActualEnd End address of the actual unlock range (optional).
|
||||
/// \return 0 if successful; otherwise returns an error code.
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Unlock(Media *media,
|
||||
unsigned int start,
|
||||
unsigned int end,
|
||||
unsigned int *pActualStart,
|
||||
unsigned int *pActualEnd)
|
||||
{
|
||||
if( media->unlock ) {
|
||||
return media->unlock(media, start, end, pActualStart, pActualEnd);
|
||||
}
|
||||
else {
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief
|
||||
//! \param media Pointer to the Media instance to use
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Flush(Media *media)
|
||||
{
|
||||
if (media->flush) {
|
||||
|
||||
return media->flush(media);
|
||||
}
|
||||
else {
|
||||
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Invokes the interrupt handler of the specified media
|
||||
//! \param media Pointer to the Media instance to use
|
||||
//------------------------------------------------------------------------------
|
||||
static inline void MED_Handler(Media *media)
|
||||
{
|
||||
if (media->handler) {
|
||||
|
||||
media->handler(media);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void MED_HandleAll(Media *medias, unsigned char numMedias);
|
||||
|
||||
#endif // _MEDIA_H_
|
||||
|
||||
|
||||
|
||||
@@ -1,148 +1,148 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
uint16_t adcValues[NUM_ANALOGS];
|
||||
|
||||
#if defined(FRSKY_STICKS)
|
||||
const char ana_direction[NUM_ANALOGS] = {1, 1, 0, 1 ,0 ,1 ,0, 0, 0};
|
||||
#endif
|
||||
|
||||
|
||||
// Settings for mode register ADC_MR
|
||||
// USEQ off - silicon problem, doesn't work
|
||||
// TRANSFER = 3
|
||||
// TRACKTIM = 15 (16 clock periods)
|
||||
// ANACH = 1
|
||||
// SETTLING = 6 (not used if ANACH = 0)
|
||||
// STARTUP = 6 (96 clock periods)
|
||||
// PRESCAL = 9.0 MHz clock (between 1 and 20MHz)
|
||||
// FREERUN = 0
|
||||
// FWUP = 0
|
||||
// SLEEP = 0
|
||||
// LOWRES = 0
|
||||
// TRGSEL = 0
|
||||
// TRGEN = 0 (software trigger only)
|
||||
void adcInit()
|
||||
{
|
||||
Adc *padc ;
|
||||
uint32_t timer ;
|
||||
|
||||
timer = ( Master_frequency / (3600000*2) ) << 8 ;
|
||||
// Enable peripheral clock ADC = bit 29
|
||||
PMC->PMC_PCER0 |= 0x20000000L ; // Enable peripheral clock to ADC
|
||||
padc = ADC ;
|
||||
padc->ADC_MR = 0x3FB60000 | timer ; // 0011 1111 1011 0110 xxxx xxxx 0000 0000
|
||||
padc->ADC_ACR = ADC_ACR_TSON ; // Turn on temp sensor
|
||||
#if defined(REVA)
|
||||
padc->ADC_CHER = 0x0000E23E ; // channels 1,2,3,4,5,9,13,14,15
|
||||
#else
|
||||
padc->ADC_CHER = 0x0000E33E ; // channels 1,2,3,4,5,8,9,13,14,15
|
||||
#endif
|
||||
padc->ADC_CGR = 0 ; // Gain = 1, all channels
|
||||
padc->ADC_COR = 0 ; // Single ended, 0 offset, all channels
|
||||
}
|
||||
|
||||
// Read 8 (9 for REVB) ADC channels
|
||||
// Documented bug, must do them 1 by 1
|
||||
void adcSingleRead()
|
||||
{
|
||||
Adc *padc;
|
||||
uint32_t y;
|
||||
uint32_t x;
|
||||
|
||||
for (uint8_t i=0; i<4; i++)
|
||||
padc = ADC;
|
||||
y = padc->ADC_ISR; // Clear EOC flags
|
||||
for (y = NUM_ANALOGS+1; --y > 0;) {
|
||||
padc->ADC_CR = 2; // Start conversion
|
||||
x = 0;
|
||||
while ((padc->ADC_ISR & 0x01000000) == 0) {
|
||||
// wait for DRDY flag
|
||||
if (++x > 1000000) {
|
||||
break; // Software timeout
|
||||
}
|
||||
}
|
||||
x = padc->ADC_LCDR; // Clear DRSY flag
|
||||
}
|
||||
// Next bit may be done using the PDC
|
||||
adcValues[0] = ADC->ADC_CDR1;
|
||||
adcValues[1] = ADC->ADC_CDR2;
|
||||
adcValues[2] = ADC->ADC_CDR3;
|
||||
adcValues[3] = ADC->ADC_CDR4;
|
||||
adcValues[4] = ADC->ADC_CDR5;
|
||||
adcValues[5] = ADC->ADC_CDR9;
|
||||
adcValues[6] = ADC->ADC_CDR13;
|
||||
adcValues[7] = ADC->ADC_CDR14;
|
||||
|
||||
#if !defined(REVA)
|
||||
adcValues[8] = ADC->ADC_CDR8 ;
|
||||
#endif
|
||||
|
||||
temperature = (((int32_t)temperature * 7) + ((((int32_t)ADC->ADC_CDR15 - 838) * 621) >> 11)) >> 3; // Filter it
|
||||
if (get_tmr10ms() >= 100 && temperature > maxTemperature) {
|
||||
maxTemperature = temperature;
|
||||
}
|
||||
|
||||
// adc direction correct
|
||||
#if defined(FRSKY_STICKS)
|
||||
uint32_t i ;
|
||||
for (i=0; i<NUM_ANALOGS; i++) {
|
||||
if (ana_direction[i]) {
|
||||
adcValues[i] = 4096-adcValues[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void adcRead()
|
||||
{
|
||||
uint16_t temp[NUM_ANALOGS] = { 0 };
|
||||
|
||||
for (int i=0; i<4; i++) {
|
||||
adcSingleRead();
|
||||
for (uint8_t x=0; x<NUM_ANALOGS; x++) {
|
||||
uint16_t val = adcValues[x];
|
||||
#if defined(JITTER_MEASURE)
|
||||
if (JITTER_MEASURE_ACTIVE()) {
|
||||
rawJitter[x].measure(val);
|
||||
}
|
||||
#endif
|
||||
temp[x] += val;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t x=0; x<NUM_ANALOGS; x++) {
|
||||
adcValues[x] = temp[x] >> 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if !defined(SIMU)
|
||||
uint16_t getAnalogValue(uint8_t index)
|
||||
{
|
||||
#if defined(PCBSKY9X) && !defined(REVA)
|
||||
static const uint8_t mapping[] = {1,5,7,0,4,6,2,3};
|
||||
index = mapping[index];
|
||||
#endif
|
||||
return adcValues[index];
|
||||
}
|
||||
#endif // #if !defined(SIMU)
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
uint16_t adcValues[NUM_ANALOGS];
|
||||
|
||||
#if defined(FRSKY_STICKS)
|
||||
const char ana_direction[NUM_ANALOGS] = {1, 1, 0, 1 ,0 ,1 ,0, 0, 0};
|
||||
#endif
|
||||
|
||||
|
||||
// Settings for mode register ADC_MR
|
||||
// USEQ off - silicon problem, doesn't work
|
||||
// TRANSFER = 3
|
||||
// TRACKTIM = 15 (16 clock periods)
|
||||
// ANACH = 1
|
||||
// SETTLING = 6 (not used if ANACH = 0)
|
||||
// STARTUP = 6 (96 clock periods)
|
||||
// PRESCAL = 9.0 MHz clock (between 1 and 20MHz)
|
||||
// FREERUN = 0
|
||||
// FWUP = 0
|
||||
// SLEEP = 0
|
||||
// LOWRES = 0
|
||||
// TRGSEL = 0
|
||||
// TRGEN = 0 (software trigger only)
|
||||
void adcInit()
|
||||
{
|
||||
Adc *padc ;
|
||||
uint32_t timer ;
|
||||
|
||||
timer = ( Master_frequency / (3600000*2) ) << 8 ;
|
||||
// Enable peripheral clock ADC = bit 29
|
||||
PMC->PMC_PCER0 |= 0x20000000L ; // Enable peripheral clock to ADC
|
||||
padc = ADC ;
|
||||
padc->ADC_MR = 0x3FB60000 | timer ; // 0011 1111 1011 0110 xxxx xxxx 0000 0000
|
||||
padc->ADC_ACR = ADC_ACR_TSON ; // Turn on temp sensor
|
||||
#if defined(REVA)
|
||||
padc->ADC_CHER = 0x0000E23E ; // channels 1,2,3,4,5,9,13,14,15
|
||||
#else
|
||||
padc->ADC_CHER = 0x0000E33E ; // channels 1,2,3,4,5,8,9,13,14,15
|
||||
#endif
|
||||
padc->ADC_CGR = 0 ; // Gain = 1, all channels
|
||||
padc->ADC_COR = 0 ; // Single ended, 0 offset, all channels
|
||||
}
|
||||
|
||||
// Read 8 (9 for REVB) ADC channels
|
||||
// Documented bug, must do them 1 by 1
|
||||
void adcSingleRead()
|
||||
{
|
||||
Adc *padc;
|
||||
uint32_t y;
|
||||
uint32_t x;
|
||||
|
||||
for (uint8_t i=0; i<4; i++)
|
||||
padc = ADC;
|
||||
y = padc->ADC_ISR; // Clear EOC flags
|
||||
for (y = NUM_ANALOGS+1; --y > 0;) {
|
||||
padc->ADC_CR = 2; // Start conversion
|
||||
x = 0;
|
||||
while ((padc->ADC_ISR & 0x01000000) == 0) {
|
||||
// wait for DRDY flag
|
||||
if (++x > 1000000) {
|
||||
break; // Software timeout
|
||||
}
|
||||
}
|
||||
x = padc->ADC_LCDR; // Clear DRSY flag
|
||||
}
|
||||
// Next bit may be done using the PDC
|
||||
adcValues[0] = ADC->ADC_CDR1;
|
||||
adcValues[1] = ADC->ADC_CDR2;
|
||||
adcValues[2] = ADC->ADC_CDR3;
|
||||
adcValues[3] = ADC->ADC_CDR4;
|
||||
adcValues[4] = ADC->ADC_CDR5;
|
||||
adcValues[5] = ADC->ADC_CDR9;
|
||||
adcValues[6] = ADC->ADC_CDR13;
|
||||
adcValues[7] = ADC->ADC_CDR14;
|
||||
|
||||
#if !defined(REVA)
|
||||
adcValues[8] = ADC->ADC_CDR8 ;
|
||||
#endif
|
||||
|
||||
temperature = (((int32_t)temperature * 7) + ((((int32_t)ADC->ADC_CDR15 - 838) * 621) >> 11)) >> 3; // Filter it
|
||||
if (get_tmr10ms() >= 100 && temperature > maxTemperature) {
|
||||
maxTemperature = temperature;
|
||||
}
|
||||
|
||||
// adc direction correct
|
||||
#if defined(FRSKY_STICKS)
|
||||
uint32_t i ;
|
||||
for (i=0; i<NUM_ANALOGS; i++) {
|
||||
if (ana_direction[i]) {
|
||||
adcValues[i] = 4096-adcValues[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void adcRead()
|
||||
{
|
||||
uint16_t temp[NUM_ANALOGS] = { 0 };
|
||||
|
||||
for (int i=0; i<4; i++) {
|
||||
adcSingleRead();
|
||||
for (uint8_t x=0; x<NUM_ANALOGS; x++) {
|
||||
uint16_t val = adcValues[x];
|
||||
#if defined(JITTER_MEASURE)
|
||||
if (JITTER_MEASURE_ACTIVE()) {
|
||||
rawJitter[x].measure(val);
|
||||
}
|
||||
#endif
|
||||
temp[x] += val;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t x=0; x<NUM_ANALOGS; x++) {
|
||||
adcValues[x] = temp[x] >> 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if !defined(SIMU)
|
||||
uint16_t getAnalogValue(uint8_t index)
|
||||
{
|
||||
#if defined(PCBSKY9X) && !defined(REVA)
|
||||
static const uint8_t mapping[] = {1,5,7,0,4,6,2,3};
|
||||
index = mapping[index];
|
||||
#endif
|
||||
return adcValues[index];
|
||||
}
|
||||
#endif // #if !defined(SIMU)
|
||||
|
||||
@@ -1,195 +1,195 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
volatile uint8_t dacStarted = false;
|
||||
|
||||
#if !defined(SIMU)
|
||||
|
||||
#if !defined(SOFTWARE_VOLUME)
|
||||
const int8_t volumeScale[VOLUME_LEVEL_MAX+1] =
|
||||
{
|
||||
0, 2, 4, 6, 8, 10, 13, 17, 22, 27, 33, 40,
|
||||
64, 82, 96, 105, 112, 117, 120, 122, 124, 125, 126, 127
|
||||
} ;
|
||||
#endif
|
||||
|
||||
void setSampleRate(uint32_t frequency)
|
||||
{
|
||||
Tc *ptc ;
|
||||
uint32_t timer ;
|
||||
|
||||
timer = Master_frequency / (8 * frequency) ; // MCK/8 and 100 000 Hz
|
||||
if (timer > 65535)
|
||||
timer = 65535 ;
|
||||
if (timer < 2)
|
||||
timer = 2 ;
|
||||
|
||||
ptc = TC0 ; // Tc block 0 (TC0-2)
|
||||
ptc->TC_CHANNEL[1].TC_CCR = TC_CCR0_CLKDIS ; // Stop clock
|
||||
ptc->TC_CHANNEL[1].TC_RC = timer ; // 100 000 Hz
|
||||
ptc->TC_CHANNEL[1].TC_RA = timer >> 1 ;
|
||||
ptc->TC_CHANNEL[1].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger)
|
||||
}
|
||||
|
||||
// Start TIMER1 at 100000Hz, used for DACC trigger
|
||||
void dacTimerStart()
|
||||
{
|
||||
Tc *ptc ;
|
||||
uint32_t timer ;
|
||||
|
||||
// Enable peripheral clock TC0 = bit 23 thru TC5 = bit 28
|
||||
PMC->PMC_PCER0 |= 0x01000000L ; // Enable peripheral clock to TC1
|
||||
|
||||
timer = Master_frequency / 800000 ; // MCK/8 and 100 000 Hz
|
||||
ptc = TC0 ; // Tc block 0 (TC0-2)
|
||||
ptc->TC_BCR = 0 ; // No sync
|
||||
ptc->TC_BMR = 0 ;
|
||||
ptc->TC_CHANNEL[1].TC_CMR = 0x00008000 ; // Waveform mode
|
||||
ptc->TC_CHANNEL[1].TC_RC = timer ; // 100 000 Hz
|
||||
ptc->TC_CHANNEL[1].TC_RA = timer >> 1 ;
|
||||
ptc->TC_CHANNEL[1].TC_CMR = 0x0009C001 ; // 0000 0000 0000 1001 1100 0000 0000 0001
|
||||
// MCK/8, set @ RA, Clear @ RC waveform
|
||||
ptc->TC_CHANNEL[1].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger)
|
||||
// Sound_g.Frequency = 1000 ;
|
||||
}
|
||||
|
||||
// Configure DAC0 (or DAC1 for REVA)
|
||||
// Not sure why PB14 has not be allocated to the DAC, although it is an EXTRA function
|
||||
// So maybe it is automatically done
|
||||
void dacInit()
|
||||
{
|
||||
dacTimerStart() ;
|
||||
|
||||
PMC->PMC_PCER0 |= 0x40000000L ; // Enable peripheral clock to DAC
|
||||
|
||||
Dacc *dacptr = DACC;
|
||||
|
||||
#if defined(REVA)
|
||||
dacptr->DACC_MR = 0x0B010215L ; // 0000 1011 0000 0001 0000 0010 0001 0101
|
||||
dacptr->DACC_CHER = 2 ; // Enable channel 1
|
||||
#else
|
||||
dacptr->DACC_MR = 0x0B000215L ; // 0000 1011 0000 0001 0000 0010 0001 0101
|
||||
dacptr->DACC_CHER = 1 ; // Enable channel 0
|
||||
#endif
|
||||
|
||||
dacptr->DACC_CDR = 2048 ; // Half amplitude
|
||||
|
||||
dacptr->DACC_PTCR = DACC_PTCR_TXTEN ;
|
||||
NVIC_EnableIRQ(DACC_IRQn) ;
|
||||
}
|
||||
|
||||
inline void dacStart()
|
||||
{
|
||||
PMC->PMC_PCER0 |= 0x40000000L ; // Enable peripheral clock to DAC
|
||||
DACC->DACC_IER = DACC_IER_ENDTX ;
|
||||
dacStarted = true;
|
||||
}
|
||||
|
||||
inline void dacStop()
|
||||
{
|
||||
DACC->DACC_IDR = DACC_IDR_ENDTX ; // Disable interrupt
|
||||
dacStarted = false;
|
||||
}
|
||||
|
||||
void audioConsumeCurrentBuffer()
|
||||
{
|
||||
if (!dacStarted) {
|
||||
dacStart();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern "C" void DAC_IRQHandler()
|
||||
{
|
||||
uint32_t sr = DACC->DACC_ISR;
|
||||
if (sr & DACC_ISR_ENDTX) {
|
||||
audioQueue.buffersFifo.freeNextFilledBuffer();
|
||||
const AudioBuffer * nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer();
|
||||
if (nextBuffer) {
|
||||
// Try the first PDC buffer
|
||||
if ((DACC->DACC_TCR == 0) && (DACC->DACC_TNCR == 0)) {
|
||||
DACC->DACC_TPR = CONVERT_PTR_UINT(nextBuffer->data);
|
||||
DACC->DACC_TCR = nextBuffer->size/2;
|
||||
DACC->DACC_PTCR = DACC_PTCR_TXTEN;
|
||||
return;
|
||||
}
|
||||
// Try the second PDC buffer
|
||||
if (DACC->DACC_TNCR == 0) {
|
||||
DACC->DACC_TNPR = CONVERT_PTR_UINT(nextBuffer->data);
|
||||
DACC->DACC_TNCR = nextBuffer->size/2;
|
||||
DACC->DACC_PTCR = DACC_PTCR_TXTEN;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
dacStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sound routines
|
||||
void audioInit()
|
||||
{
|
||||
Pio * pioptr ;
|
||||
|
||||
dacInit() ;
|
||||
|
||||
pioptr = PIOA ;
|
||||
#if defined(REVA)
|
||||
pioptr->PIO_CODR = 0x00010000L ; // Set bit A16 OFF
|
||||
pioptr->PIO_PER = 0x00010000L ; // Enable bit A16 (Stock buzzer)
|
||||
pioptr->PIO_OER = 0x00010000L ; // Set bit A16 as output
|
||||
#else
|
||||
pioptr->PIO_CODR = 0x02000000L ; // Set bit A25 OFF
|
||||
pioptr->PIO_PER = 0x02000000L ; // Enable bit A25 (Stock buzzer)
|
||||
pioptr->PIO_OER = 0x02000000L ; // Set bit A25 as output
|
||||
#endif
|
||||
|
||||
#if defined(REVX)
|
||||
configure_pins( PIO_PC26, PIN_ENABLE | PIN_LOW | PIN_OUTPUT | PIN_PORTC | PIN_NO_PULLUP ) ;
|
||||
PIOC->PIO_CODR = PIO_PC26 ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void audioEnd()
|
||||
{
|
||||
DACC->DACC_IDR = DACC_IDR_ENDTX ;
|
||||
DACC->DACC_IDR = DACC_IDR_TXBUFE ;
|
||||
NVIC_DisableIRQ(DACC_IRQn) ;
|
||||
TWI0->TWI_IDR = TWI_IDR_TXCOMP ;
|
||||
NVIC_DisableIRQ(TWI0_IRQn) ;
|
||||
PMC->PMC_PCER0 &= ~0x00080000L ; // Disable peripheral clock to TWI0
|
||||
PMC->PMC_PCER0 &= ~0x40000000L ; // Disable peripheral clock to DAC
|
||||
}
|
||||
|
||||
#if !defined(SOFTWARE_VOLUME)
|
||||
void setScaledVolume(uint8_t volume)
|
||||
{
|
||||
volumeRequired = volumeScale[min<uint8_t>(volume, VOLUME_LEVEL_MAX)];
|
||||
__disable_irq() ;
|
||||
i2cCheck() ;
|
||||
__enable_irq() ;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // #if !defined(SIMU)
|
||||
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
volatile uint8_t dacStarted = false;
|
||||
|
||||
#if !defined(SIMU)
|
||||
|
||||
#if !defined(SOFTWARE_VOLUME)
|
||||
const int8_t volumeScale[VOLUME_LEVEL_MAX+1] =
|
||||
{
|
||||
0, 2, 4, 6, 8, 10, 13, 17, 22, 27, 33, 40,
|
||||
64, 82, 96, 105, 112, 117, 120, 122, 124, 125, 126, 127
|
||||
} ;
|
||||
#endif
|
||||
|
||||
void setSampleRate(uint32_t frequency)
|
||||
{
|
||||
Tc *ptc ;
|
||||
uint32_t timer ;
|
||||
|
||||
timer = Master_frequency / (8 * frequency) ; // MCK/8 and 100 000 Hz
|
||||
if (timer > 65535)
|
||||
timer = 65535 ;
|
||||
if (timer < 2)
|
||||
timer = 2 ;
|
||||
|
||||
ptc = TC0 ; // Tc block 0 (TC0-2)
|
||||
ptc->TC_CHANNEL[1].TC_CCR = TC_CCR0_CLKDIS ; // Stop clock
|
||||
ptc->TC_CHANNEL[1].TC_RC = timer ; // 100 000 Hz
|
||||
ptc->TC_CHANNEL[1].TC_RA = timer >> 1 ;
|
||||
ptc->TC_CHANNEL[1].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger)
|
||||
}
|
||||
|
||||
// Start TIMER1 at 100000Hz, used for DACC trigger
|
||||
void dacTimerStart()
|
||||
{
|
||||
Tc *ptc ;
|
||||
uint32_t timer ;
|
||||
|
||||
// Enable peripheral clock TC0 = bit 23 thru TC5 = bit 28
|
||||
PMC->PMC_PCER0 |= 0x01000000L ; // Enable peripheral clock to TC1
|
||||
|
||||
timer = Master_frequency / 800000 ; // MCK/8 and 100 000 Hz
|
||||
ptc = TC0 ; // Tc block 0 (TC0-2)
|
||||
ptc->TC_BCR = 0 ; // No sync
|
||||
ptc->TC_BMR = 0 ;
|
||||
ptc->TC_CHANNEL[1].TC_CMR = 0x00008000 ; // Waveform mode
|
||||
ptc->TC_CHANNEL[1].TC_RC = timer ; // 100 000 Hz
|
||||
ptc->TC_CHANNEL[1].TC_RA = timer >> 1 ;
|
||||
ptc->TC_CHANNEL[1].TC_CMR = 0x0009C001 ; // 0000 0000 0000 1001 1100 0000 0000 0001
|
||||
// MCK/8, set @ RA, Clear @ RC waveform
|
||||
ptc->TC_CHANNEL[1].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger)
|
||||
// Sound_g.Frequency = 1000 ;
|
||||
}
|
||||
|
||||
// Configure DAC0 (or DAC1 for REVA)
|
||||
// Not sure why PB14 has not be allocated to the DAC, although it is an EXTRA function
|
||||
// So maybe it is automatically done
|
||||
void dacInit()
|
||||
{
|
||||
dacTimerStart() ;
|
||||
|
||||
PMC->PMC_PCER0 |= 0x40000000L ; // Enable peripheral clock to DAC
|
||||
|
||||
Dacc *dacptr = DACC;
|
||||
|
||||
#if defined(REVA)
|
||||
dacptr->DACC_MR = 0x0B010215L ; // 0000 1011 0000 0001 0000 0010 0001 0101
|
||||
dacptr->DACC_CHER = 2 ; // Enable channel 1
|
||||
#else
|
||||
dacptr->DACC_MR = 0x0B000215L ; // 0000 1011 0000 0001 0000 0010 0001 0101
|
||||
dacptr->DACC_CHER = 1 ; // Enable channel 0
|
||||
#endif
|
||||
|
||||
dacptr->DACC_CDR = 2048 ; // Half amplitude
|
||||
|
||||
dacptr->DACC_PTCR = DACC_PTCR_TXTEN ;
|
||||
NVIC_EnableIRQ(DACC_IRQn) ;
|
||||
}
|
||||
|
||||
inline void dacStart()
|
||||
{
|
||||
PMC->PMC_PCER0 |= 0x40000000L ; // Enable peripheral clock to DAC
|
||||
DACC->DACC_IER = DACC_IER_ENDTX ;
|
||||
dacStarted = true;
|
||||
}
|
||||
|
||||
inline void dacStop()
|
||||
{
|
||||
DACC->DACC_IDR = DACC_IDR_ENDTX ; // Disable interrupt
|
||||
dacStarted = false;
|
||||
}
|
||||
|
||||
void audioConsumeCurrentBuffer()
|
||||
{
|
||||
if (!dacStarted) {
|
||||
dacStart();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern "C" void DAC_IRQHandler()
|
||||
{
|
||||
uint32_t sr = DACC->DACC_ISR;
|
||||
if (sr & DACC_ISR_ENDTX) {
|
||||
audioQueue.buffersFifo.freeNextFilledBuffer();
|
||||
const AudioBuffer * nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer();
|
||||
if (nextBuffer) {
|
||||
// Try the first PDC buffer
|
||||
if ((DACC->DACC_TCR == 0) && (DACC->DACC_TNCR == 0)) {
|
||||
DACC->DACC_TPR = CONVERT_PTR_UINT(nextBuffer->data);
|
||||
DACC->DACC_TCR = nextBuffer->size/2;
|
||||
DACC->DACC_PTCR = DACC_PTCR_TXTEN;
|
||||
return;
|
||||
}
|
||||
// Try the second PDC buffer
|
||||
if (DACC->DACC_TNCR == 0) {
|
||||
DACC->DACC_TNPR = CONVERT_PTR_UINT(nextBuffer->data);
|
||||
DACC->DACC_TNCR = nextBuffer->size/2;
|
||||
DACC->DACC_PTCR = DACC_PTCR_TXTEN;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
dacStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sound routines
|
||||
void audioInit()
|
||||
{
|
||||
Pio * pioptr ;
|
||||
|
||||
dacInit() ;
|
||||
|
||||
pioptr = PIOA ;
|
||||
#if defined(REVA)
|
||||
pioptr->PIO_CODR = 0x00010000L ; // Set bit A16 OFF
|
||||
pioptr->PIO_PER = 0x00010000L ; // Enable bit A16 (Stock buzzer)
|
||||
pioptr->PIO_OER = 0x00010000L ; // Set bit A16 as output
|
||||
#else
|
||||
pioptr->PIO_CODR = 0x02000000L ; // Set bit A25 OFF
|
||||
pioptr->PIO_PER = 0x02000000L ; // Enable bit A25 (Stock buzzer)
|
||||
pioptr->PIO_OER = 0x02000000L ; // Set bit A25 as output
|
||||
#endif
|
||||
|
||||
#if defined(REVX)
|
||||
configure_pins( PIO_PC26, PIN_ENABLE | PIN_LOW | PIN_OUTPUT | PIN_PORTC | PIN_NO_PULLUP ) ;
|
||||
PIOC->PIO_CODR = PIO_PC26 ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void audioEnd()
|
||||
{
|
||||
DACC->DACC_IDR = DACC_IDR_ENDTX ;
|
||||
DACC->DACC_IDR = DACC_IDR_TXBUFE ;
|
||||
NVIC_DisableIRQ(DACC_IRQn) ;
|
||||
TWI0->TWI_IDR = TWI_IDR_TXCOMP ;
|
||||
NVIC_DisableIRQ(TWI0_IRQn) ;
|
||||
PMC->PMC_PCER0 &= ~0x00080000L ; // Disable peripheral clock to TWI0
|
||||
PMC->PMC_PCER0 &= ~0x40000000L ; // Disable peripheral clock to DAC
|
||||
}
|
||||
|
||||
#if !defined(SOFTWARE_VOLUME)
|
||||
void setScaledVolume(uint8_t volume)
|
||||
{
|
||||
volumeRequired = volumeScale[min<uint8_t>(volume, VOLUME_LEVEL_MAX)];
|
||||
__disable_irq() ;
|
||||
i2cCheck() ;
|
||||
__enable_irq() ;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // #if !defined(SIMU)
|
||||
|
||||
|
||||
+609
-609
File diff suppressed because it is too large
Load Diff
+414
-414
@@ -1,414 +1,414 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _BOARD_SKY9X_H_
|
||||
#define _BOARD_SKY9X_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include "board_lowlevel.h"
|
||||
#include "audio_driver.h"
|
||||
|
||||
extern uint16_t ResetReason;
|
||||
|
||||
#define BOOTLOADER_SIZE 0x8000
|
||||
#define FIRMWARE_SIZE (256*1024)
|
||||
#define FIRMWARE_ADDRESS 0x00400000
|
||||
|
||||
// Board driver
|
||||
void boardInit(void);
|
||||
#define boardOff() pwrOff()
|
||||
|
||||
// Rotary Encoder driver
|
||||
void rotencInit();
|
||||
void rotencEnd();
|
||||
|
||||
#if !defined(REVX) && !defined(AR9X)
|
||||
#define ROTARY_ENCODERS 1
|
||||
#define ROTARY_ENCODER_NAVIGATION
|
||||
#define REA_DOWN() (!(PIOB->PIO_PDSR & 0x40))
|
||||
#else
|
||||
#define REA_DOWN() (0)
|
||||
#endif
|
||||
|
||||
// Keys driver
|
||||
#define NUM_SWITCHES 7
|
||||
enum EnumKeys
|
||||
{
|
||||
KEY_MENU,
|
||||
KEY_ENTER=KEY_MENU,
|
||||
KEY_EXIT,
|
||||
KEY_DOWN,
|
||||
KEY_MINUS = KEY_DOWN,
|
||||
KEY_UP,
|
||||
KEY_PLUS = KEY_UP,
|
||||
KEY_RIGHT,
|
||||
KEY_LEFT,
|
||||
|
||||
TRM_BASE,
|
||||
TRM_LH_DWN = TRM_BASE,
|
||||
TRM_LH_UP,
|
||||
TRM_LV_DWN,
|
||||
TRM_LV_UP,
|
||||
TRM_RV_DWN,
|
||||
TRM_RV_UP,
|
||||
TRM_RH_DWN,
|
||||
TRM_RH_UP,
|
||||
TRM_LAST = TRM_RH_UP,
|
||||
|
||||
#if defined(ROTARY_ENCODERS)
|
||||
BTN_REa,
|
||||
#endif
|
||||
|
||||
NUM_KEYS
|
||||
};
|
||||
|
||||
enum EnumSwitches
|
||||
{
|
||||
SW_ID0,
|
||||
SW_ID1,
|
||||
SW_ID2,
|
||||
SW_THR,
|
||||
SW_RUD,
|
||||
SW_ELE,
|
||||
SW_AIL,
|
||||
SW_GEA,
|
||||
SW_TRN,
|
||||
};
|
||||
#define IS_3POS(sw) ((sw) == 0)
|
||||
#define IS_TOGGLE(sw) ((sw) == SWSRC_TRN)
|
||||
|
||||
#if defined(REVA)
|
||||
#define KEYS_GPIO_REG_MENU PIOB->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_EXIT PIOA->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_UP PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_DOWN PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_RIGHT PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_LEFT PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_PIN_MENU 0x00000040
|
||||
#define KEYS_GPIO_PIN_EXIT 0x80000000
|
||||
#define KEYS_GPIO_PIN_UP 0x00000004
|
||||
#define KEYS_GPIO_PIN_DOWN 0x00000008
|
||||
#define KEYS_GPIO_PIN_RIGHT 0x00000010
|
||||
#define KEYS_GPIO_PIN_LEFT 0x00000020
|
||||
#else
|
||||
#define KEYS_GPIO_REG_MENU PIOB->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_EXIT PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_UP PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_DOWN PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_RIGHT PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_LEFT PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_PIN_MENU 0x00000020
|
||||
#define KEYS_GPIO_PIN_EXIT 0x01000000
|
||||
#define KEYS_GPIO_PIN_UP 0x00000002
|
||||
#define KEYS_GPIO_PIN_DOWN 0x00000020
|
||||
#define KEYS_GPIO_PIN_RIGHT 0x00000010
|
||||
#define KEYS_GPIO_PIN_LEFT 0x00000008
|
||||
#endif
|
||||
|
||||
#if defined(REVX)
|
||||
#define TRIMS_GPIO_REG_LHL PIOB->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LVD PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RVU PIOC->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RHL PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LHR PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LVU PIOC->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RVD PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RHR PIOC->PIO_PDSR
|
||||
#else
|
||||
#define TRIMS_GPIO_REG_LHL PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LVD PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RVU PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RHL PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LHR PIOB->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LVU PIOC->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RVD PIOC->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RHR PIOC->PIO_PDSR
|
||||
#endif
|
||||
|
||||
#if defined(REVX)
|
||||
#define TRIMS_GPIO_PIN_LHL 0x00000010
|
||||
#define TRIMS_GPIO_PIN_LVD 0x01000000
|
||||
#define TRIMS_GPIO_PIN_RVU 0x00000400
|
||||
#define TRIMS_GPIO_PIN_RHL 0x00000001
|
||||
#define TRIMS_GPIO_PIN_LHR 0x00800000
|
||||
#define TRIMS_GPIO_PIN_LVU 0x10000000
|
||||
#define TRIMS_GPIO_PIN_RVD 0x00000002
|
||||
#define TRIMS_GPIO_PIN_RHR 0x00000200
|
||||
#elif defined(REVA)
|
||||
#define TRIMS_GPIO_PIN_LHL 0x00000080
|
||||
#define TRIMS_GPIO_PIN_LVD 0x08000000
|
||||
#define TRIMS_GPIO_PIN_RVU 0x40000000
|
||||
#define TRIMS_GPIO_PIN_RHL 0x20000000
|
||||
#define TRIMS_GPIO_PIN_LHR 0x00000010
|
||||
#define TRIMS_GPIO_PIN_LVU 0x10000000
|
||||
#define TRIMS_GPIO_PIN_RVD 0x00000400
|
||||
#define TRIMS_GPIO_PIN_RHR 0x00000200
|
||||
#else
|
||||
#define TRIMS_GPIO_PIN_LHL 0x00800000
|
||||
#define TRIMS_GPIO_PIN_LVD 0x01000000
|
||||
#define TRIMS_GPIO_PIN_RVU 0x00000002
|
||||
#define TRIMS_GPIO_PIN_RHL 0x00000001
|
||||
#define TRIMS_GPIO_PIN_LHR 0x00000010
|
||||
#define TRIMS_GPIO_PIN_LVU 0x10000000
|
||||
#define TRIMS_GPIO_PIN_RVD 0x00000400
|
||||
#define TRIMS_GPIO_PIN_RHR 0x00000200
|
||||
#endif
|
||||
|
||||
// LCD driver
|
||||
#define LCD_W 128
|
||||
#define LCD_H 64
|
||||
#define LCD_DEPTH 1
|
||||
#define LCD_CONTRAST_MIN 10
|
||||
#define LCD_CONTRAST_MAX 45
|
||||
#define LCD_CONTRAST_DEFAULT 25
|
||||
void lcdInit(void);
|
||||
void lcdRefresh(void);
|
||||
#define lcdRefreshWait()
|
||||
void lcdSetRefVolt(uint8_t val);
|
||||
void lcdSetContrast(void);
|
||||
|
||||
// USB driver
|
||||
void usbMassStorage();
|
||||
|
||||
#define PIN_ENABLE 0x001
|
||||
#define PIN_PERIPHERAL 0x000
|
||||
#define PIN_INPUT 0x002
|
||||
#define PIN_OUTPUT 0x000
|
||||
#define PIN_PULLUP 0x004
|
||||
#define PIN_NO_PULLUP 0x000
|
||||
#define PIN_PULLDOWN 0x008
|
||||
#define PIN_NO_PULLDOWN 0x000
|
||||
#define PIN_PERI_MASK_L 0x010
|
||||
#define PIN_PERI_MASK_H 0x020
|
||||
#define PIN_PER_A 0x000
|
||||
#define PIN_PER_B 0x010
|
||||
#define PIN_PER_C 0x020
|
||||
#define PIN_PER_D 0x030
|
||||
#define PIN_PORT_MASK 0x0C0
|
||||
#define PIN_PORTA 0x000
|
||||
#define PIN_PORTB 0x040
|
||||
#define PIN_PORTC 0x080
|
||||
#define PIN_LOW 0x000
|
||||
#define PIN_HIGH 0x100
|
||||
|
||||
// Telemetry port
|
||||
#define SECOND_USART USART0
|
||||
#define SECOND_ID ID_USART0
|
||||
#define SECOND_PINS { PINS_USART0 }
|
||||
|
||||
void configure_pins( uint32_t pins, uint16_t config );
|
||||
uint16_t getCurrent();
|
||||
|
||||
extern uint8_t temperature ; // Raw temp reading
|
||||
extern uint8_t maxTemperature ; // Raw temp reading
|
||||
uint8_t getTemperature();
|
||||
|
||||
#define strcpy_P strcpy
|
||||
#define strcat_P strcat
|
||||
|
||||
#if !defined(REVA)
|
||||
extern uint16_t Current_analogue;
|
||||
extern uint16_t Current_max;
|
||||
extern uint32_t Current_accumulator;
|
||||
extern uint32_t Current_used;
|
||||
extern uint16_t sessionTimer;
|
||||
void calcConsumption();
|
||||
#endif
|
||||
|
||||
// Trainer driver
|
||||
#define SLAVE_MODE() (pwrCheck() == e_power_trainer)
|
||||
#define TRAINER_CONNECTED() (PIOA->PIO_PDSR & PIO_PA8)
|
||||
void checkTrainerSettings();
|
||||
void init_trainer_capture();
|
||||
|
||||
// Write Flash driver
|
||||
#define FLASH_PAGESIZE 256
|
||||
void flashWrite(uint32_t * address, uint32_t * buffer);
|
||||
|
||||
// Keys driver
|
||||
uint8_t keyState(uint8_t index);
|
||||
uint32_t switchState(uint8_t index);
|
||||
uint32_t readKeys(void);
|
||||
uint32_t readTrims(void);
|
||||
#define TRIMS_PRESSED() readTrims()
|
||||
#define KEYS_PRESSED() readKeys()
|
||||
|
||||
// Pulses driver
|
||||
void init_no_pulses(uint32_t port);
|
||||
void disable_no_pulses(uint32_t port);
|
||||
void init_ppm(uint32_t port);
|
||||
void disable_ppm(uint32_t port);
|
||||
void init_pxx(uint32_t port);
|
||||
void disable_pxx(uint32_t port);
|
||||
void init_dsm2(uint32_t port);
|
||||
void disable_dsm2(uint32_t port);
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
void init_multimodule(uint32_t module_index);
|
||||
void disable_multimodule(uint32_t module_index);
|
||||
#endif
|
||||
|
||||
// SD driver
|
||||
#if defined(SIMU)
|
||||
#define sdInit()
|
||||
#define sdDone()
|
||||
#else
|
||||
#define sdPoll10ms()
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
void init_SDcard();
|
||||
void sdInit();
|
||||
void sdDone();
|
||||
uint32_t sd_card_ready();
|
||||
uint32_t sdMounted();
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// WDT driver
|
||||
#if defined(WATCHDOG_DISABLED) || defined(SIMU)
|
||||
#define wdt_disable()
|
||||
#define wdt_enable(x)
|
||||
#define wdt_reset()
|
||||
#else
|
||||
#define wdt_disable()
|
||||
#define wdt_enable(x) WDT->WDT_MR = 0x3FFF207F
|
||||
#define wdt_reset() WDT->WDT_CR = 0xA5000001
|
||||
#endif
|
||||
|
||||
// Backlight driver
|
||||
#define backlightEnable() (PWM->PWM_CH_NUM[0].PWM_CDTY = g_eeGeneral.backlightBright)
|
||||
#define backlightDisable() (PWM->PWM_CH_NUM[0].PWM_CDTY = 100)
|
||||
#define isBacklightEnabled() (PWM->PWM_CH_NUM[0].PWM_CDTY != 100)
|
||||
#define BACKLIGHT_ENABLE() backlightEnable()
|
||||
#define BACKLIGHT_DISABLE() backlightDisable()
|
||||
|
||||
// ADC driver
|
||||
#define NUM_POTS 3
|
||||
#define NUM_SLIDERS 0
|
||||
#define NUM_XPOTS 0
|
||||
enum Analogs {
|
||||
STICK1,
|
||||
STICK2,
|
||||
STICK3,
|
||||
STICK4,
|
||||
POT_FIRST,
|
||||
POT1 = POT_FIRST,
|
||||
POT2,
|
||||
POT3,
|
||||
POT_LAST = POT3,
|
||||
TX_VOLTAGE,
|
||||
#if !defined(REVA)
|
||||
TX_CURRENT,
|
||||
#endif
|
||||
NUM_ANALOGS
|
||||
};
|
||||
enum CalibratedAnalogs {
|
||||
CALIBRATED_STICK1,
|
||||
CALIBRATED_STICK2,
|
||||
CALIBRATED_STICK3,
|
||||
CALIBRATED_STICK4,
|
||||
CALIBRATED_POT_FIRST,
|
||||
CALIBRATED_POT1 = CALIBRATED_POT_FIRST,
|
||||
CALIBRATED_POT2,
|
||||
CALIBRATED_POT3,
|
||||
CALIBRATED_POT_LAST = CALIBRATED_POT3,
|
||||
NUM_CALIBRATED_ANALOGS
|
||||
};
|
||||
#define IS_POT(x) ((x)>=POT_FIRST && (x)<=POT_LAST)
|
||||
#define IS_SLIDER(x) false
|
||||
void adcInit();
|
||||
void adcRead(void);
|
||||
uint16_t getAnalogValue(uint8_t index);
|
||||
uint16_t getBatteryVoltage(); // returns current battery voltage in 10mV steps
|
||||
void setSticksGain(uint8_t gains);
|
||||
|
||||
// Buzzer driver
|
||||
void buzzerSound(uint8_t duration);
|
||||
void buzzerHeartbeat();
|
||||
#define BUZZER_HEARTBEAT buzzerHeartbeat
|
||||
|
||||
// i2c driver
|
||||
void i2cCheck();
|
||||
|
||||
// Coproc driver
|
||||
void coprocInit();
|
||||
void coprocWriteData(uint8_t *data, uint32_t size);
|
||||
#if defined(__cplusplus)
|
||||
void coprocReadData(bool onlytemp=false);
|
||||
#endif
|
||||
extern int8_t volumeRequired;
|
||||
extern uint8_t Coproc_read;
|
||||
extern int8_t Coproc_valid;
|
||||
extern int8_t Coproc_temp;
|
||||
extern int8_t Coproc_maxtemp;
|
||||
|
||||
// Haptic driver
|
||||
void hapticOff(void);
|
||||
void hapticOn(uint32_t pwmPercent);
|
||||
|
||||
// BlueTooth driver
|
||||
#if defined(BLUETOOTH)
|
||||
void btInit();
|
||||
void btTask(void* pdata);
|
||||
void btPushByte(uint8_t data);
|
||||
#endif
|
||||
|
||||
// Power driver
|
||||
#define TRAINER_PWR
|
||||
#if !defined(REVA)
|
||||
#define SOFT_PWR_CTRL
|
||||
#endif
|
||||
void pwrInit();
|
||||
void pwrOff();
|
||||
uint32_t pwrCheck();
|
||||
uint32_t pwrPressed();
|
||||
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
|
||||
|
||||
// EEPROM driver
|
||||
#define EEPROM_SIZE (4*1024*1024/8)
|
||||
#define EEPROM_BLOCK_SIZE (4*1024)
|
||||
void eepromInit();
|
||||
uint8_t eepromReadStatus();
|
||||
uint8_t eepromIsTransferComplete(void);
|
||||
void eepromBlockErase(uint32_t address);
|
||||
void eepromStartRead(uint8_t * buffer, size_t address, size_t size);
|
||||
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size);
|
||||
|
||||
// Debug driver
|
||||
void debugPutc(const char c);
|
||||
|
||||
// Telemetry driver
|
||||
void telemetryPortInit(uint32_t baudrate, uint8_t mode);
|
||||
uint32_t telemetryTransmitPending();
|
||||
void telemetryTransmitBuffer(uint8_t * buffer, uint32_t size);
|
||||
void rxPdcUsart( void (*pChProcess)(uint8_t x) );
|
||||
|
||||
// Second UART driver
|
||||
void serial2TelemetryInit(unsigned int protocol);
|
||||
#if defined(__cplusplus)
|
||||
bool telemetrySecondPortReceive(uint8_t & data);
|
||||
#endif
|
||||
|
||||
extern const uint8_t BootCode[];
|
||||
|
||||
#endif // _BOARD_SKY9X_H_
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _BOARD_SKY9X_H_
|
||||
#define _BOARD_SKY9X_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include "board_lowlevel.h"
|
||||
#include "audio_driver.h"
|
||||
|
||||
extern uint16_t ResetReason;
|
||||
|
||||
#define BOOTLOADER_SIZE 0x8000
|
||||
#define FIRMWARE_SIZE (256*1024)
|
||||
#define FIRMWARE_ADDRESS 0x00400000
|
||||
|
||||
// Board driver
|
||||
void boardInit(void);
|
||||
#define boardOff() pwrOff()
|
||||
|
||||
// Rotary Encoder driver
|
||||
void rotencInit();
|
||||
void rotencEnd();
|
||||
|
||||
#if !defined(REVX) && !defined(AR9X)
|
||||
#define ROTARY_ENCODERS 1
|
||||
#define ROTARY_ENCODER_NAVIGATION
|
||||
#define REA_DOWN() (!(PIOB->PIO_PDSR & 0x40))
|
||||
#else
|
||||
#define REA_DOWN() (0)
|
||||
#endif
|
||||
|
||||
// Keys driver
|
||||
#define NUM_SWITCHES 7
|
||||
enum EnumKeys
|
||||
{
|
||||
KEY_MENU,
|
||||
KEY_ENTER=KEY_MENU,
|
||||
KEY_EXIT,
|
||||
KEY_DOWN,
|
||||
KEY_MINUS = KEY_DOWN,
|
||||
KEY_UP,
|
||||
KEY_PLUS = KEY_UP,
|
||||
KEY_RIGHT,
|
||||
KEY_LEFT,
|
||||
|
||||
TRM_BASE,
|
||||
TRM_LH_DWN = TRM_BASE,
|
||||
TRM_LH_UP,
|
||||
TRM_LV_DWN,
|
||||
TRM_LV_UP,
|
||||
TRM_RV_DWN,
|
||||
TRM_RV_UP,
|
||||
TRM_RH_DWN,
|
||||
TRM_RH_UP,
|
||||
TRM_LAST = TRM_RH_UP,
|
||||
|
||||
#if defined(ROTARY_ENCODERS)
|
||||
BTN_REa,
|
||||
#endif
|
||||
|
||||
NUM_KEYS
|
||||
};
|
||||
|
||||
enum EnumSwitches
|
||||
{
|
||||
SW_ID0,
|
||||
SW_ID1,
|
||||
SW_ID2,
|
||||
SW_THR,
|
||||
SW_RUD,
|
||||
SW_ELE,
|
||||
SW_AIL,
|
||||
SW_GEA,
|
||||
SW_TRN,
|
||||
};
|
||||
#define IS_3POS(sw) ((sw) == 0)
|
||||
#define IS_TOGGLE(sw) ((sw) == SWSRC_TRN)
|
||||
|
||||
#if defined(REVA)
|
||||
#define KEYS_GPIO_REG_MENU PIOB->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_EXIT PIOA->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_UP PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_DOWN PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_RIGHT PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_LEFT PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_PIN_MENU 0x00000040
|
||||
#define KEYS_GPIO_PIN_EXIT 0x80000000
|
||||
#define KEYS_GPIO_PIN_UP 0x00000004
|
||||
#define KEYS_GPIO_PIN_DOWN 0x00000008
|
||||
#define KEYS_GPIO_PIN_RIGHT 0x00000010
|
||||
#define KEYS_GPIO_PIN_LEFT 0x00000020
|
||||
#else
|
||||
#define KEYS_GPIO_REG_MENU PIOB->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_EXIT PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_UP PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_DOWN PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_RIGHT PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_LEFT PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_PIN_MENU 0x00000020
|
||||
#define KEYS_GPIO_PIN_EXIT 0x01000000
|
||||
#define KEYS_GPIO_PIN_UP 0x00000002
|
||||
#define KEYS_GPIO_PIN_DOWN 0x00000020
|
||||
#define KEYS_GPIO_PIN_RIGHT 0x00000010
|
||||
#define KEYS_GPIO_PIN_LEFT 0x00000008
|
||||
#endif
|
||||
|
||||
#if defined(REVX)
|
||||
#define TRIMS_GPIO_REG_LHL PIOB->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LVD PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RVU PIOC->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RHL PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LHR PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LVU PIOC->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RVD PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RHR PIOC->PIO_PDSR
|
||||
#else
|
||||
#define TRIMS_GPIO_REG_LHL PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LVD PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RVU PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RHL PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LHR PIOB->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LVU PIOC->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RVD PIOC->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RHR PIOC->PIO_PDSR
|
||||
#endif
|
||||
|
||||
#if defined(REVX)
|
||||
#define TRIMS_GPIO_PIN_LHL 0x00000010
|
||||
#define TRIMS_GPIO_PIN_LVD 0x01000000
|
||||
#define TRIMS_GPIO_PIN_RVU 0x00000400
|
||||
#define TRIMS_GPIO_PIN_RHL 0x00000001
|
||||
#define TRIMS_GPIO_PIN_LHR 0x00800000
|
||||
#define TRIMS_GPIO_PIN_LVU 0x10000000
|
||||
#define TRIMS_GPIO_PIN_RVD 0x00000002
|
||||
#define TRIMS_GPIO_PIN_RHR 0x00000200
|
||||
#elif defined(REVA)
|
||||
#define TRIMS_GPIO_PIN_LHL 0x00000080
|
||||
#define TRIMS_GPIO_PIN_LVD 0x08000000
|
||||
#define TRIMS_GPIO_PIN_RVU 0x40000000
|
||||
#define TRIMS_GPIO_PIN_RHL 0x20000000
|
||||
#define TRIMS_GPIO_PIN_LHR 0x00000010
|
||||
#define TRIMS_GPIO_PIN_LVU 0x10000000
|
||||
#define TRIMS_GPIO_PIN_RVD 0x00000400
|
||||
#define TRIMS_GPIO_PIN_RHR 0x00000200
|
||||
#else
|
||||
#define TRIMS_GPIO_PIN_LHL 0x00800000
|
||||
#define TRIMS_GPIO_PIN_LVD 0x01000000
|
||||
#define TRIMS_GPIO_PIN_RVU 0x00000002
|
||||
#define TRIMS_GPIO_PIN_RHL 0x00000001
|
||||
#define TRIMS_GPIO_PIN_LHR 0x00000010
|
||||
#define TRIMS_GPIO_PIN_LVU 0x10000000
|
||||
#define TRIMS_GPIO_PIN_RVD 0x00000400
|
||||
#define TRIMS_GPIO_PIN_RHR 0x00000200
|
||||
#endif
|
||||
|
||||
// LCD driver
|
||||
#define LCD_W 128
|
||||
#define LCD_H 64
|
||||
#define LCD_DEPTH 1
|
||||
#define LCD_CONTRAST_MIN 10
|
||||
#define LCD_CONTRAST_MAX 45
|
||||
#define LCD_CONTRAST_DEFAULT 25
|
||||
void lcdInit(void);
|
||||
void lcdRefresh(void);
|
||||
#define lcdRefreshWait()
|
||||
void lcdSetRefVolt(uint8_t val);
|
||||
void lcdSetContrast(void);
|
||||
|
||||
// USB driver
|
||||
void usbMassStorage();
|
||||
|
||||
#define PIN_ENABLE 0x001
|
||||
#define PIN_PERIPHERAL 0x000
|
||||
#define PIN_INPUT 0x002
|
||||
#define PIN_OUTPUT 0x000
|
||||
#define PIN_PULLUP 0x004
|
||||
#define PIN_NO_PULLUP 0x000
|
||||
#define PIN_PULLDOWN 0x008
|
||||
#define PIN_NO_PULLDOWN 0x000
|
||||
#define PIN_PERI_MASK_L 0x010
|
||||
#define PIN_PERI_MASK_H 0x020
|
||||
#define PIN_PER_A 0x000
|
||||
#define PIN_PER_B 0x010
|
||||
#define PIN_PER_C 0x020
|
||||
#define PIN_PER_D 0x030
|
||||
#define PIN_PORT_MASK 0x0C0
|
||||
#define PIN_PORTA 0x000
|
||||
#define PIN_PORTB 0x040
|
||||
#define PIN_PORTC 0x080
|
||||
#define PIN_LOW 0x000
|
||||
#define PIN_HIGH 0x100
|
||||
|
||||
// Telemetry port
|
||||
#define SECOND_USART USART0
|
||||
#define SECOND_ID ID_USART0
|
||||
#define SECOND_PINS { PINS_USART0 }
|
||||
|
||||
void configure_pins( uint32_t pins, uint16_t config );
|
||||
uint16_t getCurrent();
|
||||
|
||||
extern uint8_t temperature ; // Raw temp reading
|
||||
extern uint8_t maxTemperature ; // Raw temp reading
|
||||
uint8_t getTemperature();
|
||||
|
||||
#define strcpy_P strcpy
|
||||
#define strcat_P strcat
|
||||
|
||||
#if !defined(REVA)
|
||||
extern uint16_t Current_analogue;
|
||||
extern uint16_t Current_max;
|
||||
extern uint32_t Current_accumulator;
|
||||
extern uint32_t Current_used;
|
||||
extern uint16_t sessionTimer;
|
||||
void calcConsumption();
|
||||
#endif
|
||||
|
||||
// Trainer driver
|
||||
#define SLAVE_MODE() (pwrCheck() == e_power_trainer)
|
||||
#define TRAINER_CONNECTED() (PIOA->PIO_PDSR & PIO_PA8)
|
||||
void checkTrainerSettings();
|
||||
void init_trainer_capture();
|
||||
|
||||
// Write Flash driver
|
||||
#define FLASH_PAGESIZE 256
|
||||
void flashWrite(uint32_t * address, uint32_t * buffer);
|
||||
|
||||
// Keys driver
|
||||
uint8_t keyState(uint8_t index);
|
||||
uint32_t switchState(uint8_t index);
|
||||
uint32_t readKeys(void);
|
||||
uint32_t readTrims(void);
|
||||
#define TRIMS_PRESSED() readTrims()
|
||||
#define KEYS_PRESSED() readKeys()
|
||||
|
||||
// Pulses driver
|
||||
void init_no_pulses(uint32_t port);
|
||||
void disable_no_pulses(uint32_t port);
|
||||
void init_ppm(uint32_t port);
|
||||
void disable_ppm(uint32_t port);
|
||||
void init_pxx(uint32_t port);
|
||||
void disable_pxx(uint32_t port);
|
||||
void init_dsm2(uint32_t port);
|
||||
void disable_dsm2(uint32_t port);
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
void init_multimodule(uint32_t module_index);
|
||||
void disable_multimodule(uint32_t module_index);
|
||||
#endif
|
||||
|
||||
// SD driver
|
||||
#if defined(SIMU)
|
||||
#define sdInit()
|
||||
#define sdDone()
|
||||
#else
|
||||
#define sdPoll10ms()
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
void init_SDcard();
|
||||
void sdInit();
|
||||
void sdDone();
|
||||
uint32_t sd_card_ready();
|
||||
uint32_t sdMounted();
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// WDT driver
|
||||
#if defined(WATCHDOG_DISABLED) || defined(SIMU)
|
||||
#define wdt_disable()
|
||||
#define wdt_enable(x)
|
||||
#define wdt_reset()
|
||||
#else
|
||||
#define wdt_disable()
|
||||
#define wdt_enable(x) WDT->WDT_MR = 0x3FFF207F
|
||||
#define wdt_reset() WDT->WDT_CR = 0xA5000001
|
||||
#endif
|
||||
|
||||
// Backlight driver
|
||||
#define backlightEnable() (PWM->PWM_CH_NUM[0].PWM_CDTY = g_eeGeneral.backlightBright)
|
||||
#define backlightDisable() (PWM->PWM_CH_NUM[0].PWM_CDTY = 100)
|
||||
#define isBacklightEnabled() (PWM->PWM_CH_NUM[0].PWM_CDTY != 100)
|
||||
#define BACKLIGHT_ENABLE() backlightEnable()
|
||||
#define BACKLIGHT_DISABLE() backlightDisable()
|
||||
|
||||
// ADC driver
|
||||
#define NUM_POTS 3
|
||||
#define NUM_SLIDERS 0
|
||||
#define NUM_XPOTS 0
|
||||
enum Analogs {
|
||||
STICK1,
|
||||
STICK2,
|
||||
STICK3,
|
||||
STICK4,
|
||||
POT_FIRST,
|
||||
POT1 = POT_FIRST,
|
||||
POT2,
|
||||
POT3,
|
||||
POT_LAST = POT3,
|
||||
TX_VOLTAGE,
|
||||
#if !defined(REVA)
|
||||
TX_CURRENT,
|
||||
#endif
|
||||
NUM_ANALOGS
|
||||
};
|
||||
enum CalibratedAnalogs {
|
||||
CALIBRATED_STICK1,
|
||||
CALIBRATED_STICK2,
|
||||
CALIBRATED_STICK3,
|
||||
CALIBRATED_STICK4,
|
||||
CALIBRATED_POT_FIRST,
|
||||
CALIBRATED_POT1 = CALIBRATED_POT_FIRST,
|
||||
CALIBRATED_POT2,
|
||||
CALIBRATED_POT3,
|
||||
CALIBRATED_POT_LAST = CALIBRATED_POT3,
|
||||
NUM_CALIBRATED_ANALOGS
|
||||
};
|
||||
#define IS_POT(x) ((x)>=POT_FIRST && (x)<=POT_LAST)
|
||||
#define IS_SLIDER(x) false
|
||||
void adcInit();
|
||||
void adcRead(void);
|
||||
uint16_t getAnalogValue(uint8_t index);
|
||||
uint16_t getBatteryVoltage(); // returns current battery voltage in 10mV steps
|
||||
void setSticksGain(uint8_t gains);
|
||||
|
||||
// Buzzer driver
|
||||
void buzzerSound(uint8_t duration);
|
||||
void buzzerHeartbeat();
|
||||
#define BUZZER_HEARTBEAT buzzerHeartbeat
|
||||
|
||||
// i2c driver
|
||||
void i2cCheck();
|
||||
|
||||
// Coproc driver
|
||||
void coprocInit();
|
||||
void coprocWriteData(uint8_t *data, uint32_t size);
|
||||
#if defined(__cplusplus)
|
||||
void coprocReadData(bool onlytemp=false);
|
||||
#endif
|
||||
extern int8_t volumeRequired;
|
||||
extern uint8_t Coproc_read;
|
||||
extern int8_t Coproc_valid;
|
||||
extern int8_t Coproc_temp;
|
||||
extern int8_t Coproc_maxtemp;
|
||||
|
||||
// Haptic driver
|
||||
void hapticOff(void);
|
||||
void hapticOn(uint32_t pwmPercent);
|
||||
|
||||
// BlueTooth driver
|
||||
#if defined(BLUETOOTH)
|
||||
void btInit();
|
||||
void btTask(void* pdata);
|
||||
void btPushByte(uint8_t data);
|
||||
#endif
|
||||
|
||||
// Power driver
|
||||
#define TRAINER_PWR
|
||||
#if !defined(REVA)
|
||||
#define SOFT_PWR_CTRL
|
||||
#endif
|
||||
void pwrInit();
|
||||
void pwrOff();
|
||||
uint32_t pwrCheck();
|
||||
uint32_t pwrPressed();
|
||||
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
|
||||
|
||||
// EEPROM driver
|
||||
#define EEPROM_SIZE (4*1024*1024/8)
|
||||
#define EEPROM_BLOCK_SIZE (4*1024)
|
||||
void eepromInit();
|
||||
uint8_t eepromReadStatus();
|
||||
uint8_t eepromIsTransferComplete(void);
|
||||
void eepromBlockErase(uint32_t address);
|
||||
void eepromStartRead(uint8_t * buffer, size_t address, size_t size);
|
||||
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size);
|
||||
|
||||
// Debug driver
|
||||
void debugPutc(const char c);
|
||||
|
||||
// Telemetry driver
|
||||
void telemetryPortInit(uint32_t baudrate, uint8_t mode);
|
||||
uint32_t telemetryTransmitPending();
|
||||
void telemetryTransmitBuffer(uint8_t * buffer, uint32_t size);
|
||||
void rxPdcUsart( void (*pChProcess)(uint8_t x) );
|
||||
|
||||
// Second UART driver
|
||||
void serial2TelemetryInit(unsigned int protocol);
|
||||
#if defined(__cplusplus)
|
||||
bool telemetrySecondPortReceive(uint8_t & data);
|
||||
#endif
|
||||
|
||||
extern const uint8_t BootCode[];
|
||||
|
||||
#endif // _BOARD_SKY9X_H_
|
||||
|
||||
@@ -1,253 +1,253 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \par Purpose
|
||||
*
|
||||
* Provides the low-level initialization function that gets called on chip startup.
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "board_lowlevel.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Local definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
/** Define clock timeout */
|
||||
#define CLOCK_TIMEOUT 5000
|
||||
/** Bit 29 must always be set to 1 when programming the CKGR_PLLAR register.*/
|
||||
#define PMC_PLLA_SET_BIT29 (0x1 << 29)
|
||||
/** Specifies the number of Slow Clock cycles x8 before the LOCKA bit is set in PMC_SR after CKGR_PLLAR is written.*/
|
||||
#define PMC_PLLA_COUNT (0xBF << 8)
|
||||
/** The PLLA Clock frequency is the PLLA input frequency multiplied by 8*/
|
||||
#define PMC_PLLA_MULTIPIER (0x07 << 16)
|
||||
/** PLLA Divider is bypassed.*/
|
||||
#define PMC_PLLA_DIV (0x01)
|
||||
|
||||
void revert_osc( void ) ;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Local functions
|
||||
* returns master_frequency
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
// *** WARNING, this is called BEFORE .data and .bss have been initialised
|
||||
// *** GLOBAL variables are NOT useable
|
||||
|
||||
static uint32_t BOARD_ConfigurePmc(void)
|
||||
{
|
||||
/* TODO: configurate PLL in new way */
|
||||
//#if 0
|
||||
// uint32_t timeout = 0;
|
||||
// /** 1: Checking the Main Oscillator Frequency (Optional) and Initialize main oscillator */
|
||||
// /** 1.1 Initialize main oscillator */
|
||||
// // TODO:
|
||||
|
||||
// /** 2. Setting PLL and Divider*/
|
||||
// /** 2.1 Initialize PLLA*/
|
||||
// PMC->CKGR_PLLAR = ( PMC_PLLA_SET_BIT29 |
|
||||
// PMC_PLLA_MULTIPIER |
|
||||
// PMC_PLLA_COUNT |
|
||||
// PMC_PLLA_DIV
|
||||
// );
|
||||
// timeout = 0;
|
||||
// /** 2.2 Wait for the LOCKA bit to be set by polling the status register.*/
|
||||
// while (!(PMC->PMC_SR & PMC_SR_LOCKA) && (timeout++ < CLOCK_TIMEOUT));
|
||||
// /** 2.3 wait for the MCKRDY bit to be set by polling the status register*/
|
||||
// timeout = 0;
|
||||
// while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
// /** 3. Selection of Master Clock and Processor Clock*/
|
||||
// PMC->PMC_MCKR |= PMC_MCKR_PRES_CLK_2;
|
||||
|
||||
// /** 3.1 wait for the MCKRDY bit to be set by polling the status register*/
|
||||
// timeout = 0;
|
||||
// while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
// /** 3.2 PLLA Clock is selected */
|
||||
// PMC->PMC_MCKR = PMC_MCKR_PRES_CLK_2 | PMC_MCKR_CSS_PLLA_CLK;
|
||||
|
||||
// /** 3.3 wait for the MCKRDY bit to be set by polling the status register*/
|
||||
// timeout = 0;
|
||||
// while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
//#endif
|
||||
|
||||
#if 1 // old as sam3u
|
||||
#define AT91C_CKGR_MUL_SHIFT 16
|
||||
//#define AT91C_CKGR_OUT_SHIFT 14
|
||||
#define AT91C_CKGR_PLLCOUNT_SHIFT 8
|
||||
#define AT91C_CKGR_DIV_SHIFT 0
|
||||
|
||||
// Settings at 72MHz/2 = 36MHz
|
||||
#define BOARD_OSCOUNT (CKGR_MOR_MOSCXTST & (0x8 << 8))
|
||||
#define BOARD_PLLR ((1 << 29) | (0x5 << AT91C_CKGR_MUL_SHIFT) \
|
||||
| (0x1 << AT91C_CKGR_PLLCOUNT_SHIFT) | (0x2 << AT91C_CKGR_DIV_SHIFT))
|
||||
#define BOARD_MCKR (PMC_MCKR_CSS_PLLA_CLK)
|
||||
|
||||
// Define clock timeout
|
||||
#undef CLOCK_TIMEOUT
|
||||
#define CLOCK_TIMEOUT 0xFFFFFFFF
|
||||
|
||||
uint32_t timeout = 0 ;
|
||||
Pmc *pmcptr ;
|
||||
|
||||
pmcptr = PMC ;
|
||||
|
||||
/* Enable NRST reset
|
||||
************************************/
|
||||
//AT91C_BASE_RSTC->RSTC_RMR |= AT91C_RSTC_URSTEN;
|
||||
|
||||
/* Select external slow clock
|
||||
****************************/
|
||||
|
||||
|
||||
// if ((SUPC->SUPC_SR & SUPC_SR_OSCSEL) != SUPC_SR_OSCSEL_CRYST) {
|
||||
// SUPC->SUPC_CR = SUPC_CR_XTALSEL_CRYSTAL_SEL | ((uint32_t)0xA5 << 24);
|
||||
// timeout = 0;
|
||||
// while (!(SUPC->SUPC_SR & SUPC_SR_OSCSEL_CRYST) );
|
||||
// }
|
||||
|
||||
|
||||
/* Initialize main oscillator
|
||||
****************************/
|
||||
if(!(pmcptr->CKGR_MOR & CKGR_MOR_MOSCSEL))
|
||||
{
|
||||
|
||||
pmcptr->CKGR_MOR = (0x37 << 16) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MOSCXTS) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
}
|
||||
|
||||
/* Switch to 3-20MHz Xtal oscillator */
|
||||
pmcptr->CKGR_MOR = (0x37 << 16) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN | CKGR_MOR_MOSCSEL;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MOSCSELS) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
pmcptr->PMC_MCKR = (PMC->PMC_MCKR & ~(uint32_t)PMC_MCKR_CSS) | PMC_MCKR_CSS_MAIN_CLK;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MCKRDY) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
/* Initialize PLLA 72 MHz */
|
||||
pmcptr->CKGR_PLLAR = BOARD_PLLR;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_LOCKA) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
|
||||
/* Initialize UTMI for USB usage, can be disabled if not using USB for the sake of saving power*/
|
||||
//AT91C_BASE_CKGR->CKGR_UCKR |= (AT91C_CKGR_UPLLCOUNT & (3 << 20)) | AT91C_CKGR_UPLLEN;
|
||||
//timeout = 0;
|
||||
//while (!(PMC->PMC_SR & AT91C_PMC_LOCKU) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
/* Switch to fast clock
|
||||
**********************/
|
||||
// PMC->PMC_MCKR = (BOARD_MCKR & ~PMC_MCKR_CSS) | PMC_MCKR_CSS_MAIN_CLK;
|
||||
// timeout = 0;
|
||||
// while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
// Switch to PLLA as main clock 36MHz
|
||||
PMC->PMC_MCKR = BOARD_MCKR;
|
||||
timeout = 0;
|
||||
while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
#endif
|
||||
return 36000000L; // Master_frequency
|
||||
}
|
||||
|
||||
void revert_osc()
|
||||
{
|
||||
uint32_t timeout = 0;
|
||||
Pmc *pmcptr;
|
||||
|
||||
pmcptr = PMC;
|
||||
|
||||
// Switch back to the internal oscillator
|
||||
pmcptr->CKGR_MOR = (0x37 << 16) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MOSCSELS) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
pmcptr->PMC_MCKR = (PMC->PMC_MCKR & ~(uint32_t)PMC_MCKR_CSS) | PMC_MCKR_CSS_SLOW_CLK;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MCKRDY) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
pmcptr->CKGR_PLLAR = 1 << 29; // Stop PLLA
|
||||
}
|
||||
|
||||
#if defined(BOOT)
|
||||
// extern void sam_bootx( void ) ;
|
||||
// extern void dispUSB( void ) ;
|
||||
// extern uint32_t init
|
||||
// ReadTrims( void ) ;
|
||||
// extern void run_application( void ) ;
|
||||
|
||||
static void lowLevelUsbCheck( void )
|
||||
{
|
||||
PMC->PMC_PCER0 = (1<<ID_PIOC) ; // Enable clock to PIOC
|
||||
PIOC->PIO_PER = PIO_PC25 ; // Enable bit C25 (USB-detect)
|
||||
|
||||
uint32_t i ;
|
||||
for ( i = 0 ; i < 50 ; i += 1 ) {
|
||||
__asm("nop") ;
|
||||
}
|
||||
|
||||
for ( i = 0 ; i < 10 ; i += 1 ) {
|
||||
if ( PIOC->PIO_PDSR & 0x02000000 ) {
|
||||
PMC->PMC_PCDR0 = (1<<ID_PIOC) ; // Disable clock to PIOC
|
||||
dispUSB() ;
|
||||
sam_bootx() ;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t x = initReadTrims() ;
|
||||
if ((x & 0x42) != 0x42) {
|
||||
run_application();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Exported functions
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Performs the low-level initialization of the chip. This includes EFC,
|
||||
* master clock and watchdog configuration.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
uint32_t SystemInit (void)
|
||||
{
|
||||
#if defined(BOOT)
|
||||
lowLevelUsbCheck() ;
|
||||
#endif
|
||||
|
||||
// Set 2 cycle (1 WS) for Embedded Flash Access
|
||||
// Max clock is 38 MHz (1.8V VVDCORE)
|
||||
EFC->EEFC_FMR = (1 << 8) ;
|
||||
|
||||
// Configure PMC
|
||||
return BOARD_ConfigurePmc();
|
||||
}
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \par Purpose
|
||||
*
|
||||
* Provides the low-level initialization function that gets called on chip startup.
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "board_lowlevel.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Local definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
/** Define clock timeout */
|
||||
#define CLOCK_TIMEOUT 5000
|
||||
/** Bit 29 must always be set to 1 when programming the CKGR_PLLAR register.*/
|
||||
#define PMC_PLLA_SET_BIT29 (0x1 << 29)
|
||||
/** Specifies the number of Slow Clock cycles x8 before the LOCKA bit is set in PMC_SR after CKGR_PLLAR is written.*/
|
||||
#define PMC_PLLA_COUNT (0xBF << 8)
|
||||
/** The PLLA Clock frequency is the PLLA input frequency multiplied by 8*/
|
||||
#define PMC_PLLA_MULTIPIER (0x07 << 16)
|
||||
/** PLLA Divider is bypassed.*/
|
||||
#define PMC_PLLA_DIV (0x01)
|
||||
|
||||
void revert_osc( void ) ;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Local functions
|
||||
* returns master_frequency
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
// *** WARNING, this is called BEFORE .data and .bss have been initialised
|
||||
// *** GLOBAL variables are NOT useable
|
||||
|
||||
static uint32_t BOARD_ConfigurePmc(void)
|
||||
{
|
||||
/* TODO: configurate PLL in new way */
|
||||
//#if 0
|
||||
// uint32_t timeout = 0;
|
||||
// /** 1: Checking the Main Oscillator Frequency (Optional) and Initialize main oscillator */
|
||||
// /** 1.1 Initialize main oscillator */
|
||||
// // TODO:
|
||||
|
||||
// /** 2. Setting PLL and Divider*/
|
||||
// /** 2.1 Initialize PLLA*/
|
||||
// PMC->CKGR_PLLAR = ( PMC_PLLA_SET_BIT29 |
|
||||
// PMC_PLLA_MULTIPIER |
|
||||
// PMC_PLLA_COUNT |
|
||||
// PMC_PLLA_DIV
|
||||
// );
|
||||
// timeout = 0;
|
||||
// /** 2.2 Wait for the LOCKA bit to be set by polling the status register.*/
|
||||
// while (!(PMC->PMC_SR & PMC_SR_LOCKA) && (timeout++ < CLOCK_TIMEOUT));
|
||||
// /** 2.3 wait for the MCKRDY bit to be set by polling the status register*/
|
||||
// timeout = 0;
|
||||
// while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
// /** 3. Selection of Master Clock and Processor Clock*/
|
||||
// PMC->PMC_MCKR |= PMC_MCKR_PRES_CLK_2;
|
||||
|
||||
// /** 3.1 wait for the MCKRDY bit to be set by polling the status register*/
|
||||
// timeout = 0;
|
||||
// while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
// /** 3.2 PLLA Clock is selected */
|
||||
// PMC->PMC_MCKR = PMC_MCKR_PRES_CLK_2 | PMC_MCKR_CSS_PLLA_CLK;
|
||||
|
||||
// /** 3.3 wait for the MCKRDY bit to be set by polling the status register*/
|
||||
// timeout = 0;
|
||||
// while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
//#endif
|
||||
|
||||
#if 1 // old as sam3u
|
||||
#define AT91C_CKGR_MUL_SHIFT 16
|
||||
//#define AT91C_CKGR_OUT_SHIFT 14
|
||||
#define AT91C_CKGR_PLLCOUNT_SHIFT 8
|
||||
#define AT91C_CKGR_DIV_SHIFT 0
|
||||
|
||||
// Settings at 72MHz/2 = 36MHz
|
||||
#define BOARD_OSCOUNT (CKGR_MOR_MOSCXTST & (0x8 << 8))
|
||||
#define BOARD_PLLR ((1 << 29) | (0x5 << AT91C_CKGR_MUL_SHIFT) \
|
||||
| (0x1 << AT91C_CKGR_PLLCOUNT_SHIFT) | (0x2 << AT91C_CKGR_DIV_SHIFT))
|
||||
#define BOARD_MCKR (PMC_MCKR_CSS_PLLA_CLK)
|
||||
|
||||
// Define clock timeout
|
||||
#undef CLOCK_TIMEOUT
|
||||
#define CLOCK_TIMEOUT 0xFFFFFFFF
|
||||
|
||||
uint32_t timeout = 0 ;
|
||||
Pmc *pmcptr ;
|
||||
|
||||
pmcptr = PMC ;
|
||||
|
||||
/* Enable NRST reset
|
||||
************************************/
|
||||
//AT91C_BASE_RSTC->RSTC_RMR |= AT91C_RSTC_URSTEN;
|
||||
|
||||
/* Select external slow clock
|
||||
****************************/
|
||||
|
||||
|
||||
// if ((SUPC->SUPC_SR & SUPC_SR_OSCSEL) != SUPC_SR_OSCSEL_CRYST) {
|
||||
// SUPC->SUPC_CR = SUPC_CR_XTALSEL_CRYSTAL_SEL | ((uint32_t)0xA5 << 24);
|
||||
// timeout = 0;
|
||||
// while (!(SUPC->SUPC_SR & SUPC_SR_OSCSEL_CRYST) );
|
||||
// }
|
||||
|
||||
|
||||
/* Initialize main oscillator
|
||||
****************************/
|
||||
if(!(pmcptr->CKGR_MOR & CKGR_MOR_MOSCSEL))
|
||||
{
|
||||
|
||||
pmcptr->CKGR_MOR = (0x37 << 16) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MOSCXTS) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
}
|
||||
|
||||
/* Switch to 3-20MHz Xtal oscillator */
|
||||
pmcptr->CKGR_MOR = (0x37 << 16) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN | CKGR_MOR_MOSCSEL;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MOSCSELS) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
pmcptr->PMC_MCKR = (PMC->PMC_MCKR & ~(uint32_t)PMC_MCKR_CSS) | PMC_MCKR_CSS_MAIN_CLK;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MCKRDY) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
/* Initialize PLLA 72 MHz */
|
||||
pmcptr->CKGR_PLLAR = BOARD_PLLR;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_LOCKA) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
|
||||
/* Initialize UTMI for USB usage, can be disabled if not using USB for the sake of saving power*/
|
||||
//AT91C_BASE_CKGR->CKGR_UCKR |= (AT91C_CKGR_UPLLCOUNT & (3 << 20)) | AT91C_CKGR_UPLLEN;
|
||||
//timeout = 0;
|
||||
//while (!(PMC->PMC_SR & AT91C_PMC_LOCKU) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
/* Switch to fast clock
|
||||
**********************/
|
||||
// PMC->PMC_MCKR = (BOARD_MCKR & ~PMC_MCKR_CSS) | PMC_MCKR_CSS_MAIN_CLK;
|
||||
// timeout = 0;
|
||||
// while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
// Switch to PLLA as main clock 36MHz
|
||||
PMC->PMC_MCKR = BOARD_MCKR;
|
||||
timeout = 0;
|
||||
while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
#endif
|
||||
return 36000000L; // Master_frequency
|
||||
}
|
||||
|
||||
void revert_osc()
|
||||
{
|
||||
uint32_t timeout = 0;
|
||||
Pmc *pmcptr;
|
||||
|
||||
pmcptr = PMC;
|
||||
|
||||
// Switch back to the internal oscillator
|
||||
pmcptr->CKGR_MOR = (0x37 << 16) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MOSCSELS) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
pmcptr->PMC_MCKR = (PMC->PMC_MCKR & ~(uint32_t)PMC_MCKR_CSS) | PMC_MCKR_CSS_SLOW_CLK;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MCKRDY) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
pmcptr->CKGR_PLLAR = 1 << 29; // Stop PLLA
|
||||
}
|
||||
|
||||
#if defined(BOOT)
|
||||
// extern void sam_bootx( void ) ;
|
||||
// extern void dispUSB( void ) ;
|
||||
// extern uint32_t init
|
||||
// ReadTrims( void ) ;
|
||||
// extern void run_application( void ) ;
|
||||
|
||||
static void lowLevelUsbCheck( void )
|
||||
{
|
||||
PMC->PMC_PCER0 = (1<<ID_PIOC) ; // Enable clock to PIOC
|
||||
PIOC->PIO_PER = PIO_PC25 ; // Enable bit C25 (USB-detect)
|
||||
|
||||
uint32_t i ;
|
||||
for ( i = 0 ; i < 50 ; i += 1 ) {
|
||||
__asm("nop") ;
|
||||
}
|
||||
|
||||
for ( i = 0 ; i < 10 ; i += 1 ) {
|
||||
if ( PIOC->PIO_PDSR & 0x02000000 ) {
|
||||
PMC->PMC_PCDR0 = (1<<ID_PIOC) ; // Disable clock to PIOC
|
||||
dispUSB() ;
|
||||
sam_bootx() ;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t x = initReadTrims() ;
|
||||
if ((x & 0x42) != 0x42) {
|
||||
run_application();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Exported functions
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Performs the low-level initialization of the chip. This includes EFC,
|
||||
* master clock and watchdog configuration.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
uint32_t SystemInit (void)
|
||||
{
|
||||
#if defined(BOOT)
|
||||
lowLevelUsbCheck() ;
|
||||
#endif
|
||||
|
||||
// Set 2 cycle (1 WS) for Embedded Flash Access
|
||||
// Max clock is 38 MHz (1.8V VVDCORE)
|
||||
EFC->EEFC_FMR = (1 << 8) ;
|
||||
|
||||
// Configure PMC
|
||||
return BOARD_ConfigurePmc();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,59 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
volatile uint8_t buzzerCount ;
|
||||
|
||||
#if defined(REVA)
|
||||
void buzzerOn()
|
||||
{
|
||||
PIOA->PIO_SODR = 0x00010000L ; // Set bit A16 ON
|
||||
}
|
||||
|
||||
void buzzerOff()
|
||||
{
|
||||
PIOA->PIO_CODR = 0x00010000L ; // Set bit A16 ON
|
||||
}
|
||||
#else
|
||||
void buzzerOn()
|
||||
{
|
||||
PIOA->PIO_SODR = 0x02000000L ; // Set bit A25 ON
|
||||
}
|
||||
|
||||
void buzzerOff()
|
||||
{
|
||||
PIOA->PIO_CODR = 0x02000000L ; // Set bit A25 ON
|
||||
}
|
||||
#endif
|
||||
|
||||
void buzzerSound(uint8_t duration)
|
||||
{
|
||||
buzzerOn();
|
||||
buzzerCount = duration;
|
||||
}
|
||||
|
||||
void buzzerHeartbeat()
|
||||
{
|
||||
if (buzzerCount) {
|
||||
if (--buzzerCount == 0)
|
||||
buzzerOff();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
volatile uint8_t buzzerCount ;
|
||||
|
||||
#if defined(REVA)
|
||||
void buzzerOn()
|
||||
{
|
||||
PIOA->PIO_SODR = 0x00010000L ; // Set bit A16 ON
|
||||
}
|
||||
|
||||
void buzzerOff()
|
||||
{
|
||||
PIOA->PIO_CODR = 0x00010000L ; // Set bit A16 ON
|
||||
}
|
||||
#else
|
||||
void buzzerOn()
|
||||
{
|
||||
PIOA->PIO_SODR = 0x02000000L ; // Set bit A25 ON
|
||||
}
|
||||
|
||||
void buzzerOff()
|
||||
{
|
||||
PIOA->PIO_CODR = 0x02000000L ; // Set bit A25 ON
|
||||
}
|
||||
#endif
|
||||
|
||||
void buzzerSound(uint8_t duration)
|
||||
{
|
||||
buzzerOn();
|
||||
buzzerCount = duration;
|
||||
}
|
||||
|
||||
void buzzerHeartbeat()
|
||||
{
|
||||
if (buzzerCount) {
|
||||
if (--buzzerCount == 0)
|
||||
buzzerOff();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,104 +18,104 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definition of AT91SAM3S4 characteristics and features
|
||||
///
|
||||
/// !Usage
|
||||
/// -# For ARM core feature, see "AT91SAM3S4 - ARM core features".
|
||||
/// -# For IP features, see "AT91SAM3S4 - IP features".
|
||||
/// -# For misc, see "AT91SAM3S4 - Misc".
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definition of AT91SAM3S4 characteristics and features
|
||||
///
|
||||
/// !Usage
|
||||
/// -# For ARM core feature, see "AT91SAM3S4 - ARM core features".
|
||||
/// -# For IP features, see "AT91SAM3S4 - IP features".
|
||||
/// -# For misc, see "AT91SAM3S4 - Misc".
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _CHIP_H_
|
||||
#define _CHIP_H_
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "AT91SAM3S4 - ARM core features"
|
||||
/// This page lists several characteristics related to the ARM core
|
||||
///
|
||||
|
||||
//ARM core features
|
||||
|
||||
/// ARM core definition.
|
||||
#define cortexm3
|
||||
|
||||
/// family definition.
|
||||
#define at91sam3s
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "AT91SAM3S4 - IP features"
|
||||
/// This page lists several characteristics related to the embedded IP
|
||||
///
|
||||
|
||||
//IP FEATURES
|
||||
|
||||
// EFC GPNVM number
|
||||
#define CHIP_EFC_NUM_GPNVMS 3
|
||||
|
||||
/// Indicates chip has an Enhanced EFC.
|
||||
#define CHIP_FLASH_EEFC
|
||||
|
||||
// DMA channels number
|
||||
#define CHIP_DMA_CHANNEL_NUM 4
|
||||
|
||||
// Indicate chip's MCI interface.
|
||||
#define MCI2_INTERFACE
|
||||
|
||||
// Indicate chip SSC has DMA interface.
|
||||
#define CHIP_SSC_DMA
|
||||
|
||||
// Indicate chip SPI has DMA interface.
|
||||
#define CHIP_SPI_DMA
|
||||
|
||||
/// Indicates chip has an UDP Full Speed.
|
||||
#define CHIP_USB_UDP
|
||||
|
||||
/// Indicates chip has an internal pull-up.
|
||||
#define CHIP_USB_PULLUP_INTERNAL
|
||||
|
||||
/// Number of USB endpoints
|
||||
#define CHIP_USB_NUMENDPOINTS 8
|
||||
|
||||
/// Endpoints max paxcket size
|
||||
#define CHIP_USB_ENDPOINTS_MAXPACKETSIZE(i) \
|
||||
((i == 0) ? 64 : \
|
||||
((i == 1) ? 64 : \
|
||||
((i == 2) ? 64 : \
|
||||
((i == 3) ? 64 : \
|
||||
((i == 4) ? 512 : \
|
||||
((i == 5) ? 512 : \
|
||||
((i == 6) ? 64 : \
|
||||
((i == 7) ? 64 : 0 ))))))))
|
||||
|
||||
/// Endpoints Number of Bank
|
||||
#define CHIP_USB_ENDPOINTS_BANKS(i) \
|
||||
((i == 0) ? 1 : \
|
||||
((i == 1) ? 2 : \
|
||||
((i == 2) ? 2 : \
|
||||
((i == 3) ? 1 : \
|
||||
((i == 4) ? 2 : \
|
||||
((i == 5) ? 2 : \
|
||||
((i == 6) ? 2 : \
|
||||
((i == 7) ? 2 : 0 ))))))))
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "AT91SAM3S4 - Misc "
|
||||
/// This page lists misc features
|
||||
///
|
||||
|
||||
//Misc
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "AT91SAM3S4 - ARM core features"
|
||||
/// This page lists several characteristics related to the ARM core
|
||||
///
|
||||
|
||||
//ARM core features
|
||||
|
||||
/// ARM core definition.
|
||||
#define cortexm3
|
||||
|
||||
/// family definition.
|
||||
#define at91sam3s
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "AT91SAM3S4 - IP features"
|
||||
/// This page lists several characteristics related to the embedded IP
|
||||
///
|
||||
|
||||
//IP FEATURES
|
||||
|
||||
// EFC GPNVM number
|
||||
#define CHIP_EFC_NUM_GPNVMS 3
|
||||
|
||||
/// Indicates chip has an Enhanced EFC.
|
||||
#define CHIP_FLASH_EEFC
|
||||
|
||||
// DMA channels number
|
||||
#define CHIP_DMA_CHANNEL_NUM 4
|
||||
|
||||
// Indicate chip's MCI interface.
|
||||
#define MCI2_INTERFACE
|
||||
|
||||
// Indicate chip SSC has DMA interface.
|
||||
#define CHIP_SSC_DMA
|
||||
|
||||
// Indicate chip SPI has DMA interface.
|
||||
#define CHIP_SPI_DMA
|
||||
|
||||
/// Indicates chip has an UDP Full Speed.
|
||||
#define CHIP_USB_UDP
|
||||
|
||||
/// Indicates chip has an internal pull-up.
|
||||
#define CHIP_USB_PULLUP_INTERNAL
|
||||
|
||||
/// Number of USB endpoints
|
||||
#define CHIP_USB_NUMENDPOINTS 8
|
||||
|
||||
/// Endpoints max paxcket size
|
||||
#define CHIP_USB_ENDPOINTS_MAXPACKETSIZE(i) \
|
||||
((i == 0) ? 64 : \
|
||||
((i == 1) ? 64 : \
|
||||
((i == 2) ? 64 : \
|
||||
((i == 3) ? 64 : \
|
||||
((i == 4) ? 512 : \
|
||||
((i == 5) ? 512 : \
|
||||
((i == 6) ? 64 : \
|
||||
((i == 7) ? 64 : 0 ))))))))
|
||||
|
||||
/// Endpoints Number of Bank
|
||||
#define CHIP_USB_ENDPOINTS_BANKS(i) \
|
||||
((i == 0) ? 1 : \
|
||||
((i == 1) ? 2 : \
|
||||
((i == 2) ? 2 : \
|
||||
((i == 3) ? 1 : \
|
||||
((i == 4) ? 2 : \
|
||||
((i == 5) ? 2 : \
|
||||
((i == 6) ? 2 : \
|
||||
((i == 7) ? 2 : 0 ))))))))
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "AT91SAM3S4 - Misc "
|
||||
/// This page lists misc features
|
||||
///
|
||||
|
||||
//Misc
|
||||
|
||||
#endif // _CHIP_H_
|
||||
|
||||
|
||||
|
||||
@@ -1,205 +1,205 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
int8_t volumeRequired ;
|
||||
uint8_t coprocReadDataPending ;
|
||||
uint8_t coprocWriteDataPending ;
|
||||
uint8_t CoProc_appgo_pending ;
|
||||
uint8_t Volume_read ;
|
||||
uint8_t Coproc_read ;
|
||||
int8_t Coproc_temp ;
|
||||
int8_t Coproc_maxtemp=-127 ;
|
||||
int8_t Coproc_valid ;
|
||||
bool get_onlytemp;
|
||||
#if !defined(SIMU)
|
||||
// TODO not used? static uint8_t *Twi_read_address ;
|
||||
#endif
|
||||
static uint8_t TwiOperation ;
|
||||
|
||||
#define TWI_NONE 0
|
||||
#define TWI_WRITE_VOL 2
|
||||
#define TWI_READ_COPROC 3
|
||||
#define TWI_COPROC_APPGO 4
|
||||
#define TWI_WAIT_STOP 5
|
||||
#define TWI_WRITE_COPROC 6
|
||||
|
||||
// Commands to the coprocessor bootloader/application
|
||||
#define TWI_CMD_PAGEUPDATE 0x01 // TWI Command to program a flash page
|
||||
#define TWI_CMD_EXECUTEAPP 0x02 // TWI Command to jump to the application program
|
||||
#define TWI_CMD_SETREAD_ADDRESS 0x03 // TWI Command to set address to read from
|
||||
#define TWI_CMD_WRITE_DATA 0x04 // TWI Command send data to the application
|
||||
#define COPROC_RX_BUXSIZE 22
|
||||
uint8_t Co_proc_status[COPROC_RX_BUXSIZE] ;
|
||||
uint8_t *coprocWriteDataPtr ;
|
||||
uint32_t coprocWriteDataSize ;
|
||||
|
||||
|
||||
// This is called from an interrupt routine, or
|
||||
// interrupts must be disabled while it is called
|
||||
// from elsewhere.
|
||||
void i2cCheck()
|
||||
{
|
||||
if ( TWI0->TWI_IMR & TWI_IMR_TXCOMP ) {
|
||||
return ; // Busy
|
||||
}
|
||||
|
||||
if ( volumeRequired >= 0 ) { // Set volume to this value
|
||||
TWI0->TWI_MMR = 0x002F0000 ; // Device 5E (>>1) and master is writing
|
||||
TwiOperation = TWI_WRITE_VOL ;
|
||||
TWI0->TWI_THR = volumeRequired ; // Send data
|
||||
volumeRequired = -1 ;
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
else if (coprocReadDataPending) {
|
||||
Coproc_valid = 0 ;
|
||||
coprocReadDataPending = 0 ;
|
||||
TWI0->TWI_MMR = 0x00351000 ; // Device 35 and master is reading
|
||||
TwiOperation = TWI_READ_COPROC ;
|
||||
#ifndef SIMU
|
||||
TWI0->TWI_RPR = (uint32_t)&Co_proc_status[0] ;
|
||||
#endif
|
||||
TWI0->TWI_RCR = COPROC_RX_BUXSIZE - 1 ;
|
||||
if ( TWI0->TWI_SR & TWI_SR_RXRDY ) {
|
||||
(void) TWI0->TWI_RHR ;
|
||||
}
|
||||
TWI0->TWI_PTCR = TWI_PTCR_RXTEN ; // Start transfers
|
||||
TWI0->TWI_CR = TWI_CR_START ; // Start Rx
|
||||
TWI0->TWI_IER = TWI_IER_RXBUFF | TWI_IER_TXCOMP ;
|
||||
}
|
||||
else if ( CoProc_appgo_pending ) {
|
||||
CoProc_appgo_pending = 0 ;
|
||||
TWI0->TWI_MMR = 0x00350000 ; // Device 35 and master is writing
|
||||
TwiOperation = TWI_COPROC_APPGO ;
|
||||
TWI0->TWI_THR = TWI_CMD_EXECUTEAPP ; // Send appgo command
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
else if ( coprocWriteDataPending ) {
|
||||
coprocWriteDataPending = 0 ;
|
||||
TWI0->TWI_MMR = 0x00350000 ; // Device 35 and master is writing
|
||||
TwiOperation = TWI_WRITE_COPROC ;
|
||||
#ifndef SIMU
|
||||
TWI0->TWI_TPR = (uint32_t)coprocWriteDataPtr ;
|
||||
#endif
|
||||
TWI0->TWI_TCR = coprocWriteDataSize ;
|
||||
TWI0->TWI_THR = TWI_CMD_WRITE_DATA ; // Send write command
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTEN ; // Start data transfer
|
||||
TWI0->TWI_IER = TWI_IER_TXBUFE | TWI_IER_TXCOMP ;
|
||||
}
|
||||
}
|
||||
|
||||
void coprocReadData(bool onlytemp)
|
||||
{
|
||||
get_onlytemp = onlytemp;
|
||||
coprocReadDataPending = 1 ;
|
||||
__disable_irq() ;
|
||||
i2cCheck() ;
|
||||
__enable_irq() ;
|
||||
}
|
||||
|
||||
void coprocWriteData(uint8_t *data, uint32_t size)
|
||||
{
|
||||
coprocWriteDataPtr = data;
|
||||
coprocWriteDataSize = size;
|
||||
coprocWriteDataPending = 1;
|
||||
__disable_irq();
|
||||
i2cCheck();
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
extern "C" void TWI0_IRQHandler()
|
||||
{
|
||||
if ( TwiOperation == TWI_READ_COPROC )
|
||||
{
|
||||
if ( TWI0->TWI_SR & TWI_SR_RXBUFF )
|
||||
{
|
||||
TWI0->TWI_IDR = TWI_IDR_RXBUFF ;
|
||||
TwiOperation = TWI_WAIT_STOP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx
|
||||
TWI0->TWI_RCR = 1 ; // Last byte
|
||||
return ;
|
||||
}
|
||||
else
|
||||
{
|
||||
Coproc_valid = -1 ;
|
||||
}
|
||||
}
|
||||
|
||||
if ( TwiOperation == TWI_WAIT_STOP )
|
||||
{
|
||||
Coproc_valid = 1 ;
|
||||
Coproc_read = Co_proc_status[0] ;
|
||||
if ( Coproc_read & 0x80 ) {
|
||||
// Bootloader
|
||||
CoProc_appgo_pending = 1 ; // Action application
|
||||
}
|
||||
else {
|
||||
// Got data from tiny app
|
||||
// Set the date and time
|
||||
struct gtm utm;
|
||||
if (!get_onlytemp) {
|
||||
utm.tm_sec = Co_proc_status[1] ;
|
||||
utm.tm_min = Co_proc_status[2] ;
|
||||
utm.tm_hour = Co_proc_status[3] ;
|
||||
utm.tm_mday = Co_proc_status[4] ;
|
||||
utm.tm_mon = Co_proc_status[5] - 1;
|
||||
utm.tm_year = (Co_proc_status[6] + ( Co_proc_status[7] << 8 )) - TM_YEAR_BASE;
|
||||
g_rtcTime = gmktime(&utm);
|
||||
}
|
||||
Coproc_temp = Co_proc_status[8];
|
||||
if (Coproc_temp > Coproc_maxtemp)
|
||||
Coproc_maxtemp=Coproc_temp;
|
||||
}
|
||||
TWI0->TWI_PTCR = TWI_PTCR_RXTDIS ; // Stop transfers
|
||||
if ( TWI0->TWI_SR & TWI_SR_RXRDY ) {
|
||||
(void) TWI0->TWI_RHR ; // Discard any rubbish data
|
||||
}
|
||||
}
|
||||
|
||||
// if ( TwiOperation == TWI_WRITE_VOL )
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
if ( TwiOperation == TWI_WRITE_COPROC )
|
||||
{
|
||||
if ( TWI0->TWI_SR & TWI_SR_TXBUFE )
|
||||
{
|
||||
TWI0->TWI_IDR = TWI_IDR_TXBUFE ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTDIS ; // Stop transfers
|
||||
TwiOperation = TWI_NONE ;
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
TWI0->TWI_IDR = TWI_IDR_TXCOMP | TWI_IDR_TXBUFE | TWI_IDR_RXBUFF ;
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTDIS | TWI_PTCR_RXTDIS ; // Stop transfers
|
||||
if ( TWI0->TWI_SR & TWI_SR_NACK )
|
||||
{
|
||||
}
|
||||
TwiOperation = TWI_NONE ;
|
||||
i2cCheck() ;
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
int8_t volumeRequired ;
|
||||
uint8_t coprocReadDataPending ;
|
||||
uint8_t coprocWriteDataPending ;
|
||||
uint8_t CoProc_appgo_pending ;
|
||||
uint8_t Volume_read ;
|
||||
uint8_t Coproc_read ;
|
||||
int8_t Coproc_temp ;
|
||||
int8_t Coproc_maxtemp=-127 ;
|
||||
int8_t Coproc_valid ;
|
||||
bool get_onlytemp;
|
||||
#if !defined(SIMU)
|
||||
// TODO not used? static uint8_t *Twi_read_address ;
|
||||
#endif
|
||||
static uint8_t TwiOperation ;
|
||||
|
||||
#define TWI_NONE 0
|
||||
#define TWI_WRITE_VOL 2
|
||||
#define TWI_READ_COPROC 3
|
||||
#define TWI_COPROC_APPGO 4
|
||||
#define TWI_WAIT_STOP 5
|
||||
#define TWI_WRITE_COPROC 6
|
||||
|
||||
// Commands to the coprocessor bootloader/application
|
||||
#define TWI_CMD_PAGEUPDATE 0x01 // TWI Command to program a flash page
|
||||
#define TWI_CMD_EXECUTEAPP 0x02 // TWI Command to jump to the application program
|
||||
#define TWI_CMD_SETREAD_ADDRESS 0x03 // TWI Command to set address to read from
|
||||
#define TWI_CMD_WRITE_DATA 0x04 // TWI Command send data to the application
|
||||
#define COPROC_RX_BUXSIZE 22
|
||||
uint8_t Co_proc_status[COPROC_RX_BUXSIZE] ;
|
||||
uint8_t *coprocWriteDataPtr ;
|
||||
uint32_t coprocWriteDataSize ;
|
||||
|
||||
|
||||
// This is called from an interrupt routine, or
|
||||
// interrupts must be disabled while it is called
|
||||
// from elsewhere.
|
||||
void i2cCheck()
|
||||
{
|
||||
if ( TWI0->TWI_IMR & TWI_IMR_TXCOMP ) {
|
||||
return ; // Busy
|
||||
}
|
||||
|
||||
if ( volumeRequired >= 0 ) { // Set volume to this value
|
||||
TWI0->TWI_MMR = 0x002F0000 ; // Device 5E (>>1) and master is writing
|
||||
TwiOperation = TWI_WRITE_VOL ;
|
||||
TWI0->TWI_THR = volumeRequired ; // Send data
|
||||
volumeRequired = -1 ;
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
else if (coprocReadDataPending) {
|
||||
Coproc_valid = 0 ;
|
||||
coprocReadDataPending = 0 ;
|
||||
TWI0->TWI_MMR = 0x00351000 ; // Device 35 and master is reading
|
||||
TwiOperation = TWI_READ_COPROC ;
|
||||
#ifndef SIMU
|
||||
TWI0->TWI_RPR = (uint32_t)&Co_proc_status[0] ;
|
||||
#endif
|
||||
TWI0->TWI_RCR = COPROC_RX_BUXSIZE - 1 ;
|
||||
if ( TWI0->TWI_SR & TWI_SR_RXRDY ) {
|
||||
(void) TWI0->TWI_RHR ;
|
||||
}
|
||||
TWI0->TWI_PTCR = TWI_PTCR_RXTEN ; // Start transfers
|
||||
TWI0->TWI_CR = TWI_CR_START ; // Start Rx
|
||||
TWI0->TWI_IER = TWI_IER_RXBUFF | TWI_IER_TXCOMP ;
|
||||
}
|
||||
else if ( CoProc_appgo_pending ) {
|
||||
CoProc_appgo_pending = 0 ;
|
||||
TWI0->TWI_MMR = 0x00350000 ; // Device 35 and master is writing
|
||||
TwiOperation = TWI_COPROC_APPGO ;
|
||||
TWI0->TWI_THR = TWI_CMD_EXECUTEAPP ; // Send appgo command
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
else if ( coprocWriteDataPending ) {
|
||||
coprocWriteDataPending = 0 ;
|
||||
TWI0->TWI_MMR = 0x00350000 ; // Device 35 and master is writing
|
||||
TwiOperation = TWI_WRITE_COPROC ;
|
||||
#ifndef SIMU
|
||||
TWI0->TWI_TPR = (uint32_t)coprocWriteDataPtr ;
|
||||
#endif
|
||||
TWI0->TWI_TCR = coprocWriteDataSize ;
|
||||
TWI0->TWI_THR = TWI_CMD_WRITE_DATA ; // Send write command
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTEN ; // Start data transfer
|
||||
TWI0->TWI_IER = TWI_IER_TXBUFE | TWI_IER_TXCOMP ;
|
||||
}
|
||||
}
|
||||
|
||||
void coprocReadData(bool onlytemp)
|
||||
{
|
||||
get_onlytemp = onlytemp;
|
||||
coprocReadDataPending = 1 ;
|
||||
__disable_irq() ;
|
||||
i2cCheck() ;
|
||||
__enable_irq() ;
|
||||
}
|
||||
|
||||
void coprocWriteData(uint8_t *data, uint32_t size)
|
||||
{
|
||||
coprocWriteDataPtr = data;
|
||||
coprocWriteDataSize = size;
|
||||
coprocWriteDataPending = 1;
|
||||
__disable_irq();
|
||||
i2cCheck();
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
extern "C" void TWI0_IRQHandler()
|
||||
{
|
||||
if ( TwiOperation == TWI_READ_COPROC )
|
||||
{
|
||||
if ( TWI0->TWI_SR & TWI_SR_RXBUFF )
|
||||
{
|
||||
TWI0->TWI_IDR = TWI_IDR_RXBUFF ;
|
||||
TwiOperation = TWI_WAIT_STOP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx
|
||||
TWI0->TWI_RCR = 1 ; // Last byte
|
||||
return ;
|
||||
}
|
||||
else
|
||||
{
|
||||
Coproc_valid = -1 ;
|
||||
}
|
||||
}
|
||||
|
||||
if ( TwiOperation == TWI_WAIT_STOP )
|
||||
{
|
||||
Coproc_valid = 1 ;
|
||||
Coproc_read = Co_proc_status[0] ;
|
||||
if ( Coproc_read & 0x80 ) {
|
||||
// Bootloader
|
||||
CoProc_appgo_pending = 1 ; // Action application
|
||||
}
|
||||
else {
|
||||
// Got data from tiny app
|
||||
// Set the date and time
|
||||
struct gtm utm;
|
||||
if (!get_onlytemp) {
|
||||
utm.tm_sec = Co_proc_status[1] ;
|
||||
utm.tm_min = Co_proc_status[2] ;
|
||||
utm.tm_hour = Co_proc_status[3] ;
|
||||
utm.tm_mday = Co_proc_status[4] ;
|
||||
utm.tm_mon = Co_proc_status[5] - 1;
|
||||
utm.tm_year = (Co_proc_status[6] + ( Co_proc_status[7] << 8 )) - TM_YEAR_BASE;
|
||||
g_rtcTime = gmktime(&utm);
|
||||
}
|
||||
Coproc_temp = Co_proc_status[8];
|
||||
if (Coproc_temp > Coproc_maxtemp)
|
||||
Coproc_maxtemp=Coproc_temp;
|
||||
}
|
||||
TWI0->TWI_PTCR = TWI_PTCR_RXTDIS ; // Stop transfers
|
||||
if ( TWI0->TWI_SR & TWI_SR_RXRDY ) {
|
||||
(void) TWI0->TWI_RHR ; // Discard any rubbish data
|
||||
}
|
||||
}
|
||||
|
||||
// if ( TwiOperation == TWI_WRITE_VOL )
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
if ( TwiOperation == TWI_WRITE_COPROC )
|
||||
{
|
||||
if ( TWI0->TWI_SR & TWI_SR_TXBUFE )
|
||||
{
|
||||
TWI0->TWI_IDR = TWI_IDR_TXBUFE ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTDIS ; // Stop transfers
|
||||
TwiOperation = TWI_NONE ;
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
TWI0->TWI_IDR = TWI_IDR_TXCOMP | TWI_IDR_TXBUFE | TWI_IDR_RXBUFF ;
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTDIS | TWI_PTCR_RXTDIS ; // Stop transfers
|
||||
if ( TWI0->TWI_SR & TWI_SR_NACK )
|
||||
{
|
||||
}
|
||||
TwiOperation = TWI_NONE ;
|
||||
i2cCheck() ;
|
||||
}
|
||||
#endif
|
||||
|
||||
+848
-848
File diff suppressed because it is too large
Load Diff
+1792
-1792
File diff suppressed because it is too large
Load Diff
+131
-131
@@ -1,131 +1,131 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#define __CRT_C__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: All extern Data */
|
||||
/*=========================================================================*/
|
||||
/*
|
||||
* The next data are defined by the linker script.
|
||||
*/
|
||||
extern unsigned long _stext;
|
||||
extern unsigned long _etext;
|
||||
extern unsigned long _sdata;
|
||||
extern unsigned long _edata;
|
||||
extern unsigned long _sbss;
|
||||
extern unsigned long _ebss;
|
||||
extern unsigned long _estack;
|
||||
|
||||
/* This is the main */
|
||||
extern int main (void);
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: Prototypes */
|
||||
/*=========================================================================*/
|
||||
extern uint32_t SystemInit (void) ; // __attribute__((weak));
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: All code exported */
|
||||
/*=========================================================================*/
|
||||
|
||||
/***************************************************************************/
|
||||
/* SystemInit */
|
||||
/* */
|
||||
/* SystemInit is a function which is provided by the CMSIS interface. */
|
||||
/* If this function is not available, we need a function here to prevent */
|
||||
/* an error of the linker. Therefore this function is declared as weak. */
|
||||
/***************************************************************************/
|
||||
//uint32_t SystemInit (void)
|
||||
//{
|
||||
|
||||
//} /* SystemInit */
|
||||
|
||||
extern uint32_t Master_frequency ;
|
||||
|
||||
/***************************************************************************/
|
||||
/* ResetHandler */
|
||||
/* */
|
||||
/* This function is used for the C runtime initialisation, */
|
||||
/* for handling the .data and .bss segments. */
|
||||
/***************************************************************************/
|
||||
void ResetHandler (void)
|
||||
{
|
||||
{
|
||||
uint32_t *pSrc;
|
||||
uint32_t *pDest;
|
||||
uint32_t m_freq ;
|
||||
|
||||
/*
|
||||
* Call the SystemInit code from CMSIS interface if available.
|
||||
* SystemInit is a week function which can be override
|
||||
* by an external function.
|
||||
*/
|
||||
m_freq = SystemInit();
|
||||
|
||||
/*
|
||||
* Set the "Vector Table Offset Register". From the ARM
|
||||
* documentation, we got the following information:
|
||||
*
|
||||
* Use the Vector Table Offset Register to determine:
|
||||
* - if the vector table is in RAM or code memory
|
||||
* - the vector table offset.
|
||||
*/
|
||||
*((uint32_t*)0xE000ED08) = (uint32_t)&_stext;
|
||||
|
||||
/*
|
||||
* Copy the initialized data of the ".data" segment
|
||||
* from the flash to the are in the ram.
|
||||
*/
|
||||
pSrc = &_etext;
|
||||
pDest = &_sdata;
|
||||
while(pDest < &_edata)
|
||||
{
|
||||
*pDest++ = *pSrc++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear the ".bss" segment.
|
||||
*/
|
||||
pDest = &_sbss;
|
||||
while(pDest < &_ebss)
|
||||
{
|
||||
*pDest++ = 0;
|
||||
}
|
||||
Master_frequency = m_freq ;
|
||||
}
|
||||
|
||||
/*
|
||||
* And now the main function can be called.
|
||||
* Scotty, energie...
|
||||
*/
|
||||
main();
|
||||
|
||||
/*
|
||||
* In case there are problems with the
|
||||
* "warp drive", stop here.
|
||||
*/
|
||||
while(1) {};
|
||||
|
||||
} /* ResetHandler */
|
||||
|
||||
/*** EOF ***/
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#define __CRT_C__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: All extern Data */
|
||||
/*=========================================================================*/
|
||||
/*
|
||||
* The next data are defined by the linker script.
|
||||
*/
|
||||
extern unsigned long _stext;
|
||||
extern unsigned long _etext;
|
||||
extern unsigned long _sdata;
|
||||
extern unsigned long _edata;
|
||||
extern unsigned long _sbss;
|
||||
extern unsigned long _ebss;
|
||||
extern unsigned long _estack;
|
||||
|
||||
/* This is the main */
|
||||
extern int main (void);
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: Prototypes */
|
||||
/*=========================================================================*/
|
||||
extern uint32_t SystemInit (void) ; // __attribute__((weak));
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: All code exported */
|
||||
/*=========================================================================*/
|
||||
|
||||
/***************************************************************************/
|
||||
/* SystemInit */
|
||||
/* */
|
||||
/* SystemInit is a function which is provided by the CMSIS interface. */
|
||||
/* If this function is not available, we need a function here to prevent */
|
||||
/* an error of the linker. Therefore this function is declared as weak. */
|
||||
/***************************************************************************/
|
||||
//uint32_t SystemInit (void)
|
||||
//{
|
||||
|
||||
//} /* SystemInit */
|
||||
|
||||
extern uint32_t Master_frequency ;
|
||||
|
||||
/***************************************************************************/
|
||||
/* ResetHandler */
|
||||
/* */
|
||||
/* This function is used for the C runtime initialisation, */
|
||||
/* for handling the .data and .bss segments. */
|
||||
/***************************************************************************/
|
||||
void ResetHandler (void)
|
||||
{
|
||||
{
|
||||
uint32_t *pSrc;
|
||||
uint32_t *pDest;
|
||||
uint32_t m_freq ;
|
||||
|
||||
/*
|
||||
* Call the SystemInit code from CMSIS interface if available.
|
||||
* SystemInit is a week function which can be override
|
||||
* by an external function.
|
||||
*/
|
||||
m_freq = SystemInit();
|
||||
|
||||
/*
|
||||
* Set the "Vector Table Offset Register". From the ARM
|
||||
* documentation, we got the following information:
|
||||
*
|
||||
* Use the Vector Table Offset Register to determine:
|
||||
* - if the vector table is in RAM or code memory
|
||||
* - the vector table offset.
|
||||
*/
|
||||
*((uint32_t*)0xE000ED08) = (uint32_t)&_stext;
|
||||
|
||||
/*
|
||||
* Copy the initialized data of the ".data" segment
|
||||
* from the flash to the are in the ram.
|
||||
*/
|
||||
pSrc = &_etext;
|
||||
pDest = &_sdata;
|
||||
while(pDest < &_edata)
|
||||
{
|
||||
*pDest++ = *pSrc++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear the ".bss" segment.
|
||||
*/
|
||||
pDest = &_sbss;
|
||||
while(pDest < &_ebss)
|
||||
{
|
||||
*pDest++ = 0;
|
||||
}
|
||||
Master_frequency = m_freq ;
|
||||
}
|
||||
|
||||
/*
|
||||
* And now the main function can be called.
|
||||
* Scotty, energie...
|
||||
*/
|
||||
main();
|
||||
|
||||
/*
|
||||
* In case there are problems with the
|
||||
* "warp drive", stop here.
|
||||
*/
|
||||
while(1) {};
|
||||
|
||||
} /* ResetHandler */
|
||||
|
||||
/*** EOF ***/
|
||||
|
||||
+1380
-1380
File diff suppressed because it is too large
Load Diff
@@ -1,200 +1,200 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
volatile uint8_t Spi_complete = 1;
|
||||
uint8_t Spi_tx_buf[24];
|
||||
|
||||
uint8_t eepromIsTransferComplete()
|
||||
{
|
||||
return Spi_complete;
|
||||
}
|
||||
|
||||
uint32_t eepromTransmitData(uint8_t *command, uint8_t *tx, uint8_t *rx, uint32_t comlen, uint32_t count)
|
||||
{
|
||||
Spi * spiptr = SPI;
|
||||
uint32_t condition;
|
||||
static uint8_t discard_rx_command[4];
|
||||
|
||||
if (comlen > 4) {
|
||||
return 0x4FFFF;
|
||||
}
|
||||
|
||||
Spi_complete = 0;
|
||||
condition = SPI_SR_TXEMPTY;
|
||||
spiptr->SPI_CR = 1; // Enable
|
||||
(void) spiptr->SPI_RDR; // Dump any rx data
|
||||
(void) spiptr->SPI_SR; // Clear error flags
|
||||
spiptr->SPI_RPR = (uint32_t)discard_rx_command;
|
||||
spiptr->SPI_RCR = comlen;
|
||||
if (rx) {
|
||||
spiptr->SPI_RNPR = (uint32_t)rx;
|
||||
spiptr->SPI_RNCR = count;
|
||||
condition = SPI_SR_RXBUFF;
|
||||
}
|
||||
spiptr->SPI_TPR = (uint32_t)command;
|
||||
spiptr->SPI_TCR = comlen;
|
||||
if (tx) {
|
||||
spiptr->SPI_TNPR = (uint32_t)tx;
|
||||
}
|
||||
else {
|
||||
spiptr->SPI_TNPR = (uint32_t)rx;
|
||||
}
|
||||
spiptr->SPI_TNCR = count;
|
||||
|
||||
spiptr->SPI_PTCR = SPI_PTCR_RXTEN | SPI_PTCR_TXTEN; // Start transfers
|
||||
|
||||
// Wait for things to get started, avoids early interrupt
|
||||
for (count = 0; count < 1000; count += 1) {
|
||||
if ((spiptr->SPI_SR & SPI_SR_TXEMPTY) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
spiptr->SPI_IER = condition;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t eepromTransmitByte(uint8_t out, bool skipFirst)
|
||||
{
|
||||
Spi * spiptr = SPI;
|
||||
uint32_t delay;
|
||||
|
||||
spiptr->SPI_CR = 1; // Enable
|
||||
(void) spiptr->SPI_RDR; // Dump any rx data
|
||||
|
||||
spiptr->SPI_TDR = out;
|
||||
|
||||
delay = 0;
|
||||
while ((spiptr->SPI_SR & SPI_SR_RDRF) == 0) {
|
||||
// wait for received
|
||||
if (++delay > 10000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (skipFirst) {
|
||||
(void) spiptr->SPI_RDR; // Dump the rx data
|
||||
spiptr->SPI_TDR = 0;
|
||||
delay = 0;
|
||||
while ((spiptr->SPI_SR & SPI_SR_RDRF) == 0) {
|
||||
// wait for received
|
||||
if (++delay > 10000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
spiptr->SPI_CR = 2; // Disable
|
||||
return spiptr->SPI_RDR;
|
||||
}
|
||||
|
||||
enum EepromCommand {
|
||||
COMMAND_WRITE_STATUS_REGISTER = 0x01,
|
||||
COMMAND_BYTE_PROGRAM = 0x02,
|
||||
COMMAND_READ_ARRAY = 0x03,
|
||||
COMMAND_READ_STATUS = 0x05,
|
||||
COMMAND_WRITE_ENABLE = 0x06,
|
||||
COMMAND_BLOCK_ERASE = 0x20,
|
||||
};
|
||||
|
||||
void eepromPrepareCommand(EepromCommand command, uint32_t address)
|
||||
{
|
||||
uint8_t * p = Spi_tx_buf;
|
||||
*p = command;
|
||||
*(p+1) = address >> 16;
|
||||
*(p+2) = address >> 8;
|
||||
*(p+3) = address;
|
||||
}
|
||||
|
||||
uint8_t eepromReadStatus()
|
||||
{
|
||||
uint8_t read_status = eepromTransmitByte(COMMAND_READ_STATUS, true);
|
||||
return !(read_status & 1);
|
||||
}
|
||||
|
||||
void eepromWriteStatusRegister()
|
||||
{
|
||||
eepromTransmitByte(COMMAND_WRITE_STATUS_REGISTER, true);
|
||||
}
|
||||
|
||||
void eepromWriteEnable()
|
||||
{
|
||||
eepromTransmitByte(COMMAND_WRITE_ENABLE, false);
|
||||
}
|
||||
|
||||
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
eepromWriteEnable();
|
||||
eepromPrepareCommand(COMMAND_BYTE_PROGRAM, address);
|
||||
eepromTransmitData(Spi_tx_buf, buffer, 0, 4, size);
|
||||
}
|
||||
|
||||
void eepromStartRead(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
eepromPrepareCommand(COMMAND_READ_ARRAY, address);
|
||||
eepromTransmitData(Spi_tx_buf, 0, buffer, 4, size);
|
||||
}
|
||||
|
||||
void eepromBlockErase(uint32_t address)
|
||||
{
|
||||
eepromWriteEnable();
|
||||
eepromPrepareCommand(COMMAND_BLOCK_ERASE, address);
|
||||
eepromTransmitData(Spi_tx_buf, 0, 0, 4, 0);
|
||||
}
|
||||
|
||||
// SPI i/f to EEPROM (4Mb)
|
||||
// Peripheral ID 21 (0x00200000)
|
||||
// Connections:
|
||||
// SS PA11 (peripheral A)
|
||||
// MISO PA12 (peripheral A)
|
||||
// MOSI PA13 (peripheral A)
|
||||
// SCK PA14 (peripheral A)
|
||||
// Set clock to 3 MHz, AT25 device is rated to 70MHz, 18MHz would be better
|
||||
void eepromInit()
|
||||
{
|
||||
Spi * spiptr = SPI;
|
||||
uint32_t timer;
|
||||
|
||||
PMC->PMC_PCER0 |= 0x00200000L; // Enable peripheral clock to SPI
|
||||
/* Configure PIO */
|
||||
configure_pins(0x00007800, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA | PIN_NO_PULLUP);
|
||||
|
||||
timer = (Master_frequency / 3000000) << 8; // Baud rate 3Mb/s
|
||||
spiptr->SPI_MR = 0x14000011; // 0001 0100 0000 0000 0000 0000 0001 0001 Master
|
||||
spiptr->SPI_CSR[0] = 0x01180009 | timer; // 0000 0001 0001 1000 xxxx xxxx 0000 1001
|
||||
NVIC_EnableIRQ(SPI_IRQn);
|
||||
|
||||
eepromWriteEnable();
|
||||
eepromWriteStatusRegister();
|
||||
}
|
||||
|
||||
extern "C" void SPI_IRQHandler()
|
||||
{
|
||||
Spi * spiptr = SPI;
|
||||
SPI->SPI_IDR = 0x07FF; // All interrupts off
|
||||
spiptr->SPI_CR = 2; // Disable
|
||||
(void) spiptr->SPI_RDR; // Dump any rx data
|
||||
(void) spiptr->SPI_SR; // Clear error flags
|
||||
spiptr->SPI_PTCR = SPI_PTCR_RXTDIS | SPI_PTCR_TXTDIS; // Stop tramsfers
|
||||
Spi_complete = 1; // Indicate completion
|
||||
}
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
volatile uint8_t Spi_complete = 1;
|
||||
uint8_t Spi_tx_buf[24];
|
||||
|
||||
uint8_t eepromIsTransferComplete()
|
||||
{
|
||||
return Spi_complete;
|
||||
}
|
||||
|
||||
uint32_t eepromTransmitData(uint8_t *command, uint8_t *tx, uint8_t *rx, uint32_t comlen, uint32_t count)
|
||||
{
|
||||
Spi * spiptr = SPI;
|
||||
uint32_t condition;
|
||||
static uint8_t discard_rx_command[4];
|
||||
|
||||
if (comlen > 4) {
|
||||
return 0x4FFFF;
|
||||
}
|
||||
|
||||
Spi_complete = 0;
|
||||
condition = SPI_SR_TXEMPTY;
|
||||
spiptr->SPI_CR = 1; // Enable
|
||||
(void) spiptr->SPI_RDR; // Dump any rx data
|
||||
(void) spiptr->SPI_SR; // Clear error flags
|
||||
spiptr->SPI_RPR = (uint32_t)discard_rx_command;
|
||||
spiptr->SPI_RCR = comlen;
|
||||
if (rx) {
|
||||
spiptr->SPI_RNPR = (uint32_t)rx;
|
||||
spiptr->SPI_RNCR = count;
|
||||
condition = SPI_SR_RXBUFF;
|
||||
}
|
||||
spiptr->SPI_TPR = (uint32_t)command;
|
||||
spiptr->SPI_TCR = comlen;
|
||||
if (tx) {
|
||||
spiptr->SPI_TNPR = (uint32_t)tx;
|
||||
}
|
||||
else {
|
||||
spiptr->SPI_TNPR = (uint32_t)rx;
|
||||
}
|
||||
spiptr->SPI_TNCR = count;
|
||||
|
||||
spiptr->SPI_PTCR = SPI_PTCR_RXTEN | SPI_PTCR_TXTEN; // Start transfers
|
||||
|
||||
// Wait for things to get started, avoids early interrupt
|
||||
for (count = 0; count < 1000; count += 1) {
|
||||
if ((spiptr->SPI_SR & SPI_SR_TXEMPTY) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
spiptr->SPI_IER = condition;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t eepromTransmitByte(uint8_t out, bool skipFirst)
|
||||
{
|
||||
Spi * spiptr = SPI;
|
||||
uint32_t delay;
|
||||
|
||||
spiptr->SPI_CR = 1; // Enable
|
||||
(void) spiptr->SPI_RDR; // Dump any rx data
|
||||
|
||||
spiptr->SPI_TDR = out;
|
||||
|
||||
delay = 0;
|
||||
while ((spiptr->SPI_SR & SPI_SR_RDRF) == 0) {
|
||||
// wait for received
|
||||
if (++delay > 10000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (skipFirst) {
|
||||
(void) spiptr->SPI_RDR; // Dump the rx data
|
||||
spiptr->SPI_TDR = 0;
|
||||
delay = 0;
|
||||
while ((spiptr->SPI_SR & SPI_SR_RDRF) == 0) {
|
||||
// wait for received
|
||||
if (++delay > 10000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
spiptr->SPI_CR = 2; // Disable
|
||||
return spiptr->SPI_RDR;
|
||||
}
|
||||
|
||||
enum EepromCommand {
|
||||
COMMAND_WRITE_STATUS_REGISTER = 0x01,
|
||||
COMMAND_BYTE_PROGRAM = 0x02,
|
||||
COMMAND_READ_ARRAY = 0x03,
|
||||
COMMAND_READ_STATUS = 0x05,
|
||||
COMMAND_WRITE_ENABLE = 0x06,
|
||||
COMMAND_BLOCK_ERASE = 0x20,
|
||||
};
|
||||
|
||||
void eepromPrepareCommand(EepromCommand command, uint32_t address)
|
||||
{
|
||||
uint8_t * p = Spi_tx_buf;
|
||||
*p = command;
|
||||
*(p+1) = address >> 16;
|
||||
*(p+2) = address >> 8;
|
||||
*(p+3) = address;
|
||||
}
|
||||
|
||||
uint8_t eepromReadStatus()
|
||||
{
|
||||
uint8_t read_status = eepromTransmitByte(COMMAND_READ_STATUS, true);
|
||||
return !(read_status & 1);
|
||||
}
|
||||
|
||||
void eepromWriteStatusRegister()
|
||||
{
|
||||
eepromTransmitByte(COMMAND_WRITE_STATUS_REGISTER, true);
|
||||
}
|
||||
|
||||
void eepromWriteEnable()
|
||||
{
|
||||
eepromTransmitByte(COMMAND_WRITE_ENABLE, false);
|
||||
}
|
||||
|
||||
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
eepromWriteEnable();
|
||||
eepromPrepareCommand(COMMAND_BYTE_PROGRAM, address);
|
||||
eepromTransmitData(Spi_tx_buf, buffer, 0, 4, size);
|
||||
}
|
||||
|
||||
void eepromStartRead(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
eepromPrepareCommand(COMMAND_READ_ARRAY, address);
|
||||
eepromTransmitData(Spi_tx_buf, 0, buffer, 4, size);
|
||||
}
|
||||
|
||||
void eepromBlockErase(uint32_t address)
|
||||
{
|
||||
eepromWriteEnable();
|
||||
eepromPrepareCommand(COMMAND_BLOCK_ERASE, address);
|
||||
eepromTransmitData(Spi_tx_buf, 0, 0, 4, 0);
|
||||
}
|
||||
|
||||
// SPI i/f to EEPROM (4Mb)
|
||||
// Peripheral ID 21 (0x00200000)
|
||||
// Connections:
|
||||
// SS PA11 (peripheral A)
|
||||
// MISO PA12 (peripheral A)
|
||||
// MOSI PA13 (peripheral A)
|
||||
// SCK PA14 (peripheral A)
|
||||
// Set clock to 3 MHz, AT25 device is rated to 70MHz, 18MHz would be better
|
||||
void eepromInit()
|
||||
{
|
||||
Spi * spiptr = SPI;
|
||||
uint32_t timer;
|
||||
|
||||
PMC->PMC_PCER0 |= 0x00200000L; // Enable peripheral clock to SPI
|
||||
/* Configure PIO */
|
||||
configure_pins(0x00007800, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA | PIN_NO_PULLUP);
|
||||
|
||||
timer = (Master_frequency / 3000000) << 8; // Baud rate 3Mb/s
|
||||
spiptr->SPI_MR = 0x14000011; // 0001 0100 0000 0000 0000 0000 0001 0001 Master
|
||||
spiptr->SPI_CSR[0] = 0x01180009 | timer; // 0000 0001 0001 1000 xxxx xxxx 0000 1001
|
||||
NVIC_EnableIRQ(SPI_IRQn);
|
||||
|
||||
eepromWriteEnable();
|
||||
eepromWriteStatusRegister();
|
||||
}
|
||||
|
||||
extern "C" void SPI_IRQHandler()
|
||||
{
|
||||
Spi * spiptr = SPI;
|
||||
SPI->SPI_IDR = 0x07FF; // All interrupts off
|
||||
spiptr->SPI_CR = 2; // Disable
|
||||
(void) spiptr->SPI_RDR; // Dump any rx data
|
||||
(void) spiptr->SPI_SR; // Clear error flags
|
||||
spiptr->SPI_PTCR = SPI_PTCR_RXTDIS | SPI_PTCR_TXTDIS; // Stop tramsfers
|
||||
Spi_complete = 1; // Indicate completion
|
||||
}
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
void hapticOff()
|
||||
{
|
||||
PWM->PWM_DIS = PWM_DIS_CHID2 ; // Disable channel 2
|
||||
PWM->PWM_OOV &= ~0x00040000 ; // Force low
|
||||
PWM->PWM_OSS |= 0x00040000 ; // Force low
|
||||
}
|
||||
|
||||
// pwmPercent 0-100
|
||||
void hapticOn( uint32_t pwmPercent )
|
||||
{
|
||||
Pwm *pwmptr ;
|
||||
|
||||
pwmptr = PWM ;
|
||||
|
||||
if (pwmPercent > 100) {
|
||||
pwmPercent = 100 ;
|
||||
}
|
||||
|
||||
pwmptr->PWM_CH_NUM[2].PWM_CDTYUPD = pwmPercent ; // Duty
|
||||
pwmptr->PWM_ENA = PWM_ENA_CHID2 ; // Enable channel 2
|
||||
pwmptr->PWM_OSC = 0x00040000 ; // Enable output
|
||||
}
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
void hapticOff()
|
||||
{
|
||||
PWM->PWM_DIS = PWM_DIS_CHID2 ; // Disable channel 2
|
||||
PWM->PWM_OOV &= ~0x00040000 ; // Force low
|
||||
PWM->PWM_OSS |= 0x00040000 ; // Force low
|
||||
}
|
||||
|
||||
// pwmPercent 0-100
|
||||
void hapticOn( uint32_t pwmPercent )
|
||||
{
|
||||
Pwm *pwmptr ;
|
||||
|
||||
pwmptr = PWM ;
|
||||
|
||||
if (pwmPercent > 100) {
|
||||
pwmPercent = 100 ;
|
||||
}
|
||||
|
||||
pwmptr->PWM_CH_NUM[2].PWM_CDTYUPD = pwmPercent ; // Duty
|
||||
pwmptr->PWM_ENA = PWM_ENA_CHID2 ; // Enable channel 2
|
||||
pwmptr->PWM_OSC = 0x00040000 ; // Enable output
|
||||
}
|
||||
|
||||
@@ -1,197 +1,197 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
|
||||
// keys:
|
||||
// KEY_EXIT PA31 (PC24)
|
||||
// KEY_MENU PB6 (PB5)
|
||||
// KEY_DOWN LCD5 PC3 (PC5)
|
||||
// KEY_UP LCD6 PC2 (PC1)
|
||||
// KEY_RIGHT LCD4 PC4 (PC4)
|
||||
// KEY_LEFT LCD3 PC5 (PC3)
|
||||
// Reqd. bit 6 LEFT, 5 RIGHT, 4 UP, 3 DOWN 2 EXIT 1 MENU
|
||||
// LCD pins 5 DOWN, 4 RIGHT, 3 LEFT, 1 UP
|
||||
uint32_t readKeys()
|
||||
{
|
||||
uint32_t x;
|
||||
uint32_t result = 0;
|
||||
|
||||
x = lcdLock ? lcdInputs : PIOC->PIO_PDSR; // 6 LEFT, 5 RIGHT, 4 DOWN, 3 UP ()
|
||||
x = ~x;
|
||||
|
||||
#if defined(REVA)
|
||||
if (x & KEYS_GPIO_PIN_RIGHT)
|
||||
result |= 0x02 << KEY_RIGHT;
|
||||
if (x & KEYS_GPIO_PIN_LEFT)
|
||||
result |= 0x02 << KEY_LEFT;
|
||||
if (x & KEYS_GPIO_PIN_UP)
|
||||
result |= 0x02 << KEY_UP;
|
||||
if (x & KEYS_GPIO_PIN_DOWN)
|
||||
result |= 0x02 << KEY_DOWN;
|
||||
if (~KEYS_GPIO_REG_EXIT & KEYS_GPIO_PIN_EXIT)
|
||||
result |= 0x02 << KEY_EXIT;
|
||||
if (~KEYS_GPIO_REG_MENU & KEYS_GPIO_PIN_MENU)
|
||||
result |= 0x02 << KEY_MENU;
|
||||
#else
|
||||
if (x & KEYS_GPIO_PIN_RIGHT)
|
||||
result |= 0x02 << KEY_RIGHT;
|
||||
if (x & KEYS_GPIO_PIN_UP)
|
||||
result |= 0x02 << KEY_UP;
|
||||
if (x & KEYS_GPIO_PIN_LEFT)
|
||||
result |= 0x02 << KEY_LEFT;
|
||||
if (x & KEYS_GPIO_PIN_DOWN)
|
||||
result |= 0x02 << KEY_DOWN;
|
||||
if (x & KEYS_GPIO_PIN_EXIT)
|
||||
result |= 0x02 << KEY_EXIT;
|
||||
if (~KEYS_GPIO_REG_MENU & KEYS_GPIO_PIN_MENU)
|
||||
result |= 0x02 << KEY_MENU;
|
||||
#endif
|
||||
|
||||
// TRACE("readKeys(): %x => %x", x, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t readTrims()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
if (~TRIMS_GPIO_REG_LHL & TRIMS_GPIO_PIN_LHL)
|
||||
result |= 0x01;
|
||||
if (~TRIMS_GPIO_REG_LVD & TRIMS_GPIO_PIN_LVD)
|
||||
result |= 0x04;
|
||||
if (~TRIMS_GPIO_REG_RVU & TRIMS_GPIO_PIN_RVU)
|
||||
result |= 0x20;
|
||||
if (~TRIMS_GPIO_REG_RHL & TRIMS_GPIO_PIN_RHL)
|
||||
result |= 0x40;
|
||||
if (~TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR)
|
||||
result |= 0x02;
|
||||
if (~TRIMS_GPIO_REG_LVU & TRIMS_GPIO_PIN_LVU)
|
||||
result |= 0x08;
|
||||
if (~TRIMS_GPIO_REG_RVD & TRIMS_GPIO_PIN_RVD)
|
||||
result |= 0x10;
|
||||
if (~TRIMS_GPIO_REG_RHR & TRIMS_GPIO_PIN_RHR)
|
||||
result |= 0x80;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t trimDown(uint8_t idx)
|
||||
{
|
||||
return readTrims() & (1 << idx);
|
||||
}
|
||||
|
||||
uint8_t keyDown()
|
||||
{
|
||||
return readKeys() || REA_DOWN();
|
||||
}
|
||||
|
||||
void readKeysAndTrims()
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
#if ROTARY_ENCODERS > 0
|
||||
keys[BTN_REa].input(REA_DOWN());
|
||||
#endif
|
||||
|
||||
uint8_t index = KEY_MENU;
|
||||
uint8_t in = readKeys();
|
||||
for (i = 1; i < 7; i++) {
|
||||
keys[index].input(in & (1 << i));
|
||||
++index;
|
||||
}
|
||||
|
||||
in = readTrims();
|
||||
|
||||
for (i = 1; i < 256; i <<= 1) {
|
||||
keys[index].input(in & i);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t keyState(uint8_t index)
|
||||
{
|
||||
return keys[index].state();
|
||||
}
|
||||
|
||||
uint32_t switchState(uint8_t index)
|
||||
{
|
||||
uint32_t a = PIOA->PIO_PDSR;
|
||||
uint32_t c = PIOC->PIO_PDSR;
|
||||
|
||||
uint32_t xxx = 0;
|
||||
|
||||
switch (index) {
|
||||
#if defined(REVA)
|
||||
case SW_ELE:
|
||||
xxx = a & 0x00000100; // ELE_DR PA8
|
||||
#else
|
||||
case SW_ELE:
|
||||
xxx = c & 0x80000000; // ELE_DR PC31
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SW_AIL:
|
||||
xxx = a & 0x00000004; // AIL-DR PA2
|
||||
break;
|
||||
|
||||
case SW_RUD:
|
||||
xxx = a & 0x00008000; // RUN_DR PA15
|
||||
break;
|
||||
// INP_G_ID1 INP_E_ID2
|
||||
// id0 0 1
|
||||
// id1 1 1
|
||||
// id2 1 0
|
||||
case SW_ID0:
|
||||
xxx = ~c & 0x00004000; // SW_IDL1 PC14
|
||||
break;
|
||||
case SW_ID1:
|
||||
xxx = (c & 0x00004000);
|
||||
if (xxx) xxx = (c & 0x00000800);
|
||||
break;
|
||||
case SW_ID2:
|
||||
xxx = ~c & 0x00000800; // SW_IDL2 PC11
|
||||
break;
|
||||
|
||||
case SW_GEA:
|
||||
xxx = c & 0x00010000; // SW_GEAR PC16
|
||||
break;
|
||||
|
||||
#if defined(REVA)
|
||||
case SW_THR:
|
||||
xxx = a & 0x10000000; // SW_TCUT PA28
|
||||
#else
|
||||
case SW_THR:
|
||||
xxx = c & 0x00100000; // SW_TCUT PC20
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SW_TRN:
|
||||
xxx = c & 0x00000100; // SW-TRAIN PC8
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return xxx;
|
||||
}
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
|
||||
// keys:
|
||||
// KEY_EXIT PA31 (PC24)
|
||||
// KEY_MENU PB6 (PB5)
|
||||
// KEY_DOWN LCD5 PC3 (PC5)
|
||||
// KEY_UP LCD6 PC2 (PC1)
|
||||
// KEY_RIGHT LCD4 PC4 (PC4)
|
||||
// KEY_LEFT LCD3 PC5 (PC3)
|
||||
// Reqd. bit 6 LEFT, 5 RIGHT, 4 UP, 3 DOWN 2 EXIT 1 MENU
|
||||
// LCD pins 5 DOWN, 4 RIGHT, 3 LEFT, 1 UP
|
||||
uint32_t readKeys()
|
||||
{
|
||||
uint32_t x;
|
||||
uint32_t result = 0;
|
||||
|
||||
x = lcdLock ? lcdInputs : PIOC->PIO_PDSR; // 6 LEFT, 5 RIGHT, 4 DOWN, 3 UP ()
|
||||
x = ~x;
|
||||
|
||||
#if defined(REVA)
|
||||
if (x & KEYS_GPIO_PIN_RIGHT)
|
||||
result |= 0x02 << KEY_RIGHT;
|
||||
if (x & KEYS_GPIO_PIN_LEFT)
|
||||
result |= 0x02 << KEY_LEFT;
|
||||
if (x & KEYS_GPIO_PIN_UP)
|
||||
result |= 0x02 << KEY_UP;
|
||||
if (x & KEYS_GPIO_PIN_DOWN)
|
||||
result |= 0x02 << KEY_DOWN;
|
||||
if (~KEYS_GPIO_REG_EXIT & KEYS_GPIO_PIN_EXIT)
|
||||
result |= 0x02 << KEY_EXIT;
|
||||
if (~KEYS_GPIO_REG_MENU & KEYS_GPIO_PIN_MENU)
|
||||
result |= 0x02 << KEY_MENU;
|
||||
#else
|
||||
if (x & KEYS_GPIO_PIN_RIGHT)
|
||||
result |= 0x02 << KEY_RIGHT;
|
||||
if (x & KEYS_GPIO_PIN_UP)
|
||||
result |= 0x02 << KEY_UP;
|
||||
if (x & KEYS_GPIO_PIN_LEFT)
|
||||
result |= 0x02 << KEY_LEFT;
|
||||
if (x & KEYS_GPIO_PIN_DOWN)
|
||||
result |= 0x02 << KEY_DOWN;
|
||||
if (x & KEYS_GPIO_PIN_EXIT)
|
||||
result |= 0x02 << KEY_EXIT;
|
||||
if (~KEYS_GPIO_REG_MENU & KEYS_GPIO_PIN_MENU)
|
||||
result |= 0x02 << KEY_MENU;
|
||||
#endif
|
||||
|
||||
// TRACE("readKeys(): %x => %x", x, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t readTrims()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
if (~TRIMS_GPIO_REG_LHL & TRIMS_GPIO_PIN_LHL)
|
||||
result |= 0x01;
|
||||
if (~TRIMS_GPIO_REG_LVD & TRIMS_GPIO_PIN_LVD)
|
||||
result |= 0x04;
|
||||
if (~TRIMS_GPIO_REG_RVU & TRIMS_GPIO_PIN_RVU)
|
||||
result |= 0x20;
|
||||
if (~TRIMS_GPIO_REG_RHL & TRIMS_GPIO_PIN_RHL)
|
||||
result |= 0x40;
|
||||
if (~TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR)
|
||||
result |= 0x02;
|
||||
if (~TRIMS_GPIO_REG_LVU & TRIMS_GPIO_PIN_LVU)
|
||||
result |= 0x08;
|
||||
if (~TRIMS_GPIO_REG_RVD & TRIMS_GPIO_PIN_RVD)
|
||||
result |= 0x10;
|
||||
if (~TRIMS_GPIO_REG_RHR & TRIMS_GPIO_PIN_RHR)
|
||||
result |= 0x80;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t trimDown(uint8_t idx)
|
||||
{
|
||||
return readTrims() & (1 << idx);
|
||||
}
|
||||
|
||||
uint8_t keyDown()
|
||||
{
|
||||
return readKeys() || REA_DOWN();
|
||||
}
|
||||
|
||||
void readKeysAndTrims()
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
#if ROTARY_ENCODERS > 0
|
||||
keys[BTN_REa].input(REA_DOWN());
|
||||
#endif
|
||||
|
||||
uint8_t index = KEY_MENU;
|
||||
uint8_t in = readKeys();
|
||||
for (i = 1; i < 7; i++) {
|
||||
keys[index].input(in & (1 << i));
|
||||
++index;
|
||||
}
|
||||
|
||||
in = readTrims();
|
||||
|
||||
for (i = 1; i < 256; i <<= 1) {
|
||||
keys[index].input(in & i);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t keyState(uint8_t index)
|
||||
{
|
||||
return keys[index].state();
|
||||
}
|
||||
|
||||
uint32_t switchState(uint8_t index)
|
||||
{
|
||||
uint32_t a = PIOA->PIO_PDSR;
|
||||
uint32_t c = PIOC->PIO_PDSR;
|
||||
|
||||
uint32_t xxx = 0;
|
||||
|
||||
switch (index) {
|
||||
#if defined(REVA)
|
||||
case SW_ELE:
|
||||
xxx = a & 0x00000100; // ELE_DR PA8
|
||||
#else
|
||||
case SW_ELE:
|
||||
xxx = c & 0x80000000; // ELE_DR PC31
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SW_AIL:
|
||||
xxx = a & 0x00000004; // AIL-DR PA2
|
||||
break;
|
||||
|
||||
case SW_RUD:
|
||||
xxx = a & 0x00008000; // RUN_DR PA15
|
||||
break;
|
||||
// INP_G_ID1 INP_E_ID2
|
||||
// id0 0 1
|
||||
// id1 1 1
|
||||
// id2 1 0
|
||||
case SW_ID0:
|
||||
xxx = ~c & 0x00004000; // SW_IDL1 PC14
|
||||
break;
|
||||
case SW_ID1:
|
||||
xxx = (c & 0x00004000);
|
||||
if (xxx) xxx = (c & 0x00000800);
|
||||
break;
|
||||
case SW_ID2:
|
||||
xxx = ~c & 0x00000800; // SW_IDL2 PC11
|
||||
break;
|
||||
|
||||
case SW_GEA:
|
||||
xxx = c & 0x00010000; // SW_GEAR PC16
|
||||
break;
|
||||
|
||||
#if defined(REVA)
|
||||
case SW_THR:
|
||||
xxx = a & 0x10000000; // SW_TCUT PA28
|
||||
#else
|
||||
case SW_THR:
|
||||
xxx = c & 0x00100000; // SW_TCUT PC20
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SW_TRN:
|
||||
xxx = c & 0x00000100; // SW-TRAIN PC8
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return xxx;
|
||||
}
|
||||
|
||||
@@ -1,208 +1,208 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#ifndef SIMU
|
||||
|
||||
extern "C" {
|
||||
#include "usb/device/massstorage/MSDDriver.h"
|
||||
extern unsigned char MEDSdcard_Initialize(Media *media, unsigned char mciID);
|
||||
}
|
||||
|
||||
/** LUN read/write buffer. */
|
||||
unsigned char msdBuffer[MSD_BUFFER_SIZE];
|
||||
|
||||
unsigned int msdReadTotal=0, msdWriteTotal=0;
|
||||
|
||||
static void ConfigureUsbClock(void)
|
||||
{
|
||||
/* Enable PLLB for USB */
|
||||
PMC->CKGR_PLLBR = CKGR_PLLBR_DIVB(1)
|
||||
| CKGR_PLLBR_MULB(7)
|
||||
| CKGR_PLLBR_PLLBCOUNT_Msk;
|
||||
while((PMC->PMC_SR & PMC_SR_LOCKB) == 0); // TODO && (timeout++ < CLOCK_TIMEOUT));
|
||||
/* USB Clock uses PLLB */
|
||||
PMC->PMC_USB = PMC_USB_USBDIV(1) /* /2 */
|
||||
| PMC_USB_USBS; /* PLLB */
|
||||
}
|
||||
|
||||
/** Maximum number of LUNs which can be defined. */
|
||||
#define MAX_LUNS 1
|
||||
|
||||
/** Media index for different disks */
|
||||
#define DRV_SDMMC 0 /** SD card */
|
||||
|
||||
Media medias[MAX_LUNS];
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Local variables
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
/** Device LUNs. */
|
||||
MSDLun luns[MAX_LUNS];
|
||||
|
||||
int itoa(int val, char* buf)
|
||||
{
|
||||
const unsigned int radix = 10;
|
||||
|
||||
char* p;
|
||||
unsigned int a; //every digit
|
||||
int len;
|
||||
char* b; //start of the digit char
|
||||
char temp;
|
||||
unsigned int u;
|
||||
|
||||
p = buf;
|
||||
|
||||
#if 0
|
||||
if (val < 0)
|
||||
{
|
||||
*p++ = '-';
|
||||
val = 0 - val;
|
||||
}
|
||||
#endif
|
||||
|
||||
u = (unsigned int)val;
|
||||
|
||||
b = p;
|
||||
|
||||
do
|
||||
{
|
||||
a = u % radix;
|
||||
u /= radix;
|
||||
|
||||
*p++ = a + '0';
|
||||
|
||||
} while (u > 0);
|
||||
|
||||
len = (int)(p - buf);
|
||||
|
||||
*p-- = 0;
|
||||
|
||||
//swap
|
||||
do
|
||||
{
|
||||
temp = *p;
|
||||
*p = *b;
|
||||
*b = temp;
|
||||
--p;
|
||||
++b;
|
||||
|
||||
} while (b < p);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
uint8_t write_bytes(char *str, uint32_t bytes)
|
||||
{
|
||||
uint8_t len;
|
||||
if (bytes < 1024*100) {
|
||||
len = itoa(bytes / 1024, str);
|
||||
str[len] = '.';
|
||||
str[len+1] = '0' + ((bytes % 1024) / 103);
|
||||
str[len+2] = 'K';
|
||||
str[len+3] = '\0';
|
||||
len += 3;
|
||||
}
|
||||
else if (bytes < 1024*1024) {
|
||||
len = itoa(bytes / 1024, str);
|
||||
str[len] = 'K';
|
||||
str[len+1] = '\0';
|
||||
len += 1;
|
||||
}
|
||||
else if (bytes < 1024*1024*100) {
|
||||
len = itoa(bytes / (1024*1024), str);
|
||||
str[len] = '.';
|
||||
str[len+1] = '0' + ((bytes % (1024*1024)) / 104858);
|
||||
str[len+2] = 'M';
|
||||
str[len+3] = '\0';
|
||||
len += 3;
|
||||
}
|
||||
else {
|
||||
len = itoa(bytes / (1024*1024), str);
|
||||
str[len] = 'M';
|
||||
str[len+1] = '\0';
|
||||
len += 1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static void MSDCallbacks_Data( unsigned char flowDirection, unsigned int dataLength,
|
||||
unsigned int fifoNullCount, unsigned int fifoFullCount )
|
||||
{
|
||||
if (flowDirection)
|
||||
msdReadTotal += dataLength;
|
||||
else
|
||||
msdWriteTotal += dataLength;
|
||||
|
||||
strcpy(statusLineMsg, "USB Rd:");
|
||||
uint8_t len = write_bytes(statusLineMsg+7, msdReadTotal);
|
||||
strcpy(statusLineMsg+7+len, " Wr:");
|
||||
write_bytes(statusLineMsg+7+len+4, msdWriteTotal);
|
||||
showStatusLine();
|
||||
}
|
||||
|
||||
void usbMassStorage()
|
||||
{
|
||||
static bool initialized = false;
|
||||
|
||||
if (usbPlugged() && sd_card_ready()) {
|
||||
TRACE_DEBUG("usbMassStorage\n\r");
|
||||
|
||||
if (sdMounted()) {
|
||||
Card_state = SD_ST_DATA;
|
||||
audioQueue.stopSD();
|
||||
logsClose();
|
||||
f_mount(NULL, "", 0); // unmount SD
|
||||
}
|
||||
|
||||
if (!initialized) {
|
||||
|
||||
ConfigureUsbClock();
|
||||
|
||||
/* Initialize LUN */
|
||||
MEDSdcard_Initialize(&(medias[DRV_SDMMC]), 0);
|
||||
|
||||
LUN_Init(&(luns[DRV_SDMMC]), &(medias[DRV_SDMMC]),
|
||||
msdBuffer, MSD_BUFFER_SIZE,
|
||||
0, 0, 0, 0,
|
||||
MSDCallbacks_Data);
|
||||
|
||||
/* BOT driver initialization */
|
||||
MSDDriver_Initialize(luns, 1);
|
||||
|
||||
// VBus_Configure();
|
||||
USBD_Connect();
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
/* Mass storage state machine */
|
||||
for (uint8_t i=0; i<50; i++)
|
||||
MSDDriver_StateMachine();
|
||||
}
|
||||
else {
|
||||
msdReadTotal = 0;
|
||||
msdWriteTotal = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#ifndef SIMU
|
||||
|
||||
extern "C" {
|
||||
#include "usb/device/massstorage/MSDDriver.h"
|
||||
extern unsigned char MEDSdcard_Initialize(Media *media, unsigned char mciID);
|
||||
}
|
||||
|
||||
/** LUN read/write buffer. */
|
||||
unsigned char msdBuffer[MSD_BUFFER_SIZE];
|
||||
|
||||
unsigned int msdReadTotal=0, msdWriteTotal=0;
|
||||
|
||||
static void ConfigureUsbClock(void)
|
||||
{
|
||||
/* Enable PLLB for USB */
|
||||
PMC->CKGR_PLLBR = CKGR_PLLBR_DIVB(1)
|
||||
| CKGR_PLLBR_MULB(7)
|
||||
| CKGR_PLLBR_PLLBCOUNT_Msk;
|
||||
while((PMC->PMC_SR & PMC_SR_LOCKB) == 0); // TODO && (timeout++ < CLOCK_TIMEOUT));
|
||||
/* USB Clock uses PLLB */
|
||||
PMC->PMC_USB = PMC_USB_USBDIV(1) /* /2 */
|
||||
| PMC_USB_USBS; /* PLLB */
|
||||
}
|
||||
|
||||
/** Maximum number of LUNs which can be defined. */
|
||||
#define MAX_LUNS 1
|
||||
|
||||
/** Media index for different disks */
|
||||
#define DRV_SDMMC 0 /** SD card */
|
||||
|
||||
Media medias[MAX_LUNS];
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Local variables
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
/** Device LUNs. */
|
||||
MSDLun luns[MAX_LUNS];
|
||||
|
||||
int itoa(int val, char* buf)
|
||||
{
|
||||
const unsigned int radix = 10;
|
||||
|
||||
char* p;
|
||||
unsigned int a; //every digit
|
||||
int len;
|
||||
char* b; //start of the digit char
|
||||
char temp;
|
||||
unsigned int u;
|
||||
|
||||
p = buf;
|
||||
|
||||
#if 0
|
||||
if (val < 0)
|
||||
{
|
||||
*p++ = '-';
|
||||
val = 0 - val;
|
||||
}
|
||||
#endif
|
||||
|
||||
u = (unsigned int)val;
|
||||
|
||||
b = p;
|
||||
|
||||
do
|
||||
{
|
||||
a = u % radix;
|
||||
u /= radix;
|
||||
|
||||
*p++ = a + '0';
|
||||
|
||||
} while (u > 0);
|
||||
|
||||
len = (int)(p - buf);
|
||||
|
||||
*p-- = 0;
|
||||
|
||||
//swap
|
||||
do
|
||||
{
|
||||
temp = *p;
|
||||
*p = *b;
|
||||
*b = temp;
|
||||
--p;
|
||||
++b;
|
||||
|
||||
} while (b < p);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
uint8_t write_bytes(char *str, uint32_t bytes)
|
||||
{
|
||||
uint8_t len;
|
||||
if (bytes < 1024*100) {
|
||||
len = itoa(bytes / 1024, str);
|
||||
str[len] = '.';
|
||||
str[len+1] = '0' + ((bytes % 1024) / 103);
|
||||
str[len+2] = 'K';
|
||||
str[len+3] = '\0';
|
||||
len += 3;
|
||||
}
|
||||
else if (bytes < 1024*1024) {
|
||||
len = itoa(bytes / 1024, str);
|
||||
str[len] = 'K';
|
||||
str[len+1] = '\0';
|
||||
len += 1;
|
||||
}
|
||||
else if (bytes < 1024*1024*100) {
|
||||
len = itoa(bytes / (1024*1024), str);
|
||||
str[len] = '.';
|
||||
str[len+1] = '0' + ((bytes % (1024*1024)) / 104858);
|
||||
str[len+2] = 'M';
|
||||
str[len+3] = '\0';
|
||||
len += 3;
|
||||
}
|
||||
else {
|
||||
len = itoa(bytes / (1024*1024), str);
|
||||
str[len] = 'M';
|
||||
str[len+1] = '\0';
|
||||
len += 1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static void MSDCallbacks_Data( unsigned char flowDirection, unsigned int dataLength,
|
||||
unsigned int fifoNullCount, unsigned int fifoFullCount )
|
||||
{
|
||||
if (flowDirection)
|
||||
msdReadTotal += dataLength;
|
||||
else
|
||||
msdWriteTotal += dataLength;
|
||||
|
||||
strcpy(statusLineMsg, "USB Rd:");
|
||||
uint8_t len = write_bytes(statusLineMsg+7, msdReadTotal);
|
||||
strcpy(statusLineMsg+7+len, " Wr:");
|
||||
write_bytes(statusLineMsg+7+len+4, msdWriteTotal);
|
||||
showStatusLine();
|
||||
}
|
||||
|
||||
void usbMassStorage()
|
||||
{
|
||||
static bool initialized = false;
|
||||
|
||||
if (usbPlugged() && sd_card_ready()) {
|
||||
TRACE_DEBUG("usbMassStorage\n\r");
|
||||
|
||||
if (sdMounted()) {
|
||||
Card_state = SD_ST_DATA;
|
||||
audioQueue.stopSD();
|
||||
logsClose();
|
||||
f_mount(NULL, "", 0); // unmount SD
|
||||
}
|
||||
|
||||
if (!initialized) {
|
||||
|
||||
ConfigureUsbClock();
|
||||
|
||||
/* Initialize LUN */
|
||||
MEDSdcard_Initialize(&(medias[DRV_SDMMC]), 0);
|
||||
|
||||
LUN_Init(&(luns[DRV_SDMMC]), &(medias[DRV_SDMMC]),
|
||||
msdBuffer, MSD_BUFFER_SIZE,
|
||||
0, 0, 0, 0,
|
||||
MSDCallbacks_Data);
|
||||
|
||||
/* BOT driver initialization */
|
||||
MSDDriver_Initialize(luns, 1);
|
||||
|
||||
// VBus_Configure();
|
||||
USBD_Connect();
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
/* Mass storage state machine */
|
||||
for (uint8_t i=0; i<50; i++)
|
||||
MSDDriver_StateMachine();
|
||||
}
|
||||
else {
|
||||
msdReadTotal = 0;
|
||||
msdWriteTotal = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,367 +1,367 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
void setExternalModulePolarity()
|
||||
{
|
||||
Pwm * pwmptr = PWM;
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CDTYUPD = GET_PPM_DELAY(EXTERNAL_MODULE) * 2; // Duty in half uS
|
||||
if (GET_PPM_POLARITY(EXTERNAL_MODULE))
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CMR &= ~0x00000200; // CPOL
|
||||
else
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CMR |= 0x00000200; // CPOL
|
||||
}
|
||||
|
||||
void setExtraModulePolarity()
|
||||
{
|
||||
Pwm * pwmptr = PWM;
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CDTYUPD = GET_PPM_DELAY(EXTRA_MODULE) * 2; // Duty in half uS
|
||||
if (GET_PPM_POLARITY(EXTRA_MODULE))
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CMR &= ~0x00000200; // CPOL
|
||||
else
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CMR |= 0x00000200; // CPOL
|
||||
}
|
||||
|
||||
void module_output_active()
|
||||
{
|
||||
Pio *pioptr = PIOA;
|
||||
pioptr->PIO_ABCDSR[0] &= ~PIO_PA17; // Peripheral C
|
||||
pioptr->PIO_ABCDSR[1] |= PIO_PA17; // Peripheral C
|
||||
pioptr->PIO_PDR = PIO_PA17; // Disable bit A17 Assign to peripheral
|
||||
#if defined(REVX)
|
||||
if (g_model.moduleData[EXTERNAL_MODULE].ppm.outputType) {
|
||||
pioptr->PIO_MDDR = PIO_PA17; // Push Pull O/p in A17
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
void setExternalModulePolarity()
|
||||
{
|
||||
Pwm * pwmptr = PWM;
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CDTYUPD = GET_PPM_DELAY(EXTERNAL_MODULE) * 2; // Duty in half uS
|
||||
if (GET_PPM_POLARITY(EXTERNAL_MODULE))
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CMR &= ~0x00000200; // CPOL
|
||||
else
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CMR |= 0x00000200; // CPOL
|
||||
}
|
||||
|
||||
void setExtraModulePolarity()
|
||||
{
|
||||
Pwm * pwmptr = PWM;
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CDTYUPD = GET_PPM_DELAY(EXTRA_MODULE) * 2; // Duty in half uS
|
||||
if (GET_PPM_POLARITY(EXTRA_MODULE))
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CMR &= ~0x00000200; // CPOL
|
||||
else
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CMR |= 0x00000200; // CPOL
|
||||
}
|
||||
|
||||
void module_output_active()
|
||||
{
|
||||
Pio *pioptr = PIOA;
|
||||
pioptr->PIO_ABCDSR[0] &= ~PIO_PA17; // Peripheral C
|
||||
pioptr->PIO_ABCDSR[1] |= PIO_PA17; // Peripheral C
|
||||
pioptr->PIO_PDR = PIO_PA17; // Disable bit A17 Assign to peripheral
|
||||
#if defined(REVX)
|
||||
if (g_model.moduleData[EXTERNAL_MODULE].ppm.outputType) {
|
||||
pioptr->PIO_MDDR = PIO_PA17; // Push Pull O/p in A17
|
||||
}
|
||||
else {
|
||||
pioptr->PIO_MDER = PIO_PA17; // Open Drain O/p in A17
|
||||
}
|
||||
#else
|
||||
pioptr->PIO_MDDR = PIO_PA17; // Push Pull O/p in A17
|
||||
#endif
|
||||
pioptr->PIO_PUER = PIO_PA17; // With pull up
|
||||
}
|
||||
|
||||
void init_main_ppm(uint32_t period, uint32_t out_enable)
|
||||
{
|
||||
Pwm * pwmptr;
|
||||
|
||||
setupPulsesPPMModule(EXTERNAL_MODULE);
|
||||
|
||||
if (out_enable) {
|
||||
module_output_active();
|
||||
}
|
||||
|
||||
pwmptr = PWM;
|
||||
// PWM3 for PPM output
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CMR = 0x0004000B; // CLKA
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDR = period; // Period in half uS
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CDTY = GET_PPM_DELAY(EXTERNAL_MODULE) * 2; // Duty in half uS
|
||||
pwmptr->PWM_ENA = PWM_ENA_CHID3; // Enable channel 3
|
||||
pwmptr->PWM_IER1 = PWM_IER1_CHID3;
|
||||
|
||||
setExternalModulePolarity();
|
||||
|
||||
NVIC_SetPriority(PWM_IRQn, 3);
|
||||
NVIC_EnableIRQ(PWM_IRQn);
|
||||
}
|
||||
|
||||
void disable_main_ppm()
|
||||
{
|
||||
Pio * pioptr = PIOA;
|
||||
pioptr->PIO_PER = PIO_PA17; // Assign A17 to PIO
|
||||
PWM->PWM_IDR1 = PWM_IDR1_CHID3;
|
||||
}
|
||||
|
||||
void init_second_ppm(uint32_t period)
|
||||
{
|
||||
#if !defined(REVA)
|
||||
// PWM1 for PPM2
|
||||
Pwm * pwmptr = PWM;
|
||||
configure_pins(PIO_PC15, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_B | PIN_PORTC | PIN_NO_PULLUP);
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CMR = 0x0000000B; // CLKB
|
||||
if (!GET_PPM_POLARITY(EXTRA_MODULE)) {
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CMR |= 0x00000200; // CPOL
|
||||
}
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CPDR = period; // Period
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CPDRUPD = period; // Period
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CDTY = GET_PPM_DELAY(EXTRA_MODULE)*2; // Duty
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CDTYUPD = GET_PPM_DELAY(EXTRA_MODULE)*2; // Duty
|
||||
pwmptr->PWM_ENA = PWM_ENA_CHID1; // Enable channel 1
|
||||
pwmptr->PWM_IER1 = PWM_IER1_CHID1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void disable_second_ppm()
|
||||
{
|
||||
#if !defined(REVA)
|
||||
Pio * pioptr = PIOC;
|
||||
pioptr->PIO_PER = PIO_PC15; // Assign C17 to PIO
|
||||
PWM->PWM_IDR1 = PWM_IDR1_CHID1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void init_no_pulses(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
init_main_ppm(3000, 0);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void disable_no_pulses(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
disable_ppm(EXTERNAL_MODULE);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void init_ppm(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
init_main_ppm(3000, 1);
|
||||
}
|
||||
else {
|
||||
init_second_ppm(3000);
|
||||
}
|
||||
}
|
||||
|
||||
void disable_ppm(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
disable_main_ppm();
|
||||
}
|
||||
else {
|
||||
disable_second_ppm();
|
||||
}
|
||||
}
|
||||
|
||||
// Initialise the SSC to allow PXX output.
|
||||
// TD is on PA17, peripheral A
|
||||
void init_ssc(uint8_t baudrateDiv1000)
|
||||
{
|
||||
Ssc *sscptr;
|
||||
|
||||
PMC->PMC_PCER0 |= 0x00400000L; // Enable peripheral clock to SSC
|
||||
|
||||
configure_pins(PIO_PA17, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA);
|
||||
|
||||
sscptr = SSC;
|
||||
sscptr->SSC_THR = 0xFF; // Make the output high.
|
||||
sscptr->SSC_TFMR = 0x00000027; // 0000 0000 0000 0000 0000 0000 1010 0111 (8 bit data, lsb)
|
||||
sscptr->SSC_CMR = Master_frequency / (1000 * baudrateDiv1000 * 2);
|
||||
sscptr->SSC_TCMR = 0;
|
||||
sscptr->SSC_CR = SSC_CR_TXEN;
|
||||
|
||||
#if defined(REVX)
|
||||
if (IS_MODULE_MULTIMODULE(EXTERNAL_MODULE)) {
|
||||
PIOA->PIO_MDDR = PIO_PA17; // Push Pull O/p in A17
|
||||
} else {
|
||||
PIOA->PIO_MDER = PIO_PA17; // Open Drain O/p in A17
|
||||
}
|
||||
#else
|
||||
PIOA->PIO_MDDR = PIO_PA17; // Push Pull O/p in A17
|
||||
#endif
|
||||
}
|
||||
|
||||
void disable_ssc()
|
||||
{
|
||||
Pio *pioptr;
|
||||
Ssc *sscptr;
|
||||
|
||||
// Revert back to pwm output
|
||||
pioptr = PIOA;
|
||||
pioptr->PIO_PER = PIO_PA17; // Assign A17 to PIO
|
||||
|
||||
sscptr = SSC;
|
||||
sscptr->SSC_CR = SSC_CR_TXDIS;
|
||||
}
|
||||
|
||||
void init_pxx(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
init_main_ppm(2500 * 2, 0);
|
||||
init_ssc(125); // 8us per bit
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void disable_pxx(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
disable_ssc();
|
||||
disable_ppm(EXTERNAL_MODULE);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void init_dsm2(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
init_main_ppm(2500 * 2, 0);
|
||||
init_ssc(125);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void disable_dsm2(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
disable_ssc();
|
||||
disable_ppm(EXTERNAL_MODULE);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
void init_multimodule(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
init_main_ppm(3500 * 2, 0);
|
||||
init_ssc(100);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void disable_multimodule(uint32_t port)
|
||||
{
|
||||
disable_dsm2(port);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(SIMU)
|
||||
extern "C" void PWM_IRQHandler(void)
|
||||
{
|
||||
Pwm * pwmptr = PWM;
|
||||
uint32_t reason = pwmptr->PWM_ISR1;
|
||||
uint32_t period;
|
||||
|
||||
if (reason & PWM_ISR1_CHID3) {
|
||||
// Use the current protocol, don't switch until set_up_pulses
|
||||
switch (s_current_protocol[EXTERNAL_MODULE]) {
|
||||
case PROTO_PXX:
|
||||
// Alternate periods of 6.5mS and 2.5 mS
|
||||
period = pwmptr->PWM_CH_NUM[3].PWM_CPDR;
|
||||
if (period == 2500 * 2) {
|
||||
period = 6500 * 2;
|
||||
}
|
||||
else {
|
||||
period = 2500 * 2;
|
||||
}
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
|
||||
if (period != 2500 * 2) {
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
setExternalModulePolarity();
|
||||
}
|
||||
else {
|
||||
// Kick off serial output here
|
||||
Ssc * sscptr = SSC;
|
||||
sscptr->SSC_TPR = CONVERT_PTR_UINT(modulePulsesData[EXTERNAL_MODULE].pxx.pulses);
|
||||
sscptr->SSC_TCR = (uint8_t *)modulePulsesData[EXTERNAL_MODULE].pxx.ptr - (uint8_t *)modulePulsesData[EXTERNAL_MODULE].pxx.pulses;
|
||||
sscptr->SSC_PTCR = SSC_PTCR_TXTEN; // Start transfers
|
||||
}
|
||||
break;
|
||||
|
||||
case PROTO_DSM2_LP45:
|
||||
case PROTO_DSM2_DSM2:
|
||||
case PROTO_DSM2_DSMX:
|
||||
// Alternate periods of 19.5mS and 2.5 mS
|
||||
period = pwmptr->PWM_CH_NUM[3].PWM_CPDR;
|
||||
if (period == 2500 * 2) {
|
||||
period = 19500 * 2;
|
||||
}
|
||||
else {
|
||||
period = 2500 * 2;
|
||||
}
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
|
||||
if (period != 2500 * 2) {
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
}
|
||||
else {
|
||||
// Kick off serial output here
|
||||
Ssc * sscptr = SSC;
|
||||
sscptr->SSC_TPR = CONVERT_PTR_UINT(modulePulsesData[EXTERNAL_MODULE].dsm2.pulses);
|
||||
sscptr->SSC_TCR = (uint8_t *)modulePulsesData[EXTERNAL_MODULE].dsm2.ptr - (uint8_t *)modulePulsesData[EXTERNAL_MODULE].dsm2.pulses;
|
||||
sscptr->SSC_PTCR = SSC_PTCR_TXTEN; // Start transfers
|
||||
}
|
||||
break;
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
case PROTO_MULTIMODULE:
|
||||
// Alternate periods of 5.5mS and 3.5 mS
|
||||
period = pwmptr->PWM_CH_NUM[3].PWM_CPDR;
|
||||
if (period == 3500 * 2) {
|
||||
period = 5500 * 2;
|
||||
}
|
||||
else {
|
||||
period = 3500 * 2;
|
||||
}
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
|
||||
if (period != 3500 * 2) {
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
}
|
||||
else {
|
||||
// Kick off serial output here
|
||||
Ssc * sscptr = SSC;
|
||||
sscptr->SSC_TPR = CONVERT_PTR_UINT(modulePulsesData[EXTERNAL_MODULE].dsm2.pulses);
|
||||
sscptr->SSC_TCR = (uint8_t *)modulePulsesData[EXTERNAL_MODULE].dsm2.ptr - (uint8_t *)modulePulsesData[EXTERNAL_MODULE].dsm2.pulses;
|
||||
sscptr->SSC_PTCR = SSC_PTCR_TXTEN; // Start transfers
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = *modulePulsesData[EXTERNAL_MODULE].ppm.ptr++;
|
||||
if (*modulePulsesData[EXTERNAL_MODULE].ppm.ptr == 0) {
|
||||
setExternalModulePolarity();
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(REVA)
|
||||
if (reason & PWM_ISR1_CHID1) {
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CPDRUPD = *modulePulsesData[EXTRA_MODULE].ppm.ptr++;
|
||||
if (*modulePulsesData[EXTRA_MODULE].ppm.ptr == 0) {
|
||||
setupPulsesPPMModule(EXTRA_MODULE);
|
||||
setExtraModulePolarity();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
pioptr->PIO_MDDR = PIO_PA17; // Push Pull O/p in A17
|
||||
#endif
|
||||
pioptr->PIO_PUER = PIO_PA17; // With pull up
|
||||
}
|
||||
|
||||
void init_main_ppm(uint32_t period, uint32_t out_enable)
|
||||
{
|
||||
Pwm * pwmptr;
|
||||
|
||||
setupPulsesPPMModule(EXTERNAL_MODULE);
|
||||
|
||||
if (out_enable) {
|
||||
module_output_active();
|
||||
}
|
||||
|
||||
pwmptr = PWM;
|
||||
// PWM3 for PPM output
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CMR = 0x0004000B; // CLKA
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDR = period; // Period in half uS
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CDTY = GET_PPM_DELAY(EXTERNAL_MODULE) * 2; // Duty in half uS
|
||||
pwmptr->PWM_ENA = PWM_ENA_CHID3; // Enable channel 3
|
||||
pwmptr->PWM_IER1 = PWM_IER1_CHID3;
|
||||
|
||||
setExternalModulePolarity();
|
||||
|
||||
NVIC_SetPriority(PWM_IRQn, 3);
|
||||
NVIC_EnableIRQ(PWM_IRQn);
|
||||
}
|
||||
|
||||
void disable_main_ppm()
|
||||
{
|
||||
Pio * pioptr = PIOA;
|
||||
pioptr->PIO_PER = PIO_PA17; // Assign A17 to PIO
|
||||
PWM->PWM_IDR1 = PWM_IDR1_CHID3;
|
||||
}
|
||||
|
||||
void init_second_ppm(uint32_t period)
|
||||
{
|
||||
#if !defined(REVA)
|
||||
// PWM1 for PPM2
|
||||
Pwm * pwmptr = PWM;
|
||||
configure_pins(PIO_PC15, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_B | PIN_PORTC | PIN_NO_PULLUP);
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CMR = 0x0000000B; // CLKB
|
||||
if (!GET_PPM_POLARITY(EXTRA_MODULE)) {
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CMR |= 0x00000200; // CPOL
|
||||
}
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CPDR = period; // Period
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CPDRUPD = period; // Period
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CDTY = GET_PPM_DELAY(EXTRA_MODULE)*2; // Duty
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CDTYUPD = GET_PPM_DELAY(EXTRA_MODULE)*2; // Duty
|
||||
pwmptr->PWM_ENA = PWM_ENA_CHID1; // Enable channel 1
|
||||
pwmptr->PWM_IER1 = PWM_IER1_CHID1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void disable_second_ppm()
|
||||
{
|
||||
#if !defined(REVA)
|
||||
Pio * pioptr = PIOC;
|
||||
pioptr->PIO_PER = PIO_PC15; // Assign C17 to PIO
|
||||
PWM->PWM_IDR1 = PWM_IDR1_CHID1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void init_no_pulses(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
init_main_ppm(3000, 0);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void disable_no_pulses(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
disable_ppm(EXTERNAL_MODULE);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void init_ppm(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
init_main_ppm(3000, 1);
|
||||
}
|
||||
else {
|
||||
init_second_ppm(3000);
|
||||
}
|
||||
}
|
||||
|
||||
void disable_ppm(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
disable_main_ppm();
|
||||
}
|
||||
else {
|
||||
disable_second_ppm();
|
||||
}
|
||||
}
|
||||
|
||||
// Initialise the SSC to allow PXX output.
|
||||
// TD is on PA17, peripheral A
|
||||
void init_ssc(uint8_t baudrateDiv1000)
|
||||
{
|
||||
Ssc *sscptr;
|
||||
|
||||
PMC->PMC_PCER0 |= 0x00400000L; // Enable peripheral clock to SSC
|
||||
|
||||
configure_pins(PIO_PA17, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA);
|
||||
|
||||
sscptr = SSC;
|
||||
sscptr->SSC_THR = 0xFF; // Make the output high.
|
||||
sscptr->SSC_TFMR = 0x00000027; // 0000 0000 0000 0000 0000 0000 1010 0111 (8 bit data, lsb)
|
||||
sscptr->SSC_CMR = Master_frequency / (1000 * baudrateDiv1000 * 2);
|
||||
sscptr->SSC_TCMR = 0;
|
||||
sscptr->SSC_CR = SSC_CR_TXEN;
|
||||
|
||||
#if defined(REVX)
|
||||
if (IS_MODULE_MULTIMODULE(EXTERNAL_MODULE)) {
|
||||
PIOA->PIO_MDDR = PIO_PA17; // Push Pull O/p in A17
|
||||
} else {
|
||||
PIOA->PIO_MDER = PIO_PA17; // Open Drain O/p in A17
|
||||
}
|
||||
#else
|
||||
PIOA->PIO_MDDR = PIO_PA17; // Push Pull O/p in A17
|
||||
#endif
|
||||
}
|
||||
|
||||
void disable_ssc()
|
||||
{
|
||||
Pio *pioptr;
|
||||
Ssc *sscptr;
|
||||
|
||||
// Revert back to pwm output
|
||||
pioptr = PIOA;
|
||||
pioptr->PIO_PER = PIO_PA17; // Assign A17 to PIO
|
||||
|
||||
sscptr = SSC;
|
||||
sscptr->SSC_CR = SSC_CR_TXDIS;
|
||||
}
|
||||
|
||||
void init_pxx(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
init_main_ppm(2500 * 2, 0);
|
||||
init_ssc(125); // 8us per bit
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void disable_pxx(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
disable_ssc();
|
||||
disable_ppm(EXTERNAL_MODULE);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void init_dsm2(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
init_main_ppm(2500 * 2, 0);
|
||||
init_ssc(125);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void disable_dsm2(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
disable_ssc();
|
||||
disable_ppm(EXTERNAL_MODULE);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
void init_multimodule(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
init_main_ppm(3500 * 2, 0);
|
||||
init_ssc(100);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void disable_multimodule(uint32_t port)
|
||||
{
|
||||
disable_dsm2(port);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(SIMU)
|
||||
extern "C" void PWM_IRQHandler(void)
|
||||
{
|
||||
Pwm * pwmptr = PWM;
|
||||
uint32_t reason = pwmptr->PWM_ISR1;
|
||||
uint32_t period;
|
||||
|
||||
if (reason & PWM_ISR1_CHID3) {
|
||||
// Use the current protocol, don't switch until set_up_pulses
|
||||
switch (s_current_protocol[EXTERNAL_MODULE]) {
|
||||
case PROTO_PXX:
|
||||
// Alternate periods of 6.5mS and 2.5 mS
|
||||
period = pwmptr->PWM_CH_NUM[3].PWM_CPDR;
|
||||
if (period == 2500 * 2) {
|
||||
period = 6500 * 2;
|
||||
}
|
||||
else {
|
||||
period = 2500 * 2;
|
||||
}
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
|
||||
if (period != 2500 * 2) {
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
setExternalModulePolarity();
|
||||
}
|
||||
else {
|
||||
// Kick off serial output here
|
||||
Ssc * sscptr = SSC;
|
||||
sscptr->SSC_TPR = CONVERT_PTR_UINT(modulePulsesData[EXTERNAL_MODULE].pxx.pulses);
|
||||
sscptr->SSC_TCR = (uint8_t *)modulePulsesData[EXTERNAL_MODULE].pxx.ptr - (uint8_t *)modulePulsesData[EXTERNAL_MODULE].pxx.pulses;
|
||||
sscptr->SSC_PTCR = SSC_PTCR_TXTEN; // Start transfers
|
||||
}
|
||||
break;
|
||||
|
||||
case PROTO_DSM2_LP45:
|
||||
case PROTO_DSM2_DSM2:
|
||||
case PROTO_DSM2_DSMX:
|
||||
// Alternate periods of 19.5mS and 2.5 mS
|
||||
period = pwmptr->PWM_CH_NUM[3].PWM_CPDR;
|
||||
if (period == 2500 * 2) {
|
||||
period = 19500 * 2;
|
||||
}
|
||||
else {
|
||||
period = 2500 * 2;
|
||||
}
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
|
||||
if (period != 2500 * 2) {
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
}
|
||||
else {
|
||||
// Kick off serial output here
|
||||
Ssc * sscptr = SSC;
|
||||
sscptr->SSC_TPR = CONVERT_PTR_UINT(modulePulsesData[EXTERNAL_MODULE].dsm2.pulses);
|
||||
sscptr->SSC_TCR = (uint8_t *)modulePulsesData[EXTERNAL_MODULE].dsm2.ptr - (uint8_t *)modulePulsesData[EXTERNAL_MODULE].dsm2.pulses;
|
||||
sscptr->SSC_PTCR = SSC_PTCR_TXTEN; // Start transfers
|
||||
}
|
||||
break;
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
case PROTO_MULTIMODULE:
|
||||
// Alternate periods of 5.5mS and 3.5 mS
|
||||
period = pwmptr->PWM_CH_NUM[3].PWM_CPDR;
|
||||
if (period == 3500 * 2) {
|
||||
period = 5500 * 2;
|
||||
}
|
||||
else {
|
||||
period = 3500 * 2;
|
||||
}
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
|
||||
if (period != 3500 * 2) {
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
}
|
||||
else {
|
||||
// Kick off serial output here
|
||||
Ssc * sscptr = SSC;
|
||||
sscptr->SSC_TPR = CONVERT_PTR_UINT(modulePulsesData[EXTERNAL_MODULE].dsm2.pulses);
|
||||
sscptr->SSC_TCR = (uint8_t *)modulePulsesData[EXTERNAL_MODULE].dsm2.ptr - (uint8_t *)modulePulsesData[EXTERNAL_MODULE].dsm2.pulses;
|
||||
sscptr->SSC_PTCR = SSC_PTCR_TXTEN; // Start transfers
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = *modulePulsesData[EXTERNAL_MODULE].ppm.ptr++;
|
||||
if (*modulePulsesData[EXTERNAL_MODULE].ppm.ptr == 0) {
|
||||
setExternalModulePolarity();
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(REVA)
|
||||
if (reason & PWM_ISR1_CHID1) {
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CPDRUPD = *modulePulsesData[EXTRA_MODULE].ppm.ptr++;
|
||||
if (*modulePulsesData[EXTRA_MODULE].ppm.ptr == 0) {
|
||||
setupPulsesPPMModule(EXTRA_MODULE);
|
||||
setExtraModulePolarity();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
uint32_t pwrPressed()
|
||||
{
|
||||
#if defined(SIMU) || defined(REVA)
|
||||
return true;
|
||||
#else
|
||||
return PIOC->PIO_PDSR & PIO_PC17;
|
||||
#endif
|
||||
}
|
||||
|
||||
// turn off soft power
|
||||
void pwrOff()
|
||||
{
|
||||
#if !defined(REVA)
|
||||
configure_pins(PIO_PA8, PIN_ENABLE | PIN_OUTPUT | PIN_LOW | PIN_PORTA | PIN_NO_PULLUP);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(REVA)
|
||||
void pwrInit()
|
||||
{
|
||||
// Configure RF_power (PC17)
|
||||
configure_pins(PIO_PC17, PIN_ENABLE | PIN_INPUT | PIN_PORTC | PIN_NO_PULLUP | PIN_PULLDOWN);
|
||||
configure_pins(PIO_PA8, PIN_ENABLE | PIN_INPUT | PIN_PORTA | PIN_PULLUP); // Enable bit A8 (Soft Power)
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
uint32_t pwrPressed()
|
||||
{
|
||||
#if defined(SIMU) || defined(REVA)
|
||||
return true;
|
||||
#else
|
||||
return PIOC->PIO_PDSR & PIO_PC17;
|
||||
#endif
|
||||
}
|
||||
|
||||
// turn off soft power
|
||||
void pwrOff()
|
||||
{
|
||||
#if !defined(REVA)
|
||||
configure_pins(PIO_PA8, PIN_ENABLE | PIN_OUTPUT | PIN_LOW | PIN_PORTA | PIN_NO_PULLUP);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(REVA)
|
||||
void pwrInit()
|
||||
{
|
||||
// Configure RF_power (PC17)
|
||||
configure_pins(PIO_PC17, PIN_ENABLE | PIN_INPUT | PIN_PORTC | PIN_NO_PULLUP | PIN_PULLDOWN);
|
||||
configure_pins(PIO_PA8, PIN_ENABLE | PIN_INPUT | PIN_PORTA | PIN_PULLUP); // Enable bit A8 (Soft Power)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
void rotencInit()
|
||||
{
|
||||
configure_pins( PIO_PC19 | PIO_PC21, PIN_ENABLE | PIN_INPUT | PIN_PORTC | PIN_PULLUP ) ; // 19 and 21 are rotary encoder
|
||||
configure_pins( PIO_PB6, PIN_ENABLE | PIN_INPUT | PIN_PORTB | PIN_PULLUP ) ; // rotary encoder switch
|
||||
PIOC->PIO_IER = PIO_PC19 | PIO_PC21 ;
|
||||
NVIC_EnableIRQ(PIOC_IRQn) ;
|
||||
}
|
||||
|
||||
void rotencEnd()
|
||||
{
|
||||
NVIC_DisableIRQ(PIOC_IRQn) ;
|
||||
PIOC->PIO_IDR = PIO_PC19 | PIO_PC21 ;
|
||||
}
|
||||
|
||||
volatile uint32_t Rotary_position ;
|
||||
extern "C" void PIOC_IRQHandler()
|
||||
{
|
||||
uint32_t dummy;
|
||||
|
||||
dummy = PIOC->PIO_ISR ; // Read and clear status register
|
||||
(void) dummy ; // Discard value - prevents compiler warning
|
||||
|
||||
dummy = PIOC->PIO_PDSR ; // Read Rotary encoder (PC19, PC21)
|
||||
dummy >>= 19 ;
|
||||
dummy &= 0x05 ; // pick out the three bits
|
||||
if ( dummy != ( Rotary_position & 0x05 ) ) {
|
||||
if ( ( Rotary_position & 0x01 ) ^ ( ( dummy & 0x04) >> 2 ) )
|
||||
incRotaryEncoder(0, -1);
|
||||
else
|
||||
incRotaryEncoder(0, +1);
|
||||
|
||||
Rotary_position &= ~0x45 ;
|
||||
Rotary_position |= dummy ;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
void rotencInit()
|
||||
{
|
||||
configure_pins( PIO_PC19 | PIO_PC21, PIN_ENABLE | PIN_INPUT | PIN_PORTC | PIN_PULLUP ) ; // 19 and 21 are rotary encoder
|
||||
configure_pins( PIO_PB6, PIN_ENABLE | PIN_INPUT | PIN_PORTB | PIN_PULLUP ) ; // rotary encoder switch
|
||||
PIOC->PIO_IER = PIO_PC19 | PIO_PC21 ;
|
||||
NVIC_EnableIRQ(PIOC_IRQn) ;
|
||||
}
|
||||
|
||||
void rotencEnd()
|
||||
{
|
||||
NVIC_DisableIRQ(PIOC_IRQn) ;
|
||||
PIOC->PIO_IDR = PIO_PC19 | PIO_PC21 ;
|
||||
}
|
||||
|
||||
volatile uint32_t Rotary_position ;
|
||||
extern "C" void PIOC_IRQHandler()
|
||||
{
|
||||
uint32_t dummy;
|
||||
|
||||
dummy = PIOC->PIO_ISR ; // Read and clear status register
|
||||
(void) dummy ; // Discard value - prevents compiler warning
|
||||
|
||||
dummy = PIOC->PIO_PDSR ; // Read Rotary encoder (PC19, PC21)
|
||||
dummy >>= 19 ;
|
||||
dummy &= 0x05 ; // pick out the three bits
|
||||
if ( dummy != ( Rotary_position & 0x05 ) ) {
|
||||
if ( ( Rotary_position & 0x01 ) ^ ( ( dummy & 0x04) >> 2 ) )
|
||||
incRotaryEncoder(0, -1);
|
||||
else
|
||||
incRotaryEncoder(0, +1);
|
||||
|
||||
Rotary_position &= ~0x45 ;
|
||||
Rotary_position |= dummy ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,287 +1,287 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#if defined(REVX)
|
||||
// TODO change this, not the right place
|
||||
#define TWI_NONE 0
|
||||
#define TWI_WRITE_VOL 2
|
||||
#define TWI_WAIT_COMP 7
|
||||
#define TWI_READ_RTC 8
|
||||
#define TWI_WRITE_RTC 9
|
||||
#define TWI_WAIT_RTCSTOP 10
|
||||
#define TWI_WRITE_MFP 11
|
||||
int8_t volumeRequired ;
|
||||
int8_t Rtc_read_pending;
|
||||
uint8_t Rtc_write_pending ;
|
||||
int8_t Rtc_valid ;
|
||||
uint8_t MFPsetting = 0 ;
|
||||
uint8_t CALsetting = 0 ;
|
||||
uint8_t *Twi_read_address ;
|
||||
uint8_t TwiOperation ;
|
||||
#define RTC_RX_BUXSIZE 10
|
||||
#define RTC_SIZE 7
|
||||
uint8_t Rtc_status[RTC_RX_BUXSIZE] ;
|
||||
uint8_t *Rtc_write_ptr ;
|
||||
uint32_t Rtc_write_count ;
|
||||
uint8_t RtcConfig[8] ; // For initial config and writing to RTC
|
||||
// 0x80, 0, 0, 0x08, 0, 0, 0, 0x80
|
||||
|
||||
uint32_t fromBCD(uint8_t bcd_value)
|
||||
{
|
||||
return (((bcd_value & 0xF0) * 10) >> 4) + (bcd_value & 0x0F);
|
||||
}
|
||||
|
||||
uint32_t toBCD(uint32_t value)
|
||||
{
|
||||
div_t qr = div(value, 10);
|
||||
return (qr.quot << 4) + qr.rem;
|
||||
}
|
||||
|
||||
// This is called from an interrupt routine, or
|
||||
// interrupts must be disabled while it is called
|
||||
// from elsewhere.
|
||||
void i2cCheck()
|
||||
{
|
||||
if ( TWI0->TWI_IMR & TWI_IMR_TXCOMP ) {
|
||||
return ; // Busy
|
||||
}
|
||||
|
||||
if ( volumeRequired >= 0 ) // Set volume to this value
|
||||
{
|
||||
TWI0->TWI_MMR = 0x002F0000 ; // Device 5E (>>1) and master is writing
|
||||
TwiOperation = TWI_WRITE_VOL ;
|
||||
TWI0->TWI_THR = volumeRequired ; // Send data
|
||||
volumeRequired = -1 ;
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
else if ( Rtc_read_pending )
|
||||
{
|
||||
Rtc_valid = 0 ;
|
||||
Rtc_read_pending = 0 ;
|
||||
TWI0->TWI_MMR = 0x006F1100 ; // Device 6F and master is reading, 1 byte addr
|
||||
TWI0->TWI_IADR = 0 ;
|
||||
TwiOperation = TWI_READ_RTC ;
|
||||
#ifndef SIMU
|
||||
TWI0->TWI_RPR = (uint32_t)&Rtc_status[0] ;
|
||||
#endif
|
||||
TWI0->TWI_RCR = RTC_SIZE - 1 ;
|
||||
if ( TWI0->TWI_SR & TWI_SR_RXRDY )
|
||||
{
|
||||
(void) TWI0->TWI_RHR ;
|
||||
}
|
||||
|
||||
TWI0->TWI_PTCR = TWI_PTCR_RXTEN ; // Start transfers
|
||||
TWI0->TWI_CR = TWI_CR_START ; // Start Rx
|
||||
TWI0->TWI_IER = TWI_IER_RXBUFF | TWI_IER_TXCOMP ;
|
||||
}
|
||||
else if ( Rtc_write_pending )
|
||||
{
|
||||
if ( Rtc_write_pending & (2|4) )
|
||||
{
|
||||
TWI0->TWI_MMR = 0x006F0100 ; // Device 6F and master is writing, 1 byte addr
|
||||
TwiOperation = TWI_WRITE_MFP ;
|
||||
if ( Rtc_write_pending & 2 )
|
||||
{
|
||||
TWI0->TWI_IADR = 7 ;
|
||||
TWI0->TWI_THR = MFPsetting ; // Send data
|
||||
Rtc_write_pending &= ~2 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
TWI0->TWI_IADR = 8 ;
|
||||
TWI0->TWI_THR = CALsetting ; // Send data
|
||||
Rtc_write_pending &= ~4 ;
|
||||
}
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
else
|
||||
{
|
||||
Rtc_write_pending &= ~1 ;
|
||||
TWI0->TWI_MMR = 0x006F0100 ; // Device 6F and master is writing, 1 byte addr
|
||||
TWI0->TWI_IADR = 0 ;
|
||||
TwiOperation = TWI_WRITE_RTC ;
|
||||
#ifndef SIMU
|
||||
TWI0->TWI_TPR = (uint32_t)Rtc_write_ptr+1 ;
|
||||
#endif
|
||||
TWI0->TWI_TCR = Rtc_write_count-1 ;
|
||||
TWI0->TWI_THR = *Rtc_write_ptr ; // First byte
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTEN ; // Start data transfer
|
||||
TWI0->TWI_IER = TWI_IER_TXBUFE | TWI_IER_TXCOMP ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void writeRTC(uint8_t *ptr)
|
||||
{
|
||||
uint32_t year;
|
||||
RtcConfig[0] = 0x80 | toBCD(*ptr++);
|
||||
RtcConfig[1] = toBCD(*ptr++);
|
||||
RtcConfig[2] = toBCD(*ptr++);
|
||||
RtcConfig[3] = 0x08;
|
||||
RtcConfig[4] = toBCD(*ptr++);
|
||||
RtcConfig[5] = toBCD( *ptr++);
|
||||
year = *ptr++;
|
||||
year |= *ptr << 8;
|
||||
RtcConfig[6] = toBCD(year - 2000);
|
||||
RtcConfig[7] = MFPsetting;
|
||||
Rtc_write_ptr = RtcConfig;
|
||||
Rtc_write_count = 8;
|
||||
__disable_irq();
|
||||
Rtc_write_pending |= 1;
|
||||
i2cCheck();
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
void readRTC()
|
||||
{
|
||||
Rtc_read_pending = 1 ;
|
||||
__disable_irq() ;
|
||||
i2cCheck() ;
|
||||
__enable_irq() ;
|
||||
}
|
||||
|
||||
// TODO should be inside an i2c_driver.cpp
|
||||
#ifndef SIMU
|
||||
extern "C" void TWI0_IRQHandler()
|
||||
{
|
||||
uint32_t status ;
|
||||
status = TWI0->TWI_SR ; // Read only once, some bits cleared on read
|
||||
|
||||
if ( TwiOperation == TWI_READ_RTC )
|
||||
{
|
||||
if ( status & TWI_SR_RXBUFF )
|
||||
{
|
||||
TWI0->TWI_IDR = TWI_IDR_RXBUFF ;
|
||||
TwiOperation = TWI_WAIT_RTCSTOP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx
|
||||
TWI0->TWI_RCR = 1 ; // Last byte
|
||||
return ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// must be TXCOMP, prob. NAK in data
|
||||
if ( TWI0->TWI_RCR > 0 )
|
||||
{
|
||||
Rtc_valid = -1 ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( TwiOperation == TWI_WAIT_RTCSTOP )
|
||||
{
|
||||
Rtc_valid = 1 ;
|
||||
// Set the date and time
|
||||
struct gtm utm;
|
||||
|
||||
utm.tm_sec = fromBCD( Rtc_status[0] & 0x7F ) ;
|
||||
utm.tm_min = fromBCD( Rtc_status[1] & 0x7F ) ;
|
||||
utm.tm_hour = fromBCD( Rtc_status[2] & 0x3F ) ;
|
||||
utm.tm_mday = fromBCD( Rtc_status[4] & 0x3F ) ;
|
||||
utm.tm_mon = fromBCD( Rtc_status[5] & 0x1F ) - 1;
|
||||
utm.tm_year = fromBCD( Rtc_status[6] ) + 100 ;
|
||||
g_rtcTime = gmktime(&utm);
|
||||
|
||||
TWI0->TWI_PTCR = TWI_PTCR_RXTDIS ; // Stop transfers
|
||||
if ( status & TWI_SR_RXRDY )
|
||||
{
|
||||
(void) TWI0->TWI_RHR ; // Discard any rubbish data
|
||||
}
|
||||
}
|
||||
|
||||
if ( status & TWI_SR_NACK )
|
||||
{
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
|
||||
TWI0->TWI_IDR = TWI_IDR_TXCOMP | TWI_IDR_TXBUFE | TWI_IDR_RXBUFF ;
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTDIS | TWI_PTCR_RXTDIS ; // Stop transfers
|
||||
if ( ( status & TWI_SR_TXCOMP ) == 0 )
|
||||
{
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TwiOperation = TWI_WAIT_COMP ;
|
||||
return ;
|
||||
}
|
||||
|
||||
TwiOperation = TWI_NONE ;
|
||||
i2cCheck() ;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct t_i2cTime
|
||||
{
|
||||
uint8_t setCode ;
|
||||
uint8_t Time[7] ;
|
||||
} I2CTime ;
|
||||
|
||||
void rtcSetTime(const struct gtm * t)
|
||||
{
|
||||
g_ms100 = 0; // start of next second begins now
|
||||
|
||||
I2CTime.setCode = 0x74 ; // Tiny SET TIME CODE command
|
||||
I2CTime.Time[0] = t->tm_sec ;
|
||||
I2CTime.Time[1] = t->tm_min ;
|
||||
I2CTime.Time[2] = t->tm_hour ;
|
||||
I2CTime.Time[3] = t->tm_mday ;
|
||||
I2CTime.Time[4] = t->tm_mon+1 ;
|
||||
I2CTime.Time[5] = (uint8_t) (t->tm_year+TM_YEAR_BASE);
|
||||
I2CTime.Time[6] = (t->tm_year+TM_YEAR_BASE) >> 8;
|
||||
#if defined(REVX)
|
||||
writeRTC((uint8_t *)&I2CTime.Time[0]) ;
|
||||
#elif defined(COPROCESSOR)
|
||||
coprocWriteData((uint8_t *) &I2CTime, 8);
|
||||
#endif
|
||||
}
|
||||
|
||||
void rtcInit()
|
||||
{
|
||||
#if defined(REVX)
|
||||
readRTC();
|
||||
#elif defined(COPROCESSOR)
|
||||
coprocReadData();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(REVX)
|
||||
void writeMFP()
|
||||
{
|
||||
__disable_irq();
|
||||
Rtc_write_pending |= 2;
|
||||
i2cCheck();
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
void setMFP()
|
||||
{
|
||||
MFPsetting = 0x80;
|
||||
writeMFP();
|
||||
}
|
||||
|
||||
void clearMFP()
|
||||
{
|
||||
MFPsetting = 0;
|
||||
writeMFP();
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#if defined(REVX)
|
||||
// TODO change this, not the right place
|
||||
#define TWI_NONE 0
|
||||
#define TWI_WRITE_VOL 2
|
||||
#define TWI_WAIT_COMP 7
|
||||
#define TWI_READ_RTC 8
|
||||
#define TWI_WRITE_RTC 9
|
||||
#define TWI_WAIT_RTCSTOP 10
|
||||
#define TWI_WRITE_MFP 11
|
||||
int8_t volumeRequired ;
|
||||
int8_t Rtc_read_pending;
|
||||
uint8_t Rtc_write_pending ;
|
||||
int8_t Rtc_valid ;
|
||||
uint8_t MFPsetting = 0 ;
|
||||
uint8_t CALsetting = 0 ;
|
||||
uint8_t *Twi_read_address ;
|
||||
uint8_t TwiOperation ;
|
||||
#define RTC_RX_BUXSIZE 10
|
||||
#define RTC_SIZE 7
|
||||
uint8_t Rtc_status[RTC_RX_BUXSIZE] ;
|
||||
uint8_t *Rtc_write_ptr ;
|
||||
uint32_t Rtc_write_count ;
|
||||
uint8_t RtcConfig[8] ; // For initial config and writing to RTC
|
||||
// 0x80, 0, 0, 0x08, 0, 0, 0, 0x80
|
||||
|
||||
uint32_t fromBCD(uint8_t bcd_value)
|
||||
{
|
||||
return (((bcd_value & 0xF0) * 10) >> 4) + (bcd_value & 0x0F);
|
||||
}
|
||||
|
||||
uint32_t toBCD(uint32_t value)
|
||||
{
|
||||
div_t qr = div(value, 10);
|
||||
return (qr.quot << 4) + qr.rem;
|
||||
}
|
||||
|
||||
// This is called from an interrupt routine, or
|
||||
// interrupts must be disabled while it is called
|
||||
// from elsewhere.
|
||||
void i2cCheck()
|
||||
{
|
||||
if ( TWI0->TWI_IMR & TWI_IMR_TXCOMP ) {
|
||||
return ; // Busy
|
||||
}
|
||||
|
||||
if ( volumeRequired >= 0 ) // Set volume to this value
|
||||
{
|
||||
TWI0->TWI_MMR = 0x002F0000 ; // Device 5E (>>1) and master is writing
|
||||
TwiOperation = TWI_WRITE_VOL ;
|
||||
TWI0->TWI_THR = volumeRequired ; // Send data
|
||||
volumeRequired = -1 ;
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
else if ( Rtc_read_pending )
|
||||
{
|
||||
Rtc_valid = 0 ;
|
||||
Rtc_read_pending = 0 ;
|
||||
TWI0->TWI_MMR = 0x006F1100 ; // Device 6F and master is reading, 1 byte addr
|
||||
TWI0->TWI_IADR = 0 ;
|
||||
TwiOperation = TWI_READ_RTC ;
|
||||
#ifndef SIMU
|
||||
TWI0->TWI_RPR = (uint32_t)&Rtc_status[0] ;
|
||||
#endif
|
||||
TWI0->TWI_RCR = RTC_SIZE - 1 ;
|
||||
if ( TWI0->TWI_SR & TWI_SR_RXRDY )
|
||||
{
|
||||
(void) TWI0->TWI_RHR ;
|
||||
}
|
||||
|
||||
TWI0->TWI_PTCR = TWI_PTCR_RXTEN ; // Start transfers
|
||||
TWI0->TWI_CR = TWI_CR_START ; // Start Rx
|
||||
TWI0->TWI_IER = TWI_IER_RXBUFF | TWI_IER_TXCOMP ;
|
||||
}
|
||||
else if ( Rtc_write_pending )
|
||||
{
|
||||
if ( Rtc_write_pending & (2|4) )
|
||||
{
|
||||
TWI0->TWI_MMR = 0x006F0100 ; // Device 6F and master is writing, 1 byte addr
|
||||
TwiOperation = TWI_WRITE_MFP ;
|
||||
if ( Rtc_write_pending & 2 )
|
||||
{
|
||||
TWI0->TWI_IADR = 7 ;
|
||||
TWI0->TWI_THR = MFPsetting ; // Send data
|
||||
Rtc_write_pending &= ~2 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
TWI0->TWI_IADR = 8 ;
|
||||
TWI0->TWI_THR = CALsetting ; // Send data
|
||||
Rtc_write_pending &= ~4 ;
|
||||
}
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
else
|
||||
{
|
||||
Rtc_write_pending &= ~1 ;
|
||||
TWI0->TWI_MMR = 0x006F0100 ; // Device 6F and master is writing, 1 byte addr
|
||||
TWI0->TWI_IADR = 0 ;
|
||||
TwiOperation = TWI_WRITE_RTC ;
|
||||
#ifndef SIMU
|
||||
TWI0->TWI_TPR = (uint32_t)Rtc_write_ptr+1 ;
|
||||
#endif
|
||||
TWI0->TWI_TCR = Rtc_write_count-1 ;
|
||||
TWI0->TWI_THR = *Rtc_write_ptr ; // First byte
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTEN ; // Start data transfer
|
||||
TWI0->TWI_IER = TWI_IER_TXBUFE | TWI_IER_TXCOMP ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void writeRTC(uint8_t *ptr)
|
||||
{
|
||||
uint32_t year;
|
||||
RtcConfig[0] = 0x80 | toBCD(*ptr++);
|
||||
RtcConfig[1] = toBCD(*ptr++);
|
||||
RtcConfig[2] = toBCD(*ptr++);
|
||||
RtcConfig[3] = 0x08;
|
||||
RtcConfig[4] = toBCD(*ptr++);
|
||||
RtcConfig[5] = toBCD( *ptr++);
|
||||
year = *ptr++;
|
||||
year |= *ptr << 8;
|
||||
RtcConfig[6] = toBCD(year - 2000);
|
||||
RtcConfig[7] = MFPsetting;
|
||||
Rtc_write_ptr = RtcConfig;
|
||||
Rtc_write_count = 8;
|
||||
__disable_irq();
|
||||
Rtc_write_pending |= 1;
|
||||
i2cCheck();
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
void readRTC()
|
||||
{
|
||||
Rtc_read_pending = 1 ;
|
||||
__disable_irq() ;
|
||||
i2cCheck() ;
|
||||
__enable_irq() ;
|
||||
}
|
||||
|
||||
// TODO should be inside an i2c_driver.cpp
|
||||
#ifndef SIMU
|
||||
extern "C" void TWI0_IRQHandler()
|
||||
{
|
||||
uint32_t status ;
|
||||
status = TWI0->TWI_SR ; // Read only once, some bits cleared on read
|
||||
|
||||
if ( TwiOperation == TWI_READ_RTC )
|
||||
{
|
||||
if ( status & TWI_SR_RXBUFF )
|
||||
{
|
||||
TWI0->TWI_IDR = TWI_IDR_RXBUFF ;
|
||||
TwiOperation = TWI_WAIT_RTCSTOP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx
|
||||
TWI0->TWI_RCR = 1 ; // Last byte
|
||||
return ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// must be TXCOMP, prob. NAK in data
|
||||
if ( TWI0->TWI_RCR > 0 )
|
||||
{
|
||||
Rtc_valid = -1 ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( TwiOperation == TWI_WAIT_RTCSTOP )
|
||||
{
|
||||
Rtc_valid = 1 ;
|
||||
// Set the date and time
|
||||
struct gtm utm;
|
||||
|
||||
utm.tm_sec = fromBCD( Rtc_status[0] & 0x7F ) ;
|
||||
utm.tm_min = fromBCD( Rtc_status[1] & 0x7F ) ;
|
||||
utm.tm_hour = fromBCD( Rtc_status[2] & 0x3F ) ;
|
||||
utm.tm_mday = fromBCD( Rtc_status[4] & 0x3F ) ;
|
||||
utm.tm_mon = fromBCD( Rtc_status[5] & 0x1F ) - 1;
|
||||
utm.tm_year = fromBCD( Rtc_status[6] ) + 100 ;
|
||||
g_rtcTime = gmktime(&utm);
|
||||
|
||||
TWI0->TWI_PTCR = TWI_PTCR_RXTDIS ; // Stop transfers
|
||||
if ( status & TWI_SR_RXRDY )
|
||||
{
|
||||
(void) TWI0->TWI_RHR ; // Discard any rubbish data
|
||||
}
|
||||
}
|
||||
|
||||
if ( status & TWI_SR_NACK )
|
||||
{
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
|
||||
TWI0->TWI_IDR = TWI_IDR_TXCOMP | TWI_IDR_TXBUFE | TWI_IDR_RXBUFF ;
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTDIS | TWI_PTCR_RXTDIS ; // Stop transfers
|
||||
if ( ( status & TWI_SR_TXCOMP ) == 0 )
|
||||
{
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TwiOperation = TWI_WAIT_COMP ;
|
||||
return ;
|
||||
}
|
||||
|
||||
TwiOperation = TWI_NONE ;
|
||||
i2cCheck() ;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct t_i2cTime
|
||||
{
|
||||
uint8_t setCode ;
|
||||
uint8_t Time[7] ;
|
||||
} I2CTime ;
|
||||
|
||||
void rtcSetTime(const struct gtm * t)
|
||||
{
|
||||
g_ms100 = 0; // start of next second begins now
|
||||
|
||||
I2CTime.setCode = 0x74 ; // Tiny SET TIME CODE command
|
||||
I2CTime.Time[0] = t->tm_sec ;
|
||||
I2CTime.Time[1] = t->tm_min ;
|
||||
I2CTime.Time[2] = t->tm_hour ;
|
||||
I2CTime.Time[3] = t->tm_mday ;
|
||||
I2CTime.Time[4] = t->tm_mon+1 ;
|
||||
I2CTime.Time[5] = (uint8_t) (t->tm_year+TM_YEAR_BASE);
|
||||
I2CTime.Time[6] = (t->tm_year+TM_YEAR_BASE) >> 8;
|
||||
#if defined(REVX)
|
||||
writeRTC((uint8_t *)&I2CTime.Time[0]) ;
|
||||
#elif defined(COPROCESSOR)
|
||||
coprocWriteData((uint8_t *) &I2CTime, 8);
|
||||
#endif
|
||||
}
|
||||
|
||||
void rtcInit()
|
||||
{
|
||||
#if defined(REVX)
|
||||
readRTC();
|
||||
#elif defined(COPROCESSOR)
|
||||
coprocReadData();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(REVX)
|
||||
void writeMFP()
|
||||
{
|
||||
__disable_irq();
|
||||
Rtc_write_pending |= 2;
|
||||
i2cCheck();
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
void setMFP()
|
||||
{
|
||||
MFPsetting = 0x80;
|
||||
writeMFP();
|
||||
}
|
||||
|
||||
void clearMFP()
|
||||
{
|
||||
MFPsetting = 0;
|
||||
writeMFP();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,150 +1,150 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2011 by Michael Fischer. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*****************************************************************************
|
||||
* History:
|
||||
*
|
||||
* 22.05.2011 mifi First Version
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* In this linker script there is no heap available.
|
||||
* The stack start at the end of the ram segment.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Take a look in the "The GNU linker" manual, here you get
|
||||
* the following information about the "MEMORY":
|
||||
*
|
||||
* "The MEMORY command describes the location and size of
|
||||
* blocks of memory in the target."
|
||||
*/
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00400000, LENGTH = 128K
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* And the "SECTION" is used for:
|
||||
*
|
||||
* "The SECTIONS command tells the linker how to map input
|
||||
* sections into output sections, and how to place the output
|
||||
* sections in memory.
|
||||
*/
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
/*
|
||||
* The ".text" section is used for the code, and
|
||||
* read only (.rodata) data. Even the vectors (.vectors)
|
||||
* MUST be saved at the start of this section.
|
||||
*/
|
||||
.text :
|
||||
{
|
||||
_stext = .; /* Provide the name for the start of this section */
|
||||
|
||||
CREATE_OBJECT_SYMBOLS
|
||||
KEEP(*(.vectors))
|
||||
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the exidx part */
|
||||
*(.ARM.exidx)
|
||||
*(.ARM.exidx.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the rodata part */
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > FLASH = 0
|
||||
_etext = .; /* Provide the name for the end of this section */
|
||||
|
||||
|
||||
/*
|
||||
* The ".data" section is used for initialized data
|
||||
* and for functions (.fastrun) which should be copied
|
||||
* from flash to ram. This functions will later be
|
||||
* executed from ram instead of flash.
|
||||
*/
|
||||
.data : AT (_etext)
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sdata = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the fastrun part */
|
||||
*(.fastrun)
|
||||
*(.fastrun.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_edata = .; /* Provide the name for the end of this section */
|
||||
|
||||
|
||||
/*
|
||||
* The ".bss" section is used for uninitialized data.
|
||||
* This section will be cleared by the startup code.
|
||||
*/
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sbss = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_ebss = .; /* Provide the name for the end of this section */
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
__end = .;
|
||||
_end = .;
|
||||
|
||||
/*
|
||||
* The ".stack" section is our stack.
|
||||
* Here this section starts at the end of the ram segment.
|
||||
*/
|
||||
_estack = ORIGIN(RAM) + LENGTH(RAM);
|
||||
|
||||
}
|
||||
|
||||
/*** EOF **/
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2011 by Michael Fischer. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*****************************************************************************
|
||||
* History:
|
||||
*
|
||||
* 22.05.2011 mifi First Version
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* In this linker script there is no heap available.
|
||||
* The stack start at the end of the ram segment.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Take a look in the "The GNU linker" manual, here you get
|
||||
* the following information about the "MEMORY":
|
||||
*
|
||||
* "The MEMORY command describes the location and size of
|
||||
* blocks of memory in the target."
|
||||
*/
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00400000, LENGTH = 128K
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* And the "SECTION" is used for:
|
||||
*
|
||||
* "The SECTIONS command tells the linker how to map input
|
||||
* sections into output sections, and how to place the output
|
||||
* sections in memory.
|
||||
*/
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
/*
|
||||
* The ".text" section is used for the code, and
|
||||
* read only (.rodata) data. Even the vectors (.vectors)
|
||||
* MUST be saved at the start of this section.
|
||||
*/
|
||||
.text :
|
||||
{
|
||||
_stext = .; /* Provide the name for the start of this section */
|
||||
|
||||
CREATE_OBJECT_SYMBOLS
|
||||
KEEP(*(.vectors))
|
||||
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the exidx part */
|
||||
*(.ARM.exidx)
|
||||
*(.ARM.exidx.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the rodata part */
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > FLASH = 0
|
||||
_etext = .; /* Provide the name for the end of this section */
|
||||
|
||||
|
||||
/*
|
||||
* The ".data" section is used for initialized data
|
||||
* and for functions (.fastrun) which should be copied
|
||||
* from flash to ram. This functions will later be
|
||||
* executed from ram instead of flash.
|
||||
*/
|
||||
.data : AT (_etext)
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sdata = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the fastrun part */
|
||||
*(.fastrun)
|
||||
*(.fastrun.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_edata = .; /* Provide the name for the end of this section */
|
||||
|
||||
|
||||
/*
|
||||
* The ".bss" section is used for uninitialized data.
|
||||
* This section will be cleared by the startup code.
|
||||
*/
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sbss = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_ebss = .; /* Provide the name for the end of this section */
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
__end = .;
|
||||
_end = .;
|
||||
|
||||
/*
|
||||
* The ".stack" section is our stack.
|
||||
* Here this section starts at the end of the ram segment.
|
||||
*/
|
||||
_estack = ORIGIN(RAM) + LENGTH(RAM);
|
||||
|
||||
}
|
||||
|
||||
/*** EOF **/
|
||||
|
||||
|
||||
@@ -1,154 +1,154 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2011 by Michael Fischer. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*****************************************************************************
|
||||
* History:
|
||||
*
|
||||
* 22.05.2011 mifi First Version
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* In this linker script there is no heap available.
|
||||
* The stack start at the end of the ram segment.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Take a look in the "The GNU linker" manual, here you get
|
||||
* the following information about the "MEMORY":
|
||||
*
|
||||
* "The MEMORY command describes the location and size of
|
||||
* blocks of memory in the target."
|
||||
*/
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00400000, LENGTH = 256K
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 48K
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* And the "SECTION" is used for:
|
||||
*
|
||||
* "The SECTIONS command tells the linker how to map input
|
||||
* sections into output sections, and how to place the output
|
||||
* sections in memory.
|
||||
*/
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
/*
|
||||
* The ".text" section is used for the code, and
|
||||
* read only (.rodata) data. Even the vectors (.vectors)
|
||||
* MUST be saved at the start of this section.
|
||||
*/
|
||||
.text :
|
||||
{
|
||||
FILL(0xFFFF)
|
||||
|
||||
CREATE_OBJECT_SYMBOLS
|
||||
|
||||
*(.bootrodata)
|
||||
*(.bootrodata.*)
|
||||
|
||||
. = ALIGN(32768); /* Align the start of the exidx part */
|
||||
_stext = .; /* Provide the name for the start of this section */
|
||||
|
||||
KEEP(*(.vectors))
|
||||
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the exidx part */
|
||||
*(.ARM.exidx)
|
||||
*(.ARM.exidx.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the rodata part */
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > FLASH = 0
|
||||
_etext = .; /* Provide the name for the end of this section */
|
||||
|
||||
|
||||
/*
|
||||
* The ".data" section is used for initialized data
|
||||
* and for functions (.fastrun) which should be copied
|
||||
* from flash to ram. This functions will later be
|
||||
* executed from ram instead of flash.
|
||||
*/
|
||||
.data : AT (_etext)
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sdata = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the fastrun part */
|
||||
*(.fastrun)
|
||||
*(.fastrun.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_edata = .; /* Provide the name for the end of this section */
|
||||
|
||||
|
||||
/*
|
||||
* The ".bss" section is used for uninitialized data.
|
||||
* This section will be cleared by the startup code.
|
||||
*/
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sbss = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_ebss = .; /* Provide the name for the end of this section */
|
||||
|
||||
|
||||
/*
|
||||
* The ".stack" section is our stack.
|
||||
* Here this section starts at the end of the ram segment.
|
||||
*/
|
||||
_estack = ORIGIN(RAM) + LENGTH(RAM);
|
||||
|
||||
}
|
||||
|
||||
/*** EOF **/
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2011 by Michael Fischer. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*****************************************************************************
|
||||
* History:
|
||||
*
|
||||
* 22.05.2011 mifi First Version
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* In this linker script there is no heap available.
|
||||
* The stack start at the end of the ram segment.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Take a look in the "The GNU linker" manual, here you get
|
||||
* the following information about the "MEMORY":
|
||||
*
|
||||
* "The MEMORY command describes the location and size of
|
||||
* blocks of memory in the target."
|
||||
*/
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00400000, LENGTH = 256K
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 48K
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* And the "SECTION" is used for:
|
||||
*
|
||||
* "The SECTIONS command tells the linker how to map input
|
||||
* sections into output sections, and how to place the output
|
||||
* sections in memory.
|
||||
*/
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
/*
|
||||
* The ".text" section is used for the code, and
|
||||
* read only (.rodata) data. Even the vectors (.vectors)
|
||||
* MUST be saved at the start of this section.
|
||||
*/
|
||||
.text :
|
||||
{
|
||||
FILL(0xFFFF)
|
||||
|
||||
CREATE_OBJECT_SYMBOLS
|
||||
|
||||
*(.bootrodata)
|
||||
*(.bootrodata.*)
|
||||
|
||||
. = ALIGN(32768); /* Align the start of the exidx part */
|
||||
_stext = .; /* Provide the name for the start of this section */
|
||||
|
||||
KEEP(*(.vectors))
|
||||
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the exidx part */
|
||||
*(.ARM.exidx)
|
||||
*(.ARM.exidx.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the rodata part */
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > FLASH = 0
|
||||
_etext = .; /* Provide the name for the end of this section */
|
||||
|
||||
|
||||
/*
|
||||
* The ".data" section is used for initialized data
|
||||
* and for functions (.fastrun) which should be copied
|
||||
* from flash to ram. This functions will later be
|
||||
* executed from ram instead of flash.
|
||||
*/
|
||||
.data : AT (_etext)
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sdata = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the fastrun part */
|
||||
*(.fastrun)
|
||||
*(.fastrun.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_edata = .; /* Provide the name for the end of this section */
|
||||
|
||||
|
||||
/*
|
||||
* The ".bss" section is used for uninitialized data.
|
||||
* This section will be cleared by the startup code.
|
||||
*/
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sbss = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_ebss = .; /* Provide the name for the end of this section */
|
||||
|
||||
|
||||
/*
|
||||
* The ".stack" section is our stack.
|
||||
* Here this section starts at the end of the ram segment.
|
||||
*/
|
||||
_estack = ORIGIN(RAM) + LENGTH(RAM);
|
||||
|
||||
}
|
||||
|
||||
/*** EOF **/
|
||||
|
||||
|
||||
@@ -1,156 +1,156 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2011 by Michael Fischer. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*****************************************************************************
|
||||
* History:
|
||||
*
|
||||
* 22.05.2011 mifi First Version
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* In this linker script there is no heap available.
|
||||
* The stack start at the end of the ram segment.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Take a look in the "The GNU linker" manual, here you get
|
||||
* the following information about the "MEMORY":
|
||||
*
|
||||
* "The MEMORY command describes the location and size of
|
||||
* blocks of memory in the target."
|
||||
*/
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00400000, LENGTH = 512K
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* And the "SECTION" is used for:
|
||||
*
|
||||
* "The SECTIONS command tells the linker how to map input
|
||||
* sections into output sections, and how to place the output
|
||||
* sections in memory.
|
||||
*/
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
/*
|
||||
* The ".text" section is used for the code, and
|
||||
* read only (.rodata) data. Even the vectors (.vectors)
|
||||
* MUST be saved at the start of this section.
|
||||
*/
|
||||
.text :
|
||||
{
|
||||
FILL(0xFFFF)
|
||||
|
||||
CREATE_OBJECT_SYMBOLS
|
||||
|
||||
*(.bootrodata)
|
||||
*(.bootrodata.*)
|
||||
|
||||
. = ALIGN(32768); /* Align the start of the exidx part */
|
||||
_stext = .; /* Provide the name for the start of this section */
|
||||
KEEP(*(.vectors))
|
||||
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the exidx part */
|
||||
*(.ARM.exidx)
|
||||
*(.ARM.exidx.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the rodata part */
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > FLASH = 0
|
||||
_etext = .; /* Provide the name for the end of this section */
|
||||
|
||||
|
||||
/*
|
||||
* The ".data" section is used for initialized data
|
||||
* and for functions (.fastrun) which should be copied
|
||||
* from flash to ram. This functions will later be
|
||||
* executed from ram instead of flash.
|
||||
*/
|
||||
.data : AT (_etext)
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sdata = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the fastrun part */
|
||||
*(.fastrun)
|
||||
*(.fastrun.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_edata = .; /* Provide the name for the end of this section */
|
||||
|
||||
|
||||
/*
|
||||
* The ".bss" section is used for uninitialized data.
|
||||
* This section will be cleared by the startup code.
|
||||
*/
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sbss = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_ebss = .; /* Provide the name for the end of this section */
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
__end = .;
|
||||
_end = .;
|
||||
|
||||
/*
|
||||
* The ".stack" section is our stack.
|
||||
* Here this section starts at the end of the ram segment.
|
||||
*/
|
||||
_estack = ORIGIN(RAM) + LENGTH(RAM);
|
||||
|
||||
}
|
||||
|
||||
/*** EOF **/
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2011 by Michael Fischer. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*****************************************************************************
|
||||
* History:
|
||||
*
|
||||
* 22.05.2011 mifi First Version
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* In this linker script there is no heap available.
|
||||
* The stack start at the end of the ram segment.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Take a look in the "The GNU linker" manual, here you get
|
||||
* the following information about the "MEMORY":
|
||||
*
|
||||
* "The MEMORY command describes the location and size of
|
||||
* blocks of memory in the target."
|
||||
*/
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00400000, LENGTH = 512K
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* And the "SECTION" is used for:
|
||||
*
|
||||
* "The SECTIONS command tells the linker how to map input
|
||||
* sections into output sections, and how to place the output
|
||||
* sections in memory.
|
||||
*/
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
/*
|
||||
* The ".text" section is used for the code, and
|
||||
* read only (.rodata) data. Even the vectors (.vectors)
|
||||
* MUST be saved at the start of this section.
|
||||
*/
|
||||
.text :
|
||||
{
|
||||
FILL(0xFFFF)
|
||||
|
||||
CREATE_OBJECT_SYMBOLS
|
||||
|
||||
*(.bootrodata)
|
||||
*(.bootrodata.*)
|
||||
|
||||
. = ALIGN(32768); /* Align the start of the exidx part */
|
||||
_stext = .; /* Provide the name for the start of this section */
|
||||
KEEP(*(.vectors))
|
||||
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the exidx part */
|
||||
*(.ARM.exidx)
|
||||
*(.ARM.exidx.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the rodata part */
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > FLASH = 0
|
||||
_etext = .; /* Provide the name for the end of this section */
|
||||
|
||||
|
||||
/*
|
||||
* The ".data" section is used for initialized data
|
||||
* and for functions (.fastrun) which should be copied
|
||||
* from flash to ram. This functions will later be
|
||||
* executed from ram instead of flash.
|
||||
*/
|
||||
.data : AT (_etext)
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sdata = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the fastrun part */
|
||||
*(.fastrun)
|
||||
*(.fastrun.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_edata = .; /* Provide the name for the end of this section */
|
||||
|
||||
|
||||
/*
|
||||
* The ".bss" section is used for uninitialized data.
|
||||
* This section will be cleared by the startup code.
|
||||
*/
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sbss = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_ebss = .; /* Provide the name for the end of this section */
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
__end = .;
|
||||
_end = .;
|
||||
|
||||
/*
|
||||
* The ".stack" section is our stack.
|
||||
* Here this section starts at the end of the ram segment.
|
||||
*/
|
||||
_estack = ORIGIN(RAM) + LENGTH(RAM);
|
||||
|
||||
}
|
||||
|
||||
/*** EOF **/
|
||||
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define MCI_INITIAL_SPEED 400000
|
||||
|
||||
void init_SDcard()
|
||||
{
|
||||
#ifndef SIMU
|
||||
configure_pins( 0xFC000000, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_C | PIN_PORTA | PIN_NO_PULLUP ) ;
|
||||
configure_pins( PIO_PB7, PIN_INPUT | PIN_PORTB | PIN_NO_PULLUP | PIN_NO_PULLDOWN ) ;
|
||||
|
||||
unsigned short clkDiv;
|
||||
Hsmci *pMciHw = HSMCI ;
|
||||
|
||||
/* Enable the MCI peripheral */
|
||||
PMC->PMC_PCER0 |= 1 << ID_HSMCI ; // Enable peripheral clock to HSMCI
|
||||
pMciHw->HSMCI_CR = HSMCI_CR_SWRST; /* Reset the MCI */
|
||||
pMciHw->HSMCI_CR = HSMCI_CR_MCIDIS | HSMCI_CR_PWSDIS; /* Disable the MCI */
|
||||
pMciHw->HSMCI_IDR = 0xFFFFFFFF; /* Disable all the interrupts */
|
||||
pMciHw->HSMCI_DTOR = HSMCI_DTOR_DTOCYC_Msk | HSMCI_DTOR_DTOMUL_Msk ; /* Set the Data Timeout Register */
|
||||
pMciHw->HSMCI_CSTOR = HSMCI_CSTOR_CSTOCYC_Msk | HSMCI_CSTOR_CSTOMUL_Msk ; /* CSTOR ? */
|
||||
/* Set the Mode Register: 400KHz for MCK = 48MHz (CLKDIV = 58) */
|
||||
clkDiv = 45; // (Master_frequency / (MCI_INITIAL_SPEED * 2)) - 1;
|
||||
pMciHw->HSMCI_MR = clkDiv | (7 << 8) ;
|
||||
|
||||
/* Set the SDCard Register 1-bit, slot A */
|
||||
pMciHw->HSMCI_SDCR = HSMCI_SDCR_SDCSEL_SLOTA | HSMCI_SDCR_SDCBUS_1 ;
|
||||
/* Enable the MCI and the Power Saving */
|
||||
pMciHw->HSMCI_CR = HSMCI_CR_MCIEN/* | HSMCI_CR_PWSEN */;
|
||||
/* Configure MCI */
|
||||
pMciHw->HSMCI_CFG = HSMCI_CFG_FIFOMODE | HSMCI_CFG_FERRCTRL;
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define MCI_INITIAL_SPEED 400000
|
||||
|
||||
void init_SDcard()
|
||||
{
|
||||
#ifndef SIMU
|
||||
configure_pins( 0xFC000000, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_C | PIN_PORTA | PIN_NO_PULLUP ) ;
|
||||
configure_pins( PIO_PB7, PIN_INPUT | PIN_PORTB | PIN_NO_PULLUP | PIN_NO_PULLDOWN ) ;
|
||||
|
||||
unsigned short clkDiv;
|
||||
Hsmci *pMciHw = HSMCI ;
|
||||
|
||||
/* Enable the MCI peripheral */
|
||||
PMC->PMC_PCER0 |= 1 << ID_HSMCI ; // Enable peripheral clock to HSMCI
|
||||
pMciHw->HSMCI_CR = HSMCI_CR_SWRST; /* Reset the MCI */
|
||||
pMciHw->HSMCI_CR = HSMCI_CR_MCIDIS | HSMCI_CR_PWSDIS; /* Disable the MCI */
|
||||
pMciHw->HSMCI_IDR = 0xFFFFFFFF; /* Disable all the interrupts */
|
||||
pMciHw->HSMCI_DTOR = HSMCI_DTOR_DTOCYC_Msk | HSMCI_DTOR_DTOMUL_Msk ; /* Set the Data Timeout Register */
|
||||
pMciHw->HSMCI_CSTOR = HSMCI_CSTOR_CSTOCYC_Msk | HSMCI_CSTOR_CSTOMUL_Msk ; /* CSTOR ? */
|
||||
/* Set the Mode Register: 400KHz for MCK = 48MHz (CLKDIV = 58) */
|
||||
clkDiv = 45; // (Master_frequency / (MCI_INITIAL_SPEED * 2)) - 1;
|
||||
pMciHw->HSMCI_MR = clkDiv | (7 << 8) ;
|
||||
|
||||
/* Set the SDCard Register 1-bit, slot A */
|
||||
pMciHw->HSMCI_SDCR = HSMCI_SDCR_SDCSEL_SLOTA | HSMCI_SDCR_SDCBUS_1 ;
|
||||
/* Enable the MCI and the Power Saving */
|
||||
pMciHw->HSMCI_CR = HSMCI_CR_MCIEN/* | HSMCI_CR_PWSEN */;
|
||||
/* Configure MCI */
|
||||
pMciHw->HSMCI_CFG = HSMCI_CFG_FIFOMODE | HSMCI_CFG_FERRCTRL;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,119 +1,119 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
/** Usart Hw interface used by the console (UART0). */
|
||||
#define SECOND_SERIAL_UART UART0
|
||||
/** Usart Hw ID used by the console (UART0). */
|
||||
#define SECOND_SERIAL_ID ID_UART0
|
||||
/** Pins description corresponding to Rxd,Txd, (UART pins) */
|
||||
#define SECOND_SERIAL_PINS {PINS_UART}
|
||||
|
||||
Fifo<uint8_t, 512> serial2RxFifo;
|
||||
|
||||
#if !defined(SIMU)
|
||||
/*
|
||||
* Outputs a character on the UART line.
|
||||
*
|
||||
* This function is synchronous (i.e. uses polling).
|
||||
* c Character to send.
|
||||
*/
|
||||
void serial2Putc(const char c)
|
||||
{
|
||||
Uart *pUart = SECOND_SERIAL_UART;
|
||||
|
||||
/* Wait for the transmitter to be ready */
|
||||
while ( (pUart->UART_SR & UART_SR_TXEMPTY) == 0 ) ;
|
||||
|
||||
/* Send character */
|
||||
pUart->UART_THR = c;
|
||||
}
|
||||
|
||||
uint8_t serial2TracesEnabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a UART peripheral with the specified parameters.
|
||||
*
|
||||
* baudrate Baudrate at which the UART should operate (in Hz).
|
||||
* masterClock Frequency of the system master clock (in Hz).
|
||||
* uses PA9 and PA10, RXD2 and TXD2
|
||||
*/
|
||||
void SECOND_UART_Configure(uint32_t baudrate, uint32_t masterClock)
|
||||
{
|
||||
Uart *pUart = SECOND_SERIAL_UART;
|
||||
|
||||
/* Configure PIO */
|
||||
configure_pins( (PIO_PA9 | PIO_PA10), PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA | PIN_NO_PULLUP ) ;
|
||||
|
||||
/* Configure PMC */
|
||||
PMC->PMC_PCER0 = 1 << SECOND_SERIAL_ID;
|
||||
|
||||
/* Reset and disable receiver & transmitter */
|
||||
pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX
|
||||
| UART_CR_RXDIS | UART_CR_TXDIS;
|
||||
|
||||
/* Configure mode */
|
||||
pUart->UART_MR = 0x800 ; // NORMAL, No Parity
|
||||
|
||||
/* Configure baudrate */
|
||||
/* Asynchronous, no oversampling */
|
||||
pUart->UART_BRGR = (masterClock / baudrate) / 16;
|
||||
|
||||
/* Disable PDC channel */
|
||||
pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
|
||||
|
||||
/* Enable receiver and transmitter */
|
||||
pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN;
|
||||
|
||||
pUart->UART_IER = UART_IER_RXRDY;
|
||||
NVIC_EnableIRQ(UART0_IRQn);
|
||||
}
|
||||
|
||||
void SECOND_UART_Stop()
|
||||
{
|
||||
SECOND_SERIAL_UART->UART_IDR = UART_IDR_RXRDY ;
|
||||
NVIC_DisableIRQ(UART0_IRQn) ;
|
||||
}
|
||||
|
||||
extern "C" void UART0_IRQHandler()
|
||||
{
|
||||
serial2RxFifo.push(SECOND_SERIAL_UART->UART_RHR);
|
||||
}
|
||||
#else
|
||||
#define SECOND_UART_Configure(...)
|
||||
#endif
|
||||
|
||||
#if defined(TELEMETRY_FRSKY)
|
||||
void serial2TelemetryInit(unsigned int /*protocol*/)
|
||||
{
|
||||
SECOND_UART_Configure(FRSKY_D_BAUDRATE, Master_frequency);
|
||||
// startPdcUsartReceive();
|
||||
}
|
||||
|
||||
bool telemetrySecondPortReceive(uint8_t & data)
|
||||
{
|
||||
return serial2RxFifo.pop(data);
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
/** Usart Hw interface used by the console (UART0). */
|
||||
#define SECOND_SERIAL_UART UART0
|
||||
/** Usart Hw ID used by the console (UART0). */
|
||||
#define SECOND_SERIAL_ID ID_UART0
|
||||
/** Pins description corresponding to Rxd,Txd, (UART pins) */
|
||||
#define SECOND_SERIAL_PINS {PINS_UART}
|
||||
|
||||
Fifo<uint8_t, 512> serial2RxFifo;
|
||||
|
||||
#if !defined(SIMU)
|
||||
/*
|
||||
* Outputs a character on the UART line.
|
||||
*
|
||||
* This function is synchronous (i.e. uses polling).
|
||||
* c Character to send.
|
||||
*/
|
||||
void serial2Putc(const char c)
|
||||
{
|
||||
Uart *pUart = SECOND_SERIAL_UART;
|
||||
|
||||
/* Wait for the transmitter to be ready */
|
||||
while ( (pUart->UART_SR & UART_SR_TXEMPTY) == 0 ) ;
|
||||
|
||||
/* Send character */
|
||||
pUart->UART_THR = c;
|
||||
}
|
||||
|
||||
uint8_t serial2TracesEnabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a UART peripheral with the specified parameters.
|
||||
*
|
||||
* baudrate Baudrate at which the UART should operate (in Hz).
|
||||
* masterClock Frequency of the system master clock (in Hz).
|
||||
* uses PA9 and PA10, RXD2 and TXD2
|
||||
*/
|
||||
void SECOND_UART_Configure(uint32_t baudrate, uint32_t masterClock)
|
||||
{
|
||||
Uart *pUart = SECOND_SERIAL_UART;
|
||||
|
||||
/* Configure PIO */
|
||||
configure_pins( (PIO_PA9 | PIO_PA10), PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA | PIN_NO_PULLUP ) ;
|
||||
|
||||
/* Configure PMC */
|
||||
PMC->PMC_PCER0 = 1 << SECOND_SERIAL_ID;
|
||||
|
||||
/* Reset and disable receiver & transmitter */
|
||||
pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX
|
||||
| UART_CR_RXDIS | UART_CR_TXDIS;
|
||||
|
||||
/* Configure mode */
|
||||
pUart->UART_MR = 0x800 ; // NORMAL, No Parity
|
||||
|
||||
/* Configure baudrate */
|
||||
/* Asynchronous, no oversampling */
|
||||
pUart->UART_BRGR = (masterClock / baudrate) / 16;
|
||||
|
||||
/* Disable PDC channel */
|
||||
pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
|
||||
|
||||
/* Enable receiver and transmitter */
|
||||
pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN;
|
||||
|
||||
pUart->UART_IER = UART_IER_RXRDY;
|
||||
NVIC_EnableIRQ(UART0_IRQn);
|
||||
}
|
||||
|
||||
void SECOND_UART_Stop()
|
||||
{
|
||||
SECOND_SERIAL_UART->UART_IDR = UART_IDR_RXRDY ;
|
||||
NVIC_DisableIRQ(UART0_IRQn) ;
|
||||
}
|
||||
|
||||
extern "C" void UART0_IRQHandler()
|
||||
{
|
||||
serial2RxFifo.push(SECOND_SERIAL_UART->UART_RHR);
|
||||
}
|
||||
#else
|
||||
#define SECOND_UART_Configure(...)
|
||||
#endif
|
||||
|
||||
#if defined(TELEMETRY_FRSKY)
|
||||
void serial2TelemetryInit(unsigned int /*protocol*/)
|
||||
{
|
||||
SECOND_UART_Configure(FRSKY_D_BAUDRATE, Master_frequency);
|
||||
// startPdcUsartReceive();
|
||||
}
|
||||
|
||||
bool telemetrySecondPortReceive(uint8_t & data)
|
||||
{
|
||||
return serial2RxFifo.pop(data);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,162 +1,162 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBConfigurationDescriptor implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBConfigurationDescriptor class.
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Headers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBConfigurationDescriptor.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Returns the total length of a configuration, i.e. including the
|
||||
/// descriptors following it.
|
||||
/// \param configuration Pointer to a USBConfigurationDescriptor instance.
|
||||
/// \return Total length (in bytes) of the configuration.
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned int USBConfigurationDescriptor_GetTotalLength(
|
||||
const USBConfigurationDescriptor *configuration)
|
||||
{
|
||||
return configuration->wTotalLength;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Returns the number of interfaces in a configuration.
|
||||
/// \param configuration Pointer to a USBConfigurationDescriptor instance.
|
||||
/// \return Number of interfaces in configuration.
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned char USBConfigurationDescriptor_GetNumInterfaces(
|
||||
const USBConfigurationDescriptor *configuration)
|
||||
{
|
||||
return configuration->bNumInterfaces;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Indicates if the device is self-powered when in a given configuration.
|
||||
/// \param configuration Pointer to a USBConfigurationDescriptor instance.
|
||||
/// \return 1 if the device is self-powered when in the given configuration;
|
||||
/// otherwise 0.
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned char USBConfigurationDescriptor_IsSelfPowered(
|
||||
const USBConfigurationDescriptor *configuration)
|
||||
{
|
||||
if ((configuration->bmAttributes & (1 << 6)) != 0) {
|
||||
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Parses the given Configuration descriptor (followed by relevant
|
||||
/// interface, endpoint and class-specific descriptors) into three arrays.
|
||||
/// *Each array must have its size equal or greater to the number of
|
||||
/// descriptors it stores plus one*. A null-value is inserted after the last
|
||||
/// descriptor of each type to indicate the array end.
|
||||
///
|
||||
/// Note that if the pointer to an array is null (0), nothing is stored in
|
||||
/// it.
|
||||
/// \param configuration Pointer to the start of the whole Configuration
|
||||
/// descriptor.
|
||||
/// \param interfaces Pointer to the Interface descriptor array.
|
||||
/// \param endpoints Pointer to the Endpoint descriptor array.
|
||||
/// \param others Pointer to the class-specific descriptor array.
|
||||
//-----------------------------------------------------------------------------
|
||||
void USBConfigurationDescriptor_Parse(
|
||||
const USBConfigurationDescriptor *configuration,
|
||||
USBInterfaceDescriptor **interfaces,
|
||||
USBEndpointDescriptor **endpoints,
|
||||
USBGenericDescriptor **others)
|
||||
{
|
||||
// Get size of configuration to parse
|
||||
int size = USBConfigurationDescriptor_GetTotalLength(configuration);
|
||||
size -= sizeof(USBConfigurationDescriptor);
|
||||
|
||||
// Start parsing descriptors
|
||||
USBGenericDescriptor *descriptor = (USBGenericDescriptor *) configuration;
|
||||
while (size > 0) {
|
||||
|
||||
// Get next descriptor
|
||||
descriptor = USBGenericDescriptor_GetNextDescriptor(descriptor);
|
||||
size -= USBGenericDescriptor_GetLength(descriptor);
|
||||
|
||||
// Store descriptor in correponding array
|
||||
if (USBGenericDescriptor_GetType(descriptor)
|
||||
== USBGenericDescriptor_INTERFACE) {
|
||||
|
||||
if (interfaces) {
|
||||
|
||||
*interfaces = (USBInterfaceDescriptor *) descriptor;
|
||||
interfaces++;
|
||||
}
|
||||
}
|
||||
else if (USBGenericDescriptor_GetType(descriptor)
|
||||
== USBGenericDescriptor_ENDPOINT) {
|
||||
|
||||
if (endpoints) {
|
||||
|
||||
*endpoints = (USBEndpointDescriptor *) descriptor;
|
||||
endpoints++;
|
||||
}
|
||||
}
|
||||
else if (others) {
|
||||
|
||||
*others = descriptor;
|
||||
others++;
|
||||
}
|
||||
}
|
||||
|
||||
// Null-terminate arrays
|
||||
if (interfaces) {
|
||||
|
||||
*interfaces = 0;
|
||||
}
|
||||
if (endpoints) {
|
||||
|
||||
*endpoints = 0;
|
||||
}
|
||||
if (others) {
|
||||
|
||||
*others = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBConfigurationDescriptor implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBConfigurationDescriptor class.
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Headers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBConfigurationDescriptor.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Returns the total length of a configuration, i.e. including the
|
||||
/// descriptors following it.
|
||||
/// \param configuration Pointer to a USBConfigurationDescriptor instance.
|
||||
/// \return Total length (in bytes) of the configuration.
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned int USBConfigurationDescriptor_GetTotalLength(
|
||||
const USBConfigurationDescriptor *configuration)
|
||||
{
|
||||
return configuration->wTotalLength;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Returns the number of interfaces in a configuration.
|
||||
/// \param configuration Pointer to a USBConfigurationDescriptor instance.
|
||||
/// \return Number of interfaces in configuration.
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned char USBConfigurationDescriptor_GetNumInterfaces(
|
||||
const USBConfigurationDescriptor *configuration)
|
||||
{
|
||||
return configuration->bNumInterfaces;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Indicates if the device is self-powered when in a given configuration.
|
||||
/// \param configuration Pointer to a USBConfigurationDescriptor instance.
|
||||
/// \return 1 if the device is self-powered when in the given configuration;
|
||||
/// otherwise 0.
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned char USBConfigurationDescriptor_IsSelfPowered(
|
||||
const USBConfigurationDescriptor *configuration)
|
||||
{
|
||||
if ((configuration->bmAttributes & (1 << 6)) != 0) {
|
||||
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Parses the given Configuration descriptor (followed by relevant
|
||||
/// interface, endpoint and class-specific descriptors) into three arrays.
|
||||
/// *Each array must have its size equal or greater to the number of
|
||||
/// descriptors it stores plus one*. A null-value is inserted after the last
|
||||
/// descriptor of each type to indicate the array end.
|
||||
///
|
||||
/// Note that if the pointer to an array is null (0), nothing is stored in
|
||||
/// it.
|
||||
/// \param configuration Pointer to the start of the whole Configuration
|
||||
/// descriptor.
|
||||
/// \param interfaces Pointer to the Interface descriptor array.
|
||||
/// \param endpoints Pointer to the Endpoint descriptor array.
|
||||
/// \param others Pointer to the class-specific descriptor array.
|
||||
//-----------------------------------------------------------------------------
|
||||
void USBConfigurationDescriptor_Parse(
|
||||
const USBConfigurationDescriptor *configuration,
|
||||
USBInterfaceDescriptor **interfaces,
|
||||
USBEndpointDescriptor **endpoints,
|
||||
USBGenericDescriptor **others)
|
||||
{
|
||||
// Get size of configuration to parse
|
||||
int size = USBConfigurationDescriptor_GetTotalLength(configuration);
|
||||
size -= sizeof(USBConfigurationDescriptor);
|
||||
|
||||
// Start parsing descriptors
|
||||
USBGenericDescriptor *descriptor = (USBGenericDescriptor *) configuration;
|
||||
while (size > 0) {
|
||||
|
||||
// Get next descriptor
|
||||
descriptor = USBGenericDescriptor_GetNextDescriptor(descriptor);
|
||||
size -= USBGenericDescriptor_GetLength(descriptor);
|
||||
|
||||
// Store descriptor in correponding array
|
||||
if (USBGenericDescriptor_GetType(descriptor)
|
||||
== USBGenericDescriptor_INTERFACE) {
|
||||
|
||||
if (interfaces) {
|
||||
|
||||
*interfaces = (USBInterfaceDescriptor *) descriptor;
|
||||
interfaces++;
|
||||
}
|
||||
}
|
||||
else if (USBGenericDescriptor_GetType(descriptor)
|
||||
== USBGenericDescriptor_ENDPOINT) {
|
||||
|
||||
if (endpoints) {
|
||||
|
||||
*endpoints = (USBEndpointDescriptor *) descriptor;
|
||||
endpoints++;
|
||||
}
|
||||
}
|
||||
else if (others) {
|
||||
|
||||
*others = descriptor;
|
||||
others++;
|
||||
}
|
||||
}
|
||||
|
||||
// Null-terminate arrays
|
||||
if (interfaces) {
|
||||
|
||||
*interfaces = 0;
|
||||
}
|
||||
if (endpoints) {
|
||||
|
||||
*endpoints = 0;
|
||||
}
|
||||
if (others) {
|
||||
|
||||
*others = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,150 +1,150 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
!!!Purpose
|
||||
|
||||
Definitions and methods for USB configuration descriptor structures
|
||||
described by the USB specification.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Declare USBConfigurationDescriptor instance as a part
|
||||
of the configuration descriptors of a USB device.
|
||||
-# To get useful information (field values) from the defined USB device
|
||||
configuration descriptor, use
|
||||
- USBConfigurationDescriptor_GetTotalLength
|
||||
- USBConfigurationDescriptor_GetNumInterfaces
|
||||
- USBConfigurationDescriptor_IsSelfPowered
|
||||
-# To pase the defined USB device configuration descriptor, use
|
||||
- USBConfigurationDescriptor_Parse
|
||||
*/
|
||||
|
||||
#ifndef USBCONFIGURATIONDESCRIPTOR_H
|
||||
#define USBCONFIGURATIONDESCRIPTOR_H
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Headers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBEndpointDescriptor.h"
|
||||
#include "../../../usb/common/core/USBGenericDescriptor.h"
|
||||
#include "../../../usb/common/core/USBInterfaceDescriptor.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// \page "USB device Attributes"
|
||||
///
|
||||
/// This page lists the codes of the usb attributes.
|
||||
///
|
||||
/// !Attributes
|
||||
/// - USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
|
||||
/// - USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP
|
||||
/// - USBConfigurationDescriptor_BUSPOWERED_RWAKEUP
|
||||
/// - USBConfigurationDescriptor_SELFPOWERED_RWAKEUP
|
||||
/// - USBConfigurationDescriptor_POWER
|
||||
|
||||
/// Device is bus-powered and not support remote wake-up.
|
||||
#define USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP 0x80
|
||||
/// Device is self-powered and not support remote wake-up.
|
||||
#define USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP 0xC0
|
||||
/// Device is bus-powered and supports remote wake-up.
|
||||
#define USBConfigurationDescriptor_BUSPOWERED_RWAKEUP 0xA0
|
||||
/// Device is self-powered and supports remote wake-up.
|
||||
#define USBConfigurationDescriptor_SELFPOWERED_RWAKEUP 0xE0
|
||||
|
||||
/// Calculates the value of the power consumption field given the value in mA.
|
||||
/// \param power The power consumption value in mA
|
||||
/// \return The value that should be set to the field in descriptor
|
||||
#define USBConfigurationDescriptor_POWER(power) (power / 2)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// USB standard configuration descriptor structure.
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBDESC_CONFIGURATION of "USB Descriptor types").
|
||||
unsigned char bDescriptorType;
|
||||
/// Length of all descriptors returned along with this configuration
|
||||
/// descriptor.
|
||||
unsigned short wTotalLength;
|
||||
/// Number of interfaces in this configuration.
|
||||
unsigned char bNumInterfaces;
|
||||
/// Value for selecting this configuration.
|
||||
unsigned char bConfigurationValue;
|
||||
/// Index of the configuration string descriptor.
|
||||
unsigned char iConfiguration;
|
||||
/// Configuration characteristics.
|
||||
unsigned char bmAttributes;
|
||||
/// Maximum power consumption of the device when in this configuration.
|
||||
unsigned char bMaxPower;
|
||||
|
||||
} __attribute__ ((packed)) USBConfigurationDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
extern unsigned int USBConfigurationDescriptor_GetTotalLength(
|
||||
const USBConfigurationDescriptor *configuration);
|
||||
|
||||
extern unsigned char USBConfigurationDescriptor_GetNumInterfaces(
|
||||
const USBConfigurationDescriptor *configuration);
|
||||
|
||||
extern unsigned char USBConfigurationDescriptor_IsSelfPowered(
|
||||
const USBConfigurationDescriptor *configuration);
|
||||
|
||||
extern void USBConfigurationDescriptor_Parse(
|
||||
const USBConfigurationDescriptor *configuration,
|
||||
USBInterfaceDescriptor **interfaces,
|
||||
USBEndpointDescriptor **endpoints,
|
||||
USBGenericDescriptor **others);
|
||||
|
||||
#endif //#ifndef USBCONFIGURATIONDESCRIPTOR_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
!!!Purpose
|
||||
|
||||
Definitions and methods for USB configuration descriptor structures
|
||||
described by the USB specification.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Declare USBConfigurationDescriptor instance as a part
|
||||
of the configuration descriptors of a USB device.
|
||||
-# To get useful information (field values) from the defined USB device
|
||||
configuration descriptor, use
|
||||
- USBConfigurationDescriptor_GetTotalLength
|
||||
- USBConfigurationDescriptor_GetNumInterfaces
|
||||
- USBConfigurationDescriptor_IsSelfPowered
|
||||
-# To pase the defined USB device configuration descriptor, use
|
||||
- USBConfigurationDescriptor_Parse
|
||||
*/
|
||||
|
||||
#ifndef USBCONFIGURATIONDESCRIPTOR_H
|
||||
#define USBCONFIGURATIONDESCRIPTOR_H
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Headers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBEndpointDescriptor.h"
|
||||
#include "../../../usb/common/core/USBGenericDescriptor.h"
|
||||
#include "../../../usb/common/core/USBInterfaceDescriptor.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// \page "USB device Attributes"
|
||||
///
|
||||
/// This page lists the codes of the usb attributes.
|
||||
///
|
||||
/// !Attributes
|
||||
/// - USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
|
||||
/// - USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP
|
||||
/// - USBConfigurationDescriptor_BUSPOWERED_RWAKEUP
|
||||
/// - USBConfigurationDescriptor_SELFPOWERED_RWAKEUP
|
||||
/// - USBConfigurationDescriptor_POWER
|
||||
|
||||
/// Device is bus-powered and not support remote wake-up.
|
||||
#define USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP 0x80
|
||||
/// Device is self-powered and not support remote wake-up.
|
||||
#define USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP 0xC0
|
||||
/// Device is bus-powered and supports remote wake-up.
|
||||
#define USBConfigurationDescriptor_BUSPOWERED_RWAKEUP 0xA0
|
||||
/// Device is self-powered and supports remote wake-up.
|
||||
#define USBConfigurationDescriptor_SELFPOWERED_RWAKEUP 0xE0
|
||||
|
||||
/// Calculates the value of the power consumption field given the value in mA.
|
||||
/// \param power The power consumption value in mA
|
||||
/// \return The value that should be set to the field in descriptor
|
||||
#define USBConfigurationDescriptor_POWER(power) (power / 2)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// USB standard configuration descriptor structure.
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBDESC_CONFIGURATION of "USB Descriptor types").
|
||||
unsigned char bDescriptorType;
|
||||
/// Length of all descriptors returned along with this configuration
|
||||
/// descriptor.
|
||||
unsigned short wTotalLength;
|
||||
/// Number of interfaces in this configuration.
|
||||
unsigned char bNumInterfaces;
|
||||
/// Value for selecting this configuration.
|
||||
unsigned char bConfigurationValue;
|
||||
/// Index of the configuration string descriptor.
|
||||
unsigned char iConfiguration;
|
||||
/// Configuration characteristics.
|
||||
unsigned char bmAttributes;
|
||||
/// Maximum power consumption of the device when in this configuration.
|
||||
unsigned char bMaxPower;
|
||||
|
||||
} __attribute__ ((packed)) USBConfigurationDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
extern unsigned int USBConfigurationDescriptor_GetTotalLength(
|
||||
const USBConfigurationDescriptor *configuration);
|
||||
|
||||
extern unsigned char USBConfigurationDescriptor_GetNumInterfaces(
|
||||
const USBConfigurationDescriptor *configuration);
|
||||
|
||||
extern unsigned char USBConfigurationDescriptor_IsSelfPowered(
|
||||
const USBConfigurationDescriptor *configuration);
|
||||
|
||||
extern void USBConfigurationDescriptor_Parse(
|
||||
const USBConfigurationDescriptor *configuration,
|
||||
USBInterfaceDescriptor **interfaces,
|
||||
USBEndpointDescriptor **endpoints,
|
||||
USBGenericDescriptor **others);
|
||||
|
||||
#endif //#ifndef USBCONFIGURATIONDESCRIPTOR_H
|
||||
|
||||
|
||||
@@ -1,125 +1,125 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
!!!Purpose
|
||||
|
||||
Class for manipulating USB device descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- Declare a USBDeviceDescriptor instance as the device descriptor of a
|
||||
USB device.
|
||||
*/
|
||||
|
||||
#ifndef USBDEVICEDESCRIPTOR_H
|
||||
#define USBDEVICEDESCRIPTOR_H
|
||||
|
||||
#include "board_lowlevel.h"
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB release numbers"
|
||||
///
|
||||
/// This page lists the codes of USB release numbers.
|
||||
///
|
||||
/// !Code
|
||||
/// - USBDeviceDescriptor_USB2_00
|
||||
|
||||
/// The device supports USB 2.00.
|
||||
#define USBDeviceDescriptor_USB2_00 0x0200
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// USB standard device descriptor structure.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of this descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBGenericDescriptor_DEVICE).
|
||||
unsigned char bDescriptorType;
|
||||
/// USB specification release number in BCD format.
|
||||
unsigned short bcdUSB;
|
||||
/// Device class code.
|
||||
unsigned char bDeviceClass;
|
||||
/// Device subclass code.
|
||||
unsigned char bDeviceSubClass;
|
||||
/// Device protocol code.
|
||||
unsigned char bDeviceProtocol;
|
||||
/// Maximum packet size of endpoint 0 (in bytes).
|
||||
unsigned char bMaxPacketSize0;
|
||||
/// Vendor ID.
|
||||
unsigned short idVendor;
|
||||
/// Product ID.
|
||||
unsigned short idProduct;
|
||||
/// Device release number in BCD format.
|
||||
unsigned short bcdDevice;
|
||||
/// Index of the manufacturer string descriptor.
|
||||
unsigned char iManufacturer;
|
||||
/// Index of the product string descriptor.
|
||||
unsigned char iProduct;
|
||||
/// Index of the serial number string descriptor.
|
||||
unsigned char iSerialNumber;
|
||||
/// Number of possible configurations for the device.
|
||||
unsigned char bNumConfigurations;
|
||||
|
||||
} __attribute__ ((packed)) USBDeviceDescriptor; // GCC
|
||||
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
typedef struct {
|
||||
|
||||
/// Size of this descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBGenericDescriptor_OTG).
|
||||
unsigned char bDescriptorType;
|
||||
/// Attribute Fields D7�2: Reserved D1: HNP support D0: SRP support
|
||||
unsigned char bmAttributes;
|
||||
|
||||
} __attribute__ ((packed)) USBOtgDescriptor; // GCC
|
||||
#endif
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBDEVICEDESCRIPTOR_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
!!!Purpose
|
||||
|
||||
Class for manipulating USB device descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- Declare a USBDeviceDescriptor instance as the device descriptor of a
|
||||
USB device.
|
||||
*/
|
||||
|
||||
#ifndef USBDEVICEDESCRIPTOR_H
|
||||
#define USBDEVICEDESCRIPTOR_H
|
||||
|
||||
#include "board_lowlevel.h"
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB release numbers"
|
||||
///
|
||||
/// This page lists the codes of USB release numbers.
|
||||
///
|
||||
/// !Code
|
||||
/// - USBDeviceDescriptor_USB2_00
|
||||
|
||||
/// The device supports USB 2.00.
|
||||
#define USBDeviceDescriptor_USB2_00 0x0200
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// USB standard device descriptor structure.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of this descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBGenericDescriptor_DEVICE).
|
||||
unsigned char bDescriptorType;
|
||||
/// USB specification release number in BCD format.
|
||||
unsigned short bcdUSB;
|
||||
/// Device class code.
|
||||
unsigned char bDeviceClass;
|
||||
/// Device subclass code.
|
||||
unsigned char bDeviceSubClass;
|
||||
/// Device protocol code.
|
||||
unsigned char bDeviceProtocol;
|
||||
/// Maximum packet size of endpoint 0 (in bytes).
|
||||
unsigned char bMaxPacketSize0;
|
||||
/// Vendor ID.
|
||||
unsigned short idVendor;
|
||||
/// Product ID.
|
||||
unsigned short idProduct;
|
||||
/// Device release number in BCD format.
|
||||
unsigned short bcdDevice;
|
||||
/// Index of the manufacturer string descriptor.
|
||||
unsigned char iManufacturer;
|
||||
/// Index of the product string descriptor.
|
||||
unsigned char iProduct;
|
||||
/// Index of the serial number string descriptor.
|
||||
unsigned char iSerialNumber;
|
||||
/// Number of possible configurations for the device.
|
||||
unsigned char bNumConfigurations;
|
||||
|
||||
} __attribute__ ((packed)) USBDeviceDescriptor; // GCC
|
||||
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
typedef struct {
|
||||
|
||||
/// Size of this descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBGenericDescriptor_OTG).
|
||||
unsigned char bDescriptorType;
|
||||
/// Attribute Fields D7�2: Reserved D1: HNP support D0: SRP support
|
||||
unsigned char bmAttributes;
|
||||
|
||||
} __attribute__ ((packed)) USBOtgDescriptor; // GCC
|
||||
#endif
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBDEVICEDESCRIPTOR_H
|
||||
|
||||
|
||||
@@ -1,89 +1,89 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Class for manipulating USB device qualifier descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- Declare a USBDeviceQualifierDescriptor instance as the device qualifier
|
||||
descriptor of a USB device.
|
||||
*/
|
||||
|
||||
#ifndef USBDEVICEQUALIFIERDESCRIPTOR_H
|
||||
#define USBDEVICEQUALIFIERDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Alternate device descriptor indicating the capabilities of the device
|
||||
/// in full-speed, if currently in high-speed; or in high-speed, if it is
|
||||
/// currently in full-speed. Only relevant for devices supporting the
|
||||
/// high-speed mode.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBDESC_DEVICE_QUALIFIER or "USB device types").
|
||||
unsigned char bDescriptorType;
|
||||
/// USB specification release number (in BCD format).
|
||||
unsigned short bcdUSB;
|
||||
/// Device class code.
|
||||
unsigned char bDeviceClass;
|
||||
/// Device subclass code.
|
||||
unsigned char bDeviceSubClass;
|
||||
/// Device protocol code.
|
||||
unsigned char bDeviceProtocol;
|
||||
/// Maximum packet size of endpoint 0.
|
||||
unsigned char bMaxPacketSize0;
|
||||
/// Number of possible configurations for the device.
|
||||
unsigned char bNumConfigurations;
|
||||
/// Reserved.
|
||||
unsigned char bReserved;
|
||||
|
||||
} __attribute__ ((packed)) USBDeviceQualifierDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBDEVICEQUALIFIERDESCRIPTOR_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Class for manipulating USB device qualifier descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- Declare a USBDeviceQualifierDescriptor instance as the device qualifier
|
||||
descriptor of a USB device.
|
||||
*/
|
||||
|
||||
#ifndef USBDEVICEQUALIFIERDESCRIPTOR_H
|
||||
#define USBDEVICEQUALIFIERDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Alternate device descriptor indicating the capabilities of the device
|
||||
/// in full-speed, if currently in high-speed; or in high-speed, if it is
|
||||
/// currently in full-speed. Only relevant for devices supporting the
|
||||
/// high-speed mode.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBDESC_DEVICE_QUALIFIER or "USB device types").
|
||||
unsigned char bDescriptorType;
|
||||
/// USB specification release number (in BCD format).
|
||||
unsigned short bcdUSB;
|
||||
/// Device class code.
|
||||
unsigned char bDeviceClass;
|
||||
/// Device subclass code.
|
||||
unsigned char bDeviceSubClass;
|
||||
/// Device protocol code.
|
||||
unsigned char bDeviceProtocol;
|
||||
/// Maximum packet size of endpoint 0.
|
||||
unsigned char bMaxPacketSize0;
|
||||
/// Number of possible configurations for the device.
|
||||
unsigned char bNumConfigurations;
|
||||
/// Reserved.
|
||||
unsigned char bReserved;
|
||||
|
||||
} __attribute__ ((packed)) USBDeviceQualifierDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBDEVICEQUALIFIERDESCRIPTOR_H
|
||||
|
||||
|
||||
@@ -1,109 +1,109 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBEndpointDescriptor implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBEndpointDescriptor class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBEndpointDescriptor.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the number of an endpoint given its descriptor.
|
||||
/// \param endpoint Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Endpoint number.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetNumber(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->bEndpointAddress & 0xF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the direction of an endpoint given its descriptor.
|
||||
/// \param endpoint Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Endpoint direction (see <Endpoint directions>).
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetDirection(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
if ((endpoint->bEndpointAddress & 0x80) != 0) {
|
||||
|
||||
return USBEndpointDescriptor_IN;
|
||||
}
|
||||
else {
|
||||
|
||||
return USBEndpointDescriptor_OUT;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of an endpoint given its descriptor.
|
||||
/// \param endpoint Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Endpoint type (see <Endpoint types>).
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetType(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->bmAttributes & 0x3;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the maximum size of a packet (in bytes) on an endpoint given
|
||||
/// its descriptor.
|
||||
/// \param endpoint - Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Maximum packet size of endpoint.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBEndpointDescriptor_GetMaxPacketSize(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->wMaxPacketSize;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the polling interval on an endpoint given its descriptor.
|
||||
/// \param endpoint - Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Polling interval of endpoint.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetInterval(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->bInterval;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBEndpointDescriptor implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBEndpointDescriptor class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBEndpointDescriptor.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the number of an endpoint given its descriptor.
|
||||
/// \param endpoint Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Endpoint number.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetNumber(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->bEndpointAddress & 0xF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the direction of an endpoint given its descriptor.
|
||||
/// \param endpoint Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Endpoint direction (see <Endpoint directions>).
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetDirection(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
if ((endpoint->bEndpointAddress & 0x80) != 0) {
|
||||
|
||||
return USBEndpointDescriptor_IN;
|
||||
}
|
||||
else {
|
||||
|
||||
return USBEndpointDescriptor_OUT;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of an endpoint given its descriptor.
|
||||
/// \param endpoint Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Endpoint type (see <Endpoint types>).
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetType(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->bmAttributes & 0x3;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the maximum size of a packet (in bytes) on an endpoint given
|
||||
/// its descriptor.
|
||||
/// \param endpoint - Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Maximum packet size of endpoint.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBEndpointDescriptor_GetMaxPacketSize(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->wMaxPacketSize;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the polling interval on an endpoint given its descriptor.
|
||||
/// \param endpoint - Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Polling interval of endpoint.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetInterval(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->bInterval;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,224 +1,224 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for handling USB endpoint descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Declare USBEndpointDescriptor instance as a part of the
|
||||
configuration descriptors of a USB device.
|
||||
-# To get useful information (field values) from the defined USB device
|
||||
endpoint descriptor (to configure hardware for endpoints, etc), use
|
||||
- USBEndpointDescriptor_GetNumber
|
||||
- USBEndpointDescriptor_GetDirection
|
||||
- USBEndpointDescriptor_GetType
|
||||
- USBEndpointDescriptor_GetMaxPacketSize
|
||||
*/
|
||||
|
||||
#ifndef USBENDPOINTDESCRIPTOR_H
|
||||
#define USBENDPOINTDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint definitions"
|
||||
///
|
||||
/// This page lists definitions and macro for endpoint descriptors.
|
||||
///
|
||||
/// - USB Endpoint directions
|
||||
/// - USBEndpointDescriptor_OUT
|
||||
/// - USBEndpointDescriptor_IN
|
||||
///
|
||||
/// - USB Endpoint types
|
||||
/// - USBEndpointDescriptor_CONTROL
|
||||
/// - USBEndpointDescriptor_ISOCHRONOUS
|
||||
/// - USBEndpointDescriptor_BULK
|
||||
/// - USBEndpointDescriptor_INTERRUPT
|
||||
///
|
||||
/// - USB Endpoint maximun sizes
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS
|
||||
///
|
||||
/// - USB Endpoint address define
|
||||
/// - USBEndpointDescriptor_ADDRESS
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint directions"
|
||||
///
|
||||
/// This page lists definitions of USB endpoint directions.
|
||||
///
|
||||
/// !Directions
|
||||
/// - USBEndpointDescriptor_OUT
|
||||
/// - USBEndpointDescriptor_IN
|
||||
|
||||
/// Endpoint receives data from the host.
|
||||
#define USBEndpointDescriptor_OUT 0
|
||||
/// Endpoint sends data to the host.
|
||||
#define USBEndpointDescriptor_IN 1
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint types"
|
||||
///
|
||||
/// This page lists definitions of USB endpoint types.
|
||||
///
|
||||
/// !Types
|
||||
/// - USBEndpointDescriptor_CONTROL
|
||||
/// - USBEndpointDescriptor_ISOCHRONOUS
|
||||
/// - USBEndpointDescriptor_BULK
|
||||
/// - USBEndpointDescriptor_INTERRUPT
|
||||
|
||||
/// Control endpoint type.
|
||||
#define USBEndpointDescriptor_CONTROL 0
|
||||
/// Isochronous endpoint type.
|
||||
#define USBEndpointDescriptor_ISOCHRONOUS 1
|
||||
/// Bulk endpoint type.
|
||||
#define USBEndpointDescriptor_BULK 2
|
||||
/// Interrupt endpoint type.
|
||||
#define USBEndpointDescriptor_INTERRUPT 3
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint maximun sizes"
|
||||
///
|
||||
/// This page lists definitions of USB endpoint maximun sizes.
|
||||
///
|
||||
/// !Sizes
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS
|
||||
|
||||
/// Maximum size for a full-speed control endpoint.
|
||||
#define USBEndpointDescriptor_MAXCTRLSIZE_FS 64
|
||||
/// Maximum size for a high-speed control endpoint.
|
||||
#define USBEndpointDescriptor_MAXCTRLSIZE_HS 64
|
||||
/// Maximum size for a full-speed bulk endpoint.
|
||||
#define USBEndpointDescriptor_MAXBULKSIZE_FS 64
|
||||
/// Maximum size for a high-speed bulk endpoint.
|
||||
#define USBEndpointDescriptor_MAXBULKSIZE_HS 512
|
||||
/// Maximum size for a full-speed interrupt endpoint.
|
||||
#define USBEndpointDescriptor_MAXINTERRUPTSIZE_FS 64
|
||||
/// Maximum size for a high-speed interrupt endpoint.
|
||||
#define USBEndpointDescriptor_MAXINTERRUPTSIZE_HS 1024
|
||||
/// Maximum size for a full-speed isochronous endpoint.
|
||||
#define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS 1023
|
||||
/// Maximum size for a high-speed isochronous endpoint.
|
||||
#define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS 1024
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint address define"
|
||||
///
|
||||
/// This page lists macro for USB endpoint address definition.
|
||||
///
|
||||
/// !Macro
|
||||
/// - USBEndpointDescriptor_ADDRESS
|
||||
|
||||
/// Calculates the address of an endpoint given its number and direction
|
||||
/// \param direction USB endpoint direction definition
|
||||
/// \param number USB endpoint number
|
||||
/// \return The value used to set the endpoint descriptor based on input number
|
||||
/// and direction
|
||||
#define USBEndpointDescriptor_ADDRESS(direction, number) \
|
||||
(((direction & 0x01) << 7) | (number & 0xF))
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// USB standard endpoint descriptor structure.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (<USBGenericDescriptor_ENDPOINT>).
|
||||
unsigned char bDescriptorType;
|
||||
/// Address and direction of the endpoint.
|
||||
unsigned char bEndpointAddress;
|
||||
/// Endpoint type and additional characteristics (for isochronous endpoints).
|
||||
unsigned char bmAttributes;
|
||||
/// Maximum packet size (in bytes) of the endpoint.
|
||||
unsigned short wMaxPacketSize;
|
||||
/// Polling rate of the endpoint.
|
||||
unsigned char bInterval;
|
||||
|
||||
} __attribute__ ((packed)) USBEndpointDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetNumber(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetDirection(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetType(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned short USBEndpointDescriptor_GetMaxPacketSize(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetInterval(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
#endif //#ifndef USBENDPOINTDESCRIPTOR_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for handling USB endpoint descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Declare USBEndpointDescriptor instance as a part of the
|
||||
configuration descriptors of a USB device.
|
||||
-# To get useful information (field values) from the defined USB device
|
||||
endpoint descriptor (to configure hardware for endpoints, etc), use
|
||||
- USBEndpointDescriptor_GetNumber
|
||||
- USBEndpointDescriptor_GetDirection
|
||||
- USBEndpointDescriptor_GetType
|
||||
- USBEndpointDescriptor_GetMaxPacketSize
|
||||
*/
|
||||
|
||||
#ifndef USBENDPOINTDESCRIPTOR_H
|
||||
#define USBENDPOINTDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint definitions"
|
||||
///
|
||||
/// This page lists definitions and macro for endpoint descriptors.
|
||||
///
|
||||
/// - USB Endpoint directions
|
||||
/// - USBEndpointDescriptor_OUT
|
||||
/// - USBEndpointDescriptor_IN
|
||||
///
|
||||
/// - USB Endpoint types
|
||||
/// - USBEndpointDescriptor_CONTROL
|
||||
/// - USBEndpointDescriptor_ISOCHRONOUS
|
||||
/// - USBEndpointDescriptor_BULK
|
||||
/// - USBEndpointDescriptor_INTERRUPT
|
||||
///
|
||||
/// - USB Endpoint maximun sizes
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS
|
||||
///
|
||||
/// - USB Endpoint address define
|
||||
/// - USBEndpointDescriptor_ADDRESS
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint directions"
|
||||
///
|
||||
/// This page lists definitions of USB endpoint directions.
|
||||
///
|
||||
/// !Directions
|
||||
/// - USBEndpointDescriptor_OUT
|
||||
/// - USBEndpointDescriptor_IN
|
||||
|
||||
/// Endpoint receives data from the host.
|
||||
#define USBEndpointDescriptor_OUT 0
|
||||
/// Endpoint sends data to the host.
|
||||
#define USBEndpointDescriptor_IN 1
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint types"
|
||||
///
|
||||
/// This page lists definitions of USB endpoint types.
|
||||
///
|
||||
/// !Types
|
||||
/// - USBEndpointDescriptor_CONTROL
|
||||
/// - USBEndpointDescriptor_ISOCHRONOUS
|
||||
/// - USBEndpointDescriptor_BULK
|
||||
/// - USBEndpointDescriptor_INTERRUPT
|
||||
|
||||
/// Control endpoint type.
|
||||
#define USBEndpointDescriptor_CONTROL 0
|
||||
/// Isochronous endpoint type.
|
||||
#define USBEndpointDescriptor_ISOCHRONOUS 1
|
||||
/// Bulk endpoint type.
|
||||
#define USBEndpointDescriptor_BULK 2
|
||||
/// Interrupt endpoint type.
|
||||
#define USBEndpointDescriptor_INTERRUPT 3
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint maximun sizes"
|
||||
///
|
||||
/// This page lists definitions of USB endpoint maximun sizes.
|
||||
///
|
||||
/// !Sizes
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS
|
||||
|
||||
/// Maximum size for a full-speed control endpoint.
|
||||
#define USBEndpointDescriptor_MAXCTRLSIZE_FS 64
|
||||
/// Maximum size for a high-speed control endpoint.
|
||||
#define USBEndpointDescriptor_MAXCTRLSIZE_HS 64
|
||||
/// Maximum size for a full-speed bulk endpoint.
|
||||
#define USBEndpointDescriptor_MAXBULKSIZE_FS 64
|
||||
/// Maximum size for a high-speed bulk endpoint.
|
||||
#define USBEndpointDescriptor_MAXBULKSIZE_HS 512
|
||||
/// Maximum size for a full-speed interrupt endpoint.
|
||||
#define USBEndpointDescriptor_MAXINTERRUPTSIZE_FS 64
|
||||
/// Maximum size for a high-speed interrupt endpoint.
|
||||
#define USBEndpointDescriptor_MAXINTERRUPTSIZE_HS 1024
|
||||
/// Maximum size for a full-speed isochronous endpoint.
|
||||
#define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS 1023
|
||||
/// Maximum size for a high-speed isochronous endpoint.
|
||||
#define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS 1024
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint address define"
|
||||
///
|
||||
/// This page lists macro for USB endpoint address definition.
|
||||
///
|
||||
/// !Macro
|
||||
/// - USBEndpointDescriptor_ADDRESS
|
||||
|
||||
/// Calculates the address of an endpoint given its number and direction
|
||||
/// \param direction USB endpoint direction definition
|
||||
/// \param number USB endpoint number
|
||||
/// \return The value used to set the endpoint descriptor based on input number
|
||||
/// and direction
|
||||
#define USBEndpointDescriptor_ADDRESS(direction, number) \
|
||||
(((direction & 0x01) << 7) | (number & 0xF))
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// USB standard endpoint descriptor structure.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (<USBGenericDescriptor_ENDPOINT>).
|
||||
unsigned char bDescriptorType;
|
||||
/// Address and direction of the endpoint.
|
||||
unsigned char bEndpointAddress;
|
||||
/// Endpoint type and additional characteristics (for isochronous endpoints).
|
||||
unsigned char bmAttributes;
|
||||
/// Maximum packet size (in bytes) of the endpoint.
|
||||
unsigned short wMaxPacketSize;
|
||||
/// Polling rate of the endpoint.
|
||||
unsigned char bInterval;
|
||||
|
||||
} __attribute__ ((packed)) USBEndpointDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetNumber(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetDirection(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetType(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned short USBEndpointDescriptor_GetMaxPacketSize(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetInterval(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
#endif //#ifndef USBENDPOINTDESCRIPTOR_H
|
||||
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBFeatureRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBFeatureRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBFeatureRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the feature selector of a given CLEAR_FEATURE or SET_FEATURE
|
||||
/// request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Feature selector.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBFeatureRequest_GetFeatureSelector(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return USBGenericRequest_GetValue(request);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates the test that the device must undertake following a
|
||||
/// SET_FEATURE request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Test selector.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBFeatureRequest_GetTestSelector(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return (USBGenericRequest_GetIndex(request) >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBFeatureRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBFeatureRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBFeatureRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the feature selector of a given CLEAR_FEATURE or SET_FEATURE
|
||||
/// request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Feature selector.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBFeatureRequest_GetFeatureSelector(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return USBGenericRequest_GetValue(request);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates the test that the device must undertake following a
|
||||
/// SET_FEATURE request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Test selector.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBFeatureRequest_GetTestSelector(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return (USBGenericRequest_GetIndex(request) >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,146 +1,146 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for manipulating CLEAR_FEATURE and SET_FEATURE
|
||||
requests.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- To get USB feature request information (field values) from the
|
||||
USBGenericRequest instance, use
|
||||
- USBFeatureRequest_GetFeatureSelector
|
||||
- USBFeatureRequest_GetTestSelector
|
||||
*/
|
||||
|
||||
#ifndef USBFEATUREREQUEST_H
|
||||
#define USBFEATUREREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Feature Request definitions"
|
||||
///
|
||||
/// This page lists codes of USB Feature Request
|
||||
///
|
||||
/// - USB Feature selectors
|
||||
/// - USBFeatureRequest_ENDPOINTHALT
|
||||
/// - USBFeatureRequest_DEVICEREMOTEWAKEUP
|
||||
/// - USBFeatureRequest_TESTMODE
|
||||
///
|
||||
/// - USB Test mode selectors
|
||||
/// - USBFeatureRequest_TESTJ
|
||||
/// - USBFeatureRequest_TESTK
|
||||
/// - USBFeatureRequest_TESTSE0NAK
|
||||
/// - USBFeatureRequest_TESTPACKET
|
||||
/// - USBFeatureRequest_TESTFORCEENABLE
|
||||
/// - USBFeatureRequest_TESTSENDZLP
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Feature selectors"
|
||||
///
|
||||
/// This page lists codes of USB feature selectors.
|
||||
///
|
||||
/// !Selectors
|
||||
/// - USBFeatureRequest_ENDPOINTHALT
|
||||
/// - USBFeatureRequest_DEVICEREMOTEWAKEUP
|
||||
/// - USBFeatureRequest_TESTMODE
|
||||
|
||||
/// Halt feature of an endpoint.
|
||||
#define USBFeatureRequest_ENDPOINTHALT 0
|
||||
/// Remote wake-up feature of the device.
|
||||
#define USBFeatureRequest_DEVICEREMOTEWAKEUP 1
|
||||
/// Test mode of the device.
|
||||
#define USBFeatureRequest_TESTMODE 2
|
||||
/// OTG set feature
|
||||
#define USBFeatureRequest_OTG 0x0B
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// On The Go Feature Selectors
|
||||
/// b_hnp_enable 3
|
||||
/// a_hnp_support 4
|
||||
/// a_alt_hnp_support 5
|
||||
#define USBFeatureRequest_OTG_B_HNP_ENABLE 3
|
||||
#define USBFeatureRequest_OTG_A_HNP_SUPPORT 4
|
||||
#define USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT 5
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Test mode selectors"
|
||||
///
|
||||
/// This page lists codes of USB high speed test mode selectors.
|
||||
///
|
||||
/// !Selectors
|
||||
/// - USBFeatureRequest_TESTJ
|
||||
/// - USBFeatureRequest_TESTK
|
||||
/// - USBFeatureRequest_TESTSE0NAK
|
||||
/// - USBFeatureRequest_TESTPACKET
|
||||
/// - USBFeatureRequest_TESTFORCEENABLE
|
||||
/// - USBFeatureRequest_TESTSENDZLP
|
||||
|
||||
/// Tests the high-output drive level on the D+ line.
|
||||
#define USBFeatureRequest_TESTJ 1
|
||||
/// Tests the high-output drive level on the D- line.
|
||||
#define USBFeatureRequest_TESTK 2
|
||||
/// Tests the output impedance, low-level output voltage and loading
|
||||
/// characteristics.
|
||||
#define USBFeatureRequest_TESTSE0NAK 3
|
||||
/// Tests rise and fall times, eye patterns and jitter.
|
||||
#define USBFeatureRequest_TESTPACKET 4
|
||||
/// Tests the hub disconnect detection.
|
||||
#define USBFeatureRequest_TESTFORCEENABLE 5
|
||||
/// Send a ZLP in Test Mode.
|
||||
#define USBFeatureRequest_TESTSENDZLP 6
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBFeatureRequest_GetFeatureSelector(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
|
||||
extern unsigned char USBFeatureRequest_GetTestSelector(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBFEATUREREQUEST_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for manipulating CLEAR_FEATURE and SET_FEATURE
|
||||
requests.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- To get USB feature request information (field values) from the
|
||||
USBGenericRequest instance, use
|
||||
- USBFeatureRequest_GetFeatureSelector
|
||||
- USBFeatureRequest_GetTestSelector
|
||||
*/
|
||||
|
||||
#ifndef USBFEATUREREQUEST_H
|
||||
#define USBFEATUREREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Feature Request definitions"
|
||||
///
|
||||
/// This page lists codes of USB Feature Request
|
||||
///
|
||||
/// - USB Feature selectors
|
||||
/// - USBFeatureRequest_ENDPOINTHALT
|
||||
/// - USBFeatureRequest_DEVICEREMOTEWAKEUP
|
||||
/// - USBFeatureRequest_TESTMODE
|
||||
///
|
||||
/// - USB Test mode selectors
|
||||
/// - USBFeatureRequest_TESTJ
|
||||
/// - USBFeatureRequest_TESTK
|
||||
/// - USBFeatureRequest_TESTSE0NAK
|
||||
/// - USBFeatureRequest_TESTPACKET
|
||||
/// - USBFeatureRequest_TESTFORCEENABLE
|
||||
/// - USBFeatureRequest_TESTSENDZLP
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Feature selectors"
|
||||
///
|
||||
/// This page lists codes of USB feature selectors.
|
||||
///
|
||||
/// !Selectors
|
||||
/// - USBFeatureRequest_ENDPOINTHALT
|
||||
/// - USBFeatureRequest_DEVICEREMOTEWAKEUP
|
||||
/// - USBFeatureRequest_TESTMODE
|
||||
|
||||
/// Halt feature of an endpoint.
|
||||
#define USBFeatureRequest_ENDPOINTHALT 0
|
||||
/// Remote wake-up feature of the device.
|
||||
#define USBFeatureRequest_DEVICEREMOTEWAKEUP 1
|
||||
/// Test mode of the device.
|
||||
#define USBFeatureRequest_TESTMODE 2
|
||||
/// OTG set feature
|
||||
#define USBFeatureRequest_OTG 0x0B
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// On The Go Feature Selectors
|
||||
/// b_hnp_enable 3
|
||||
/// a_hnp_support 4
|
||||
/// a_alt_hnp_support 5
|
||||
#define USBFeatureRequest_OTG_B_HNP_ENABLE 3
|
||||
#define USBFeatureRequest_OTG_A_HNP_SUPPORT 4
|
||||
#define USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT 5
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Test mode selectors"
|
||||
///
|
||||
/// This page lists codes of USB high speed test mode selectors.
|
||||
///
|
||||
/// !Selectors
|
||||
/// - USBFeatureRequest_TESTJ
|
||||
/// - USBFeatureRequest_TESTK
|
||||
/// - USBFeatureRequest_TESTSE0NAK
|
||||
/// - USBFeatureRequest_TESTPACKET
|
||||
/// - USBFeatureRequest_TESTFORCEENABLE
|
||||
/// - USBFeatureRequest_TESTSENDZLP
|
||||
|
||||
/// Tests the high-output drive level on the D+ line.
|
||||
#define USBFeatureRequest_TESTJ 1
|
||||
/// Tests the high-output drive level on the D- line.
|
||||
#define USBFeatureRequest_TESTK 2
|
||||
/// Tests the output impedance, low-level output voltage and loading
|
||||
/// characteristics.
|
||||
#define USBFeatureRequest_TESTSE0NAK 3
|
||||
/// Tests rise and fall times, eye patterns and jitter.
|
||||
#define USBFeatureRequest_TESTPACKET 4
|
||||
/// Tests the hub disconnect detection.
|
||||
#define USBFeatureRequest_TESTFORCEENABLE 5
|
||||
/// Send a ZLP in Test Mode.
|
||||
#define USBFeatureRequest_TESTSENDZLP 6
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBFeatureRequest_GetFeatureSelector(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
|
||||
extern unsigned char USBFeatureRequest_GetTestSelector(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBFEATUREREQUEST_H
|
||||
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBGenericDescriptor implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBGenericDescriptor class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericDescriptor.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the length of a descriptor.
|
||||
/// \param descriptor Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Length of descriptor in bytes.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int USBGenericDescriptor_GetLength(
|
||||
const USBGenericDescriptor *descriptor)
|
||||
{
|
||||
return descriptor->bLength;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of a descriptor.
|
||||
/// \param descriptor Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Type of descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericDescriptor_GetType(
|
||||
const USBGenericDescriptor *descriptor)
|
||||
{
|
||||
return descriptor->bDescriptorType;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns a pointer to the descriptor right after the given one, when
|
||||
/// parsing a Configuration descriptor.
|
||||
/// \param descriptor - Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Pointer to the next descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
|
||||
const USBGenericDescriptor *descriptor)
|
||||
{
|
||||
return (USBGenericDescriptor *)
|
||||
(((char *) descriptor) + USBGenericDescriptor_GetLength(descriptor));
|
||||
}
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBGenericDescriptor implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBGenericDescriptor class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericDescriptor.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the length of a descriptor.
|
||||
/// \param descriptor Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Length of descriptor in bytes.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int USBGenericDescriptor_GetLength(
|
||||
const USBGenericDescriptor *descriptor)
|
||||
{
|
||||
return descriptor->bLength;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of a descriptor.
|
||||
/// \param descriptor Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Type of descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericDescriptor_GetType(
|
||||
const USBGenericDescriptor *descriptor)
|
||||
{
|
||||
return descriptor->bDescriptorType;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns a pointer to the descriptor right after the given one, when
|
||||
/// parsing a Configuration descriptor.
|
||||
/// \param descriptor - Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Pointer to the next descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
|
||||
const USBGenericDescriptor *descriptor)
|
||||
{
|
||||
return (USBGenericDescriptor *)
|
||||
(((char *) descriptor) + USBGenericDescriptor_GetLength(descriptor));
|
||||
}
|
||||
|
||||
@@ -1,133 +1,133 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !!!Purpose
|
||||
///
|
||||
/// Definition of a generic USB descriptor class.
|
||||
///
|
||||
/// !!!Usage
|
||||
///
|
||||
/// -# Declare or access USB descriptors by USBGenericDescriptor instance.
|
||||
/// -# To get usful information (field values) from the USB descriptors, use
|
||||
/// - USBGenericDescriptor_GetLength
|
||||
/// - USBGenericDescriptor_GetType
|
||||
/// -# To scan the descriptors, use
|
||||
/// - USBGenericDescriptor_GetNextDescriptor
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef USBGENERICDESCRIPTOR_H
|
||||
#define USBGENERICDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Descriptor types"
|
||||
///
|
||||
/// This page lists the codes of the usb descriptor types
|
||||
///
|
||||
/// !Types
|
||||
/// - USBGenericDescriptor_DEVICE
|
||||
/// - USBGenericDescriptor_CONFIGURATION
|
||||
/// - USBGenericDescriptor_STRING
|
||||
/// - USBGenericDescriptor_INTERFACE
|
||||
/// - USBGenericDescriptor_ENDPOINT
|
||||
/// - USBGenericDescriptor_DEVICEQUALIFIER
|
||||
/// - USBGenericDescriptor_OTHERSPEEDCONFIGURATION
|
||||
/// - USBGenericDescriptor_INTERFACEPOWER
|
||||
/// - USBGenericDescriptor_OTG
|
||||
/// - USBGenericDescriptor_DEBUG
|
||||
/// - USBGenericDescriptor_INTERFACEASSOCIATION
|
||||
|
||||
/// Device descriptor type.
|
||||
#define USBGenericDescriptor_DEVICE 1
|
||||
/// Configuration descriptor type.
|
||||
#define USBGenericDescriptor_CONFIGURATION 2
|
||||
/// String descriptor type.
|
||||
#define USBGenericDescriptor_STRING 3
|
||||
/// Interface descriptor type.
|
||||
#define USBGenericDescriptor_INTERFACE 4
|
||||
/// Endpoint descriptor type.
|
||||
#define USBGenericDescriptor_ENDPOINT 5
|
||||
/// Device qualifier descriptor type.
|
||||
#define USBGenericDescriptor_DEVICEQUALIFIER 6
|
||||
/// Other speed configuration descriptor type.
|
||||
#define USBGenericDescriptor_OTHERSPEEDCONFIGURATION 7
|
||||
/// Interface power descriptor type.
|
||||
#define USBGenericDescriptor_INTERFACEPOWER 8
|
||||
/// On-The-Go descriptor type.
|
||||
#define USBGenericDescriptor_OTG 9
|
||||
/// Debug descriptor type.
|
||||
#define USBGenericDescriptor_DEBUG 10
|
||||
/// Interface association descriptor type.
|
||||
#define USBGenericDescriptor_INTERFACEASSOCIATION 11
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
/// Holds the few fields shared by all USB descriptors.
|
||||
typedef struct {
|
||||
|
||||
/// Length of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type.
|
||||
unsigned char bDescriptorType;
|
||||
|
||||
} __attribute__ ((packed)) USBGenericDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned int USBGenericDescriptor_GetLength(
|
||||
const USBGenericDescriptor *descriptor);
|
||||
|
||||
extern unsigned char USBGenericDescriptor_GetType(
|
||||
const USBGenericDescriptor *descriptor);
|
||||
|
||||
extern USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
|
||||
const USBGenericDescriptor *descriptor);
|
||||
|
||||
#endif //#ifndef USBGENERICDESCRIPTOR_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !!!Purpose
|
||||
///
|
||||
/// Definition of a generic USB descriptor class.
|
||||
///
|
||||
/// !!!Usage
|
||||
///
|
||||
/// -# Declare or access USB descriptors by USBGenericDescriptor instance.
|
||||
/// -# To get usful information (field values) from the USB descriptors, use
|
||||
/// - USBGenericDescriptor_GetLength
|
||||
/// - USBGenericDescriptor_GetType
|
||||
/// -# To scan the descriptors, use
|
||||
/// - USBGenericDescriptor_GetNextDescriptor
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef USBGENERICDESCRIPTOR_H
|
||||
#define USBGENERICDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Descriptor types"
|
||||
///
|
||||
/// This page lists the codes of the usb descriptor types
|
||||
///
|
||||
/// !Types
|
||||
/// - USBGenericDescriptor_DEVICE
|
||||
/// - USBGenericDescriptor_CONFIGURATION
|
||||
/// - USBGenericDescriptor_STRING
|
||||
/// - USBGenericDescriptor_INTERFACE
|
||||
/// - USBGenericDescriptor_ENDPOINT
|
||||
/// - USBGenericDescriptor_DEVICEQUALIFIER
|
||||
/// - USBGenericDescriptor_OTHERSPEEDCONFIGURATION
|
||||
/// - USBGenericDescriptor_INTERFACEPOWER
|
||||
/// - USBGenericDescriptor_OTG
|
||||
/// - USBGenericDescriptor_DEBUG
|
||||
/// - USBGenericDescriptor_INTERFACEASSOCIATION
|
||||
|
||||
/// Device descriptor type.
|
||||
#define USBGenericDescriptor_DEVICE 1
|
||||
/// Configuration descriptor type.
|
||||
#define USBGenericDescriptor_CONFIGURATION 2
|
||||
/// String descriptor type.
|
||||
#define USBGenericDescriptor_STRING 3
|
||||
/// Interface descriptor type.
|
||||
#define USBGenericDescriptor_INTERFACE 4
|
||||
/// Endpoint descriptor type.
|
||||
#define USBGenericDescriptor_ENDPOINT 5
|
||||
/// Device qualifier descriptor type.
|
||||
#define USBGenericDescriptor_DEVICEQUALIFIER 6
|
||||
/// Other speed configuration descriptor type.
|
||||
#define USBGenericDescriptor_OTHERSPEEDCONFIGURATION 7
|
||||
/// Interface power descriptor type.
|
||||
#define USBGenericDescriptor_INTERFACEPOWER 8
|
||||
/// On-The-Go descriptor type.
|
||||
#define USBGenericDescriptor_OTG 9
|
||||
/// Debug descriptor type.
|
||||
#define USBGenericDescriptor_DEBUG 10
|
||||
/// Interface association descriptor type.
|
||||
#define USBGenericDescriptor_INTERFACEASSOCIATION 11
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
/// Holds the few fields shared by all USB descriptors.
|
||||
typedef struct {
|
||||
|
||||
/// Length of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type.
|
||||
unsigned char bDescriptorType;
|
||||
|
||||
} __attribute__ ((packed)) USBGenericDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned int USBGenericDescriptor_GetLength(
|
||||
const USBGenericDescriptor *descriptor);
|
||||
|
||||
extern unsigned char USBGenericDescriptor_GetType(
|
||||
const USBGenericDescriptor *descriptor);
|
||||
|
||||
extern USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
|
||||
const USBGenericDescriptor *descriptor);
|
||||
|
||||
#endif //#ifndef USBGENERICDESCRIPTOR_H
|
||||
|
||||
|
||||
@@ -1,138 +1,138 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBGenericRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBGenericRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return "USB Request Types"
|
||||
//------------------------------------------------------------------------------
|
||||
extern unsigned char USBGenericRequest_GetType(const USBGenericRequest *request)
|
||||
{
|
||||
return ((request->bmRequestType >> 5) & 0x3);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the request code of the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Request code.
|
||||
/// \sa "USB Request Codes"
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetRequest(const USBGenericRequest *request)
|
||||
{
|
||||
return request->bRequest;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the wValue field of the given request.
|
||||
/// \param request - Pointer to a USBGenericRequest instance.
|
||||
/// \return Request value.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBGenericRequest_GetValue(const USBGenericRequest *request)
|
||||
{
|
||||
return request->wValue;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the wIndex field of the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Request index;
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBGenericRequest_GetIndex(const USBGenericRequest *request)
|
||||
{
|
||||
return request->wIndex;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the expected length of the data phase following a request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Length of data phase.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBGenericRequest_GetLength(const USBGenericRequest *request)
|
||||
{
|
||||
return request->wLength;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the endpoint number targetted by a given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Endpoint number.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetEndpointNumber(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return USBGenericRequest_GetIndex(request) & 0xF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the intended recipient of a given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Request recipient.
|
||||
/// \sa "USB Request Recipients"
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetRecipient(const USBGenericRequest *request)
|
||||
{
|
||||
// Recipient is in bits [0..4] of the bmRequestType field
|
||||
return request->bmRequestType & 0xF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the direction of the data transfer following the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Transfer direction.
|
||||
/// \sa "USB Request Directions"
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetDirection(const USBGenericRequest *request)
|
||||
{
|
||||
// Transfer direction is located in bit D7 of the bmRequestType field
|
||||
if ((request->bmRequestType & 0x80) != 0) {
|
||||
|
||||
return USBGenericRequest_IN;
|
||||
}
|
||||
else {
|
||||
|
||||
return USBGenericRequest_OUT;
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBGenericRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBGenericRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return "USB Request Types"
|
||||
//------------------------------------------------------------------------------
|
||||
extern unsigned char USBGenericRequest_GetType(const USBGenericRequest *request)
|
||||
{
|
||||
return ((request->bmRequestType >> 5) & 0x3);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the request code of the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Request code.
|
||||
/// \sa "USB Request Codes"
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetRequest(const USBGenericRequest *request)
|
||||
{
|
||||
return request->bRequest;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the wValue field of the given request.
|
||||
/// \param request - Pointer to a USBGenericRequest instance.
|
||||
/// \return Request value.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBGenericRequest_GetValue(const USBGenericRequest *request)
|
||||
{
|
||||
return request->wValue;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the wIndex field of the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Request index;
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBGenericRequest_GetIndex(const USBGenericRequest *request)
|
||||
{
|
||||
return request->wIndex;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the expected length of the data phase following a request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Length of data phase.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBGenericRequest_GetLength(const USBGenericRequest *request)
|
||||
{
|
||||
return request->wLength;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the endpoint number targetted by a given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Endpoint number.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetEndpointNumber(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return USBGenericRequest_GetIndex(request) & 0xF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the intended recipient of a given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Request recipient.
|
||||
/// \sa "USB Request Recipients"
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetRecipient(const USBGenericRequest *request)
|
||||
{
|
||||
// Recipient is in bits [0..4] of the bmRequestType field
|
||||
return request->bmRequestType & 0xF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the direction of the data transfer following the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Transfer direction.
|
||||
/// \sa "USB Request Directions"
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetDirection(const USBGenericRequest *request)
|
||||
{
|
||||
// Transfer direction is located in bit D7 of the bmRequestType field
|
||||
if ((request->bmRequestType & 0x80) != 0) {
|
||||
|
||||
return USBGenericRequest_IN;
|
||||
}
|
||||
else {
|
||||
|
||||
return USBGenericRequest_OUT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,244 +1,244 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of the USBGenericRequest class and its methods.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Declare or access USB requests by USBGenericRequest instance.
|
||||
-# To get usful information (field values) from the USB requests, use
|
||||
- USBGenericRequest_GetType
|
||||
- USBGenericRequest_GetRequest
|
||||
- USBGenericRequest_GetValue
|
||||
- USBGenericRequest_GetIndex
|
||||
- USBGenericRequest_GetLength
|
||||
- USBGenericRequest_GetEndpointNumber
|
||||
- USBGenericRequest_GetRecipient
|
||||
- USBGenericRequest_GetDirection
|
||||
*/
|
||||
|
||||
#ifndef USBGENERICREQUEST_H
|
||||
#define USBGENERICREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Generic Request definitions"
|
||||
///
|
||||
/// This page lists the codes of USB generic request.
|
||||
///
|
||||
/// - USB Request codes
|
||||
/// - USBGenericRequest_GETSTATUS
|
||||
/// - USBGenericRequest_CLEARFEATURE
|
||||
/// - USBGenericRequest_SETFEATURE
|
||||
/// - USBGenericRequest_SETADDRESS
|
||||
/// - USBGenericRequest_GETDESCRIPTOR
|
||||
/// - USBGenericRequest_SETDESCRIPTOR
|
||||
/// - USBGenericRequest_GETCONFIGURATION
|
||||
/// - USBGenericRequest_SETCONFIGURATION
|
||||
/// - USBGenericRequest_GETINTERFACE
|
||||
/// - USBGenericRequest_SETINTERFACE
|
||||
/// - USBGenericRequest_SYNCHFRAME
|
||||
///
|
||||
/// - USB Request Recipients
|
||||
/// - USBGenericRequest_DEVICE
|
||||
/// - USBGenericRequest_INTERFACE
|
||||
/// - USBGenericRequest_ENDPOINT
|
||||
/// - USBGenericRequest_OTHER
|
||||
///
|
||||
/// - USB Request Types
|
||||
/// - USBGenericRequest_STANDARD
|
||||
/// - USBGenericRequest_CLASS
|
||||
/// - USBGenericRequest_VENDOR
|
||||
///
|
||||
/// - USB Request Directions
|
||||
/// - USBGenericRequest_IN
|
||||
/// - USBGenericRequest_OUT
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request codes"
|
||||
///
|
||||
/// This page lists the USB generic request codes.
|
||||
///
|
||||
/// !Codes
|
||||
/// - USBGenericRequest_GETSTATUS
|
||||
/// - USBGenericRequest_CLEARFEATURE
|
||||
/// - USBGenericRequest_SETFEATURE
|
||||
/// - USBGenericRequest_SETADDRESS
|
||||
/// - USBGenericRequest_GETDESCRIPTOR
|
||||
/// - USBGenericRequest_SETDESCRIPTOR
|
||||
/// - USBGenericRequest_GETCONFIGURATION
|
||||
/// - USBGenericRequest_SETCONFIGURATION
|
||||
/// - USBGenericRequest_GETINTERFACE
|
||||
/// - USBGenericRequest_SETINTERFACE
|
||||
/// - USBGenericRequest_SYNCHFRAME
|
||||
|
||||
/// GET_STATUS request code.
|
||||
#define USBGenericRequest_GETSTATUS 0
|
||||
/// CLEAR_FEATURE request code.
|
||||
#define USBGenericRequest_CLEARFEATURE 1
|
||||
/// SET_FEATURE request code.
|
||||
#define USBGenericRequest_SETFEATURE 3
|
||||
/// SET_ADDRESS request code.
|
||||
#define USBGenericRequest_SETADDRESS 5
|
||||
/// GET_DESCRIPTOR request code.
|
||||
#define USBGenericRequest_GETDESCRIPTOR 6
|
||||
/// SET_DESCRIPTOR request code.
|
||||
#define USBGenericRequest_SETDESCRIPTOR 7
|
||||
/// GET_CONFIGURATION request code.
|
||||
#define USBGenericRequest_GETCONFIGURATION 8
|
||||
/// SET_CONFIGURATION request code.
|
||||
#define USBGenericRequest_SETCONFIGURATION 9
|
||||
/// GET_INTERFACE request code.
|
||||
#define USBGenericRequest_GETINTERFACE 10
|
||||
/// SET_INTERFACE request code.
|
||||
#define USBGenericRequest_SETINTERFACE 11
|
||||
/// SYNCH_FRAME request code.
|
||||
#define USBGenericRequest_SYNCHFRAME 12
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request Recipients"
|
||||
///
|
||||
/// This page lists codes of USB request recipients.
|
||||
///
|
||||
/// !Recipients
|
||||
/// - USBGenericRequest_DEVICE
|
||||
/// - USBGenericRequest_INTERFACE
|
||||
/// - USBGenericRequest_ENDPOINT
|
||||
/// - USBGenericRequest_OTHER
|
||||
|
||||
/// Recipient is the whole device.
|
||||
#define USBGenericRequest_DEVICE 0
|
||||
/// Recipient is an interface.
|
||||
#define USBGenericRequest_INTERFACE 1
|
||||
/// Recipient is an endpoint.
|
||||
#define USBGenericRequest_ENDPOINT 2
|
||||
/// Recipient is another entity.
|
||||
#define USBGenericRequest_OTHER 3
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request Types"
|
||||
///
|
||||
/// This page lists codes of USB request types.
|
||||
///
|
||||
/// !Types
|
||||
/// - USBGenericRequest_STANDARD
|
||||
/// - USBGenericRequest_CLASS
|
||||
/// - USBGenericRequest_VENDOR
|
||||
|
||||
/// Request is standard.
|
||||
#define USBGenericRequest_STANDARD 0
|
||||
/// Request is class-specific.
|
||||
#define USBGenericRequest_CLASS 1
|
||||
/// Request is vendor-specific.
|
||||
#define USBGenericRequest_VENDOR 2
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request Directions"
|
||||
///
|
||||
/// This page lists codes of USB request directions.
|
||||
///
|
||||
/// !Directions
|
||||
/// - USBGenericRequest_IN
|
||||
/// - USBGenericRequest_OUT
|
||||
|
||||
/// Transfer occurs from device to the host.
|
||||
#define USBGenericRequest_OUT 0
|
||||
/// Transfer occurs from the host to the device.
|
||||
#define USBGenericRequest_IN 1
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Generic USB SETUP request sent over Control endpoints.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Type of request
|
||||
/// \sa "USB Request Recipients"
|
||||
/// \sa "USB Request Types"
|
||||
/// \sa "USB Request Directions"
|
||||
unsigned char bmRequestType:8;
|
||||
/// Request code
|
||||
/// \sa "USB Request Codes"
|
||||
unsigned char bRequest:8;
|
||||
/// Request-specific value parameter.
|
||||
unsigned short wValue:16;
|
||||
/// Request-specific index parameter.
|
||||
unsigned short wIndex:16;
|
||||
/// Expected length (in bytes) of the data phase.
|
||||
unsigned short wLength:16;
|
||||
|
||||
} USBGenericRequest;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBGenericRequest_GetType(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
|
||||
extern unsigned char USBGenericRequest_GetRequest(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned short USBGenericRequest_GetValue(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned short USBGenericRequest_GetIndex(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned short USBGenericRequest_GetLength(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGenericRequest_GetEndpointNumber(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGenericRequest_GetRecipient(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGenericRequest_GetDirection(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBGENERICREQUEST_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of the USBGenericRequest class and its methods.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Declare or access USB requests by USBGenericRequest instance.
|
||||
-# To get usful information (field values) from the USB requests, use
|
||||
- USBGenericRequest_GetType
|
||||
- USBGenericRequest_GetRequest
|
||||
- USBGenericRequest_GetValue
|
||||
- USBGenericRequest_GetIndex
|
||||
- USBGenericRequest_GetLength
|
||||
- USBGenericRequest_GetEndpointNumber
|
||||
- USBGenericRequest_GetRecipient
|
||||
- USBGenericRequest_GetDirection
|
||||
*/
|
||||
|
||||
#ifndef USBGENERICREQUEST_H
|
||||
#define USBGENERICREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Generic Request definitions"
|
||||
///
|
||||
/// This page lists the codes of USB generic request.
|
||||
///
|
||||
/// - USB Request codes
|
||||
/// - USBGenericRequest_GETSTATUS
|
||||
/// - USBGenericRequest_CLEARFEATURE
|
||||
/// - USBGenericRequest_SETFEATURE
|
||||
/// - USBGenericRequest_SETADDRESS
|
||||
/// - USBGenericRequest_GETDESCRIPTOR
|
||||
/// - USBGenericRequest_SETDESCRIPTOR
|
||||
/// - USBGenericRequest_GETCONFIGURATION
|
||||
/// - USBGenericRequest_SETCONFIGURATION
|
||||
/// - USBGenericRequest_GETINTERFACE
|
||||
/// - USBGenericRequest_SETINTERFACE
|
||||
/// - USBGenericRequest_SYNCHFRAME
|
||||
///
|
||||
/// - USB Request Recipients
|
||||
/// - USBGenericRequest_DEVICE
|
||||
/// - USBGenericRequest_INTERFACE
|
||||
/// - USBGenericRequest_ENDPOINT
|
||||
/// - USBGenericRequest_OTHER
|
||||
///
|
||||
/// - USB Request Types
|
||||
/// - USBGenericRequest_STANDARD
|
||||
/// - USBGenericRequest_CLASS
|
||||
/// - USBGenericRequest_VENDOR
|
||||
///
|
||||
/// - USB Request Directions
|
||||
/// - USBGenericRequest_IN
|
||||
/// - USBGenericRequest_OUT
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request codes"
|
||||
///
|
||||
/// This page lists the USB generic request codes.
|
||||
///
|
||||
/// !Codes
|
||||
/// - USBGenericRequest_GETSTATUS
|
||||
/// - USBGenericRequest_CLEARFEATURE
|
||||
/// - USBGenericRequest_SETFEATURE
|
||||
/// - USBGenericRequest_SETADDRESS
|
||||
/// - USBGenericRequest_GETDESCRIPTOR
|
||||
/// - USBGenericRequest_SETDESCRIPTOR
|
||||
/// - USBGenericRequest_GETCONFIGURATION
|
||||
/// - USBGenericRequest_SETCONFIGURATION
|
||||
/// - USBGenericRequest_GETINTERFACE
|
||||
/// - USBGenericRequest_SETINTERFACE
|
||||
/// - USBGenericRequest_SYNCHFRAME
|
||||
|
||||
/// GET_STATUS request code.
|
||||
#define USBGenericRequest_GETSTATUS 0
|
||||
/// CLEAR_FEATURE request code.
|
||||
#define USBGenericRequest_CLEARFEATURE 1
|
||||
/// SET_FEATURE request code.
|
||||
#define USBGenericRequest_SETFEATURE 3
|
||||
/// SET_ADDRESS request code.
|
||||
#define USBGenericRequest_SETADDRESS 5
|
||||
/// GET_DESCRIPTOR request code.
|
||||
#define USBGenericRequest_GETDESCRIPTOR 6
|
||||
/// SET_DESCRIPTOR request code.
|
||||
#define USBGenericRequest_SETDESCRIPTOR 7
|
||||
/// GET_CONFIGURATION request code.
|
||||
#define USBGenericRequest_GETCONFIGURATION 8
|
||||
/// SET_CONFIGURATION request code.
|
||||
#define USBGenericRequest_SETCONFIGURATION 9
|
||||
/// GET_INTERFACE request code.
|
||||
#define USBGenericRequest_GETINTERFACE 10
|
||||
/// SET_INTERFACE request code.
|
||||
#define USBGenericRequest_SETINTERFACE 11
|
||||
/// SYNCH_FRAME request code.
|
||||
#define USBGenericRequest_SYNCHFRAME 12
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request Recipients"
|
||||
///
|
||||
/// This page lists codes of USB request recipients.
|
||||
///
|
||||
/// !Recipients
|
||||
/// - USBGenericRequest_DEVICE
|
||||
/// - USBGenericRequest_INTERFACE
|
||||
/// - USBGenericRequest_ENDPOINT
|
||||
/// - USBGenericRequest_OTHER
|
||||
|
||||
/// Recipient is the whole device.
|
||||
#define USBGenericRequest_DEVICE 0
|
||||
/// Recipient is an interface.
|
||||
#define USBGenericRequest_INTERFACE 1
|
||||
/// Recipient is an endpoint.
|
||||
#define USBGenericRequest_ENDPOINT 2
|
||||
/// Recipient is another entity.
|
||||
#define USBGenericRequest_OTHER 3
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request Types"
|
||||
///
|
||||
/// This page lists codes of USB request types.
|
||||
///
|
||||
/// !Types
|
||||
/// - USBGenericRequest_STANDARD
|
||||
/// - USBGenericRequest_CLASS
|
||||
/// - USBGenericRequest_VENDOR
|
||||
|
||||
/// Request is standard.
|
||||
#define USBGenericRequest_STANDARD 0
|
||||
/// Request is class-specific.
|
||||
#define USBGenericRequest_CLASS 1
|
||||
/// Request is vendor-specific.
|
||||
#define USBGenericRequest_VENDOR 2
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request Directions"
|
||||
///
|
||||
/// This page lists codes of USB request directions.
|
||||
///
|
||||
/// !Directions
|
||||
/// - USBGenericRequest_IN
|
||||
/// - USBGenericRequest_OUT
|
||||
|
||||
/// Transfer occurs from device to the host.
|
||||
#define USBGenericRequest_OUT 0
|
||||
/// Transfer occurs from the host to the device.
|
||||
#define USBGenericRequest_IN 1
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Generic USB SETUP request sent over Control endpoints.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Type of request
|
||||
/// \sa "USB Request Recipients"
|
||||
/// \sa "USB Request Types"
|
||||
/// \sa "USB Request Directions"
|
||||
unsigned char bmRequestType:8;
|
||||
/// Request code
|
||||
/// \sa "USB Request Codes"
|
||||
unsigned char bRequest:8;
|
||||
/// Request-specific value parameter.
|
||||
unsigned short wValue:16;
|
||||
/// Request-specific index parameter.
|
||||
unsigned short wIndex:16;
|
||||
/// Expected length (in bytes) of the data phase.
|
||||
unsigned short wLength:16;
|
||||
|
||||
} USBGenericRequest;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBGenericRequest_GetType(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
|
||||
extern unsigned char USBGenericRequest_GetRequest(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned short USBGenericRequest_GetValue(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned short USBGenericRequest_GetIndex(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned short USBGenericRequest_GetLength(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGenericRequest_GetEndpointNumber(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGenericRequest_GetRecipient(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGenericRequest_GetDirection(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBGENERICREQUEST_H
|
||||
|
||||
|
||||
@@ -1,72 +1,72 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBGetDescriptorRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBGetDescriptorRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGetDescriptorRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of the descriptor requested by the host given the
|
||||
/// corresponding GET_DESCRIPTOR request.
|
||||
/// \param request Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Type of the requested descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGetDescriptorRequest_GetDescriptorType(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
// Requested descriptor type is in the high-byte of the wValue field
|
||||
return (USBGenericRequest_GetValue(request) >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the index of the requested descriptor, given the corresponding
|
||||
/// GET_DESCRIPTOR request.
|
||||
/// \param request Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Index of the requested descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGetDescriptorRequest_GetDescriptorIndex(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
// Requested descriptor index if in the low byte of the wValue field
|
||||
return USBGenericRequest_GetValue(request) & 0xFF;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBGetDescriptorRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBGetDescriptorRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGetDescriptorRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of the descriptor requested by the host given the
|
||||
/// corresponding GET_DESCRIPTOR request.
|
||||
/// \param request Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Type of the requested descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGetDescriptorRequest_GetDescriptorType(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
// Requested descriptor type is in the high-byte of the wValue field
|
||||
return (USBGenericRequest_GetValue(request) >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the index of the requested descriptor, given the corresponding
|
||||
/// GET_DESCRIPTOR request.
|
||||
/// \param request Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Index of the requested descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGetDescriptorRequest_GetDescriptorIndex(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
// Requested descriptor index if in the low byte of the wValue field
|
||||
return USBGenericRequest_GetValue(request) & 0xFF;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of the USBGetDescriptorRequest class.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- After a GET_DESCRIPTOR request has been received, retrive the useful
|
||||
values with following functions:
|
||||
- USBGetDescriptorRequest_GetDescriptorType: the descriptor type
|
||||
- USBGetDescriptorRequest_GetDescriptorIndex: the index of the requested
|
||||
descriptor
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBGETDESCRIPTORREQUEST_H
|
||||
#define USBGETDESCRIPTORREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBGetDescriptorRequest_GetDescriptorType(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGetDescriptorRequest_GetDescriptorIndex(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBGETDESCRIPTORREQUEST_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of the USBGetDescriptorRequest class.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- After a GET_DESCRIPTOR request has been received, retrive the useful
|
||||
values with following functions:
|
||||
- USBGetDescriptorRequest_GetDescriptorType: the descriptor type
|
||||
- USBGetDescriptorRequest_GetDescriptorIndex: the index of the requested
|
||||
descriptor
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBGETDESCRIPTORREQUEST_H
|
||||
#define USBGETDESCRIPTORREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBGetDescriptorRequest_GetDescriptorType(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGetDescriptorRequest_GetDescriptorIndex(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBGETDESCRIPTORREQUEST_H
|
||||
|
||||
|
||||
@@ -1,86 +1,86 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* \page USBInterfaceAssociateDescriptor
|
||||
* !!!Purpose
|
||||
*
|
||||
* Class for manipulating USB IAD descriptors.
|
||||
*
|
||||
* !!!Usage
|
||||
*
|
||||
* -# Test
|
||||
*/
|
||||
|
||||
#ifndef USBDIADDESCRIPTOR_H
|
||||
#define USBDIADDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
/*
|
||||
Type: USBDeviceDescriptor
|
||||
USB standard device descriptor structure.
|
||||
|
||||
Variables:
|
||||
bLength - Size of this descriptor in bytes.
|
||||
bDescriptorType - Descriptor type (<USBGenericDescriptor_IAD>).
|
||||
bFirstInterface - Interface number of the first interface that is
|
||||
associated with this function.
|
||||
bInterfaceCount - Number of contiguous interfaces that are
|
||||
associated with this function.
|
||||
bFunctionClass - Class code (assigned by USB-IF).
|
||||
bFunctionSubClass - Subclass code (assigned by USB-IF).
|
||||
bFunctionProtocol - Protocol code (assigned by USB-IF)
|
||||
iFunction - Index of string descriptor describing this function.
|
||||
*/
|
||||
typedef struct {
|
||||
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned char bFirstInterface;
|
||||
unsigned char bInterfaceCount;
|
||||
unsigned char bFunctionClass;
|
||||
unsigned char bFunctionSubClass;
|
||||
unsigned char bFunctionProtocol;
|
||||
unsigned char iFunction;
|
||||
} __attribute__ ((packed)) USBInterfaceAssociationDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBDIADDESCRIPTOR_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* \page USBInterfaceAssociateDescriptor
|
||||
* !!!Purpose
|
||||
*
|
||||
* Class for manipulating USB IAD descriptors.
|
||||
*
|
||||
* !!!Usage
|
||||
*
|
||||
* -# Test
|
||||
*/
|
||||
|
||||
#ifndef USBDIADDESCRIPTOR_H
|
||||
#define USBDIADDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
/*
|
||||
Type: USBDeviceDescriptor
|
||||
USB standard device descriptor structure.
|
||||
|
||||
Variables:
|
||||
bLength - Size of this descriptor in bytes.
|
||||
bDescriptorType - Descriptor type (<USBGenericDescriptor_IAD>).
|
||||
bFirstInterface - Interface number of the first interface that is
|
||||
associated with this function.
|
||||
bInterfaceCount - Number of contiguous interfaces that are
|
||||
associated with this function.
|
||||
bFunctionClass - Class code (assigned by USB-IF).
|
||||
bFunctionSubClass - Subclass code (assigned by USB-IF).
|
||||
bFunctionProtocol - Protocol code (assigned by USB-IF)
|
||||
iFunction - Index of string descriptor describing this function.
|
||||
*/
|
||||
typedef struct {
|
||||
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned char bFirstInterface;
|
||||
unsigned char bInterfaceCount;
|
||||
unsigned char bFunctionClass;
|
||||
unsigned char bFunctionSubClass;
|
||||
unsigned char bFunctionProtocol;
|
||||
unsigned char iFunction;
|
||||
} __attribute__ ((packed)) USBInterfaceAssociationDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBDIADDESCRIPTOR_H
|
||||
|
||||
|
||||
@@ -1,87 +1,87 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for manipulating USB interface descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- Declare USBInterfaceDescriptor instance as a part of the configuration
|
||||
descriptors of a USB device.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBINTERFACEDESCRIPTOR_H
|
||||
#define USBINTERFACEDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// USB standard interface descriptor structure.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBGenericDescriptor_INTERFACE).
|
||||
unsigned char bDescriptorType;
|
||||
/// Number of the interface in its configuration.
|
||||
unsigned char bInterfaceNumber;
|
||||
/// Value to select this alternate interface setting.
|
||||
unsigned char bAlternateSetting;
|
||||
/// Number of endpoints used by the inteface (excluding endpoint 0).
|
||||
unsigned char bNumEndpoints;
|
||||
/// Interface class code.
|
||||
unsigned char bInterfaceClass;
|
||||
/// Interface subclass code.
|
||||
unsigned char bInterfaceSubClass;
|
||||
/// Interface protocol code.
|
||||
unsigned char bInterfaceProtocol;
|
||||
/// Index of the interface string descriptor.
|
||||
unsigned char iInterface;
|
||||
|
||||
} __attribute__ ((packed)) USBInterfaceDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBINTERFACEDESCRIPTOR_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for manipulating USB interface descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- Declare USBInterfaceDescriptor instance as a part of the configuration
|
||||
descriptors of a USB device.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBINTERFACEDESCRIPTOR_H
|
||||
#define USBINTERFACEDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// USB standard interface descriptor structure.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBGenericDescriptor_INTERFACE).
|
||||
unsigned char bDescriptorType;
|
||||
/// Number of the interface in its configuration.
|
||||
unsigned char bInterfaceNumber;
|
||||
/// Value to select this alternate interface setting.
|
||||
unsigned char bAlternateSetting;
|
||||
/// Number of endpoints used by the inteface (excluding endpoint 0).
|
||||
unsigned char bNumEndpoints;
|
||||
/// Interface class code.
|
||||
unsigned char bInterfaceClass;
|
||||
/// Interface subclass code.
|
||||
unsigned char bInterfaceSubClass;
|
||||
/// Interface protocol code.
|
||||
unsigned char bInterfaceProtocol;
|
||||
/// Index of the interface string descriptor.
|
||||
unsigned char iInterface;
|
||||
|
||||
} __attribute__ ((packed)) USBInterfaceDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBINTERFACEDESCRIPTOR_H
|
||||
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBInterfaceRequest
|
||||
|
||||
About: Purpose
|
||||
Implementation of USBInterfaceRequest class methods.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBInterfaceRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates which interface is targetted by a GET_INTERFACE or
|
||||
/// SET_INTERFACE request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Interface number.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBInterfaceRequest_GetInterface(const USBGenericRequest *request)
|
||||
{
|
||||
return (USBGenericRequest_GetIndex(request) & 0xFF);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates the new alternate setting that the interface targetted by a
|
||||
/// SET_INTERFACE request should use.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return New active setting for the interface.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBInterfaceRequest_GetAlternateSetting(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return (USBGenericRequest_GetValue(request) & 0xFF);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBInterfaceRequest
|
||||
|
||||
About: Purpose
|
||||
Implementation of USBInterfaceRequest class methods.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBInterfaceRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates which interface is targetted by a GET_INTERFACE or
|
||||
/// SET_INTERFACE request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Interface number.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBInterfaceRequest_GetInterface(const USBGenericRequest *request)
|
||||
{
|
||||
return (USBGenericRequest_GetIndex(request) & 0xFF);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates the new alternate setting that the interface targetted by a
|
||||
/// SET_INTERFACE request should use.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return New active setting for the interface.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBInterfaceRequest_GetAlternateSetting(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return (USBGenericRequest_GetValue(request) & 0xFF);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definitions for manipulating SET_INTERFACE and GET_INTERFACE request.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# After a SET_INTERFACE request has been received, retrieve the
|
||||
target interface using USBInterfaceRequest_GetInterface and its
|
||||
new alternate setting with USBInterfaceRequest_GetAlternateSetting.
|
||||
-# After a GET_INTERFACE request has been received, retrieve the target
|
||||
interface using USBInterfaceRequest_GetInterface.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBINTERFACEREQUEST_H
|
||||
#define USBINTERFACEREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBInterfaceRequest_GetInterface(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
|
||||
extern unsigned char USBInterfaceRequest_GetAlternateSetting(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBINTERFACEREQUEST_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definitions for manipulating SET_INTERFACE and GET_INTERFACE request.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# After a SET_INTERFACE request has been received, retrieve the
|
||||
target interface using USBInterfaceRequest_GetInterface and its
|
||||
new alternate setting with USBInterfaceRequest_GetAlternateSetting.
|
||||
-# After a GET_INTERFACE request has been received, retrieve the target
|
||||
interface using USBInterfaceRequest_GetInterface.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBINTERFACEREQUEST_H
|
||||
#define USBINTERFACEREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBInterfaceRequest_GetInterface(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
|
||||
extern unsigned char USBInterfaceRequest_GetAlternateSetting(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBINTERFACEREQUEST_H
|
||||
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBIrqHandler implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USB Interrupt Handler.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
#include <exceptions.h>
|
||||
|
||||
#include "radio/src/targets/sky9x/board_lowlevel.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Call Arbitrer, device and host interrupt handler.
|
||||
/// The IRQ functions are defined with weak and can be surcharged if needed.
|
||||
//------------------------------------------------------------------------------
|
||||
void USB_IrqHandler( void )
|
||||
{
|
||||
// Most arbitrer interrupt
|
||||
usb_general_interrupt();
|
||||
// Device interrupt
|
||||
USBD_IrqHandler();
|
||||
// Host interrupt
|
||||
usb_pipe_interrupt();
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBIrqHandler implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USB Interrupt Handler.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
#include <exceptions.h>
|
||||
|
||||
#include "radio/src/targets/sky9x/board_lowlevel.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Call Arbitrer, device and host interrupt handler.
|
||||
/// The IRQ functions are defined with weak and can be surcharged if needed.
|
||||
//------------------------------------------------------------------------------
|
||||
void USB_IrqHandler( void )
|
||||
{
|
||||
// Most arbitrer interrupt
|
||||
usb_general_interrupt();
|
||||
// Device interrupt
|
||||
USBD_IrqHandler();
|
||||
// Host interrupt
|
||||
usb_pipe_interrupt();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Implementation of the USB Interrupt Handler.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# The IRQ functions are defined with weak and can be surcharged if needed.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBIRQHANDLER_H
|
||||
#define USBIRQHANDLER_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
extern void USB_IrqHandler( void );
|
||||
|
||||
#endif //#ifndef USBIRQHANDLER_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Implementation of the USB Interrupt Handler.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# The IRQ functions are defined with weak and can be surcharged if needed.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBIRQHANDLER_H
|
||||
#define USBIRQHANDLER_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
extern void USB_IrqHandler( void );
|
||||
|
||||
#endif //#ifndef USBIRQHANDLER_H
|
||||
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBSetAddressRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBSetAddressRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBSetAddressRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the address that the device must take in response to a
|
||||
/// SET_ADDRESS request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return New device address.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBSetAddressRequest_GetAddress(const USBGenericRequest *request)
|
||||
{
|
||||
return USBGenericRequest_GetValue(request) & 0x7F;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBSetAddressRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBSetAddressRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBSetAddressRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the address that the device must take in response to a
|
||||
/// SET_ADDRESS request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return New device address.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBSetAddressRequest_GetAddress(const USBGenericRequest *request)
|
||||
{
|
||||
return USBGenericRequest_GetValue(request) & 0x7F;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for manipulating SET_ADDRESS USB requests.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- After a SET_ADDRESS request has been received, retrive the new address
|
||||
value with USBSetAddressRequest_GetAddress.
|
||||
*/
|
||||
|
||||
#ifndef USBSETADDRESSREQUEST_H
|
||||
#define USBSETADDRESSREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBSetAddressRequest_GetAddress(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBSETADDRESSREQUEST_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for manipulating SET_ADDRESS USB requests.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- After a SET_ADDRESS request has been received, retrive the new address
|
||||
value with USBSetAddressRequest_GetAddress.
|
||||
*/
|
||||
|
||||
#ifndef USBSETADDRESSREQUEST_H
|
||||
#define USBSETADDRESSREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBSetAddressRequest_GetAddress(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBSETADDRESSREQUEST_H
|
||||
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBSetConfigurationRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBSetConfigurationRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBSetConfigurationRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the number of the configuration that should be set in response
|
||||
/// to the given SET_CONFIGURATION request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Number of the requested configuration.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBSetConfigurationRequest_GetConfiguration(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return USBGenericRequest_GetValue(request);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBSetConfigurationRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBSetConfigurationRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBSetConfigurationRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the number of the configuration that should be set in response
|
||||
/// to the given SET_CONFIGURATION request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Number of the requested configuration.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBSetConfigurationRequest_GetConfiguration(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return USBGenericRequest_GetValue(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for the Set Configuration request.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- After a SET_CONFIGURATION request has been received, retrive the new
|
||||
configuration value with USBSetConfigurationRequest_GetConfiguration.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBSETCONFIGURATIONREQUEST_H
|
||||
#define USBSETCONFIGURATIONREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBSetConfigurationRequest_GetConfiguration(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBSETCONFIGURATIONREQUEST_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for the Set Configuration request.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- After a SET_CONFIGURATION request has been received, retrive the new
|
||||
configuration value with USBSetConfigurationRequest_GetConfiguration.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBSETCONFIGURATIONREQUEST_H
|
||||
#define USBSETCONFIGURATIONREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBSetConfigurationRequest_GetConfiguration(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBSETCONFIGURATIONREQUEST_H
|
||||
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !!!Purpose
|
||||
///
|
||||
/// Definition of a class for manipulating String descriptors.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef USBSTRINGDESCRIPTOR_H
|
||||
#define USBSTRINGDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB String Descriptor definitions"
|
||||
///
|
||||
/// This page lists the codes and macros for USB string descriptor definition.
|
||||
///
|
||||
/// !Language IDs
|
||||
/// - USBStringDescriptor_ENGLISH_US
|
||||
///
|
||||
/// !String Descriptor Length
|
||||
/// - USBStringDescriptor_LENGTH
|
||||
///
|
||||
/// !ASCII to UNICODE convertion
|
||||
/// - USBStringDescriptor_UNICODE
|
||||
|
||||
/// Language ID for US english.
|
||||
#define USBStringDescriptor_ENGLISH_US 0x09, 0x04
|
||||
|
||||
/// Calculates the length of a string descriptor given the number of ascii
|
||||
/// characters/language IDs in it.
|
||||
/// \param length The ascii format string length.
|
||||
/// \return The actual data length in bytes.
|
||||
#define USBStringDescriptor_LENGTH(length) ((length) * 2 + 2)
|
||||
/// Converts an ascii character to its unicode representation.
|
||||
/// \param ascii The ASCII character to convert
|
||||
/// \return A 2-byte-array for the UNICODE based on given ASCII
|
||||
#define USBStringDescriptor_UNICODE(ascii) (ascii), 0
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif //#ifndef USBSTRINGDESCRIPTOR_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !!!Purpose
|
||||
///
|
||||
/// Definition of a class for manipulating String descriptors.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef USBSTRINGDESCRIPTOR_H
|
||||
#define USBSTRINGDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB String Descriptor definitions"
|
||||
///
|
||||
/// This page lists the codes and macros for USB string descriptor definition.
|
||||
///
|
||||
/// !Language IDs
|
||||
/// - USBStringDescriptor_ENGLISH_US
|
||||
///
|
||||
/// !String Descriptor Length
|
||||
/// - USBStringDescriptor_LENGTH
|
||||
///
|
||||
/// !ASCII to UNICODE convertion
|
||||
/// - USBStringDescriptor_UNICODE
|
||||
|
||||
/// Language ID for US english.
|
||||
#define USBStringDescriptor_ENGLISH_US 0x09, 0x04
|
||||
|
||||
/// Calculates the length of a string descriptor given the number of ascii
|
||||
/// characters/language IDs in it.
|
||||
/// \param length The ascii format string length.
|
||||
/// \return The actual data length in bytes.
|
||||
#define USBStringDescriptor_LENGTH(length) ((length) * 2 + 2)
|
||||
/// Converts an ascii character to its unicode representation.
|
||||
/// \param ascii The ASCII character to convert
|
||||
/// \return A 2-byte-array for the UNICODE based on given ASCII
|
||||
#define USBStringDescriptor_UNICODE(ascii) (ascii), 0
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif //#ifndef USBSTRINGDESCRIPTOR_H
|
||||
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Declaration of constants for using Device Descriptors with a Mass Storage
|
||||
/// driver.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// - For a USB device:
|
||||
/// -# When declaring a USBDeviceDescriptor instance, use the Mass Storage
|
||||
/// codes defined in this file (see "MS device codes").
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDEVICEDESCRIPTOR_H
|
||||
#define MSDEVICEDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MS device codes"
|
||||
/// This page lists the class, subclass & protocol codes used by a device with
|
||||
/// a Mass Storage driver.
|
||||
///
|
||||
/// !Codes
|
||||
///
|
||||
/// - MSDeviceDescriptor_CLASS
|
||||
/// - MSDeviceDescriptor_SUBCLASS
|
||||
/// - MSDeviceDescriptor_PROTOCOL
|
||||
|
||||
/// Class code for a Mass Storage device.
|
||||
#define MSDeviceDescriptor_CLASS 0
|
||||
|
||||
/// Subclass code for a Mass Storage device.
|
||||
#define MSDeviceDescriptor_SUBCLASS 0
|
||||
|
||||
/// Protocol code for a Mass Storage device.
|
||||
#define MSDeviceDescriptor_PROTOCOL 0
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif //#ifndef MSDEVICEDESCRIPTOR_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Declaration of constants for using Device Descriptors with a Mass Storage
|
||||
/// driver.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// - For a USB device:
|
||||
/// -# When declaring a USBDeviceDescriptor instance, use the Mass Storage
|
||||
/// codes defined in this file (see "MS device codes").
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDEVICEDESCRIPTOR_H
|
||||
#define MSDEVICEDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MS device codes"
|
||||
/// This page lists the class, subclass & protocol codes used by a device with
|
||||
/// a Mass Storage driver.
|
||||
///
|
||||
/// !Codes
|
||||
///
|
||||
/// - MSDeviceDescriptor_CLASS
|
||||
/// - MSDeviceDescriptor_SUBCLASS
|
||||
/// - MSDeviceDescriptor_PROTOCOL
|
||||
|
||||
/// Class code for a Mass Storage device.
|
||||
#define MSDeviceDescriptor_CLASS 0
|
||||
|
||||
/// Subclass code for a Mass Storage device.
|
||||
#define MSDeviceDescriptor_SUBCLASS 0
|
||||
|
||||
/// Protocol code for a Mass Storage device.
|
||||
#define MSDeviceDescriptor_PROTOCOL 0
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif //#ifndef MSDEVICEDESCRIPTOR_H
|
||||
|
||||
|
||||
@@ -1,75 +1,75 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definition of several constants used when manipulating Mass Storage interface
|
||||
/// descriptors.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// - For a USB device:
|
||||
/// -# When declaring an interface descriptor for a Mass Storage device, use
|
||||
/// the class, subclass and protocol codes defined here (see
|
||||
/// "MS interface codes").
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSINTERFACEDESCRIPTOR_H
|
||||
#define MSINTERFACEDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MS interface codes"
|
||||
/// This page lists the available class, subclass & protocol codes for a Mass
|
||||
/// Storage interface.
|
||||
///
|
||||
/// !Codes
|
||||
///
|
||||
/// - MSInterfaceDescriptor_CLASS
|
||||
/// - MSInterfaceDescriptor_SCSI
|
||||
/// - MSInterfaceDescriptor_BULKONLY
|
||||
|
||||
/// Class code for a Mass Storage interface.
|
||||
#define MSInterfaceDescriptor_CLASS 0x08
|
||||
|
||||
/// Subclass code for a Mass Storage interface using the SCSI protocol.
|
||||
#define MSInterfaceDescriptor_SCSI 0x06
|
||||
|
||||
/// Protocol code for a Mass Storage interface using Bulk-Only Transport.
|
||||
#define MSInterfaceDescriptor_BULKONLY 0x50
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#endif //#ifndef MSINTERFACEDESCRIPTOR_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definition of several constants used when manipulating Mass Storage interface
|
||||
/// descriptors.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// - For a USB device:
|
||||
/// -# When declaring an interface descriptor for a Mass Storage device, use
|
||||
/// the class, subclass and protocol codes defined here (see
|
||||
/// "MS interface codes").
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSINTERFACEDESCRIPTOR_H
|
||||
#define MSINTERFACEDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MS interface codes"
|
||||
/// This page lists the available class, subclass & protocol codes for a Mass
|
||||
/// Storage interface.
|
||||
///
|
||||
/// !Codes
|
||||
///
|
||||
/// - MSInterfaceDescriptor_CLASS
|
||||
/// - MSInterfaceDescriptor_SCSI
|
||||
/// - MSInterfaceDescriptor_BULKONLY
|
||||
|
||||
/// Class code for a Mass Storage interface.
|
||||
#define MSInterfaceDescriptor_CLASS 0x08
|
||||
|
||||
/// Subclass code for a Mass Storage interface using the SCSI protocol.
|
||||
#define MSInterfaceDescriptor_SCSI 0x06
|
||||
|
||||
/// Protocol code for a Mass Storage interface using Bulk-Only Transport.
|
||||
#define MSInterfaceDescriptor_BULKONLY 0x50
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#endif //#ifndef MSINTERFACEDESCRIPTOR_H
|
||||
|
||||
|
||||
@@ -1,233 +1,233 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Mass Storage class definitions.
|
||||
///
|
||||
/// See
|
||||
/// - <a
|
||||
/// href="http://www.usb.org/developers/devclass_docs/usb_msc_overview_1.2.pdf">
|
||||
/// USB Mass Storage Class Spec. Overview</a>
|
||||
/// - <a href="http://www.usb.org/developers/devclass_docs/usbmassbulk_10.pdf">
|
||||
/// USB Mass Storage Class Bulk-Only Transport</a>
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Uses "MSD Requests" to check incoming requests from USB Host.
|
||||
/// -# Uses "MSD Subclass Codes" and "MSD Protocol Codes" to fill %device
|
||||
/// interface descriptors for a MSD %device.
|
||||
/// -# Handle the incoming Bulk data with "MSD CBW Definitions" and MSCbw
|
||||
/// structure.
|
||||
/// -# Prepare the outgoing Bulk data with "MSD CSW Definitions" and MSCsw
|
||||
/// structure.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSD_H
|
||||
#define MSD_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Requests"
|
||||
/// This page lists MSD-specific requests ( Actually for Bulk-only protocol ).
|
||||
///
|
||||
/// !Requests
|
||||
/// - MSD_BULK_ONLY_RESET
|
||||
/// - MSD_GET_MAX_LUN
|
||||
|
||||
/// Reset the mass storage %device and its associated interface.
|
||||
#define MSD_BULK_ONLY_RESET 0xFF
|
||||
/// Return the maximum LUN number supported by the %device.
|
||||
#define MSD_GET_MAX_LUN 0xFE
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Subclass Codes"
|
||||
/// This page lists the Subclass Codes for bInterfaceSubClass field.
|
||||
/// (Table 2.1, USB Mass Storage Class Spec. Overview)
|
||||
///
|
||||
/// !SubClasses
|
||||
/// - MSD_SUBCLASS_RBC
|
||||
/// - MSD_SUBCLASS_SFF_MCC
|
||||
/// - MSD_SUBCLASS_QIC
|
||||
/// - MSD_SUBCLASS_UFI
|
||||
/// - MSD_SUBCLASS_SFF
|
||||
/// - MSD_SUBCLASS_SCSI
|
||||
|
||||
/// Reduced Block Commands (RBC) T10
|
||||
#define MSD_SUBCLASS_RBC 0x01
|
||||
/// C/DVD devices
|
||||
#define MSD_SUBCLASS_SFF_MCC 0x02
|
||||
/// Tape device
|
||||
#define MSD_SUBCLASS_QIC 0x03
|
||||
/// Floppy disk drive (FDD) device
|
||||
#define MSD_SUBCLASS_UFI 0x04
|
||||
/// Floppy disk drive (FDD) device
|
||||
#define MSD_SUBCLASS_SFF 0x05
|
||||
/// SCSI transparent command set
|
||||
#define MSD_SUBCLASS_SCSI 0x06
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Protocol Codes"
|
||||
/// This page lists the Transport Protocol codes for MSD.
|
||||
/// (Table 3.1, USB Mass Storage Class Spec. Overview)
|
||||
///
|
||||
/// !Protocols
|
||||
/// - MSD_PROTOCOL_CBI_COMPLETION
|
||||
/// - MSD_PROTOCOL_CBI
|
||||
/// - MSD_PROTOCOL_BULK_ONLY
|
||||
|
||||
/// Control/Bulk/Interrupt (CBI) Transport (with command complete interrupt)
|
||||
#define MSD_PROTOCOL_CBI_COMPLETION 0x00
|
||||
/// Control/Bulk/Interrupt (CBI) Transport (no command complete interrupt)
|
||||
#define MSD_PROTOCOL_CBI 0x01
|
||||
/// Bulk-Only Transport
|
||||
#define MSD_PROTOCOL_BULK_ONLY 0x50
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Test unit control:
|
||||
#define CTRL_NOT_READY 0x00
|
||||
#define CTRL_GOOD 0x01
|
||||
#define CTRL_BUSY 0x02
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD CBW Definitions"
|
||||
/// This page lists the Command Block Wrapper (CBW) definitions.
|
||||
///
|
||||
/// !Constants
|
||||
/// - MSD_CBW_SIZE
|
||||
/// - MSD_CBW_SIGNATURE
|
||||
///
|
||||
/// !Fields
|
||||
/// - MSD_CBW_DEVICE_TO_HOST
|
||||
|
||||
/// Command Block Wrapper Size
|
||||
#define MSD_CBW_SIZE 31
|
||||
/// 'USBC' 0x43425355
|
||||
#define MSD_CBW_SIGNATURE 0x43425355
|
||||
|
||||
/// CBW bmCBWFlags field
|
||||
#define MSD_CBW_DEVICE_TO_HOST (1 << 7)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD CSW Definitions"
|
||||
/// This page lists the Command Status Wrapper (CSW) definitions.
|
||||
///
|
||||
/// !Constants
|
||||
/// - MSD_CSW_SIZE
|
||||
/// - MSD_CSW_SIGNATURE
|
||||
///
|
||||
/// !Command Block Status Values
|
||||
/// (Table 5.3 , USB Mass Storage Class Bulk-Only Transport)
|
||||
/// - MSD_CSW_COMMAND_PASSED
|
||||
/// - MSD_CSW_COMMAND_FAILED
|
||||
/// - MSD_CSW_PHASE_ERROR
|
||||
|
||||
/// Command Status Wrapper Size
|
||||
#define MSD_CSW_SIZE 13
|
||||
/// 'USBS' 0x53425355
|
||||
#define MSD_CSW_SIGNATURE 0x53425355
|
||||
|
||||
/// Command Passed (good status)
|
||||
#define MSD_CSW_COMMAND_PASSED 0
|
||||
/// Command Failed
|
||||
#define MSD_CSW_COMMAND_FAILED 1
|
||||
/// Phase Error
|
||||
#define MSD_CSW_PHASE_ERROR 2
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Structures
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Command Block Wrapper (CBW),
|
||||
/// See Table 5.1, USB Mass Storage Class Bulk-Only Transport.
|
||||
///
|
||||
/// The CBW shall start on a packet boundary and shall end as a
|
||||
/// short packet with exactly 31 (1Fh) bytes transferred.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// 'USBC' 0x43425355 (little endian)
|
||||
unsigned int dCBWSignature;
|
||||
/// Must be the same as dCSWTag
|
||||
unsigned int dCBWTag;
|
||||
/// Number of bytes transfer
|
||||
unsigned int dCBWDataTransferLength;
|
||||
/// Indicates the directin of the transfer:
|
||||
/// 0x80=IN=device-to-host,
|
||||
/// 0x00=OUT=host-to-device
|
||||
unsigned char bmCBWFlags;
|
||||
/// bits 0->3: bCBWLUN
|
||||
unsigned char bCBWLUN :4,
|
||||
bReserved1:4; /// reserved
|
||||
/// bits 0->4: bCBWCBLength
|
||||
unsigned char bCBWCBLength:5,
|
||||
bReserved2 :3; /// reserved
|
||||
/// Command block
|
||||
unsigned char pCommand[16];
|
||||
|
||||
} MSCbw;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Command Status Wrapper (CSW),
|
||||
/// See Table 5.2, USB Mass Storage Class Bulk-Only Transport.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct
|
||||
{
|
||||
/// 'USBS' 0x53425355 (little endian)
|
||||
unsigned int dCSWSignature;
|
||||
/// Must be the same as dCBWTag
|
||||
unsigned int dCSWTag;
|
||||
/// For Data-Out the device shall report in the dCSWDataResidue the
|
||||
/// difference between the amount of data expected as stated in the
|
||||
/// dCBWDataTransferLength, and the actual amount of data processed by
|
||||
/// the device. For Data-In the device shall report in the dCSWDataResidue
|
||||
/// the difference between the amount of data expected as stated in the
|
||||
/// dCBWDataTransferLength and the actual amount of relevant data sent by
|
||||
/// the device. The dCSWDataResidue shall not exceed the value sent in the
|
||||
/// dCBWDataTransferLength.
|
||||
unsigned int dCSWDataResidue;
|
||||
/// Indicates the success or failure of the command.
|
||||
unsigned char bCSWStatus;
|
||||
|
||||
} MSCsw;
|
||||
|
||||
#endif //#ifndef MSD_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Mass Storage class definitions.
|
||||
///
|
||||
/// See
|
||||
/// - <a
|
||||
/// href="http://www.usb.org/developers/devclass_docs/usb_msc_overview_1.2.pdf">
|
||||
/// USB Mass Storage Class Spec. Overview</a>
|
||||
/// - <a href="http://www.usb.org/developers/devclass_docs/usbmassbulk_10.pdf">
|
||||
/// USB Mass Storage Class Bulk-Only Transport</a>
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Uses "MSD Requests" to check incoming requests from USB Host.
|
||||
/// -# Uses "MSD Subclass Codes" and "MSD Protocol Codes" to fill %device
|
||||
/// interface descriptors for a MSD %device.
|
||||
/// -# Handle the incoming Bulk data with "MSD CBW Definitions" and MSCbw
|
||||
/// structure.
|
||||
/// -# Prepare the outgoing Bulk data with "MSD CSW Definitions" and MSCsw
|
||||
/// structure.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSD_H
|
||||
#define MSD_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Requests"
|
||||
/// This page lists MSD-specific requests ( Actually for Bulk-only protocol ).
|
||||
///
|
||||
/// !Requests
|
||||
/// - MSD_BULK_ONLY_RESET
|
||||
/// - MSD_GET_MAX_LUN
|
||||
|
||||
/// Reset the mass storage %device and its associated interface.
|
||||
#define MSD_BULK_ONLY_RESET 0xFF
|
||||
/// Return the maximum LUN number supported by the %device.
|
||||
#define MSD_GET_MAX_LUN 0xFE
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Subclass Codes"
|
||||
/// This page lists the Subclass Codes for bInterfaceSubClass field.
|
||||
/// (Table 2.1, USB Mass Storage Class Spec. Overview)
|
||||
///
|
||||
/// !SubClasses
|
||||
/// - MSD_SUBCLASS_RBC
|
||||
/// - MSD_SUBCLASS_SFF_MCC
|
||||
/// - MSD_SUBCLASS_QIC
|
||||
/// - MSD_SUBCLASS_UFI
|
||||
/// - MSD_SUBCLASS_SFF
|
||||
/// - MSD_SUBCLASS_SCSI
|
||||
|
||||
/// Reduced Block Commands (RBC) T10
|
||||
#define MSD_SUBCLASS_RBC 0x01
|
||||
/// C/DVD devices
|
||||
#define MSD_SUBCLASS_SFF_MCC 0x02
|
||||
/// Tape device
|
||||
#define MSD_SUBCLASS_QIC 0x03
|
||||
/// Floppy disk drive (FDD) device
|
||||
#define MSD_SUBCLASS_UFI 0x04
|
||||
/// Floppy disk drive (FDD) device
|
||||
#define MSD_SUBCLASS_SFF 0x05
|
||||
/// SCSI transparent command set
|
||||
#define MSD_SUBCLASS_SCSI 0x06
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Protocol Codes"
|
||||
/// This page lists the Transport Protocol codes for MSD.
|
||||
/// (Table 3.1, USB Mass Storage Class Spec. Overview)
|
||||
///
|
||||
/// !Protocols
|
||||
/// - MSD_PROTOCOL_CBI_COMPLETION
|
||||
/// - MSD_PROTOCOL_CBI
|
||||
/// - MSD_PROTOCOL_BULK_ONLY
|
||||
|
||||
/// Control/Bulk/Interrupt (CBI) Transport (with command complete interrupt)
|
||||
#define MSD_PROTOCOL_CBI_COMPLETION 0x00
|
||||
/// Control/Bulk/Interrupt (CBI) Transport (no command complete interrupt)
|
||||
#define MSD_PROTOCOL_CBI 0x01
|
||||
/// Bulk-Only Transport
|
||||
#define MSD_PROTOCOL_BULK_ONLY 0x50
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Test unit control:
|
||||
#define CTRL_NOT_READY 0x00
|
||||
#define CTRL_GOOD 0x01
|
||||
#define CTRL_BUSY 0x02
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD CBW Definitions"
|
||||
/// This page lists the Command Block Wrapper (CBW) definitions.
|
||||
///
|
||||
/// !Constants
|
||||
/// - MSD_CBW_SIZE
|
||||
/// - MSD_CBW_SIGNATURE
|
||||
///
|
||||
/// !Fields
|
||||
/// - MSD_CBW_DEVICE_TO_HOST
|
||||
|
||||
/// Command Block Wrapper Size
|
||||
#define MSD_CBW_SIZE 31
|
||||
/// 'USBC' 0x43425355
|
||||
#define MSD_CBW_SIGNATURE 0x43425355
|
||||
|
||||
/// CBW bmCBWFlags field
|
||||
#define MSD_CBW_DEVICE_TO_HOST (1 << 7)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD CSW Definitions"
|
||||
/// This page lists the Command Status Wrapper (CSW) definitions.
|
||||
///
|
||||
/// !Constants
|
||||
/// - MSD_CSW_SIZE
|
||||
/// - MSD_CSW_SIGNATURE
|
||||
///
|
||||
/// !Command Block Status Values
|
||||
/// (Table 5.3 , USB Mass Storage Class Bulk-Only Transport)
|
||||
/// - MSD_CSW_COMMAND_PASSED
|
||||
/// - MSD_CSW_COMMAND_FAILED
|
||||
/// - MSD_CSW_PHASE_ERROR
|
||||
|
||||
/// Command Status Wrapper Size
|
||||
#define MSD_CSW_SIZE 13
|
||||
/// 'USBS' 0x53425355
|
||||
#define MSD_CSW_SIGNATURE 0x53425355
|
||||
|
||||
/// Command Passed (good status)
|
||||
#define MSD_CSW_COMMAND_PASSED 0
|
||||
/// Command Failed
|
||||
#define MSD_CSW_COMMAND_FAILED 1
|
||||
/// Phase Error
|
||||
#define MSD_CSW_PHASE_ERROR 2
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Structures
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Command Block Wrapper (CBW),
|
||||
/// See Table 5.1, USB Mass Storage Class Bulk-Only Transport.
|
||||
///
|
||||
/// The CBW shall start on a packet boundary and shall end as a
|
||||
/// short packet with exactly 31 (1Fh) bytes transferred.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// 'USBC' 0x43425355 (little endian)
|
||||
unsigned int dCBWSignature;
|
||||
/// Must be the same as dCSWTag
|
||||
unsigned int dCBWTag;
|
||||
/// Number of bytes transfer
|
||||
unsigned int dCBWDataTransferLength;
|
||||
/// Indicates the directin of the transfer:
|
||||
/// 0x80=IN=device-to-host,
|
||||
/// 0x00=OUT=host-to-device
|
||||
unsigned char bmCBWFlags;
|
||||
/// bits 0->3: bCBWLUN
|
||||
unsigned char bCBWLUN :4,
|
||||
bReserved1:4; /// reserved
|
||||
/// bits 0->4: bCBWCBLength
|
||||
unsigned char bCBWCBLength:5,
|
||||
bReserved2 :3; /// reserved
|
||||
/// Command block
|
||||
unsigned char pCommand[16];
|
||||
|
||||
} MSCbw;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Command Status Wrapper (CSW),
|
||||
/// See Table 5.2, USB Mass Storage Class Bulk-Only Transport.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct
|
||||
{
|
||||
/// 'USBS' 0x53425355 (little endian)
|
||||
unsigned int dCSWSignature;
|
||||
/// Must be the same as dCBWTag
|
||||
unsigned int dCSWTag;
|
||||
/// For Data-Out the device shall report in the dCSWDataResidue the
|
||||
/// difference between the amount of data expected as stated in the
|
||||
/// dCBWDataTransferLength, and the actual amount of data processed by
|
||||
/// the device. For Data-In the device shall report in the dCSWDataResidue
|
||||
/// the difference between the amount of data expected as stated in the
|
||||
/// dCBWDataTransferLength and the actual amount of relevant data sent by
|
||||
/// the device. The dCSWDataResidue shall not exceed the value sent in the
|
||||
/// dCBWDataTransferLength.
|
||||
unsigned int dCSWDataResidue;
|
||||
/// Indicates the success or failure of the command.
|
||||
unsigned char bCSWStatus;
|
||||
|
||||
} MSCsw;
|
||||
|
||||
#endif //#ifndef MSD_H
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,264 +1,264 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definitions, structs, functions required by a Mass Storage device driver
|
||||
/// state machine..
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// - For a USB device:
|
||||
/// -# MSDD_Write, MSDD_Read, MSDD_Halt should be defined for
|
||||
/// usage in the state machine procedure.
|
||||
///
|
||||
/// -# MSDD_StateMachine is invoked to run the MSD state machine.
|
||||
///
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDDSTATEMACHINE_H
|
||||
#define MSDDSTATEMACHINE_H
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Headers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSD.h"
|
||||
#include "../../../usb/device/massstorage/MSDLun.h"
|
||||
#include "debug.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Possible states"
|
||||
/// ...
|
||||
///
|
||||
/// !States
|
||||
/// - MSDD_STATE_READ_CBW
|
||||
/// - MSDD_STATE_WAIT_CBW
|
||||
/// - MSDD_STATE_PROCESS_CBW
|
||||
/// - MSDD_STATE_WAIT_HALT
|
||||
/// - MSDD_STATE_SEND_CSW
|
||||
/// - MSDD_STATE_WAIT_CSW
|
||||
/// - MSDD_STATE_WAIT_RESET
|
||||
|
||||
//! \brief Driver is expecting a command block wrapper
|
||||
#define MSDD_STATE_READ_CBW (1 << 0)
|
||||
|
||||
//! \brief Driver is waiting for the transfer to finish
|
||||
#define MSDD_STATE_WAIT_CBW (1 << 1)
|
||||
|
||||
//! \brief Driver is processing the received command
|
||||
#define MSDD_STATE_PROCESS_CBW (1 << 2)
|
||||
|
||||
//! \brief Driver is halted because pipe halt or wait reset
|
||||
#define MSDD_STATE_WAIT_HALT (1 << 3)
|
||||
|
||||
//! \brief Driver is starting the transmission of a command status wrapper
|
||||
#define MSDD_STATE_SEND_CSW (1 << 4)
|
||||
|
||||
//! \brief Driver is waiting for the CSW transmission to finish
|
||||
#define MSDD_STATE_WAIT_CSW (1 << 5)
|
||||
|
||||
//! \brief Driver is waiting for the MassStorageReset
|
||||
#define MSDD_STATE_WAIT_RESET (1 << 6)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Result Codes"
|
||||
/// This page lists result codes for MSD functions.
|
||||
///
|
||||
/// !Codes
|
||||
/// - MSDD_STATUS_SUCCESS
|
||||
/// - MSDD_STATUS_ERROR
|
||||
/// - MSDD_STATUS_INCOMPLETE
|
||||
/// - MSDD_STATUS_PARAMETER
|
||||
/// - MSDD_STATUS_RW
|
||||
|
||||
//! \brief Method was successful
|
||||
#define MSDD_STATUS_SUCCESS 0x00
|
||||
|
||||
//! \brief There was an error when trying to perform a method
|
||||
#define MSDD_STATUS_ERROR 0x01
|
||||
|
||||
//! \brief No error was encountered but the application should call the
|
||||
//! method again to continue the operation
|
||||
#define MSDD_STATUS_INCOMPLETE 0x02
|
||||
|
||||
//! \brief A wrong parameter has been passed to the method
|
||||
#define MSDD_STATUS_PARAMETER 0x03
|
||||
|
||||
//! \brief An error when reading/writing disk (protected or not present)
|
||||
#define MSDD_STATUS_RW 0x04
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Action Cases"
|
||||
/// This page lists actions to perform during the post-processing phase of a
|
||||
/// command.
|
||||
///
|
||||
/// !Actions
|
||||
/// - MSDD_CASE_PHASE_ERROR
|
||||
/// - MSDD_CASE_STALL_IN
|
||||
/// - MSDD_CASE_STALL_OUT
|
||||
|
||||
//! \brief Indicates that the CSW should report a phase error
|
||||
#define MSDD_CASE_PHASE_ERROR (1 << 0)
|
||||
|
||||
//! \brief The driver should halt the Bulk IN pipe after the transfer
|
||||
#define MSDD_CASE_STALL_IN (1 << 1)
|
||||
|
||||
//! \brief The driver should halt the Bulk OUT pipe after the transfer
|
||||
#define MSDD_CASE_STALL_OUT (1 << 2)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Xfr Directions"
|
||||
/// This page lists possible direction values for a data transfer
|
||||
///
|
||||
/// !Directions
|
||||
/// - MSDD_DEVICE_TO_HOST
|
||||
/// - MSDD_HOST_TO_DEVICE
|
||||
/// - MSDD_NO_TRANSFER
|
||||
|
||||
#define MSDD_DEVICE_TO_HOST 0
|
||||
#define MSDD_HOST_TO_DEVICE 1
|
||||
#define MSDD_NO_TRANSFER 2
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Structure for holding the result of a USB transfer
|
||||
//! \see MSDDriver_Callback
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
volatile unsigned int transferred; /// Number of bytes transferred
|
||||
volatile unsigned int remaining; /// Number of bytes not transferred
|
||||
volatile unsigned short semaphore; /// Semaphore to indicate transfer completion
|
||||
volatile unsigned short status; /// Operation result code
|
||||
|
||||
} MSDTransfer;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Status of an executing command
|
||||
//! \see MSDCbw
|
||||
//! \see MSDCsw
|
||||
//! \see MSDTransfer
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
MSDTransfer transfer; /// Current transfer status (USB)
|
||||
MSDTransfer disktransfer;/// Current transfer status (Disk)
|
||||
unsigned int length; /// Remaining length of command
|
||||
MSCbw cbw; /// Received CBW (31 bytes)
|
||||
unsigned char state; /// Current command state
|
||||
MSCsw csw; /// CSW to send (13 bytes)
|
||||
unsigned char postprocess; /// Actions to perform when command is complete
|
||||
|
||||
} MSDCommandState;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \brief MSD driver state variables
|
||||
/// \see MSDCommandState
|
||||
/// \see MSDLun
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// LUN list for the %device.
|
||||
MSDLun *luns;
|
||||
/// State of the currently executing command
|
||||
MSDCommandState commandState;
|
||||
/// Maximum LUN index
|
||||
unsigned char maxLun;
|
||||
/// Current state of the driver
|
||||
unsigned char state;
|
||||
/// Indicates if the driver is waiting for a reset recovery
|
||||
unsigned char waitResetRecovery;
|
||||
|
||||
} MSDDriver;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inline functions
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
/// This function is to be used as a callback for USB or LUN transfers.
|
||||
/// \param transfer Pointer to the transfer structure to update
|
||||
/// \param status Operation result code
|
||||
/// \param transferred Number of bytes transferred by the command
|
||||
/// \param remaining Number of bytes not transferred
|
||||
//-----------------------------------------------------------------------------
|
||||
static inline void MSDDriver_Callback(MSDTransfer *transfer,
|
||||
unsigned char status,
|
||||
unsigned int transferred,
|
||||
unsigned int remaining)
|
||||
{
|
||||
TRACE_DEBUG("Cbk ");
|
||||
transfer->semaphore++;
|
||||
transfer->status = status;
|
||||
transfer->transferred = transferred;
|
||||
transfer->remaining = remaining;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Driver functions
|
||||
//-----------------------------------------------------------------------------
|
||||
//- MSD General support function
|
||||
extern char MSDD_Read(
|
||||
void* pData,
|
||||
unsigned int dLength,
|
||||
TransferCallback fCallback,
|
||||
void* pArgument);
|
||||
|
||||
extern char MSDD_Write(
|
||||
void* pData,
|
||||
unsigned int dLength,
|
||||
TransferCallback fCallback,
|
||||
void* pArgument);
|
||||
|
||||
extern void MSDD_Halt(unsigned int stallCase);
|
||||
|
||||
extern unsigned int MSDD_IsHalted(void);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
extern void MSDD_StateMachine(MSDDriver * pMsdDriver);
|
||||
|
||||
#endif // #define MSDDSTATEMACHINE_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definitions, structs, functions required by a Mass Storage device driver
|
||||
/// state machine..
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// - For a USB device:
|
||||
/// -# MSDD_Write, MSDD_Read, MSDD_Halt should be defined for
|
||||
/// usage in the state machine procedure.
|
||||
///
|
||||
/// -# MSDD_StateMachine is invoked to run the MSD state machine.
|
||||
///
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDDSTATEMACHINE_H
|
||||
#define MSDDSTATEMACHINE_H
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Headers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSD.h"
|
||||
#include "../../../usb/device/massstorage/MSDLun.h"
|
||||
#include "debug.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Possible states"
|
||||
/// ...
|
||||
///
|
||||
/// !States
|
||||
/// - MSDD_STATE_READ_CBW
|
||||
/// - MSDD_STATE_WAIT_CBW
|
||||
/// - MSDD_STATE_PROCESS_CBW
|
||||
/// - MSDD_STATE_WAIT_HALT
|
||||
/// - MSDD_STATE_SEND_CSW
|
||||
/// - MSDD_STATE_WAIT_CSW
|
||||
/// - MSDD_STATE_WAIT_RESET
|
||||
|
||||
//! \brief Driver is expecting a command block wrapper
|
||||
#define MSDD_STATE_READ_CBW (1 << 0)
|
||||
|
||||
//! \brief Driver is waiting for the transfer to finish
|
||||
#define MSDD_STATE_WAIT_CBW (1 << 1)
|
||||
|
||||
//! \brief Driver is processing the received command
|
||||
#define MSDD_STATE_PROCESS_CBW (1 << 2)
|
||||
|
||||
//! \brief Driver is halted because pipe halt or wait reset
|
||||
#define MSDD_STATE_WAIT_HALT (1 << 3)
|
||||
|
||||
//! \brief Driver is starting the transmission of a command status wrapper
|
||||
#define MSDD_STATE_SEND_CSW (1 << 4)
|
||||
|
||||
//! \brief Driver is waiting for the CSW transmission to finish
|
||||
#define MSDD_STATE_WAIT_CSW (1 << 5)
|
||||
|
||||
//! \brief Driver is waiting for the MassStorageReset
|
||||
#define MSDD_STATE_WAIT_RESET (1 << 6)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Result Codes"
|
||||
/// This page lists result codes for MSD functions.
|
||||
///
|
||||
/// !Codes
|
||||
/// - MSDD_STATUS_SUCCESS
|
||||
/// - MSDD_STATUS_ERROR
|
||||
/// - MSDD_STATUS_INCOMPLETE
|
||||
/// - MSDD_STATUS_PARAMETER
|
||||
/// - MSDD_STATUS_RW
|
||||
|
||||
//! \brief Method was successful
|
||||
#define MSDD_STATUS_SUCCESS 0x00
|
||||
|
||||
//! \brief There was an error when trying to perform a method
|
||||
#define MSDD_STATUS_ERROR 0x01
|
||||
|
||||
//! \brief No error was encountered but the application should call the
|
||||
//! method again to continue the operation
|
||||
#define MSDD_STATUS_INCOMPLETE 0x02
|
||||
|
||||
//! \brief A wrong parameter has been passed to the method
|
||||
#define MSDD_STATUS_PARAMETER 0x03
|
||||
|
||||
//! \brief An error when reading/writing disk (protected or not present)
|
||||
#define MSDD_STATUS_RW 0x04
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Action Cases"
|
||||
/// This page lists actions to perform during the post-processing phase of a
|
||||
/// command.
|
||||
///
|
||||
/// !Actions
|
||||
/// - MSDD_CASE_PHASE_ERROR
|
||||
/// - MSDD_CASE_STALL_IN
|
||||
/// - MSDD_CASE_STALL_OUT
|
||||
|
||||
//! \brief Indicates that the CSW should report a phase error
|
||||
#define MSDD_CASE_PHASE_ERROR (1 << 0)
|
||||
|
||||
//! \brief The driver should halt the Bulk IN pipe after the transfer
|
||||
#define MSDD_CASE_STALL_IN (1 << 1)
|
||||
|
||||
//! \brief The driver should halt the Bulk OUT pipe after the transfer
|
||||
#define MSDD_CASE_STALL_OUT (1 << 2)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Xfr Directions"
|
||||
/// This page lists possible direction values for a data transfer
|
||||
///
|
||||
/// !Directions
|
||||
/// - MSDD_DEVICE_TO_HOST
|
||||
/// - MSDD_HOST_TO_DEVICE
|
||||
/// - MSDD_NO_TRANSFER
|
||||
|
||||
#define MSDD_DEVICE_TO_HOST 0
|
||||
#define MSDD_HOST_TO_DEVICE 1
|
||||
#define MSDD_NO_TRANSFER 2
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Structure for holding the result of a USB transfer
|
||||
//! \see MSDDriver_Callback
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
volatile unsigned int transferred; /// Number of bytes transferred
|
||||
volatile unsigned int remaining; /// Number of bytes not transferred
|
||||
volatile unsigned short semaphore; /// Semaphore to indicate transfer completion
|
||||
volatile unsigned short status; /// Operation result code
|
||||
|
||||
} MSDTransfer;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Status of an executing command
|
||||
//! \see MSDCbw
|
||||
//! \see MSDCsw
|
||||
//! \see MSDTransfer
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
MSDTransfer transfer; /// Current transfer status (USB)
|
||||
MSDTransfer disktransfer;/// Current transfer status (Disk)
|
||||
unsigned int length; /// Remaining length of command
|
||||
MSCbw cbw; /// Received CBW (31 bytes)
|
||||
unsigned char state; /// Current command state
|
||||
MSCsw csw; /// CSW to send (13 bytes)
|
||||
unsigned char postprocess; /// Actions to perform when command is complete
|
||||
|
||||
} MSDCommandState;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \brief MSD driver state variables
|
||||
/// \see MSDCommandState
|
||||
/// \see MSDLun
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// LUN list for the %device.
|
||||
MSDLun *luns;
|
||||
/// State of the currently executing command
|
||||
MSDCommandState commandState;
|
||||
/// Maximum LUN index
|
||||
unsigned char maxLun;
|
||||
/// Current state of the driver
|
||||
unsigned char state;
|
||||
/// Indicates if the driver is waiting for a reset recovery
|
||||
unsigned char waitResetRecovery;
|
||||
|
||||
} MSDDriver;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inline functions
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
/// This function is to be used as a callback for USB or LUN transfers.
|
||||
/// \param transfer Pointer to the transfer structure to update
|
||||
/// \param status Operation result code
|
||||
/// \param transferred Number of bytes transferred by the command
|
||||
/// \param remaining Number of bytes not transferred
|
||||
//-----------------------------------------------------------------------------
|
||||
static inline void MSDDriver_Callback(MSDTransfer *transfer,
|
||||
unsigned char status,
|
||||
unsigned int transferred,
|
||||
unsigned int remaining)
|
||||
{
|
||||
TRACE_DEBUG("Cbk ");
|
||||
transfer->semaphore++;
|
||||
transfer->status = status;
|
||||
transfer->transferred = transferred;
|
||||
transfer->remaining = remaining;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Driver functions
|
||||
//-----------------------------------------------------------------------------
|
||||
//- MSD General support function
|
||||
extern char MSDD_Read(
|
||||
void* pData,
|
||||
unsigned int dLength,
|
||||
TransferCallback fCallback,
|
||||
void* pArgument);
|
||||
|
||||
extern char MSDD_Write(
|
||||
void* pData,
|
||||
unsigned int dLength,
|
||||
TransferCallback fCallback,
|
||||
void* pArgument);
|
||||
|
||||
extern void MSDD_Halt(unsigned int stallCase);
|
||||
|
||||
extern unsigned int MSDD_IsHalted(void);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
extern void MSDD_StateMachine(MSDDriver * pMsdDriver);
|
||||
|
||||
#endif // #define MSDDSTATEMACHINE_H
|
||||
|
||||
|
||||
@@ -1,342 +1,342 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Includes
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDDriver.h"
|
||||
|
||||
#include "../../../usb/common/core/USBFeatureRequest.h"
|
||||
#include "../../../usb/device/core/USBDDriver.h"
|
||||
#include "../../../usb/device/massstorage/MSDDriverDescriptors.h"
|
||||
#include "../../../usb/device/massstorage/SBCMethods.h"
|
||||
#include "../../../Media.h"
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
#include "debug.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Internal variables
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// Mass storage device driver instance.
|
||||
static MSDDriver msdDriver;
|
||||
|
||||
/// Standard device driver instance.
|
||||
static USBDDriver usbdDriver;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Internal functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Resets the state of the MSD driver
|
||||
//-----------------------------------------------------------------------------
|
||||
static void MSDDriver_Reset(void)
|
||||
{
|
||||
TRACE_INFO_WP("MSDReset ");
|
||||
|
||||
msdDriver.state = MSDD_STATE_READ_CBW;
|
||||
msdDriver.waitResetRecovery = 0;
|
||||
msdDriver.commandState.state = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Callback re-implementation
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Invoked when a new SETUP request is received from the host. Forwards the
|
||||
/// request to the Mass Storage device driver handler function.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
//-----------------------------------------------------------------------------
|
||||
void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
|
||||
{
|
||||
MSDDriver_RequestHandler(request);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Invoked when the configuration of the device changes. Resets the mass
|
||||
/// storage driver.
|
||||
/// \param cfgnum New configuration number.
|
||||
//-----------------------------------------------------------------------------
|
||||
void USBDDriverCallbacks_ConfigurationChanged(unsigned char cfgnum)
|
||||
{
|
||||
if (cfgnum > 0) {
|
||||
|
||||
MSDDriver_Reset();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Driver functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Reads from host through MSD defined bulk OUT pipe. Act as USBD_Read but by
|
||||
/// a fixed OUT endpoint.
|
||||
/// \param data Pointer to the data buffer that contains data read from host.
|
||||
/// \param size The number of bytes should be read (buffer size).
|
||||
/// \param callback Pointer to the function invoked on end of reading.
|
||||
/// \param argument Pointer to additional argument data struct.
|
||||
//-----------------------------------------------------------------------------
|
||||
char MSDD_Read(void *data,
|
||||
unsigned int size,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
|
||||
{
|
||||
return USBD_Read(MSDDriverDescriptors_BULKOUT,
|
||||
data,
|
||||
size,
|
||||
callback,
|
||||
argument);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Writes to host through MSD defined bulk IN pipe. Act as USBD_Write but by
|
||||
/// a fixed IN endpoint.
|
||||
/// \param data Pointer to the data that writes to the host.
|
||||
/// \param size The number of bytes should be write.
|
||||
/// \param callback Pointer to the function invoked on end of writing.
|
||||
/// \param argument Pointer to additional argument data struct.
|
||||
//-----------------------------------------------------------------------------
|
||||
char MSDD_Write(void *data,
|
||||
unsigned int size,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
return USBD_Write(MSDDriverDescriptors_BULKIN,
|
||||
data,
|
||||
size,
|
||||
callback,
|
||||
argument);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// HALT Specified USB pipe.
|
||||
/// \param stallCASE Case of the stall condition (Bulk In/Out/Both).
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDD_Halt(unsigned int stallCASE)
|
||||
{
|
||||
if (stallCASE & MSDD_CASE_STALL_OUT) {
|
||||
|
||||
USBD_Halt(MSDDriverDescriptors_BULKOUT);
|
||||
}
|
||||
|
||||
if (stallCASE & MSDD_CASE_STALL_IN) {
|
||||
|
||||
USBD_Halt(MSDDriverDescriptors_BULKIN);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Return halted status
|
||||
/// \return stallCASE bitmap, case of the stall condition
|
||||
/// (bit: MSDD_CASE_STALL_OUT or MSDD_CASE_STALL_IN)
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned int MSDD_IsHalted(void)
|
||||
{
|
||||
unsigned int stallCASE = 0;
|
||||
if (USBD_IsHalted(MSDDriverDescriptors_BULKOUT)) {
|
||||
|
||||
stallCASE |= MSDD_CASE_STALL_OUT;
|
||||
}
|
||||
if (USBD_IsHalted(MSDDriverDescriptors_BULKIN)) {
|
||||
|
||||
stallCASE |= MSDD_CASE_STALL_IN;
|
||||
}
|
||||
return stallCASE;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Initializes the MSD driver and the associated USB driver.
|
||||
/// \param luns Pointer to a list of LUNs
|
||||
/// \param numLuns Number of LUN in list
|
||||
/// \see MSDLun
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_Initialize(MSDLun *defLuns, unsigned char numLuns)
|
||||
{
|
||||
|
||||
TRACE_INFO("MSD init\n\r");
|
||||
|
||||
// Command state initialization
|
||||
msdDriver.commandState.state = 0;
|
||||
msdDriver.commandState.postprocess = 0;
|
||||
msdDriver.commandState.length = 0;
|
||||
msdDriver.commandState.transfer.semaphore = 0;
|
||||
|
||||
// LUNs
|
||||
msdDriver.luns = defLuns;
|
||||
msdDriver.maxLun = (unsigned char) (numLuns - 1);
|
||||
|
||||
// Reset BOT driver
|
||||
MSDDriver_Reset();
|
||||
|
||||
// Init the USB driver
|
||||
USBDDriver_Initialize(&usbdDriver, &msdDriverDescriptors, 0);
|
||||
USBD_Init();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Handler for incoming SETUP requests on default Control endpoint 0.
|
||||
///
|
||||
/// Standard requests are forwarded to the USBDDriver_RequestHandler
|
||||
/// method.
|
||||
/// \param request Pointer to a USBGenericRequest instance
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_RequestHandler(const USBGenericRequest *request)
|
||||
{
|
||||
TRACE_INFO_WP("NewReq ");
|
||||
|
||||
// Handle requests
|
||||
switch (USBGenericRequest_GetRequest(request)) {
|
||||
//---------------------
|
||||
case USBGenericRequest_CLEARFEATURE:
|
||||
//---------------------
|
||||
TRACE_INFO_WP("ClrFeat ");
|
||||
|
||||
switch (USBFeatureRequest_GetFeatureSelector(request)) {
|
||||
|
||||
//---------------------
|
||||
case USBFeatureRequest_ENDPOINTHALT:
|
||||
//---------------------
|
||||
TRACE_INFO_WP("Hlt ");
|
||||
|
||||
// Do not clear the endpoint halt status if the device is waiting
|
||||
// for a reset recovery sequence
|
||||
if (!msdDriver.waitResetRecovery) {
|
||||
|
||||
// Forward the request to the standard handler
|
||||
USBDDriver_RequestHandler(&usbdDriver, request);
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_INFO_WP("No ");
|
||||
}
|
||||
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
break;
|
||||
|
||||
//------
|
||||
default:
|
||||
//------
|
||||
// Forward the request to the standard handler
|
||||
USBDDriver_RequestHandler(&usbdDriver, request);
|
||||
}
|
||||
break;
|
||||
|
||||
//-------------------
|
||||
case MSD_GET_MAX_LUN:
|
||||
//-------------------
|
||||
TRACE_INFO_WP("gMaxLun ");
|
||||
|
||||
// Check request parameters
|
||||
if ((request->wValue == 0)
|
||||
&& (request->wIndex == 0)
|
||||
&& (request->wLength == 1)) {
|
||||
|
||||
USBD_Write(0, &(msdDriver.maxLun), 1, 0, 0);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING(
|
||||
"MSDDriver_RequestHandler: GetMaxLUN(%d,%d,%d)\n\r",
|
||||
request->wValue, request->wIndex, request->wLength);
|
||||
USBD_Stall(0);
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------
|
||||
case MSD_BULK_ONLY_RESET:
|
||||
//-----------------------
|
||||
TRACE_INFO_WP("Rst ");
|
||||
|
||||
// Check parameters
|
||||
if ((request->wValue == 0)
|
||||
&& (request->wIndex == 0)
|
||||
&& (request->wLength == 0)) {
|
||||
|
||||
// Reset the MSD driver
|
||||
MSDDriver_Reset();
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING(
|
||||
"MSDDriver_RequestHandler: Reset(%d,%d,%d)\n\r",
|
||||
request->wValue, request->wIndex, request->wLength);
|
||||
USBD_Stall(0);
|
||||
}
|
||||
break;
|
||||
|
||||
//------
|
||||
default:
|
||||
//------
|
||||
// Forward request to standard handler
|
||||
USBDDriver_RequestHandler(&usbdDriver, request);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// State machine for the MSD driver
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_StateMachine(void)
|
||||
{
|
||||
if (USBD_GetState() < USBD_STATE_CONFIGURED){}
|
||||
else MSDD_StateMachine(&msdDriver);
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Starts a remote wake-up sequence if the host has explicitely enabled it
|
||||
/// by sending the appropriate SET_FEATURE request.
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_RemoteWakeUp(void)
|
||||
{
|
||||
// Remote wake-up has been enabled
|
||||
if (USBDDriver_IsRemoteWakeUpEnabled(&usbdDriver)) {
|
||||
|
||||
USBD_RemoteWakeUp();
|
||||
}
|
||||
// Remote wake-up NOT enabled
|
||||
else {
|
||||
|
||||
TRACE_WARNING(
|
||||
"MSD..RemoteWakeUp: Host has not enabled remote wake-up\n\r");
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Includes
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDDriver.h"
|
||||
|
||||
#include "../../../usb/common/core/USBFeatureRequest.h"
|
||||
#include "../../../usb/device/core/USBDDriver.h"
|
||||
#include "../../../usb/device/massstorage/MSDDriverDescriptors.h"
|
||||
#include "../../../usb/device/massstorage/SBCMethods.h"
|
||||
#include "../../../Media.h"
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
#include "debug.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Internal variables
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// Mass storage device driver instance.
|
||||
static MSDDriver msdDriver;
|
||||
|
||||
/// Standard device driver instance.
|
||||
static USBDDriver usbdDriver;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Internal functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Resets the state of the MSD driver
|
||||
//-----------------------------------------------------------------------------
|
||||
static void MSDDriver_Reset(void)
|
||||
{
|
||||
TRACE_INFO_WP("MSDReset ");
|
||||
|
||||
msdDriver.state = MSDD_STATE_READ_CBW;
|
||||
msdDriver.waitResetRecovery = 0;
|
||||
msdDriver.commandState.state = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Callback re-implementation
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Invoked when a new SETUP request is received from the host. Forwards the
|
||||
/// request to the Mass Storage device driver handler function.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
//-----------------------------------------------------------------------------
|
||||
void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
|
||||
{
|
||||
MSDDriver_RequestHandler(request);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Invoked when the configuration of the device changes. Resets the mass
|
||||
/// storage driver.
|
||||
/// \param cfgnum New configuration number.
|
||||
//-----------------------------------------------------------------------------
|
||||
void USBDDriverCallbacks_ConfigurationChanged(unsigned char cfgnum)
|
||||
{
|
||||
if (cfgnum > 0) {
|
||||
|
||||
MSDDriver_Reset();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Driver functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Reads from host through MSD defined bulk OUT pipe. Act as USBD_Read but by
|
||||
/// a fixed OUT endpoint.
|
||||
/// \param data Pointer to the data buffer that contains data read from host.
|
||||
/// \param size The number of bytes should be read (buffer size).
|
||||
/// \param callback Pointer to the function invoked on end of reading.
|
||||
/// \param argument Pointer to additional argument data struct.
|
||||
//-----------------------------------------------------------------------------
|
||||
char MSDD_Read(void *data,
|
||||
unsigned int size,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
|
||||
{
|
||||
return USBD_Read(MSDDriverDescriptors_BULKOUT,
|
||||
data,
|
||||
size,
|
||||
callback,
|
||||
argument);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Writes to host through MSD defined bulk IN pipe. Act as USBD_Write but by
|
||||
/// a fixed IN endpoint.
|
||||
/// \param data Pointer to the data that writes to the host.
|
||||
/// \param size The number of bytes should be write.
|
||||
/// \param callback Pointer to the function invoked on end of writing.
|
||||
/// \param argument Pointer to additional argument data struct.
|
||||
//-----------------------------------------------------------------------------
|
||||
char MSDD_Write(void *data,
|
||||
unsigned int size,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
return USBD_Write(MSDDriverDescriptors_BULKIN,
|
||||
data,
|
||||
size,
|
||||
callback,
|
||||
argument);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// HALT Specified USB pipe.
|
||||
/// \param stallCASE Case of the stall condition (Bulk In/Out/Both).
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDD_Halt(unsigned int stallCASE)
|
||||
{
|
||||
if (stallCASE & MSDD_CASE_STALL_OUT) {
|
||||
|
||||
USBD_Halt(MSDDriverDescriptors_BULKOUT);
|
||||
}
|
||||
|
||||
if (stallCASE & MSDD_CASE_STALL_IN) {
|
||||
|
||||
USBD_Halt(MSDDriverDescriptors_BULKIN);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Return halted status
|
||||
/// \return stallCASE bitmap, case of the stall condition
|
||||
/// (bit: MSDD_CASE_STALL_OUT or MSDD_CASE_STALL_IN)
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned int MSDD_IsHalted(void)
|
||||
{
|
||||
unsigned int stallCASE = 0;
|
||||
if (USBD_IsHalted(MSDDriverDescriptors_BULKOUT)) {
|
||||
|
||||
stallCASE |= MSDD_CASE_STALL_OUT;
|
||||
}
|
||||
if (USBD_IsHalted(MSDDriverDescriptors_BULKIN)) {
|
||||
|
||||
stallCASE |= MSDD_CASE_STALL_IN;
|
||||
}
|
||||
return stallCASE;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Initializes the MSD driver and the associated USB driver.
|
||||
/// \param luns Pointer to a list of LUNs
|
||||
/// \param numLuns Number of LUN in list
|
||||
/// \see MSDLun
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_Initialize(MSDLun *defLuns, unsigned char numLuns)
|
||||
{
|
||||
|
||||
TRACE_INFO("MSD init\n\r");
|
||||
|
||||
// Command state initialization
|
||||
msdDriver.commandState.state = 0;
|
||||
msdDriver.commandState.postprocess = 0;
|
||||
msdDriver.commandState.length = 0;
|
||||
msdDriver.commandState.transfer.semaphore = 0;
|
||||
|
||||
// LUNs
|
||||
msdDriver.luns = defLuns;
|
||||
msdDriver.maxLun = (unsigned char) (numLuns - 1);
|
||||
|
||||
// Reset BOT driver
|
||||
MSDDriver_Reset();
|
||||
|
||||
// Init the USB driver
|
||||
USBDDriver_Initialize(&usbdDriver, &msdDriverDescriptors, 0);
|
||||
USBD_Init();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Handler for incoming SETUP requests on default Control endpoint 0.
|
||||
///
|
||||
/// Standard requests are forwarded to the USBDDriver_RequestHandler
|
||||
/// method.
|
||||
/// \param request Pointer to a USBGenericRequest instance
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_RequestHandler(const USBGenericRequest *request)
|
||||
{
|
||||
TRACE_INFO_WP("NewReq ");
|
||||
|
||||
// Handle requests
|
||||
switch (USBGenericRequest_GetRequest(request)) {
|
||||
//---------------------
|
||||
case USBGenericRequest_CLEARFEATURE:
|
||||
//---------------------
|
||||
TRACE_INFO_WP("ClrFeat ");
|
||||
|
||||
switch (USBFeatureRequest_GetFeatureSelector(request)) {
|
||||
|
||||
//---------------------
|
||||
case USBFeatureRequest_ENDPOINTHALT:
|
||||
//---------------------
|
||||
TRACE_INFO_WP("Hlt ");
|
||||
|
||||
// Do not clear the endpoint halt status if the device is waiting
|
||||
// for a reset recovery sequence
|
||||
if (!msdDriver.waitResetRecovery) {
|
||||
|
||||
// Forward the request to the standard handler
|
||||
USBDDriver_RequestHandler(&usbdDriver, request);
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_INFO_WP("No ");
|
||||
}
|
||||
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
break;
|
||||
|
||||
//------
|
||||
default:
|
||||
//------
|
||||
// Forward the request to the standard handler
|
||||
USBDDriver_RequestHandler(&usbdDriver, request);
|
||||
}
|
||||
break;
|
||||
|
||||
//-------------------
|
||||
case MSD_GET_MAX_LUN:
|
||||
//-------------------
|
||||
TRACE_INFO_WP("gMaxLun ");
|
||||
|
||||
// Check request parameters
|
||||
if ((request->wValue == 0)
|
||||
&& (request->wIndex == 0)
|
||||
&& (request->wLength == 1)) {
|
||||
|
||||
USBD_Write(0, &(msdDriver.maxLun), 1, 0, 0);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING(
|
||||
"MSDDriver_RequestHandler: GetMaxLUN(%d,%d,%d)\n\r",
|
||||
request->wValue, request->wIndex, request->wLength);
|
||||
USBD_Stall(0);
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------
|
||||
case MSD_BULK_ONLY_RESET:
|
||||
//-----------------------
|
||||
TRACE_INFO_WP("Rst ");
|
||||
|
||||
// Check parameters
|
||||
if ((request->wValue == 0)
|
||||
&& (request->wIndex == 0)
|
||||
&& (request->wLength == 0)) {
|
||||
|
||||
// Reset the MSD driver
|
||||
MSDDriver_Reset();
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING(
|
||||
"MSDDriver_RequestHandler: Reset(%d,%d,%d)\n\r",
|
||||
request->wValue, request->wIndex, request->wLength);
|
||||
USBD_Stall(0);
|
||||
}
|
||||
break;
|
||||
|
||||
//------
|
||||
default:
|
||||
//------
|
||||
// Forward request to standard handler
|
||||
USBDDriver_RequestHandler(&usbdDriver, request);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// State machine for the MSD driver
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_StateMachine(void)
|
||||
{
|
||||
if (USBD_GetState() < USBD_STATE_CONFIGURED){}
|
||||
else MSDD_StateMachine(&msdDriver);
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Starts a remote wake-up sequence if the host has explicitely enabled it
|
||||
/// by sending the appropriate SET_FEATURE request.
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_RemoteWakeUp(void)
|
||||
{
|
||||
// Remote wake-up has been enabled
|
||||
if (USBDDriver_IsRemoteWakeUpEnabled(&usbdDriver)) {
|
||||
|
||||
USBD_RemoteWakeUp();
|
||||
}
|
||||
// Remote wake-up NOT enabled
|
||||
else {
|
||||
|
||||
TRACE_WARNING(
|
||||
"MSD..RemoteWakeUp: Host has not enabled remote wake-up\n\r");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,75 +1,75 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Mass storage %device driver implementation.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Enable and setup USB related pins (see pio & board.h).
|
||||
/// -# Configure the memory interfaces used for Mass Storage LUNs
|
||||
/// (see memories, MSDLun.h).
|
||||
/// -# Configure the USB MSD %driver using MSDDriver_Initialize.
|
||||
/// -# Invoke MSDDriver_StateMachine in main loop to handle all Mass Storage
|
||||
/// operations.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDDRIVER_H
|
||||
#define MSDDRIVER_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSD.h"
|
||||
#include "../../../usb/device/massstorage/MSDLun.h"
|
||||
// #include <utility/trace.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void MSDDriver_Initialize(MSDLun *luns, unsigned char numLuns);
|
||||
|
||||
extern void MSDDriver_RequestHandler(const USBGenericRequest *request);
|
||||
|
||||
extern void MSDDriver_StateMachine(void);
|
||||
|
||||
extern void MSDDriver_RemoteWakeUp(void);
|
||||
|
||||
extern void MSDDriver_DataCallback(unsigned char isRead,
|
||||
unsigned int dataLength,
|
||||
unsigned int nullCnt,
|
||||
unsigned int fullCnt);
|
||||
|
||||
#endif // #ifndef MSDDRIVER_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Mass storage %device driver implementation.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Enable and setup USB related pins (see pio & board.h).
|
||||
/// -# Configure the memory interfaces used for Mass Storage LUNs
|
||||
/// (see memories, MSDLun.h).
|
||||
/// -# Configure the USB MSD %driver using MSDDriver_Initialize.
|
||||
/// -# Invoke MSDDriver_StateMachine in main loop to handle all Mass Storage
|
||||
/// operations.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDDRIVER_H
|
||||
#define MSDDRIVER_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSD.h"
|
||||
#include "../../../usb/device/massstorage/MSDLun.h"
|
||||
// #include <utility/trace.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void MSDDriver_Initialize(MSDLun *luns, unsigned char numLuns);
|
||||
|
||||
extern void MSDDriver_RequestHandler(const USBGenericRequest *request);
|
||||
|
||||
extern void MSDDriver_StateMachine(void);
|
||||
|
||||
extern void MSDDriver_RemoteWakeUp(void);
|
||||
|
||||
extern void MSDDriver_DataCallback(unsigned char isRead,
|
||||
unsigned int dataLength,
|
||||
unsigned int nullCnt,
|
||||
unsigned int fullCnt);
|
||||
|
||||
#endif // #ifndef MSDDRIVER_H
|
||||
|
||||
|
||||
@@ -1,469 +1,469 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDDriverDescriptors.h"
|
||||
|
||||
#include "../../../usb/common/core/USBStringDescriptor.h"
|
||||
#include "../../../usb/common/massstorage/MSDeviceDescriptor.h"
|
||||
#include "../../../usb/common/massstorage/MSInterfaceDescriptor.h"
|
||||
#include "board_lowlevel.h"
|
||||
#include "../../../usb/common/core/USBConfigurationDescriptor.h"
|
||||
#include "../../../usb/common/core/USBDeviceDescriptor.h"
|
||||
#include "../../../usb/common/core/USBEndpointDescriptor.h"
|
||||
#include "../../../usb/common/core/USBGenericDescriptor.h"
|
||||
#include "../../../usb/common/core/USBInterfaceDescriptor.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Device Descriptor IDs"
|
||||
/// ...
|
||||
/// !IDs
|
||||
/// - MSDDriverDescriptors_VENDORID
|
||||
/// - MSDDriverDescriptors_PRODUCTID
|
||||
/// - MSDDriverDescriptors_RELEASE
|
||||
|
||||
/// Vendor ID for the Mass Storage device driver.
|
||||
#define MSDDriverDescriptors_VENDORID 0x03EB
|
||||
/// Product ID for the Mass Storage device driver.
|
||||
#define MSDDriverDescriptors_PRODUCTID 0x6129
|
||||
/// Device release number for the Mass Storage device driver.
|
||||
#define MSDDriverDescriptors_RELEASE 0x0100
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Macros
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Returns the minimum between two values.
|
||||
#define MIN(a, b) ((a < b) ? a : b)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// List of configuration descriptors used by a Mass Storage device driver.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Standard configuration descriptor.
|
||||
USBConfigurationDescriptor configuration;
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
USBOtgDescriptor otgDescriptor;
|
||||
#endif
|
||||
/// Mass storage interface descriptor.
|
||||
USBInterfaceDescriptor interface;
|
||||
/// Bulk-out endpoint descriptor.
|
||||
USBEndpointDescriptor bulkOut;
|
||||
/// Bulk-in endpoint descriptor.
|
||||
USBEndpointDescriptor bulkIn;
|
||||
|
||||
} __attribute__ ((packed)) MSDConfigurationDescriptors;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Local variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Mass storage driver device descriptor.
|
||||
static const USBDeviceDescriptor deviceDescriptor = {
|
||||
|
||||
sizeof(USBDeviceDescriptor),
|
||||
USBGenericDescriptor_DEVICE,
|
||||
USBDeviceDescriptor_USB2_00,
|
||||
MSDeviceDescriptor_CLASS,
|
||||
MSDeviceDescriptor_SUBCLASS,
|
||||
MSDeviceDescriptor_PROTOCOL,
|
||||
CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
|
||||
MSDDriverDescriptors_VENDORID,
|
||||
MSDDriverDescriptors_PRODUCTID,
|
||||
MSDDriverDescriptors_RELEASE,
|
||||
1, // Manufacturer string descriptor index.
|
||||
2, // Product string descriptor index.
|
||||
3, // Serial number string descriptor index.
|
||||
1 // Device has one possible configuration.
|
||||
};
|
||||
|
||||
#if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS)
|
||||
/// Device qualifier descriptor.
|
||||
static const USBDeviceQualifierDescriptor qualifierDescriptor = {
|
||||
|
||||
sizeof(USBDeviceQualifierDescriptor),
|
||||
USBGenericDescriptor_DEVICEQUALIFIER,
|
||||
USBDeviceDescriptor_USB2_00,
|
||||
MSDeviceDescriptor_CLASS,
|
||||
MSDeviceDescriptor_SUBCLASS,
|
||||
MSDeviceDescriptor_PROTOCOL,
|
||||
CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
|
||||
1, // Device has one possible configuration.
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
/// Full-speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors configurationDescriptorsFS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_CONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // Must be 0 for full-speed Bulk endpoints.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // Must be 0 for full-speed Bulk endpoints.
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS)
|
||||
/// Full-speed other speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors otherSpeedDescriptorsFS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
}
|
||||
};
|
||||
|
||||
/// High-speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors configurationDescriptorsHS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_CONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
}
|
||||
};
|
||||
|
||||
/// High-speed other speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors otherSpeedDescriptorsHS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // No string descriptor for endpoint.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // No string descriptor for endpoint.
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
/// Language ID string descriptor.
|
||||
static const unsigned char languageIdDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(1),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_ENGLISH_US
|
||||
};
|
||||
|
||||
/// Manufacturer string descriptor.
|
||||
static const unsigned char manufacturerDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(7),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('9'),
|
||||
USBStringDescriptor_UNICODE('X'),
|
||||
USBStringDescriptor_UNICODE(' '),
|
||||
USBStringDescriptor_UNICODE('T'),
|
||||
USBStringDescriptor_UNICODE('E'),
|
||||
USBStringDescriptor_UNICODE('A'),
|
||||
USBStringDescriptor_UNICODE('M'),
|
||||
};
|
||||
|
||||
/// Product string descriptor.
|
||||
static const unsigned char productDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(5),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('S'),
|
||||
USBStringDescriptor_UNICODE('K'),
|
||||
USBStringDescriptor_UNICODE('Y'),
|
||||
USBStringDescriptor_UNICODE('9'),
|
||||
USBStringDescriptor_UNICODE('X'),
|
||||
};
|
||||
|
||||
/// Serial number string descriptor. The serial number must be at least 12
|
||||
/// characters long and made up of only letters & numbers to be compliant with
|
||||
/// the MSD specification.
|
||||
static const unsigned char serialNumberDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(12),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('0'),
|
||||
USBStringDescriptor_UNICODE('1'),
|
||||
USBStringDescriptor_UNICODE('2'),
|
||||
USBStringDescriptor_UNICODE('3'),
|
||||
USBStringDescriptor_UNICODE('4'),
|
||||
USBStringDescriptor_UNICODE('5'),
|
||||
USBStringDescriptor_UNICODE('6'),
|
||||
USBStringDescriptor_UNICODE('7'),
|
||||
USBStringDescriptor_UNICODE('8'),
|
||||
USBStringDescriptor_UNICODE('9'),
|
||||
USBStringDescriptor_UNICODE('A'),
|
||||
USBStringDescriptor_UNICODE('B')
|
||||
};
|
||||
|
||||
/// List of all string descriptors used.
|
||||
static const unsigned char *stringDescriptors[] = {
|
||||
|
||||
languageIdDescriptor,
|
||||
manufacturerDescriptor,
|
||||
productDescriptor,
|
||||
serialNumberDescriptor
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// List of the standard descriptors used by the Mass Storage driver.
|
||||
const USBDDriverDescriptors msdDriverDescriptors = {
|
||||
|
||||
&deviceDescriptor,
|
||||
(USBConfigurationDescriptor *) &configurationDescriptorsFS,
|
||||
#if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS)
|
||||
&qualifierDescriptor,
|
||||
(USBConfigurationDescriptor *) &otherSpeedDescriptorsFS,
|
||||
&deviceDescriptor,
|
||||
(USBConfigurationDescriptor *) &configurationDescriptorsHS,
|
||||
&qualifierDescriptor,
|
||||
(USBConfigurationDescriptor *) &otherSpeedDescriptorsHS,
|
||||
#else
|
||||
0, // No full-speed device qualifier descriptor
|
||||
0, // No full-speed other speed configuration
|
||||
0, // No high-speed device descriptor
|
||||
0, // No high-speed configuration descriptor
|
||||
0, // No high-speed device qualifier descriptor
|
||||
0, // No high-speed other speed configuration descriptor
|
||||
#endif
|
||||
stringDescriptors,
|
||||
4 // Four string descriptors in array
|
||||
};
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDDriverDescriptors.h"
|
||||
|
||||
#include "../../../usb/common/core/USBStringDescriptor.h"
|
||||
#include "../../../usb/common/massstorage/MSDeviceDescriptor.h"
|
||||
#include "../../../usb/common/massstorage/MSInterfaceDescriptor.h"
|
||||
#include "board_lowlevel.h"
|
||||
#include "../../../usb/common/core/USBConfigurationDescriptor.h"
|
||||
#include "../../../usb/common/core/USBDeviceDescriptor.h"
|
||||
#include "../../../usb/common/core/USBEndpointDescriptor.h"
|
||||
#include "../../../usb/common/core/USBGenericDescriptor.h"
|
||||
#include "../../../usb/common/core/USBInterfaceDescriptor.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Device Descriptor IDs"
|
||||
/// ...
|
||||
/// !IDs
|
||||
/// - MSDDriverDescriptors_VENDORID
|
||||
/// - MSDDriverDescriptors_PRODUCTID
|
||||
/// - MSDDriverDescriptors_RELEASE
|
||||
|
||||
/// Vendor ID for the Mass Storage device driver.
|
||||
#define MSDDriverDescriptors_VENDORID 0x03EB
|
||||
/// Product ID for the Mass Storage device driver.
|
||||
#define MSDDriverDescriptors_PRODUCTID 0x6129
|
||||
/// Device release number for the Mass Storage device driver.
|
||||
#define MSDDriverDescriptors_RELEASE 0x0100
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Macros
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Returns the minimum between two values.
|
||||
#define MIN(a, b) ((a < b) ? a : b)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// List of configuration descriptors used by a Mass Storage device driver.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Standard configuration descriptor.
|
||||
USBConfigurationDescriptor configuration;
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
USBOtgDescriptor otgDescriptor;
|
||||
#endif
|
||||
/// Mass storage interface descriptor.
|
||||
USBInterfaceDescriptor interface;
|
||||
/// Bulk-out endpoint descriptor.
|
||||
USBEndpointDescriptor bulkOut;
|
||||
/// Bulk-in endpoint descriptor.
|
||||
USBEndpointDescriptor bulkIn;
|
||||
|
||||
} __attribute__ ((packed)) MSDConfigurationDescriptors;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Local variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Mass storage driver device descriptor.
|
||||
static const USBDeviceDescriptor deviceDescriptor = {
|
||||
|
||||
sizeof(USBDeviceDescriptor),
|
||||
USBGenericDescriptor_DEVICE,
|
||||
USBDeviceDescriptor_USB2_00,
|
||||
MSDeviceDescriptor_CLASS,
|
||||
MSDeviceDescriptor_SUBCLASS,
|
||||
MSDeviceDescriptor_PROTOCOL,
|
||||
CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
|
||||
MSDDriverDescriptors_VENDORID,
|
||||
MSDDriverDescriptors_PRODUCTID,
|
||||
MSDDriverDescriptors_RELEASE,
|
||||
1, // Manufacturer string descriptor index.
|
||||
2, // Product string descriptor index.
|
||||
3, // Serial number string descriptor index.
|
||||
1 // Device has one possible configuration.
|
||||
};
|
||||
|
||||
#if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS)
|
||||
/// Device qualifier descriptor.
|
||||
static const USBDeviceQualifierDescriptor qualifierDescriptor = {
|
||||
|
||||
sizeof(USBDeviceQualifierDescriptor),
|
||||
USBGenericDescriptor_DEVICEQUALIFIER,
|
||||
USBDeviceDescriptor_USB2_00,
|
||||
MSDeviceDescriptor_CLASS,
|
||||
MSDeviceDescriptor_SUBCLASS,
|
||||
MSDeviceDescriptor_PROTOCOL,
|
||||
CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
|
||||
1, // Device has one possible configuration.
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
/// Full-speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors configurationDescriptorsFS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_CONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // Must be 0 for full-speed Bulk endpoints.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // Must be 0 for full-speed Bulk endpoints.
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS)
|
||||
/// Full-speed other speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors otherSpeedDescriptorsFS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
}
|
||||
};
|
||||
|
||||
/// High-speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors configurationDescriptorsHS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_CONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
}
|
||||
};
|
||||
|
||||
/// High-speed other speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors otherSpeedDescriptorsHS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // No string descriptor for endpoint.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // No string descriptor for endpoint.
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
/// Language ID string descriptor.
|
||||
static const unsigned char languageIdDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(1),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_ENGLISH_US
|
||||
};
|
||||
|
||||
/// Manufacturer string descriptor.
|
||||
static const unsigned char manufacturerDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(7),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('9'),
|
||||
USBStringDescriptor_UNICODE('X'),
|
||||
USBStringDescriptor_UNICODE(' '),
|
||||
USBStringDescriptor_UNICODE('T'),
|
||||
USBStringDescriptor_UNICODE('E'),
|
||||
USBStringDescriptor_UNICODE('A'),
|
||||
USBStringDescriptor_UNICODE('M'),
|
||||
};
|
||||
|
||||
/// Product string descriptor.
|
||||
static const unsigned char productDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(5),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('S'),
|
||||
USBStringDescriptor_UNICODE('K'),
|
||||
USBStringDescriptor_UNICODE('Y'),
|
||||
USBStringDescriptor_UNICODE('9'),
|
||||
USBStringDescriptor_UNICODE('X'),
|
||||
};
|
||||
|
||||
/// Serial number string descriptor. The serial number must be at least 12
|
||||
/// characters long and made up of only letters & numbers to be compliant with
|
||||
/// the MSD specification.
|
||||
static const unsigned char serialNumberDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(12),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('0'),
|
||||
USBStringDescriptor_UNICODE('1'),
|
||||
USBStringDescriptor_UNICODE('2'),
|
||||
USBStringDescriptor_UNICODE('3'),
|
||||
USBStringDescriptor_UNICODE('4'),
|
||||
USBStringDescriptor_UNICODE('5'),
|
||||
USBStringDescriptor_UNICODE('6'),
|
||||
USBStringDescriptor_UNICODE('7'),
|
||||
USBStringDescriptor_UNICODE('8'),
|
||||
USBStringDescriptor_UNICODE('9'),
|
||||
USBStringDescriptor_UNICODE('A'),
|
||||
USBStringDescriptor_UNICODE('B')
|
||||
};
|
||||
|
||||
/// List of all string descriptors used.
|
||||
static const unsigned char *stringDescriptors[] = {
|
||||
|
||||
languageIdDescriptor,
|
||||
manufacturerDescriptor,
|
||||
productDescriptor,
|
||||
serialNumberDescriptor
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// List of the standard descriptors used by the Mass Storage driver.
|
||||
const USBDDriverDescriptors msdDriverDescriptors = {
|
||||
|
||||
&deviceDescriptor,
|
||||
(USBConfigurationDescriptor *) &configurationDescriptorsFS,
|
||||
#if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS)
|
||||
&qualifierDescriptor,
|
||||
(USBConfigurationDescriptor *) &otherSpeedDescriptorsFS,
|
||||
&deviceDescriptor,
|
||||
(USBConfigurationDescriptor *) &configurationDescriptorsHS,
|
||||
&qualifierDescriptor,
|
||||
(USBConfigurationDescriptor *) &otherSpeedDescriptorsHS,
|
||||
#else
|
||||
0, // No full-speed device qualifier descriptor
|
||||
0, // No full-speed other speed configuration
|
||||
0, // No high-speed device descriptor
|
||||
0, // No high-speed configuration descriptor
|
||||
0, // No high-speed device qualifier descriptor
|
||||
0, // No high-speed other speed configuration descriptor
|
||||
#endif
|
||||
stringDescriptors,
|
||||
4 // Four string descriptors in array
|
||||
};
|
||||
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definitions of the descriptors required by a Mass Storage device driver.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// - For a USB %device:
|
||||
/// -# When initializing a USBDDriver instance, use msdDriverDescriptors as
|
||||
/// the list of standard descriptors.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDDRIVERDESCRIPTORS_H
|
||||
#define MSDDRIVERDESCRIPTORS_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/core/USBDDriverDescriptors.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD endpoint addresses"
|
||||
/// This page lists the addresses used by the Mass Storage driver %endpoints.
|
||||
///
|
||||
/// !Addresses
|
||||
///
|
||||
/// - MSDDriverDescriptors_BULKOUT
|
||||
/// - MSDDriverDescriptors_BULKIN
|
||||
|
||||
/// Address of the Mass Storage bulk-out endpoint.
|
||||
#define MSDDriverDescriptors_BULKOUT 1
|
||||
|
||||
/// Address of the Mass Storage bulk-in endpoint.
|
||||
#if defined(at91sam9m10)
|
||||
#define MSDDriverDescriptors_BULKIN 6
|
||||
#else
|
||||
#define MSDDriverDescriptors_BULKIN 2
|
||||
#endif
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern const USBDDriverDescriptors msdDriverDescriptors;
|
||||
|
||||
#endif //#ifndef MSDDRIVERDESCRIPTORS_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definitions of the descriptors required by a Mass Storage device driver.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// - For a USB %device:
|
||||
/// -# When initializing a USBDDriver instance, use msdDriverDescriptors as
|
||||
/// the list of standard descriptors.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDDRIVERDESCRIPTORS_H
|
||||
#define MSDDRIVERDESCRIPTORS_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/core/USBDDriverDescriptors.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD endpoint addresses"
|
||||
/// This page lists the addresses used by the Mass Storage driver %endpoints.
|
||||
///
|
||||
/// !Addresses
|
||||
///
|
||||
/// - MSDDriverDescriptors_BULKOUT
|
||||
/// - MSDDriverDescriptors_BULKIN
|
||||
|
||||
/// Address of the Mass Storage bulk-out endpoint.
|
||||
#define MSDDriverDescriptors_BULKOUT 1
|
||||
|
||||
/// Address of the Mass Storage bulk-in endpoint.
|
||||
#if defined(at91sam9m10)
|
||||
#define MSDDriverDescriptors_BULKIN 6
|
||||
#else
|
||||
#define MSDDriverDescriptors_BULKIN 2
|
||||
#endif
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern const USBDDriverDescriptors msdDriverDescriptors;
|
||||
|
||||
#endif //#ifndef MSDDRIVERDESCRIPTORS_H
|
||||
|
||||
|
||||
@@ -1,135 +1,135 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef _MSDIOFIFO_H
|
||||
#define _MSDIOFIFO_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Idle state, do nothing
|
||||
#define MSDIO_IDLE 0
|
||||
/// Start, to start IO operation
|
||||
#define MSDIO_START 1
|
||||
/// Wait, waiting for IO operation done
|
||||
#define MSDIO_WAIT 2
|
||||
/// Next, to check if the next block can be performed
|
||||
#define MSDIO_NEXT 3
|
||||
/// Pause, to pause the process for buffer full or null
|
||||
#define MSDIO_PAUSE 4
|
||||
/// Abort, to abort the process
|
||||
#define MSDIO_ABORT 5
|
||||
/// Done, finish without error
|
||||
#define MSDIO_DONE 6
|
||||
/// Error, any error happens
|
||||
#define MSDIO_ERROR 7
|
||||
|
||||
/// FIFO offset before USB transmit start
|
||||
//#define MSDIO_FIFO_OFFSET (4*512)
|
||||
|
||||
/// FIFO trunk size (in each transfer, large amount of data)
|
||||
#if !defined(MSD_OP_BUFFER)
|
||||
#define MSDIO_READ10_CHUNK_SIZE (4*512)
|
||||
#define MSDIO_WRITE10_CHUNK_SIZE (4*512)
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// FIFO buffer for READ/WRITE (disk) operation of a mass storage device
|
||||
typedef struct _MSDIOFifo {
|
||||
|
||||
/// Pointer to the ring buffer allocated for read/write
|
||||
unsigned char * pBuffer;
|
||||
/// The size of the buffer allocated
|
||||
unsigned int bufferSize;
|
||||
#ifdef MSDIO_FIFO_OFFSET
|
||||
/// The offset to start USB transfer (READ10)
|
||||
unsigned int bufferOffset;
|
||||
#endif
|
||||
/// The index of input data (loaded to fifo buffer)
|
||||
unsigned int inputNdx;
|
||||
/// The total size of the loaded data
|
||||
unsigned int inputTotal;
|
||||
/// The index of output data (sent from the fifo buffer)
|
||||
unsigned int outputNdx;
|
||||
/// The total size of the output data
|
||||
unsigned int outputTotal;
|
||||
|
||||
/// The total size of the data
|
||||
unsigned int dataTotal;
|
||||
/// The size of the block in bytes
|
||||
unsigned short blockSize;
|
||||
#if defined(MSDIO_READ10_CHUNK_SIZE) || defined(MSDIO_WRITE10_CHUNK_SIZE)
|
||||
/// The size of one chunk
|
||||
/// (1 block, or several blocks for large amount data R/W)
|
||||
unsigned int chunkSize;
|
||||
#endif
|
||||
/// State of input & output
|
||||
unsigned char inputState;
|
||||
unsigned char outputState;
|
||||
|
||||
//- Statistics
|
||||
/// Times when fifo has no data to send
|
||||
unsigned short nullCnt;
|
||||
/// Times when fifo can not load more input data
|
||||
unsigned short fullCnt;
|
||||
} MSDIOFifo, *PMSDIOFifo;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// MACROS
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Increase the index, by defined block size, in the ring buffer
|
||||
/// \param ndx The index to be increased
|
||||
/// \param sectSize The defined block size
|
||||
/// \param bufSize The ring buffer size
|
||||
//------------------------------------------------------------------------------
|
||||
#define MSDIOFifo_IncNdx(ndx, sectSize, bufSize) \
|
||||
if ((ndx) >= (bufSize) - (sectSize)) (ndx) = 0; \
|
||||
else (ndx) += (sectSize)
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
extern void MSDIOFifo_Init(MSDIOFifo *pFifo,
|
||||
void * pBuffer, unsigned short bufferSize);
|
||||
|
||||
#endif // _MSDIOFIFO_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef _MSDIOFIFO_H
|
||||
#define _MSDIOFIFO_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Idle state, do nothing
|
||||
#define MSDIO_IDLE 0
|
||||
/// Start, to start IO operation
|
||||
#define MSDIO_START 1
|
||||
/// Wait, waiting for IO operation done
|
||||
#define MSDIO_WAIT 2
|
||||
/// Next, to check if the next block can be performed
|
||||
#define MSDIO_NEXT 3
|
||||
/// Pause, to pause the process for buffer full or null
|
||||
#define MSDIO_PAUSE 4
|
||||
/// Abort, to abort the process
|
||||
#define MSDIO_ABORT 5
|
||||
/// Done, finish without error
|
||||
#define MSDIO_DONE 6
|
||||
/// Error, any error happens
|
||||
#define MSDIO_ERROR 7
|
||||
|
||||
/// FIFO offset before USB transmit start
|
||||
//#define MSDIO_FIFO_OFFSET (4*512)
|
||||
|
||||
/// FIFO trunk size (in each transfer, large amount of data)
|
||||
#if !defined(MSD_OP_BUFFER)
|
||||
#define MSDIO_READ10_CHUNK_SIZE (4*512)
|
||||
#define MSDIO_WRITE10_CHUNK_SIZE (4*512)
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// FIFO buffer for READ/WRITE (disk) operation of a mass storage device
|
||||
typedef struct _MSDIOFifo {
|
||||
|
||||
/// Pointer to the ring buffer allocated for read/write
|
||||
unsigned char * pBuffer;
|
||||
/// The size of the buffer allocated
|
||||
unsigned int bufferSize;
|
||||
#ifdef MSDIO_FIFO_OFFSET
|
||||
/// The offset to start USB transfer (READ10)
|
||||
unsigned int bufferOffset;
|
||||
#endif
|
||||
/// The index of input data (loaded to fifo buffer)
|
||||
unsigned int inputNdx;
|
||||
/// The total size of the loaded data
|
||||
unsigned int inputTotal;
|
||||
/// The index of output data (sent from the fifo buffer)
|
||||
unsigned int outputNdx;
|
||||
/// The total size of the output data
|
||||
unsigned int outputTotal;
|
||||
|
||||
/// The total size of the data
|
||||
unsigned int dataTotal;
|
||||
/// The size of the block in bytes
|
||||
unsigned short blockSize;
|
||||
#if defined(MSDIO_READ10_CHUNK_SIZE) || defined(MSDIO_WRITE10_CHUNK_SIZE)
|
||||
/// The size of one chunk
|
||||
/// (1 block, or several blocks for large amount data R/W)
|
||||
unsigned int chunkSize;
|
||||
#endif
|
||||
/// State of input & output
|
||||
unsigned char inputState;
|
||||
unsigned char outputState;
|
||||
|
||||
//- Statistics
|
||||
/// Times when fifo has no data to send
|
||||
unsigned short nullCnt;
|
||||
/// Times when fifo can not load more input data
|
||||
unsigned short fullCnt;
|
||||
} MSDIOFifo, *PMSDIOFifo;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// MACROS
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Increase the index, by defined block size, in the ring buffer
|
||||
/// \param ndx The index to be increased
|
||||
/// \param sectSize The defined block size
|
||||
/// \param bufSize The ring buffer size
|
||||
//------------------------------------------------------------------------------
|
||||
#define MSDIOFifo_IncNdx(ndx, sectSize, bufSize) \
|
||||
if ((ndx) >= (bufSize) - (sectSize)) (ndx) = 0; \
|
||||
else (ndx) += (sectSize)
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
extern void MSDIOFifo_Init(MSDIOFifo *pFifo,
|
||||
void * pBuffer, unsigned short bufferSize);
|
||||
|
||||
#endif // _MSDIOFIFO_H
|
||||
|
||||
|
||||
@@ -1,367 +1,367 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDLun.h"
|
||||
#include "board_lowlevel.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
#include "debug.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Constants
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Default LUN block size in bytes
|
||||
#define DEFAULT_LUN_BLOCK_SIZE BLOCK_SIZE
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Inquiry data to return to the host for the Lun.
|
||||
static SBCInquiryData inquiryData = {
|
||||
|
||||
SBC_DIRECT_ACCESS_BLOCK_DEVICE, // Direct-access block device
|
||||
SBC_PERIPHERAL_DEVICE_CONNECTED,// Peripheral device is connected
|
||||
0x00, // Reserved bits
|
||||
0x01, // Media is removable
|
||||
0x02, // SBC_SPC_VERSION_4, // SPC-4 supported
|
||||
0x2, // Response data format, must be 0x2
|
||||
0, // Hierarchical addressing not supported
|
||||
0, // ACA not supported
|
||||
0x0, // Obsolete bits
|
||||
sizeof(SBCInquiryData) - 5, // Additional length
|
||||
0, // No embedded SCC
|
||||
0, // No access control coordinator
|
||||
SBC_TPGS_NONE, // No target port support group
|
||||
0, // Third-party copy not supported
|
||||
0x0, // Reserved bits
|
||||
0, // Protection information not supported
|
||||
0x0, // Obsolete bit
|
||||
0, // No embedded enclosure service component
|
||||
0x0, // ???
|
||||
0, // Device is not multi-port
|
||||
0x0, // Obsolete bits
|
||||
0x0, // Unused feature
|
||||
0x0, // Unused features
|
||||
0, // Task management model not supported
|
||||
0x0, // ???
|
||||
{'A','T','M','E','L',' ',' ',' '},
|
||||
{'M','a','s','s',' ',
|
||||
'S','t','o','r','a','g','e',' ',
|
||||
'M','S','D'},
|
||||
{'0','.','0','1'},
|
||||
{'M','a','s','s',' ',
|
||||
'S','t','o','r','a','g','e',' ',
|
||||
'E','x','a','m','p','l','e'},
|
||||
0x00, // Unused features
|
||||
0x00, // Reserved bits
|
||||
{SBC_VERSION_DESCRIPTOR_SBC_3}, // SBC-3 compliant device
|
||||
{0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0} // Reserved
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Initializes a LUN instance. Must be invoked at least once even no
|
||||
//! Media is linked.
|
||||
//! \param lun Pointer to the MSDLun instance to initialize
|
||||
//! \param media Media on which the LUN is constructed, set to 0 to
|
||||
//! disconnect the Media or initialize an ejected LUN.
|
||||
//! \param ioBuffer Pointer to a buffer used for read/write operation and
|
||||
//! which must be blockSize bytes long.
|
||||
//! \param ioBufferSize Size of the allocated IO buffer.
|
||||
//! \param baseAddress Base address of the LUN in number of media blocks
|
||||
//! \param size Total size of the LUN in number of media blocks
|
||||
//! \param blockSize One block of the LUN in number of media blocks
|
||||
//! \param protected The LUN area is forced to readonly even the media
|
||||
//! is writable
|
||||
//! \param dataMonitor Pointer to a Monitor Function to analyze the flow of
|
||||
//! this LUN.
|
||||
//------------------------------------------------------------------------------
|
||||
void LUN_Init(MSDLun *lun,
|
||||
Media *media,
|
||||
unsigned char *ioBuffer,
|
||||
unsigned int ioBufferSize,
|
||||
unsigned int baseAddress,
|
||||
unsigned int size,
|
||||
unsigned short blockSize,
|
||||
unsigned char protected,
|
||||
void (*dataMonitor)(unsigned char flowDirection,
|
||||
unsigned int dataLength,
|
||||
unsigned int fifoNullCount,
|
||||
unsigned int fifoFullCount))
|
||||
{
|
||||
unsigned int logicalBlockAddress;
|
||||
TRACE_INFO("LUN init\n\r");
|
||||
|
||||
// Initialize inquiry data
|
||||
lun->inquiryData = &inquiryData;
|
||||
|
||||
// Initialize request sense data
|
||||
lun->requestSenseData.bResponseCode = SBC_SENSE_DATA_FIXED_CURRENT;
|
||||
lun->requestSenseData.isValid = 1;
|
||||
lun->requestSenseData.bObsolete1 = 0;
|
||||
lun->requestSenseData.bSenseKey = SBC_SENSE_KEY_NO_SENSE;
|
||||
lun->requestSenseData.bReserved1 = 0;
|
||||
lun->requestSenseData.isILI = 0;
|
||||
lun->requestSenseData.isEOM = 0;
|
||||
lun->requestSenseData.isFilemark = 0;
|
||||
lun->requestSenseData.pInformation[0] = 0;
|
||||
lun->requestSenseData.pInformation[1] = 0;
|
||||
lun->requestSenseData.pInformation[2] = 0;
|
||||
lun->requestSenseData.pInformation[3] = 0;
|
||||
lun->requestSenseData.bAdditionalSenseLength
|
||||
= sizeof(SBCRequestSenseData) - 8;
|
||||
lun->requestSenseData.bAdditionalSenseCode = 0;
|
||||
lun->requestSenseData.bAdditionalSenseCodeQualifier = 0;
|
||||
lun->requestSenseData.bFieldReplaceableUnitCode = 0;
|
||||
lun->requestSenseData.bSenseKeySpecific = 0;
|
||||
lun->requestSenseData.pSenseKeySpecific[0] = 0;
|
||||
lun->requestSenseData.pSenseKeySpecific[0] = 0;
|
||||
lun->requestSenseData.isSKSV = 0;
|
||||
|
||||
STORE_DWORDB(0, lun->readCapacityData.pLogicalBlockAddress);
|
||||
STORE_DWORDB(0, lun->readCapacityData.pLogicalBlockLength);
|
||||
|
||||
// Initialize LUN
|
||||
lun->media = media;
|
||||
if (media == 0) {
|
||||
lun->status = LUN_NOT_PRESENT;
|
||||
return;
|
||||
}
|
||||
|
||||
lun->baseAddress = baseAddress;
|
||||
|
||||
// Customized block size
|
||||
if (blockSize) {
|
||||
lun->blockSize = blockSize;
|
||||
}
|
||||
else {
|
||||
if (media->blockSize < DEFAULT_LUN_BLOCK_SIZE)
|
||||
lun->blockSize = DEFAULT_LUN_BLOCK_SIZE / media->blockSize;
|
||||
else
|
||||
lun->blockSize = 1;
|
||||
}
|
||||
|
||||
if (size) {
|
||||
lun->size = size;
|
||||
}
|
||||
else {
|
||||
lun->size = media->size;
|
||||
//if (blockSize)
|
||||
// lun->size = media->size / blockSize;
|
||||
//else {
|
||||
// if (media->blockSize < DEFAULT_LUN_BLOCK_SIZE)
|
||||
// lun->size = media->size / lun->blockSize;
|
||||
// else
|
||||
// lun->size = media->size;
|
||||
//}
|
||||
}
|
||||
|
||||
TRACE_INFO("LUN: blkSize %d, size %d\n\r", (int)lun->blockSize, (int)lun->size);
|
||||
if (protected) lun->protected = 1;
|
||||
else lun->protected = media->protected;
|
||||
|
||||
lun->ioFifo.pBuffer = ioBuffer;
|
||||
lun->ioFifo.bufferSize = ioBufferSize;
|
||||
|
||||
lun->dataMonitor = dataMonitor;
|
||||
|
||||
// Initialize read capacity data
|
||||
logicalBlockAddress = lun->size / lun->blockSize - 1;
|
||||
STORE_DWORDB(logicalBlockAddress,
|
||||
lun->readCapacityData.pLogicalBlockAddress);
|
||||
STORE_DWORDB(lun->blockSize * media->blockSize,
|
||||
lun->readCapacityData.pLogicalBlockLength);
|
||||
|
||||
// Indicate media change
|
||||
lun->status = LUN_CHANGED;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Eject the media from a LUN
|
||||
//! \param lun Pointer to the MSDLun instance to initialize
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LUN_Eject(MSDLun *lun)
|
||||
{
|
||||
if (lun->media) {
|
||||
|
||||
// Avoid any LUN R/W in progress
|
||||
if (lun->media->state == MED_STATE_BUSY) {
|
||||
|
||||
return USBD_STATUS_LOCKED;
|
||||
}
|
||||
|
||||
// Remove the link of the media
|
||||
lun->media = 0;
|
||||
}
|
||||
// LUN is removed
|
||||
lun->status = LUN_NOT_PRESENT;
|
||||
|
||||
return USBD_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Writes data on the a LUN starting at the specified block address.
|
||||
//! \param lun Pointer to a MSDLun instance
|
||||
//! \param blockAddress First block address to write
|
||||
//! \param data Pointer to the data to write
|
||||
//! \param length Number of blocks to write
|
||||
//! \param callback Optional callback to invoke when the write finishes
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LUN_Write(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
unsigned int medBlk, medLen;
|
||||
unsigned char status;
|
||||
|
||||
TRACE_INFO_WP("LUNWrite(%u) ", blockAddress);
|
||||
|
||||
// Check that the data is not too big
|
||||
if ((length + blockAddress) * lun->blockSize > lun->size) {
|
||||
|
||||
TRACE_WARNING("LUN_Write: Data too big\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else if (lun->media == 0 || lun->status != LUN_READY) {
|
||||
|
||||
TRACE_WARNING("LUN_Write: Media not ready\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else if (lun->protected) {
|
||||
TRACE_WARNING("LUN_Write: LUN is readonly\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else {
|
||||
|
||||
// Compute write start address
|
||||
medBlk = lun->baseAddress + blockAddress * lun->blockSize;
|
||||
medLen = length * lun->blockSize;
|
||||
|
||||
// Start write operation
|
||||
status = MED_Write(lun->media,
|
||||
medBlk,
|
||||
data,
|
||||
medLen,
|
||||
(MediaCallback) callback,
|
||||
argument);
|
||||
|
||||
// Check operation result code
|
||||
if (status == MED_STATUS_SUCCESS) {
|
||||
|
||||
status = USBD_STATUS_SUCCESS;
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING("LUN_Write: Cannot write media\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Reads data from a LUN, starting at the specified block address.
|
||||
//! \param lun Pointer to a MSDLun instance
|
||||
//! \param blockAddress First block address to read
|
||||
//! \param data Pointer to a data buffer in which to store the data
|
||||
//! \param length Number of blocks to read
|
||||
//! \param callback Optional callback to invoke when the read finishes
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LUN_Read(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
unsigned int medBlk, medLen;
|
||||
unsigned char status;
|
||||
|
||||
// Check that the data is not too big
|
||||
if ((length + blockAddress) * lun->blockSize > lun->size) {
|
||||
|
||||
TRACE_WARNING("LUN_Read: Area: (%d + %d)*%d > %d\n\r",
|
||||
(int)length, (int)blockAddress, (int)lun->blockSize, (int)lun->size);
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else if (lun->media == 0 || lun->status != LUN_READY) {
|
||||
|
||||
TRACE_WARNING("LUN_Read: Media not present\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_INFO_WP("LUNRead(%u) ", blockAddress);
|
||||
|
||||
// Compute read start address
|
||||
medBlk = lun->baseAddress + (blockAddress * lun->blockSize);
|
||||
medLen = length * lun->blockSize;
|
||||
|
||||
// Start write operation
|
||||
status = MED_Read(lun->media,
|
||||
medBlk,
|
||||
data,
|
||||
medLen,
|
||||
(MediaCallback) callback,
|
||||
argument);
|
||||
|
||||
// Check result code
|
||||
if (status == MED_STATUS_SUCCESS) {
|
||||
|
||||
status = USBD_STATUS_SUCCESS;
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING("LUN_Read: Cannot read media\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDLun.h"
|
||||
#include "board_lowlevel.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
#include "debug.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Constants
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Default LUN block size in bytes
|
||||
#define DEFAULT_LUN_BLOCK_SIZE BLOCK_SIZE
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Inquiry data to return to the host for the Lun.
|
||||
static SBCInquiryData inquiryData = {
|
||||
|
||||
SBC_DIRECT_ACCESS_BLOCK_DEVICE, // Direct-access block device
|
||||
SBC_PERIPHERAL_DEVICE_CONNECTED,// Peripheral device is connected
|
||||
0x00, // Reserved bits
|
||||
0x01, // Media is removable
|
||||
0x02, // SBC_SPC_VERSION_4, // SPC-4 supported
|
||||
0x2, // Response data format, must be 0x2
|
||||
0, // Hierarchical addressing not supported
|
||||
0, // ACA not supported
|
||||
0x0, // Obsolete bits
|
||||
sizeof(SBCInquiryData) - 5, // Additional length
|
||||
0, // No embedded SCC
|
||||
0, // No access control coordinator
|
||||
SBC_TPGS_NONE, // No target port support group
|
||||
0, // Third-party copy not supported
|
||||
0x0, // Reserved bits
|
||||
0, // Protection information not supported
|
||||
0x0, // Obsolete bit
|
||||
0, // No embedded enclosure service component
|
||||
0x0, // ???
|
||||
0, // Device is not multi-port
|
||||
0x0, // Obsolete bits
|
||||
0x0, // Unused feature
|
||||
0x0, // Unused features
|
||||
0, // Task management model not supported
|
||||
0x0, // ???
|
||||
{'A','T','M','E','L',' ',' ',' '},
|
||||
{'M','a','s','s',' ',
|
||||
'S','t','o','r','a','g','e',' ',
|
||||
'M','S','D'},
|
||||
{'0','.','0','1'},
|
||||
{'M','a','s','s',' ',
|
||||
'S','t','o','r','a','g','e',' ',
|
||||
'E','x','a','m','p','l','e'},
|
||||
0x00, // Unused features
|
||||
0x00, // Reserved bits
|
||||
{SBC_VERSION_DESCRIPTOR_SBC_3}, // SBC-3 compliant device
|
||||
{0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0} // Reserved
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Initializes a LUN instance. Must be invoked at least once even no
|
||||
//! Media is linked.
|
||||
//! \param lun Pointer to the MSDLun instance to initialize
|
||||
//! \param media Media on which the LUN is constructed, set to 0 to
|
||||
//! disconnect the Media or initialize an ejected LUN.
|
||||
//! \param ioBuffer Pointer to a buffer used for read/write operation and
|
||||
//! which must be blockSize bytes long.
|
||||
//! \param ioBufferSize Size of the allocated IO buffer.
|
||||
//! \param baseAddress Base address of the LUN in number of media blocks
|
||||
//! \param size Total size of the LUN in number of media blocks
|
||||
//! \param blockSize One block of the LUN in number of media blocks
|
||||
//! \param protected The LUN area is forced to readonly even the media
|
||||
//! is writable
|
||||
//! \param dataMonitor Pointer to a Monitor Function to analyze the flow of
|
||||
//! this LUN.
|
||||
//------------------------------------------------------------------------------
|
||||
void LUN_Init(MSDLun *lun,
|
||||
Media *media,
|
||||
unsigned char *ioBuffer,
|
||||
unsigned int ioBufferSize,
|
||||
unsigned int baseAddress,
|
||||
unsigned int size,
|
||||
unsigned short blockSize,
|
||||
unsigned char protected,
|
||||
void (*dataMonitor)(unsigned char flowDirection,
|
||||
unsigned int dataLength,
|
||||
unsigned int fifoNullCount,
|
||||
unsigned int fifoFullCount))
|
||||
{
|
||||
unsigned int logicalBlockAddress;
|
||||
TRACE_INFO("LUN init\n\r");
|
||||
|
||||
// Initialize inquiry data
|
||||
lun->inquiryData = &inquiryData;
|
||||
|
||||
// Initialize request sense data
|
||||
lun->requestSenseData.bResponseCode = SBC_SENSE_DATA_FIXED_CURRENT;
|
||||
lun->requestSenseData.isValid = 1;
|
||||
lun->requestSenseData.bObsolete1 = 0;
|
||||
lun->requestSenseData.bSenseKey = SBC_SENSE_KEY_NO_SENSE;
|
||||
lun->requestSenseData.bReserved1 = 0;
|
||||
lun->requestSenseData.isILI = 0;
|
||||
lun->requestSenseData.isEOM = 0;
|
||||
lun->requestSenseData.isFilemark = 0;
|
||||
lun->requestSenseData.pInformation[0] = 0;
|
||||
lun->requestSenseData.pInformation[1] = 0;
|
||||
lun->requestSenseData.pInformation[2] = 0;
|
||||
lun->requestSenseData.pInformation[3] = 0;
|
||||
lun->requestSenseData.bAdditionalSenseLength
|
||||
= sizeof(SBCRequestSenseData) - 8;
|
||||
lun->requestSenseData.bAdditionalSenseCode = 0;
|
||||
lun->requestSenseData.bAdditionalSenseCodeQualifier = 0;
|
||||
lun->requestSenseData.bFieldReplaceableUnitCode = 0;
|
||||
lun->requestSenseData.bSenseKeySpecific = 0;
|
||||
lun->requestSenseData.pSenseKeySpecific[0] = 0;
|
||||
lun->requestSenseData.pSenseKeySpecific[0] = 0;
|
||||
lun->requestSenseData.isSKSV = 0;
|
||||
|
||||
STORE_DWORDB(0, lun->readCapacityData.pLogicalBlockAddress);
|
||||
STORE_DWORDB(0, lun->readCapacityData.pLogicalBlockLength);
|
||||
|
||||
// Initialize LUN
|
||||
lun->media = media;
|
||||
if (media == 0) {
|
||||
lun->status = LUN_NOT_PRESENT;
|
||||
return;
|
||||
}
|
||||
|
||||
lun->baseAddress = baseAddress;
|
||||
|
||||
// Customized block size
|
||||
if (blockSize) {
|
||||
lun->blockSize = blockSize;
|
||||
}
|
||||
else {
|
||||
if (media->blockSize < DEFAULT_LUN_BLOCK_SIZE)
|
||||
lun->blockSize = DEFAULT_LUN_BLOCK_SIZE / media->blockSize;
|
||||
else
|
||||
lun->blockSize = 1;
|
||||
}
|
||||
|
||||
if (size) {
|
||||
lun->size = size;
|
||||
}
|
||||
else {
|
||||
lun->size = media->size;
|
||||
//if (blockSize)
|
||||
// lun->size = media->size / blockSize;
|
||||
//else {
|
||||
// if (media->blockSize < DEFAULT_LUN_BLOCK_SIZE)
|
||||
// lun->size = media->size / lun->blockSize;
|
||||
// else
|
||||
// lun->size = media->size;
|
||||
//}
|
||||
}
|
||||
|
||||
TRACE_INFO("LUN: blkSize %d, size %d\n\r", (int)lun->blockSize, (int)lun->size);
|
||||
if (protected) lun->protected = 1;
|
||||
else lun->protected = media->protected;
|
||||
|
||||
lun->ioFifo.pBuffer = ioBuffer;
|
||||
lun->ioFifo.bufferSize = ioBufferSize;
|
||||
|
||||
lun->dataMonitor = dataMonitor;
|
||||
|
||||
// Initialize read capacity data
|
||||
logicalBlockAddress = lun->size / lun->blockSize - 1;
|
||||
STORE_DWORDB(logicalBlockAddress,
|
||||
lun->readCapacityData.pLogicalBlockAddress);
|
||||
STORE_DWORDB(lun->blockSize * media->blockSize,
|
||||
lun->readCapacityData.pLogicalBlockLength);
|
||||
|
||||
// Indicate media change
|
||||
lun->status = LUN_CHANGED;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Eject the media from a LUN
|
||||
//! \param lun Pointer to the MSDLun instance to initialize
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LUN_Eject(MSDLun *lun)
|
||||
{
|
||||
if (lun->media) {
|
||||
|
||||
// Avoid any LUN R/W in progress
|
||||
if (lun->media->state == MED_STATE_BUSY) {
|
||||
|
||||
return USBD_STATUS_LOCKED;
|
||||
}
|
||||
|
||||
// Remove the link of the media
|
||||
lun->media = 0;
|
||||
}
|
||||
// LUN is removed
|
||||
lun->status = LUN_NOT_PRESENT;
|
||||
|
||||
return USBD_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Writes data on the a LUN starting at the specified block address.
|
||||
//! \param lun Pointer to a MSDLun instance
|
||||
//! \param blockAddress First block address to write
|
||||
//! \param data Pointer to the data to write
|
||||
//! \param length Number of blocks to write
|
||||
//! \param callback Optional callback to invoke when the write finishes
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LUN_Write(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
unsigned int medBlk, medLen;
|
||||
unsigned char status;
|
||||
|
||||
TRACE_INFO_WP("LUNWrite(%u) ", blockAddress);
|
||||
|
||||
// Check that the data is not too big
|
||||
if ((length + blockAddress) * lun->blockSize > lun->size) {
|
||||
|
||||
TRACE_WARNING("LUN_Write: Data too big\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else if (lun->media == 0 || lun->status != LUN_READY) {
|
||||
|
||||
TRACE_WARNING("LUN_Write: Media not ready\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else if (lun->protected) {
|
||||
TRACE_WARNING("LUN_Write: LUN is readonly\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else {
|
||||
|
||||
// Compute write start address
|
||||
medBlk = lun->baseAddress + blockAddress * lun->blockSize;
|
||||
medLen = length * lun->blockSize;
|
||||
|
||||
// Start write operation
|
||||
status = MED_Write(lun->media,
|
||||
medBlk,
|
||||
data,
|
||||
medLen,
|
||||
(MediaCallback) callback,
|
||||
argument);
|
||||
|
||||
// Check operation result code
|
||||
if (status == MED_STATUS_SUCCESS) {
|
||||
|
||||
status = USBD_STATUS_SUCCESS;
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING("LUN_Write: Cannot write media\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Reads data from a LUN, starting at the specified block address.
|
||||
//! \param lun Pointer to a MSDLun instance
|
||||
//! \param blockAddress First block address to read
|
||||
//! \param data Pointer to a data buffer in which to store the data
|
||||
//! \param length Number of blocks to read
|
||||
//! \param callback Optional callback to invoke when the read finishes
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LUN_Read(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
unsigned int medBlk, medLen;
|
||||
unsigned char status;
|
||||
|
||||
// Check that the data is not too big
|
||||
if ((length + blockAddress) * lun->blockSize > lun->size) {
|
||||
|
||||
TRACE_WARNING("LUN_Read: Area: (%d + %d)*%d > %d\n\r",
|
||||
(int)length, (int)blockAddress, (int)lun->blockSize, (int)lun->size);
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else if (lun->media == 0 || lun->status != LUN_READY) {
|
||||
|
||||
TRACE_WARNING("LUN_Read: Media not present\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_INFO_WP("LUNRead(%u) ", blockAddress);
|
||||
|
||||
// Compute read start address
|
||||
medBlk = lun->baseAddress + (blockAddress * lun->blockSize);
|
||||
medLen = length * lun->blockSize;
|
||||
|
||||
// Start write operation
|
||||
status = MED_Read(lun->media,
|
||||
medBlk,
|
||||
data,
|
||||
medLen,
|
||||
(MediaCallback) callback,
|
||||
argument);
|
||||
|
||||
// Check result code
|
||||
if (status == MED_STATUS_SUCCESS) {
|
||||
|
||||
status = USBD_STATUS_SUCCESS;
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING("LUN_Read: Cannot read media\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -1,161 +1,161 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Logical Unit Number (LUN) used by the Mass Storage driver and the SCSI
|
||||
/// protocol. Represents a logical hard-drive.
|
||||
///
|
||||
/// !Usage
|
||||
/// -# Initialize Memory related pins (see pio & board.h).
|
||||
/// -# Initialize a Media instance for the LUN (see memories).
|
||||
/// -# Initlalize the LUN with LUN_Init, and link to the initialized Media.
|
||||
/// -# To read data from the LUN linked media, uses LUN_Read.
|
||||
/// -# To write data to the LUN linked media, uses LUN_Write.
|
||||
/// -# To unlink the media, uses LUN_Eject.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDLUN_H
|
||||
#define MSDLUN_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../Media.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
#include "../../../usb/device/massstorage/MSDIOFifo.h"
|
||||
#include "../../../usb/device/massstorage/SBC.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// LUN RC: success
|
||||
#define LUN_STATUS_SUCCESS 0x00
|
||||
/// LUN RC: error
|
||||
#define LUN_STATUS_ERROR 0x02
|
||||
|
||||
/// Media of LUN is removed
|
||||
#define LUN_NOT_PRESENT 0x00
|
||||
/// LUN is ejected by host
|
||||
#define LUN_EJECTED 0x01
|
||||
/// Media of LUN is changed
|
||||
#define LUN_CHANGED 0x10
|
||||
/// LUN Not Ready to Ready transition
|
||||
#define LUN_TRANS_READY LUN_CHANGED
|
||||
/// Media of LUN is ready
|
||||
#define LUN_READY 0x11
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Structures
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// LUN structure
|
||||
typedef struct {
|
||||
|
||||
/// Pointer to a SBCInquiryData instance.
|
||||
SBCInquiryData *inquiryData;
|
||||
/// Fifo for USB transfer, must be assigned.
|
||||
MSDIOFifo ioFifo;
|
||||
/// Pointer to Media instance for the LUN.
|
||||
Media *media;
|
||||
/// Pointer to a Monitor Function to analyze the flow of LUN.
|
||||
/// \param flowDirection 1 - device to host (READ10)
|
||||
/// 0 - host to device (WRITE10)
|
||||
/// \param dataLength Length of data transferred in bytes.
|
||||
/// \param fifoNullCount Times that FIFO is NULL to wait
|
||||
/// \param fifoFullCount Times that FIFO is filled to wait
|
||||
void (*dataMonitor)(unsigned char flowDirection,
|
||||
unsigned int dataLength,
|
||||
unsigned int fifoNullCount,
|
||||
unsigned int fifoFullCount);
|
||||
/// The start position of the media (blocks) allocated to the LUN.
|
||||
unsigned int baseAddress;
|
||||
/// The size of the media (blocks) allocated to the LUN.
|
||||
unsigned int size;
|
||||
/// Sector size of the media in number of media blocks
|
||||
unsigned short blockSize;
|
||||
/// The LUN can be readonly even the media is writable
|
||||
#ifdef __cplusplus
|
||||
unsigned char protectd;
|
||||
#else
|
||||
unsigned char protected;
|
||||
#endif
|
||||
|
||||
/// The LUN status (Ejected/Changed/)
|
||||
unsigned char status;
|
||||
|
||||
/// Data for the RequestSense command.
|
||||
SBCRequestSenseData requestSenseData;
|
||||
/// Data for the ReadCapacity command.
|
||||
SBCReadCapacity10Data readCapacityData;
|
||||
|
||||
} MSDLun;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
extern void LUN_Init(MSDLun *lun,
|
||||
Media *media,
|
||||
unsigned char *ioBuffer,
|
||||
unsigned int ioBufferSize,
|
||||
unsigned int baseAddress,
|
||||
unsigned int size,
|
||||
unsigned short blockSize,
|
||||
#ifdef __cplusplus
|
||||
unsigned char protectd,
|
||||
#else
|
||||
unsigned char protected,
|
||||
#endif
|
||||
void (*dataMonitor)(unsigned char flowDirection,
|
||||
unsigned int dataLength,
|
||||
unsigned int fifoNullCount,
|
||||
unsigned int fifoFullCount));
|
||||
|
||||
extern unsigned char LUN_Eject(MSDLun *lun);
|
||||
|
||||
extern unsigned char LUN_Write(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument);
|
||||
|
||||
extern unsigned char LUN_Read(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument);
|
||||
|
||||
#endif //#ifndef MSDLUN_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Logical Unit Number (LUN) used by the Mass Storage driver and the SCSI
|
||||
/// protocol. Represents a logical hard-drive.
|
||||
///
|
||||
/// !Usage
|
||||
/// -# Initialize Memory related pins (see pio & board.h).
|
||||
/// -# Initialize a Media instance for the LUN (see memories).
|
||||
/// -# Initlalize the LUN with LUN_Init, and link to the initialized Media.
|
||||
/// -# To read data from the LUN linked media, uses LUN_Read.
|
||||
/// -# To write data to the LUN linked media, uses LUN_Write.
|
||||
/// -# To unlink the media, uses LUN_Eject.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDLUN_H
|
||||
#define MSDLUN_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../Media.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
#include "../../../usb/device/massstorage/MSDIOFifo.h"
|
||||
#include "../../../usb/device/massstorage/SBC.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// LUN RC: success
|
||||
#define LUN_STATUS_SUCCESS 0x00
|
||||
/// LUN RC: error
|
||||
#define LUN_STATUS_ERROR 0x02
|
||||
|
||||
/// Media of LUN is removed
|
||||
#define LUN_NOT_PRESENT 0x00
|
||||
/// LUN is ejected by host
|
||||
#define LUN_EJECTED 0x01
|
||||
/// Media of LUN is changed
|
||||
#define LUN_CHANGED 0x10
|
||||
/// LUN Not Ready to Ready transition
|
||||
#define LUN_TRANS_READY LUN_CHANGED
|
||||
/// Media of LUN is ready
|
||||
#define LUN_READY 0x11
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Structures
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// LUN structure
|
||||
typedef struct {
|
||||
|
||||
/// Pointer to a SBCInquiryData instance.
|
||||
SBCInquiryData *inquiryData;
|
||||
/// Fifo for USB transfer, must be assigned.
|
||||
MSDIOFifo ioFifo;
|
||||
/// Pointer to Media instance for the LUN.
|
||||
Media *media;
|
||||
/// Pointer to a Monitor Function to analyze the flow of LUN.
|
||||
/// \param flowDirection 1 - device to host (READ10)
|
||||
/// 0 - host to device (WRITE10)
|
||||
/// \param dataLength Length of data transferred in bytes.
|
||||
/// \param fifoNullCount Times that FIFO is NULL to wait
|
||||
/// \param fifoFullCount Times that FIFO is filled to wait
|
||||
void (*dataMonitor)(unsigned char flowDirection,
|
||||
unsigned int dataLength,
|
||||
unsigned int fifoNullCount,
|
||||
unsigned int fifoFullCount);
|
||||
/// The start position of the media (blocks) allocated to the LUN.
|
||||
unsigned int baseAddress;
|
||||
/// The size of the media (blocks) allocated to the LUN.
|
||||
unsigned int size;
|
||||
/// Sector size of the media in number of media blocks
|
||||
unsigned short blockSize;
|
||||
/// The LUN can be readonly even the media is writable
|
||||
#ifdef __cplusplus
|
||||
unsigned char protectd;
|
||||
#else
|
||||
unsigned char protected;
|
||||
#endif
|
||||
|
||||
/// The LUN status (Ejected/Changed/)
|
||||
unsigned char status;
|
||||
|
||||
/// Data for the RequestSense command.
|
||||
SBCRequestSenseData requestSenseData;
|
||||
/// Data for the ReadCapacity command.
|
||||
SBCReadCapacity10Data readCapacityData;
|
||||
|
||||
} MSDLun;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
extern void LUN_Init(MSDLun *lun,
|
||||
Media *media,
|
||||
unsigned char *ioBuffer,
|
||||
unsigned int ioBufferSize,
|
||||
unsigned int baseAddress,
|
||||
unsigned int size,
|
||||
unsigned short blockSize,
|
||||
#ifdef __cplusplus
|
||||
unsigned char protectd,
|
||||
#else
|
||||
unsigned char protected,
|
||||
#endif
|
||||
void (*dataMonitor)(unsigned char flowDirection,
|
||||
unsigned int dataLength,
|
||||
unsigned int fifoNullCount,
|
||||
unsigned int fifoFullCount));
|
||||
|
||||
extern unsigned char LUN_Eject(MSDLun *lun);
|
||||
|
||||
extern unsigned char LUN_Write(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument);
|
||||
|
||||
extern unsigned char LUN_Read(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument);
|
||||
|
||||
#endif //#ifndef MSDLUN_H
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,110 +1,110 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// SCSI commands implementation.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# After a CBW is received from host, use SBC_GetCommandInformation to check
|
||||
/// if the command is supported, and get the command length and type
|
||||
/// information before processing it.
|
||||
/// -# Then SBC_ProcessCommand can be used to handle a valid command, to
|
||||
/// perform the command operations.
|
||||
/// -# SBC_UpdateSenseData is used to update the sense data that will be sent
|
||||
/// to host.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef SBCMETHODS_H
|
||||
#define SBCMETHODS_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDDStateMachine.h"
|
||||
#include "../../../usb/device/massstorage/SBC.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "SBC Command States"
|
||||
/// This page lists the possible states of a SBC command.
|
||||
///
|
||||
/// !States
|
||||
/// - SBC_STATE_READ
|
||||
/// - SBC_STATE_WAIT_READ
|
||||
/// - SBC_STATE_WRITE
|
||||
/// - SBC_STATE_WAIT_WRITE
|
||||
/// - SBC_STATE_NEXT_BLOCK
|
||||
|
||||
/// Start of reading bulk data
|
||||
#define SBC_STATE_READ 0x01
|
||||
/// Waiting for the bulk data reading complete
|
||||
#define SBC_STATE_WAIT_READ 0x02
|
||||
/// Read error state
|
||||
#define SBC_STATE_READ_ERROR 0x03
|
||||
/// Start next read block
|
||||
#define SBC_STATE_NEXT_READ 0x04
|
||||
/// Start writing bulk data to host
|
||||
#define SBC_STATE_WRITE 0x05
|
||||
/// Waiting for the bulk data sending complete
|
||||
#define SBC_STATE_WAIT_WRITE 0x06
|
||||
/// Write error state
|
||||
#define SBC_STATE_WRITE_ERROR 0x07
|
||||
/// Start next write block
|
||||
#define SBC_STATE_NEXT_WRITE 0x08
|
||||
/// Start next command block
|
||||
#define SBC_STATE_NEXT_BLOCK 0x09
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void SBC_UpdateSenseData(SBCRequestSenseData *requestSenseData,
|
||||
unsigned char senseKey,
|
||||
unsigned char additionalSenseCode,
|
||||
unsigned char additionalSenseCodeQualifier);
|
||||
|
||||
unsigned char SBC_GetCommandInformation(void *command,
|
||||
unsigned int *length,
|
||||
unsigned char *type,
|
||||
MSDLun *lun);
|
||||
|
||||
unsigned char SBC_ProcessCommand(MSDLun *lun,
|
||||
MSDCommandState *commandState);
|
||||
|
||||
#endif //#ifndef SBCMETHODS_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// SCSI commands implementation.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# After a CBW is received from host, use SBC_GetCommandInformation to check
|
||||
/// if the command is supported, and get the command length and type
|
||||
/// information before processing it.
|
||||
/// -# Then SBC_ProcessCommand can be used to handle a valid command, to
|
||||
/// perform the command operations.
|
||||
/// -# SBC_UpdateSenseData is used to update the sense data that will be sent
|
||||
/// to host.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef SBCMETHODS_H
|
||||
#define SBCMETHODS_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDDStateMachine.h"
|
||||
#include "../../../usb/device/massstorage/SBC.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "SBC Command States"
|
||||
/// This page lists the possible states of a SBC command.
|
||||
///
|
||||
/// !States
|
||||
/// - SBC_STATE_READ
|
||||
/// - SBC_STATE_WAIT_READ
|
||||
/// - SBC_STATE_WRITE
|
||||
/// - SBC_STATE_WAIT_WRITE
|
||||
/// - SBC_STATE_NEXT_BLOCK
|
||||
|
||||
/// Start of reading bulk data
|
||||
#define SBC_STATE_READ 0x01
|
||||
/// Waiting for the bulk data reading complete
|
||||
#define SBC_STATE_WAIT_READ 0x02
|
||||
/// Read error state
|
||||
#define SBC_STATE_READ_ERROR 0x03
|
||||
/// Start next read block
|
||||
#define SBC_STATE_NEXT_READ 0x04
|
||||
/// Start writing bulk data to host
|
||||
#define SBC_STATE_WRITE 0x05
|
||||
/// Waiting for the bulk data sending complete
|
||||
#define SBC_STATE_WAIT_WRITE 0x06
|
||||
/// Write error state
|
||||
#define SBC_STATE_WRITE_ERROR 0x07
|
||||
/// Start next write block
|
||||
#define SBC_STATE_NEXT_WRITE 0x08
|
||||
/// Start next command block
|
||||
#define SBC_STATE_NEXT_BLOCK 0x09
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void SBC_UpdateSenseData(SBCRequestSenseData *requestSenseData,
|
||||
unsigned char senseKey,
|
||||
unsigned char additionalSenseCode,
|
||||
unsigned char additionalSenseCodeQualifier);
|
||||
|
||||
unsigned char SBC_GetCommandInformation(void *command,
|
||||
unsigned int *length,
|
||||
unsigned char *type,
|
||||
MSDLun *lun);
|
||||
|
||||
unsigned char SBC_ProcessCommand(MSDLun *lun,
|
||||
MSDCommandState *commandState);
|
||||
|
||||
#endif //#ifndef SBCMETHODS_H
|
||||
|
||||
|
||||
@@ -18,156 +18,156 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#define __VECTORS_SAM3S_C__
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: All extern Data */
|
||||
/*=========================================================================*/
|
||||
extern unsigned long _estack;
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: Prototypes */
|
||||
/*=========================================================================*/
|
||||
void ResetHandler(void);
|
||||
|
||||
void NMI_Handler (void) __attribute__((weak));
|
||||
void HardFault_Handler (void) __attribute__((weak));
|
||||
void MemManage_Handler (void) __attribute__((weak));
|
||||
void BusFault_Handler (void) __attribute__((weak));
|
||||
void UsageFault_Handler (void) __attribute__((weak));
|
||||
void SVC_Handler (void) __attribute__((weak));
|
||||
void DebugMon_Handler (void) __attribute__((weak));
|
||||
void PendSV_Handler(void) __attribute__((weak));
|
||||
void SysTick_Handler (void) __attribute__((weak));
|
||||
void SUPC_IRQHandler (void) __attribute__((weak));
|
||||
void RSTC_IRQHandler (void) __attribute__((weak));
|
||||
void RTC_IRQHandler (void) __attribute__((weak));
|
||||
void RTT_IRQHandler (void) __attribute__((weak));
|
||||
void WDT_IRQHandler (void) __attribute__((weak));
|
||||
void PMC_IRQHandler (void) __attribute__((weak));
|
||||
void EEFC_IRQHandler (void) __attribute__((weak));
|
||||
void UART0_IRQHandler (void) __attribute__((weak));
|
||||
void UART1_IRQHandler (void) __attribute__((weak));
|
||||
void SMC_IRQHandler (void) __attribute__((weak));
|
||||
void PIOA_IRQHandler (void) __attribute__((weak));
|
||||
void PIOB_IRQHandler (void) __attribute__((weak));
|
||||
void PIOC_IRQHandler (void) __attribute__((weak));
|
||||
void USART0_IRQHandler (void) __attribute__((weak));
|
||||
void USART1_IRQHandler (void) __attribute__((weak));
|
||||
void MCI_IRQHandler (void) __attribute__((weak));
|
||||
void TWI0_IRQHandler (void) __attribute__((weak));
|
||||
void TWI1_IRQHandler (void) __attribute__((weak));
|
||||
void SPI_IRQHandler (void) __attribute__((weak));
|
||||
void SSC_IRQHandler (void) __attribute__((weak));
|
||||
void TC0_IRQHandler (void) __attribute__((weak));
|
||||
void TC1_IRQHandler (void) __attribute__((weak));
|
||||
void TC2_IRQHandler (void) __attribute__((weak));
|
||||
void TC3_IRQHandler (void) __attribute__((weak));
|
||||
void TC4_IRQHandler (void) __attribute__((weak));
|
||||
void TC5_IRQHandler (void) __attribute__((weak));
|
||||
void ADC_IRQHandler (void) __attribute__((weak));
|
||||
void DAC_IRQHandler (void) __attribute__((weak));
|
||||
void PWM_IRQHandler (void) __attribute__((weak));
|
||||
void CRCCU_IRQHandler (void) __attribute__((weak));
|
||||
void ACC_IRQHandler (void) __attribute__((weak));
|
||||
void USBD_IrqHandler (void) __attribute__((weak));
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: All code exported */
|
||||
/*=========================================================================*/
|
||||
/*
|
||||
* This is our vector table.
|
||||
*/
|
||||
__attribute__ ((section(".vectors"), used))
|
||||
void (* const gVectors[])(void) =
|
||||
{
|
||||
(void (*)(void))((unsigned long)&_estack),
|
||||
ResetHandler,
|
||||
NMI_Handler,
|
||||
HardFault_Handler,
|
||||
MemManage_Handler,
|
||||
BusFault_Handler,
|
||||
UsageFault_Handler,
|
||||
0, 0, 0, 0,
|
||||
SVC_Handler,
|
||||
DebugMon_Handler,
|
||||
0,
|
||||
PendSV_Handler,
|
||||
SysTick_Handler,
|
||||
|
||||
SUPC_IRQHandler, /* 0 SUPPLY CONTROLLER */
|
||||
RSTC_IRQHandler, /* 1 RESET CONTROLLER */
|
||||
RTC_IRQHandler, /* 2 REAL TIME CLOCK */
|
||||
RTT_IRQHandler, /* 3 REAL TIME TIMER */
|
||||
WDT_IRQHandler, /* 4 WATCHDOG TIMER */
|
||||
PMC_IRQHandler, /* 5 PMC */
|
||||
EEFC_IRQHandler, /* 6 EEFC */
|
||||
0, /* 7 Reserved */
|
||||
UART0_IRQHandler, /* 8 UART0 */
|
||||
UART1_IRQHandler, /* 9 UART1 */
|
||||
SMC_IRQHandler, /* 10 SMC */
|
||||
PIOA_IRQHandler, /* 11 Parallel IO Controller A */
|
||||
PIOB_IRQHandler, /* 12 Parallel IO Controller B */
|
||||
PIOC_IRQHandler, /* 13 Parallel IO Controller C */
|
||||
USART0_IRQHandler, /* 14 USART 0 */
|
||||
USART1_IRQHandler, /* 15 USART 1 */
|
||||
0, /* 16 Reserved */
|
||||
0, /* 17 Reserved */
|
||||
MCI_IRQHandler, /* 18 MCI */
|
||||
TWI0_IRQHandler, /* 19 TWI 0 */
|
||||
TWI1_IRQHandler, /* 20 TWI 1 */
|
||||
SPI_IRQHandler, /* 21 SPI */
|
||||
SSC_IRQHandler, /* 22 SSC */
|
||||
TC0_IRQHandler, /* 23 Timer Counter 0 */
|
||||
TC1_IRQHandler, /* 24 Timer Counter 1 */
|
||||
TC2_IRQHandler, /* 25 Timer Counter 2 */
|
||||
TC3_IRQHandler, /* 26 Timer Counter 3 */
|
||||
TC4_IRQHandler, /* 27 Timer Counter 4 */
|
||||
TC5_IRQHandler, /* 28 Timer Counter 5 */
|
||||
ADC_IRQHandler, /* 29 ADC controller */
|
||||
DAC_IRQHandler, /* 30 DAC controller */
|
||||
PWM_IRQHandler, /* 31 PWM */
|
||||
CRCCU_IRQHandler, /* 32 CRC Calculation Unit */
|
||||
ACC_IRQHandler, /* 33 Analog Comparator */
|
||||
USBD_IrqHandler, /* 34 USB Device Port */
|
||||
0 /* 35 not used */
|
||||
}; /* gVectors */
|
||||
|
||||
/*
|
||||
* And here are the weak interrupt handlers.
|
||||
*/
|
||||
void NMI_Handler (void) { while(1); }
|
||||
void HardFault_Handler (void) { while(1); }
|
||||
void MemManage_Handler (void) { while(1); }
|
||||
void BusFault_Handler (void) { while(1); }
|
||||
void UsageFault_Handler (void) { while(1); }
|
||||
void SVC_Handler (void) { while(1); }
|
||||
void DebugMon_Handler (void) { while(1); }
|
||||
void SUPC_IRQHandler (void) { while(1); }
|
||||
void RSTC_IRQHandler (void) { while(1); }
|
||||
void RTC_IRQHandler (void) { while(1); }
|
||||
void RTT_IRQHandler (void) { while(1); }
|
||||
void WDT_IRQHandler (void) { while(1); }
|
||||
void PMC_IRQHandler (void) { while(1); }
|
||||
void EEFC_IRQHandler (void) { while(1); }
|
||||
void UART1_IRQHandler (void) { while(1); }
|
||||
void SMC_IRQHandler (void) { while(1); }
|
||||
void PIOA_IRQHandler (void) { while(1); }
|
||||
void PIOB_IRQHandler (void) { while(1); }
|
||||
void PIOC_IRQHandler (void) { while(1); }
|
||||
void USART0_IRQHandler (void) { while(1); }
|
||||
void USART1_IRQHandler (void) { while(1); }
|
||||
void MCI_IRQHandler (void) { while(1); }
|
||||
void TWI1_IRQHandler (void) { while(1); }
|
||||
void SSC_IRQHandler (void) { while(1); }
|
||||
void TC0_IRQHandler (void) { while(1); }
|
||||
void TC1_IRQHandler (void) { while(1); }
|
||||
void TC4_IRQHandler (void) { while(1); }
|
||||
void TC5_IRQHandler (void) { while(1); }
|
||||
void ADC_IRQHandler (void) { while(1); }
|
||||
void CRCCU_IRQHandler (void) { while(1); }
|
||||
void ACC_IRQHandler (void) { while(1); }
|
||||
|
||||
/*** EOF ***/
|
||||
#define __VECTORS_SAM3S_C__
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: All extern Data */
|
||||
/*=========================================================================*/
|
||||
extern unsigned long _estack;
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: Prototypes */
|
||||
/*=========================================================================*/
|
||||
void ResetHandler(void);
|
||||
|
||||
void NMI_Handler (void) __attribute__((weak));
|
||||
void HardFault_Handler (void) __attribute__((weak));
|
||||
void MemManage_Handler (void) __attribute__((weak));
|
||||
void BusFault_Handler (void) __attribute__((weak));
|
||||
void UsageFault_Handler (void) __attribute__((weak));
|
||||
void SVC_Handler (void) __attribute__((weak));
|
||||
void DebugMon_Handler (void) __attribute__((weak));
|
||||
void PendSV_Handler(void) __attribute__((weak));
|
||||
void SysTick_Handler (void) __attribute__((weak));
|
||||
void SUPC_IRQHandler (void) __attribute__((weak));
|
||||
void RSTC_IRQHandler (void) __attribute__((weak));
|
||||
void RTC_IRQHandler (void) __attribute__((weak));
|
||||
void RTT_IRQHandler (void) __attribute__((weak));
|
||||
void WDT_IRQHandler (void) __attribute__((weak));
|
||||
void PMC_IRQHandler (void) __attribute__((weak));
|
||||
void EEFC_IRQHandler (void) __attribute__((weak));
|
||||
void UART0_IRQHandler (void) __attribute__((weak));
|
||||
void UART1_IRQHandler (void) __attribute__((weak));
|
||||
void SMC_IRQHandler (void) __attribute__((weak));
|
||||
void PIOA_IRQHandler (void) __attribute__((weak));
|
||||
void PIOB_IRQHandler (void) __attribute__((weak));
|
||||
void PIOC_IRQHandler (void) __attribute__((weak));
|
||||
void USART0_IRQHandler (void) __attribute__((weak));
|
||||
void USART1_IRQHandler (void) __attribute__((weak));
|
||||
void MCI_IRQHandler (void) __attribute__((weak));
|
||||
void TWI0_IRQHandler (void) __attribute__((weak));
|
||||
void TWI1_IRQHandler (void) __attribute__((weak));
|
||||
void SPI_IRQHandler (void) __attribute__((weak));
|
||||
void SSC_IRQHandler (void) __attribute__((weak));
|
||||
void TC0_IRQHandler (void) __attribute__((weak));
|
||||
void TC1_IRQHandler (void) __attribute__((weak));
|
||||
void TC2_IRQHandler (void) __attribute__((weak));
|
||||
void TC3_IRQHandler (void) __attribute__((weak));
|
||||
void TC4_IRQHandler (void) __attribute__((weak));
|
||||
void TC5_IRQHandler (void) __attribute__((weak));
|
||||
void ADC_IRQHandler (void) __attribute__((weak));
|
||||
void DAC_IRQHandler (void) __attribute__((weak));
|
||||
void PWM_IRQHandler (void) __attribute__((weak));
|
||||
void CRCCU_IRQHandler (void) __attribute__((weak));
|
||||
void ACC_IRQHandler (void) __attribute__((weak));
|
||||
void USBD_IrqHandler (void) __attribute__((weak));
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: All code exported */
|
||||
/*=========================================================================*/
|
||||
/*
|
||||
* This is our vector table.
|
||||
*/
|
||||
__attribute__ ((section(".vectors"), used))
|
||||
void (* const gVectors[])(void) =
|
||||
{
|
||||
(void (*)(void))((unsigned long)&_estack),
|
||||
ResetHandler,
|
||||
NMI_Handler,
|
||||
HardFault_Handler,
|
||||
MemManage_Handler,
|
||||
BusFault_Handler,
|
||||
UsageFault_Handler,
|
||||
0, 0, 0, 0,
|
||||
SVC_Handler,
|
||||
DebugMon_Handler,
|
||||
0,
|
||||
PendSV_Handler,
|
||||
SysTick_Handler,
|
||||
|
||||
SUPC_IRQHandler, /* 0 SUPPLY CONTROLLER */
|
||||
RSTC_IRQHandler, /* 1 RESET CONTROLLER */
|
||||
RTC_IRQHandler, /* 2 REAL TIME CLOCK */
|
||||
RTT_IRQHandler, /* 3 REAL TIME TIMER */
|
||||
WDT_IRQHandler, /* 4 WATCHDOG TIMER */
|
||||
PMC_IRQHandler, /* 5 PMC */
|
||||
EEFC_IRQHandler, /* 6 EEFC */
|
||||
0, /* 7 Reserved */
|
||||
UART0_IRQHandler, /* 8 UART0 */
|
||||
UART1_IRQHandler, /* 9 UART1 */
|
||||
SMC_IRQHandler, /* 10 SMC */
|
||||
PIOA_IRQHandler, /* 11 Parallel IO Controller A */
|
||||
PIOB_IRQHandler, /* 12 Parallel IO Controller B */
|
||||
PIOC_IRQHandler, /* 13 Parallel IO Controller C */
|
||||
USART0_IRQHandler, /* 14 USART 0 */
|
||||
USART1_IRQHandler, /* 15 USART 1 */
|
||||
0, /* 16 Reserved */
|
||||
0, /* 17 Reserved */
|
||||
MCI_IRQHandler, /* 18 MCI */
|
||||
TWI0_IRQHandler, /* 19 TWI 0 */
|
||||
TWI1_IRQHandler, /* 20 TWI 1 */
|
||||
SPI_IRQHandler, /* 21 SPI */
|
||||
SSC_IRQHandler, /* 22 SSC */
|
||||
TC0_IRQHandler, /* 23 Timer Counter 0 */
|
||||
TC1_IRQHandler, /* 24 Timer Counter 1 */
|
||||
TC2_IRQHandler, /* 25 Timer Counter 2 */
|
||||
TC3_IRQHandler, /* 26 Timer Counter 3 */
|
||||
TC4_IRQHandler, /* 27 Timer Counter 4 */
|
||||
TC5_IRQHandler, /* 28 Timer Counter 5 */
|
||||
ADC_IRQHandler, /* 29 ADC controller */
|
||||
DAC_IRQHandler, /* 30 DAC controller */
|
||||
PWM_IRQHandler, /* 31 PWM */
|
||||
CRCCU_IRQHandler, /* 32 CRC Calculation Unit */
|
||||
ACC_IRQHandler, /* 33 Analog Comparator */
|
||||
USBD_IrqHandler, /* 34 USB Device Port */
|
||||
0 /* 35 not used */
|
||||
}; /* gVectors */
|
||||
|
||||
/*
|
||||
* And here are the weak interrupt handlers.
|
||||
*/
|
||||
void NMI_Handler (void) { while(1); }
|
||||
void HardFault_Handler (void) { while(1); }
|
||||
void MemManage_Handler (void) { while(1); }
|
||||
void BusFault_Handler (void) { while(1); }
|
||||
void UsageFault_Handler (void) { while(1); }
|
||||
void SVC_Handler (void) { while(1); }
|
||||
void DebugMon_Handler (void) { while(1); }
|
||||
void SUPC_IRQHandler (void) { while(1); }
|
||||
void RSTC_IRQHandler (void) { while(1); }
|
||||
void RTC_IRQHandler (void) { while(1); }
|
||||
void RTT_IRQHandler (void) { while(1); }
|
||||
void WDT_IRQHandler (void) { while(1); }
|
||||
void PMC_IRQHandler (void) { while(1); }
|
||||
void EEFC_IRQHandler (void) { while(1); }
|
||||
void UART1_IRQHandler (void) { while(1); }
|
||||
void SMC_IRQHandler (void) { while(1); }
|
||||
void PIOA_IRQHandler (void) { while(1); }
|
||||
void PIOB_IRQHandler (void) { while(1); }
|
||||
void PIOC_IRQHandler (void) { while(1); }
|
||||
void USART0_IRQHandler (void) { while(1); }
|
||||
void USART1_IRQHandler (void) { while(1); }
|
||||
void MCI_IRQHandler (void) { while(1); }
|
||||
void TWI1_IRQHandler (void) { while(1); }
|
||||
void SSC_IRQHandler (void) { while(1); }
|
||||
void TC0_IRQHandler (void) { while(1); }
|
||||
void TC1_IRQHandler (void) { while(1); }
|
||||
void TC4_IRQHandler (void) { while(1); }
|
||||
void TC5_IRQHandler (void) { while(1); }
|
||||
void ADC_IRQHandler (void) { while(1); }
|
||||
void CRCCU_IRQHandler (void) { while(1); }
|
||||
void ACC_IRQHandler (void) { while(1); }
|
||||
|
||||
/*** EOF ***/
|
||||
|
||||
Reference in New Issue
Block a user