Hi,
I am now looking on the app_easy_timer api in SDK5. This is a very great tool - no need to think of messages, just pass a callback that you want to be called when the timer expires (Are there any javascript developers here?).
In our app we are using GAPM_USE_ENC_BLOCK_CMD and GAPM_USER_ENC_BLOCK_IND directly to encrypt some user data.
A similar api could be implemented for encrypting blocks. Unlike the timers, two encryption requests cannot run in parallel. Therefore, there should be a queue of encryption requests & callbacks (with push, pop and peek).
The function can be called:
app_easy_encrypt_block(const uint8_t *operand_1, const uint8_t *operand_2, void(*fn)(const uint8_t*))
It can either return a boolean or a uint8_t, containing an error in case of failure (for example, if the queue is full).
When the function is called, it should create a struct-element of operand_1, operand_2 and fn, and try to push it to the queue.
If the queue was empty right before this push, it means there are no parallel encryptions - the function should send a new GAPM_USER_ENC_BLOCK_CMD with operand_1 and operand_2 that were just inserted.
When a GAPM_USER_ENC_BLOCK_IND arrives, we should pop an element from the queue and save it aside in a temporary variable (an assertion should make sure that the queue was not empty).
Then, if the queue is still not empty, we should peek its head and send a new GAPM_USER_ENC_BLOCK_CMD in order to continue the encryption process.
At last, we should call the fn callback from the element that was saved aside, with the result field from the GAPM_USER_ENC_BLOCK_IND.
Let me know what you think about it,
Oren Zomer