The MCR20A Wireless UART application functions as an wireless UART bridge between two (one-to-one) or several (one to many) boards. The application can be used with both a TERM, or with software that is capable of opening a serial port and writing to or reading from it. The characters sent or received are not necessarily ASCII printable characters.

Dependencies:   fsl_phy_mcr20a fsl_smac mbed-rtos mbed

Fork of mcr20_wireless_uart by Freescale

By default, the application uses broadcast addresses for OTA communication. This way, the application can be directly downloaded and run without any user intervention. The following use case assumes no changes have been done to the project.

  • Two (or more) MCR20A platforms (plugged into the FRDM-K64F Freescale Freedom Development platform) have to be connected to the PC using the mini/micro-USB cables.
  • The code must be downloaded on the platforms via CMSIS-DAP (or other means).
  • After that, two or more TERM applications must be opened, and the serial ports must be configured with the same baud rate as the one in the project (default baud rate is 115200). Other necessary serial configurations are 8 bit, no parity, and 1 stop bit.
  • To start the setup, each platform must be reset, and one of the (user) push buttons found on the MCR20A platform must be pressed. The user can press any of the non-reset buttons on the FRDM-K64F Freescale Freedom Development platform as well. *This initiates the state machine of the application so user can start.

Documentation

SMAC Demo Applications User Guide

