Skip to content

Commit eb16a0f

Browse files
committed
clean up
1 parent 9c3c0e7 commit eb16a0f

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

cores/nRF5/flash/flash_nrf5x.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@
4444
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
4545
//--------------------------------------------------------------------+
4646
static SemaphoreHandle_t _sem = NULL;
47-
static volatile uint32_t _op_result;
4847

4948
void flash_nrf5x_event_cb (uint32_t event)
5049
{
51-
_op_result = event;
52-
xSemaphoreGive(_sem);
50+
// if (event != NRF_EVT_FLASH_OPERATION_SUCCESS) LOG_LV1("IFLASH", "Flash op Failed");
51+
if ( _sem ) xSemaphoreGive(_sem);
5352
}
5453

5554
// Flash Abstraction Layer
@@ -101,52 +100,46 @@ bool flash_nrf5x_erase(uint32_t addr)
101100
bool fal_erase (uint32_t addr)
102101
{
103102
// Init semaphore for first call
104-
if ( !_sem )
103+
if ( _sem == NULL )
105104
{
106-
_sem = xSemaphoreCreateBinary();
105+
_sem = xSemaphoreCreateCounting(10, 0);
107106
VERIFY(_sem);
108107
}
109108

110-
// delay and retry if busy
109+
// retry if busy
111110
uint32_t err;
112111
while ( NRF_ERROR_BUSY == (err = sd_flash_page_erase(addr / FLASH_NRF52_PAGE_SIZE)) )
113112
{
114113
delay(1);
115114
}
116-
VERIFY_STATUS(err);
115+
VERIFY_STATUS(err, false);
117116

118117
// wait for async event if SD is enabled
119118
uint8_t sd_en = 0;
120119
(void) sd_softdevice_is_enabled(&sd_en);
121120

122-
if ( sd_en )
123-
{
124-
xSemaphoreTake(_sem, portMAX_DELAY);
125-
VERIFY(_op_result == NRF_EVT_FLASH_OPERATION_SUCCESS);
126-
}
127-
121+
if ( sd_en ) xSemaphoreTake(_sem, portMAX_DELAY);
122+
128123
return true;
129124
}
130125

131126
static uint32_t fal_program (uint32_t dst, void const * src, uint32_t len)
132127
{
133-
// delay and try again if busy
128+
cprintf("Programming 0x%08X\n", dst);
129+
130+
// try again if busy
134131
uint32_t err;
135132
while ( NRF_ERROR_BUSY == (err = sd_flash_write((uint32_t*) dst, (uint32_t const *) src, len / 4)) )
136133
{
137134
delay(1);
138135
}
139-
VERIFY_STATUS(err);
136+
VERIFY_STATUS(err, 0);
140137

141138
// wait for async event if SD is enabled
142139
uint8_t sd_en = 0;
143140
(void) sd_softdevice_is_enabled(&sd_en);
144141

145-
if ( sd_en )
146-
{
147-
xSemaphoreTake(_sem, portMAX_DELAY);
148-
VERIFY(_op_result == NRF_EVT_FLASH_OPERATION_SUCCESS);
149-
}
142+
if ( sd_en ) xSemaphoreTake(_sem, portMAX_DELAY);
150143

151144
return len;
152145
}
@@ -161,5 +154,3 @@ static bool fal_verify (uint32_t addr, void const * buf, uint32_t len)
161154
{
162155
return 0 == memcmp((void*) addr, buf, len);
163156
}
164-
165-

0 commit comments

Comments
 (0)