Ejemplo n.º 1
0
static int setupHardware( void )
{
	// When using the JTAG debugger the hardware is not always initialised to
	// the correct default state.  This line just ensures that this does not
	// cause all interrupts to be masked at the start.
	AT91C_BASE_AIC->AIC_EOICR = 0;

	// Enable the peripheral clock.
	AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, (1 << AT91C_ID_PIOA) |  //Enable Clock for PIO
												(1 << AT91C_ID_IRQ0) |  //Enable Clock for IRQ0
												(1 << AT91C_ID_PWMC) |	//Enable Clock for the PWM controller
												(1 << AT91C_ID_US0)  |  //USART0
												(1 << AT91C_ID_US1)		//USART1
							  );


	// Enable reset-button
	AT91F_RSTSetMode( AT91C_BASE_RSTC , AT91C_RSTC_URSTEN );

	if (!initUsart()) return 0;
	if (!vInitUSBInterface()) return 0;

	init_serial();

	rtc_init();

	InitLoggerHardware();
	return 1;
 }
Ejemplo n.º 2
0
int main (void)
{
        initUsart ();
        initUsb ();
        initExti ();

        while (1) {
        }
}
Ejemplo n.º 3
0
/** Entry point. This is the first thing which is called after startup code.
  * This never returns. */
int main(void)
{
	initUsart();
	initAdc();
	initLcdAndInput();

	do
	{
		processPacket();
	} while (true);
}
Ejemplo n.º 4
0
int main (void)
{
        initUsart ();
        logf ("Init\r\n");

        /*!< At this stage the microcontroller clock setting is already configured,
         this is done through SystemInit() function which is called from startup
         files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s)
         before to branch to application main. To reconfigure the default setting
         of SystemInit() function, refer to system_stm32f4xx.c file
         */

        /* NVIC Configuration */
        NVIC_Configuration ();
        logf ("NVIC_Configuration\r\n");

        /*------------------------------ SD Init ---------------------------------- */
        if ((Status = SD_Init ()) != SD_OK) {
                logf ("SD_Init failed\r\n");
        }
        else {
                logf ("SD_Init OK\r\n");
        }

        while ((Status == SD_OK) && (uwSDCardOperation != SD_OPERATION_END) && (SD_Detect () == SD_PRESENT)) {
                switch (uwSDCardOperation) {
                        /*-------------------------- SD Single Block Test --------------------- */
                        case (SD_OPERATION_BLOCK):
                        {
                                SD_SingleBlockTest ();
                                uwSDCardOperation = SD_OPERATION_ERASE;
                                break;
                        }
                        /*-------------------------- SD Erase Test ---------------------------- */
                        case (SD_OPERATION_ERASE):
                        {
                                SD_EraseTest ();
                                uwSDCardOperation = SD_OPERATION_MULTI_BLOCK;
                                break;
                        }
                        /*-------------------------- SD Multi Blocks Test --------------------- */
                        case (SD_OPERATION_MULTI_BLOCK):
                        {
                                SD_MultiBlockTest ();
                                uwSDCardOperation = SD_OPERATION_END;
                                break;
                        }
                }
        }

        /* Infinite loop */
        while (1) {
        }
}
Ejemplo n.º 5
0
    int main()
  {
    
    
    RCC_Config();  // to read and write to AFIO_remap AFIO_clock must first be eanble
    NVIC_Config();
    TIM_Config(); 
    GPIO_Config();
    EXTI_Configuration();
    initUsart();
    //initBT();
    
              // Only for debug the clock tree  *********************************************** 
          // Put the clock configuration into RCC_APB2PeriphClockCmd 
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); 
          /* Output clock on MCO pin ---------------------------------------------*/ 
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; 
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
          GPIO_Init(GPIOA, &GPIO_InitStructure); 
          //  RCC_MCOConfig(RCC_MCO_HSE); // Put on MCO pin the: freq. of external crystal 
          RCC_MCOConfig(RCC_MCO_SYSCLK);  // Put on MCO pin the: System clock selected  
          // 
    //RTCInit();
    
    RCC_GetClocksFreq(&RCC_Clocks);   
    
    writeStringUSART2("\033[2J"); //clear usart 2 screen
    writeStringUSART1("\033[2J");  //clear usart 1 screen
    writeStringUSART1("     <<<<- Welcome To Hinkens Cobra Bluetooth ->>>>\n\n\r");


    
    

    while(1)
    {

        if(GPIO_ReadInputDataBit(GPIOB, COBRA_BOARDSWITCH)== false) writeStringUSART1("On Hook\n\r");
        else            //Luren är lyft
        {
            writeStringUSART1("Phone is off hook!\n\r Dial: \n\r");
            acceptCall(); //accept incoming call
            Delay(Delay_10ms);
            //for(counter = 0 ; counter < 10 ; counter++)
            while(TIM_GetITStatus(TIM2, TIM_IT_Update) == RESET) //
            {
                
                dialed_number = 0;
                while(GPIO_ReadInputDataBit(GPIOB, COBRA_DIALING)== true && GPIO_ReadInputDataBit(GPIOB, COBRA_BOARDSWITCH)== true)//Wait for user to start dialing
                {
                  //writeStringUSART1("Timer Counter: %d\r\n",TIM_GetCounter(TIM2));
                  if(state == 1 && dialingFlag == true) //check if timer has run out and user has started a call
                  {
                    writeStringUSART1("time is up dialing number: ");
                    for (int x = 0; x < counter; x++)
                    {
                      //printf("%d", number[x] );
                    }
                    sendPhoneNumber(number, counter);
                    writeStringUSART1("\r\n");
                    dialingFlag = false;
                    state =  0;
                    counter = 0;
                  }
                    
                }
                Delay(Delay_100ms); //Wait for switch to debounce
          
                while(GPIO_ReadInputDataBit(GPIOB, COBRA_DIALING) == false)
                {    
                     dialingFlag = true;
                     state = 0;
                     TIM_SetCounter(TIM2, 0);
                     TIM_Cmd(TIM2, ENABLE); //Start timer
                     
                     //RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
                     Delay(Delay_10ms);
                     Delay(Delay_10ms);
                      //Now count how many times the mechnical switch toggles
                     if(GPIO_ReadInputDataBit(GPIOB, COBRA_PULSE)== false && pulseFlag == 1)
                     {
                       pulseFlag = 0;
                       dialed_number ++;
                     }
                     else if(GPIO_ReadInputDataBit(GPIOB, COBRA_PULSE) == true && pulseFlag == 0)
                     {
                       pulseFlag = 1;
                        //Do notthing just idle..
                     }
                     
                  Delay(Delay_10ms);   

                }
                Delay(Delay_100ms);
                if(dialed_number != 0) // to handle the error of a extra loop after dialed number
                {
                  dialed_number--; //Rotary always has one extra closure that must be taken off
                  number[counter] = dialed_number;
                  counter ++;
                }

                if(GPIO_ReadInputDataBit(GPIOB, COBRA_BOARDSWITCH)== false) //Hunng upp
                {
                  hangUp(); //hang-up command to bluettooh
                  writeStringUSART1("Hung up!\n\r");
                  counter = 0;
                  break;
                }

              
                //printf("%d\n\r", dialed_number);
                    
            }//end for loop
        }
        
        Delay(Delay_100ms);
    
    }//end while(1)

  }//end main()
