1
0

change way to send token

This commit is contained in:
Rémi Heredero 2024-04-24 15:25:06 +02:00
parent d5e1467b3f
commit a0ce103a16
3 changed files with 75 additions and 27 deletions

View File

@ -6,4 +6,4 @@ C R |
1 0 | Sapi on the station isn't connected -> Error msg on lcd 1 0 | Sapi on the station isn't connected -> Error msg on lcd
1 1 | Everything all right -> free 1 1 | Everything all right -> free
Frome someone else -> Send back now From someone else -> Send back now

View File

@ -6,13 +6,25 @@
#include <cassert> #include <cassert>
uint8_t* lastToken; uint8_t* lastToken;
uint8_t* lastSentMsgPtr[15]; uint8_t* lastSentMsgPtr;
osMessageQueueId_t queue_macData_id; osMessageQueueId_t queue_macData_id;
const osMessageQueueAttr_t queue_macData_attr = { const osMessageQueueAttr_t queue_macData_attr = {
.name = "MAC_DATA" .name = "MAC_DATA"
}; };
void sendToken() {
struct queueMsg_t queueMsg;
queueMsg.anyPtr = lastToken;
queueMsg.type = TO_PHY;
osStatus_t retCode = osMessageQueuePut(
queue_phyS_id,
&queueMsg,
osPriorityNormal,
0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
}
void MacSender(void *argument) { void MacSender(void *argument) {
struct queueMsg_t queueMsg; // queue message struct queueMsg_t queueMsg; // queue message
uint8_t* msg; uint8_t* msg;
@ -75,17 +87,9 @@ void MacSender(void *argument) {
osPriorityNormal, osPriorityNormal,
0); 0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
} else {
sendToken();
} }
// Send token
queueMsg.anyPtr = lastToken;
queueMsg.type = TO_PHY;
retCode = osMessageQueuePut(
queue_phyS_id,
&queueMsg,
osPriorityNormal,
0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
break; break;
} }
@ -101,8 +105,9 @@ void MacSender(void *argument) {
if(dst.addr == BROADCAST_ADDRESS) { if(dst.addr == BROADCAST_ADDRESS) {
retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
sendToken();
} else if(src.addr != gTokenInterface.myAddress) { } else if(src.addr != gTokenInterface.myAddress) {
// Send original message when token is here
queueMsg.type = TO_PHY; queueMsg.type = TO_PHY;
retCode = osMessageQueuePut( retCode = osMessageQueuePut(
queue_phyS_id, queue_phyS_id,
@ -116,14 +121,17 @@ void MacSender(void *argument) {
// Everything is fine, free memory // Everything is fine, free memory
retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
sendToken();
} else { } else {
// Checksum error, send original message again when token is here // Checksum error, send original message again
if(lastSentMsgPtr[src.addr] != NULL) { if(lastSentMsgPtr != NULL) {
queueMsg.anyPtr = lastSentMsgPtr[src.addr]; retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
queueMsg.type = TO_PHY; queueMsg.type = TO_PHY;
queueMsg.anyPtr = lastSentMsgPtr;
retCode = osMessageQueuePut( retCode = osMessageQueuePut(
queue_macData_id, queue_phyS_id,
&queueMsg, &queueMsg,
osPriorityNormal, osPriorityNormal,
0); 0);
@ -132,7 +140,7 @@ void MacSender(void *argument) {
} else { } else {
// Error, no original message found // Error, no original message found
strPtr = osMemoryPoolAlloc(memPool, osWaitForever); strPtr = osMemoryPoolAlloc(memPool, osWaitForever);
sprintf(strPtr, "Someone did shit on the ring #1\0"); sprintf(strPtr, "%d did shit on the ring #1\0", dst.addr);
queueMsg.type = MAC_ERROR; queueMsg.type = MAC_ERROR;
queueMsg.addr = src.addr; queueMsg.addr = src.addr;
queueMsg.sapi = src.sapi; queueMsg.sapi = src.sapi;
@ -147,13 +155,7 @@ void MacSender(void *argument) {
} }
} else { } else {
// Send original message when token is here retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr);
queueMsg.type = TO_PHY;
retCode = osMessageQueuePut(
queue_macData_id,
&queueMsg,
osPriorityNormal,
0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
// Send error message to LCD // Send error message to LCD
@ -169,6 +171,8 @@ void MacSender(void *argument) {
osPriorityNormal, osPriorityNormal,
0); 0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
sendToken();
} }
break; break;
@ -248,6 +252,12 @@ void MacSender(void *argument) {
retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
if(dst.addr != BROADCAST_ADDRESS) {
lastSentMsgPtr = osMemoryPoolAlloc(memPool, osWaitForever);
memcpy(lastSentMsgPtr, msg, length+4);
}
queueMsg.anyPtr = msg; queueMsg.anyPtr = msg;
queueMsg.type = TO_PHY; queueMsg.type = TO_PHY;
retCode = osMessageQueuePut( retCode = osMessageQueuePut(

View File

@ -120,7 +120,7 @@
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>EVENTREC_CNF</Key> <Key>EVENTREC_CNF</Key>
<Name>-l0 -a1 -s0 -f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</Name> <Name>-l2 -a1 -s0 -f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</Name>
</SetRegEntry> </SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
@ -153,7 +153,40 @@
<Name>UL2CM3(-S0 -C0 -P0 -FD20010000 -FC1000 -FN1 -FF0STM32F7x_1024 -FS08000000 -FL0100000 -FP0($$Device:STM32F746NGHx$CMSIS\Flash\STM32F7x_1024.FLM))</Name> <Name>UL2CM3(-S0 -C0 -P0 -FD20010000 -FC1000 -FN1 -FF0STM32F7x_1024 -FS08000000 -FL0100000 -FP0($$Device:STM32F746NGHx$CMSIS\Flash\STM32F7x_1024.FLM))</Name>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint/> <Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>18</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134311210</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\mac_receiver.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\tokenring_project\mac_receiver.c\18</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>199</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>.\main.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
</Breakpoint>
<WatchWindow1> <WatchWindow1>
<Ww> <Ww>
<count>0</count> <count>0</count>
@ -175,6 +208,11 @@
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>lastToken</ItemText> <ItemText>lastToken</ItemText>
</Ww> </Ww>
<Ww>
<count>4</count>
<WinNumber>1</WinNumber>
<ItemText>queue_macData_id</ItemText>
</Ww>
</WatchWindow1> </WatchWindow1>
<MemoryWindow1> <MemoryWindow1>
<Mm> <Mm>