Main Page | Data Structures | File List | Data Fields | Globals

cctalk-channel.c File Reference


Detailed Description

Provide a channel to perform a cctalk transaction over.

This module will provide a channel like interface to the cctalk module. Each channel will consist of a create channel, queue transaction, receive completed transactions, and a close channel It will be possible to create a channel then perform cctalk transactions on the channel and when finished with the channel close the channel. A channel will map directly to a specific Linux tty all this will be hidden from the user. All the user is concerned with is that he can perform a cctalk transaction.

A cctalk transaction is considered both a TX packet and a RX packet with a timeout and packet sizes.

The user will pass in cctalk transactions to be queued to a cctalk channel if there are no transaction in progress the transaction will be processed straight away otherwise the transaction will be queued.

Author:
Rod Boyce
Date:
19/10/04

#include <stdio.h>
#include <termios.h>
#include <string.h>
#include <pthread.h>
#include "cctalk-channel-defs.h"
#include "cctalk-operations.h"
#include "cctalk-channel.h"
#include "cctalk-driver.h"
#include "cctalk-svr-mem.h"
#include "cctalk-debug.h"

Include dependency graph for cctalk-channel.c:

Include dependency graph

Data Structures

struct  tsTHREAD_COMM_OPERATION
 This structure is used to spin off a thread to perform a cctalk operation. More...


Functions

void cctalk_ch_Initialise (void)
 Called to initialise the channel operation code.

void * cctalk_ch_SerialOperationThread (void *pvOperation)
 This function performs cctalk transactions on the serial port.

teCCTALK_ERRORS cctalk_ch_RemoveTxOps (teCCTALK_CHANNEL eCctCh, tsCCTALK_OPERATION *psCctOp)
 Receive completed transactions from a cctalk channel.

teCCTALK_ERRORS cctalk_OpenChannel (teCCTALK_CHANNEL eCctCh, teCCTALK_SPEED eCctSpd)
 Open a cctalk channel for communication.

teCCTALK_ERRORS cctalk_CloseChannel (teCCTALK_CHANNEL eCctCh)
 Called to close a cctalk channel.

teCCTALK_ERRORS cctalk_QueueOperation (teCCTALK_CHANNEL eCctCh, tsCCTALK_OPERATION *psCctOp)
 Called to perform cctalk transactions.

teCCTALK_ERRORS cctalk_ReceiveOperation (teCCTALK_CHANNEL eCctCh, tsCCTALK_OPERATION *psCctOp)
 Receive completed transactions from a cctalk channel.

void cctalk_SvrDoSerialOperations (void)
 spin off threads to cctalk serial operations

void cctalk_SvrCloseOpsForSocket (int fdSock)
 Free cctalk operations associated with a socket.

teCCTALK_ERRORS cctalk_SvrChannelStatus (teCCTALK_CHANNEL eCctCh, int fdSock)
 Called on request for operation status.

teCCTALK_ERRORS cctalk_SvrForceClose (teCCTALK_CHANNEL eCctCh)
 Force closure for the cctalk channel.


Variables

tsCCT_COMM_HANDLER asCctChannels [eCCTALK_CHANNEL_END]
tsTHREAD_COMM_OPERATION asCommOps [eCCTALK_CHANNEL_END]
unsigned char qIsInitialised = 0

Function Documentation

void cctalk_ch_Initialise void   )  [static]
 

Called to initialise the channel operation code.

This code is called to initialise the cctalk channel code. Firstly zero all structures Then initialise the necessary structure values to the not in-use value and set-up the volatile structures for each cctalk comms channel being controlled.

Date:
02/11/04
Author:
Rod Boyce

History

teCCTALK_ERRORS cctalk_ch_RemoveTxOps teCCTALK_CHANNEL  eCctCh,
tsCCTALK_OPERATION psCctOp
[static]
 

Receive completed transactions from a cctalk channel.

This function is called when a socket is closing to remove any pending cctalk operations from the waiting to be processed chain. If the search gets to the end of the list and no more operations are found for this socket then eCH_NO_DATA is returned. If a pending transaction is found then the transaction is removed from the chain and returned to the caller.

Date:
05/11/04
Author:
Rod Boyce
Parameters:
eCctCh - The cctalk channel to check.
psCctOp - pointer to a cctalk op structure to return the operation in.
Returns:
The error code returned is found in teCCTALK_ERRORS.

History

Here is the call graph for this function:

void * cctalk_ch_SerialOperationThread void *  pvOperation  )  [static]
 

This function performs cctalk transactions on the serial port.

This function is spin off into a thread to perform a cctalk transaction. The TX buffer is written to the serial port and we wait for either a timeout or a replay from the cctalk device. The device will receive the TX buffer and send a reply. This function runs inside its own thread context. There are two flags used by the thread controller the first flag qRunning is set before the thread is started to say an operation is in progress and we cannot start another one. The second qFinished tells the thread controller when the thread has finished at to process the transaction.

Date:
27/10/04
Author:
Rod Boyce
Parameters:
pvOperation - pointer to the cctalk transaction
Returns:
nothing

