예제 #1
0
void read_temp_str(char *temp)
{
	int data=read_sensor_data();
	int data_high=data>>7;
	int data_low=(data>>3 & 0X0F)*625;
	sprintf(temp,"%d.%4d",data_high,data_low);
}
예제 #2
0
/**
 * pthread function to poll the sensors at regular intervals.
 */
static void* odroid_ioctl_poll_sensors(void* args) {
  energymon_odroid_ioctl* state = (energymon_odroid_ioctl*) args;
  uint64_t sum_uw;
  unsigned int i;
  int64_t exec_us;
  int err_save;
  struct timespec ts;
  if (energymon_clock_gettime(&ts)) {
    // must be that CLOCK_MONOTONIC is not supported
    perror("odroid_ioctl_poll_sensors");
    return (void*) NULL;
  }
  energymon_sleep_us(state->poll_delay_us);
  while (state->poll_sensors) {
    // read individual sensors
    for (errno = 0, sum_uw = 0, i = 0; i < SENSOR_COUNT && !errno; i++) {
      if (!read_sensor_data(&state->sensor[i])) {
        sum_uw += state->sensor[i].data.cur_uW;
      }
    }
    err_save = errno;
    exec_us = energymon_gettime_us(&ts);
    if (err_save) {
      errno = err_save;
      perror("odroid_ioctl_poll_sensors: skipping power sensor reading");
    } else {
      state->total_uj += sum_uw * exec_us / 1000000;
    }
    // sleep for the update interval of the sensors (minus most overhead)
    energymon_sleep_us(2 * state->poll_delay_us - exec_us);
    errno = 0;
  }
  return (void*) NULL;
}
예제 #3
0
void read_temp(int *data_high,int *data_low)
{
	int data=read_sensor_data();
	*data_high=data>>7;
	*data_low=(data>>3 & 0X0F)*625;
}
예제 #4
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();
}