#include <stdlib.h>
#include <stdio.h>
#include <sys/neutrino.h>
#include <stdint.h>
#include <sys/mman.h>
#include <hw/inout.h>
#include <errno.h>
#include <unistd.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include<strings.h>
#include<unix.h>
#include<math.h>
#include <termios.h>
#include "heliap_address.h"
unsigned long supplyout_sys_addr;
unsigned long xgyroout_sys_addr;
unsigned long ygyroout_sys_addr;
unsigned long zgyroout_sys_addr;
unsigned long xacclout_sys_addr;
unsigned long yacclout_sys_addr;
unsigned long zacclout_sys_addr;
unsigned long xmagnout_sys_addr;
unsigned long ymagnout_sys_addr;
unsigned long zmagnout_sys_addr;
unsigned long tempout_sys_addr;
unsigned long auxout_sys_addr;
unsigned long waddress_sys_addr;
unsigned long wdata_sys_addr;
unsigned long wrsel_sys_addr;
unsigned long signal_sys_addr;
unsigned long raddress_sys_addr;
unsigned long rdata_sys_addr;
unsigned long d1reg_sys_addr;
unsigned long d2reg_sys_addr;
unsigned long word1reg_sys_addr;
unsigned long word2reg_sys_addr;
unsigned long word3reg_sys_addr;
unsigned long word4reg_sys_addr;
unsigned long lamp1_sys_addr;
int get_bit_from_data(unsigned short int data, int bits) {
int bit;
bit = (data & (1 << bits)) >> bits;
return bit;
}
unsigned short int get14_from_data(unsigned short int data) {
unsigned short int val;
val = data & 0x3fff;
return val;
}
short int get14_two_complement(unsigned short int data)
{
short int val = 0;
if (0 == get_bit_from_data(data, 13)) {
val = data;
} else if (1 == get_bit_from_data(data, 13)) {
if (0x2000 == data) {
val = 0;
} else {
data = ((~data) & 0x3fff) + 1;
val = -data;
}
}
return val;
}
int config_address() {
ThreadCtl(_NTO_TCTL_IO, 0);
/*ADIS16405 Power supply measurement*/
supplyout_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | SUPPLY_OUT_F);
if (supplyout_sys_addr == EINVAL || supplyout_sys_addr == ENOMEM
|| supplyout_sys_addr == ENXIO) {
return -1;
}
/*ADIS16405 Gyroscope output*/
xgyroout_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | XGYRO_OUT_F);
if (xgyroout_sys_addr == EINVAL || xgyroout_sys_addr == ENOMEM
|| xgyroout_sys_addr == ENXIO) {
return -1;
}
ygyroout_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | YGYRO_OUT_F);
if (ygyroout_sys_addr == EINVAL || ygyroout_sys_addr == ENOMEM
|| ygyroout_sys_addr == ENXIO) {
return -1;
}
zgyroout_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | ZGYRO_OUT_F);
if (zgyroout_sys_addr == EINVAL || zgyroout_sys_addr == ENOMEM
|| zgyroout_sys_addr == ENXIO) {
return -1;
}
/*ADIS16405 Accelerometer output*/
xacclout_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | XACCL_OUT_F);
if (xacclout_sys_addr == EINVAL || xacclout_sys_addr == ENOMEM
|| xacclout_sys_addr == ENXIO) {
return -1;
}
yacclout_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | YACCL_OUT_F);
if (yacclout_sys_addr == EINVAL || yacclout_sys_addr == ENOMEM
|| yacclout_sys_addr == ENXIO) {
return -1;
}
zacclout_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | ZACCL_OUT_F);
if (zacclout_sys_addr == EINVAL || zacclout_sys_addr == ENOMEM
|| zacclout_sys_addr == ENXIO) {
return -1;
}
/*ADIS16405 Magnetometer measurement*/
xmagnout_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | XMAGN_OUT_F);
if (xmagnout_sys_addr == EINVAL || xmagnout_sys_addr == ENOMEM
|| xmagnout_sys_addr == ENXIO) {
return -1;
}
ymagnout_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | YMAGN_OUT_F);
if (ymagnout_sys_addr == EINVAL || ymagnout_sys_addr == ENOMEM
|| ymagnout_sys_addr == ENXIO) {
return -1;
}
zmagnout_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | ZMAGN_OUT_F);
if (zmagnout_sys_addr == EINVAL || zmagnout_sys_addr == ENOMEM
|| zmagnout_sys_addr == ENXIO) {
return -1;
}
/*ADIS16405 System status*/
raddress_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | R_ADDRESS_F);
if (raddress_sys_addr == EINVAL || raddress_sys_addr == ENOMEM
|| raddress_sys_addr == ENXIO) {
return -1;
};
rdata_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | R_DATA_F);
if (rdata_sys_addr == EINVAL || rdata_sys_addr == ENOMEM
|| rdata_sys_addr == ENXIO) {
return -1;
};
waddress_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | W_ADDRESS_F);
if (waddress_sys_addr == EINVAL || waddress_sys_addr == ENOMEM
|| waddress_sys_addr == ENXIO) {
return -1;
};
wdata_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | W_DATA_F);
if (wdata_sys_addr == EINVAL || wdata_sys_addr == ENOMEM || wdata_sys_addr
== ENXIO) {
return -1;
};
wrsel_sys_addr = mmap_device_io(1, IO_BASE_ADDRESS | WR_SEL_F);
if (wrsel_sys_addr == EINVAL || wrsel_sys_addr == ENOMEM || wrsel_sys_addr
== ENXIO) {
return -1;
};
signal_sys_addr = mmap_device_io(1, IO_BASE_ADDRESS | SIGNAL_F);
if (signal_sys_addr == EINVAL || signal_sys_addr == ENOMEM
|| signal_sys_addr == ENXIO) {
return -1;
};
/* MS5534B */
d1reg_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | D1_REG_F);
if (d1reg_sys_addr == EINVAL || d1reg_sys_addr == ENOMEM || d1reg_sys_addr
== ENXIO) {
return -1;
}
d2reg_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | D2_REG_F);
if (d2reg_sys_addr == EINVAL || d2reg_sys_addr == ENOMEM || d2reg_sys_addr
== ENXIO) {
return -1;
}
word1reg_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | WORD1_REG_F);
if (word1reg_sys_addr == EINVAL || word1reg_sys_addr == ENOMEM
|| word1reg_sys_addr == ENXIO) {
return -1;
}
word2reg_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | WORD2_REG_F);
if (word2reg_sys_addr == EINVAL || word2reg_sys_addr == ENOMEM
|| word2reg_sys_addr == ENXIO) {
return -1;
}
word3reg_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | WORD3_REG_F);
if (word3reg_sys_addr == EINVAL || word3reg_sys_addr == ENOMEM
|| word3reg_sys_addr == ENXIO) {
return -1;
}
word4reg_sys_addr = mmap_device_io(2, IO_BASE_ADDRESS | WORD4_REG_F);
if (word4reg_sys_addr == EINVAL || word4reg_sys_addr == ENOMEM
|| word4reg_sys_addr == ENXIO) {
return -1;
}
/*Lamp*/
lamp1_sys_addr = mmap_device_io(1, IO_BASE_ADDRESS | LAMP1_F);
if (lamp1_sys_addr == EINVAL || lamp1_sys_addr == ENOMEM || lamp1_sys_addr
== ENXIO) {
return -1;
}
return 1;
}
//主函数
int main(int argc, char *argv[]) {
config_address();
int val = 0;
double Temp;
double XGYRO_OFF_data;
double YGYRO_OFF_data;
double ZGYRO_OFF_data;
//读寄存器TEMP_OUT
printf("Read a data from TEMP_OUT\n");
out16(waddress_sys_addr, TEMP_OUT);
out8(wrsel_sys_addr, 2);
val = 0;
while (val != 1) {
val = in8(signal_sys_addr);
printf("signal=%d\n", val);
delay(1);
}
printf("Data=0x%x\n", in16(rdata_sys_addr));
printf("Address=%x\n", in16(raddress_sys_addr));
Temp= get14_two_complement(get14_from_data(in16(rdata_sys_addr)))
* TEMP_OUT_SCALE+25;
printf("Temp = %lf\n",Temp);
//读寄存器FLASH_CNT
printf("Read a data from FLASH_CNT\n");
out16(waddress_sys_addr, FLASH_CNT);
out8(wrsel_sys_addr, 2);
val = 0;
while (val != 1) {
val = in8(signal_sys_addr);
printf("signal=%d\n", val);
delay(1);
}
printf("FLASH_CNT_Data=0x%x\n", in16(rdata_sys_addr));
printf("FLASH_CNT_Address=%x\n", in16(raddress_sys_addr));
//读寄存器XGYRO_OFF
printf("Read a data from XGYRO_OFF\n");
out16(waddress_sys_addr, XGYRO_OFF);
out8(wrsel_sys_addr, 2);
val = 0;
while (val != 1) {
val = in8(signal_sys_addr);
printf("signal=%d\n", val);
delay(1);