Revisión | 1310ff8c398b9ba440430383dc9b9ea53ff00ac2 (tree) |
---|---|
Tiempo | 2015-12-27 16:37:39 |
Autor | Yoshinori Sato <ysato@user...> |
Commiter | Yoshinori Sato |
TPU simulation
@@ -592,10 +592,21 @@ mem_get_content_type (int address) | ||
592 | 592 | #define TMRI_CMB (1<<1) |
593 | 593 | #define TMRI_OVF (1<<0) |
594 | 594 | |
595 | +#define TPU_CH 6 | |
596 | +#define TPU_TSTR (tpubase[0]) | |
597 | +#define TPU_TCR(ch) (tpubase[(ch+1) * 0x10 + 0]) | |
598 | +#define TPU_TSR(ch) (tpubase[(ch+1) * 0x10 + 5]) | |
599 | +#define TPU_TCNTH(ch) (tpubase[(ch+1) * 0x10 + 7]) | |
600 | +#define TPU_TCNTL(ch) (tpubase[(ch+1) * 0x10 + 6]) | |
601 | +#define TPU_GRAH(ch) (tpubase[(ch+1) * 0x10 + 9]) | |
602 | +#define TPU_GRAL(ch) (tpubase[(ch+1) * 0x10 + 8]) | |
603 | +#define TPU_GRBH(ch) (tpubase[(ch+1) * 0x10 + 11]) | |
604 | +#define TPU_GRBL(ch) (tpubase[(ch+1) * 0x10 + 10]) | |
605 | + | |
595 | 606 | static unsigned char get_tmrisr(int ch) |
596 | 607 | { |
597 | 608 | unsigned char *irptr = rx_mem_ptr(IRADR(174 + ch * 3), MPA_READING); |
598 | - unsigned char isr; | |
609 | + unsigned char isr = 0; | |
599 | 610 | unsigned int i; |
600 | 611 | for (i = 0; i < 3; i++) |
601 | 612 | { |
@@ -757,6 +768,80 @@ cmt_update(int cycles_diff) | ||
757 | 768 | } |
758 | 769 | } |
759 | 770 | |
771 | +static void | |
772 | +tpu_update(unsigned int cycles_diff) | |
773 | +{ | |
774 | + static int prescale[4]={1,4,16,64}; | |
775 | + const int prescale_div[4]={1,4,16,64}; | |
776 | + int tm, cnt, pcnt, gr, pulse; | |
777 | + unsigned char *tpubase = rx_mem_ptr(0x00088100, MPA_WRITING); | |
778 | + | |
779 | + for (pcnt = 0; pcnt < 4; pcnt++) { | |
780 | + prescale[pcnt] -= cycles_diff; | |
781 | + pulse = -prescale[pcnt] / prescale_div[pcnt] + 1; | |
782 | + if (prescale[pcnt]<=0) | |
783 | + { | |
784 | + /* input time pulse */ | |
785 | + for(tm=0; tm < TPU_CH; tm++) { | |
786 | + | |
787 | + /* Timer enable check */ | |
788 | + if (!(TPU_TSTR & (1 << tm))) | |
789 | + continue; | |
790 | + | |
791 | + /* update counter */ | |
792 | + if ((TPU_TCR(tm) & 0x0f) == pcnt) | |
793 | + { | |
794 | + cnt = ((TPU_TCNTH(tm) << 8) | TPU_TCNTL(tm)); | |
795 | + cnt += pulse; | |
796 | + | |
797 | + /* CNT overflow check */ | |
798 | + if (cnt>=0x10000) | |
799 | + { | |
800 | + int cascade_low = tm % 3; | |
801 | + cnt -= 0x10000; | |
802 | + if (cascade_low == 2) | |
803 | + { | |
804 | + int cascade_high = tm - cascade_low + 1; | |
805 | + if ((TPU_TCR(cascade_high) & 0x0f) == 0x0f) | |
806 | + { | |
807 | + int cascade_cnt; | |
808 | + cascade_cnt = ((TPU_TCNTH(cascade_high) << 8) | | |
809 | + TPU_TCNTL(cascade_high)); | |
810 | + cascade_cnt++; | |
811 | + TPU_TCNTH(cascade_high) = (cascade_cnt >> 8); | |
812 | + TPU_TCNTL(cascade_high) = cascade_cnt & 0xff; | |
813 | + } | |
814 | + } | |
815 | + } | |
816 | + | |
817 | + /* GRA compare match check*/ | |
818 | + gr = (TPU_GRAH(tm) << 8) | TPU_GRAL(tm); | |
819 | + if (cnt >= gr) | |
820 | + { | |
821 | + if ((TPU_TCR(tm) & 0xe0) == 0x20) | |
822 | + cnt = 0; | |
823 | + } | |
824 | + | |
825 | + /* GRB compare match check*/ | |
826 | + gr = (TPU_GRBH(tm) << 8) | TPU_GRBL(tm); | |
827 | + if (cnt >= gr) | |
828 | + { | |
829 | + if ((TPU_TCR(tm) & 0xe0) == 0x40) | |
830 | + cnt = 0; | |
831 | + } | |
832 | + | |
833 | + /* update TCNT */ | |
834 | + TPU_TCNTH(tm) = (cnt >> 8); | |
835 | + TPU_TCNTL(tm) = cnt & 0xff; | |
836 | + } | |
837 | + | |
838 | + } | |
839 | + prescale[pcnt]+=prescale_div[pcnt]; | |
840 | + /* update TSR */ | |
841 | + } | |
842 | + } | |
843 | +} | |
844 | + | |
760 | 845 | #define SMR(ch) (scibase[(ch) * 8 + 0]) |
761 | 846 | #define BRR(ch) (scibase[(ch) * 8 + 1]) |
762 | 847 | #define SCR(ch) (scibase[(ch) * 8 + 2]) |
@@ -1117,6 +1202,7 @@ int io_simulation(cpupri) | ||
1117 | 1202 | prev_pcycle = pcycles; |
1118 | 1203 | tmr_update(3, pcycle_diff); |
1119 | 1204 | cmt_update(pcycle_diff); |
1205 | + tpu_update(pcycle_diff); | |
1120 | 1206 | sci(pcycle_diff); |
1121 | 1207 | return icu(cpupri); |
1122 | 1208 | } |