Ejemplo n.º 6
0
int main (void)
{
        initI2C1 ();
        initUsart ();

#if 0

        /*
         * +----------------+
         * | Initialization |
         * +----------------+
         */

        accelgyro.initialize();
            setClockSource(MPU6050_CLOCK_PLL_XGYRO/*0x01*/);
                /*
                 * Excerpt from domcumentation : Upon power up, the MPU-60X0 clock source defaults to the internal oscillator.
                 * However, it is highly recommended that the device be configured to use one of the gyroscopes. Below is the code
                 * which does it:
                 */
                I2Cdev::writeBits(devAddr, MPU6050_RA_PWR_MGMT_1/*0x6B*/, MPU6050_PWR1_CLKSEL_BIT/*2*/, MPU6050_PWR1_CLKSEL_LENGTH/*3*/, source/*MPU6050_CLOCK_PLL_XGYRO         0x01*/);

            setFullScaleGyroRange(MPU6050_GYRO_FS_250/*0x00*/);
                /*
                 * 0x1b register is used to trigger gyroscope self-test and configure the gyroscopes’ full scale range. Below
                 * we set ful scale to be +/- 250 units (seconds?)
                 */
                I2Cdev::writeBits(devAddr, MPU6050_RA_GYRO_CONFIG/*0x1B*/, MPU6050_GCONFIG_FS_SEL_BIT/*4*/, MPU6050_GCONFIG_FS_SEL_LENGTH/*2*/, range/*0x00*/);

            setFullScaleAccelRange(MPU6050_ACCEL_FS_2/*0x00*/);
                /*
                 * Set accelerometer full scale to be +/- 2g.
                 */
                I2Cdev::writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG/*0x1C*/, MPU6050_ACONFIG_AFS_SEL_BIT/*4*/, MPU6050_ACONFIG_AFS_SEL_LENGTH/*2*/, range/*0*/);

            setSleepEnabled(false); // thanks to Jack Elston for pointing this one out!
                /*
                 * By default MPU6050 is in sleep mode after powering up. Below we are waking it back on. This
                 * is done using the same register as in first line,
                 */
                I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_1/*0x6B*/, MPU6050_PWR1_SLEEP_BIT/*6*/, enabled/*false*/);

        accelgyro.testConnection()
                getDeviceID() == 0x34;
                        /*
                         * This register is used to verify the identity of the device. The contents of WHO_AM_I are
                         * the upper 6 bits of the MPU-60X0’s 7-bit I C address. The Power-On-Reset value of Bit6:Bit1 is 0b110100 == 0x34.
                         */
                        I2Cdev::readBits(devAddr, MPU6050_RA_WHO_AM_I/*0x75*/, MPU6050_WHO_AM_I_BIT/*6*/, MPU6050_WHO_AM_I_LENGTH/*6*/, buffer);
                        return buffer[0];

        /*
         * +----------------+
         * | Main loop      |
         * +----------------+
         */
        int16_t ax, ay, az;
        int16_t gx, gy, gz;

        accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

                /*
                 * In MPU-6000 and MPU-6050 Product Specification Rev 3.3 on pages 36 and 37 we read, that I²C reads and writes
                 * can be performed with single byte or multiple bytes. In single byte mode, we issue (after sending slave
                 * address ofcourse) a register address, and send or receive one byte of data. Multiple byte reads and writes, at the
                 * other hand consist of slave address, regiser address and multiple consecutive bytes od data. Slave puts or gets
                 * first byte from the register with the address we've just sent, and increases this addres by 1 after each byte.
                 *
                 * This is very useful in case of accelerometer and gyroscope because manufacturer has set up the apropriate registers
                 * cnsecutively, so one can read accel, internal temp and gyro data in one read command. Below is the code which does
                 * exactly this:
                 */
                I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H/*0x3B*/, 14, buffer);
                *ax = (((int16_t)buffer[0]) << 8) | buffer[1];
                *ay = (((int16_t)buffer[2]) << 8) | buffer[3];
                *az = (((int16_t)buffer[4]) << 8) | buffer[5];
                *gx = (((int16_t)buffer[8]) << 8) | buffer[9];
                *gy = (((int16_t)buffer[10]) << 8) | buffer[11];
                *gz = (((int16_t)buffer[12]) << 8) | buffer[13];

