Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: fsl_phy_mcr20a fsl_smac mbed-rtos mbed
Fork of mcr20_wireless_uart by
Revision 23:6f13fea3cace, committed 2015-04-25
- Comitter:
- FSL\B36402
- Date:
- Sat Apr 25 00:50:20 2015 -0500
- Parent:
- 22:7703e6571f21
- Child:
- 24:088286081619
- Commit message:
- First version working with IAR
Changed in this revision
--- a/FSL_IEEE802_15_4_PHY/MCR20Drv/MCR20Drv.c Fri Apr 24 22:54:35 2015 +0000 +++ b/FSL_IEEE802_15_4_PHY/MCR20Drv/MCR20Drv.c Sat Apr 25 00:50:20 2015 -0500 @@ -42,7 +42,6 @@ #include "MCR20Reg.h" #include "XcvrSpi.h" -//#include "arm_hal_interrupt.h" /***************************************************************************** * PRIVATE VARIABLES *
--- a/FSL_IEEE802_15_4_PHY/PhyPacketProcessor.c Fri Apr 24 22:54:35 2015 +0000 +++ b/FSL_IEEE802_15_4_PHY/PhyPacketProcessor.c Sat Apr 25 00:50:20 2015 -0500 @@ -37,7 +37,6 @@ ************************************************************************************* ************************************************************************************/ #include "EmbeddedTypes.h" -//#include "board.h" #include "MCR20Drv.h" #include "MCR20Reg.h" #include "MCR20Overwrites.h" @@ -45,11 +44,13 @@ #include "Phy.h" #include "MpmInterface.h" -//#include "fsl_os_abstraction.h" -//#include "fsl_gpio_driver.h" +#if 0 +#include "board.h" +#include "fsl_os_abstraction.h" +#include "fsl_gpio_driver.h" -//extern const IRQn_Type g_portIrqId[HW_PORT_INSTANCE_COUNT]; - +extern const IRQn_Type g_portIrqId[HW_PORT_INSTANCE_COUNT]; +#endif /************************************************************************************ ************************************************************************************* * Public macros
--- a/FSL_IEEE802_15_4_PHY/PhyStateMachine.c Fri Apr 24 22:54:35 2015 +0000 +++ b/FSL_IEEE802_15_4_PHY/PhyStateMachine.c Sat Apr 25 00:50:20 2015 -0500 @@ -63,8 +63,6 @@ #include "AspInterface.h" #include "MpmInterface.h" -//#include "arm_hal_interrupt.h" - /************************************************************************************ ************************************************************************************* * Public macros
--- a/FSL_IEEE802_15_4_PHY/PhyTime.c Fri Apr 24 22:54:35 2015 +0000 +++ b/FSL_IEEE802_15_4_PHY/PhyTime.c Sat Apr 25 00:50:20 2015 -0500 @@ -43,7 +43,6 @@ #include "Phy.h" //#include "FunctionLib.h" -//#include "arm_hal_interrupt.h" /************************************************************************************ *************************************************************************************
--- a/FSL_SMAC/SMAC.cpp Fri Apr 24 22:54:35 2015 +0000
+++ b/FSL_SMAC/SMAC.cpp Sat Apr 25 00:50:20 2015 -0500
@@ -26,11 +26,15 @@
#include "EmbeddedTypes.h"
#include "SMAC_Config.h"
-//#include "MemManager.h"
-//#include "FunctionLib.h"
-//#include "panic.h"
+#if 0
+#include "MemManager.h"
+#include "FunctionLib.h"
+#include "panic.h"
+#endif
#include "cmsis_os.h"
+#include "rtos.h"
+
/************************************************************************************
*************************************************************************************
* Public memory declarations
@@ -98,9 +102,9 @@
void *param
)
{
- osTimerId id;
- //RtosTimer smac_timer(pfTimerCallBack, osTimerOnce , NULL);
- id = osTimerCreate (osTimer(SmacTimer), osTimerOnce, NULL);
+ //RtosTimer smac_timer(pfTimerCallBack, osTimerOnce , NULL);
+
+ osTimerId id = osTimerCreate (osTimer(SmacTimer), osTimerOnce, NULL);
osTimerStart (id, timeInMilliseconds);
return 0;
}
--- a/main.cpp Fri Apr 24 22:54:35 2015 +0000
+++ b/main.cpp Sat Apr 25 00:50:20 2015 -0500
@@ -1,25 +1,30 @@
#include "mbed.h"
#include "rtos.h"
+#include "Phy.h"
#include "SMAC_Interface.h"
#include "SMAC_Config.h"
-static uint8_t mAppSer;
-static uint8_t timePassed;
+#define gMcps_Cnf_EVENT_c (1<<1)
+#define gMcps_Ind_EVENT_c (1<<2)
+#define gMlme_EdCnf_EVENT_c (1<<3)
+#define gMlme_CcaCnf_EVENT_c (1<<4)
+#define gMlme_TimeoutInd_EVENT_c (1<<5)
+#define gWUSelf_EVENT_c (1<<6)
+
#ifdef VERBOSE
static bool_t bCCAFailed;
static bool_t bACKFailed;
#endif
-static bool_t bTxDone;
-static bool_t bRxDone;
-static bool_t evKeyPressed;
-static bool_t bTxInProgress;
+uint32_t gTaskEventFlags;
static uint8_t gau8TxDataBuffer[gMaxSmacSDULength_c + sizeof(rxPacket_t)];
static txPacket_t *gAppTxPacket;
static rxPacket_t *gAppRxPacket;
static txContextConfig_t txConfigContext;
void InitProject(void);
+void InitApp(void);
+
extern smacErrors_t smacToAppMlmeSap(smacToAppMlmeMessage_t* pMsg, instanceId_t instance);
extern smacErrors_t smacToAppMcpsSap(smacToAppDataMessage_t* pMsg, instanceId_t instance);
@@ -27,6 +32,7 @@
InterruptIn sw2(SW2);
uint32_t button_pressed;
Thread *thread2;
+Thread *eventsThread;
void sw2_press(void)
{
@@ -49,91 +55,163 @@
}
}
+void events_thread(void const *argument)
+{
+ uint8_t rcvd = 0;
+
+ while (true)
+ {
+ Thread::signal_wait(0x1);
+
+ if(gMcps_Cnf_EVENT_c == (gTaskEventFlags & gMcps_Cnf_EVENT_c))
+ {
+ //get back in RX
+ MLMERXEnableRequest(gAppRxPacket, 0);
+
+ //printf("McpsDataCnf: Packet sent\r\n");
+ }
+
+ if(gMcps_Ind_EVENT_c == (gTaskEventFlags & gMcps_Ind_EVENT_c))
+ {
+ rcvd = gAppRxPacket->smacPdu.smacPdu[0];
+
+ //get back in RX
+ //gAppRxPacket = (rxPacket_t*)MEM_BufferAlloc(gMaxSmacSDULength_c + sizeof(rxPacket_t));
+ //gAppRxPacket->u8MaxDataLength = gMaxSmacSDULength_c;
+ MLMERXEnableRequest(gAppRxPacket, 0);
+
+ printf("McpsDataInd: Received %d\r\n", rcvd);
+ }
+
+ if(gMlme_TimeoutInd_EVENT_c == (gTaskEventFlags & gMlme_TimeoutInd_EVENT_c))
+ {
+ //printf("MlmeTimeoutInd: \r\n");
+ }
+
+ if(gMlme_EdCnf_EVENT_c == (gTaskEventFlags & gMlme_EdCnf_EVENT_c))
+ {
+ //printf("EdCnf: \r\n");
+ }
+
+ if(gMlme_CcaCnf_EVENT_c == (gTaskEventFlags & gMlme_CcaCnf_EVENT_c))
+ {
+ //printf("CcaCnf: \r\n");
+ }
+
+ if(gWUSelf_EVENT_c == (gTaskEventFlags & gWUSelf_EVENT_c))
+ {
+
+ }
+
+ gTaskEventFlags = 0;
+ }
+}
+
int main()
{
Thread thread(led_thread);
thread2 = new Thread(button_thread);
-
+ eventsThread = new Thread(events_thread);
+
+ Phy_Init();
InitSmac();
- Smac_RegisterSapHandlers((SMAC_APP_MCPS_SapHandler_t)smacToAppMcpsSap,(SMAC_APP_MLME_SapHandler_t)smacToAppMlmeSap,0);
-
- InitProject();
-
- gAppTxPacket = (txPacket_t*)gau8TxDataBuffer; //Map TX packet to buffer
- gAppRxPacket = (rxPacket_t*)MEM_BufferAlloc(gMaxSmacSDULength_c + sizeof(rxPacket_t));
- SMACFillHeader(&(gAppTxPacket->smacHeader), gDefaultAddress_c);
-
- (void)MLMEPAOutputAdjust(gDefaultOutputPower_c);
- (void)MLMESetChannelRequest(gDefaultChannelNumber_c);
- (void)MLMEConfigureTxContext(&txConfigContext);
- gAppRxPacket->u8MaxDataLength = gMaxSmacSDULength_c;
- (void)MLMERXEnableRequest(gAppRxPacket, 0);
-
+ //Tell SMAC who to call when it needs to pass a message to the application thread.
+ Smac_RegisterSapHandlers((SMAC_APP_MCPS_SapHandler_t)smacToAppMcpsSap,(SMAC_APP_MLME_SapHandler_t)smacToAppMlmeSap,0);
+
+ InitApp();
+
button_pressed = 0;
sw2.fall(&sw2_press);
while (true) {
Thread::wait(5000);
+ gAppTxPacket->smacPdu.smacPdu[0] = (uint8_t)button_pressed;
+ gAppTxPacket->u8DataLength = 1;
+ (void)MLMERXDisableRequest();
+ (void)MCPSDataRequest(gAppTxPacket);
printf("SW2 was pressed (last 5 seconds): %d \r\n", button_pressed);
fflush(stdout);
button_pressed = 0;
}
}
+void InitApp()
+{
+ gAppTxPacket = (txPacket_t*)gau8TxDataBuffer; //Map TX packet to buffer
+ gAppRxPacket = (rxPacket_t*)MEM_BufferAlloc(gMaxSmacSDULength_c + sizeof(rxPacket_t));
+
+ InitProject();
+
+ SMACFillHeader(&(gAppTxPacket->smacHeader), gDefaultAddress_c);
+
+ (void)MLMEPAOutputAdjust(gDefaultOutputPower_c);
+ (void)MLMESetChannelRequest(gDefaultChannelNumber_c);
+ (void)MLMEConfigureTxContext(&txConfigContext);
+ //AppDelayTmr = TMR_AllocateTimer();
+ gAppRxPacket->u8MaxDataLength = gMaxSmacSDULength_c;
+ (void)MLMERXEnableRequest(gAppRxPacket, 0);
+}
+
+/* (Management) Sap handler for managing timeout indication and ED confirm
+ This is running in INTERRUPT context, so need to send messages to one of the task */
smacErrors_t smacToAppMlmeSap(smacToAppMlmeMessage_t* pMsg, instanceId_t instance)
{
switch(pMsg->msgType)
{
- case gMlmeEdCnf_c:
- printf("EdCnf: \r\n");
- //(void)OSA_EventSet(&gTaskEvent, gMlme_EdCnf_EVENT_c);
- break;
- case gMlmeCcaCnf_c:
- printf("CcaCnf: \r\n");
- //(void)OSA_EventSet(&gTaskEvent, gMlme_CcaCnf_EVENT_c);
- break;
- case gMlmeTimeoutInd_c:
- printf("MlmeTimeoutInd: \r\n");
- //(void)OSA_EventSet(&gTaskEvent, gMlme_TimeoutInd_EVENT_c);
- break;
- default:
- break;
+ case gMlmeEdCnf_c:
+ gTaskEventFlags |= gMlme_EdCnf_EVENT_c;
+ break;
+ case gMlmeCcaCnf_c:
+ gTaskEventFlags |= gMlme_CcaCnf_EVENT_c;
+ break;
+ case gMlmeTimeoutInd_c:
+ gTaskEventFlags |= gMlme_TimeoutInd_EVENT_c;
+ break;
+ default:
+ break;
}
+ eventsThread->signal_set(0x1);
MEM_BufferFree(pMsg);
return gErrorNoError_c;
}
-//(Data) Sap handler for managing data confirm and data indication
+/* (Data) Sap handler for managing data confirm and data indication
+ This is running in INTERRUPT context, so need to send messages to one of the task */
smacErrors_t smacToAppMcpsSap(smacToAppDataMessage_t* pMsg, instanceId_t instance)
-{
- switch(pMsg->msgType)
- {
- case gMcpsDataInd_c:
- if(pMsg->msgData.dataInd.pRxPacket->rxStatus == rxSuccessStatus_c)
- {
- printf("McpsDataInd: \r\n");
- //(void)OSA_EventSet(&gTaskEvent, gMcps_Ind_EVENT_c);
- }
- break;
- case gMcpsDataCnf_c:
-#ifdef VERBOSE
- if(pMsg->msgData.dataCnf.status == gErrorChannelBusy_c)
+{
+ switch(pMsg->msgType)
{
- bCCAFailed = TRUE;
- }
- if(pMsg->msgData.dataCnf.status == gErrorNoAck_c)
- {
- bACKFailed = TRUE;
- }
+ case gMcpsDataInd_c:
+ if(pMsg->msgData.dataInd.pRxPacket->rxStatus == rxSuccessStatus_c)
+ {
+ gTaskEventFlags |= gMcps_Ind_EVENT_c;
+ }
+ break;
+
+ case gMcpsDataCnf_c:
+#ifdef VERBOSE
+ if(pMsg->msgData.dataCnf.status == gErrorChannelBusy_c)
+ {
+ bCCAFailed = TRUE;
+ }
+
+ if(pMsg->msgData.dataCnf.status == gErrorNoAck_c)
+ {
+ bACKFailed = TRUE;
+ }
#endif
- printf("McpsDataCnf: \r\n");
- //(void)OSA_EventSet(&gTaskEvent, gMcps_Cnf_EVENT_c);
- break;
- default:
- break;
- }
- MEM_BufferFree(pMsg);
- return gErrorNoError_c;
+
+ gTaskEventFlags |= gMcps_Cnf_EVENT_c;
+ break;
+
+ default:
+ break;
+ }
+
+ eventsThread->signal_set(0x1);
+ MEM_BufferFree(pMsg);
+
+ return gErrorNoError_c;
}
void InitProject(void)
@@ -143,11 +221,11 @@
bACKFailed = FALSE;
bCCAFailed = FALSE;
#endif
- bTxInProgress = FALSE;
- bTxDone = FALSE;
- evKeyPressed = FALSE;
+
+ gTaskEventFlags = 0;
+
txConfigContext.autoAck = FALSE;
txConfigContext.ccaBeforeTx = FALSE;
txConfigContext.retryCountAckFail = 0;
txConfigContext.retryCountCCAFail = 0;
-}
\ No newline at end of file
+}
