emi_mpu_v1.c 805 B

123456789101112131415161718192021222324252627282930
  1. #include <emi_mpu_v1.h>
  2. #include <emi_hw.h>
  3. int emi_mpu_set_protection(struct emi_region_info_t *region_info)
  4. {
  5. unsigned int start, end;
  6. int dgroup;
  7. start = (unsigned int)(region_info->start >> EMI_MPU_ALIGN_BITS);
  8. end = (unsigned int)(region_info->end >> EMI_MPU_ALIGN_BITS);
  9. if (region_info->region >= EMI_MPU_REGION_NUM)
  10. return -1;
  11. if ((start >= DRAM_OFFSET) && (end >= start)) {
  12. start -= DRAM_OFFSET;
  13. end -= DRAM_OFFSET;
  14. } else
  15. return -1;
  16. #if ENABLE_MPU
  17. for (dgroup = EMI_MPU_DGROUP_NUM - 1; dgroup >= 0; dgroup--) {
  18. *((volatile unsigned int *)EMI_MPU_SA(region_info->region)) = start;
  19. *((volatile unsigned int *)EMI_MPU_EA(region_info->region)) = end;
  20. *((volatile unsigned int *)EMI_MPU_APC(region_info->region, dgroup)) = region_info->apc[dgroup];
  21. }
  22. #endif
  23. return 0;
  24. }