Author Topic: IIC - wake task on write complete  (Read 9154 times)

Offline akorud

  • Newbie
  • *
  • Posts: 31
    • View Profile
IIC - wake task on write complete
« on: December 30, 2009, 05:33:23 PM »
Hi, I'd like to use task activation on IIC write complete - for performing long writes which do not fit in TX buffer and must be performed sequentially.
According to documentation it's possible - just assign task to tIICParameters.Task_to_wake field.
However I cannot make it work - did I miss something?

Thanks in advance,
Andriy

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: IIC - wake task on write complete
« Reply #1 on: December 30, 2009, 06:03:31 PM »
Hi Andriy

The code responsible for this is in the I2C interrupt routine:

        if (!(IIC_tx_control[0]->IIC_queue.chars)) {                     // transmission complete
            I2CR = (IIC_IEN | IIC_MTX);                                  // send stop condition and disable interrupts
            IIC_tx_control[0]->ucState &= ~(TX_WAIT | TX_ACTIVE | RX_ACTIVE);
            if (IIC_tx_control[0]->wake_task ) {
               uTaskerStateChange(IIC_tx_control[0]->wake_task, UTASKER_ACTIVATE);// wake up owner task since the transmission has terminated
            }
        }
        else {       
            fnTxIIC(IIC_tx_control[0], 0);                               // we have another message to send so we can send a repeated start condition
        }


If the parameter wake_task is not zero it should activate the task when all transmission has terminated.

Please also see a patch for a possible I2C problem (number 7) when the application sends a frame exactly as the first is terminating (which is possible if the woken application sends another message in your case): http://www.utasker.com/forum/index.php?topic=644.msg2954#msg2954

Regards

Mark



Offline akorud

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: IIC - wake task on write complete
« Reply #2 on: December 30, 2009, 06:09:50 PM »
Yes, I've studied this code I it's obvious that it should work, but it does not. I'm still trying to debug this, will keep you informed.
BTW, will application receive any message or will be just activated?

Andriy

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: IIC - wake task on write complete
« Reply #3 on: December 30, 2009, 06:24:19 PM »
Hi Andriy

The application will simply be activated - there is no event assigned to this.
This means that the task controlling it may need to be dedicated to the job since it will otherwise not be sure why it was woken.

You can however also check whether the output buffer is empty by using the fnWrite() call as described in the I2C document http://www.utasker.com/docs/uTasker/uTaskerIIC.PDF - chapter 4.

Regards

Mark