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

Coprocessor Module


Data Structures

struct  Cop_Data
struct  Cop_DataBlock
struct  countconfig
struct  countdata
struct  PWMconfig
struct  RG_ParseMask
struct  VersionInfo

Defines

#define NEW   1
#define OLD   0
#define TRUE   1
#define FALSE   0
#define RS232BUFSIZE   1000
#define RS422BUFSIZE   1000
#define LCD_QSZ   10
#define COPCODE
#define BITMASK(data)   (1<<data)
#define INTERNAL_ATOD_NUM   16
#define EXTERNAL_ATOD_NUM   8
#define PWMNUM   16
#define COUNTNUM   8
#define ATOD0RESPONSE   (BITMASK(ADBLK0))
#define ATOD1RESPONSE   (BITMASK(ADBLK1))

Typedefs

typedef Cop_DataBlock Cop_DataBlock
typedef VersionInfo VersionInfo
typedef RG_ParseMask RG_ParseMask
typedef PWMconfig PWMconfig
typedef countconfig countconfig
typedef countdata countdata
typedef Cop_Data Cop_Data

Functions

int CopParsePacket (Cop_Data *data)
int CopGetPacket (Cop_Data *data, Cop_DataBlock *block)
int CopPacketMask (Cop_Data *data, Cop_DataBlock *block)
int CopPacketStart (Cop_Data *data, Cop_DataBlock *block)
void CopPackBreak (Cop_Data *data)
Cop_DataCopDeviceCreate (int flags)
int CopDeviceDestroy (Cop_Data *Cop)
__u32 E12_Packet_Route (Cop_Data *Cop, unsigned char *data, int datasize)
__u32 E12_Parse_Until (int fd, Cop_Data *Cop, __u32 bitmask)
int UpdatetHardwareCounterInfo (int fd, Cop_Data *Cop)
int UpdatetHardwarePWMInfo (int fd, Cop_Data *Cop)
int e12packetout (int fd, __u8 device, __u8 maskcnt, void *data)
int E12_PWMControl (int fd, int pwm, int frequency, int duty, Cop_Data *Cop)
int E12_PWMCfg_Req (int fd, int pwm)
int E12_CountConfig (int fd, int counter, int trigger, int threshold, int flags, Cop_Data *Cop)
int E12_CountCfg_Req (int fd, int counter)
int E12_CounterReadRQ (int fd, int counter)
int E12_CounterLoad (int fd, int counter, int data, Cop_Data *Cop)
int E12_CounterCalcFreq (int counter, Cop_Data *Cop)
int E12_CountCommand (int fd, int counter, int command)
int E12_Digitalout (int fd, __u8 data, int port)
int E12_Digital_Req (int fd)
int E12_Digital_Cfg (int fd, __u8 mask, int port)
int E12_Internal_AtoD_Req (int fd, int channel)
int E12_External_AtoD_Req (int fd, int channel)
int E12_AtoD_Req (int fd, int channel)
int E12_DtoA_Write (int fd, int channel, int data)
int E12_Serial_Write (int fd, int port, int numchars, char *buffer)
int E12_Serial_Config (int fd, int port, int baud, int mode)
int E12_VersionReq (int fd)

Detailed Description

This module contains wrapper functions for interpreting the protocol of the 37e12, it essentially defines the high level API for communicating with the device. Because all communication with the 37e12 comes through one IO channel, all data, incoming and outcoming, is wrapped in a proprietary packet structure. This data can be commands sent to the 37e12, requests for data from the 37e12, responses to requests, and in some cases unsolicited asychronous data. When a user application is expecting data from a 37e12 device it calls read to read back a chunk of raw data. Typically this is done by setting number of bytes in the read function to some high value. The driver will cut it off and return the data when it has nothing left to send(or when the number is reached).

