Strange problem on aes128 module

9 posts / 0 new
Last post
summer20100514
Offline
Last seen:4 years 3 months ago
Guru
加入:2014-12-30 05:01
Strange problem on aes128 module

I am working on project DA14580_DIALOG_BEACONS_3.40.2, and I need do some encryption work when necessary. The aes128 module is working well, but I found a strange problem yesterday. I do some operations as follows.

I'm using the extended sleep mode.

First I send gapm_use_enc_block_cmd in app_adv_func():

void app_adv_func(struct gapm_start_advertise_cmd *cmd)
{
// Advertising Data

// Scan Response Data

app_env.enc_in_use = true;//encryption moudule busy

//send encryption command
struct gapm_use_enc_block_cmd *cmd = KE_MSG_ALLOC(GAPM_USE_ENC_BLOCK_CMD,
TASK_GAPM, TASK_APP,
gapm_use_enc_block_cmd);
cmd->operation = GAPM_USE_ENC_BLOCK;
memcpy (cmd - > operand_1 app_env。关键,16);
memcpy(cmd->operand_2, app_env.plaintext, 16);

// Send the message
ke_msg_send(cmd);

}

Second I do some printing and set one flag to indicate the encryption is completed.

int gapm_use_enc_block_ind_handler(ke_msg_id_t msgid,
struct gapm_use_enc_block_ind *param,
ke_task_id_t dest_id,
ke_task_id_t src_id)
{
arch_printf("data encryption cpl\r\n");

app_env.enc_in_use = false;//the flag is used to indicate that encryption moudule is idle now

app_adv_stop();//encryption complete, stop advertising to update data

return (KE_MSG_CONSUMED);
}

Finally I check the app_env.enc_in_use flag and wait for encryption module idle, then send another encryption cmd

void app_set_dev_config_complete_func(void)
{
ke_state_set(TASK_APP, APP_CONNECTABLE);

app_adv_start();

while(app_env.enc_in_use);//check flag and wait for encryption moudule idle

app_env.enc_in_use = true;//encryption moudule busy

//send encryption command
struct gapm_use_enc_block_cmd *cmd = KE_MSG_ALLOC(GAPM_USE_ENC_BLOCK_CMD,
TASK_GAPM, TASK_APP,
gapm_use_enc_block_cmd);
cmd->operation = GAPM_USE_ENC_BLOCK;
memcpy (cmd - > operand_1 app_env。关键,16);
memcpy(cmd->operand_2, app_env.plaintext, 16);

// Send the message
ke_msg_send(cmd);
}

The result is encryption module won't work and the code is executing while(app_env.enc_in_use); all the time. At the same time, of course, print nothing.

But after I comment the line while(app_env.enc_in_use); in void app_set_dev_config_complete_func(void), the encrytion module works well and print "data encryption cpl" successfully.

一个s you can see, I need to do two encryption operations after some initialization procedure.

summer20100514
Offline
Last seen:4 years 3 months ago
Guru
加入:2014-12-30 05:01
一个ny suggestions?

一个ny suggestions?

WT_Dialog (not verified)
Hi,

Hi,

while(app_env.enc_in_use);//check flag and wait for encryption moudule idle
please bear in mind the whole system is non preemptive. once the while loop starts, the whole system is blocked by this while loop.

Thereforeapp_env.enc_in_use will not get updated. So the code could end up in deadlock. I think that is what is happening.

summer20100514
Offline
Last seen:4 years 3 months ago
Guru
加入:2014-12-30 05:01
@WT_Dialog, thank you, but I

@WT_Dialog, thank you, but I still have one question. Is it true that interrupts (caused by timer, external pin signal etc.) in the system are non preemptive either?

WT_Dialog (not verified)
Hi there, the interrupts are

Hi there, the interrupts are preemptive. But the tasks (TASK_APP, TASK_GAPC etc..) are not preemptive.

summer20100514
Offline
Last seen:4 years 3 months ago
Guru
加入:2014-12-30 05:01
You solved my problem, thank

You solved my problem, thank you.

summer20100514
Offline
Last seen:4 years 3 months ago
Guru
加入:2014-12-30 05:01
Could you please give me more

Could you please give me more detailed explanations about the interrupt system of DA14580 ? Recently I met one strange problem which the external interrupt is not detected once in a while. Thanks.

summer20100514
Offline
Last seen:4 years 3 months ago
Guru
加入:2014-12-30 05:01
For example, are there any

For example, are there any side effects in using GLOBAL_INT_DISABLE() and GLOBAL_INT_RESTORE() pairs ?

MT_dialog
Offline
Last seen:1 month 1 week ago
Staff
加入:2015-06-08 11:34
Hi summer20100514,

Hi summer20100514,

There is no particular document for the interrupt system, you can advice ARM's manual for this.

Thanks MT_dialog