예제 #1
0
int main(void)
{
    debug_init(SOFTWARE_NAME);

    PIO_InitializeInterrupts(AT91C_AIC_PRIOR_LOWEST);
    char_display_init();
    LED_Configure(0);
    LED_Configure(1);

    if (! BCAN_Init(1000, 0, NULL)) {
        printf("INIT FAIL");
        LED_Set(1);
        return 1;
    }

    printf("INIT OK\n\r");
    LED_Set(0);

    BCAN_InitMailboxRegisters( 0, 2, AT91C_CAN_MIDvA, (0x5AC << 18), AT91C_CAN_MOT_RX, 0x0);

    char_display_number(6);
    while(1) {
        CAN_Packet packet = BCAN_ReadAndClear(0,2);
        if (packet.valid) {
            char_display_number(packet.data_low);
        }
        char_display_tick();
        for (unsigned volatile int i = 0xFF; i > 0; i--) ;
    }

    return 0;
}
예제 #2
0
int main(void)
{
	/// Init DBGU
	TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
	printf("-- %s: blink-interrupt Project with at91lib v%s --\n\r", BOARD_NAME, SOFTPACK_VERSION);
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

	/// Init PIOA & PIOB interrupt
	PIO_InitializeInterrupts(0);

	/// Init LED
	PIO_Configure(&pinLed, 1);
	TRACE_INFO("LED:\n\r");

	/// Configure and enable the interrupt
	PIO_ConfigureIt(&pinButton, (void (*)(const Pin *)) User_InterruptHandler);
	PIO_EnableIt(&pinButton);

	while (1)
	{
		PIO_Set(&pinLed);
		delay(1000);

		PIO_Clear(&pinLed);
		delay(1000);
	}
}
예제 #3
0
//------------------------------------------------------------------------------
/// Initializes drivers and start the USB <-> Serial bridge.
//------------------------------------------------------------------------------
void samserial_init()
{
    //TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
//    printf("-- USB Device CDC Serial Project %s --\n\r", SOFTPACK_VERSION);
//    printf("-- %s\n\r", BOARD_NAME);
//    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
    // If they are present, configure Vbus & Wake-up pins
    PIO_InitializeInterrupts(0);


    CDCDSerialDriver_Initialize();

    // connect if needed
    VBUS_CONFIGURE();
    // Connect pull-up, wait for configuration
    USBD_Connect();
    
    // Driver loop
        while (USBD_GetState() < USBD_STATE_CONFIGURED) {
            if (isSerialConnected)
                isSerialConnected = 0;
        }
        isSerialConnected = 1;
        // Start receiving data on the USB
        CDCDSerialDriver_Read(usbBuffer,DATABUFFERSIZE,(TransferCallback) UsbDataReceived,0);
       
}
예제 #4
0
파일: main.c 프로젝트: emagii/at91sam3s
/**
 *  Initializes the system, connects the USB and waits indefinitely.
 *
 * \callgraph
 */
int main(void)
{
    /* Disable watchdog */
    WDT_Disable( WDT );

    /* Output example information */
    printf( "-- USB Device Core Project %s --\n\r", SOFTPACK_VERSION ) ;
    printf( "-- %s\n\r", BOARD_NAME ) ;
    printf( "-- Compiled: %s %s --\n\r", __DATE__, __TIME__ ) ;

    /* If they are present, configure Vbus & Wake-up pins */
    PIO_InitializeInterrupts(0) ;

    /* Enable UPLL for USB */
    _ConfigureUsbClock();

    /* USB initialization, Disable Pull-up */
    TRACE_INFO("USB initialization\n\r");
    USBDDriver_Initialize(&usbdDriver, &usbdDriverDescriptors, 0);
    USBD_Init();

    /* Wait about 10ms so that host detach the device to re-enumerate
       Device connection */
    TRACE_INFO("Connecting device\n\r");

    /* connect if needed */
    VBus_Configure();
    while (USBD_GetState() < USBD_STATE_CONFIGURED);

    // Infinite loop
    while (1) {
    }
}
예제 #5
0
/**
 *  \brief getting-started Application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
    /* Disable watchdog */
    WDT_Disable();

    /* Output example information */
    printf("-- Getting Started Example %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    /* Configure systick for 1 ms. */
    printf("Configure system tick to get 1ms tick period.\n\r");
    if (SysTick_Config(BOARD_MCK / (1000)))
        printf("-F- Systick configuration error\n\r");

    /* PIO configuration for LEDs and Buttons. */
    PIO_InitializeInterrupts(IRQ_PRIOR_PIO);

    printf("Configure LED PIOs.\n\r");
    ConfigureLeds();

    printf("Configure button debouncing.\n\r");
    ConfigureButtons();
    
    printf("Press USRBP1 to Start/Stop the blue LED D2 blinking.\n\r");
    printf("Press USRBP2 to Start/Stop the green LED D3 blinking.\n\r");

    while (1) ;
}
예제 #6
0
/**
 * \brief usb_massstorage Application entry point.
 *
 * Configures UART,
 * Configures TC0, USB MSD Driver and run it.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main( void )
{
    sSdCard *pSd = 0;
 
    /* Disable watchdog */
    WDT_Disable( WDT ) ;
        
    SCB_EnableICache();
    SCB_EnableDCache();

#if defined LUN_RAMDISK
     /* Enable SDRAM */
    BOARD_ConfigureSdram();