Revision:
19:71b793021c78
Parent:
18:b02fc0e53df8
Child:
20:933513bba8a1
--- a/IEEE802_14_5_PHY/driverRFinterface.c	Fri Apr 03 05:23:33 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,447 +0,0 @@
-/*
- * driverRFinterface.c
- *
- *  Created on: 12 March 2015
- *      Author: mBed Team
- */
-
-#include "EmbeddedTypes.h"
-#include "Phy.h"
-#include "driverRFinterface.h"
-
-#if 0
-#include "arm_hal_interrupt.h"
-#include "arm_hal_phy.h"
-
-static uint8_t fsl_MAC[8];
-static phy_device_driver_s device_driver;
-static phy_device_channel_info_s channel_info;
-
-static uint8_t rf_channel;
-static int8_t rf_radio_driver_id = -1;
-
-static uint8_t mac_tx_handle = 0;
-static uint8_t tx_sequence = 0xff;
-static macToPdDataMessage_t *pPdSapMsg = NULL;
-
- /*
- * \brief Function sets the MAC address array.
- *
- * \param ptr Pointer to given MAC address array
- *
- * \return none
- */
-void rf_set_mac_address(const uint8_t *ptr)
-{
-    memcpy(fsl_MAC,ptr,8);
-}
-
-/*
- * \brief Function initialises and registers the RF driver.
- *
- * \param none
- *
- * \return rf_radio_driver_id Driver ID given by NET library
- */
-int8_t rf_device_register(void)
-{
-    //rf_init();
-   
-    Phy_Init();
-    Phy_RegisterSapHandlers( (PD_MAC_SapHandler_t)PD_PLME_MAC_SapHandler, 
-                             (PLME_MAC_SapHandler_t)PD_PLME_MAC_SapHandler, 
-                             0);
-    PhyPlmeSetPwrState( gPhyPwrAutodoze_c );
-    PhyPlmeSetRxOnWhenIdle( TRUE, 0 );
-    PhyPpSetPromiscuous(0);
-
-    /*Set pointer to MAC address*/
-    device_driver.PHY_MAC = fsl_MAC;
-    device_driver.driver_description = "FSL_MAC";
-#if PHY_LINK_15_4_2_4GHZ_TYPE
-      /*Number of channels in PHY*/
-        channel_info.channel_count = 16;
-        /*Channel mask 26-11*/
-        channel_info.channel_mask = 0x07FFF800;
-        /*Type of RF PHY is SubGHz*/
-        device_driver.link_type = PHY_LINK_15_4_2_4GHZ_TYPE;
-        device_driver.link_channel_info = &channel_info;
-#else
-    /*Number of channels in PHY*/
-    channel_info.channel_count = 11;
-    /*Channel mask 0-10*/
-    channel_info.channel_mask = 0x000007ff;
-    /*Type of RF PHY is SubGHz*/
-    device_driver.link_type = PHY_LINK_15_4_SUBGHZ_TYPE;
-    device_driver.link_channel_info = &channel_info;
-#endif
-   /*Maximum size of payload is 127*/
-    device_driver.phy_MTU = 127;
-    /*No header in PHY*/
-    device_driver.phy_header_length = 0;
-    /*No tail in PHY*/
-    device_driver.phy_tail_length = 0;
-    /*Set address write function*/
-    device_driver.phy_xx_address_write = &rf_address_write;
-    /*Set RF extension function*/
-    device_driver.phy_xx_extension = &rf_extension;
-    /*Set RF state control function*/
-    device_driver.phy_xx_state_control = &rf_interface_state_control;
-    /*Set transmit function*/
-    device_driver.phy_xx_tx = &rf_tx;
-    printf("RF Device Registration...");
-    /*Register device driver*/
-    rf_radio_driver_id = arm_net_phy_register(&device_driver);
-    printf("OK\r\n");   
-    return rf_radio_driver_id;
-}
-
-/*! *********************************************************************************
-* \brief  Sends a PD message from PHY to MAC
-*
-* \param[in]  pMsg pointer to the Phy Message
-* \param[in]  id the MAC instance which should be updated
-*
-* \return  resultType_t
-*
-********************************************************************************** */
-void PD_PLME_MAC_SapHandler( void* pMsg, instanceId_t id )
-{
-    pdDataToMacMessage_t* pPhyMsg = pMsg;
-    phy_link_tx_status_e phy_status = PHY_LINK_TX_FAIL;
-    uint8_t * pPsdu;
-    uint8_t psduLength = 0;
-    uint8_t lqi = 0;
-    
-    int retval = 5;
-    
-    switch(pPhyMsg->msgType)
-    {
-        case gPdDataCnf_c:
-            switch(pPhyMsg->msgData.dataCnf.status)
-            {
-                case gPhySuccess_c:
-                    phy_status = PHY_LINK_TX_DONE;
-                    break;
-                 
-                case gPhyChannelBusy_c:
-                    phy_status = PHY_LINK_CCA_FAIL;
-                    break;
-                    
-                case gPhyNoAck_c:
-                    phy_status = PHY_LINK_TX_DONE_PENDING;
-                    break;
-
-                case gPhyBusy_c:                    
-                default:
-                    break;
-            }
-            
-            //free PHY PdSap Structure
-            MEM_BufferFree(pPdSapMsg);
-            
-            /*Call PHY TX Done API*/
-            arm_net_phy_tx_done(rf_radio_driver_id, mac_tx_handle, phy_status, 1, 1);
-            //printf("MSG: TX Done. \r\n");
-            break;
-
-        case gPdDataInd_c:
-            psduLength = pPhyMsg->msgData.dataInd.psduLength;
-            pPsdu = MEM_BufferAlloc(psduLength);
-            lqi = pPhyMsg->msgData.dataInd.ppduLinkQuality;
-            FLib_MemCpy(pPsdu, pPhyMsg->msgData.dataInd.pPsdu, psduLength);
-
-            //free PHY PdSap Structure
-            MEM_BufferFree(pPdSapMsg);
-            
-            //retval = arm_net_phy_rx(pPhyMsg->msgData.dataInd.pPsdu, pPhyMsg->msgData.dataInd.psduLength, pPhyMsg->msgData.dataInd.ppduLinkQuality, rf_radio_driver_id);
-            retval = arm_net_phy_rx(pPsdu, psduLength, lqi, rf_radio_driver_id);
-            
-            if(-1 == retval)
-            {
-                //printf("MSG: RX Error. \r\n");
-                while(1);
-            }
-            //printf("MSG: RX Done. \r\n");
-            break;
-
-        default:
-            break;
-    }
-}
-#endif
-#if 0
-
-typedef enum
-{
-	PHY_LINK_TX_DONE, 			/**< TX process Ready and ACK RX */
-	PHY_LINK_TX_DONE_PENDING,	/**< TX process OK with ACK pending flag*/
-	PHY_LINK_TX_SUCCESS, 		/**< MAC TX complete MAC will make decission to enter wait ack or TX Done state*/
-	PHY_LINK_TX_FAIL, 			/**< Link TX process fail*/
-	PHY_LINK_CCA_FAIL,			/**< RF Link CCA process fail */
-} phy_link_tx_status_e;
-#endif
-#if 0
-/*
- * \brief Function sets the addresses to RF address filters.
- *
- * \param address_type Type of address
- * \param address_ptr Pointer to given address
- *
- * \return 0 Success
- */
-static int8_t rf_address_write(phy_address_type_e address_type, uint8_t *address_ptr)
-{
-    int8_t ret_val = 0;
-    uint64_t temp64 = 0;
-    uint16_t temp16 = 0;
-    
-    switch (address_type)
-    {
-        /*Set 48-bit address*/
-        case PHY_MAC_48BIT:
-            break;
-            /*Set 64-bit address*/
-        case PHY_MAC_64BIT:
-            temp64 = atouint64(address_ptr);
-            temp64 = NWKU_Revert64(temp64);
-            PhyPlmeSetPIBRequest(gPhyPibLongAddress_c, temp64,  0, 0 );
-            break;
-        /*Set 16-bit address*/
-        case PHY_MAC_16BIT:
-            temp16 = atouint16(address_ptr);
-            PhyPlmeSetPIBRequest(gPhyPibShortAddress_c, temp16, 0, 0 );
-            break;
-        /*Set PAN Id*/
-        case PHY_MAC_PANID:
-            temp16 = atouint16(address_ptr);
-            PhyPlmeSetPIBRequest(gPhyPibPanId_c, temp16, 0, 0 );
-            break;
-    }
-    return ret_val;
-}
-
-/*
- * \brief Function controls the ACK pending, channel setting and energy detection.
- *
- * \param extension_type Type of control
- * \param data_ptr Data from NET library
- *
- * \return 0 Success
- */
-static int8_t rf_extension(phy_extension_type_e extension_type, uint8_t *data_ptr)
-{
-    switch (extension_type)
-    {
-        /*Control MAC pending bit for Indirect data transmission*/
-        case PHY_EXTENSION_CTRL_PENDING_BIT:
-            if(*data_ptr)
-            {
-                //rf_if_ack_pending_ctrl(1);
-            }
-            else
-            {
-                //rf_if_ack_pending_ctrl(0);
-            }
-            break;
-        /*Return frame pending status*/
-        case PHY_EXTENSION_READ_LAST_ACK_PENDING_STATUS:
-            //*data_ptr = rf_if_last_acked_pending();
-            break;
-        /*Set channel*/
-        case PHY_EXTENSION_SET_CHANNEL:
-            break;
-        /*Read energy on the channel*/
-        case PHY_EXTENSION_READ_CHANNEL_ENERGY:
-            break;
-        /*Read status of the link*/
-        case PHY_EXTENSION_READ_LINK_STATUS:
-            break;
-    }
-    return 0;
-}
-
-/*
- * \brief Function gives the control of RF states to MAC.
- *
- * \param new_state RF state
- * \param rf_channel RF channel
- *
- * \return 0 Success
- */
-static int8_t rf_interface_state_control(phy_interface_state_e new_state, uint8_t rf_channel)
-{
-    int8_t ret_val = 0;
-    switch (new_state)
-    {
-        /*Reset PHY driver and set to idle*/
-        case PHY_INTERFACE_RESET:
-            break;
-        /*Disable PHY Interface driver*/
-        case PHY_INTERFACE_DOWN:
-            //PhyPlmeForceTrxOffRequest();
-            //rf_shutdown();
-            break;
-        /*Enable PHY Interface driver*/
-        case PHY_INTERFACE_UP:
-            //PhyPlmeSetPwrState( gPhyPwrAutodoze_c );
-            //PhyPlmeSetRxOnWhenIdle( TRUE, 0 );
-            //PhyPpSetPromiscuous(0);
-            //rf_channel_set(rf_channel);
-            //rf_receive();
-            break;
-        /*Enable wireless interface ED scan mode*/
-        case PHY_INTERFACE_RX_ENERGY_STATE:
-            break;
-    }
-    return ret_val;
-}
-
-
-/*
- * \brief Function starts the CCA process before starting data transmission and copies the data to RF TX FIFO.
- *
- * \param data_ptr Pointer to TX data
- * \param data_length Length of the TX data
- * \param tx_handle Handle to transmission
- * \return 0 Success
- * \return -1 Busy
- */
-int8_t rf_tx(uint8_t *data_ptr, uint16_t data_length, uint8_t tx_handle)
-{
-    /*Store TX handle*/
-    mac_tx_handle = tx_handle;
-
-    /*Store the sequence number for ACK handling*/
-    tx_sequence = *(data_ptr + 2);
-        
-    pPdSapMsg = MEM_BufferAlloc(sizeof(macToPdDataMessage_t));
-    pPdSapMsg->macInstance   = 0;
-    pPdSapMsg->msgType       = gPdDataReq_c;
-
-    /*Check if transmitted data needs to be acked*/
-    if(*data_ptr & 0x20)
-    {
-        pPdSapMsg->msgData.dataReq.ackRequired  = gPhyRxAckRqd_c;
-    }
-    else
-    {
-        pPdSapMsg->msgData.dataReq.ackRequired  = gPhyNoAckRqd_c;
-    }
-    
-    pPdSapMsg->msgData.dataReq.startTime    = gPhySeqStartAsap_c;
-    pPdSapMsg->msgData.dataReq.txDuration   = gPhySeqStartAsap_c;
-    pPdSapMsg->msgData.dataReq.CCABeforeTx  = gPhyCCAMode1_c;
-    pPdSapMsg->msgData.dataReq.slottedTx    = gPhyUnslottedMode_c;
-    pPdSapMsg->msgData.dataReq.pPsdu        = data_ptr;
-    pPdSapMsg->msgData.dataReq.psduLength   = data_length;
-
-    MAC_PD_SapHandler(pPdSapMsg, 0);
-
-    
-#if 0
-    /*Check if transmitter is busy*/
-    if((rf_if_read_trx_state() == BUSY_RX_AACK) || (rf_if_read_trx_state() == BUSY_RX))
-    {
-        /*Return busy*/
-        return -1;
-    }
-    else
-    {
-        arm_enter_critical();
-        /*Check if transmitted data needs to be acked*/
-        if(*data_ptr & 0x20)
-            need_ack = 1;
-        else
-            need_ack = 0;
-        /*Store the sequence number for ACK handling*/
-        tx_sequence = *(data_ptr + 2);
-        /*Set radio in RX state to read channel*/
-        rf_receive();
-        /*Write TX FIFO*/
-        rf_if_write_frame_buffer(data_ptr, (uint8_t)data_length);
-        rf_flags_set(RFF_CCA);
-        /*Start CCA process*/
-        rf_if_enable_cca_ed_done_interrupt();
-        rf_if_start_cca_process();
-        /*Store TX handle*/
-        mac_tx_handle = tx_handle;
-        arm_exit_critical();
-    }
-#endif
-    
-    /*Return success*/
-    return 0;
-}
-
-/*
- * \brief Function sets the RF channel.
- *
- * \param ch New channel
- *
- * \return none
- */
-void rf_channel_set(uint8_t ch)
-{
-    //arm_enter_critical();
-    if(ch < 0x1f)
-    {
-        rf_channel = ch;
-        PhyPlmeSetPIBRequest(gPhyPibCurrentChannel_c, ch, 0, 0 );
-    }
-    //arm_exit_critical();
-}
-#endif
-
-uint16_t atouint16
-(
-    uint8_t* pArray
-)
-{
-    uuint16_t out = {0};
-
-    out.u8[1] = *pArray++;
-    out.u8[0] = *pArray;
-
-    return out.u16;
-}
-
-uint64_t atouint64
-(
-    uint8_t* pArray
-)
-{
-    uuint64_t out;
-
-    out.u8[7] = *pArray++;
-    out.u8[6] = *pArray++;
-    out.u8[5] = *pArray++;
-    out.u8[4] = *pArray++;   
-    out.u8[3] = *pArray++;
-    out.u8[2] = *pArray++;
-    out.u8[1] = *pArray++;
-    out.u8[0] = *pArray;
-
-    return out.u64;
-}
-
-uint64_t NWKU_Revert64
-(
-    uint64_t value
-)
-{
-    uuint64_t in;
-    uuint64_t out;
-    in.u64 = value;
-
-    out.u8[0] = in.u8[7];
-    out.u8[1] = in.u8[6];
-    out.u8[2] = in.u8[5];
-    out.u8[3] = in.u8[4];
-    out.u8[4] = in.u8[3];
-    out.u8[5] = in.u8[2];
-    out.u8[6] = in.u8[1];
-    out.u8[7] = in.u8[0];
-
-    return out.u64;
-}