This raw data is then interpreted by passing it into the E12_Packet_Route function, which breaks it down and puts received data into the fields of a Cop_Data structure. User programs know what data has been returned by reading the return value from the packet routing function(E12_Packet_Route).This returned value is a bitmask, because more than one packet may be contained in any given chunk of raw data. Different types of data will set different bits, as detailed in the function descriptions below. Cop_Data structures are created and initialized with the CopDeviceCreate function, and destroyed with the CopDeviceDestroy function.


Typedef Documentation

typedef struct Cop_Data Cop_Data
 

The Cop_Data typedef This is a type of structure created and initialized by CopDeviceCreate. It is used for the stored of packet data currently being parsed, as well as to store data that has already been parsed and is being passed back to the user.

See also:
CopDeviceCreate , CopDeviceDestroy , E12_Packet_Route

typedef struct countconfig countconfig
 

This countconfig structure is used to configure an port 0 digital line to be a counter. E12_CountConfig fills out this structure based on parameters passed to it and passes it the e12packetout

See also:
E12_CountConfig

typedef struct countdata countdata
 

Counter data structure. This type of structure contains data collected from a running counter

typedef struct PWMconfig PWMconfig
 

This PWMconfig structure is used to configure an internal digital port to be a PWM. E12_PWMControl fills out this structure based on parameters passed to it and passes it the e12packetout

See also:
E12_PWMControl

typedef struct RG_ParseMask RG_ParseMask
 

Request/grant RG_ParseMask parse mask for devices with multiple channels. This substructure within the Cop_Data structure is a collection of bitmasks indicating that new data has arrived It is updated by a call to E12_Packet_Route. For example, after calling E12_Packet_Route on a particular block of data, External_AD might have a value of 6. This would indicate that channels 0 and 2 have received new data which is now stored in the Cop->External_AD[0] and Cop->External_AD[1].

typedef struct VersionInfo VersionInfo
 

version info structure VersionInfo This is how data received from the E12_VersionReq function is stored.


Function Documentation

Cop_Data* CopDeviceCreate int    flags
 

Create a Coprocessor structure This function creates a Cop_Data structure which can be passed to E12_Packet_Route to be filled with with incoming data from the coprocessor device

Parameters:
flags  unused
Returns:
a pointer to a new Cop_Data structure

Definition at line 418 of file Coprocessor.c.

int CopDeviceDestroy Cop_Data   Cop
 

Destroys a Coprocessor structure This function destroys a previously allocated Cop_Data structure

Parameters:
Cop  the structure to destroy
Returns:
0

Definition at line 425 of file Coprocessor.c.

int CopGetPacket Cop_Data   data,
Cop_DataBlock *    block
 

Pull data from an input block and check if it completes a packet based on parameters discoved by CopPacketMask and CopPacketStart. If it does, pass the data on through the Cop_Data structure into CopParsePacket

Parameters:
data  data pointer to the Cop_Data structure to store data in. Typically received from E12_Packet_Route.
block  a block of data received from the driver, this is typically passed from E12_Packet_Route.

Definition at line 173 of file Coprocessor.c.

References Cop_Data::packet, Cop_Data::psize, and Cop_Data::ptogo.

void CopPackBreak Cop_Data   data
 

called when a packet is marked as invalid to reset a Cop_Data structures packet counts

Parameters:
data  data pointer to the Cop_Data structure to store data in. Typically received from E12_Packet_Route.

Definition at line 161 of file Coprocessor.c.

References Cop_Data::packet, and Cop_Data::psize.

int CopPacketMask Cop_Data   data,
Cop_DataBlock *    block
 

Pull a chunk of data from a block and interprete its parameters to find data length, and masking. This is used by the lower level packet functions and could have unpredicatable results if by the applications developer.

Parameters:
data  data pointer to the Cop_Data structure to store data in. Typically received from E12_Packet_Route.
block  a block of data received from the driver, this is typically passed from E12_Packet_Route.

Definition at line 127 of file Coprocessor.c.

References Cop_Data::packet, Cop_Data::packetdata, Cop_Data::psize, and Cop_Data::ptogo.

int CopPacketStart Cop_Data   data,
Cop_DataBlock *    block
 