#endif

    TRACE_INFO("-- USB Device Mass Storage Example %s --\n\r", SOFTPACK_VERSION);
    TRACE_INFO("-- %s\n\r", BOARD_NAME);
    TRACE_INFO("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    /* If they are present, configure Vbus & Wake-up pins */
    PIO_InitializeInterrupts(0);

    /* Initialize all USB power (off) */
    _ConfigureUotghs();
    /* Initialize PIO pins */
    _ConfigurePIOs();

    /* Initialize drivers */
    _ConfigureDrivers();

    _MemoriesInitialize(pSd);
    
    /* BOT driver initialization */
    MSDDriver_Initialize(&msdDriverDescriptors, luns, MAX_LUNS);

    /* connect if needed */
    USBD_Connect();
    while (1) {

        /* Mass storage state machine */
        if (USBD_GetState() < USBD_STATE_CONFIGURED){}
        else 
        {
          MSDDriver_StateMachine();
          
          if (msdRefresh)
          {
              msdRefresh = 0;

              if (msdWriteTotal < 50 * 1000)
              {
                  /* Flush Disk Media */
              }
              msdWriteTotal = 0;
          }
        }
    }
}
예제 #7
0
int main(void)
{
    unsigned int switchPressed;

    debug_init(SOFTWARE_NAME);

    PIO_InitializeInterrupts(AT91C_AIC_PRIOR_LOWEST);
    switches_init();
    char_display_init();
    LED_Configure(0);
    LED_Configure(1);

    if (! BCAN_Init(1000, 0, NULL)) {
        printf("INIT FAIL");
        LED_Set(1);
        return 1;
    }

    printf("INIT OK\n\r");
    LED_Set(0);

    BCAN_InitMailboxRegisters( 0, 1, 0x0, (0x5AC << 18), AT91C_CAN_MOT_TX, 0x0);

    while(1) {
        DisplayMenu();

        switchPressed = -1;
        while (switchPressed == -1) {
            if (switches_pressed(0)) {
                TRACE_INFO("Switch 0 is pressed\n\r");
                switchPressed = 0;
            } else if (switches_pressed(1)) {
                TRACE_INFO("Switch 1 is pressed\n\r");
                switchPressed = 1;
            } else if (switches_pressed(2)) {
                TRACE_INFO("Switch 2 is pressed\n\r");
                switchPressed = 2;
            } else if (switches_pressed(3)) {
                TRACE_INFO("Switch 3 is pressed\n\r");
                switchPressed = 3;
            } else {
                //TRACE_INFO("No Switch is pressed\n\r");
            }
            char_display_tick();
            for (volatile unsigned int i = 0xFF; i > 0; i--) ;
        }

        unsigned int result = -1;
        while (result != CAN_STATUS_SUCCESS) {
            result = BCAN_Write(0, 1, 0, switchPressed, 0x1);
        }
        char_display_number(switchPressed);
    }

    return 0;
}
예제 #8
0
파일: main.c 프로젝트: mknapik/avr-MAC
/**
 * @brief Configures the buttons to generate interrupts when pressed.
 */
