Exemplo n.º 1
0
void setup_unplug_detect_pin() {
	gpio_register_callback(unplug_detect, PLUG_DETECT_PORT_NUM, PLUG_DETECT_PIN_NUM);
	GPIO_DETECT_FALLING(PLUG_DETECT_PORT_BASE, PLUG_DETECT_PIN_MASK);
	GPIO_POWER_UP_ON_FALLING(PLUG_DETECT_PORT_NUM, PLUG_DETECT_PIN_MASK);
	GPIO_CLEAR_INTERRUPT(PLUG_DETECT_PORT_BASE, PLUG_DETECT_PIN_MASK);
	GPIO_CLEAR_POWER_UP_INTERRUPT(PLUG_DETECT_PORT_NUM, PLUG_DETECT_PIN_MASK);
	GPIO_ENABLE_INTERRUPT(PLUG_DETECT_PORT_BASE, PLUG_DETECT_PIN_MASK);
	GPIO_ENABLE_POWER_UP_INTERRUPT(PLUG_DETECT_PORT_NUM, PLUG_DETECT_PIN_MASK);
}
Exemplo n.º 2
0
void cb(uint8_t port, uint8_t pin){

	GPIO_CLEAR_INTERRUPT(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin));
	if(port==2 && pin==0){
		start_time = vtimer_arch_now();
	}
	else{
		printf("time = %lu\n", vtimer_arch_now()-start_time);
	}
}
Exemplo n.º 3
0
void clear_and_disable_plug_int() {
	GPIO_DISABLE_INTERRUPT(PLUG_DETECT_PORT_BASE, PLUG_DETECT_PIN_MASK);
	GPIO_DISABLE_POWER_UP_INTERRUPT(PLUG_DETECT_PORT_NUM, PLUG_DETECT_PIN_MASK);
	GPIO_CLEAR_POWER_UP_INTERRUPT(PLUG_DETECT_PORT_NUM, PLUG_DETECT_PIN_MASK);
	GPIO_CLEAR_INTERRUPT(PLUG_DETECT_PORT_BASE, PLUG_DETECT_PIN_MASK);
}
Exemplo n.º 4
0
static void spiCScallBack(uint8_t port, uint8_t pin){
    GPIO_CLEAR_INTERRUPT(SPI0_CS_PORT_BASE, SPI0_CS_PIN_MASK);
    spi_cs_int = 1;
    process_poll(&spiProcess);
}
Exemplo n.º 5
0
PROCESS_THREAD(MPU_DATA, ev, data)
{
    static struct etimer sdtimer;

    PROCESS_BEGIN();

    if(isInitialized==0)
    {
// Turn off 3.3-V domain (lcd/sdcard power, output low)
//GPIOPinTypeGPIOOutput(BSP_3V3_EN_BASE, BSP_3V3_EN);
//GPIOPinWrite(BSP_3V3_EN_BASE, BSP_3V3_EN, 0);
        GPIO_SET_OUTPUT(BSP_3V3_EN_BASE, BSP_3V3_EN);
        GPIO_CLR_PIN(BSP_3V3_EN_BASE, BSP_3V3_EN);

// If 3.3-V domain is initially off, make sure it's off >1 ms for a complete
// sd card power cycle

// Approx 10 ms delay
        Delay_ms(10);

// Enable 3.3-V domain (it takes <= 600 us to stabilize)
//GPIOPinWrite(BSP_3V3_EN_BASE, BSP_3V3_EN, BSP_3V3_EN);  // high
        GPIO_SET_PIN(BSP_3V3_EN_BASE, BSP_3V3_EN);
        Delay_ms(100);//100ms

//Disable LCD
//GPIOPinTypeGPIOOutput(GPIO_B_BASE, (5));
//GPIOPinWrite(GPIO_B_BASE, (5), (5));
        GPIO_SET_OUTPUT(GPIO_B_BASE, GPIO_PIN_MASK(5));
        GPIO_SET_PIN(GPIO_B_BASE, GPIO_PIN_MASK(5));
        GPIO_SET_INPUT(GPIO_B_BASE, GPIO_PIN_MASK(3));
        GPIO_CLEAR_INTERRUPT(GPIO_B_BASE, 0xFF);
        GPIO_ENABLE_INTERRUPT(GPIO_B_BASE, 0X08);
        GPIO_DETECT_RISING(GPIO_B_BASE, 0X08);

//Turn on Bluetooth
//GPIO_SET_OUTPUT(GPIO_D_BASE, GPIO_PIN_MASK(3));
//GPIO_SET_PIN(GPIO_D_BASE, GPIO_PIN_MASK(3));
        uart_init(UART_CONF_BASE);

        GPIO_SET_OUTPUT(GPIO_B_BASE, GPIO_PIN_MASK(6));
        GPIO_CLR_PIN(GPIO_B_BASE, GPIO_PIN_MASK(6));

        clock_delay(6000);
        GPIO_SET_PIN(GPIO_B_BASE, GPIO_PIN_MASK(6));
        clock_delay(6000);
        init_i2c();
        clock_delay(6000);
        init_MPU9150 ();

        isInitialized = 1;
    }

    while(1)
    {
//  PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&sdtimer));

//GPIO_SET_PIN(GPIO_C_BASE, lGPIO_PIN_MASK(2));
        etimer_set(&sdtimer, CLOCK_SECOND/400);    //TODO: change from 80 ---> 200

        PROCESS_YIELD();

//GPIO_SET_PIN(GPIO_C_BASE, GPIO_PIN_MASK(1));
#define GPIO_B_BASE             0x400DA000  // GPIO
#define GPIO_PIN_3              0x00000008  // GPIO pin 3

        uint32_t gpio = REG(GPIO_B_BASE + (0x00000000 + (GPIO_PIN_3 << 2))) & GPIO_PIN_3;
        if(gpio)
        {
            read_sensor_data(IMU.Payload);

            PKT_NUM ++;
            IMU_PACKET[0]=IMU.Payload[0];
            IMU_PACKET[1]=IMU.Payload[1];
            IMU_PACKET[2]=IMU.Payload[2];
            IMU_PACKET[3]=IMU.Payload[3];
            IMU_PACKET[4]=IMU.Payload[4];
            IMU_PACKET[5]=IMU.Payload[5];
            IMU_PACKET[6]=IMU.Payload[6];
            IMU_PACKET[7]=IMU.Payload[7];
            IMU_PACKET[8]=IMU.Payload[8];
            IMU_PACKET[9]=IMU.Payload[9];
            IMU_PACKET[10]=IMU.Payload[10];
            IMU_PACKET[11]=IMU.Payload[11];
            IMU_PACKET[12]=IMU.Payload[12];
            IMU_PACKET[13]=IMU.Payload[13];
            IMU_PACKET[14]=IMU.Payload[14];
            IMU_PACKET[15]=IMU.Payload[15];
            IMU_PACKET[16]=IMU.Payload[16];
            IMU_PACKET[17]=IMU.Payload[17];

            if (cycle==1)
            {

                IMU_PACKET[18]=IMU.RSS1;
                IMU_PACKET[19]=IMU.RSS2;
                IMU_PACKET[20]=IMU.RSS3;
                IMU_PACKET[21]=IMU.RSS4;

                if (vat==0)
                {
                    GPIO_SET_OUTPUT(GPIO_C_BASE, GPIO_PIN_MASK(0));
                    GPIO_SET_PIN(GPIO_C_BASE, GPIO_PIN_MASK(0));
                    vat=1;
                }

                else if (vat==1)
                {

                    GPIO_CLR_PIN(GPIO_C_BASE, GPIO_PIN_MASK(0));
                    vat=0;
                }
                cycle=0;
            }

            else if (cycle==0)
            {

                IMU_PACKET[18]=0;
                IMU_PACKET[19]=0;
                IMU_PACKET[20]=0;
                IMU_PACKET[21]=0;
            }

            // Add packet number, so we can detect packet loss.
            IMU_PACKET[22]=PKT_NUM & 0x00ff;
            IMU_PACKET[23]=PKT_NUM >> 8 & 0x00ff ;

            unsigned char outLen = 0;
            byteStuff (&IMU_PACKET[0], PKT_LEN, outPkt, &outLen);
            char i;
            for(i=0; i<outLen; i++)
            {
                uart_write_byte(0,outPkt[i]);
            }
        }

//push_data_to_buffer_imu();
        /*
        if ((stage_imu==1) &&(SD_BUSY==0))
        writedata_imu();
        */
    }
    PROCESS_END();
}