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.
#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:

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 |
|
|
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.
History |
|
||||||||||||
|
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.
History |
Here is the call graph for this function:

|
|
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.
History |
Here is the call graph for this function:

|
|
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.
History |
|
||||||||||||
|
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.
History |
|
||||||||||||
|
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.
History |
|
||||||||||||
|
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.
History |
|
||||||||||||
|
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.
History |
Here is the call graph for this function:

|
|
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.
History |
Here is the call graph for this function:

|
|
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.
History |
Here is the call graph for this function:

|
|
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.
History |
Here is the call graph for this function:

|
|
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 |
1.3.6