Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Related Pages  

counter - counter.c


Defines

#define NOE   0
#define RISEE   1
#define FALLE   2
#define ANYE   3
#define ICSTART   0
#define ICSTOP   1
#define ICNOTIFYON   2
#define ICNOTIFYOFF   3
#define NULLCOMMAND   4
#define ANOTE   1
#define AUTOLOAD   2
#define AUTOSTOP   4
#define NOTIFYRESPONSE   BITMASK(ICNOTIFY)
#define COUNTRESPONSE   BITMASK(COUNTER)

Typedefs

typedef void(* CountHander )(int, void *)

Functions

int E12_CountConfig (int fd, int counter, int trigger, int threshold, int flags, Cop_Data *Cop)
int E12_CounterCalcFreq (int counter, Cop_Data *Cop)
int E12_CounterLoad (int fd, int counter, int data, Cop_Data *Cop)
int E12_CounterReadRQ (int fd, int counter)
int E12_CountCommand (int fd, int counter, int command)
int E12_CountCfg_Req (int fd, int counter)
int UpdatetHardwareCounterInfo (int fd, Cop_Data *Cop)

Detailed Description

The counter functions are demostrated through a ncurses form that displays the counters,trigger,flags and zeros. Most of it's fields are dynamically updateable using the arrow keys. This module is designed to showcase the flexiblity of the counters and for testing their functionality. For a good ncurses/forms tutorial try http://en.tldp.org/HOWTO/NCURSES-Programming-HOWTO/

The 37e12 provides 8 general purpose digital lines on port 0 that can be configured as counters. These counters are all 16 bit down counters that can be configured to trigger on any edge. They can be set to do any of the following things when they hit zero:


Define Documentation

#define ANOTE   1
 

enable zero cross notification this will stick a packet into the 37e12's output FIFO whenever a zero cross occurs If the 37e12 goes for long periods without being read and isn't in autostop mode you may want to leave this off so you don't read a huge amount of notifications when you return to reading it. If you are reading periodically however it is recommended that you turn it on, as the parser will use it's notifications to store timestamp information about zero crossings

Definition at line 70 of file counter.h.

#define ANYE   3
 

any edge

Definition at line 42 of file counter.h.

#define AUTOLOAD   2
 

automatically reload from the threshold element when roll-over from zero occurs

Definition at line 73 of file counter.h.

#define AUTOSTOP   4
 

stop counter when zero is reached, notification will still work in this case as it notifys at zero and not at the roll-over-

Definition at line 76 of file counter.h.

#define FALLE   2
 

falling edge

Definition at line 40 of file counter.h.

#define ICNOTIFYOFF   3
 

turn off zero cross notification

Definition at line 56 of file counter.h.

#define ICNOTIFYON   2
 

turn on zero cross notification

Definition at line 54 of file counter.h.

#define ICSTART   0
 

start the addressed counter

Definition at line 50 of file counter.h.

#define ICSTOP   1
 

stop the addressed counter

Definition at line 52 of file counter.h.

#define NOE   0
 

no input capture

Definition at line 36 of file counter.h.

#define NULLCOMMAND   4
 

do nothing, legacy command

Definition at line 58 of file counter.h.

#define RISEE   1
 

rising edge

Definition at line 38 of file counter.h.


Function Documentation

int E12_CountCfg_Req int    fd,
int    counter
 

Request a counters configuration information from the hardware This function requests a counters configuration information from the hardware. Typically it's wrapped by UpdatetHardwareCounterInfo to update all the counters at once and handle the reading/parsing as well.

Parameters:
fd  the 37e12 device being addressed
counter  the counter to request 0-COUNTNUM

Definition at line 592 of file Coprocessor.c.

References countconfig::counter.

int E12_CountCommand int    fd,
int    counter,
int    command
 

Send a command to a configured counter. Once a counter has been configured with E12_CountConfig it can be used toxz

