2023-05-04 09:09 AM
Hi,
I need some help trying to undestand this operation in Lorawan_end_node example project
nvm_size = ( ( sizeof( LoRaMacNvmData_t ) + 7 ) & ~0x07 ); in the code below:
Maybe it is so simple, but i thought that it would be something like that
nvm_size = sizeof( LoRaMacNvmData_t );
Thanks in advance
LmHandlerErrorStatus_t LmHandlerNvmDataStore( void )
{
#if (defined( CONTEXT_MANAGEMENT_ENABLED ) && ( CONTEXT_MANAGEMENT_ENABLED == 1 ))
LoRaMacNvmData_t *nvm;
uint32_t nvm_size;
LmHandlerErrorStatus_t lmhStatus = LORAMAC_HANDLER_SUCCESS;
int32_t status = NVM_DATA_OK;
lmhStatus = LmHandlerHalt();
if( lmhStatus == LORAMAC_HANDLER_SUCCESS )
{
status = NvmDataMgmtStoreBegin();
if( status == NVM_DATA_NO_UPDATED_DATA )
{
lmhStatus = LORAMAC_HANDLER_NVM_DATA_UP_TO_DATE;
}
else if( ( status != NVM_DATA_OK ) || ( LmHandlerCallbacks->OnStoreContextRequest == NULL ) )
{
lmhStatus = LORAMAC_HANDLER_ERROR;
}
else
{
MibRequestConfirm_t mibReq;
mibReq.Type = MIB_NVM_CTXS;
LoRaMacMibGetRequestConfirm( &mibReq );
nvm = ( LoRaMacNvmData_t * )mibReq.Param.Contexts;
nvm_size = ( ( sizeof( LoRaMacNvmData_t ) + 7 ) & ~0x07 );
LmHandlerCallbacks->OnStoreContextRequest( nvm, nvm_size );
}
if( NvmDataMgmtStoreEnd() != NVM_DATA_OK )
{
lmhStatus = LORAMAC_HANDLER_ERROR;
}
}
if( ( lmhStatus == LORAMAC_HANDLER_SUCCESS ) && ( LmHandlerCallbacks->OnNvmDataChange != NULL ) )
{
LmHandlerCallbacks->OnNvmDataChange( LORAMAC_HANDLER_NVM_STORE );
}
return lmhStatus;
#else
return LORAMAC_HANDLER_ERROR;
#endif /* CONTEXT_MANAGEMENT_ENABLED */
}
Solved! Go to Solution.
2023-05-04 10:38 AM
Hello @RPaja.1 and welcome to ST Community
I think that this line of code is used in order to round the size of the `LoRaMacNvmData_t` to the nearest multiple of 8 bytes.
hope this is helpful
Issam
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-05-04 10:38 AM
Hello @RPaja.1 and welcome to ST Community
I think that this line of code is used in order to round the size of the `LoRaMacNvmData_t` to the nearest multiple of 8 bytes.
hope this is helpful
Issam
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-05-05 12:33 AM
Thanks for your response @IIRHO.1 , sizeof returns the number of bytes of LoRaMacNvmData_t, in that case 1484 bytes, is it correct?
It is multiple of 8 bits, my operation, maybe is wrong is that:
nvm_size = ( ( sizeof( LoRaMacNvmData_t ) + 7 ) & ~0x07 );
nvm_size = ( ( 1484 + 7 ) & ~0x07 )
nvm_size = (1491 ) & 0xFFF8 )
nvm_size =1488
Do you mean multiple of 8 bytes?
2023-05-05 12:42 AM
Hi again @RPaja.1 yes, I mean 8 Bytes . It's just a typo. I corrected . If this is what you are looking for, please mention my answer as the best answer so that the information will be defused
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.