atsamr34_long_range_p2p icon indicating copy to clipboard operation
atsamr34_long_range_p2p copied to clipboard

System breaks after several iterations (p2p_demo.c implementation)

Open victorK8 opened this issue 2 years ago • 0 comments

Hi,

We are using that library. After some iterations of sending LoRa messages, system breaks.

We check that the problem is the function that send data to nodes. There is no MiMemFree, so heap of WLR089 breaks in some moment.

void p2p_demo_send_data(uint8_t msgType, uint8_t targetAddr, uint8_t *data, uint8_t len)
{
#ifdef DUTY_CYCLING
	remainingDutyCycleDuration = SwTimerReadValue(DutyCyclingTimerId) ;
	#if defined (ENABLE_CONSOLE)
	printf("\r\nRemaining duty cycling duration to wait before sending next app data: %ld us\r\n", remainingDutyCycleDuration) ;
	#endif
	if (remainingDutyCycleDuration)
	{
		#if defined (ENABLE_CONSOLE)
		printf("NO_FREE_CH\r\n") ;
		#endif
		return ;
	}
#endif // #ifdef DUTY_CYCLING
	
	uint8_t* dataPtr = NULL ;
	uint8_t dataLen = 0 ;
	uint16_t broadcastAddress = 0xFFFF ;
	bool sendData_status ;	

	dataPtr = MiMem_Alloc(CALC_SEC_PAYLOAD_SIZE(len)) ;
	if (NULL == dataPtr)
		return ;
	
	for (i = 0; i < len; i++)
	{
		dataPtr[dataLen++] = data[i] ;
	}
#if defined(ENABLE_SLEEP_FEATURE)
	// to not enter to the sleep loop until data has been sent
	send_data = 1;
#endif // #if defined(ENABLE_SLEEP_FEATURE)

#if defined (ENABLE_CONSOLE)
	if (msgType == UNICAST)
	{
		printf("\r\nSending unicast message to %02d-%02x%02x%02x\r\n", targetAddr, ConnectionTable[targetAddr].Address[0], ConnectionTable[targetAddr].Address[1], ConnectionTable[targetAddr].Address[2]) ;		
	}
	else
	{
		printf("\r\nSending broadcast message\r\n") ;
	}
#endif

#ifdef DUTY_CYCLING
	appDataPhyLen = dataLen ;
#endif // #ifdef DUTY_CYCLING

	if (msgType == UNICAST)
	{
		// unicast message
		sendData_status = MiApp_SendData(LONG_ADDR_LEN, ConnectionTable[targetAddr].Address, dataLen, dataPtr, msghandledemo++, 1, dataConfcb) ;
	}
	else
	{
		// broadcast message
		sendData_status = MiApp_SendData(SHORT_ADDR_LEN, (uint8_t *)&broadcastAddress, dataLen, dataPtr, msghandledemo++, true, dataConfcb) ;
	}

	if (sendData_status == false)
	{
#if defined(ENABLE_SLEEP_FEATURE)
		PHY_DataConf(FAILURE);
#endif // #if defined(ENABLE_SLEEP_FEATURE)
		if (msgType == UNICAST)
			DemoOutput_UnicastFail();
		else
			DemoOutput_BroadcastFail() ;
	}
	else
	{
		// Successful Transmission
		TxNum++ ;
		SwTimerStart (TxTimerId, MS_TO_US(5000), 0/*SW_TIMEOUT_RELATIVE*/, (void *)TxToutCallback, NULL) ;
	}
	// Update the LCD
	DemoOutput_UpdateTxRx(TxNum, RxNum);
	DemoOutput_Instruction();
	printf("Tx Messages: %d - Rx Messages: %d\r\n", TxNum, RxNum) ;	
}

victorK8 avatar Jul 20 '22 15:07 victorK8