Beispiel #1
0
/**
 * Implementation of the readBlock Function of the 24C512 chip.
 * @see eeprom.h
 * @private
 */
void _readEeprom24C512Block(Eeprom* eeprom_, unsigned long index, unsigned int length, Buffer* buffer){
   I2cBusConnection* i2cBusConnection = _24c512GetI2cBusConnection(eeprom_);
   I2cBus* i2cBus = i2cBusConnection->i2cBus;

   portableMasterWaitSendI2C(i2cBusConnection);

    portableMasterWaitSendI2C(i2cBusConnection);
    portableMasterStartI2C(i2cBusConnection);
    WaitI2C(i2cBus);
    unsigned int blockAddress = get24C512BlockAddress(index);
    portableMasterWriteI2C(i2cBusConnection, blockAddress);
    WaitI2C(i2cBus);

    unsigned int msbaddress = index >> 8;
    unsigned int lsbaddress = index & 0xFFFF;

    portableMasterWriteI2C(i2cBusConnection, msbaddress);
    WaitI2C(i2cBus);
    portableMasterWriteI2C(i2cBusConnection, lsbaddress);
    WaitI2C(i2cBus);

    // read the data
    portableMasterStartI2C(i2cBusConnection);
    WaitI2C(i2cBus);

    portableMasterWriteI2C(i2cBusConnection, blockAddress | 0x01);

    int i;
    for (i = 0; i < length - 1; i++) {
        char c = portableMasterReadI2C(i2cBusConnection);
        portableMasterAckI2C(i2cBusConnection);
        WaitI2C(i2cBus);
        bufferWriteChar(buffer, c);
    }
    char c = portableMasterReadI2C(i2cBusConnection);
    portableMasterNackI2C(i2cBusConnection);
    WaitI2C(i2cBus);
    bufferWriteChar(buffer, c);
    portableMasterStopI2C(i2cBusConnection);
    WaitI2C(i2cBus);
}
/**
 * @private
 */
void fillI2CInputInternalBuffer(InputStream* inputStream) {
    while (true) {
        I2cBusConnection* i2cBusConnection = _i2cMasterInputStreamGetI2cBusConnection(inputStream);
        unsigned char c = i2cMasterReadChar(i2cBusConnection);

        if (c == I2C_SLAVE_NO_DATA_IN_READ_BUFFER || c == INCORRECT_DATA) {
            break;
        }

        appendI2cDebugInputChar(c);

        Buffer* buffer = _i2cMasterInputStreamGetBuffer(inputStream);
        bufferWriteChar(buffer, c);
    }
}
void handleUartInterrupt(UART_MODULE uart, Buffer* buffer) {
    // Is this an RX interrupt?
    if (INTGetFlag(INT_SOURCE_UART_RX(uart))) {
        if (UARTReceivedDataIsAvailable(uart)) {
            unsigned char c = UARTGetDataByte(uart);
            // BUG2018, BUG2019 (255 / 254 value) when Motor Power is too strong
            if (c != 'ÿ' && c != 'þ') {
                bufferWriteChar(buffer, c);
            }
            // Clear the RX interrupt Flag
            INTClearFlag(INT_SOURCE_UART_RX(uart));
        }
    }
    // We don't care about TX interrupt
    if ( INTGetFlag(INT_SOURCE_UART_TX(uart)) ) {
        INTClearFlag(INT_SOURCE_UART_TX(uart));
    }
}
Beispiel #4
0
/**
 * Definition of a function which is able to write a character.
 */
void _bufferWriteChar(OutputStream* outputStream, char c) {
    Buffer* buffer = (Buffer*) outputStream->object;

    bufferWriteChar(buffer, c);
}