Hi,

I am trying to read a CAN Stick with a USB interface and I am connected to a sensor module. I have a program which transfer sensor data from the embedded controller to the CAN Stick. There is a program which use an internal queue to transfer data from the embedded controller to the CAN STICK. The program is not efficient and on each cycle it grabs one message and transfer. Which is not efficient. The queue it use is mostly un used as it only store one message at the queue and transfer. Everytime one at a time. And then wait for acknowledge signal at the end. Which makes the program inefficient. I want to use interrupt and polling technology to utilize the unused time.

Please provide me an example for this problem.

Thank you.

I think the hardware is already interrupt driven (most likely). Some example of your code would be helpful as to how you determine when there is data to read and/or write.

Here is the code snippet.

In this situation I am trying to read the message on DLL_Transmit( _ui8InstructionResult ) then I have to wait on _ui8InstructionResult = DLL_UsrWaitInstRetEvent22( INFINITE ) for ack from CAN STICK.

    static UINT8 _ui8InstructionResult = DLL_k_OK;
                static UINT8 _ui8WaitForMsgResult;
                while( 1 ){
                    //Wait for a transmit message event
                    DLL_UsrWaitTxEvent();       // first wait event to transmit message
                    //Get the message from transmit queue and write it to the COM-port
                    _ui8TxResult = DLL_Transmit( _ui8InstructionResult );
                    if( DLL_k_OK == _ui8TxResult ){
                        _ui8WaitForMsgResult = 1;
                    }else if( DLL_k_BSY == _ui8TxResult ){
                        //This is an overlapped transfer, so we have to wait for the
                        //transmit finished event of the COM-port
                        if( MiCAN_OK == MiCanTxInt() ){
                            _ui8WaitForMsgResult = 1;
                        }else{
                            _ui8WaitForMsgResult = 0;
                            DiagOutput( DIAG_ERROR, "Unable to send message trough COM-port\r\n" );
                        }
                    }else{
                        //If an error occurred print a user message and stop the task
                        if( DLL_k_IV == _ui8TxResult ){
                            DiagOutput( DIAG_ERROR, "Tx event set, but no message in queue\r\n" );
                        }else if( DLL_k_NO == _ui8TxResult ){
                            DiagOutput( DIAG_ERROR, "Failed to send message\r\n" );
                        }else{
                            DiagOutput( DIAG_ERROR, "Unknown transmit state\r\n" );
                        }
                        while( 1 ){
                            GOE_TaskSleep( 1 );// delay occurs in this instruction
                        }
                    }
                    if( _ui8WaitForMsgResult ){

                        //Wait for the result event of the MiCAN stick
                        _ui8InstructionResult = DLL_UsrWaitInstRetEvent22( INFINITE );// wait as long as required, this function is modified to write more message in the queue
                        DLL_UsrResetInstRetEvent();
                        if( DLL_k_OK == _ui8InstructionResult ){
                            bueS_SetTxConnection();
                            DLL_UsrLockTxQueue();
                            DLL_UsrResetTxEvent( 0 );
                            DLL_UsrUnlockTxQueue();
                        }
                    }
                }


        return ( (GOE_t_TASKRETTYPE)0 );

I am trying to use a while(1) on the whole segment and use a semaphore and polling to check the status and on the same time keep doing transfer on the line

_ui8TxResult = DLL_Transmit( _ui8InstructionResult );

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.