Beispiel #1
0
xdc_Void A110x2500Radio::serviceInterrupt(xdc_UArg arg0, xdc_UArg arg1) {
  while(1) {
    Semaphore_pend(sem, BIOS_WAIT_FOREVER);

    GateMutex_enter(GateMutex_handle(&mygate));

    // Note: It is assumed that interrupts are disabled.

    // The GDO0 ISR will only look for the EOP edge. Therefore, if the radio
    // is not transmitting the EOP, it must be receiving an EOP signal.
    if (gDataTransmitting)
    {
      /**
       *  Note: GDO0 is issued prior to the transmitter being completely
       *  finished. The state machine will remain in TX_END until transmission
       *  completes. The following waits for TX_END to correct the hardware
       *  behavior.
       */ 
      while (CC1101GetMarcState(&gPhyInfo.cc1101) == eCC1101MarcStateTx_end);
      gDataTransmitting = false;
    }
    else
    {
      gDataReceived = true;
      readDataStream();
    }

    // Always go back to sleep.
    sleep();
    GateMutex_leave(GateMutex_handle(&mygate), 0);
  }
}
/*
 *  ======== USBMSCHFatFsTiva_diskWrite ========
 *  This function writes sector(s) to the disk drive
 *
 *  @param  drv     Drive Number
 *
 *  @param  buf     Pointer to a buffer from which data is read
 *
 *  @param  sector  Sector number to write to
 *
 *  @param  count   Number of sectors to be written
 */
DRESULT USBMSCHFatFsTiva_diskWrite(BYTE drv, const BYTE *buf,
                                   DWORD sector, BYTE count)
{
    unsigned int                key;
    uint32_t                    driveWrite;
    USBMSCHFatFsTiva_Object    *object = USBMSCHFatFs_config->object;

    Log_print2(Diags_USER1, "USBMSCHFatFs: diskWrite: Sector %d, Count %d",
                             sector, count);

    if (!count) {
        Log_print0(Diags_USER1, "USBMSCHFatFs: diskWrite: ERROR");
        return (RES_PARERR);
    }

    if (object->state != USBMSCHFatFsTiva_CONNECTED) {
        Log_print0(Diags_USER1, "USBMSCHFatFs: diskWrite: not initialized");
        return (RES_NOTRDY);
    }

    key = GateMutex_enter(GateMutex_handle(&(object->gateUSBLibAccess)));
    driveWrite = USBHMSCBlockWrite(object->MSCInstance, sector, (uint8_t *)buf, count);
    GateMutex_leave(GateMutex_handle(&(object->gateUSBLibAccess)), key);

    if (driveWrite == 0) {
        Log_print0(Diags_USER2, "USBMSCHFatFs: diskWrite: OK");
        return (RES_OK);
    }
    else {
        Log_print0(Diags_USER2, "USBMSCHFatFs: diskWrite: ERROR");
        return (RES_ERROR);
    }
}
/*
 *  ======== USBMSCHFatFsTiva_diskRead ========
 *  This function reads sector(s) from the disk drive
 *
 *  @param  drv     Drive Number
 *
 *  @param  buf     Pointer to a buffer to which data is written
 *
 *  @param  sector  Sector number to read from
 *
 *  @param  count   Number of sectors to be read
 */
DRESULT USBMSCHFatFsTiva_diskRead(BYTE drv, BYTE *buf,
                                  DWORD sector, BYTE count)
{
    unsigned int                key;
    uint32_t                    driveRead;
    USBMSCHFatFsTiva_Object    *object = USBMSCHFatFs_config->object;

    Log_print2(Diags_USER1, "USBMSCHFatFs: diskRead: Sector %d, Count %d",
                             sector, count);

    if (object->state != USBMSCHFatFsTiva_CONNECTED) {
        Log_print0(Diags_USER1, "USBMSCHFatFs: diskRead: not initialized");
        return (RES_NOTRDY);
    }

    /* READ BLOCK */
    key = GateMutex_enter(GateMutex_handle(&(object->gateUSBLibAccess)));
    driveRead = USBHMSCBlockRead(object->MSCInstance, sector, buf, count);
    GateMutex_leave(GateMutex_handle(&(object->gateUSBLibAccess)), key);

    if (driveRead == 0) {
        Log_print0(Diags_USER2, "USBMSCHFatFs: diskRead: OK");
        return (RES_OK);
    }
    else {
        Log_print0(Diags_USER2, "USBMSCHFatFs: diskRead: ERROR");
        return (RES_ERROR);
    }
}
/*
 *  ======== USBMSCHFatFsTiva_diskInitialize ========
 *  This function checks the USB Drive to see if it's ready to be accessed.
 *
 *  This function attempts to read the USBHMSCDriveReady() function up to 10
 *  times to get a good return code. For some reason the first attempt to read
 *  this function doesn't return a good response value. Generally, you should
 *  get a good response on the second attempt.
 *  A gateMutex lock is required to prevent concurrent access to the USB
 *  Library's state machine variables within MSCInstance.
 *
 *  @param  drv Drive Number
 *
 *  @return Returns the disk status to the FatFs module
 */
