int CAN_device_tx_msg(uint8_t channel, CAN_msg * msg, unsigned int timeoutMs)
{
        CanTxMsg TxMessage;

        /* Transmit Structure preparation */
        if (msg->isExtendedAddress) {
                TxMessage.ExtId = msg->addressValue;
                TxMessage.IDE = CAN_ID_EXT;
        } else {
                TxMessage.StdId = msg->addressValue;
                TxMessage.IDE = CAN_ID_STD;
        }

        TxMessage.RTR = CAN_RTR_DATA;
        TxMessage.DLC = msg->dataLength;
        memcpy(TxMessage.Data, msg->data, msg->dataLength);

        CAN_TypeDef* chan = channel == 0 ? CAN1 : CAN2;
        const uint8_t mailbox = CAN_Transmit(chan, &TxMessage);

        /*
         * Then they don't want to wait.  Ok.  Let caller know if they
         * got a mailbox then.  If not, message was unable to be sent.
         */
        if (0 == timeoutMs)
                return mailbox != CAN_TxStatus_NoMailBox;

        /* Using ticks avoids a race-condition */
        size_t ticks = getCurrentTicks();
        const size_t trigger = ticks + msToTicks(timeoutMs);
        uint8_t status = CAN_TxStatus_Failed;

        while(ticks <= trigger) {
                status = CAN_TransmitStatus(chan, mailbox);
                if (CAN_TxStatus_Pending != status)
                        break;

                /*
                 * Not using yield here as it will cause lower priority tasks
                 * to starve.  Yield only allows tasks of equal or greater
                 * priority to run.
                 */
                delayTicks(1);

                ticks = getCurrentTicks();
        }

        if (CAN_TxStatus_Pending == status)
                CAN_CancelTransmit(chan, mailbox);

        return status == CAN_TxStatus_Ok;
}
Beispiel #2
0
void AndroidLog::logTime() {
    if(prevTick_ == static_cast<uint64_t>(0)){
        /*
         * init counter, bypass the first one
         */
        prevTick_ = getCurrentTicks();
        return;
    }
    uint64_t curTick = getCurrentTicks();
    uint64_t delta = curTick - prevTick_;
    log("%" PRIu64 "    %" PRIu64 "\n", curTick, delta);
    prevTick_ = curTick;
}
Beispiel #3
0
void Board::enableFlashErase(void)
{
    uint32_t delayTicks = BOARD_BUTTON_DELAY_TICKS;

    // Calculate timeout
    delayTicks += getCurrentTicks();

    // Wait until timeout
    while (!isExpiredTicks(delayTicks));

    // Set the callback and enable interrupt
    button_user.setCallback(&flashEraseCallback_);
    button_user.enableInterrupts();
}
LoggerMessage create_logger_message(const enum LoggerMessageType t,
                                    struct sample *s)
{
        const size_t ticks = getCurrentTicks();
        LoggerMessage msg;

        msg.type = t;
        msg.ticks = ticks;
        msg.sample = s;

        /* Set matching timestamps.  Needed for validation */
        if (s)
                s->ticks = ticks;

        return msg;
}
Beispiel #5
0
 unsigned int Timer::getElapsedMicroseconds() const {
     return static_cast<unsigned int>(getCurrentTicks() - m_ticks);
 }
Beispiel #6
0
 void Timer::start() {
     m_ticks = getCurrentTicks();
 }
Beispiel #7
0
long double getElapsedTime(const long double &startTicks) {
    return (getCurrentTicks() - startTicks)/Resolution;
}