Pull a chunk of data from a block and interprete its parameters to find the type and masking. This is used by the lower level packet functions and could have unpredicatable results if by the applications developer.

Parameters:
data  data pointer to the Cop_Data structure to store data in. Typically received from E12_Packet_Route.
block  a block of data received from the driver, this is typically passed from E12_Packet_Route.

Definition at line 95 of file Coprocessor.c.

References Cop_Data::packet, Cop_Data::packetdata, and Cop_Data::psize.

int CopParsePacket Cop_Data   data
 

Interprete packet data and store it in a Cop_Data structure This function is the core of the interface between the low level packet parsing functions and the user space programs. It determines what happens to the data after it has been interpreted. In this case it passes it to a Cop_DataBlock structure element and sets the appropriate flags within it.

Parameters:
data  pointer to the Cop_Data structure to store data in. This is passed to CopParsePacket by E12_Packet_Route->CopGetPacket once the packet has been determined to be complete.

Definition at line 218 of file Coprocessor.c.

References Cop_Data::CAN_message, RG_ParseMask::counter, Cop_Data::counter_config, Cop_Data::counter_data, countdata::countstart, VersionInfo::date, PWMconfig::delay, Cop_Data::Digital, PWMconfig::duty, RG_ParseMask::External_AD, Cop_Data::External_AD, countconfig::flags, PWMconfig::frequency, RG_ParseMask::Internal_AD, Cop_Data::Internal_AD, Cop_Data::Key, countdata::laststamp, countdata::laststart, Cop_Data::packet, Cop_Data::packetdata, Cop_Data::parsemask, Cop_Data::psize, Cop_Data::ptogo, RG_ParseMask::pwm, PWMconfig::pwm, Cop_Data::PWM_config, Cop_Data::RS232_string, Cop_Data::RS422_string, countconfig::threshold, countdata::timestamp, countconfig::trigger, VersionInfo::version, Cop_Data::version, RG_ParseMask::zero, and countdata::zerocross.

int E12_AtoD_Req int    fd,
int    channel
 

Request AtoD reading calls Internal or External AtoD req based on the number if the number is greater than the number of internal AtoD channels it call external at channel-internal Atod channels. Return packets will set the appropriate bits in E12_Packet_Route's return value and in the Cop_Data structure's parsemask.

Parameters:
fd  the 37e12 device being addressed
channel  the channel to address
See also:
E12_Internal_AtoD_Req , E12_External_AtoD_Req
Returns:
0

Definition at line 695 of file Coprocessor.c.

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 E12_Digital_Cfg int    fd,
__u8    mask,
int    port
 

Write a byte of configuration data to a digital port. This is used to configure the lines of a digital port to be 1(outputs) or 0(inputs) This function applies to the internal ports 0 and 1 of the 37e12. The isolated external ports are not configurable. the byte is a bitmask of the lines. ex: 0x03 is binary for 00000011 which would activate lines 0 and 1 of the port being addressed, and deactivate the other lines.

Parameters:
fd  the 37e12 device being addressed
mask  the bitmask to write to the port
port  the portnumber to write to, on the 37e12 this is 0-1
Returns:
0

Definition at line 666 of file Coprocessor.c.

int E12_Digital_Req int    fd
 

Request Internal Digital port reading. This requests a packet from the 37e12 containing the readings from both the digital ports. When E12_Packet_Route parses raw data containing a return packet from this function it sets BITMASK(PRTIN0) to 1 in it's return value . See e12digitalGP.c for an example of this.

Parameters:
fd  the 37e12 device being addressed
Returns:
0
See also:
E12_Packet_Route

Definition at line 658 of file Coprocessor.c.

int E12_Digitalout int    fd,
__u8    data,
int    port
 

