コード例 #1
0
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;
}
コード例 #2
0
ファイル: debug_utils.cpp プロジェクト: 03050903/android-ndk
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;
}
コード例 #3
0
ファイル: Board.cpp プロジェクト: OsamaWajiha/firmware
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();
}
コード例 #4
0
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;
}
コード例 #5
0
ファイル: catch_timer.hpp プロジェクト: 0x1997/Catch
 unsigned int Timer::getElapsedMicroseconds() const {
     return static_cast<unsigned int>(getCurrentTicks() - m_ticks);
 }
コード例 #6
0
ファイル: catch_timer.hpp プロジェクト: 0x1997/Catch
 void Timer::start() {
     m_ticks = getCurrentTicks();
 }
コード例 #7
0
ファイル: OSF1Timer.cpp プロジェクト: huilang22/Projects
long double getElapsedTime(const long double &startTicks) {
    return (getCurrentTicks() - startTicks)/Resolution;
}