Parameters:
fd  the 37e12 device being addressed
counter  the counter to request 0-COUNTNUM
command  ICSTART, ICSTOP, ICNOTIFYON, or ICNOTIFYOFF

Definition at line 628 of file Coprocessor.c.

int E12_CountConfig int    fd,
int    counter,
int    trigger,
int    threshold,
int    flags,
Cop_Data   Cop
 

This is the first step in using a counter. Before any of the other function will work this must be called. This function is used to configure a general purpose digital line on port 0 as a counter. Configuring a line as a counter will destroy any other configuration currently held on that pin, this will be reflected in the Cop_Data's configuration structures. This command does not start the counter, only configures it. To start a counter E12_CountCommand must be used with the ICSTART command.

Parameters:
fd  the 37e12 device being addressed
counter  the counter, or line number, to configure. 0-COUNTNUM. Only port 0 lines are configurable as counters.
trigger  int value from 0-3 determining what edge the counter counts on NOE, RISEE, FALLE, or ANYE
threshold  the reload value for the counter when the AUTOLOAD flag is on.
flags  a bitmask of 0 or more of the following counter options: ANOTE, AUTOLOAD and AUTOSTOP,
Returns:
0
See also:
countconfig

Definition at line 578 of file Coprocessor.c.

References Cop_Data::counter_config, PWMconfig::duty, countconfig::flags, PWMconfig::frequency, Cop_Data::PWM_config, countconfig::threshold, and countconfig::trigger.

int E12_CounterCalcFreq int    counter,
Cop_Data   Cop
 

Compute an average frequency for a running counter from the timestamps. The frequency is calculated by dividing the starting count by the difference between the zero cross timestamp and the starting timestamp. It is therefore only accurate under the following conditions 1. The notify flag must be set. If it isn't then the 37e12 will not notify the board when zero crossings occur so accurate timestamps will not be available. 2. The counter value most not be modified while it's running. The 37e12 only sends a timer start timestamp when the board first receives the timer start signal, therefore if the counter value is modified during a count the timestamp will be wrong. 3. The frequency must be constant, if not the function can only compute an average frequency, not the current frequency.

The greater the count relative to the frequency the more accurate the calculation.

Definition at line 616 of file Coprocessor.c.

References Cop_Data::counter_data, countdata::laststamp, countdata::laststart, and countdata::timestamp.

int E12_CounterLoad int    fd,
int    counter,
int    data,
Cop_Data   Cop
 

Change the value of a counter. This function can be used to change the current count. It can be used at any time, including while the counter is running. Changing the value of a running counter will not send a new countstart timestamp, only the start counter command does this. Therefore if a counter is changed while it's running E12_CounterCalcFreq will return an invalid value until the next count cycle.

Parameters:
fd  the 37e12 device being addressed
counter  the counter to modify 0-COUNTNUM
data  the new 16 bit value of the counter 0-0xffff
Cop  Cop data structure to shadow the variables into.
Returns:
0

Definition at line 608 of file Coprocessor.c.

int E12_CounterReadRQ int    fd,
int    counter
 

Request an update of a Cop counter element. This sends a request to the 37e12 to return the current status of a counter. This will result in a packet of type COUNTER being returned, or a bitmask of COUNTRESPONSE. The appropriate parsemask will be set for the counter returned.

Parameters:
fd  the 37e12 device being addressed
counter  the counter to request 0-COUNTNUM

Definition at line 601 of file Coprocessor.c.

int UpdatetHardwareCounterInfo int    fd,
Cop_Data   Cop
 

Update the Cop structures count_config structures with data from the hardware.

Parameters:
fd  the 37e12 device being addressed
Cop  Cop data structure to shadow the variables into.
Returns:
0

Definition at line 504 of file Coprocessor.c.

References RG_ParseMask::counter, and Cop_Data::parsemask.


Generated on Thu Jan 8 09:51:01 2004 for PCM-37e12 by doxygen1.2.15