Hi,

I've got a doubt about s526 driver on reading analog input.

I read analog data in this way

sampl_t data;
a4l_insn_t insn_tab = {
.type = A4L_INSN_READ,
.idx_subd = idx_subd,
.chan_desc = CHAN(idx_chan),
.data_size = sizeof(data),
.data = &data};

/* Sends the read instruction to the Analogy layer */
ret = a4l_snd_insn(&dsc, &insn_tab);

on driver side data_size is the number of samples not the nr of byte to 
read,
the driver expect data_size to be the number of samples and data to be a 
vector of samples

uint16_t *data = (uint16_t *)insn->data;

/* convert n samples */
for (n = 0; n < insn->data_size; n++) {
/* trigger conversion */
outw(value, ADDR_REG(REG_ADC));
a4l_info(dev, "s526_ai_rinsn: Wrote 0x%04x to ADC\n", value);
a4l_info(dev, "s526_ai_rinsn: ADC reg=0x%04x\n", inw(ADDR_REG(REG_ADC)));

#define TIMEOUT 100

/* wait for conversion to end */
for (i = 0; i < TIMEOUT; i++) {
status = inw(ADDR_REG(REG_ISR));
if (status & ISR_ADC_DONE) {
outw(ISR_ADC_DONE, ADDR_REG(REG_ISR));
break;
}
}
if (i == TIMEOUT) {
a4l_warn(dev, "s526_ai_rinsn: ADC(0x%04x) timeout\n", 
inw(ADDR_REG(REG_ISR)));
return -ETIMEDOUT;
}

/* read data */
d = inw(ADDR_REG(REG_ADD));
a4l_info(dev, "s526_ai_rinsn: AI[%d]=0x%04x\n", n, (unsigned short)(d & 
0xFFFF));

/* munge data */
data[n] = d ^ 0x8000;
}

TIA

Alessio

-- 

ISTITUTO ITALIANO
DI TECNOLOGIA

Alessio Margan
/Senior Technician/
mail me <mailto:alessio.mar...@iit.it>

Via Morego, 30 16163 Genova 
<http://maps.google.com/maps?f=q&hl=en&geocode=&q=via+morego,+30+genova&sll=37.0625,-95.677068&sspn=85.420533,191.601563&ie=UTF8&ll=44.474913,8.907037&spn=0.004685,0.011652&t=h&z=17&iwloc=addr>

www.iit.it <http://www.iit.it>

*Legal Disclaimer*
This electronic message contains information that is confidential. The 
information is intended for the use of the addressee only. If you are 
not the addressee we would appreciate your notification in this respect. 
Please note that any disclosure, copy, distribution or use of the 
contents of this message is prohibited and may be unlawful. We have 
taken every reasonable precaution to ensure that any kind of attachment 
to this e-mail has been swept for viruses. However, we cannot accept 
liability for any damage sustained as a result of software viruses and 
would advise you to carry out your own virus checks before opening any 
attachment.
*Avvertenza legale*
Questo messaggio Email contiene informazioni confidenziali riservate ai 
soli destinatari. Qualora veniate in possesso di tali informazioni senza 
essere definito come destinatario vi reghiamo di leggere le seguenti 
note. Ogni apertura, copia, distribuzione del contenuto del messaggio e 
dei suoi allegati è proibito e potrebbe violare le presenti leggi. 
Abbiamo attivato ogni possibile e ragionevole precauzione per assicurare 
che gli allegati non contengano virus. Comunque non assumeremo alcuna 
responsabilità per ogni eventuale danno causato da virus software e 
simili in quanto è onere del destinatario verificarne l’assenza in ogni 
allegato attuando propri indipendenti controlli.


_______________________________________________
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core

Reply via email to