diff --git a/mac_receiver.c b/mac_receiver.c index 8dc3fe9..9743296 100644 --- a/mac_receiver.c +++ b/mac_receiver.c @@ -13,7 +13,10 @@ void send_DATA_IND(Adresse source, Adresse destination, uint8_t* dataFramePtr) { queueMsg.addr = source.addr; queueMsg.sapi = source.sapi; - strPtr = osMemoryPoolAlloc(memPool, osWaitForever); + strPtr = osMemoryPoolAlloc(memPool, 0); + if(strPtr == NULL) { + assert(false); + } for(uint8_t i = 0; i < dataFramePtr[2]; i++) { strPtr[i] = (char)dataFramePtr[3+i]; @@ -27,7 +30,7 @@ void send_DATA_IND(Adresse source, Adresse destination, uint8_t* dataFramePtr) { queue_timeR_id, &queueMsg, osPriorityNormal, - osWaitForever); + 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); break; case CHAT_SAPI: @@ -35,7 +38,7 @@ void send_DATA_IND(Adresse source, Adresse destination, uint8_t* dataFramePtr) { queue_chatR_id, &queueMsg, osPriorityNormal, - osWaitForever); + 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); break; default: @@ -57,7 +60,7 @@ void send_DATABACK(Adresse source, Adresse destination, uint8_t* dataFramePtr) { queue_macS_id, &queueMsg, osPriorityNormal, - osWaitForever); + 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); } @@ -102,6 +105,7 @@ void MacReceiver(void *argument) { &queueMsg, osPriorityNormal, osWaitForever); + printf("Token received\r\n"); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); } else { @@ -142,7 +146,7 @@ void MacReceiver(void *argument) { queue_phyS_id, &queueMsg, osPriorityNormal, - osWaitForever); + 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); } @@ -166,7 +170,7 @@ void MacReceiver(void *argument) { queue_phyS_id, &queueMsg, osPriorityNormal, - osWaitForever); + 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); } diff --git a/mac_sender.c b/mac_sender.c index b5303c1..5824d8d 100644 --- a/mac_sender.c +++ b/mac_sender.c @@ -1,4 +1,5 @@ #include "main.h" +#include #include uint8_t* lastToken; @@ -57,22 +58,18 @@ void MacSender(void *argument) { &queueMsg, osPriorityNormal, osWaitForever); + printf("Token sended\r\n"); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); // Send one msg from internal queue if exist - if (osMemoryPoolGetCount(queue_macData_id) != 0) { // Message in Queue - retCode = osMessageQueueGet( - queue_macData_id, - &queueMsg, - NULL, - osWaitForever); - CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + //if (osMemoryPoolGetCount(queue_macData_id) != 0) { // Message in Queue + if(osMessageQueueGet(queue_macData_id, &queueMsg, NULL, 0) == 0){ queueMsg.type = TO_PHY; retCode = osMessageQueuePut( queue_phyS_id, &queueMsg, osPriorityNormal, - osWaitForever); + 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); } @@ -83,7 +80,7 @@ void MacSender(void *argument) { queue_phyS_id, &queueMsg, osPriorityNormal, - osWaitForever); + 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); break; } @@ -97,19 +94,34 @@ void MacSender(void *argument) { length = msg[2]; status.raw = msg[3+length]; - if(status.read == 0) { + if(src.addr == BROADCAST_ADDRESS) { + retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); + CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + } + + if(status.read == 1) { if(status.ack == 0) { msg = osMemoryPoolAlloc(memPool, osWaitForever); queueMsg.type = TO_PHY; - queueMsg.anyPtr = + //queueMsg.anyPtr = } else { } } else { + // Send original message to PHY + queueMsg.type = TO_PHY; + retCode = osMessageQueuePut( + queue_macData_id, + &queueMsg, + osPriorityNormal, + 0); + CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + + // Send error message to LCD strPtr = osMemoryPoolAlloc(memPool, osWaitForever); - sprintf(strPtr, "Dest. %d couldn't read message from %d\0", dst.add+1, src.addr+1); + sprintf(strPtr, "Dest. %d couldn't read message from %d\0", dst.addr+1, src.addr+1); queueMsg.type = MAC_ERROR; queueMsg.addr = src.addr; queueMsg.sapi = src.sapi; @@ -118,7 +130,7 @@ void MacSender(void *argument) { queue_lcd_id, &queueMsg, osPriorityNormal, - osWaitForever); + 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); } break; @@ -184,7 +196,7 @@ void MacSender(void *argument) { status.ack = 0; } - msg = osMemoryPoolAlloc(memPool, osWaitForever); + msg = osMemoryPoolAlloc(memPool, osWaitForever); // TODO - Leak of memory msg[0] = src.raw; msg[1] = dst.raw; msg[2] = length; @@ -200,7 +212,7 @@ void MacSender(void *argument) { queue_macData_id, &queueMsg, osPriorityNormal, - osWaitForever); + 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); break; } diff --git a/main.h b/main.h index 7375580..5c94e42 100644 --- a/main.h +++ b/main.h @@ -138,4 +138,4 @@ typedef union { uint8_t checksum: 6; // LSB }; uint8_t raw; -} Status; \ No newline at end of file +} Status;