Beispiel #1
0
void SleepIfOkay() {
    // we won't sleep if the main isn't willing to block
    if (MQ_Main_Willing_to_block == 0) {
        return;
    }
    // check to see if we are handling a low priority interrupt
    // if so, we are not going to sleep
    if (in_low_int()) {
        return;
    }
    // we know that we are in a high priority interrupt handler
    // but we'll check to make sure and return if we are not
    if (!in_high_int()) {
        return;
    }
    // since we are the only thing executing that could be
    // putting something into a message queue destined for main()
    // we can safely check the message queues now
    //   if they are empty, we'll go to sleep
    if (check_msg(&ToMainHigh_MQ)) {
        return;
    }
    if (check_msg(&ToMainLow_MQ)) {
        return;
    }
    enter_sleep_mode();
}
Beispiel #2
0
int in_main() {
    if ((!in_low_int()) && (!in_high_int())) {
        return (1);
    } else {
        return (0);
    }
}
Beispiel #3
0
signed char SensorData_sendmsg(unsigned char length, unsigned char id, void *data) {
#ifdef DEBUG
    if (!in_high_int()) {
        return (MSG_NOT_IN_HIGH);
    }
#endif

    if(id > (SENSORQUEUELEN - 1))
    {
        return INDEX_OUT_OF_RANGE;
    }

    //unsigned char slot;
    msg *qmsg;
    size_t tlength = length;
    sensor_queue *qptr = &SensorData_SQ;

    qmsg = &(qptr->queue[id]);
    qmsg->length = length;
    memcpy(qmsg->data, data, tlength);

    // This *must* be done after the message is completely inserted
    qmsg->full = 1;
    return (MSGSEND_OKAY);
}
Beispiel #4
0
signed char FromMainHigh_recvmsg(unsigned char maxlength, unsigned char *msgtype, void *data) {
#ifdef DEBUG
    if (!in_high_int()) {
        return (MSG_NOT_IN_HIGH);
    }
#endif
    return (recv_msg(&FromMainHigh_MQ, maxlength, msgtype, data));
}
Beispiel #5
0
signed char ToMainHigh_sendmsg(unsigned char length, unsigned char msgtype, void *data) {
#ifdef DEBUG
    if (!in_high_int()) {
        return (MSG_NOT_IN_HIGH);
    }
#endif
    return (send_msg(&ToMainHigh_MQ, length, msgtype, data));
}
Beispiel #6
0
int in_low_int() {
    if (INTCONbits.GIEL == 1) {
        return (0);
    } else if (in_high_int()) {
        return (0);
    } else {
        return (1);
    }
}
signed char	ADQueue_recvmsg(unsigned char maxlength,unsigned char *msgtype,void *data)
{
#ifdef DEBUG
	if (!in_high_int()) {
		return(MSG_NOT_IN_HIGH);
	}
#endif
	return(recv_msg(&adReadQueue,maxlength,msgtype,data));
}
Beispiel #8
0
int in_low_int() {
    //low priority enabled
    if (INTCONbits.GIEL == 1) {
        return (0);
    } else if (in_high_int()) {
        return (0);
    } else {
        return (1);
    }
}
Beispiel #9
0
signed char SensorData_sendmsg(unsigned char length, unsigned char msgtype, void *data) {
#ifdef DEBUG
    if (!in_high_int()) {
        return (MSG_NOT_IN_HIGH);
    }
#endif
    //unsigned char slot;
    msg *qmsg;
    size_t tlength = length;
    msg_queue *qptr = &SensorData_MQ;

    for(int i = 0; i < MSGQUEUELEN; i++)
    {
        if(i == (MSGQUEUELEN - 1))
        {
            qmsg = &(qptr->queue[i]);
            qmsg->length = length;
            memcpy(qmsg->data, data, tlength);
        }
        else
        {
            qmsg = &(qptr->queue[i]);
            msg *temp = &(qptr->queue[i + 1]);
            qmsg->length = temp->length;
            memcpy(qmsg->data, temp->data, qmsg->length);
        }
    }

    //slot = qptr->cur_write_ind;
    //qmsg = &(qptr->queue[slot]);
    // if the slot isn't empty, then we should return
    //if (qmsg->full != 0) {
       // return (MSGQUEUE_FULL);
    //}

    // now fill in the message
    //qmsg->length = length;
    //memcpy(qmsg->data, data, tlength);

    // This *must* be done after the message is completely inserted
    qmsg->full = 1;
    return (MSGSEND_OKAY);
    //return (send_msg(&SensorData_MQ, length, msgtype, data));
}