MCPcopy Create free account
hub / github.com/CE-Programming/CEmu / mem_write_flash

Function mem_write_flash

core/mem.c:551–610  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

549}
550
551static void mem_write_flash(uint32_t addr, uint8_t byte) {
552 if (asic.serFlash) {
553 /* Writes cause a cache touch, but the write does not modify the cache */
554 cpu.cycles += flash_touch_cache(addr);
555 return;
556 }
557
558 if (unlikely(addr >= flash.mappedBytes)) {
559 cpu.cycles += 258;
560 return;
561 }
562
563 if (unlikely(++cpu.flashTotalAccesses == 0)) {
564 cpu.flashTotalAccesses = 0x80000000;
565 cpu.flashDelayCycles >>= 1;
566 }
567 cpu.cycles += flash.waitStates;
568 if (!flash_unlocked()) {
569 /* privileged writes with flash locked are probably ignored */
570 return;
571 }
572
573 int i;
574 int partial_match = 0;
575 flash_write_t *w;
576 flash_write_pattern_t *pattern;
577
578 if (mem.flash.command != FLASH_NO_COMMAND) {
579 if ((mem.flash.command != FLASH_DEEP_POWER_DOWN && byte == 0xF0) ||
580 (mem.flash.command == FLASH_DEEP_POWER_DOWN && byte == 0xAB)) {
581 if( mem.flash.command != FLASH_WAIT_PB_EXIT )
582 {
583 mem.flash.command = FLASH_NO_COMMAND;
584 flash_reset_write_index(addr, byte);
585 }
586 return;
587 }
588 }
589
590 w = &mem.flash.writes[mem.flash.write++];
591 w->addr = addr;
592 w->value = byte;
593
594 for (pattern = patterns; pattern->length; pattern++) {
595 for (i = 0; (i < mem.flash.write) && (i < pattern->length) &&
596 (mem.flash.writes[i].addr & pattern->pattern[i].addrMask) == pattern->pattern[i].addr &&
597 (mem.flash.writes[i].value & pattern->pattern[i].valueMask) == pattern->pattern[i].value; i++) {
598 }
599 if (i == pattern->length) {
600 pattern->handler(addr, byte);
601 partial_match = 0;
602 break;
603 } else if (i == mem.flash.write) {
604 partial_match = 1;
605 }
606 }
607 if (!partial_match) {
608 flash_reset_write_index(addr, byte);

Callers 1

mem_write_cpuFunction · 0.85

Calls 3

flash_touch_cacheFunction · 0.85
flash_unlockedFunction · 0.85
flash_reset_write_indexFunction · 0.85

Tested by

no test coverage detected