Write a byte of data to a digital port. This is used to set the lines of a digital port to 1(logic on) or 0(logic off) This function applies to the internal ports 0 and 1 of the 37e12. The isolated ports are controlled externally from the processor and are accessed directly by the driver. see e12digitalGP.c for an example of how to write to the internal ports, and ISO_out.c/ISO_in.c for examples of how to write to the external isolated ports. the byte is a bitmask of the lines. ex: 0x03 is binary for 00000011 which would activate lines 0 and 1 of the port being addressed, and deactivate the other lines.

Parameters:
fd  the 37e12 device being addressed
data  the bitmask to write to the port
port  the portnumber to write to, on the 37e12 this is 0-1
Returns:
0

Definition at line 642 of file Coprocessor.c.

int E12_DtoA_Write int    fd,
int    channel,
int    data
 

Write to DtoA Writes the value data to external DtoA channel channel This is a 12 bit DtoA, bits above that in the data field are ignored.

Parameters:
fd  the 37e12 device being addressed
channel  the channel to address 0-3
data  the data to write to the channel.
Returns:
0

Definition at line 708 of file Coprocessor.c.

int E12_External_AtoD_Req int    fd,
int    channel
 

Request External AtoD reading Raw data containing a packet returned from this function will set BITMASK(ADBLK1) in E12_Packet_Route's return value. It will also set a bit in the Cop_Data structure's parsemask.External_AD element, indicating the number of the channel returned.

Parameters:
fd  the 37e12 device being addressed
channel  the channel to address
Returns:
0

Definition at line 688 of file Coprocessor.c.

int E12_Internal_AtoD_Req int    fd,
int    channel
 

Request Internal AtoD reading Raw data containing a packet returned from this function will set BITMASK(ADBLK0) in E12_Packet_Route's return value. It will also set a bit in the Cop_Data structure's parsemask.Internal_AD element, indicating the number of the channel returned.

Parameters:
fd  the 37e12 device being addressed
channel  the channel to address
Returns:
0

Definition at line 682 of file Coprocessor.c.

__u32 E12_Packet_Route Cop_Data   Cop,
unsigned char *    data,
int    datasize
 

Interpret raw data read from the 37e12 This is the main packet parsing function, it takes a chunk of raw data "data" of size "datasize" interprets it and updates the fields in "Cop" appropriately. Typically this would be called right after a read as in: rxnum = read(fd,buffer,sizeof(buffer)); typemask = E12_Packet_Route(CopRouter,buffer, rxnum); where fd would be a pointer to a /dev/37e12 device, buffer would be a user allocated buffer and CopRouter would be a previously allocated Cop_Data structure.

Parameters:
Cop  The previously allocated Cop_Data structure to fill
data  pointer to the raw data obtained through a read to a 37e12
datasize  the size of the raw data packet
Returns:
bitmask of the packets that have been received

Definition at line 438 of file Coprocessor.c.

References Cop_Data::parsemask, and Cop_Data::psize.

__u32 E12_Parse_Until int    fd,
Cop_Data   Cop,
__u32    bitmask
 

Read and Interpret raw data read from the 37e12 until the desired packet is returned This is a secondary packet parsing function, it reads data from fd and parses it until it receives a typemask containing one of the bits in bitmask. This function calls read so whether or not it blocks is dependent on the driver and the flags that were passed to it when the fd was opened. If the function is used in non-blocking mode it does 1000 iterations before timing out and returning if no data is available.

Parameters:
fd  the 37e12 device being addressed
Cop  The previously allocated Cop_Data structure to fill
bitmask  type of packet to parse until. If any bit in the bitmask is reached the function will return.
Returns:
bitmask of the packets that have been received

Definition at line 468 of file Coprocessor.c.

References Cop_Data::parsemask, and Cop_Data::psize.

int E12_PWMControl int    fd,
int    pwm,
int    frequency,
int    duty,
Cop_Data   Cop
 

Configure an internal Digital port to be a pwm. This function sets up a one of the digital port lines to be a PWM. The 2 ports, 0 and 1 behave differently with respect to this function. It requires a the Cop data structure to be passed to it so that it can shadow the configuration. This also updates the other configuration parameters to reflect the effect of the PWM configuration, ie, if a the port was previously configured as a counter it changes the counters shadow status to show that it is no longer on.

