Changeset 9e0cd12 in buchla-emu
- Timestamp:
- 08/05/2017 10:54:17 AM (7 years ago)
- Branches:
- master
- Children:
- 40b2112
- Parents:
- 52c8401
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
emu/tim.c
r52c8401 r9e0cd12 22 22 #define ver3(...) _ver(tim_verbose, 2, __VA_ARGS__) 23 23 24 typedef struct { 25 uint32_t irq; 26 bool run; 27 uint32_t latch; 28 uint32_t count; 29 } state_timer; 30 31 static state_timer timers[] = { 32 {.irq = 0, .run = false, .latch = 32, .count = 32}, 33 {.irq = 0, .run = false, .latch = 3200, .count = 3200}, 34 {.irq = 0, .run = false, .latch = 801, .count = 801} 35 }; 24 int32_t tim_verbose = 0; 36 25 37 26 #define REG_CRX 0 … … 44 33 #define REG_T3L 7 45 34 46 int32_t tim_verbose = 0; 35 #define COUNT_1 32 36 #define COUNT_2 3200 37 #define COUNT_3 801 38 39 typedef struct { 40 bool irq_e; 41 bool irq; 42 int32_t latch; 43 int32_t count; 44 } state_timer; 45 46 static state_timer timers[] = { 47 { .irq_e = false, .irq = false, .latch = COUNT_1, .count = COUNT_1 }, 48 { .irq_e = false, .irq = false, .latch = COUNT_2, .count = COUNT_2 }, 49 { .irq_e = false, .irq = false, .latch = COUNT_3, .count = COUNT_3 } 50 }; 51 52 static bool wr_cr1 = false; 53 static bool oper = false; 47 54 48 55 void tim_init(void) … … 58 65 bool tim_exec(void) 59 66 { 60 for (int32_t i = 0; i < ARRAY_COUNT(timers); ++i) {61 if(timers[i].run == true) {67 if (oper) { 68 for (int32_t i = 0; i < ARRAY_COUNT(timers); ++i) { 62 69 --timers[i].count; 63 if(timers[i].count == 0) { 70 71 if (timers[i].count == 0) { 72 ver2("tim %d zero", i + 1); 64 73 timers[i].count = timers[i].latch; 65 timers[i].irq = 1; 74 75 if (timers[i].irq_e) { 76 ver2("tim %d irq", i + 1); 77 timers[i].irq = true; 78 } 66 79 } 67 //ver2("tim%d %u", i, timers[i].count);68 80 } 69 81 } … … 75 87 { 76 88 ver2("tim rd %u:%d", off, sz * 8); 77 uint32_t rv;78 rv = 0;79 switch(off) {80 case REG_CRX:81 break;82 89 90 if (sz != 1 || off > 7) { 91 fail("invalid tim rd %u:%d", off, sz * 8); 92 } 93 94 uint32_t rv = 0x00; 95 96 switch (off) { 83 97 case REG_CR2: 84 rv |= (timers[0].irq << 0); 85 rv |= (timers[1].irq << 1); 86 rv |= (timers[2].irq << 2); 87 ver2("tim plc %u fc %u rtc %u", timers[0].irq, timers[1].irq, timers[2].irq); 88 //ver2("tim rv %u", rv); 89 break; 98 rv |= (uint32_t)timers[0].irq << 0; 99 rv |= (uint32_t)timers[1].irq << 1; 100 rv |= (uint32_t)timers[2].irq << 2; 90 101 91 case REG_T1H:92 rv = 0;102 ver2("tim irqs %u %u %u", 103 (uint32_t)timers[0].irq, (uint32_t)timers[1].irq, (uint32_t)timers[2].irq); 93 104 break; 94 105 95 106 case REG_T1L: 96 rv = 31; 97 timers[0].irq = 0; 98 break; 107 if (timers[0].irq) { 108 ver2("tim 1 !irq"); 109 timers[0].irq = false; 110 } 99 111 100 case REG_T2H:101 rv = 12;102 112 break; 103 113 104 114 case REG_T2L: 105 rv = 127; 106 timers[1].irq = 0; 107 break; 115 if (timers[1].irq) { 116 ver2("tim 2 !irq"); 117 timers[1].irq = false; 118 } 108 119 109 case REG_T3H:110 rv = 3;111 120 break; 112 121 113 122 case REG_T3L: 114 rv = 32; 115 timers[2].irq = 0; 123 if (timers[2].irq) { 124 ver2("tim 3 !irq"); 125 timers[2].irq = false; 126 } 127 116 128 break; 117 129 … … 126 138 { 127 139 ver2("tim wr %u:%d 0x%0*x", off, sz * 8, sz * 2, val); 128 if( off == 0 && (val & (1 << 7)) ) { 129 timers[0].run = true; 130 timers[1].run = true; 131 timers[2].run = true; 140 141 if (sz != 1 || off > 7) { 142 fail("invalid tim wr %u:%d", off, sz * 8); 143 } 144 145 switch (off) { 146 case REG_CRX: 147 if (wr_cr1) { 148 if ((val & 0x01) == 0) { 149 ver2("tim start"); 150 oper = true; 151 } 152 153 timers[0].irq_e = (val & 0x40) != 0; 154 } 155 else { 156 timers[2].irq_e = (val & 0x40) != 0; 157 } 158 159 break; 160 161 case REG_CR2: 162 wr_cr1 = (val & 0x01) != 0; 163 timers[1].irq_e = (val & 0x40) != 0; 164 break; 165 166 default: 167 break; 132 168 } 133 169 }
Note:
See TracChangeset
for help on using the changeset viewer.