Ejemplo n.º 1
0
//*****************************************************************************
//
// Called by the NVIC as a result of GPIO port M interrupt event. For this
// application GPIO port M pin 3 is the interrupt line for the MPU9150
//
// For BoosterPack 2 Interface use Port M pin 7.
//
//*****************************************************************************
void
GPIOPortMIntHandler(void)
{
    unsigned long ulStatus;

    //
    // Get the status flags to see which pin(s) caused the interrupt.
    //
    ulStatus = GPIOIntStatus(GPIO_PORTM_BASE, true);

    //
    // Clear all the pin interrupts that are set
    //
    GPIOIntClear(GPIO_PORTM_BASE, ulStatus);

    //
    // Check if this is an interrupt on the MPU9150 interrupt line.
    //
    // For BoosterPack 2 use Pin 7 instead.
    //
    if(ulStatus & GPIO_PIN_3) {
        //
        // Turn on the LED to show that transaction is starting.
        //
        LEDWrite(CLP_D3 | CLP_D4, CLP_D3);

        //
        // MPU9150 Data is ready for retrieval and processing.
        //
        MPU9150DataRead(&g_sMPU9150Inst, MPU9150AppCallback, &g_sMPU9150Inst);
    }
}
void Timer1IntHandler(void)
{
	TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
	if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0))
	{
		GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0, PIN_LOW);
	}
	else
	{
		GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0, PIN_HIGH);
	}
	switch(sensorTurn)
	{
		case 0:
		{
				TMP006DataRead(&g_sTMP006Inst, TMP006AppCallback, &g_sTMP006Inst);
				TimerDisable(TIMER1_BASE, TIMER_A);
				
				break;
		}
		case 1:
		{
				BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst);
				TimerDisable(TIMER1_BASE, TIMER_A);
				
				break;
		}
		case 2:
		{
				ISL29023DataRead(&g_sISL29023Inst, ISL29023AppCallback, &g_sISL29023Inst);
				TimerDisable(TIMER1_BASE, TIMER_A);
				
				break;
		}
		case 3:
		{						
				SHT21DataRead(&g_sSHT21Inst, SHT21AppCallback, &g_sSHT21Inst);
				TimerDisable(TIMER1_BASE, TIMER_A);
				break;
		}
		case 4:
		{
				MPU9150DataRead(&g_sMPU9150Inst, MPU9150AppCallback, &g_sMPU9150Inst);
				TimerDisable(TIMER1_BASE, TIMER_A);
				
				break;
		}
	}
		
			
}
//*****************************************************************************
//
// Called by the NVIC as a result of GPIO port E interrupt event. For this
// application GPIO port E pin 2 is the interrupt line for the MPU9150
//
//*****************************************************************************
void IntGPIOE(void) {
	unsigned long ulStatus;

	ulStatus = GPIOIntStatus(GPIO_PORTE_BASE, true);

	//
	// Clear all the pin interrupts that are set
	//
	GPIOIntClear(GPIO_PORTE_BASE, ulStatus);

	if (ulStatus & GPIO_PIN_2) {
		//
		// MPU9150 Data is ready for retrieval and processing.
		//
		MPU9150DataRead(&g_sMPU9150Inst, MPU9150AppCallback, &g_sMPU9150Inst);
	}
}
Ejemplo n.º 4
0
//*****************************************************************************
//
// Called by the NVIC as a result of GPIO port S interrupt event. For this
// application GPIO port S pin 2 is the interrupt line for the MPU9150
//
//*****************************************************************************
void
GPIOSIntHandler(void)
{
    uint32_t ui32Status;

    ui32Status = MAP_GPIOIntStatus(GPIO_PORTS_BASE, true);

    //
    // Clear all the pin interrupts that are set
    //
    MAP_GPIOIntClear(GPIO_PORTS_BASE, ui32Status);

    //
    // Check which GPIO caused the interrupt event.
    //
    if(ui32Status & GPIO_PIN_2) {
        //
        // The MPU9150 data ready pin was asserted so start an I2C transfer
        // to go get the latest data from the device.
        //
        MPU9150DataRead(&g_sMPU9150Inst, MotionCallback, &g_sMPU9150Inst);
    }
}
Ejemplo n.º 5
0
void main (void)
{

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
	ROM_SysCtlClockSet (SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
	IntMasterEnable();
	ConfigureUART();
	ConfigureGPRS();

	float fAccel[3];
	tMPU9150 sMPU9150;

	UARTprintf("Point 0\n");
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

	ROM_GPIOPinConfigure(GPIO_PD0_I2C3SCL);
	ROM_GPIOPinConfigure(GPIO_PD1_I2C3SDA);

	//
	// Select the I2C function for these pins.  This function will also
	// configure the GPIO pins pins for I2C operation, setting them to
	// open-drain operation with weak pull-ups.  Consult the data sheet
	// to see which functions are allocated per pin.
	//

	GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
	ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);

	//
	// Initialize the MPU9150.  This code assumes that the I2C master instance
	// has already been initialized.
	//
	I2CMInit(&sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff,
			ROM_SysCtlClockGet());

	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 4);
	UARTprintf("Point 2\n");
	g_bMPU9150Done = false;
	MPU9150Init(&sMPU9150, &sI2CInst, 0x68, MPU9150Callback, 0);
	while(!g_bMPU9150Done)
	{
	}
	//
	// Configure the MPU9150 for +/- 4 g accelerometer range.
	//

	UARTprintf("Point 3\n");
	g_bMPU9150Done = false;
	//  MPU9150ReadModifyWrite(&sMPU9150, MPU9150_O_ACCEL_CONFIG,
	//      ~MPU9150_ACCEL_CONFIG_AFS_SEL_M,
	//      MPU9150_ACCEL_CONFIG_AFS_SEL_16G, MPU9150Callback,
	//      0);

	sMPU9150.pui8Data[0] = MPU9150_CONFIG_DLPF_CFG_94_98;
	sMPU9150.pui8Data[1] = MPU9150_GYRO_CONFIG_FS_SEL_250;
	sMPU9150.pui8Data[2] = (MPU9150_ACCEL_CONFIG_ACCEL_HPF_5HZ |
			MPU9150_ACCEL_CONFIG_AFS_SEL_16G);
	MPU9150Write(&sMPU9150, MPU9150_O_CONFIG, sMPU9150.pui8Data, 3,
			MPU9150Callback, 0);
	//  while(1){}
	while(!g_bMPU9150Done)
	{
	}
	//
	// Loop forever reading data from the MPU9150.  Typically, this process
	// would be done in the background, but for the purposes of this example,
	// it is shown in an infinite loop.
	//
	int count=0;
	int prev_count=-100;
	int is_acc=0;
	float imp[3];
	int j=0;
	for(;j<2;j++) imp[j]=0;
	float curr_avg=0;

	while(1)
	{
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 8);
		//
		// Request another reading from the MPU9150.
		//
		g_bMPU9150Done = false;
		if(!MPU9150DataRead(&sMPU9150, MPU9150Callback, 0)) continue;
		while(!g_bMPU9150Done)
		{
		}
		//
		// Get the new accelerometer, gyroscope, and magnetometer readings.
		//

		float backup[3];
		int l=0;
		if(count!=0)for(;l<3;l++)backup[l]=fAccel[l];
		MPU9150DataAccelGetFloat(&sMPU9150, &fAccel[0], &fAccel[1],
				&fAccel[2]);
		//   MPU9150DataGyroGetFloat(&sMPU9150, &fGyro[0], &fGyro[1], &fGyro[2]);
		//    MPU9150DataMagnetoGetFloat(&sMPU9150, &fMagneto[0], &fMagneto[1],
		//        &fMagneto[2]);
		//    float factor = 0.0011970964;

		// UARTprintf("%d %d %d ",(int)(fMagneto[0]*1000), (int)(fMagneto[1]*1000),(int)(fMagneto[2]*1000));
		//   UARTprintf("Accel %d %d %d \n",(int)(fAccel[0]*1000), (int)(fAccel[1]*1000),(int)(fAccel[2]*1000));
		//   if(count ==0)UARTprintf("\n");
		//   UARTprintf("Gyro %d %d %d \n",(int)(fGyro[0]*1000), (int)(fGyro[1]*1000),(int)(fGyro[2]*1000));
		// int iter;
		//    for(iter=0;iter<6;iter++)
		//    UARTprintf("%f %f %f \n",fAccel[0]*factor, fAccel[1] *factor,fAccel[2]*factor );

		float temp = check_acc(fAccel, backup);

		curr_avg = curr_avg + (temp - curr_avg)/(count +1);

		if(is_acc && count< prev_count+ 400)
		{
			int j=0;
			for(;j<2;j++)imp[j]+=(fAccel[j] - backup[j]);
		}

		if(is_acc && count == prev_count + 400)
		{
			is_acc = 0;
			UARTprintf("Impulse %d %d %d \n",(int)(imp[0]*1000), (int)(imp[1]*1000),(int)(imp[2]*1000));
			int side = 0;
			int sign=0;
			int j=0, max_imp = 0;
			for(;j<2;j++) if(imp[j]*imp[j] > max_imp) {
				max_imp = imp[j]*imp[j];
				side = j;
				sign = imp[j] > 0 ? 1 : -1;
			}
			send_accident_data(side, sign);
			j=0;
			for(;j<2;j++)imp[j]=0;
		}

		if(count!=0 && temp >= thres && count >= prev_count + 400)
		{
			UARTprintf("Accel %d %d %d ",(int)(fAccel[0]*1000), (int)(fAccel[1]*1000),(int)(fAccel[2]*1000));
			prev_count = count;
			is_acc=1;
		}

		count++;
		if(count % 5000 ==0) UARTprintf("Driver stats : %d\r\n", (int)(curr_avg));
		if(count % 50000 == 0)
		{
			int rating = driver_rating(curr_avg);
			//			UARTprintf("Sending data to server\r\n");
			memset(command,0,200);
			strcpy(command,"AT+HTTPPARA=\"URL\",\"embedded-roshanroshan.rhcloud.com/add/Driver_rating=");
			itoa(rating, command+strlen(command));
			strcpy(command+strlen(command), "\"");
			send_AT_command(command,NULL);
			send_AT_command("AT+HTTPACTION=0",NULL);
			count=0;
			curr_avg = 0;
		}
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
		//    SysCtlDelay(5000000);
		//
		// Do something with the new accelerometer, gyroscope, and magnetometer
		// readings.
		//
	}
}