void ConfigureButtons(void)
{
    // Configure PIO
    PIO_Configure(&pinPB1, 1);
    PIO_Configure(&pinPB2, 1);

    // Initialize interrupts
    PIO_InitializeInterrupts(AT91C_AIC_PRIOR_LOWEST);
    PIO_ConfigureIt(&pinPB1, (void (*)(const Pin *)) ISR_Bp1);
    PIO_ConfigureIt(&pinPB2, (void (*)(const Pin *)) ISR_Bp2);
    PIO_EnableIt(&pinPB1);
    PIO_EnableIt(&pinPB2);
}
예제 #9
0
static void prvCDCInit( void )
{
extern WEAK const USBDDriverDescriptors cdcdSerialDriverDescriptors;

	/* If they are present, configure Vbus & Wake-up pins */
	PIO_InitializeInterrupts( 0 );

	/* CDC serial driver initialization */
	CDCDSerialDriver_Initialize( &cdcdSerialDriverDescriptors );

	/* Configure VBus pins and interrupts, and check for connection. */
	prvConfigureVBus();
}
예제 #10
0
파일: main.c 프로젝트: amsterr/at91work
//------------------------------------------------------------------------------
/// Initializes the CCID driver and runs it.
/// \return Unused (ANSI-C compatibility)
//------------------------------------------------------------------------------
int main( void )
{
    // Initialize traces
    TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
    printf("-- USB Device CCID Project %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    // If they are present, configure Vbus & Wake-up pins
    PIO_InitializeInterrupts(0);

    // Configure IT on Smart Card
    ConfigureCardDetection();

    // Configure ISO7816 driver
    PIO_Configure(pinsISO7816, PIO_LISTSIZE(pinsISO7816));
    PIO_Configure(pinsPower, PIO_LISTSIZE(pinsPower));

    /* power up the card */
    PIO_Set(&pinsPower[0]);

    ISO7816_Init( pinIso7816RstMC );

    // USB audio driver initialization
    CCIDDriver_Initialize();

    // connect if needed
    VBUS_CONFIGURE();
    while (USBD_GetState() < USBD_STATE_CONFIGURED);

    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;
}
예제 #11
0
int
main(void)
{
  /*
   * Initalize hardware.
   */
  PIO_InitializeInterrupts(0);

  usbmain();
  clock_init();
  rtimer_init();
  
  process_init();
  process_start(&etimer_process, NULL);

  ctimer_init();

  NETSTACK_RADIO.init();

  rimeaddr_t addr;
  eeprom_init();

  memset(&addr, 0, sizeof(rimeaddr_t));
  memcpy(&addr.u8, eeprom_getEUI64(), 8);

#if UIP_CONF_IPV6
  memcpy(&uip_lladdr.addr, &addr.u8, 8);
#endif
#if RF212BB
    rf212_set_pan_addr(
        eeprom_getPanid(),
        eeprom_getPanaddr(),
        (uint8_t *)&addr.u8);
#endif

  extern uint16_t mac_dst_pan_id;
  extern uint16_t mac_src_pan_id;
  //set pan_id for frame creation
  mac_dst_pan_id = eeprom_getPanid();
  mac_src_pan_id = mac_dst_pan_id;

  rimeaddr_set_node_addr(&addr); 

  PRINTFD("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);

  /* Initialize stack protocols */
  queuebuf_init();
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

  //netstack_init();
  process_start(&tcpip_process, NULL);
  /*
   * Initialize Contiki and our processes.
   */
  //netstack_init();
  autostart_start(autostart_processes);

  while(1) {
    
    int r;    
    
    do {
      /* Reset watchdog. */
      r = process_run();
    } while(r > 0);
  }
}
예제 #12
0
파일: main.c 프로젝트: NissankaW/Mariokart3
//------------------------------------------------------------------------------
/// Initializes drivers and start the USB <-> Serial bridge.
//------------------------------------------------------------------------------
int main()
{
    TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
    TRACE_INFO("-- USB Device CDC Serial Project %s --\n\r", SOFTPACK_VERSION);
    TRACE_INFO("-- %s\n\r", BOARD_NAME);
    TRACE_INFO("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    // If they are present, configure Vbus & Wake-up pins
    PIO_InitializeInterrupts(0);

    // Configure USART
    PIO_Configure(pins, PIO_LISTSIZE(pins));
    AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_US0;
    AT91C_BASE_US0->US_IDR = 0xFFFFFFFF;
    USART_Configure(AT91C_BASE_US0,
                    USART_MODE_ASYNCHRONOUS,
                    115200,
                    BOARD_MCK);
    USART_SetTransmitterEnabled(AT91C_BASE_US0, 1);
    USART_SetReceiverEnabled(AT91C_BASE_US0, 1);
    AIC_ConfigureIT(AT91C_ID_US0, 0, ISR_Usart0);
    AIC_EnableIT(AT91C_ID_US0);

    // Configure timer 0
    AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_TC0);
    AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
    AT91C_BASE_TC0->TC_IDR = 0xFFFFFFFF;
    AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV5_CLOCK
                             | AT91C_TC_CPCSTOP
                             | AT91C_TC_CPCDIS
                             | AT91C_TC_WAVESEL_UP_AUTO
                             | AT91C_TC_WAVE;
    AT91C_BASE_TC0->TC_RC = 0x00FF;
    AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS;
    AIC_ConfigureIT(AT91C_ID_TC0, 0, ISR_Timer0);
    AIC_EnableIT(AT91C_ID_TC0);

    // BOT driver initialization
    CDCDSerialDriver_Initialize();

    // connect if needed
    VBus_Configure();

    // Driver loop
    while (1) {

        // Device is not configured
        if (USBD_GetState() < USBD_STATE_CONFIGURED) {

            // Connect pull-up, wait for configuration
            USBD_Connect();
            while (USBD_GetState() < USBD_STATE_CONFIGURED);

            // Start receiving data on the USART
            usartCurrentBuffer = 0;
            USART_ReadBuffer(AT91C_BASE_US0, usartBuffers[0], DATABUFFERSIZE);
            USART_ReadBuffer(AT91C_BASE_US0, usartBuffers[1], DATABUFFERSIZE);
            AT91C_BASE_US0->US_IER = AT91C_US_ENDRX
                                     | AT91C_US_FRAME
                                     | AT91C_US_OVER;
            AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;

            // Start receiving data on the USB
            CDCDSerialDriver_Read(usbBuffer,
                                  DATABUFFERSIZE,
                                  (TransferCallback) UsbDataReceived,
                                  0);
        }
        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;
        }
    }
}
예제 #13
0
파일: main.c 프로젝트: JiaoXianjun/osmo-sdr
//------------------------------------------------------------------------------
/// Main function
//------------------------------------------------------------------------------
int main(void)
{
    unsigned char key;
    unsigned char isValid;

    // Configure all pins
    PIO_Configure(pins, PIO_LISTSIZE(pins));

    LED_Configure(0);
    LED_Set(0);
    LED_Configure(1);
    LED_Set(1);

    // Initialize the DBGU
    TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);

    // Switch to Main clock
    AT91C_BASE_PMC->PMC_MCKR = (AT91C_BASE_PMC->PMC_MCKR & ~AT91C_PMC_CSS) | AT91C_PMC_CSS_MAIN_CLK;
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0);

    // Configure PLL to 98.285MHz
    *AT91C_CKGR_PLLR = ((1 << 29) | (171 << AT91C_CKGR_MUL_SHIFT) \
        | (0x0 << AT91C_CKGR_OUT_SHIFT) |(0x3f << AT91C_CKGR_PLLCOUNT_SHIFT) \
        | (21 << AT91C_CKGR_DIV_SHIFT));
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK) == 0);

    // Configure master clock in two operations
    AT91C_BASE_PMC->PMC_MCKR = (( AT91C_PMC_PRES_CLK_2 | AT91C_PMC_CSS_PLLA_CLK) & ~AT91C_PMC_CSS) | AT91C_PMC_CSS_MAIN_CLK;
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0);
    AT91C_BASE_PMC->PMC_MCKR = ( AT91C_PMC_PRES_CLK_2 | AT91C_PMC_CSS_PLLA_CLK);
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0);

    // DBGU reconfiguration
    DBGU_Configure(DBGU_STANDARD, 115200, SSC_MCK);

    // Configure and enable the TWI (required for accessing the DAC)
    *AT91C_PMC_PCER = (1<< AT91C_ID_TWI0); 
    TWI_ConfigureMaster(AT91C_BASE_TWI0, TWI_CLOCK, SSC_MCK);
    TWID_Initialize(&twid, AT91C_BASE_TWI0);

    printf("-- OsmoSDR firmware (" BOARD_NAME ") " GIT_REVISION " --\n\r");
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

	req_ctx_init();
	PIO_InitializeInterrupts(0);

	cmd_state.out = vprintf;
	uart_cmd_reset(&cmd_state);
	uart_cmds_register(cmds, sizeof(cmds)/sizeof(cmds[0]));

	fastsource_init();
	VBus_Configure();

	power_peripherals(1);

	si570_init(&si570, &twid, SI570_I2C_ADDR);
	set_si570_freq(30000000);

	sam3u_e4k_init(&e4k, &twid, E4K_I2C_ADDR);
	e4k.vco.fosc = 30000000;

	osdr_fpga_init(SSC_MCK);
	//osdr_fpga_reg_write(OSDR_FPGA_REG_ADC_TIMING, (1 << 8) | 255);
	//osdr_fpga_reg_write(OSDR_FPGA_REG_PWM1, (1 << 400) | 800);
	osdr_fpga_set_iq_swap(0);

	ssc_init();
	e4k_init(&e4k);
	e4k_init(&e4k);

    // Enter menu loop
    while (1) {

    	if (DBGU_IsRxReady()) {
        	key = DBGU_GetChar();
        	// Process user input
        	if (uart_cmd_char(&cmd_state, key) == 1) {
        		//ssc_stats();
        	}
    	}
    	ssc_dma_start();
    	fastsource_start();
    }
}
예제 #14
0
int main(void)
{
    unsigned char bmButtons = 0;

    TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
    printf("-- USB Device HID Mouse Project %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    // SPP +
    int i;

    button_flag = 0;

    //Enable RESET
    m_pRSTC->RSTC_RCR = 0xA5000008;
    m_pRSTC->RSTC_RMR = 0xA5000001;
    Delay(1000);

    // Init USB device
    //AT91F_USB_Open();

    // Configure the RTT:
    *AT91C_RTTC_RTMR = BUTTON_SAMPLING;

    // Set in PIO mode and Configure in Input
    //AT91F_PIOA_CfgPMC();

    // InitMAM
    InitMMA();

    // InitADC
    ADCInit();

    // UART0 Init
    InitUSART0();

    // Stat led
    s_pPio->PIO_PER   = BIT31;
    // Configure PA31 as output
    s_pPio->PIO_OER   = BIT31;
    // Set PA31 to HIGH
    s_pPio->PIO_SODR  = BIT31;


    // Test flash
    if(TestFlash()) 
    {
      for(i=0; i<20; i++) 
      {
        s_pPio->PIO_CODR  = BIT31; Delay(150000);
        s_pPio->PIO_SODR  = BIT31; Delay(150000);
      }
    }

    // Button
    // Configure P20 as input
    s_pPio->PIO_ODR   = BIT20;
    // Enable
    s_pPio->PIO_PER   = BIT20;

    Delay(1000);

    // CALIBRATE WHEN BUTT IS PRESS
    // while((s_pPio->PIO_PDSR&BIT20)==BIT20);

    Delay(1000);
    // SPP -

    // If they are present, configure Vbus & Wake-up pins
    PIO_InitializeInterrupts(0);

    WAKEUP_CONFIGURE();

    // If there is on board power, switch it off
  #ifdef PIN_USB_POWER_ENB
  { const Pin pinUsbPwr = PIN_USB_POWER_ENB;
    PIO_Configure(&pinUsbPwr, 1);
  }
  #endif

    // Initialize key statuses and configure push buttons
#if defined(at91cap9dk)
    const Pin pinRow0 = PIN_KEYBOARD_ROW0;
    PIO_Configure(&pinRow0, 1);
#endif       
    PIO_Configure(pinsJoystick, PIO_LISTSIZE(pinsJoystick));

    // HID driver initialization
    HIDDMouseDriver_Initialize();

    // connect if needed
    VBUS_CONFIGURE();
    
    // Infinite loop
    while (1) 
    {
       // SPP +
       #define TIMEOUT  100
       static int Timeout = TIMEOUT;
        GetCoordinates();
        base_y = Coordinates[0]/NSAMPLE;
        base_x = Coordinates[1]/NSAMPLE;
        base_z = Coordinates[2]/NSAMPLE;
       // SPP -

        if( USBState == STATE_SUSPEND ) 
        {
            TRACE_DEBUG("suspend  !\n\r");
            USBState = STATE_IDLE;
            LowPowerMode();
        }
        if( USBState == STATE_RESUME ) 
        {
            // Return in normal MODE
            NormalPowerMode();
            USBState = STATE_IDLE;
            TRACE_DEBUG("resume !\n\r");
        }
        if (USBD_GetState() < USBD_STATE_CONFIGURED)
            continue;

        if (!Timeout)
        {
        
            unsigned char status;

            do 
            {
               status = HIDDMouseDriver_ChangePoints(bmButtons, base_x, base_y);
            }
            while (status != USBD_STATUS_SUCCESS);
            Timeout = TIMEOUT;
        }
        else
           Timeout--;
        
    }
}
예제 #15
0
파일: main.c 프로젝트: cxjlante/at91sam3s
/*----------------------------------------------------------------------------*/
extern int main( void )
{
    uint8_t i;

    /* Disable watchdog */
    WDT_Disable( WDT ) ;

    /* Output example information */
    printf( "-- PIO Parallel Capture example %s --\n\r", SOFTPACK_VERSION ) ;
    printf( "-- %s\n\r", BOARD_NAME ) ;
    printf( "-- Compiled: %s %s --\n\r", __DATE__, __TIME__ ) ;

    printf( "Frequency: %d MHz\n\r", BOARD_MCK/1000000 ) ;

    printf( "  Press r to Receive data on PIO Parallel Capture\n\r" ) ;
    printf( "  Press s to Send data on PIO Parallel Capture\n\r" ) ;
    _ucKey = 0 ;
    while( (_ucKey != 'r') && (_ucKey != 's') )
    {
        _ucKey = UART_GetChar() ;
    }
    if( _ucKey == 'r')
    {
        printf("** RECEIVE mode **\n\r");
        PIO_InitializeInterrupts(0);
        /* Clear Recept buffer */
        for(i=0; i<SIZE_BUFF_RECEPT; i++)
        {
            _adwPIO_mes_rx[i]=0;
        }
        /* Init calback */
        /* PIO_PCRHR register is a WORD */
        _PioCapture.dsize = 2;
        _PioCapture.dPDCsize = 16;
        /* A word, 16x, so we wait 64 bytes */
        /* Buffer for received data */
        _PioCapture.pData = _adwPIO_mes_rx;

        printf("  Press y to samples the data when both data enables are active\n\r");
        printf("  Press n to samples the data whatever the data enables are\n\r");
        _ucKey = 0;
        while( (_ucKey != 'y') && (_ucKey != 'n') )
        {
            _ucKey = UART_GetChar();
        }
        if( _ucKey == 'y')
        {
            /* The parallel capture mode samples the data when both data enables are active. */
            _PioCapture.alwaysSampling = 0;
            printf("We receive data when both data enables are active\n\r");
        }
        else
        {
            /* The parallel capture mode samples the data whatever the data enables are.*/
            _PioCapture.alwaysSampling = 1;
            printf("We receive data whatever the data enables are\n\r");
        }
        printf("  Press y to samples all the data\n\r");
        printf("  Press n to samples the data only one time out of two\n\r");
        _ucKey = 0;
        while( (_ucKey != 'y') && (_ucKey != 'n') )
        {
            _ucKey = UART_GetChar();
        }
        if( _ucKey == 'y')
        {
            /* The parallel capture mode samples all the data */
            _PioCapture.halfSampling = 0;
        }
        else
        {
            /* The parallel capture mode samples the data only one time out of two */
            _PioCapture.halfSampling = 1;
            printf("Data with an even index are sampled\n\r");
        }
        /* Only if halfSampling is set, data with an even index are sampled. */
        _PioCapture.modeFirstSample = 0;
        /* No callback for Data Ready */
        _PioCapture.CbkDataReady = NULL;
        /* No callback for Overrun */
        _PioCapture.CbkOverrun = NULL;
        /* Callback for end of reception */
        _PioCapture.CbkEndReception = OnEndOfReceptionTransfer;
        /* Callback for Reception Buffer Full */
        _PioCapture.CbkBuffFull = OnReceptionBufferFull;
        /* Custom parameter not used in this application */
        _PioCapture.pParam = NULL;

        while(1)
        {
            printf("\n\r");
            if( _PioCapture.alwaysSampling == 0 )
            {
                printf("Data enables are active");
            }
            else
            {
                printf("Whatever the data enables are");
            }
            if( _PioCapture.halfSampling == 0 )
            {
                printf(", sample all the data\n\r");
            }
            else
            {
                printf(" only one time out of two, with an even index\n\r");
            }
            /* Init PIO Parallel Capture */
            ucCbkReceived = 0;
            PIO_CaptureInit( &_PioCapture );
            PIO_CaptureEnable();
            printf("wait\n\r");
            while(ucCbkReceived == 0);
        }
    }
    else if( _ucKey == 's')
    {
        printf("** SEND mode **\n\r");
        printf("This is for debug purpose only !\n\r");
        printf("Frequency of PIO controller clock must be strictly superior to");
        printf(" 2 times the frequency of the clock of the device which");
        printf(" generates the parallel data.\n\r");
        printf("\n\rPlease, connect the second board, and put it in reception mode\n\r");
        PMC_EnablePeripheral( ID_PIOA );

        /* Configure PIO Parrallel Capture pins */
        PIO_Configure(_pinsPIOCD, PIO_LISTSIZE(_pinsPIOCD));

        /* Define PIO used for PIO DC */
        PIOA->PIO_OWER = PIO_OWER_P24 | PIO_OWER_P25 | PIO_OWER_P26 | PIO_OWER_P27
                       | PIO_OWER_P28 | PIO_OWER_P29 | PIO_OWER_P30 | PIO_OWER_P31;

        PIOA->PIO_ODSR = 0x00000000;
        PIO_Clear( &_pinPIODCCLK );

        printf("  Press y to send data without data enables pins\n\r");
        printf("  Press n to send data with data enables pins\n\r");
        _ucKey = 0;
        while( (_ucKey != 'y') && (_ucKey != 'n') )
        {
            _ucKey = UART_GetChar();
        }
        if( _ucKey == 'y')
        {
            while(1)
            {
                printf("\n\rWe send data without data enables pins\n\r");
                /* 0x3020100 0x7060504 0xB0A0908 0xF0E0D0C 0x13121110
                 * 0x17161514 0x1B1A1918 0x1F1E1D1C 0x23222120 0x27262524
                 * 0x2B2A2928 0x2F2E2D2C 0x33323130 0x37363534 0x3B3A3938
                 * 0x3F3E3D3C */
                for( i=0; i<64; i++)
                {
                    /* Set Data */
                    PIOA->PIO_ODSR = (i<<24);
                    /* set Clock */
                    PIO_Set( &_pinPIODCCLK );
                    PIOA->PIO_ODSR = (i<<24);
                    /* Clear clock */
                    PIO_Clear( &_pinPIODCCLK );
                    /* Clear data */
                    PIOA->PIO_ODSR = 0x00000000;
                }
                printf("  Press a key\n\r");
                while( UART_GetChar() == 0 );
            }
        }
        else
        {
            while(1)
            {
                printf("\n\rWe send data with data enables pins\n\r");
                /* 0x3020100 0x7060504 0xB0A0908 0xF0E0D0C 0x13121110
                 * 0x17161514 0x1B1A1918 0x1F1E1D1C 0x23222120 0x27262524
                 * 0x2B2A2928 0x2F2E2D2C 0x33323130 0x37363534 0x3B3A3938
                 * 0x3F3E3D3C */
                for( i=0; i<64; i++)
                {
                    /* set Enable */
                    PIO_Set( &_pinPIODCEN1 );
                    PIO_Set( &_pinPIODCEN2 );
                    /* Set Data */
                    //PIOA->PIO_ODSR = 0xA5000000;
                    PIOA->PIO_ODSR = (i<<24);
                    /* set Clock */
                    PIO_Set( &_pinPIODCCLK );
                    PIOA->PIO_ODSR = (i<<24);
                    /* Clear clock */
                    PIO_Clear( &_pinPIODCCLK );
                    PIOA->PIO_ODSR = 0x00000000;
                    /* Clear Enable */
                    PIO_Clear( &_pinPIODCEN1 );
                    PIO_Clear( &_pinPIODCEN2 );
                }
                printf("  Press a key\n\r");
                while( UART_GetChar() == 0 );
            }
        }
    }

    return 0 ;
}
예제 #16
0
파일: main.c 프로젝트: gstroe/Arm
/**
 * Initializes drivers and start the USB CDCMSD device.
 */
int main(void)
{
	uint8_t usbConnected = 0, serialON = 0;

	/* Disable watchdog */
	WDT_Disable(WDT);

	SCB_EnableICache();
	SCB_EnableDCache();

	printf("-- USB CDCMSD Device Project %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ ,
			COMPILER_NAME);

	/* If they are present, configure Vbus & Wake-up pins */
	PIO_InitializeInterrupts(0);

	/* If there is on board power, switch it off */
	_ConfigureUotghs();

	/* ----- MSD Function Initialize */
	/* Configure memories */
	_MemoriesInitialize();

	/* USB CDCMSD driver initialization */
	CDCMSDDriver_Initialize(&cdcmsddDriverDescriptors, luns, MAX_LUNS);

	/* connect if needed */
	USBD_Connect();

	/* Driver loop */
	while (1) {
		/* Device is not configured */
		if (USBD_GetState() < USBD_STATE_CONFIGURED) {
			if (usbConnected) {
				printf("-I- USB Disconnect/Suspend\n\r");
				usbConnected = 0;

				/* Serial port closed */
				isSerialPortON = 0;
			}
		} else {
			if (usbConnected == 0) {
				printf("-I- USB Connect\n\r");
				usbConnected = 1;
			}

			if (!serialON && isSerialPortON) {
				printf("-I- SerialPort ON\n\r");
				/* Start receiving data on the USART */
				/* Start receiving data on the USB */
				CDCDSerial_Read(usbSerialBuffer0, DATAPACKETSIZE, 0, 0);
				serialON = 1;
			} else if (serialON && !isSerialPortON) {
				printf("-I- SeriaoPort OFF\n\r");
				serialON = 0;
			}

			MSDFunction_StateMachine();

			if (msdRefresh) {
				msdRefresh = 0;

				if (msdWriteTotal < 50 * 1000) {
					/* Flush Disk Media */
				}

				msdWriteTotal = 0;
			}
		}
	}
}
예제 #17
0
파일: main.c 프로젝트: cxjlante/at91sam3s
/**
 * Initializes drivers and start the USB CDCHID device.
 */
int main(void)
{
    uint8_t usbConnected = 0, serialON = 0;

    /* Disable watchdog */
    WDT_Disable( WDT );

    printf("-- USB CDCHID Device Project %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    /* If they are present, configure Vbus & Wake-up pins */
    PIO_InitializeInterrupts(0);

    /* If there is on board power, switch it off */

    /* Enable UPLL for USB */
    ConfigureUsbClock();

    /* Configure timer 0 */
    ConfigureTc0();

    /* ----- CDC Function Initialize */
    /* Configure USART */
    ConfigureUsart();

    /* ----- HID Function Initialize */
    /* Initialize key statuses and configure push buttons */
    PIO_Configure(pinsPushButtons, PIO_LISTSIZE(pinsPushButtons));
    memset(keyStatus, 1, NUM_KEYS);

    /* Configure LEDs */
    LED_Configure(LED_NUMLOCK);


    /* USB CDCHID driver initialization */
    CDCHIDDDriver_Initialize(&cdchiddDriverDescriptors);

    /* connect if needed */
    VBus_Configure();

    /* Driver loop */
    while (1) {

        /* Device is not configured */
        if (USBD_GetState() < USBD_STATE_CONFIGURED) {

            if (usbConnected) {
                printf("-I- USB Disconnect/Suspend\n\r");
                usbConnected = 0;

                /* Serial port closed */
                isSerialPortON = 0;
            }
        }
        else {

            if (usbConnected == 0) {
                printf("-I- USB Connect\n\r");
                usbConnected = 1;
            }

            if (!serialON && isSerialPortON) {
                printf("-I- SerialPort ON\n\r");
                /* Start receiving data on the USART */
                usartCurrentBuffer = 0;
                USART_ReadBuffer(BASE_USART,
                                 usartBuffers[0], DATABUFFERSIZE);
                USART_ReadBuffer(BASE_USART,
                                 usartBuffers[1], DATABUFFERSIZE);
                BASE_USART->US_IER = US_CSR_ENDRX
                                     | US_CSR_FRAME
                                     | US_CSR_OVRE;

                /* Start receiving data on the USB */
                CDCDSerial_Read(usbSerialBuffer0,
                                DATABUFFERSIZE,
                                (TransferCallback) UsbDataReceived,
                                0);
                serialON = 1;
            }
            else if (serialON && !isSerialPortON) {
                printf("-I- SeriaoPort OFF\n\r");
                serialON = 0;
            }

            HIDDKeyboardProcessKeys();
        }
    }
}
예제 #18
0
파일: main.c 프로젝트: gstroe/Arm
/**
 *  \brief usb_iad_hid_aud Application entry point.
 *
 *  Starts the driver and waits for an audio input stream to forward to the DAC.
 */
int main(void)
{
	volatile uint8_t usbConn = 0;
	volatile uint8_t audioOn = 0;
	int32_t  numDiff = 0, prevDiff = 0;
	int8_t   clockAdjust = 0;

	/* Disable watchdog */
	WDT_Disable(WDT);

	SCB_EnableICache();
	SCB_EnableDCache();


	printf("-- USB HID + Audio Device Example %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ ,
			COMPILER_NAME);

	TimeTick_Configure();
	/* Interrupt priority */
	NVIC_SetPriority(USBHS_IRQn, 2);

	/* If they are present, configure Vbus & Wake-up pins */
	PIO_InitializeInterrupts(0);

	/* Initialize all USB power (off) */
	_ConfigureUsbhs();

	/* ----- HID Function Initialize */
#ifdef NO_PUSHBUTTON
	printf("-- : DBG key 1 2 used as buttons\n\r");
	printf("-- : 1st press to push, 2nd press to release\n\r");
#else
	/* Initialize key statuses and configure push buttons */
	PIO_Configure(pinsPushButtons, PIO_LISTSIZE(pinsPushButtons));
#endif
	memset(keyStatus, 1, NUM_KEYS);
	//LED_Configure(LED_NUMLOCK);

	/* Audio STREAM LED */
	LED_Configure(USBD_LEDOTHER);

	/* Configure Audio */
	_ConfigureAudioPlay(AUDDevice_SAMPLERATE, BOARD_MCK);

	/* Configure DMA */
	_ConfigureDma();

	/* USB audio driver initialization */
	HIDAUDDDriver_Initialize(&hidauddDriverDescriptors);

	/* connect if needed */
	USBD_Connect();

	/* Infinite loop */
	while (1) {
		if (USBD_GetState() < USBD_STATE_CONFIGURED) {
			usbConn = 0;
			continue;
		}

		if (audioOn) {
			if (isDacActive == 0) {
				AudioPlayEnable(0);
				printf("audE ");
				isFirstFrame = 1;
				audioOn = 0;
			} else {
				numDiff = numBuffersToSend - DAC_DELAY;

				if (prevDiff != numDiff) {
					prevDiff = numDiff;

					if (numDiff > 1 && clockAdjust != 1) {
						printf("+");
						/* USB too fast or SSC too slow: faster clock */
						clockAdjust = 1;
						_SyncAdjust(1);
					}

					if (numDiff < -1 && clockAdjust != -1) {
						printf("-");
						/* USB too slow or SSC too fast: slower clock */
						clockAdjust = -1;
						_SyncAdjust(-1);
					}

					if (numDiff == 0 && clockAdjust != 0) {
						clockAdjust = 0;
						_SyncAdjust(0);
					}
				}
			}
		} else if (isDacActive) {
			printf("audS ");
			audioOn = 1;
		}

		if (usbConn == 0) {
			usbConn = 1;
			/* Start Reading the incoming audio stream */
			AUDDFunction_Read(buffers[inBufferIndex],
							  AUDDevice_BYTESPERFRAME,
							  (TransferCallback) FrameReceived,
							  0); // No optional argument
		}

		HIDDKeyboardProcessKeys();
	}
}
예제 #19
0
void brick_init(void) {
	// Wait 5ms so everything can power up
	SLEEP_MS(5);
	logging_init();

	logsi("Booting %d\n\r", BRICK_DEVICE_IDENTIFIER);
	logsi("Compiled on %s %s\n\r", __DATE__, __TIME__);
	logsi("Processor family %s\n\r", IS_SAM3() ? "SAM3S" : "SAM4S");

    led_init();
	led_on(LED_STD_BLUE);
#ifdef LED_STD_RED
#if LOGGING_LEVEL == LOGGING_NONE
	led_off(LED_STD_RED);
#else
	led_on(LED_STD_RED);
#endif
#endif
	logsi("LEDs initialized\n\r");

	com_info.uid = uid_get_uid32();

	// Add 0 at end for printing
    char sn[MAX_BASE58_STR_SIZE] = {'\0'};
    uid_to_serial_number(com_info.uid, sn);
    set_serial_number_descriptor(sn, MAX_BASE58_STR_SIZE);
    logsi("Unique ID %s (%lu)\n\r\n\r", sn, com_info.uid);

    wdt_start();
    logsi("Watchdog disabled\n\r");

    mutex_init();
    logsi("Mutexes initialized\n\r");

	// Disable JTAG (Pins are needed for i2c)
#ifdef DISABLE_JTAG_ON_STARTUP
	MATRIX->CCFG_SYSIO |= (CCFG_SYSIO_SYSIO12 |
	                       CCFG_SYSIO_SYSIO4  |
	                       CCFG_SYSIO_SYSIO5  |
	                       CCFG_SYSIO_SYSIO6  |
	                       CCFG_SYSIO_SYSIO7);
	logsi("JTAG disabled\n\r");
#endif

	com_info.current = COM_NONE;
    PIO_InitializeInterrupts(15);

    bricklet_clear_eeproms();
    i2c_eeprom_master_init(TWI_BRICKLET);
    logsi("I2C for Bricklets initialized\n\r");

	usb_detect_configure();

	adc_init();
	adc_enable_temperature_sensor();
#ifndef NO_PERIODIC_ADC_CONVERISION
	adc_start_periodic_conversion();
#endif
    logsi("A/D converter initialized\n\r");

	bricklet_init();
}
예제 #20
0
파일: main.c 프로젝트: gstroe/Arm
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	uint8_t isUsbConnected = 0;
	/* Disable watchdog */
	WDT_Disable(WDT);


	SCB_EnableICache();
	SCB_EnableDCache();

	/* Output example information */
	printf("-- USB Device CDC Serial Project %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ ,
			COMPILER_NAME);

	/* Initialize PIO interrupts */
	PIO_InitializeInterrupts(0);

	/* Interrupt priority */
	NVIC_SetPriority(USBHS_IRQn, 2);

	/* Configure DMA driver */
	_ConfigureDma();

	/* Configure USART */
	_ConfigureUsart();
	_UsartDmaRxSetup();

	/* Initialize OTG clocks */
	_ConfigureUotghs();

	/* CDC serial driver initialization */
	CDCDSerialDriver_Initialize(&cdcdSerialDriverDescriptors);

	/* Help information */
	_DebugHelp();

	// Start USB stack to authorize VBus monitoring
	USBD_Connect();

	/* Driver loop */
	while (1) {
		/* Device is not configured */
		if (USBD_GetState() < USBD_STATE_CONFIGURED) {
			if (isUsbConnected) {
				isUsbConnected = 0;
				isCdcSerialON  = 0;
			}
		} else if (isUsbConnected == 0)
			isUsbConnected = 1;

		/* Serial port ON/OFF */
		if (CDCDSerialDriver_GetControlLineState() & CDCControlLineState_DTR) {
			if (!isCdcSerialON) {
				isCdcSerialON = 1;

				/* Start receiving data on the USART */
				_UsartDmaRx();
				USART_EnableIt(BASE_USART, US_CSR_FRAME | US_CSR_OVRE | US_IER_TIMEOUT);
				USART_EnableRecvTimeOut(BASE_USART, USART_TIMEOUT);
				/* Start receiving data on the USB */
				CDCDSerialDriver_Read(usbBuffer,
									  DATAPACKETSIZE,
									  (TransferCallback) _UsbDataReceived,
									  0);
			}
		} else if (isCdcSerialON)
			isCdcSerialON = 0;

		if (DBG_IsRxReady()) {
			uint8_t key = DBG_GetChar();

			/* ESC: CDC Echo ON/OFF */
			if (key == 27) {
				printf("** CDC Echo %s\n\r",
					   isCdcEchoON ? "OFF" : "ON");
				isCdcEchoON = !isCdcEchoON;
			}
			/* 't': Test CDC writing  */
			else if (key == 't')
				_SendText();
			else {
				printf("Alive\n\r");

				while (CDCDSerialDriver_Write((char *)"Alive\n\r", 8, 0, 0)
					   != USBD_STATUS_SUCCESS);

				_DebugHelp();
			}
		}
	}
}