206 | | |
207 | | |
208 | | The transmitter can send new packets, resend old packets, send ACKs and send nACKs, depending on what state the machine is in when it is called. To help abstraction, the transmitter does not directly send packets. Instead, it passes them off to a dedicated function that interfaces directly with the PHY layer (see mem2ifc). |
209 | | |
210 | | [source:/ResearchApps/MAC/ACKMAC/src/ackmac.c@91#L629 rx] |
211 | | |
212 | | The receiver gets called by the PHY receiver whenever it has received a packet. The receiver has different behavior depending on whether the packet received was destined for itself or another node. Also, it sets the state machine appropriately depending on what was received (ACK, nACK, or data). |
213 | | |
214 | | [source:/ResearchApps/MAC/ACKMAC/src/ackmac.c@91#L238 timer_a_int_handler] |
215 | | |
216 | | |
217 | | [source:/ResearchApps/MAC/ACKMAC/src/ackmac.c@91#L773 setTimer] |
218 | | |
219 | | The setTimer function allows the use of software timers for the MAC. Currently, the two types of timers needed are timeouts and backoffs. The timeout is a preset amount of time that the node is willing to wait for an ACK before retransmitting. The backoff occurs whenever a collision is inferred. The backoff is an exponential uniformly distributed random variable. |
220 | | |
221 | | [source:/ResearchApps/MAC/ACKMAC/src/ackmac.c@91#L844 writeMem2Ifc] |
222 | | |
223 | | This function is responsible for converting the frameStruct type into an array of bytes to be sent in the PHY layer. Because this conversion effectively defines the frame format, placing this into its own function allows us to upgrade frame formats without affecting the behavior of the MAC itself. |
224 | | |
225 | | [source:/ResearchApps/MAC/ACKMAC/src/ackmac.c@91#L910 writeIfc2Mem] |
226 | | |
227 | | This is the inverse process of the previous function. This converts the array of bytes back into something that the MAC can understand (the frameStruct type). |
228 | | |
229 | | [source:/ResearchApps/MAC/ACKMAC/src/ackmac.c@91#L968 writeMem2Mem] |
230 | | |
231 | | This is responsible for copying received packet structure into receive queue for higher layers to access. |
232 | | |
233 | | [source:/ResearchApps/MAC/ACKMAC/src/ackmac.c@91#L997 checkSum] |
234 | | |
235 | | The checksum is used to infer corrupted data upon receipt of a packet. This checksum is a very simple addition of bytes. If we choose to implement other checksum algorithms, we can replace this function without the MAC even knowing. |