void SendMgmtMsg(uint8_t *p_header, uint8_t headerLength, uint8_t *p_data, uint8_t dataLength) { if (DRV_WIFI_InHibernateMode()) { DRV_WIFI_UserEventSet(DRV_WIFI_EVENT_ERROR, DRV_WIFI_ERROR_IN_HIBERNATE_MODE, true); return; } WF_MGMTMSG_MUTEX_LOCK(); EnsureWFisAwake(); /* write out management header */ RawSetIndex(RAW_SCRATCH_ID, MGMT_TX_BASE); RawSetByte(RAW_SCRATCH_ID, p_header, headerLength); /* write out data (if any) */ if (dataLength > 0) { RawSetByte(RAW_SCRATCH_ID, p_data, dataLength); } /* Signal MRF24WG that mgmt message ready to process */ Write16BitWFRegister(WF_HOST_MAIL_BOX_0_MSW_REG, 0x0400); Write16BitWFRegister(WF_HOST_MAIL_BOX_0_LSW_REG, 0x0000); }
/***************************************************************************** * FUNCTION: SendMgmtMsg * * RETURNS: error code * * PARAMS: p_header -- pointer to mgmt message header data * headerLength -- number of bytes in the header * will be written * p_data -- pointer to mgmt message data * dataLength -- number of byte of data * * NOTES: Sends a management message *****************************************************************************/ void SendMgmtMsg(UINT8 *p_header, UINT8 headerLength, UINT8 *p_data, UINT8 dataLength) { #if defined(__18CXX) static UINT32 startTickCount; static UINT32 maxAllowedTicks; #else UINT32 startTickCount; UINT32 maxAllowedTicks; #endif /* cannot send management messages while in WF_ProcessEvent() */ WF_ASSERT(!isInWFProcessEvent()); EnsureWFisAwake(); /* if a Rx Data packet is mounted that has not yet been processed */ if (GetRawWindowState(RAW_RX_ID) == WF_RAW_DATA_MOUNTED) { /* save it, so after mgmt response received it can be restored */ PushRawWindow(RAW_RX_ID); RestoreRxData = TRUE; } /* mounts a tx mgmt buffer on the MRF24W when data tx is done */ maxAllowedTicks = TICKS_PER_SECOND / 200; /* 5 ms timeout */ startTickCount = (UINT32)TickGet(); while (!WFisTxMgmtReady() ) { MACProcess(); /* DEBUG -- REMOVE AFTER FIGURE OUT WHY TIMING OUT (RARELY HAPPENS) */ if (TickGet() - startTickCount >= maxAllowedTicks) { /* force flags so WFisTxMgmtReady will return TRUE */ SetRawWindowState(RAW_TX_ID, WF_RAW_UNMOUNTED); RawWindowReady[RAW_TX_ID] = FALSE; } } /* write out management header */ RawSetByte(RAW_TX_ID, p_header, headerLength); /* write out data (if any) */ if (dataLength > 0) { RawSetByte(RAW_TX_ID, p_data, dataLength); } /* send mgmt msg to MRF24W */ SendRAWManagementFrame(headerLength + dataLength); }
/* ********************************************************************************************************* * RawWrite() * * Description : Writes the specified number of bytes to a mounted RAW window at the specified starting * index * * Argument(s) : rawId -- RAW window ID being written to * startIndex -- start index within RAW window to write to * length -- number of bytes to write to RAW window * p_src -- pointer to Host buffer write data * * Return(s) : None * * Caller(s) : WF Driver * * Notes: : None * ********************************************************************************************************* */ void RawWrite(UINT8 rawId, UINT16 startIndex, UINT16 length, UINT8 *p_src) { /*set raw index in dest memory */ RawSetIndex(rawId, startIndex); /* write data to RAW window */ RawSetByte(rawId, p_src, length); }
/* ********************************************************************************************************* * RawWrite() * * Description : Writes the specified number of bytes to a mounted RAW window at the specified starting * index * * Argument(s) : rawId -- RAW window ID being written to * startIndex -- start index within RAW window to write to * length -- number of bytes to write to RAW window * p_src -- pointer to Host buffer write data * * Return(s) : None * * Caller(s) : WF Driver * * Notes: : None * ********************************************************************************************************* */ void RawWrite(uint8_t rawId, uint16_t startIndex, uint16_t length, uint8_t *p_src) { /*set raw index in dest memory */ RawSetIndex(rawId, startIndex); /* write data to RAW window */ RawSetByte(rawId, p_src, length); }
/******************************************************************************* Function: void SendMgmtMsg(UINT8 *p_header, UINT8 headerLength, UINT8 *p_data, UINT8 dataLength) Summary: Sends a management message to MRF24W. Description: Allocates management buffer on MRF24W. Then sends the management message (header + data) to MRF24W. Precondition: MACInit must be called. Parameters: p_header -- pointer to mgmt message header data headerLength -- number of bytes in the header will be written p_data -- pointer to mgmt message data dataLength -- number of bytes of data Returns: None Remarks: *****************************************************************************/ void SendMgmtMsg(UINT8 *p_header, UINT8 headerLength, UINT8 *p_data, UINT8 dataLength) { UINT32 timeoutPeriod; UINT32 startTickCount; /* cannot send management messages while in WF_ProcessEvent() */ WF_ASSERT(!isInWFProcessEvent()); EnsureWFisAwake(); /* Allocate a management buffer on the WiFi device. May have to wait a bit while the previous Data Tx packet is being sent */ /* which will free up the memory for this mgmt packet. */ timeoutPeriod = TICKS_PER_SECOND / 2; /* 500 ms */ startTickCount = (UINT32)TickGet(); while (AllocateMgmtTxBuffer(WF_MAX_TX_MGMT_MSG_SIZE) == FALSE) { if (TickGet() - startTickCount >= timeoutPeriod) { WF_ASSERT(FALSE); } } /* write out management header */ RawSetByte(RAW_MGMT_TX_ID, p_header, headerLength); /* write out data (if any) */ if (dataLength > 0) { RawSetByte(RAW_MGMT_TX_ID, p_data, dataLength); } /* send mgmt msg to MRF24W */ SendRAWManagementFrame(headerLength + dataLength); }
void RawCopyTest() { BOOL res; UINT8 i; UINT8 byte; UINT16 rawIndex; UINT16 bufAvail; UINT16 srcRawId = 5; UINT16 byteCount; /* get total bytes available for MGMT tx memory pool */ bufAvail = Read16BitWFRegister(WF_HOST_WFIFO_BCNT1_REG) & 0x0fff; /* LS 12 bits contain length */ /* verify we can read and write from scratch buffer (already mounted) */ RawSetIndex(RAW_SCRATCH_ID, 0); rawIndex = RawGetIndex(RAW_SCRATCH_ID); WF_ASSERT(rawIndex == 0); for (i = 0; i < 128; ++i) { RawSetByte(RAW_SCRATCH_ID, &i, 1); rawIndex = RawGetIndex(RAW_SCRATCH_ID); WF_ASSERT(rawIndex == i + 1); } rawIndex = RawGetIndex(RAW_SCRATCH_ID); /* raw index should be at 128 */ WF_ASSERT(rawIndex == 128); RawSetIndex(RAW_SCRATCH_ID, 0); rawIndex = RawGetIndex(RAW_SCRATCH_ID); WF_ASSERT(rawIndex == 0); for (i = 0; i < 128; ++i) { RawGetByte(RAW_SCRATCH_ID, &byte, 1); WF_ASSERT(byte == i); } RawSetIndex(RAW_SCRATCH_ID, 0); rawIndex = RawGetIndex(RAW_SCRATCH_ID); WF_ASSERT(rawIndex == 0); /* now zero out scratch */ byte = 0; for (i = 0; i < 128; ++i) { RawSetByte(RAW_SCRATCH_ID, &byte, 1); rawIndex = RawGetIndex(RAW_SCRATCH_ID); WF_ASSERT(rawIndex == i + 1); } RawSetIndex(RAW_SCRATCH_ID, 0); rawIndex = RawGetIndex(RAW_SCRATCH_ID); WF_ASSERT(rawIndex == 0); /* verify scratch is zeroed out */ for (i = 0; i < 128; ++i) { RawGetByte(RAW_SCRATCH_ID, &byte, 1); WF_ASSERT(byte == 0); } RawSetIndex(RAW_SCRATCH_ID, 0); rawIndex = RawGetIndex(RAW_SCRATCH_ID); WF_ASSERT(rawIndex == 0); /* allocate raw buffer of 128 bytes */ byteCount = RawMove(srcRawId, RAW_MGMT_POOL, TRUE, 128); WF_ASSERT(byteCount >= 128); /* fill up buffer with known values */ for (i = 0; i < 128; ++i) { RawSetByte(srcRawId, &i, 1); } rawIndex = RawGetIndex(srcRawId); /* raw index should be at 128 */ WF_ASSERT(rawIndex == 128); /* put raw index back to 0 and verify */ res = RawSetIndex(srcRawId, 0); WF_ASSERT(res == TRUE); rawIndex = RawGetIndex(srcRawId); WF_ASSERT(rawIndex == 0); /* read back from source buffer to ensure write was successful */ for (i = 0; i < 128; ++i) { RawGetByte(srcRawId, &byte, 1); rawIndex = RawGetIndex(srcRawId); WF_ASSERT(rawIndex == i + 1); if (byte != i) { WF_ASSERT(FALSE); } } /* put raw index back to 0 and verify */ res = RawSetIndex(srcRawId, 0); WF_ASSERT(res == TRUE); rawIndex = RawGetIndex(srcRawId); WF_ASSERT(rawIndex == 0); /* set the Scratch index to 0 and verify */ RawSetIndex(RAW_SCRATCH_ID, 0); rawIndex = RawGetIndex(RAW_SCRATCH_ID); WF_ASSERT(rawIndex == 0); /* set the raw source index to 0 and verify */ RawSetIndex(srcRawId, 0); rawIndex = RawGetIndex(srcRawId); WF_ASSERT(rawIndex == 0); /* perform raw to raw copy and verify raw indexes*/ RawToRawCopy(RAW_SCRATCH_ID, srcRawId, 128); rawIndex = RawGetIndex(RAW_SCRATCH_ID); WF_ASSERT(rawIndex == 128); rawIndex = RawGetIndex(srcRawId); WF_ASSERT(rawIndex == 128); /* put scratch raw index back to 0 */ res = RawSetIndex(RAW_SCRATCH_ID, 0); WF_ASSERT(res == TRUE); rawIndex = RawGetIndex(RAW_SCRATCH_ID); WF_ASSERT(rawIndex == 0); /* read data from scratch and see if it matches what was copied */ for (i = 0; i < 128; ++i) { RawGetByte(RAW_SCRATCH_ID, &byte, 1); rawIndex = RawGetIndex(RAW_SCRATCH_ID); WF_ASSERT(rawIndex == (i+1)); if (byte != i) { WF_ASSERT(FALSE); } } }