Get samples from device fifo
This commit is contained in:
parent
1f92d206ed
commit
506893ab2b
1 changed files with 33 additions and 24 deletions
55
adxl345.c
55
adxl345.c
|
@ -66,6 +66,10 @@ static int fifo_full(struct Fifo *f) {
|
|||
static void fifo_push(struct Fifo *f, struct Sample *s) {
|
||||
f->content[f->write_idx] = *s;
|
||||
f->write_idx = (f->write_idx + 1) % FIFO_SIZE;
|
||||
// Push read index because we keep only the {FIFO_SIZE} last samples
|
||||
if(f->write_idx == f->read_idx){
|
||||
f->read_idx = (f->read_idx + 1) % FIFO_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
static struct Sample fifo_pop(struct Fifo *f) {
|
||||
|
@ -104,43 +108,48 @@ ssize_t adxl345_read(struct file *file, char __user *buf, size_t count, loff_t *
|
|||
|
||||
irq_handler_t adxl345_int(int irq, struct adxl345_device * d){
|
||||
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t z;
|
||||
struct Sample sample;
|
||||
|
||||
struct Sample sample = {
|
||||
.x = x,
|
||||
.y = y,
|
||||
.z = z
|
||||
};
|
||||
|
||||
char question = 0x00;
|
||||
char response;
|
||||
char question[2];
|
||||
// TODO: changer le format de question
|
||||
question[0] = 0x39;
|
||||
question[1] = 0x00;
|
||||
unsigned char response[6];
|
||||
char ret_code[2];
|
||||
|
||||
int nentries;
|
||||
int nsample;
|
||||
char nentries;
|
||||
char nsample;
|
||||
char i;
|
||||
|
||||
struct miscdevice miscdev = d->miscdev;
|
||||
struct i2c_client *ptrclient = container_of(miscdev.parent,struct i2c_client,dev);
|
||||
struct i2c_client *client;
|
||||
copy_from_user(client,ptrclient,sizeof(ptrclient));
|
||||
|
||||
|
||||
struct device *dev = miscdev.parent;
|
||||
struct i2c_client *client = container_of(dev,struct i2c_client,dev);
|
||||
|
||||
// Get number of entries in Hard FIFO
|
||||
ret_code[0] = i2c_master_send(client,question,1);
|
||||
ret_code[1] = i2c_master_recv(client,response,1);
|
||||
|
||||
if(ret_code[0] < 0 || ret_code[1] < 0){
|
||||
pr_info("Error in reading FIFO STATUS: %i %i\n",ret_code[0], ret_code[1]);
|
||||
}
|
||||
nentries = response >>2;
|
||||
pr_info("HARD FIFO entries: %x\n",nentries);
|
||||
nentries = response[0] & 0x3f;
|
||||
//pr_info("Getting %i sample from the Hard FIFO:\n",nentries);
|
||||
|
||||
fifo_push(&(d->fifo), &sample);
|
||||
for(i=nentries; i>0; i--){
|
||||
// Get entries from Hard FIFO
|
||||
question[0] = 0x32;
|
||||
ret_code[0] = i2c_master_send(client,question,1);
|
||||
ret_code[1] = i2c_master_recv(client,response,6);
|
||||
|
||||
sample.x = (int16_t)(response[1]<<8 | response[0]);
|
||||
sample.y = (int16_t)(response[3]<<8 | response[2]);
|
||||
sample.z = (int16_t)(response[5]<<8 | response[4]);
|
||||
|
||||
//pr_info(" Nouveau Sample: X=%i Y=%i Z=%i\n",sample.x,sample.y,sample.z);
|
||||
|
||||
fifo_push(&(d->fifo), &sample);
|
||||
}
|
||||
nsample = fifo_len(&(d->fifo));
|
||||
pr_info("%i samples in SOFT FIFO\n",nsample);
|
||||
//pr_info("%i samples in Soft FIFO\n",nsample);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue