Author Topic: Task not woken on IIC read  (Read 6710 times)

Offline akorud

  • Newbie
  • *
  • Posts: 31
    • View Profile
Task not woken on IIC read
« on: May 24, 2008, 02:31:28 PM »
Hi, I'm trying to read from IIC chips and:
- first, init IIC:
Code: [Select]
tIICParameters.Channel = OUR_IIC_CHANNEL;
tIICParameters.usSpeed = 100;                                        // 100k
tIICParameters.Rx_tx_sizes.TxQueueSize = 64;
tIICParameters.Rx_tx_sizes.RxQueueSize = 64;
tIICParameters.Task_to_wake = 0;                                     // No wake on transmission

if (InternalIICPortID = fnOpen( TYPE_IIC, FOR_I_O, &tIICParameters )) {   
...
- start reading:
Code: [Select]
static const unsigned char ucReadIICADC[] = {3, MAX1037_ADDR_READ, OWN_TASK};
fnRead(InternalIICPortID, (unsigned char *)&ucReadIICADC, 0);   
- wait for data in main loop:
Code: [Select]
while ( fnRead( PortIDInternal, ucInputMessage, HEADER_LENGTH )) {   // check input queue
        switch ( ucInputMessage[ MSG_SOURCE_TASK ] ) {                   // switch depending on message
         ...
        }

if (fnMsgs(InternalIICPortID)) {
while ((LengthIIC = fnRead( InternalIICPortID, ucInputMessage, MEDIUM_MESSAGE)) != 0) {
int x = 0;
while (x < LengthIIC) {                                      // display received bytes
fnDebugHex(ucInputMessage[x++], (WITH_LEADIN | WITH_SPACE | 1));
}
fnDebugMsg("\r\n");
}
}
The problem is that task is not woken afrer IIC read. When it wakes up on timer event - IIC data are ready and I can successfully read. However if I disable timer events for this task - it will wait forever...
Did I miss something?

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Task not woken on IIC read
« Reply #1 on: May 24, 2008, 07:31:56 PM »
Hi

I think that the problem is that the read from the I2C handle is conditional on messages being in the internal queue:
while (internal messages) {
    read (internal queue);
    if (fnMsgs(InternalIICPortID)) {  // only checked when message(s) in the task input queue
        read(InternalIICPortID);
    }
}


The task is probably being woken but, since the I2C reception doesn't write anything to the internal queue, it is quitting without doing anything. Any internal messages (like your timer event) will cause it to be woken again and this time the I2C data to be (finally) read.

If you put the I2C part outside of the while it will probably work:

while (internal messages) {
    read (internal queue);
}
if (fnMsgs(InternalIICPortID)) {                // always checked whenever the task is woken
    read(InternalIICPortID);
}


Regards

Mark