Configuring a Port 0 line to be a PWM uses the DG128's IOC counter functionality to emulate PWM's . This does not allow as high a frequency as the hardware PWM's, but has the advantage of having independent channels(the frequency of one has no bearing on the frequency of the others). Since the PWM cycle is software based, maximum frequency and duty cycle are a function of the system load. The software PWM's can reliably handle pulse widths between 60us and 2.7ms, which would limit the frequency's to 186-8334Hz at 50% duty cycle.

Port 1 PWMS use the hardware PWM's of the DG128 processor. This allows for much higher PWM rates, but suffers in that it doesn't allow for many different frequencies. This is because the hardware PWM's share internal clocks so if one gets bumped up too high, the others will change frequency as well. There are 2 clocks(ClockA and ClockB) shared among the eight lines as follows:

  • 0 A
  • 1 A
  • 2 B
  • 3 B
  • 4 A
  • 5 A
  • 6 B
  • 7 B
These clocks will automatically pre-scale to accommodate a requested frequency when a new packet is received. Therefore changing the frequency of one hardware PWM can potentially effect the frequency of other hardware PWM's on the same clock. The frequency/prescale ratio is as follows
  • Hz - prescale
  • 65535 to 47059 - 0
  • 47058 to 23530 - 1
  • 23529 to 11765 - 2
  • 11764 to 5883 - 3
  • 5882 to 2942 - 4
  • 2941 to 1471 - 5
  • 1470 to 738 - 6
  • 735 to 367 - 7
Duty cycles are unaffected by the prescale and can be set to any value between 0 and 100. ex:

setting pin 7 of port 1 to 1Khz would cause clock B to be set at a prescale of 6. If pin 6 (which shares the same clock) was then set to 2Khz clock B's prescale would change to 5 and which would double the frequency of pin 7 to 200)KHz as well. Setting pin 6 to 1KHz would have had no effect because it would be within the same prescale range, also setting pin 5 to any value would have no effect on pin 7 because it uses a different clock.

Parameters:
fd  the 37e12 device being addressed
pwm  the line number to address 0-7 are port0 0-7, 8-15 are port1 0-7
frequency  the frequency of the PWM
duty  the duty cycle of the PWM.
Cop  Cop data structure to shadow the variables into.
Returns:
0

Definition at line 549 of file Coprocessor.c.

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

int E12_Serial_Config int    fd,
int    port,
int    baud,
int    mode
 

Configure a 37e12's mode and baud rate

Parameters:
fd  file descriptor of the 37e12
port  port to address RS232PORT or RS422PORT
baud  the baud rate
mode  EIGHT_BIT OR NINE_BIT

Definition at line 749 of file Coprocessor.c.

int E12_Serial_Write int    fd,
int    port,
int    numchars,
char *    buffer
 

Write data to a serial port

Parameters:
fd  file descriptor of the 37e12

Definition at line 717 of file Coprocessor.c.

int E12_VersionReq int    fd
 

Request version info Sends a request to the 37e12 for firmware version information, the version number and the __DATE__ it was compiled.

Parameters:
fd  the 37e12 device being addressed
channel  the channel to address 0-3
data  the data to write to the channel.
Returns:
0

int e12packetout int    fd,
__u8    device,
__u8    maskcnt,
void *    data
 

Create and send a packet to the device described by fd This function is a low level function used by the other transmit functions to send packets to the 37e12 It's direct use is not recommended as it requires some knowledge of the internal packet structure. Use the wrapper functions instead.

Parameters:
fd  the 37e12 device being addressed
device  a packet header nibble
maskcnt  a mask/count of the bytes being transmitted
data  generic data pointer to data to transmit
Returns:
0

Definition at line 539 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.

int UpdatetHardwarePWMInfo int    fd,
Cop_Data   Cop
 

Update the Cop structures PWM_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 521 of file Coprocessor.c.

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


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