History

Here is the call graph for this function:

cctalk_CloseChannel teCCTALK_CHANNEL  eCctCh  ) 
 

Called to close a cctalk channel.

When a user has finished using a cctalk channel the close channel fn is called to close the channel. a check is made to confirm that all transactions have finished and the channel is then closed.

Date:
19/10/04
Author:
Rod Boyce
Parameters:
eCctCh - The channel to perform this action on.
Returns:

History

cctalk_OpenChannel teCCTALK_CHANNEL  eCctCh,
teCCTALK_SPEED  eCctSpd
 

Open a cctalk channel for communication.

Open a cctalk channel for communication with the device(s) on this cctalk channel. There many be more than one device here. This routine is not concerned with auto discovery the devices must already be known on this channel.

Date:
19/10/04
Author:
Rod Boyce
Parameters:
eCctCh - The cctalk channel to open
eCctSpd - The speed to communication over this channel with
Returns:
see enum teCCTALK_ERRORS for error code definitions

History

cctalk_QueueOperation teCCTALK_CHANNEL  eCctCh,
tsCCTALK_OPERATION psCctOp
 

Called to perform cctalk transactions.

A cctalk operation consists of a packet to transmit, a reply packet, the maximum size of the expected reply packet, how long to wait for the reply packet, and the size of the TX packet. The format of the packet can vary depending on, if an addition checksum, a CRC16 checksum, or if encryption is being used on the wire. This interface provides a conduit for transactions but the end developer must format the packets correctly.

Date:
19/10/04
Author:
Rod Boyce
Parameters:
eCctCh - The channel to perform the transaction on.
psCctOp - the cctalk transaction to perform
Returns:

History

cctalk_ReceiveOperation teCCTALK_CHANNEL  eCctCh,
tsCCTALK_OPERATION psCctOp
 

Receive completed transactions from a cctalk channel.

A call this is will return a cctalk transaction if one is available to be returned. This job of this function just got a lot more differcult as not only are we interested in the cctalk channel but also a socket handle.

Date:
19/10/04
Author:
Rod Boyce
Parameters:
eCctCh - The cctalk channel to check.
psCctOp - pointer to a cctalk op structure to return the operation in.
Returns:
The error code returned is found in teCCTALK_ERRORS.

History

cctalk_SvrChannelStatus teCCTALK_CHANNEL  eCctCh,
int  fdSock
 

Called on request for operation status.

This function is called when the client wants to know if there are any cctalk operations either in the Tx queue waiting to be send or in the Rx queue waiting to be received or currently being processed. If there are cctalk operations at some stage of being processed that eCCTALK_CH_BUSY is returned otherwise eCCTALK_NO_DATA is returned.

Date:
05/11/04
Author:
Rod Boyce
Parameters:
eCctCh - The cctalk channel that the status is required of.
fdSock - The socket to look for operation in the cctalk channel.
Returns:
eCCTALK_CH_NO_DATA if there are no more cctalk operations for that channel or eCCTALK_CH_BUSY if there is still data to be sent or wait to be received.

History

Here is the call graph for this function:

cctalk_SvrCloseOpsForSocket int  fdSock  ) 
 

Free cctalk operations associated with a socket.

What's happening here is that when a client closes without receiving all the cctalk transactions for itself this leaves memory behind that will never be deallocated. What must happen is that when the server closes the client socket it must free all the cctalk transactions that the client has not received. This memory leak was discovered while debugging the application. It is unlikely that this will happen in normal operation but it is still good to perform this check most of the code is written I just need to implement the top functionality. Look though the TX queue for cctalk operations as well. There is still one last problem the current operation may also be for this socket there is nothing that can be done until the current operation is finished so signal such and next time we process a cctalk operation delete this operation.

Date:
01/11/04
Author:
Rod Boyce
Parameters:
fdSock - the socket handle that we are closing

History

Here is the call graph for this function:

cctalk_SvrDoSerialOperations void   ) 
 

spin off threads to cctalk serial operations

This function is called to perform a cctalk operation on each channel. Firstly a check is performed to see if any previous transaction has completed if so the results are posted on that channel. Next if there is any queued operations and all operations have finished another operation is started.

Date:
26/10/04
Author:
Rod Boyce

History

Here is the call graph for this function:

cctalk_SvrForceClose teCCTALK_CHANNEL  eCctCh  ) 
 

Force closure for the cctalk channel.

This code is called when the client want to force the closure of a cctalk channel. Any resources associated with this channel are released and the serial tty is closed.

Date:
08/11/04
Author:
Rod Boyce
Parameters:
eCctCh - The cctalk channel to close.
Returns:
An error code defined in teCCTALK_ERRORS

History

Here is the call graph for this function:


Variable Documentation

unsigned char qIsInitialised = 0 [static]
 

This is used to check if the system has been initialised correctly on entry to any of the public functions a check is made each time


Generated on Thu Jan 20 16:11:03 2005 for Axis cctalk sub-system by doxygen 1.3.6