| 66 | |
| 67 | The examples assume some values are defined elsewhere in user code. These variables are used for convenience, and are borrowed from our full MAC implementations in the [wiki:OFDMReferenceDesign OFDM Reference Design]. |
| 68 | * {{{PKTHEADER_INDX_TYPE}}}: is the byte index of the pktType field in the header |
| 69 | * {{{PKTHEADER_INDX_RELADDR}}}: is the byte index of the relAddr field in the header |
| 70 | * {{{PKTHEADER_INDX_SRCADDR}}}: is the byte index of the srcAddr field in the header |
| 71 | * {{{PKTHEADER_INDX_DSTADDR}}}: is the byte index of the dstAddr field in the header |
| 72 | * {{{ACKPACKET}}}: and DATAPACKET are (unsigned char) values specifying packet types |
| 73 | * {{{MY_ADDR}}}: is the (unsigned short int) value of the local node's MAC address |
| 74 | * {{{pktBuf_tx_ACK}}}: is the index (in [1,30]) of a PHY packet buffer used for transmitting ACKs |
| 75 | * {{{pktBuf_rx}}}: is the index (in [1,30]) of the PHY packet buffer where received packets are written |
| 120 | |
| 121 | === Simple Multi-hop === |
| 122 | This example configures the PHY to automatically re-transmit received DATA packets, overwriting the source MAC address with the node's own address. |
| 123 | |
| 124 | {{{ |
| 125 | #!C |
| 126 | //Configure match unit 0 to search for packets whose relay address matches this node's address |
| 127 | // Looks for 2 bytes starting at index PKTHEADER_INDX_RELAYADDR with value MY_ADDR |
| 128 | mimo_ofdmTxRx_setMatch0( PHY_AUTORESPONSE_MATCH_CONFIG(PKTHEADER_INDX_RELADDR, 2, MY_ADDR) ); |
| 129 | |
| 130 | //Configure match unit 1 to search for DATA packets |
| 131 | // Looks for 1 byte starting at index PKTHEADER_INDX_TYPE with value DATAPACKET |
| 132 | mimo_ofdmTxRx_setMatch1( PHY_AUTORESPONSE_MATCH_CONFIG(PKTHEADER_INDX_TYPE, 1, DATAPACKET) ); |
| 133 | |
| 134 | //Configure the header translator to replace the outgoing source address with the received relay address |
| 135 | PHY_HEADERTRANSLATE_SET(pktBuf_rx, (PKTHEADER_INDX_SRCADDR+0), pktBuf_rx, (PKTHEADER_INDX_RELADDR+0)); |
| 136 | PHY_HEADERTRANSLATE_SET(pktBuf_rx, (PKTHEADER_INDX_SRCADDR+1), pktBuf_rx, (PKTHEADER_INDX_RELADDR+1)); |
| 137 | |
| 138 | //Configure actor 0 to transit the received packet using the header translator |
| 139 | // after 5µs when the PHY receives a good data packet using this node as a relay |
| 140 | mimo_ofdmTxRx_setAction0( |
| 141 | PHY_AUTORESPONSE_TXACTION_CONFIG(pktBuf_rx, PHY_AUTORESPONSE_ACT_TRANS_HDR, 20, |
| 142 | (PHY_AUTORESPONSE_REQ_MATCH0 | PHY_AUTORESPONSE_REQ_MATCH1 | PHY_AUTORESPONSE_REQ_GOODHDR | PHY_AUTORESPONSE_REQ_GOODPKT))); |
| 143 | |
| 144 | //Disable the unused actors |
| 145 | mimo_ofdmTxRx_setAction1(0); |
| 146 | mimo_ofdmTxRx_setAction2(0); |
| 147 | mimo_ofdmTxRx_setAction3(0); |
| 148 | mimo_ofdmTxRx_setAction4(0); |
| 149 | mimo_ofdmTxRx_setAction5(0); |
| 150 | }}} |