1
0
mirror of https://github.com/elua/elua.git synced 2025-01-08 20:56:17 +08:00
elua/inc/elua_adc.h
James Snyder bd2e819368 ADC Updated
- adc_wait_samples now returns the actual number of samples available at the
  time it returns.  this simplifies a pattern where one would wait on samples
  if blocking and then subsequently check the number of available samples.
- adc.insertsamples(id, table, idx, count) function now available to take
  samples and insert them into a table.  this is slightly slower than
  assignment for single values in a table, but can avoid having to use
  getsamples (returning new tables) for certain situations
  idx: starting index in table where values will be inserted
  count: number of samples to get from channel id
2009-04-22 15:36:50 +00:00

63 lines
2.3 KiB
C

#ifndef __ELUA_ADC_H__
#define __ELUA_ADC_H__
#include "type.h"
#include "platform_conf.h"
typedef struct
{
// Status Bit Flags
volatile u8 op_pending: 1, // Is there a pending conversion?
blocking: 1, // Are we in blocking or non-blocking mode? (0 - blocking, 1 - nonblocking)
freerunning: 1, // If true, we don't stop when we've acquired the requested number of samples
smooth_ready: 1, // Has smoothing filter warmed up (i.e. smoothlen samples collected)
value_fresh: 1; // Whether the value pointed to by value_ptr is fresh
unsigned id;
u8 logsmoothlen;
volatile u16 smoothidx;
volatile u32 smoothsum;
u16 *smoothbuf;
volatile u16 reqsamples;
volatile u16 *value_ptr;
} elua_adc_ch_state;
typedef struct
{
elua_adc_ch_state *ch_state[ NUM_ADC ];
volatile u16 sample_buf[ NUM_ADC ];
volatile u8 clocked: 1,
force_reseq: 1,
skip_cycle: 1,
running: 1; // Whether or not sequence is running
volatile u32 ch_active; // bits represent whether channel should be converted on this device
volatile u32 last_ch_active; // keep copy of old configuration
unsigned timer_id, seq_id; // Timer bound to device, sequencer device id
volatile u8 seq_ctr, seq_len;
} elua_adc_dev_state;
// Channel Management
#define ACTIVATE_CHANNEL( d, id ) ( d->ch_active |= ( ( u32 )1 << ( id ) ) )
#define INACTIVATE_CHANNEL( d, id ) ( d->ch_active &= ~( ( u32 )1 << ( id ) ) )
#define INCR_SEQCTR( d ) ( d->seq_ctr++ )
int adc_setup_channel( unsigned id, u8 logcount );
void adc_update_dev_sequence( unsigned dev_id );
void adc_init_dev_state( unsigned dev_id );
elua_adc_dev_state *adc_get_dev_state( unsigned dev_id );
void adc_smooth_data( unsigned id );
elua_adc_ch_state *adc_get_ch_state( unsigned id );
u16 adc_get_processed_sample( unsigned id );
void adc_init_ch_state( unsigned id );
int adc_update_smoothing( unsigned id, u8 loglen );
void adc_flush_smoothing( unsigned id );
u16 adc_samples_requested( unsigned id );
u16 adc_samples_available( unsigned id );
u16 adc_wait_samples( unsigned id, unsigned samples );
#endif