Commit 347f3262 authored by Alberto Escolar Piedras's avatar Alberto Escolar Piedras Committed by Carles Cufi
Browse files

Bluetooth: controller: Use nRFx functions for ECB reg with sideeffect



In the BLE HAL for the ECB:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: default avatarAlberto Escolar Piedras <alpi@oticon.com>
parent bc606d22
Loading
Loading
Loading
Loading
+9 −19
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
#include "common/log.h"
#include "hal/debug.h"

#include "nrf_ecb.h"

struct ecb_param {
	u8_t key[16];
	u8_t clear_text[16];
@@ -23,15 +25,11 @@ struct ecb_param {
static void do_ecb(struct ecb_param *ecb)
{
	do {
		NRF_ECB->TASKS_STOPECB = 1;
		nrf_ecb_task_trigger(NRF_ECB, NRF_ECB_TASK_STOPECB);
		NRF_ECB->ECBDATAPTR = (u32_t)ecb;
		NRF_ECB->EVENTS_ENDECB = 0;
		NRF_ECB->EVENTS_ERRORECB = 0;
		NRF_ECB->TASKS_STARTECB = 1;
#if defined(CONFIG_BOARD_NRFXX_NWTSIM)
		NRF_ECB_regw_sideeffects_TASKS_STOPECB();
		NRF_ECB_regw_sideeffects_TASKS_STARTECB();
#endif
		nrf_ecb_task_trigger(NRF_ECB, NRF_ECB_TASK_STARTECB);
		while ((NRF_ECB->EVENTS_ENDECB == 0) &&
		       (NRF_ECB->EVENTS_ERRORECB == 0) &&
		       (NRF_ECB->ECBDATAPTR != 0)) {
@@ -41,10 +39,7 @@ static void do_ecb(struct ecb_param *ecb)
			/*__WFE();*/
#endif
		}
		NRF_ECB->TASKS_STOPECB = 1;
#if defined(CONFIG_BOARD_NRFXX_NWTSIM)
		NRF_ECB_regw_sideeffects_TASKS_STOPECB();
#endif
		nrf_ecb_task_trigger(NRF_ECB, NRF_ECB_TASK_STOPECB);
	} while ((NRF_ECB->EVENTS_ERRORECB != 0) || (NRF_ECB->ECBDATAPTR == 0));

	NRF_ECB->ECBDATAPTR = 0;
@@ -101,18 +96,15 @@ u32_t ecb_encrypt_nonblocking(struct ecb *ecb)
	NRF_ECB->ECBDATAPTR = (u32_t)ecb;
	NRF_ECB->EVENTS_ENDECB = 0;
	NRF_ECB->EVENTS_ERRORECB = 0;
	NRF_ECB->INTENSET = ECB_INTENSET_ERRORECB_Msk | ECB_INTENSET_ENDECB_Msk;
	nrf_ecb_int_enable(NRF_ECB, ECB_INTENSET_ERRORECB_Msk
				    | ECB_INTENSET_ENDECB_Msk);

	/* enable interrupt */
	NVIC_ClearPendingIRQ(ECB_IRQn);
	irq_enable(ECB_IRQn);

	/* start the encryption h/w */
	NRF_ECB->TASKS_STARTECB = 1;
#if defined(CONFIG_BOARD_NRFXX_NWTSIM)
	NRF_ECB_regw_sideeffects_INTENSET();
	NRF_ECB_regw_sideeffects_TASKS_STARTECB();
#endif
	nrf_ecb_task_trigger(NRF_ECB, NRF_ECB_TASK_STARTECB);

	return 0;
}
@@ -121,9 +113,7 @@ static void ecb_cleanup(void)
{
	/* stop h/w */
	NRF_ECB->TASKS_STOPECB = 1;
#if defined(CONFIG_BOARD_NRFXX_NWTSIM)
	NRF_ECB_regw_sideeffects_TASKS_STOPECB();
#endif
	nrf_ecb_task_trigger(NRF_ECB, NRF_ECB_TASK_STOPECB);

	/* cleanup interrupt */
	irq_disable(ECB_IRQn);