/***************************************************************************** Function: BOOL AllocateMgmtTxBuffer(uint16_t bytesNeeded) Summary: Allocates a Mgmt Tx buffer Description: Determines if WiFi chip has enough memory to allocate a tx mgmt buffer, and, if so, allocates it. Precondition: None Parameters: bytesNeeded -- number of bytes needed for the mgmt tx message Returns: True if mgmt tx buffer successfully allocated, else False Remarks: None *****************************************************************************/ bool AllocateMgmtTxBuffer(uint16_t bytesNeeded) { uint16_t bufAvail; uint16_t byteCount; /* get total bytes available for MGMT tx memory pool */ bufAvail = Read16BitWFRegister(WF_HOST_WFIFO_BCNT1_REG) & 0x0fff; /* LS 12 bits contain length */ /* if enough bytes available to allocate */ if ( bufAvail >= bytesNeeded ) { /* allocate and create the new Mgmt Tx buffer */ byteCount = RawMove(RAW_MGMT_TX_ID, RAW_MGMT_POOL, true, bytesNeeded); if (byteCount == 0) { EventEnqueue(WF_EVENT_ERROR, UD_ERROR_MGMT_BUFFER_ALLOCATION_FAILED); return false; } ClearIndexOutOfBoundsFlag(RAW_MGMT_TX_ID); return true; } /* else not enough bytes available at this time to satisfy request */ else { /* if we allocated some bytes, but not enough, then deallocate what was allocated */ if (bufAvail > 0) { RawMove(RAW_MGMT_RX_ID, RAW_MGMT_POOL, false, 0); } return false; } }
/***************************************************************************** Function: BOOL RawSetIndex(UINT16 rawId, UINT16 index) Summary: Sets the index within the specified RAW window. Description: Sets the index within the specified RAW window. If attempt to set RAW index outside boundaries of RAW window (past the end) this function will time out. It's legal to set the index past the end of the raw window so long as there is no attempt to read or write at that index. Precondition: None Parameters: rawId -- RAW window ID index -- desired index within RAW window Returns: True if successful, False if caller tried to set raw index past end of window Remarks: None *****************************************************************************/ BOOL RawSetIndex(UINT16 rawId, UINT16 index) { UINT8 regId; UINT16 regValue; UINT32 startTickCount; UINT32 maxAllowedTicks; /* get the index register associated with the raw ID and write to it */ regId = g_RawIndexReg[rawId]; Write16BitWFRegister(regId, index); /* Get the raw status register address associated with the raw ID. This will be polled to */ /* determine that: */ /* 1) raw set index completed successfully OR */ /* 2) raw set index failed, implying that the raw index was set past the end of the raw window */ regId = g_RawStatusReg[rawId]; maxAllowedTicks = TICKS_PER_SECOND / 200; /* 5ms */ startTickCount = (UINT32)TickGet(); /* read the status register until set index operation completes or times out */ while (1) { regValue = Read16BitWFRegister(regId); if ((regValue & WF_RAW_STATUS_REG_BUSY_MASK) == 0) { ClearIndexOutOfBoundsFlag(rawId); return TRUE; } /* if timed out then trying to set index past end of raw window, which is OK so long as the app */ /* doesn't try to access it */ if (TickGet() - startTickCount >= maxAllowedTicks) { SetIndexOutOfBoundsFlag(rawId); return FALSE; /* timed out waiting for Raw set index to complete */ } } }
/***************************************************************************** Function: void RawSetIndex(uint16_t rawId, uint16_t index) Summary: Sets the index within the specified RAW window. Description: Sets the index within the specified RAW window. If attempt to set RAW index outside boundaries of RAW window (past the end) this function will time out. It's legal to set the index past the end of the raw window so long as there is no attempt to read or write at that index. For now, flag an event. Precondition: None Parameters: rawId -- RAW window ID index -- desired index within RAW window Returns: None Remarks: None *****************************************************************************/ void RawSetIndex(uint16_t rawId, uint16_t index) { uint8_t regId; uint16_t regValue; uint32_t elapsedTime; uint32_t startTime; /* get the index register associated with the raw ID and write to it */ regId = g_RawIndexReg[rawId]; Write16BitWFRegister(regId, index); /* Get the raw status register address associated with the raw ID. This will be polled to */ /* determine that: */ /* 1) raw set index completed successfully OR */ /* 2) raw set index failed, implying that the raw index was set past the end of the raw window */ regId = g_RawStatusReg[rawId]; /* read the status register until set index operation completes or times out */ startTime = WF_TimerRead(); while (1) { regValue = Read16BitWFRegister(regId); if ((regValue & WF_RAW_STATUS_REG_BUSY_MASK) == 0) { ClearIndexOutOfBoundsFlag(rawId); break; } elapsedTime = GetElapsedTime(startTime, WF_TimerRead()); if (elapsedTime > 5) { // if we timed out that means that the caller is trying to set the index // past the end of the raw window. Not illegal in of itself so long // as there is no attempt to read or write at this location. But, // applications should avoid this to avoid the timeout in SetIndexOutOfBoundsFlag(rawId); EventEnqueue(WF_EVENT_ERROR, UD_ERROR_RAW_SET_INDEX_OUT_OF_BOUNDS); break; } } }
/***************************************************************************** Function: bool RawSetIndex(uint16_t rawId, uint16_t index) Summary: Sets the index within the specified RAW window. Description: Sets the index within the specified RAW window. If attempt to set RAW index outside boundaries of RAW window (past the end) this function will time out. It's legal to set the index past the end of the raw window so long as there is no attempt to read or write at that index. Precondition: None Parameters: rawId -- RAW window ID index -- desired index within RAW window Returns: True if successful, False if caller tried to set raw index past end of window Remarks: None *****************************************************************************/ bool RawSetIndex(uint16_t rawId, uint16_t index) { uint8_t regId; uint16_t regValue; uint32_t startTickCount; uint32_t maxAllowedTicks; /* get the index register associated with the raw ID and write to it */ regId = g_RawIndexReg[rawId]; Write16BitWFRegister(regId, index); /* Get the raw status register address associated with the raw ID. This will be polled to */ /* determine that: */ /* 1) raw set index completed successfully OR */ /* 2) raw set index failed, implying that the raw index was set past the end of the raw window */ regId = g_RawStatusReg[rawId]; maxAllowedTicks = SYS_TMR_TickPerSecond() / 200; /* 5ms */ startTickCount = SYS_TMR_TickCountGet(); /* read the status register until set index operation completes or times out */ while (1) { regValue = Read16BitWFRegister(regId); if ((regValue & WF_RAW_STATUS_REG_BUSY_MASK) == 0) { ClearIndexOutOfBoundsFlag(rawId); return true; } /* if timed out then trying to set index past end of raw window, which is OK so long as the app */ /* doesn't try to access it */ if (SYS_TMR_TickCountGet() - startTickCount >= maxAllowedTicks) { SetIndexOutOfBoundsFlag(rawId); return false; /* timed out waiting for Raw set index to complete */ } } }