Ejemplo n.º 1
0
void MsgRcvISR()
{
	int mid = pcbs[cur_pid].tf_p ->eax;
	msg_t *source, *destination = (msg_t *)pcbs[cur_pid].tf_p->ebx;

	if(!MsgQEmpty(&mboxes[mid].msg_q))
	{
		source = DeQMsg(&mboxes[mid].msg_q);
		MyMemCpy((char*)destination,(char*)source,sizeof(msg_t));
	}
	else
	{
		EnQ(cur_pid, &mboxes[mid].wait_q);
		pcbs[cur_pid].state = WAIT;
		cur_pid=-1;
	}
}
Ejemplo n.º 2
0
uint8_t os_msg_receive( Msg_t *msg, MsgQ_t queue ) {
    #if( N_QUEUES > 0 )

    OSMsgQ_t *temp;
    uint8_t *data;
    uint8_t i;
    uint8_t found;

    temp = &msgQList[ queue ];

    if ( MsgQEmpty( temp ) == 1 ) {
        return MSG_QUEUE_EMPTY;
    }

    /* If all messages have a delay > 0 we consider the queue as empty */
    if ( MsgQAllDelayed( temp ) == 1 ) {
        return MSG_QUEUE_EMPTY;
    }

    /* At least one message is ready to be delivered. Find it! */
    found = 0;
    while ( found == 0 ) {

        data = (uint8_t*)( (Mem_t)temp->msgPool + (temp->tail) * (temp->messageSize) );
        for ( i = 0; i < temp->messageSize; ++i ) {
            ((uint8_t*)msg)[ i ] = data[ i ];
        }

        /* Look for buffer wrap around */
        if ( temp->tail == 0 ) {
            temp->tail = temp->size - 1;
        }
        else {
            temp->tail--;
        }

        uint8_t messagePeriodic = ( msg->reload > 0 );
        uint8_t messageTimedOut = ( msg->delay == 0 );

        if ( messageTimedOut ){
            found = 1;
            if ( messagePeriodic ) {
                msg->delay = msg->reload;
            }
        }

        /* Put the message back at head position if delay > 0, or if it is a periodic message that timed out */
        if (( !messageTimedOut ) || ( messagePeriodic && messageTimedOut )) {
            data = (uint8_t*)( (Mem_t)temp->msgPool + (temp->head) * (temp->messageSize) );

            for ( i = 0; i < temp->messageSize; ++i ) {
                data[ i ] = ((uint8_t*)msg)[i];
            }

            /* Look for buffer wrap around */
            if ( temp->head == 0 ) {
                temp->head = temp->size - 1;
            }
            else {
                temp->head--;
            }
        }
    }
    /* Signal the change event */
    os_signal_event(temp->change);
    os_event_set_signaling_tid( temp->change, running_tid );

    return MSG_QUEUE_RECEIVED;
#else
    return 0;
#endif
}