#endif

        // Configuration:
        I2C_start (I2C1, MPU6050_ADDRESS_AD0_LOW, I2C_Direction_Transmitter); // start a transmission in Master transmitter mode
        I2C_write_slow (I2C1, MPU6050_RA_PWR_MGMT_1); // Register address
        I2C_write (I2C1, MPU6050_CLOCK_PLL_XGYRO); // Register value = 0x01. Which means, that DEVICE_RESET, SLEEP, CYCLE and TEMP_DIS are all 0.
        I2C_stop (I2C1);

        I2C_start (I2C1, MPU6050_ADDRESS_AD0_LOW, I2C_Direction_Transmitter);
        I2C_write (I2C1, MPU6050_RA_GYRO_CONFIG);
        I2C_write (I2C1, MPU6050_GYRO_FS_250); // All bits set to zero.
        I2C_stop (I2C1);

        I2C_start (I2C1, MPU6050_ADDRESS_AD0_LOW, I2C_Direction_Transmitter);
        I2C_write (I2C1, MPU6050_RA_ACCEL_CONFIG);
        I2C_write (I2C1, MPU6050_ACCEL_FS_2); // All bits set to zero.
        I2C_stop (I2C1);

        // Simple test if communication is working

        I2C_start (I2C1, MPU6050_ADDRESS_AD0_LOW, I2C_Direction_Transmitter);
        I2C_write (I2C1, MPU6050_RA_WHO_AM_I);
        I2C_stop (I2C1);
        I2C_start (I2C1, MPU6050_ADDRESS_AD0_LOW, I2C_Direction_Receiver);
        uint8_t whoAmI = I2C_read_nack (I2C1); // read one byte and don't request another byte
        I2C_stop (I2C1);

        if (whoAmI == 0x34) {
                usartSendString (USART1, "Accelerometer has been found!\r\n");
        }
        else {
                usartSendString (USART1, "*NO* Accelerometer has been found!\r\n");
        }

        while (1) {
                I2C_start (I2C1, MPU6050_ADDRESS_AD0_LOW, I2C_Direction_Transmitter);
                I2C_write (I2C1, MPU6050_RA_ACCEL_XOUT_H);
                I2C_stop (I2C1);
                I2C_start (I2C1, MPU6050_ADDRESS_AD0_LOW, I2C_Direction_Receiver);
                uint16_t ax = ((uint16_t)I2C_read_ack (I2C1) << 8) | I2C_read_ack (I2C1);
                uint16_t ay = ((uint16_t)I2C_read_ack (I2C1) << 8) | I2C_read_ack (I2C1);
                uint16_t az = ((uint16_t)I2C_read_ack (I2C1) << 8) | I2C_read_ack (I2C1);
                uint16_t temp = ((uint16_t)I2C_read_ack (I2C1) << 8) | I2C_read_ack (I2C1);
                uint16_t gx = ((uint16_t)I2C_read_ack (I2C1) << 8) | I2C_read_ack (I2C1);
                uint16_t gy = ((uint16_t)I2C_read_ack (I2C1) << 8) | I2C_read_ack (I2C1);
                uint16_t gz = ((uint16_t)I2C_read_ack (I2C1) << 8) | I2C_read_nack (I2C1);
                I2C_stop (I2C1);

                printf ("Accel : (%d, %d, %d), temperature : %d, gyro : (%d, %d, %d)\r\n", ax, ay, az, temp, gx, gy, gz);
        }
}