DSTATUS USBMSCHFatFsTiva_diskInitialize(BYTE drv)
{
    unsigned char               i;
    unsigned int                key;
    uint32_t                    driveReady;
    USBMSCHFatFsTiva_Object    *object = USBMSCHFatFs_config->object;

    /* Determine if the USB Drive is ready up to 10 times */
    for (i = 0; i < 10; i++ ) {

        key = GateMutex_enter(GateMutex_handle(&(object->gateUSBLibAccess)));
        driveReady = USBHMSCDriveReady(object->MSCInstance);
        GateMutex_leave(GateMutex_handle(&(object->gateUSBLibAccess)), key);

        if (driveReady == 0) {
            Log_print1(Diags_USER1, "USBMSCHFatFs: disk initialization: "
                                    "ready after %d tries", i);

            return (0x00); /* Disk OK */
        }
    }

    Log_print0(Diags_USER1, "USBMSCHFatFs: disk initialization: not ready");
    return (STA_NOINIT);
}
/*
 *  ======== USBMSCHFatFsTiva_serviceUSBHost ========
 *  Task to periodically service the USB Stack
 *
 *  USBHCDMain handles the USB Stack's statemachine. For example it handles the
 *  enumeration process when a device connects.
 *  Future USB library improvement goal is to remove this polling requirement..
 */
static void USBMSCHFatFsTiva_serviceUSBHost(UArg arg0, UArg arg1)
{
    unsigned int                key;
    USBMSCHFatFsTiva_Object    *object = USBMSCHFatFs_config->object;

    while (true) {
        key = GateMutex_enter(GateMutex_handle(&(object->gateUSBLibAccess)));
        USBHCDMain();
        GateMutex_leave(GateMutex_handle(&(object->gateUSBLibAccess)), key);

        /* Future enhancement to remove the Task_sleep */
        Task_sleep(10);
    }
}
Beispiel #6
0
uint8_t TwoWire::endTransmission(uint8_t sendStop)
{
    bool ret;
    WireContext *wc = getWireContext();

    if (i2c == NULL) {
        return (4); /* 4 = 'other error' */
    }
    
    ret = I2C_transfer(i2c, &(wc->i2cTransaction));

    wc->txWriteIndex = 0;

    wc->i2cTransaction.writeCount = 0;
    wc->rxReadIndex = 0; //i2cTransaction will overwrite buffer staring at 0
    wc->rxWriteIndex = wc->i2cTransaction.readCount;

    wc->i2cTransaction.readCount = 0;

    if (sendStop) {
        wc->idle = true;
    }

    if (gateEnterCount) {
        GateMutex_leave(GateMutex_handle(&gate), --gateEnterCount);
    }

    /* success = 0; 4 = other error */
    return (ret ? 0 : 4);
}
/*
 *  ======== USBMSCHFatFsTiva_waitForConnect ========
 */
bool USBMSCHFatFsTiva_waitForConnect(USBMSCHFatFs_Handle handle,
                                     unsigned int timeout)
{
    unsigned int                key;
    bool                        ret = true;
    USBMSCHFatFsTiva_Object    *object = handle->object;

    /* Need exclusive access to prevent a race condition */
    key = GateMutex_enter(GateMutex_handle(&(object->gateUSBWait)));

    if (object->state == USBMSCHFatFsTiva_NO_DEVICE) {
        if (!Semaphore_pend(Semaphore_handle(&(object->semUSBConnected)),
                                             timeout)) {
            ret = false;
        }
    }

    GateMutex_leave(GateMutex_handle(&(object->gateUSBWait)), key);

    return (ret);
}
Beispiel #8
0
void TwoWire::beginTransmission(uint8_t address)
{
    WireContext *wc = getWireContext();

    GateMutex_enter(GateMutex_handle(&gate));
    gateEnterCount++;

    if (wc->idle) {
        wc->i2cTransaction.slaveAddress = address;
        wc->idle = false;
    }
}