/*This file is prepared for Doxygen automatic documentation generation.*/
/*! \file *********************************************************************
 *
 * \brief AT32UC3B USPSR_2B board header file.
 *
 * This file contains definitions and services related to the features of the
 * USPSR board rev. 2B.
 *
 * To use this board, define BOARD=USPSR2B.
 *
 * - Compiler:           GNU GCC for AVR32
 * - Supported devices:  AT32UC3B1256
 * - AppNote:
 *
 * \author               Atmel Corporation: http://www.atmel.com \n
 *                       Support and FAQ: http://support.atmel.no/
 *
 ******************************************************************************/

/* Copyright (c) 2009 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:
 *
 * 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. The name of Atmel may not be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * 4. This software may only be redistributed and used in connection with an Atmel
 * AVR product.
 *
 * 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
 * EXPRESSLY AND SPECIFICALLY 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 _USPSR_2B_H_
#define _USPSR_2B_H_

#include "compiler.h"

/*! \name Oscillator Definitions
 */
//! @{

// RCOsc has no custom calibration by default. Set the following definition to
// the appropriate value if a custom RCOsc calibration has been applied to your
// part.
//#define FRCOSC          AVR32_PM_RCOSC_FREQUENCY              		//!< RCOsc frequency: Hz.

#define FOSC0           	12000000L                              		//!< Osc0 frequency: Hz.
#define OSC0_STARTUP    	AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC		//!< Osc0 startup time: RCOsc periods.

#define PLL_MUL				9
#define PLL_DIV				1
#define PBACLK_DIVEN		1
#define PBBCLK_DIVEN		0
#define HSBCLK_DIVEN		0

#define USPSR_PBACLK		FOSC0*(PLL_MUL+1)/PLL_DIV/2/(PBACLK_DIVEN+1) //!< PBA clock target frequency, in Hz

//! @}

/*! \name Board specific definitions
 */
//! @{

#define USPSR_COM_USART					(&AVR32_USART2)
#define USPSR_COM_USART_RX_PIN			AVR32_USART2_RXD_0_0_PIN
#define USPSR_COM_USART_RX_FUNCTION		AVR32_USART2_RXD_0_0_FUNCTION
#define USPSR_COM_USART_TX_PIN			AVR32_USART2_TXD_0_0_PIN
#define USPSR_COM_USART_TX_FUNCTION		AVR32_USART2_TXD_0_0_FUNCTION
#define USPSR_RFI_USART					(&AVR32_USART1)
#define USPSR_RFI_USART_RX_PIN			AVR32_USART1_RXD_0_0_PIN
#define USPSR_RFI_USART_RX_FUNCTION		AVR32_USART1_RXD_0_0_FUNCTION
#define USPSR_LED0_GPIO					AVR32_PIN_PA20
#define USPSR_LED1_GPIO					AVR32_PIN_PA21
#define USPSR_LED2_GPIO					AVR32_PIN_PA22
#define USPSR_LED3_GPIO					AVR32_PIN_PA23

#define USPSR_POT1_GPIO					AVR32_PIN_PA09   /////////////////////////////////////////////////////////////////////
#define USPSR_POT2_GPIO					AVR32_PIN_PA10

#define SPIO			(&AVR32_SPI)
//#define SPI_CS				16 // PA.16 - Output: SPI Select
//#define SPI_SCK				15 // PA.15 - Output: SPI Serial Clock
//#define SPI_MISO			25 // PA.25 - Input: Master Input
#define SPI_CS				AVR32_PIN_PA16
#define SPI_SCK_PIN			AVR32_SPI_SCK_0_0_PIN
#define SPI_SCK_FUNCTION	AVR32_SPI_SCK_0_0_FUNCTION
#define SPI_MISO_PIN		AVR32_SPI_MISO_0_0_PIN
#define SPI_MISO_FUNCTION	AVR32_SPI_MISO_0_0_FUNCTION
////
#define SPI_NPCS_PIN		AVR32_SPI_NPCS_0_0_PIN
#define SPI_NPCS_FUNCTION	AVR32_SPI_NPCS_0_0_FUNCTION
////
 #define spi_select(x)			spi_selectChip(SPIO,x)
  #define spi_unselect(x)		spi_unselectChip(SPIO,x)
  #define spi_send(x)			spi_write(SPIO,x)
  #define spi_rcv(x)			spi_read(SPIO,x)



////


#define PWM_ADDRESS		(&AVR32_PWM_ADDRESS)
#define PWM_PIN			(AVR32_PWM_0_0_PIN )
#define PWM_FUNCTION	(AVR32_PWM_0_0_FUNCTION)
#define PWM_DIRECTION	AVR32_PIN_PA08
#define PWM_CHANNEL_ID	3

	
/*#define ENA	(AVR32_PWM_ENA)
#define IER AVR32_PWM_IER
#define CMR AVR32_PWM_CMR
#define CDTY AVR32_PWM_CDTY
#define CPRD AVR32_PWM_CPRD

#define IDR AVR32_PWM_IDR
#define CPD AVR32_PWM_CPD	

#define CPOL AVR32_PWM_CPOL	*/



////
#define USPSR_TC						(&AVR32_TC)
#define USPSR_TC_IRQ_GROUP				AVR32_TC_IRQ_GROUP
#define USPSR_TC_IRQ					AVR32_TC_IRQ0
#define USPSR_TC_CHANNEL				0

//! @}

/*! \name ADC Connection for RF Receiver RSSI channel
 */
//! @{
#define ADC_RF_RSSI_CHANNEL     7
#define ADC_RF_RSSI_PIN         AVR32_ADC_AD_7_PIN
#define ADC_RF_RSSI_FUNCTION    AVR32_ADC_AD_7_FUNCTION
//! @}


#endif  // _USPSR_2B_H_



