MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / MSC_WriteWord

Function MSC_WriteWord

bsp/efm32/Libraries/emlib/src/em_msc.c:243–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

241#pragma diag_suppress=Ta023
242#endif
243msc_Return_TypeDef MSC_WriteWord(uint32_t *address, void const *data, int numBytes)
244{
245 int timeOut;
246 int wordCount;
247 int numWords;
248
249 /* Check alignment (Must be aligned to words) */
250 EFM_ASSERT(((uint32_t) address & 0x3) == 0);
251
252 /* Check number of bytes. Must be divisable by four */
253 EFM_ASSERT((numBytes & 0x3) == 0);
254
255 /* Enable writing to the MSC */
256 MSC->WRITECTRL |= MSC_WRITECTRL_WREN;
257
258 /* Convert bytes to words */
259 numWords = numBytes >> 2;
260
261 for (wordCount = 0; wordCount < numWords; wordCount++)
262 {
263 /* Load address */
264 MSC->ADDRB = (uint32_t)(address + wordCount);
265 MSC->WRITECMD = MSC_WRITECMD_LADDRIM;
266
267 /* Check for invalid address */
268 if (MSC->STATUS & MSC_STATUS_INVADDR)
269 {
270 /* Disable writing to the MSC */
271 MSC->WRITECTRL &= ~MSC_WRITECTRL_WREN;
272 return mscReturnInvalidAddr;
273 }
274
275 /* Check for write protected page */
276 if (MSC->STATUS & MSC_STATUS_LOCKED)
277 {
278 /* Disable writing to the MSC */
279 MSC->WRITECTRL &= ~MSC_WRITECTRL_WREN;
280 return mscReturnLocked;
281 }
282
283 /* Wait for the MSC to be ready for a new data word */
284 /* Due to the timing of this function, the MSC should already by ready */
285 timeOut = MSC_PROGRAM_TIMEOUT;
286 while (((MSC->STATUS & MSC_STATUS_WDATAREADY) == 0) && (timeOut != 0))
287 {
288 timeOut--;
289 }
290
291 /* Check for timeout */
292 if (timeOut == 0)
293 {
294 /* Disable writing to the MSC */
295 MSC->WRITECTRL &= ~MSC_WRITECTRL_WREN;
296 return mscReturnTimeOut;
297 }
298
299 /* Load data into write data register */
300 MSC->WDATA = *(((uint32_t *)data) + wordCount);

Callers 2

TRACE_ProfilerEnableFunction · 0.85
TRACE_ProfilerEnableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected