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) {
|
static void fifo_push(struct Fifo *f, struct Sample *s) {
|
||||||
f->content[f->write_idx] = *s;
|
f->content[f->write_idx] = *s;
|
||||||
f->write_idx = (f->write_idx + 1) % FIFO_SIZE;
|
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) {
|
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){
|
irq_handler_t adxl345_int(int irq, struct adxl345_device * d){
|
||||||
|
|
||||||
int16_t x;
|
struct Sample sample;
|
||||||
int16_t y;
|
|
||||||
int16_t z;
|
|
||||||
|
|
||||||
struct Sample sample = {
|
char question[2];
|
||||||
.x = x,
|
// TODO: changer le format de question
|
||||||
.y = y,
|
question[0] = 0x39;
|
||||||
.z = z
|
question[1] = 0x00;
|
||||||
};
|
unsigned char response[6];
|
||||||
|
|
||||||
char question = 0x00;
|
|
||||||
char response;
|
|
||||||
char ret_code[2];
|
char ret_code[2];
|
||||||
|
|
||||||
int nentries;
|
char nentries;
|
||||||
int nsample;
|
char nsample;
|
||||||
|
char i;
|
||||||
|
|
||||||
struct miscdevice miscdev = d->miscdev;
|
struct miscdevice miscdev = d->miscdev;
|
||||||
struct i2c_client *ptrclient = container_of(miscdev.parent,struct i2c_client,dev);
|
struct device *dev = miscdev.parent;
|
||||||
struct i2c_client *client;
|
struct i2c_client *client = container_of(dev,struct i2c_client,dev);
|
||||||
copy_from_user(client,ptrclient,sizeof(ptrclient));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Get number of entries in Hard FIFO
|
||||||
ret_code[0] = i2c_master_send(client,question,1);
|
ret_code[0] = i2c_master_send(client,question,1);
|
||||||
ret_code[1] = i2c_master_recv(client,response,1);
|
ret_code[1] = i2c_master_recv(client,response,1);
|
||||||
|
|
||||||
if(ret_code[0] < 0 || ret_code[1] < 0){
|
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]);
|
pr_info("Error in reading FIFO STATUS: %i %i\n",ret_code[0], ret_code[1]);
|
||||||
}
|
}
|
||||||
nentries = response >>2;
|
nentries = response[0] & 0x3f;
|
||||||
pr_info("HARD FIFO entries: %x\n",nentries);
|
//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));
|
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;
|
return IRQ_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue