コード例 #1
0
ファイル: Wire.cpp プロジェクト: JuergenGe/Energia
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop)
{
    uint8_t error = 0;
    uint8_t oldWriteIndex = rxWriteIndex;
    uint8_t spaceAvailable = (rxWriteIndex >= rxReadIndex) ?
                             BUFFER_LENGTH - (rxWriteIndex - rxReadIndex) : (rxReadIndex - rxWriteIndex);

    if (quantity > spaceAvailable)
        quantity = spaceAvailable;
    if (!quantity) return 0;

    //Select which slave we are requesting data from
    //true indicates we are reading from the slave
    ROM_I2CMasterSlaveAddrSet(MASTER_BASE, address, true);

    unsigned long cmd = 0;

    if((quantity > 1) || !sendStop)
        cmd = RUN_BIT | START_BIT | ACK_BIT;
    else cmd = RUN_BIT | START_BIT | (sendStop << 2);

    error = getRxData(cmd);
    if(error) return 0;

    currentState = MASTER_RX;

    for (int i = 1; i < quantity; i++) {
        //since NACK is being sent on last byte, a consecutive burst read will
        //need to send a start condition
        if(i == (quantity - 1))
            cmd = RUN_BIT;
        else
            cmd = RUN_BIT | ACK_BIT;

        error = getRxData(cmd);
        if(error) return i;
    }

    if(sendStop) {
        HWREG(MASTER_BASE + I2C_O_MCS) = STOP_BIT;
        while(ROM_I2CMasterBusy(MASTER_BASE));
        currentState = IDLE;
    }

    uint8_t bytesWritten = (rxWriteIndex >= oldWriteIndex) ?
                           BUFFER_LENGTH - (rxWriteIndex - oldWriteIndex) : (oldWriteIndex - rxWriteIndex);

    return(bytesWritten);

}
コード例 #2
0
ファイル: RF_Control_B1.c プロジェクト: ericluo1123/myCcode
inline void setRF_Main() {
    char error = 0;
    char TX = 0;
    char RX = 0;
    int command = 0;

    if (RF1.Enable == true) {
        //delay time
        if (RF1.debounce == true) {
            RF1.Count++;
            if (RF1.Count >= (RF1.RunTime / Main_Time)) {
                RF1.Count = (RF1.RunTime / Main_Time);
                RF1.Count = 0;
                RF1.debounce = false;
            }
        } else {
            command = RF_getCommand();

            switch (command) {
                case 0: //exit
                    break;
                case 1: //RX
                    if (RF1.RxStatus == false) {
                        RF1.RxStatus = true;
                        CC2500_WriteCommand(CC2500_SIDLE); // idle
                        CC2500_WriteCommand(CC2500_SFRX); // clear RXFIFO data
                        CC2500_WriteCommand(CC2500_SRX); // set receive mode

                    } else {

                        CC2500_RxData();
                        if (RF1.ReceiveGO == true) {
                            RF1.ReceiveGO = false;
                            RF1.RxStatus = false;
                            getRxData();
                            RF1.debounce = true;
                        }
                    }
                    break;
                case 2: //TX
                    if (RF1.TransceiveGO == true) {                  
                        RF1.RxStatus = false;
                        //                    RF1.CorrectionCounter = 0;
                        //                    RF_RxDisable();
                        setData();
                        CC2500_TxData();
                        RF1.debounce = true;
                        if(RF1.again == false){
                            RF1.again = true;
                        }else{
                            RF1.again = false;
                             RF1.TransceiveGO = false;
                        }
                    }
                    break;
            };
        }


        //        if (getBuz_GO() == 0) {
        //
        //#if Switch_use == 1
        //            command = RF_getCommand();
        //#else
        //            KeyPress = 0;
        //#endif
        //
        //            if (command == 0) {
        //
        //                if (RF1.TransceiveGO == true) {
        //                    //                    if (RF1.Learn == false) {
        //                    RF1.Count++;
        //                    if (RF1.Count >= (RF1.RunTime / Main_Time)) {
        //                        RF1.Count = (RF1.RunTime / Main_Time);
        //
        //                        RF1.TransceiveGO = false;
        //                        RF1.CorrectionCounter = 0;
        //                        RF_RxDisable();
        //                        setData();
        //                        CC2500_TxData();
        //
        //
        //                        ErrLED = ErrLED == true ? false : true;
        //                        //                        }
        //                    } else {
        //                        RF1.Count = 0;
        //                        RF1.TransceiveGO = false;
        //                    }
        //                } else {
        //                    if (RF1.RxStatus == true) {
        //#if Rx_Enable == 1
        //                        CC2500_RxData();
        //#endif
        //                        if (RF1.ReceiveGO == true) {
        //                            RF1.ReceiveGO = false;
        //                            RF1.CorrectionCounter = 0;
        //#if I2C_use == 1
        //                            I2C_SetData(1);
        //                            //LED2=~LED2;
        //#elif UART_use == 1
        //                            //UART_SetData();
        //                            //LED2=~LED2;
        //#else
        //                            getRxData();
        //                            //                                ErrLED = ErrLED == true ? false : true;
        //#endif
        //                        }
        //                    } else {
        //                        RF1.Count++;
        //                        if (RF1.Count >= (RF1.RunTime / Main_Time)) {
        //                            RF1.Count = 0;
        //#if Rx_Enable == 1
        //                            RF1.RxStatus = true;
        //                            CC2500_WriteCommand(CC2500_SIDLE); // idle
        //                            CC2500_WriteCommand(CC2500_SFRX); // clear RXFIFO data
        //                            CC2500_WriteCommand(CC2500_SRX); // set receive mode
        //#endif
        //                        }
        //                    }
        //                }
        //            }
        //        }

        //        RF1.CorrectionCounter++;
        //        if (RF1.CorrectionCounter > (60000 / Main_Time)) {
        //            RF1.CorrectionCounter = 0;
        //
        //            RF1.RxStatus = false;
        //            RF1.ReceiveGO = false;
        //            CC2500_WriteCommand(CC2500_SIDLE); // idle
        //            //            CC2500_WriteCommand(CC2500_SFRX); // clear RXFIFO data
        //        }
        //
        //        if (RF1.Timeout == true) {
        //            RF1.Timeout = false;
        //            CC2500_PowerOnInitial();
        //        }

    } else {
        if (myMain.PowerON == true) {
            RF1.Enable = true;

            RF_Initialization();
            CC2500_PowerOnInitial();

        }
    }
}