diff --git a/sam3s_example/mains/at91lib_based_ccid_example.c b/sam3s_example/mains/at91lib_based_ccid_example.c
deleted file mode 100644
index bbf319fa..00000000
--- a/sam3s_example/mains/at91lib_based_ccid_example.c
+++ /dev/null
@@ -1,355 +0,0 @@
-/* ----------------------------------------------------------------------------
- * ATMEL Microcontroller Software Support
- * ----------------------------------------------------------------------------
- * 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:
- *
- * - 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 usart_iso7816 USART ISO7816 Example
- *
- * \section Purpose
- * This example sends ISO 7816 commands to a smartcard connected to the
- * evaluation kits on sam3s.
- *
- * \section Requirements
- * This example can be used on sam3s evaluation kit. Please connect the
- * smartcard contacts with following pins which could be easily wired from
- * the board.
- * - SAM3S-EK -- SMARTCARD
- * - PA11 -- RST
- * - TXD1(PA22) -- I/O
- * - SCK1(PA23) -- CLK
- *
- * \section Description
- * The iso7816 software provide in this examples is use to transform APDU
- * commands to TPDU commands for the smart card.
- * The iso7816 provide here is for the protocol T=0 only.
- * The send and the receive of a character is made under polling.
- * In the file ISO7816_Init is defined all pins of the card. User must have to
- * change this pins according to his environment.
- * The driver is compliant with CASE 1, 2, 3 of the ISO7816-4 specification.
- *
- * \section Usage
- * -# Build the program and download it inside the evaluation board. Please
- * refer to the SAM-BA User Guide,
- * the GNU-Based Software Development
- * application note or to the IAR EWARM User Guide,
- * depending on your chosen solution.
- * -# On the computer, open and configure a terminal application (e.g.
- * HyperTerminal on Microsoft Windows) with these settings:
- * - 115200 bauds
- * - 8 data bits
- * - No parity
- * - 1 stop bit
- * - No flow control
- * -# Connect the card reader to sam3s-ek board:
- *
- * | C1: Vcc: 7816_3V5V | C5: Gnd | C4: RFU |
- * | C2: Reset: 7816_RST | C6: Vpp | C8: RFU |
- * | C3: Clock: 7816_CLK | C7: 7816_IO |
- *
- * If necessary,another pin must be connected on the card reader for detecting the
- * insertion and removal: 7816_IRQ.
- * On Atmel boards, all this pins can be easily connecting with jumpers.
- * -# Start the application. The following traces shall appear on the terminal:
- * \code
- * -- USART ISO7816 Example xxx --
- * -- xxxxxx-xx
- * -- Compiled: xxx xx xxxx xx:xx:xx --
- * Display the ATR
- * \endcode
- *
- * \section References
- * - usart_iso7816/main.c
- * - iso7816_4.c
- * - pio.h
- * - usart.h
- *
- */
-
-/** \file
- *
- * This file contains all the specific code for the usart_iso7816 example.
- *
- */
-
-
-/*------------------------------------------------------------------------------
- * Headers
- *------------------------------------------------------------------------------*/
-
-#include "board.h"
-
-#include
-
-/*------------------------------------------------------------------------------
- * Internal definitions
- *------------------------------------------------------------------------------*/
-
-/** Maximum ucSize in bytes of the smartcard answer to a command.*/
-#define MAX_ANSWER_SIZE 10
-
-/** Maximum ATR ucSize in bytes.*/
-#define MAX_ATR_SIZE 55
-
-/** USB states */
-/// Use for power management
-#define STATE_IDLE 0
-/// The USB device is in suspend state
-#define STATE_SUSPEND 4
-/// The USB device is in resume state
-#define STATE_RESUME 5
-
-/*------------------------------------------------------------------------------
- * Internal variables
- *------------------------------------------------------------------------------*/
-/** USB state: suspend, resume, idle */
-unsigned char USBState = STATE_IDLE;
-
-/** Test command #1.*/
-static const uint8_t testCommand1[] = {0x00, 0x10, 0x00, 0x00};
-/** Test command #2.*/
-static const uint8_t testCommand2[] = {0x00, 0x20, 0x00, 0x00, 0x02};
-/** Test command #3.*/
-static const uint8_t testCommand3[] = {0x00, 0x30, 0x00, 0x00, 0x02, 0x0A, 0x0B};
-/* Select MF */
-static const uint8_t testCommand4[] = {0x00, 0xa4, 0x00, 0x00, 0x02, 0x3f, 0x00};
-/** ISO7816 pins */
-static const Pin pinsISO7816[] = {PINS_ISO7816};
-/** ISO7816 RST pin */
-static const Pin pinIso7816RstMC = PIN_ISO7816_RSTMC;
-static uint8_t sim_inserted = 0;
-
-static const Pin pPwr[] = {
- /* Enable power converter 4.5-6V to 3.3V; low: off */
- {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT},
-
- /* Enable second power converter: VCC_PHONE to VCC_SIM; high: off */
- {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
-};
-
-/*------------------------------------------------------------------------------
- * Optional smartcard detection
- *------------------------------------------------------------------------------*/
-
-#ifdef SMARTCARD_CONNECT_PIN
-
-/** Smartcard detection pin.*/
-static const Pin pinSmartCard = SMARTCARD_CONNECT_PIN;
-
-/**
- * PIO interrupt service routine. Checks if the smartcard has been connected
- * or disconnected.
- */
-static void ISR_PioSmartCard( const Pin *pPin )
-{
-/* FIXME: why is pinSmartCard.pio->PIO_ISR the wrong number?
- printf("+++++ Trying to check for pending interrupts (PIO ISR: 0x%X)\n\r", pinSmartCard.pio->PIO_ISR);
- printf("+++++ Mask: 0x%X\n\r", pinSmartCard.mask);
-Output:
- +++++ Trying to check for pending interrupts (PIO ISR: 0x400)) = 1<<10
- +++++ Mask: 0x100 = 1<<8
-*/
- // PA10 is DTXD, which is the debug uart transmit pin
-
- printf("Interrupt!!\n\r");
- /* Check all pending interrupts */
- // FIXME: this if condition is not always true...
-// if ( (pinSmartCard.pio->PIO_ISR & pinSmartCard.mask) != 0 )
- {
- /* Check current level on pin */
- if ( PIO_Get( &pinSmartCard ) == 0 )
- {
- sim_inserted = 1;
- printf( "-I- Smartcard inserted\n\r" ) ;
- CCID_Insertion();
- }
- else
- {
- sim_inserted = 0;
- printf( "-I- Smartcard removed\n\r" ) ;
- CCID_Removal();
- }
- }
-}
-
-/**
- * Configures the smartcard detection pin to trigger an interrupt.
- */
-static void ConfigureCardDetection( void )
-{
- printf("+++++ Configure PIOs\n\r");
- PIO_Configure( &pinSmartCard, 1 ) ;
- NVIC_EnableIRQ( PIOA_IRQn );
-// FIXME: Do we need to set priority?: NVIC_SetPriority( PIOA_IRQn, 10);
- PIO_ConfigureIt( &pinSmartCard, ISR_PioSmartCard ) ;
- PIO_EnableIt( &pinSmartCard ) ;
-}
-
-#else
-
-/**
- * Dummy implementation.
- */
-static void ConfigureCardDetection( void )
-{
- printf( "-I- Smartcard detection not supported.\n\r" ) ;
-}
-
-#endif
-
-
-/*------------------------------------------------------------------------------
- * USB
- *------------------------------------------------------------------------------*/
-
-// FIXME: Implement those two functions
-//------------------------------------------------------------------------------
-/// Put the CPU in 32kHz, disable PLL, main oscillator
-/// Put voltage regulator in standby mode
-//------------------------------------------------------------------------------
-void LowPowerMode(void)
-{
-// FIXME: Implement low power consumption mode?
-// PMC_CPUInIdleMode();
-}
-//------------------------------------------------------------------------------
-/// Put voltage regulator in normal mode
-/// Return the CPU to normal speed 48MHz, enable PLL, main oscillator
-//------------------------------------------------------------------------------
-void NormalPowerMode(void)
-{
-}
-
-
-/*------------------------------------------------------------------------------
- * Main
- *------------------------------------------------------------------------------*/
-
-/**
- * Initializes the DBGU and ISO7816 driver, and starts some tests.
- * \return Unused (ANSI-C compatibility)
- */
-extern int main( void )
-{
- uint8_t pAtr[MAX_ATR_SIZE] ;
- uint8_t ucSize ;
-
- LED_Configure(LED_NUM_GREEN);
- LED_Set(LED_NUM_GREEN);
-
- /* Disable watchdog*/
- WDT_Disable( WDT ) ;
-
- /* Initialize Atr buffer */
- memset( pAtr, 0, sizeof( pAtr ) ) ;
-
- printf("%s", "=====================================================\n\r");
- printf( "-- USART ISO7816 Example %s --\n\r", SOFTPACK_VERSION ) ;
- printf( "-- %s\n\r", BOARD_NAME ) ;
- printf( "-- Compiled: %s %s --\n\r", __DATE__, __TIME__ ) ;
- printf("%s", "=====================================================\n\r");
-
-
- PIO_InitializeInterrupts(0);
-
- /* Configure IT on Smart Card */
- ConfigureCardDetection() ;
-
- /* Configure Phone SIM connection*/
-/* Pin phone_sim_connect[] = {PIN_SC_SW, PIN_IO_SW};
- PIO_Configure( phone_sim_connect, PIO_LISTSIZE(phone_sim_connect) );
-*/
-
- /* Configure ISO7816 driver */
- PIO_Configure( pinsISO7816, PIO_LISTSIZE( pinsISO7816 ) ) ;
- PIO_Configure(pPwr, PIO_LISTSIZE(pPwr));
-
-// Card has no power until now
- PIO_Set(&pPwr[0]);
-
-// FIXME: RST seems to be allways low here
- TRACE_DEBUG("******* Reset State1 (1 if the Pin RstMC is high): 0x%X", ISO7816_StatusReset());
-
- ISO7816_Init( pinIso7816RstMC ) ;
-
- TRACE_DEBUG("******* Reset State2 (1 if the Pin RstMC is high): 0x%X", ISO7816_StatusReset());
-
- /* Read ATR */
- ISO7816_warm_reset() ;
-
- ISO7816_Datablock_ATR( pAtr, &ucSize ) ;
- TRACE_DEBUG("******* Reset State3 (1 if the Pin RstMC is high): 0x%X", ISO7816_StatusReset());
-
- /* Decode ATR */
- ISO7816_Decode_ATR( pAtr ) ;
-
-// FIXME: RST seems to be allways high
- TRACE_DEBUG("******* Reset State4 (1 if the Pin RstMC is high): 0x%X", ISO7816_StatusReset());
- //SendReceiveCommands() ;
-
- CCIDDriver_Initialize();
-
-// FIXME: Or do I need to call VBUS_CONFIGURE() here instead, which will call USBD_Connect() later?
- USBD_Connect();
-// FIXME: USB clock? USB PMC?
- NVIC_EnableIRQ( UDP_IRQn );
-
- // FIXME: At some point USBD_IrqHandler() should get called and set USBD_STATE_CONFIGURED
- while (USBD_GetState() < USBD_STATE_CONFIGURED) {
- int i = 1;
- if ((i%10000) == 0) {
- TRACE_DEBUG("%d: USB State: %x\n\r", i, USBD_GetState());
- }
- i++;
- }
-
-// FIXME. what if smcard is not inserted?
- if(PIO_Get(&pinSmartCard) == 0) {
- printf("SIM card inserted\n\r");
- CCID_Insertion();
- }
-
- // Infinite loop
- while (1) {
-
- if( USBState == STATE_SUSPEND ) {
- TRACE_DEBUG("suspend !\n\r");
- LowPowerMode();
- USBState = STATE_IDLE;
- }
- if( USBState == STATE_RESUME ) {
- // Return in normal MODE
- TRACE_DEBUG("resume !\n\r");
- NormalPowerMode();
- USBState = STATE_IDLE;
- }
- CCID_SmartCardRequest();
- }
-
- return 0 ;
-}
-
diff --git a/sam3s_example/mains/blink.c b/sam3s_example/mains/blink.c
deleted file mode 100644
index d5bf27d4..00000000
--- a/sam3s_example/mains/blink.c
+++ /dev/null
@@ -1,22 +0,0 @@
-// Xtal: Default internal 4MHz
-#include
-//#include
-
-int main () {
- int i,j;
- //i=1000;
- //j=10000;
- PMC->PMC_WPMR = 0x504D4300;// Disable write protect
- PMC->PMC_PCER0 = (1<<11);// Enable PIO clock
- PIOA->PIO_PER = (1<<19); //Enable PIO
- PIOA->PIO_OER = (1<<19); //Enable Output
-
- while (1) {
- PIOA->PIO_CODR = (1<<18);// Turn LED on
- for (i=1;i<1000;i++) // Waiting
- for (j=1;j<3000;j++);
- PIOA->PIO_SODR = (1<<18);// Turn LED off
- for (i=1;i<1000;i++) // Waiting
- for (j=1;j<2000;j++);
- }
-}
diff --git a/sam3s_example/mains/blink2.c b/sam3s_example/mains/blink2.c
deleted file mode 100644
index 112bfe92..00000000
--- a/sam3s_example/mains/blink2.c
+++ /dev/null
@@ -1,55 +0,0 @@
-#include "board.h"
-#include "pio.h"
-
-const Pin statusled = {PIO_PA18, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
-const Pin statusled2 = {PIO_PA17, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
-const Pin io = PIN_PHONE_IO;
-
-int main()
-{
- register int i = 0;
- register int b = 0;
-
- PIO_Configure(&io, PIO_LISTSIZE(io));
- PIO_Clear(&io);
-
- PIO_Configure(&statusled, PIO_LISTSIZE(statusled));
- PIO_Clear(&statusled);
- PIO_Configure(&statusled2, PIO_LISTSIZE(statusled2));
- PIO_Clear(&statusled2);
-
- for(;;) {
- i = i+1;
- if ((i%100000) == 0) {
- switch(b) {
- case 0:
- PIO_Set(&statusled);
- b=1;
- PIO_Set(&io);
- break;
- case 1:
- PIO_Set(&statusled2);
- PIO_Set(&statusled);
- b = 2;
- PIO_Clear(&io);
- break;
- case 2:
- PIO_Clear(&statusled);
- b = 3;
- PIO_Set(&io);
- break;
- case 3:
- PIO_Clear(&statusled2);
- b = 0;
- break;
- PIO_Clear(&io);
- default:
- b = 0;
- }
- }
- }
-
- return i;
-}
-
-/* vim: set ts=4: */
diff --git a/sam3s_example/mains/blink_thilo.c b/sam3s_example/mains/blink_thilo.c
deleted file mode 100644
index 0228922e..00000000
--- a/sam3s_example/mains/blink_thilo.c
+++ /dev/null
@@ -1,45 +0,0 @@
-#include "board.h"
-#include "pio.h"
-
-const Pin statusled = {PIO_PA18, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
-const Pin statusled2 = {PIO_PA17, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
-
-int main()
-{
- register int i = 0;
- register int b = 0;
-
- PIO_Configure(&statusled, PIO_LISTSIZE(statusled));
- PIO_Clear(&statusled);
- PIO_Configure(&statusled2, PIO_LISTSIZE(statusled2));
- PIO_Clear(&statusled2);
-
- for(;;) {
- i = i+1;
- if ((i%100000) == 0) {
- switch(b) {
- case 0:
- PIO_Set(&statusled);
- b=1;
- break;
- case 1:
- PIO_Set(&statusled2);
- PIO_Set(&statusled);
- b = 2;
- break;
- case 2:
- PIO_Clear(&statusled);
- b = 3;
- break;
- case 3:
- PIO_Clear(&statusled2);
- b = 0;
- break;
- default:
- b = 0;
- }
- }
- }
-
- return i;
-}
diff --git a/sam3s_example/mains/debug_uart_stdlib.c b/sam3s_example/mains/debug_uart_stdlib.c
deleted file mode 100644
index 1eb20149..00000000
--- a/sam3s_example/mains/debug_uart_stdlib.c
+++ /dev/null
@@ -1,33 +0,0 @@
-#include "board.h"
-
-#include
-#include
-
-extern void UART_PutString(const char *str, int len);
-
-void Configure_LEDs() {
- LED_Configure(LED_NUM_RED);
- LED_Configure(LED_NUM_GREEN);
-}
-
-int main() {
- size_t ret = 0;
-
- Configure_LEDs();
-
- ret = printf("Clockval: %d\r\n", BOARD_MCK);
-
- if (ret < 0){
- LED_Clear(LED_NUM_GREEN);
- LED_Set(LED_NUM_RED);
- } else {
- LED_Clear(LED_NUM_RED);
- LED_Set(LED_NUM_GREEN);
-
- while (1) {
- printf("Clockval**++????: %d\r\n", BOARD_MCK);
- }
- }
-
- return 0;
-}
diff --git a/sam3s_example/mains/iso7816.c b/sam3s_example/mains/iso7816.c
deleted file mode 100644
index 05b2b3da..00000000
--- a/sam3s_example/mains/iso7816.c
+++ /dev/null
@@ -1,381 +0,0 @@
-/* ----------------------------------------------------------------------------
- * ATMEL Microcontroller Software Support
- * ----------------------------------------------------------------------------
- * 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:
- *
- * - 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 usart_iso7816 USART ISO7816 Example
- *
- * \section Purpose
- * This example sends ISO 7816 commands to a smartcard connected to the
- * evaluation kits on sam3s.
- *
- * \section Requirements
- * This example can be used on sam3s evaluation kit. Please connect the
- * smartcard contacts with following pins which could be easily wired from
- * the board.
- * - SAM3S-EK -- SMARTCARD
- * - PA11 -- RST
- * - TXD1(PA22) -- I/O
- * - SCK1(PA23) -- CLK
- *
- * \section Description
- * The iso7816 software provide in this examples is use to transform APDU
- * commands to TPDU commands for the smart card.
- * The iso7816 provide here is for the protocol T=0 only.
- * The send and the receive of a character is made under polling.
- * In the file ISO7816_Init is defined all pins of the card. User must have to
- * change this pins according to his environment.
- * The driver is compliant with CASE 1, 2, 3 of the ISO7816-4 specification.
- *
- * \section Usage
- * -# Build the program and download it inside the evaluation board. Please
- * refer to the SAM-BA User Guide,
- * the GNU-Based Software Development
- * application note or to the IAR EWARM User Guide,
- * depending on your chosen solution.
- * -# On the computer, open and configure a terminal application (e.g.
- * HyperTerminal on Microsoft Windows) with these settings:
- * - 115200 bauds
- * - 8 data bits
- * - No parity
- * - 1 stop bit
- * - No flow control
- * -# Connect the card reader to sam3s-ek board:
- *
- * | C1: Vcc: 7816_3V5V | C5: Gnd | C4: RFU |
- * | C2: Reset: 7816_RST | C6: Vpp | C8: RFU |
- * | C3: Clock: 7816_CLK | C7: 7816_IO |
- *
- * If necessary,another pin must be connected on the card reader for detecting the
- * insertion and removal: 7816_IRQ.
- * On Atmel boards, all this pins can be easily connecting with jumpers.
- * -# Start the application. The following traces shall appear on the terminal:
- * \code
- * -- USART ISO7816 Example xxx --
- * -- xxxxxx-xx
- * -- Compiled: xxx xx xxxx xx:xx:xx --
- * Display the ATR
- * \endcode
- *
- * \section References
- * - usart_iso7816/main.c
- * - iso7816_4.c
- * - pio.h
- * - usart.h
- *
- */
-
-/** \file
- *
- * This file contains all the specific code for the usart_iso7816 example.
- *
- */
-
-
-/*------------------------------------------------------------------------------
- * Headers
- *------------------------------------------------------------------------------*/
-
-#include "board.h"
-
-#include
-
-/*------------------------------------------------------------------------------
- * Internal definitions
- *------------------------------------------------------------------------------*/
-
-/** Maximum ucSize in bytes of the smartcard answer to a command.*/
-#define MAX_ANSWER_SIZE 10
-
-/** Maximum ATR ucSize in bytes.*/
-#define MAX_ATR_SIZE 55
-
-/*------------------------------------------------------------------------------
- * Internal variables
- *------------------------------------------------------------------------------*/
-
-/** Test command #1.*/
-static const uint8_t testCommand1[] = {0x00, 0x10, 0x00, 0x00};
-/** Test command #2.*/
-static const uint8_t testCommand2[] = {0x00, 0x20, 0x00, 0x00, 0x02};
-/** Test command #3.*/
-static const uint8_t testCommand3[] = {0x00, 0x30, 0x00, 0x00, 0x02, 0x0A, 0x0B};
-/* Select MF */
-static const uint8_t testCommand4[] = {0x00, 0xa4, 0x00, 0x00, 0x02, 0x3f, 0x00};
-/** ISO7816 pins */
-static const Pin pinsISO7816[] = {PINS_ISO7816};
-/** ISO7816 RST pin */
-static const Pin pinIso7816RstMC = PIN_ISO7816_RSTMC;
-static uint8_t sim_inserted = 0;
-/*------------------------------------------------------------------------------
- * Internal functions
- *------------------------------------------------------------------------------*/
-
-/*------------------------------------------------------------------------------
- * Optional smartcard detection
- *------------------------------------------------------------------------------*/
-
-#ifdef SMARTCARD_CONNECT_PIN
-
-/** Smartcard detection pin.*/
-static const Pin pinSmartCard = SMARTCARD_CONNECT_PIN;
-
-/**
- * PIO interrupt service routine. Checks if the smartcard has been connected
- * or disconnected.
- */
-static void ISR_PioSmartCard( const Pin *pPin )
-{
-/* FIXME: why is pinSmartCard.pio->PIO_ISR the wrong number?
- printf("+++++ Trying to check for pending interrupts (PIO ISR: 0x%X)\n\r", pinSmartCard.pio->PIO_ISR);
- printf("+++++ Mask: 0x%X\n\r", pinSmartCard.mask);
-Output:
- +++++ Trying to check for pending interrupts (PIO ISR: 0x400)) = 1<<10
- +++++ Mask: 0x100 = 1<<8
-*/
- /* Check all pending interrupts */
- if ( (pinSmartCard.pio->PIO_ISR & pinSmartCard.mask) != 0 )
- {
- /* Check current level on pin */
- if ( PIO_Get( &pinSmartCard ) == 0 )
- {
- sim_inserted = 1;
- printf( "-I- Smartcard inserted\n\r" ) ;
- }
- else
- {
- sim_inserted = 0;
- printf( "-I- Smartcard removed\n\r" ) ;
- }
- }
-}
-
-/**
- * Configures the smartcard detection pin to trigger an interrupt.
- */
-static void ConfigureCardDetection( void )
-{
- printf("+++++ Configure PIOs\n\r");
- PIO_Configure( &pinSmartCard, 1 ) ;
- NVIC_EnableIRQ( PIOA_IRQn );
-// FIXME: Do we need to set priority?: NVIC_SetPriority( PIOA_IRQn, 10);
- PIO_ConfigureIt( &pinSmartCard, ISR_PioSmartCard ) ;
- PIO_EnableIt( &pinSmartCard ) ;
-}
-
-#else
-
-/**
- * Dummy implementation.
- */
-static void ConfigureCardDetection( void )
-{
- printf( "-I- Smartcard detection not supported.\n\r" ) ;
-}
-
-#endif
-
-/**
- * Displays a menu which enables the user to send several commands to the
- * smartcard and check its answers.
- */
-static void SendReceiveCommands( void )
-{
- uint8_t pMessage[MAX_ANSWER_SIZE];
- uint8_t ucSize ;
- uint8_t ucKey ;
- uint8_t command;
- uint8_t i;
-
- /* Clear message buffer */
- memset( pMessage, 0, sizeof( pMessage ) ) ;
-
- /* Display menu */
- printf( "-I- The following three commands can be sent:\n\r" ) ;
- printf( " 1. " ) ;
- for ( i=0 ; i < sizeof( testCommand1 ) ; i++ )
- {
- printf( "0x%X ", testCommand1[i] ) ;
- }
- printf( "\n\r 2. " ) ;
-
- for ( i=0 ; i < sizeof( testCommand2 ) ; i++ )
- {
- printf( "0x%X ", testCommand2[i] ) ;
- }
- printf( "\n\r 3. " ) ;
-
- for ( i=0 ; i < sizeof( testCommand3 ) ; i++ )
- {
- printf( "0x%X ", testCommand3[i] ) ;
- }
- printf( "\n\r 4. " ) ;
-
- for ( i=0 ; i < sizeof( testCommand4 ) ; i++ )
- {
- printf( "0x%X ", testCommand4[i] ) ;
- }
- printf( "\n\r" ) ;
-
- /* Get user input */
- ucKey = 0 ;
- while ( ucKey != 'q' )
- {
- printf( "\r " ) ;
- printf( "\rChoice ? (q to quit): " ) ;
-#if defined ( __GNUC__ )
- fflush(stdout);
-#endif
- ucKey = UART_GetChar() ;
- printf( "%c", ucKey ) ;
- command = ucKey - '0';
-
- /* Check user input */
- ucSize = 0 ;
- if ( command == 1 )
- {
- printf( "\n\r-I- Sending command " ) ;
- for ( i=0 ; i < sizeof( testCommand1 ) ; i++ )
- {
- printf( "0x%02X ", testCommand1[i] ) ;
- }
- printf( "...\n\r" ) ;
- ucSize = ISO7816_XfrBlockTPDU_T0( testCommand1, pMessage, sizeof( testCommand1 ) ) ;
- }
- else
- {
- if ( command == 2 )
- {
- printf( "\n\r-I- Sending command " ) ;
- for ( i=0 ; i < sizeof( testCommand2 ) ; i++ )
- {
- printf("0x%02X ", testCommand2[i] ) ;
- }
- printf( "...\n\r" ) ;
- ucSize = ISO7816_XfrBlockTPDU_T0( testCommand2, pMessage, sizeof( testCommand2 ) ) ;
- }
- else
- {
- if ( command == 3 )
- {
- printf( "\n\r-I- Sending command " ) ;
- for ( i=0 ; i < sizeof( testCommand3 ) ; i++ )
- {
- printf( "0x%02X ", testCommand3[i] ) ;
- }
- printf( "...\n\r" ) ;
- ucSize = ISO7816_XfrBlockTPDU_T0( testCommand3, pMessage, sizeof( testCommand3 ) ) ;
- }
- else
- {
- if ( command == 4 )
- {
- printf( "\n\r-I- Sending command " ) ;
- for ( i=0 ; i < sizeof( testCommand4 ) ; i++ )
- {
- printf( "0x%02X ", testCommand4[i] ) ;
- }
- printf( "...\n\r" ) ;
- ucSize = ISO7816_XfrBlockTPDU_T0( testCommand4, pMessage, sizeof( testCommand4 ) ) ;
- }
- }
- }
- }
-
- /* Output smartcard answer */
- if ( ucSize > 0 )
- {
- printf( "\n\rAnswer: " ) ;
- for ( i=0 ; i < ucSize ; i++ )
- {
- printf( "0x%02X ", pMessage[i] ) ;
- }
- printf( "\n\r" ) ;
- }
- }
-
- printf( "Quitting ...\n\r" ) ;
-}
-
-/*------------------------------------------------------------------------------
- * Exported functions
- *------------------------------------------------------------------------------*/
-
-/**
- * Initializes the DBGU and ISO7816 driver, and starts some tests.
- * \return Unused (ANSI-C compatibility)
- */
-extern int main( void )
-{
- uint8_t pAtr[MAX_ATR_SIZE] ;
- uint8_t ucSize ;
-
- LED_Configure(LED_NUM_GREEN);
- LED_Set(LED_NUM_GREEN);
-
- /* Disable watchdog*/
- WDT_Disable( WDT ) ;
-
- /* Initialize Atr buffer */
- memset( pAtr, 0, sizeof( pAtr ) ) ;
-
- printf( "-- USART ISO7816 Example %s --\n\r", SOFTPACK_VERSION ) ;
- printf( "-- %s\n\r", BOARD_NAME ) ;
- printf( "-- Compiled: %s %s --\n\r", __DATE__, __TIME__ ) ;
-
- /* Configure IT on Smart Card */
- ConfigureCardDetection() ;
-
- /* Configure ISO7816 driver */
- PIO_Configure( pinsISO7816, PIO_LISTSIZE( pinsISO7816 ) ) ;
-
-// FIXME: RST seems to be allways low here
- printf("******* Reset State1 (1 if the Pin RstMC is high): 0x%X\n\r", ISO7816_StatusReset());
-
- ISO7816_Init( pinIso7816RstMC ) ;
-
- printf("******* Reset State2 (1 if the Pin RstMC is high): 0x%X\n\r", ISO7816_StatusReset());
-
- /* Read ATR */
- ISO7816_warm_reset() ;
-
- ISO7816_Datablock_ATR( pAtr, &ucSize ) ;
- printf("******* Reset State3 (1 if the Pin RstMC is high): 0x%X\n\r", ISO7816_StatusReset());
-
- /* Decode ATR */
- ISO7816_Decode_ATR( pAtr ) ;
-
-// FIXME: RST seems to be allways high
- printf("******* Reset State4 (1 if the Pin RstMC is high): 0x%X\n\r", ISO7816_StatusReset());
-
- /* Allow user to send some commands */
- SendReceiveCommands() ;
-
- return 0 ;
-}
-
diff --git a/sam3s_example/mains/phone_test.c b/sam3s_example/mains/phone_test.c
deleted file mode 100644
index 2a88dbef..00000000
--- a/sam3s_example/mains/phone_test.c
+++ /dev/null
@@ -1,387 +0,0 @@
-/* ----------------------------------------------------------------------------
- * ATMEL Microcontroller Software Support
- * ----------------------------------------------------------------------------
- * 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:
- *
- * - 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 "board.h"
-
-#include
-
-/*------------------------------------------------------------------------------
- * Internal definitions
- *------------------------------------------------------------------------------*/
-
-/** Maximum ucSize in bytes of the smartcard answer to a command.*/
-#define MAX_ANSWER_SIZE 10
-
-/** Maximum ATR ucSize in bytes.*/
-#define MAX_ATR_SIZE 55
-
-/** USB states */
-/// Use for power management
-#define STATE_IDLE 0
-/// The USB device is in suspend state
-#define STATE_SUSPEND 4
-/// The USB device is in resume state
-#define STATE_RESUME 5
-
-/*------------------------------------------------------------------------------
- * Internal variables
- *------------------------------------------------------------------------------*/
-/** USB state: suspend, resume, idle */
-unsigned char USBState = STATE_IDLE;
-
-/** ISO7816 pins */
-static const Pin pinsISO7816_PHONE[] = {PINS_ISO7816_PHONE};
-/** ISO7816 RST pin */
-static const Pin pinIso7816RstMC = PIN_ISO7816_RST_PHONE;
-static uint8_t sim_inserted = 0;
-
-static const Pin pPwr[] = {
- /* Enable power converter 4.5-6V to 3.3V; low: off */
- {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT},
-
- /* Enable second power converter: VCC_PHONE to VCC_SIM; high: off */
- {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
-};
-
-// SuperSIM ATR: 3B 9A 94 00 92 02 75 93 11 00 01 02 02 19
-static const uint8_t ATR[] = {0x3B, 0x9A, 0x94, 0x00, 0x92, 0x02, 0x75, 0x93, 0x11, 0x00, 0x01, 0x02, 0x02, 0x19};
-#define NONE 0
-#define SEND_ATR 1
-#define AFTER_ATR 2
-static uint8_t phone_state = NONE;
-
-
-#define ISO7816_PHONE_RST {PIO_PA24, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP | PIO_DEBOUNCE | PIO_DEGLITCH | PIO_IT_EDGE }
-static const Pin pinPhoneRST = ISO7816_PHONE_RST;
-//#define ISO7816_PHONE_CLK {PIO_PA23A_SCK1, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP | PIO_DEBOUNCE | PIO_DEGLITCH | PIO_IT_EDGE }
-//static const Pin pinPhoneClk = ISO7816_PHONE_CLK;
-
-/* ===================================================*/
-/* Taken from iso7816_4.c */
-/* ===================================================*/
-/** Flip flop for send and receive char */
-#define USART_SEND 0
-#define USART_RCV 1
-/*-----------------------------------------------------------------------------
- * Internal variables
- *-----------------------------------------------------------------------------*/
-/** Variable for state of send and receive froom USART */
-static uint8_t StateUsartGlobal = USART_RCV;
-/** Pin reset master card */
-static Pin st_pinIso7816RstMC;
-
-static uint32_t char_stat = 0;
-static char rcvdChar = 0;
-
-/*-----------------------------------------------------------------------------
- * Interrupt routines
- *-----------------------------------------------------------------------------*/
-/*
- * char_stat is zero if no error occured.
- * Otherwise it is filled with the content of the status register.
- */
-void USART1_IrqHandler( void )
-{
- uint32_t stat;
- char_stat = 0;
- // Rcv buf full
-/* if((stat & US_CSR_RXBUFF) == US_CSR_RXBUFF) {
- TRACE_DEBUG("Rcv buf full");
- USART_DisableIt(USART1, US_IDR_RXBUFF);
- }
-*/
- uint32_t csr = USART_PHONE->US_CSR;
-
-// printf(".\n\r");
-
- if (csr & US_CSR_TXRDY) {
- /* transmit buffer empty, nothing to transmit */
- }
- if (csr & US_CSR_RXRDY) {
- stat = (csr&(US_CSR_OVRE|US_CSR_FRAME|
- US_CSR_PARE|US_CSR_TIMEOUT|US_CSR_NACK|
- (1<<10)));
-
- if (stat == 0 ) {
- /* Get a char */
- rcvdChar = ((USART_PHONE->US_RHR) & 0xFF);
- } /* else: error occured */
- char_stat = stat;
- }
-}
-
-static void ISR_PhoneRST( const Pin *pPin)
-{
- TRACE_DEBUG("+++++++++ Interrupt!! ISR:0x%x, CSR:0x%x\n\r", pinPhoneRST.pio->PIO_ISR, USART1->US_CSR);
- phone_state = SEND_ATR;
- PIO_DisableIt( &pinPhoneRST ) ;
-}
-
-static void Config_PhoneRST_IrqHandler()
-{
- PIO_Configure( &pinPhoneRST, 1);
-// PIO_Configure( &pinPhoneClk, 1);
- PIO_ConfigureIt( &pinPhoneRST, ISR_PhoneRST ) ;
-// PIO_ConfigureIt( &pinPhoneClk, ISR_PhoneRST ) ;
- PIO_EnableIt( &pinPhoneRST ) ;
-// PIO_EnableIt( &pinPhoneClk ) ;
- NVIC_EnableIRQ( PIOA_IRQn );
-}
-
-/**
- * Get a character from ISO7816
- * \param pCharToReceive Pointer for store the received char
- * \return 0: if timeout else status of US_CSR
- */
-static uint32_t ISO7816_GetChar( uint8_t *pCharToReceive )
-{
- uint32_t status;
- uint32_t timeout=0;
-
- TRACE_DEBUG("--");
-
- if( StateUsartGlobal == USART_SEND ) {
- while((USART_PHONE->US_CSR & US_CSR_TXEMPTY) == 0) {}
- USART_PHONE->US_CR = US_CR_RSTSTA | US_CR_RSTIT | US_CR_RSTNACK;
- StateUsartGlobal = USART_RCV;
- }
-
- /* Wait USART ready for reception */
- while( ((USART_PHONE->US_CSR & US_CSR_RXRDY) == 0) ) {
- if(timeout++ > 12000 * (BOARD_MCK/1000000)) {
- TRACE_DEBUG("TimeOut\n\r");
- return( 0 );
- }
- }
-
- /* At least one complete character has been received and US_RHR has not yet been read. */
-
- /* Get a char */
- *pCharToReceive = ((USART_PHONE->US_RHR) & 0xFF);
-
- status = (USART_PHONE->US_CSR&(US_CSR_OVRE|US_CSR_FRAME|
- US_CSR_PARE|US_CSR_TIMEOUT|US_CSR_NACK|
- (1<<10)));
-
- if (status != 0 ) {
- TRACE_DEBUG("R:0x%X\n\r", status);
- TRACE_DEBUG("R:0x%X\n\r", USART_PHONE->US_CSR);
- TRACE_DEBUG("Nb:0x%X\n\r", USART_PHONE->US_NER );
- USART_PHONE->US_CR = US_CR_RSTSTA;
- }
-
- /* Return status */
- return( status );
-}
-
-/**
- * Send a char to ISO7816
- * \param CharToSend char to be send
- * \return status of US_CSR
- */
-static uint32_t ISO7816_SendChar( uint8_t CharToSend )
-{
- uint32_t status;
-
- TRACE_DEBUG("********** Send char: %c (0x%X)\n\r", CharToSend, CharToSend);
-
- if( StateUsartGlobal == USART_RCV ) {
- USART_PHONE->US_CR = US_CR_RSTSTA | US_CR_RSTIT | US_CR_RSTNACK;
- StateUsartGlobal = USART_SEND;
- }
-
- /* Wait USART ready for transmit */
- while((USART_PHONE->US_CSR & US_CSR_TXRDY) == 0) {}
- /* There is no character in the US_THR */
-
- /* Transmit a char */
- USART_PHONE->US_THR = CharToSend;
-
- status = (USART_PHONE->US_CSR&(US_CSR_OVRE|US_CSR_FRAME|
- US_CSR_PARE|US_CSR_TIMEOUT|US_CSR_NACK|
- (1<<10)));
-
- if (status != 0 ) {
- TRACE_DEBUG("******* status: 0x%X (Overrun: %d, NACK: %d, Timeout: %d, underrun: %d)\n\r",
- status, ((status & US_CSR_OVRE)>> 5), ((status & US_CSR_NACK) >> 13),
- ((status & US_CSR_TIMEOUT) >> 8), ((status & (1 << 10)) >> 10));
-
- TRACE_DEBUG("E (USART CSR reg):0x%X\n\r", USART_PHONE->US_CSR);
- TRACE_DEBUG("Nb (Number of errors):0x%X\n\r", USART_PHONE->US_NER );
- USART_PHONE->US_CR = US_CR_RSTSTA;
- }
-
- /* Return status */
- return( status );
-}
-
-
-/** Initializes a ISO driver
- * \param pPinIso7816RstMC Pin ISO 7816 Rst MC
- */
-void _ISO7816_Init( const Pin pPinIso7816RstMC )
-{
- TRACE_DEBUG("ISO_Init\n\r");
-
- /* Pin ISO7816 initialize */
- st_pinIso7816RstMC = pPinIso7816RstMC;
-
- USART_Configure( USART_PHONE,
- US_MR_USART_MODE_IS07816_T_0
-// Nope, we aren't master:
- // | US_MR_USCLKS_MCK
- | US_MR_USCLKS_SCK
- | US_MR_NBSTOP_1_BIT
- | US_MR_PAR_EVEN
- | US_MR_CHRL_8_BIT
- | US_MR_CLKO /** TODO: This field was set in the original simtrace firmware..why? */
- | (3<<24), /* MAX_ITERATION */
- 1,
- 0);
- /*
- SYNC = 0 (async mode)
- OVER = 0 (oversampling by 8?)
- FIDI = 372 (default val on startup before other value is negotiated)
- USCLKS = 3 (Select SCK as input clock) --> US_MR_USCLKS_SCK
- CD = 1 ? --> US_BRGR_CD(1)
- */
- USART_PHONE->US_FIDI = 372;
-// USART_PHONE->US_IDR = (uint32_t) -1;
- USART_PHONE->US_BRGR = US_BRGR_CD(1);
-// USART_PHONE->US_BRGR = BOARD_MCK / (372*9600);
- USART_PHONE->US_TTGR = 5;
-
- /* Configure USART */
- PMC_EnablePeripheral(ID_USART_PHONE);
-
- USART1->US_IDR = 0xffffffff;
- USART_EnableIt( USART1, US_IER_RXRDY) ;
- /* enable USART1 interrupt */
- NVIC_EnableIRQ( USART1_IRQn ) ;
-
-// USART_PHONE->US_IER = US_IER_RXRDY | US_IER_OVRE | US_IER_FRAME | US_IER_PARE | US_IER_NACK | US_IER_ITER;
-
- USART_SetTransmitterEnabled(USART_PHONE, 1);
- USART_SetReceiverEnabled(USART_PHONE, 1);
-
-}
-
-/*------------------------------------------------------------------------------
- * Main
- *------------------------------------------------------------------------------*/
-
-/**
- * Initializes the DBGU and ISO7816 driver, and starts some tests.
- * \return Unused (ANSI-C compatibility)
- */
-extern int main( void )
-{
- uint8_t pAtr[MAX_ATR_SIZE] ;
- uint8_t ucSize ;
- static uint8_t buff[100];
-
- LED_Configure(LED_NUM_GREEN);
- LED_Set(LED_NUM_GREEN);
-
- /* Disable watchdog*/
- WDT_Disable( WDT ) ;
-
- PIO_InitializeInterrupts(0);
-
- /* Configure ISO7816 driver */
- PIO_Configure( pinsISO7816_PHONE, PIO_LISTSIZE( pinsISO7816_PHONE ) ) ;
- PIO_Configure(pPwr, PIO_LISTSIZE( pPwr ));
-
- Config_PhoneRST_IrqHandler();
-
- _ISO7816_Init(pinIso7816RstMC);
-
-// FIXME: Or do I need to call VBUS_CONFIGURE() here instead, which will call USBD_Connect() later?
-// USBD_Connect();
-// FIXME: USB clock? USB PMC?
-// NVIC_EnableIRQ( UDP_IRQn );
-
-
-
- // USART_EnableIt( USART_PHONE, US_IER_RXRDY) ;
-
- // FIXME: At some point USBD_IrqHandler() should get called and set USBD_STATE_CONFIGURED
- /* while (USBD_GetState() < USBD_STATE_CONFIGURED) {
- int i = 1;
- if ((i%10000) == 0) {
- TRACE_DEBUG("%d: USB State: %x\n\r", i, USBD_GetState());
- }
- i++;
- }
-*/
- printf("***** START \n\r");
- TRACE_DEBUG("%s", "Start while loop\n\r");
- while (1) {
-// printf(".\n\r");
-
- uint8_t j;
-/* for( j=0; j < 100; j++ ) {
- // ISO7816_GetChar(&buff[j++]);
- }
-*/
- // for( j=0; j < 1000; j++ ) {
- /* printf("0x%x ", buff[j++]);
- if ((j % 40)==0) {
- printf("\n\r");
- }
- */
-// }
- //ISO7816_GetChar(&buff[0]);
- //printf("buf: 0x%x\n\r", buff[0]);
-
- uint32_t ret=-1;
-
- if (phone_state == SEND_ATR) {
- printf("*");
- TRACE_DEBUG("Send char %x %x %x ..", ATR[0], ATR[1], ATR[2]);
- for (j=0; j < sizeof(ATR)/sizeof(ATR[0]); j++) {
- ret = ISO7816_SendChar(ATR[j]);
- TRACE_DEBUG("ret: 0x%x\n\r", ret);
- }
- phone_state = AFTER_ATR;
- PIO_EnableIt( &pinPhoneRST ) ;
- } else {
-// printf("Nothing to do\n\r");
- }
- if (rcvdChar != 0) {
- printf("Received _%x_ \n\r", rcvdChar);
- rcvdChar = 0;
- }
- }
- return 0 ;
-}
diff --git a/sam3s_example/mains/sniffer.c b/sam3s_example/mains/sniffer.c
deleted file mode 100644
index 52684931..00000000
--- a/sam3s_example/mains/sniffer.c
+++ /dev/null
@@ -1,194 +0,0 @@
-/* ----------------------------------------------------------------------------
- * ATMEL Microcontroller Software Support
- * ----------------------------------------------------------------------------
- * 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:
- *
- * - 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 "board.h"
-
-#include
-
-/*------------------------------------------------------------------------------
- * Internal definitions
- *------------------------------------------------------------------------------*/
-
-/** Maximum ucSize in bytes of the smartcard answer to a command.*/
-#define MAX_ANSWER_SIZE 10
-
-/** Maximum ATR ucSize in bytes.*/
-#define MAX_ATR_SIZE 55
-
-/* Sniffer configuration */
-#ifdef PIN_SC_SW
-#undef PIN_SC_SW
-#endif
-#define PIN_SC_SW {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
-
-#ifdef PIN_IO_SW
-#undef PIN_IO_SW
-#endif
-#define PIN_IO_SW {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
-
-#define PINS_BUS PIN_SC_SW, PIN_IO_SW
-
-#define PINS_SIM_SNIFF_SIM PIN_PHONE_IO, PIN_PHONE_CLK
-
-/*------------------------------------------------------------------------------
- * Internal variables
- *------------------------------------------------------------------------------*/
-/** ISO7816 pins */
-static const Pin pinsISO7816_sniff[] = {PINS_SIM_SNIFF_SIM};
-static const Pin pins_bus[] = {PINS_BUS};
-static const Pin pPwr[] = {
- /* Enable power converter 4.5-6V to 3.3V; low: off */
- {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT},
-
- /* Enable second power converter: VCC_PHONE to VCC_SIM; high: off */
- {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
-};
-
-uint32_t char_stat = 0;
-uint8_t rcvdChar = 0;
-
-/*-----------------------------------------------------------------------------
- * Interrupt routines
- *-----------------------------------------------------------------------------*/
-/*
- * char_stat is zero if no error occured.
- * Otherwise it is filled with the content of the status register.
- */
-void USART1_IrqHandler( void )
-{
- uint32_t stat;
- char_stat = 0;
- // Rcv buf full
-/* if((stat & US_CSR_RXBUFF) == US_CSR_RXBUFF) {
- TRACE_DEBUG("Rcv buf full");
- USART_DisableIt(USART1, US_IDR_RXBUFF);
- }
-*/
- uint32_t csr = USART_PHONE->US_CSR;
-
- if (csr & US_CSR_TXRDY) {
- /* transmit buffer empty, nothing to transmit */
- }
- if (csr & US_CSR_RXRDY) {
- stat = (csr&(US_CSR_OVRE|US_CSR_FRAME|
- US_CSR_PARE|US_CSR_TIMEOUT|US_CSR_NACK|
- (1<<10)));
-
- if (stat == 0 ) {
- /* Get a char */
- rcvdChar = ((USART_PHONE->US_RHR) & 0xFF);
- } /* else: error occured */
- char_stat = stat;
- }
-}
-
-/** Initializes a ISO driver
- * \param pPinIso7816RstMC Pin ISO 7816 Rst MC
- */
-void _ISO7816_Init( )
-{
- TRACE_DEBUG("ISO_Init\n\r");
-
- USART_Configure( USART_PHONE,
- US_MR_USART_MODE_IS07816_T_0
-// Nope, we aren't master:
- // | US_MR_USCLKS_MCK
- | US_MR_USCLKS_SCK
- | US_MR_NBSTOP_1_BIT
- | US_MR_PAR_EVEN
- | US_MR_CHRL_8_BIT
- | US_MR_CLKO /** TODO: This field was set in the original simtrace firmware..why? */
- | (3<<24), /* MAX_ITERATION */
- 1,
- 0);
- /*
- SYNC = 0 (async mode)
- OVER = 0 (oversampling by 8?)
- FIDI = 372 (default val on startup before other value is negotiated)
- USCLKS = 3 (Select SCK as input clock) --> US_MR_USCLKS_SCK
- CD = 1 ? --> US_BRGR_CD(1)
- */
- USART_PHONE->US_FIDI = 372;
- USART_PHONE->US_BRGR = US_BRGR_CD(1);
-// USART_PHONE->US_BRGR = BOARD_MCK / (372*9600);
- USART_PHONE->US_TTGR = 5;
-
- /* Configure USART */
- PMC_EnablePeripheral(ID_USART_PHONE);
-
- USART1->US_IDR = 0xffffffff;
- USART_EnableIt( USART1, US_IER_RXRDY) ;
- /* enable USART1 interrupt */
- NVIC_EnableIRQ( USART1_IRQn ) ;
-
-// USART_PHONE->US_IER = US_IER_RXRDY | US_IER_OVRE | US_IER_FRAME | US_IER_PARE | US_IER_NACK | US_IER_ITER;
-
- USART_SetReceiverEnabled(USART_PHONE, 1);
-
-}
-
-/*------------------------------------------------------------------------------
- * Main
- *------------------------------------------------------------------------------*/
-
-extern int main( void )
-{
- uint8_t ucSize ;
- static uint8_t buff[100];
-
- LED_Configure(LED_NUM_GREEN);
- LED_Set(LED_NUM_GREEN);
-
- /* Disable watchdog*/
- WDT_Disable( WDT ) ;
-
- PIO_InitializeInterrupts(0);
-
- /* Configure ISO7816 driver */
- PIO_Configure( pinsISO7816_sniff, PIO_LISTSIZE( pinsISO7816_sniff ) ) ;
- PIO_Configure( pins_bus, PIO_LISTSIZE( pins_bus) ) ;
- PIO_Configure(pPwr, PIO_LISTSIZE( pPwr ));
-
- _ISO7816_Init( );
-
- printf("***** START \n\r");
- while (1) {
-// printf(".\n\r");
-
- if (rcvdChar != 0) {
- printf("Received _%x_ \n\r", rcvdChar);
- rcvdChar = 0;
- }
- }
- return 0 ;
-}
diff --git a/sam3s_example/mains/spi.c b/sam3s_example/mains/spi.c
deleted file mode 100644
index 4abaf6bd..00000000
--- a/sam3s_example/mains/spi.c
+++ /dev/null
@@ -1,77 +0,0 @@
-#include "board.h"
-#include "spi.h"
-#include "pio.h"
-#include "pmc.h"
-#include "usart.h"
-
-#define BUFFER_SIZE 20
-
-/** Pins to configure for the application.*/
-const Pin pins[] = { BOARD_PIN_USART_RXD,
- BOARD_PIN_USART_TXD
-// PIN_USART1_SCK,
-// BOARD_PIN_USART_RTS,
-// BOARD_PIN_USART_CTS,
-// PINS_SPI,
-// PIN_SPI_NPCS0_PA11
- };
-
-char Buffer[BUFFER_SIZE] = "Hello World";
-/**
- * \brief Configures USART in synchronous mode,8N1
- * * \param mode 1 for master, 0 for slave
- * */
-static void _ConfigureUsart(uint32_t freq )
-{
- uint32_t mode;
-/* MASTER; mode = US_MR_USART_MODE_NORMAL
- | US_MR_USCLKS_MCK
- | US_MR_CHMODE_NORMAL
- | US_MR_CLKO
- | US_MR_SYNC // FIXME: sync or not sync?
- | US_MR_MSBF
- | US_MR_CHRL_8_BIT
- | US_MR_NBSTOP_1_BIT
- | US_MR_PAR_NO ;
-*/
-
-
-// Slave mode:
- mode = US_MR_USART_MODE_NORMAL
-// | US_MR_USCLKS_SCK // we don't have serial clock, do we?
- | US_MR_CHMODE_NORMAL
-// | US_MR_SYNC
- | US_MR_MSBF
- | US_MR_CHRL_8_BIT
- | US_MR_NBSTOP_1_BIT
- | US_MR_PAR_NO;
-
- /* Enable the peripheral clock in the PMC */
- PMC_EnablePeripheral( BOARD_ID_USART ) ;
-
- /* Configure the USART in the desired mode @USART_SPI_CLK bauds*/
- USART_Configure( BOARD_USART_BASE, mode, freq, BOARD_MCK ) ;
-
- /* enable USART1 interrupt */
-// NVIC_EnableIRQ( USART1_IRQn ) ;
-
- /* Enable receiver & transmitter */
- USART_SetTransmitterEnabled( BOARD_USART_BASE, 1 ) ;
- USART_SetReceiverEnabled( BOARD_USART_BASE, 1 ) ;
-}
-
-int main() {
- /* Configure pins */
- PIO_Configure( pins, PIO_LISTSIZE( pins ) ) ;
-
- _ConfigureUsart( 1000000UL);
-
- USART_WriteBuffer(BOARD_USART_BASE, Buffer, BUFFER_SIZE);
-
-// FIXME: do we need to call USARTEnable?
-
-
-// FIXME: do we need to call USARTDisable?
-
- return 0;
-}
diff --git a/sam3s_example/mains/usart.c b/sam3s_example/mains/usart.c
deleted file mode 100644
index f8df7e0f..00000000
--- a/sam3s_example/mains/usart.c
+++ /dev/null
@@ -1,144 +0,0 @@
-#include "board.h"
-#include "spi.h"
-#include "pio.h"
-#include "pmc.h"
-#include "usart.h"
-
-#define BUFFER_SIZE 20
-
-const Pin statusled = {LED_GREEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
-
-/*
- * Describes the type and attribute of one PIO pin or a group of similar pins.
- * The #type# field can have the following values:
- * - PIO_PERIPH_A
- * - PIO_PERIPH_B
- * - PIO_OUTPUT_0
- * - PIO_OUTPUT_1
- * - PIO_INPUT
- *
- * The #attribute# field is a bitmask that can either be set to PIO_DEFAULt,
- * or combine (using bitwise OR '|') any number of the following constants:
- * - PIO_PULLUP
- * - PIO_DEGLITCH
- * - PIO_DEBOUNCE
- * - PIO_OPENDRAIN
- * - PIO_IT_LOW_LEVEL
- * - PIO_IT_HIGH_LEVEL
- * - PIO_IT_FALL_EDGE
- * - PIO_IT_RISE_EDGE
- */
-#if 0
-typedef struct _Pin
-{
- /* Bitmask indicating which pin(s) to configure. */
- uint32_t mask;
- /* Pointer to the PIO controller which has the pin(s). */
- Pio *pio;
- /* Peripheral ID of the PIO controller which has the pin(s). */
- uint8_t id;
- /* Pin type. */
- uint8_t type;
- /* Pin attribute. */
- uint8_t attribute;
-} Pin ; */
- #endif
-
-
-
-/** Pins to configure for the application.*/
-const Pin pins[] = { BOARD_PIN_USART_RXD,
- BOARD_PIN_USART_TXD
-// PIN_USART1_SCK,
-// BOARD_PIN_USART_RTS,
-// BOARD_PIN_USART_CTS,
-// PINS_SPI,
-// PIN_SPI_NPCS0_PA11
- };
-
-char Buffer[BUFFER_SIZE] = "Hello World";
-/**
- * \brief Configures USART in synchronous mode,8N1
- * * \param mode 1 for master, 0 for slave
- * */
-static void _ConfigureUsart(uint32_t freq )
-{
- uint32_t mode;
-
-/* MASTER; mode = US_MR_USART_MODE_NORMAL
- | US_MR_USCLKS_MCK
- | US_MR_CHMODE_NORMAL
- | US_MR_CLKO
- | US_MR_SYNC // FIXME: sync or not sync?
- | US_MR_MSBF
- | US_MR_CHRL_8_BIT
- | US_MR_NBSTOP_1_BIT
- | US_MR_PAR_NO ;
-*/
-
-// Slave mode:
- mode = US_MR_USART_MODE_NORMAL
- | US_MR_USCLKS_SCK // we don't have serial clock, do we?
- | US_MR_CHMODE_NORMAL
-// | US_MR_SYNC
- | US_MR_MSBF
- | US_MR_CHRL_8_BIT
- | US_MR_NBSTOP_1_BIT
- | US_MR_PAR_NO;
-
- /* Enable the peripheral clock in the PMC */
- PMC_EnablePeripheral( BOARD_ID_USART ) ;
-
- /* Configure the USART in the desired mode @USART_SPI_CLK bauds*/
- USART_Configure( BOARD_USART_BASE, mode, freq, BOARD_MCK ) ;
- UART_Configure(9600, BOARD_MCK);
-
- /* enable USART1 interrupt */
-// NVIC_EnableIRQ( USART1_IRQn ) ;
-
- /* Enable receiver & transmitter */
- USART_SetTransmitterEnabled( BOARD_USART_BASE, 1 ) ;
- USART_SetReceiverEnabled( BOARD_USART_BASE, 1 ) ;
-}
-
-int main() {
- register int i = 0;
- register int state = 0;
- /* Configure pins */
-
-// FIXME: initialize system clock done in lowlevelinit?
-
- PIO_Configure(&statusled, PIO_LISTSIZE(statusled));
- PIO_Clear(&statusled);
-
- PIO_Configure( pins, PIO_LISTSIZE( pins ) ) ;
-
- _ConfigureUsart( 1000000UL);
-
- while(1) {
- USART_WriteBuffer(BOARD_USART_BASE, Buffer, BUFFER_SIZE);
-
- i = i+1;
- if ((i%500000) == 0) {
- switch(state) {
- case 0:
- PIO_Set(&statusled);
- state=1;
- break;
- case 1:
- PIO_Clear(&statusled);
- state = 2;
- break;
- default:
- state = 0;
- }
- }
- }
-
-// FIXME: do we need to call USARTEnable?
-
-
-// FIXME: do we need to call USARTDisable?
-
- return 0;
-}
diff --git a/sam3s_example/mains/usb_enum.c b/sam3s_example/mains/usb_enum.c
deleted file mode 100644
index 5b09ca09..00000000
--- a/sam3s_example/mains/usb_enum.c
+++ /dev/null
@@ -1,358 +0,0 @@
-/* ----------------------------------------------------------------------------
- * ATMEL Microcontroller Software Support
- * ----------------------------------------------------------------------------
- * 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:
- *
- * - 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 "board.h"
-
-/*----------------------------------------------------------------------------
- * Internal variables
- *----------------------------------------------------------------------------*/
-
-/** Standard USB device descriptor for the CDC serial driver */
-const USBDeviceDescriptor deviceDescriptor = {
-
- sizeof(USBDeviceDescriptor),
- USBGenericDescriptor_DEVICE,
- USBDeviceDescriptor_USB2_00,
- 0xff,
-// CDCDeviceDescriptor_CLASS,
- 0xff,
-// CDCDeviceDescriptor_SUBCLASS,
- 0xff,
-// CDCDeviceDescriptor_PROTOCOL,
- BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0),
- ATMEL_VENDOR_ID,
- SIMTRACE_PRODUCT_ID,
- 1, /* Release number */
- 0, /* No string descriptor for manufacturer */
- 1, /* Index of product string descriptor is #1 */
- 0, /* No string descriptor for serial number */
- 2 /* Device has 2 possible configurations */
-};
-
-typedef struct _SIMTraceDriverConfigurationDescriptors {
-
- /** Standard configuration descriptor. */
- USBConfigurationDescriptor configuration;
- /** Data interface descriptor. */
- USBInterfaceDescriptor data;
- /** Data OUT endpoint descriptor. */
- USBEndpointDescriptor dataOut;
- /** Data IN endpoint descriptor. */
- USBEndpointDescriptor dataIn;
-
-} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptor;
-
-const SIMTraceDriverConfigurationDescriptor configurationDescriptorsFS1 = {
- /* Standard configuration descriptor */
- {
- sizeof(USBConfigurationDescriptor),
- USBGenericDescriptor_CONFIGURATION,
- sizeof(SIMTraceDriverConfigurationDescriptor),
- 2, /* There are two interfaces in this configuration */
- 1, /* This is configuration #1 */
- 2, /* Second string descriptor for this configuration */
- USBD_BMATTRIBUTES,
- USBConfigurationDescriptor_POWER(100)
- },
- /* Communication class interface standard descriptor */
- {
- sizeof(USBInterfaceDescriptor),
- USBGenericDescriptor_INTERFACE,
- 0, /* This is interface #0 */
- 0, /* This is alternate setting #0 for this interface */
- 2, /* This interface uses 2 endpoints */
- //CDCCommunicationInterfaceDescriptor_CLASS,
- 0xff,
-// CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
- 0,
-// CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
- 0,
- 1 /* Second in string descriptor for this interface */
- },
- /* Bulk-OUT endpoint standard descriptor */
-#define DATAOUT 1
- {
- sizeof(USBEndpointDescriptor),
- USBGenericDescriptor_ENDPOINT,
- USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
- DATAOUT),
- USBEndpointDescriptor_BULK,
- MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAOUT),
- USBEndpointDescriptor_MAXBULKSIZE_FS),
- 0 /* Must be 0 for full-speed bulk endpoints */
- },
- /* Bulk-IN endpoint descriptor */
-#define DATAIN 2
- {
- sizeof(USBEndpointDescriptor),
- USBGenericDescriptor_ENDPOINT,
- USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
- DATAIN),
- USBEndpointDescriptor_BULK,
- MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAIN),
- USBEndpointDescriptor_MAXBULKSIZE_FS),
- 0 /* Must be 0 for full-speed bulk endpoints */
- }
-};
-
-const SIMTraceDriverConfigurationDescriptor configurationDescriptorsFS2 = {
- /** Second configuration **/
- {
- sizeof(USBConfigurationDescriptor),
- USBGenericDescriptor_CONFIGURATION,
- sizeof(SIMTraceDriverConfigurationDescriptor),
- 2, /* There are two interfaces in this configuration */
- 2, /* This is configuration #2 */
- 3, /* Third string descriptor for this configuration */
- USBD_BMATTRIBUTES,
- USBConfigurationDescriptor_POWER(100)
- },
- /* Communication class interface standard descriptor */
- {
- sizeof(USBInterfaceDescriptor),
- USBGenericDescriptor_INTERFACE,
- 0, /* This is interface #0 */
- 0, /* This is alternate setting #0 for this interface */
- 2, /* This interface uses 2 endpoints */
- //CDCCommunicationInterfaceDescriptor_CLASS,
- 0xff,
-// CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
- 0,
-// CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
- 0,
- 3 /* Third in string descriptor for this interface */
- },
- /* Bulk-OUT endpoint standard descriptor */
- {
- sizeof(USBEndpointDescriptor),
- USBGenericDescriptor_ENDPOINT,
- USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
- DATAOUT),
- USBEndpointDescriptor_BULK,
- MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAOUT),
- USBEndpointDescriptor_MAXBULKSIZE_FS),
- 0 /* Must be 0 for full-speed bulk endpoints */
- },
- /* Bulk-IN endpoint descriptor */
- {
- sizeof(USBEndpointDescriptor),
- USBGenericDescriptor_ENDPOINT,
- USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
- DATAIN),
- USBEndpointDescriptor_BULK,
- MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAIN),
- USBEndpointDescriptor_MAXBULKSIZE_FS),
- 0 /* Must be 0 for full-speed bulk endpoints */
- }
-};
-
-const SIMTraceDriverConfigurationDescriptor *configurationDescriptorsFSarr[] = {
- &configurationDescriptorsFS1,
- &configurationDescriptorsFS2
-};
-
-const unsigned char someString[] = {
- USBStringDescriptor_LENGTH(4),
- USBGenericDescriptor_STRING,
- USBStringDescriptor_UNICODE('S'),
- USBStringDescriptor_UNICODE('O'),
- USBStringDescriptor_UNICODE('M'),
- USBStringDescriptor_UNICODE('E'),
-};
-
-const unsigned char productStringDescriptor[] = {
-
- USBStringDescriptor_LENGTH(13),
- USBGenericDescriptor_STRING,
- USBStringDescriptor_UNICODE('S'),
- USBStringDescriptor_UNICODE('I'),
- USBStringDescriptor_UNICODE('M'),
- USBStringDescriptor_UNICODE('T'),
- USBStringDescriptor_UNICODE('R'),
- USBStringDescriptor_UNICODE('A'),
- USBStringDescriptor_UNICODE('C'),
- USBStringDescriptor_UNICODE('E'),
- USBStringDescriptor_UNICODE('~'),
- USBStringDescriptor_UNICODE('~'),
- USBStringDescriptor_UNICODE('~'),
- USBStringDescriptor_UNICODE('~'),
- USBStringDescriptor_UNICODE('~')
-};
-
-const unsigned char productStringDescriptor2[] = {
-
- USBStringDescriptor_LENGTH(13),
- USBGenericDescriptor_STRING,
- USBStringDescriptor_UNICODE('S'),
- USBStringDescriptor_UNICODE('I'),
- USBStringDescriptor_UNICODE('M'),
- USBStringDescriptor_UNICODE('T'),
- USBStringDescriptor_UNICODE('R'),
- USBStringDescriptor_UNICODE('A'),
- USBStringDescriptor_UNICODE('C'),
- USBStringDescriptor_UNICODE('E'),
- USBStringDescriptor_UNICODE('~'),
- USBStringDescriptor_UNICODE('2'),
- USBStringDescriptor_UNICODE('~'),
- USBStringDescriptor_UNICODE('~'),
- USBStringDescriptor_UNICODE('~')
-};
-
-/** List of string descriptors used by the device */
-const unsigned char *stringDescriptors[] = {
-/* FIXME: Is it true that I can't use the string desc #0,
- * because 0 also stands for "no string desc"?
- * on the other hand, dmesg output:
- * "string descriptor 0 malformed (err = -61), defaulting to 0x0409" */
- 0,
- productStringDescriptor,
- someString,
- productStringDescriptor2,
-};
-
-const USBDDriverDescriptors driverDescriptors = {
-
- &deviceDescriptor,
- (USBConfigurationDescriptor **) &(configurationDescriptorsFSarr), /* full-speed configuration descriptor */
- 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 */
- stringDescriptors,
- 4 /* 4 string descriptors in list */
-};
-
-
-
-/**
- * \brief Configure 48MHz Clock for USB
- */
-static void _ConfigureUsbClock(void)
-{
- /* Enable PLLB for USB */
-// FIXME: are these the dividers I actually need?
-// FIXME: I could just use PLLA, since it has a frequ of 48Mhz anyways?
- PMC->CKGR_PLLBR = CKGR_PLLBR_DIVB(5)
- | CKGR_PLLBR_MULB(0xc) /* MULT+1=0xd*/
- | CKGR_PLLBR_PLLBCOUNT_Msk;
- while((PMC->PMC_SR & PMC_SR_LOCKB) == 0);
- /* USB Clock uses PLLB */
- PMC->PMC_USB = PMC_USB_USBDIV(0) /* /1 (no divider) */
- | PMC_USB_USBS; /* PLLB */
-}
-
-
-void SIMtraceDriver_Initialize( void )
-{
- // Get std USB driver
- USBDDriver *pUsbd = USBD_GetDriver();
-
- TRACE_DEBUG(".");
-
- // Initialize standard USB driver
- USBDDriver_Initialize(pUsbd,
- &driverDescriptors,
-// FIXME: 2 interface settings supported in MITM mode
- 0); // Multiple interface settings not supported
-
- USBD_Init();
- TRACE_DEBUG("%s", "leaving");
-}
-
-/*
-void USBDDriverCallbacks_ConfigurationChanged(unsigned char cfgnum)
-{
- printf("Configuration change requested: %c\n\r", cfgnum);
-}
-
-void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
-{
- printf("RequestHandler called %d\n\r", USBGenericRequest_GetType(request));
-}
-*/
-/*----------------------------------------------------------------------------
- * Main
- *----------------------------------------------------------------------------*/
-
-/**
- * \brief usb_cdc_serial Application entry point.
- *
- * Initializes drivers and start the USB <-> Serial bridge.
- */
-int main(void)
-{
- uint8_t isUsbConnected = 0;
-
- LED_Configure(LED_NUM_GREEN);
- LED_Set(LED_NUM_GREEN);
-
- /* Disable watchdog */
- WDT_Disable( WDT );
-
- PIO_InitializeInterrupts(0);
-
-// NVIC_EnableIRQ(UDP_IRQn);
-
- /* Enable UPLL for USB */
-// _ConfigureUsbClock();
-
- /* CDC serial driver initialization */
-// CDCDSerialDriver_Initialize(&driverDescriptors);
- SIMtraceDriver_Initialize();
-// CCIDDriver_Initialize();
-
- USBD_Connect();
-
- NVIC_EnableIRQ( UDP_IRQn );
-
- printf("**** Start");
-
- while (1) {
- /* Device is not configured */
- if (USBD_GetState() < USBD_STATE_CONFIGURED) {
-
- if (isUsbConnected) {
- isUsbConnected = 0;
-// TC_Stop(TC0, 0);
- }
- }
- else if (isUsbConnected == 0) {
- printf("USB is now configured\n\r");
-
- isUsbConnected = 1;
-// TC_Start(TC0, 0);
- }
- }
-}