lower more irq priorities, split a function slowpath
[megadrive.git] / main.c
diff --git a/main.c b/main.c
index 3ad3bec..794317b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,3 +1,28 @@
+/*
+ * TeensyTAS, TAS input player for MegaDrive
+ * Copyright (c) 2014 notaz
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
@@ -71,6 +96,16 @@ static void portb_isr_fixed(void)
        g.edge_cnt++;
 }
 
+static noinline void do_to_step(void)
+{
+       g.frame_cnt++;
+
+       g.t_o = (g.t_o + 1) & STREAM_BUF_MASK;
+       if (g.t_o == g.t_i)
+               // done
+               attachInterruptVector(IRQ_PORTB, portb_isr_fixed);
+}
+
 static void portb_isr_do_to_inc(void)
 {
        uint32_t isfr, th;
@@ -80,14 +115,8 @@ static void portb_isr_do_to_inc(void)
        th = (GPIOB_PDIR >> CORE_PIN0_BIT) & 1;
 
        GPIOD_PDOR = g.stream_to[g.t_o][th];
-       if (th) {
-               g.t_o = (g.t_o + 1) & STREAM_BUF_MASK;
-               if (g.t_o == g.t_i)
-                       // done
-                       attachInterruptVector(IRQ_PORTB, portb_isr_fixed);
-               g.frame_cnt++;
-       }
-       g.edge_cnt++;
+       if (th)
+               do_to_step();
 }
 
 static void portb_isr_do_to(void)
@@ -384,6 +413,7 @@ int main(void)
 
        NVIC_SET_PRIORITY(IRQ_PORTB, 0);
        NVIC_SET_PRIORITY(IRQ_PORTC, 16);
+       SCB_SHPR1 = SCB_SHPR2 = SCB_SHPR3 = 0x10101010;
 
        pinMode( 2, OUTPUT);
        pinMode(14, OUTPUT);
@@ -401,9 +431,11 @@ int main(void)
        printf("GPIOD PDDR, PDIR: %08x %08x\n", GPIOD_PDIR, GPIOD_PDDR);
        printf("PORTB_PCR16: %08x\n", PORTB_PCR16);
        printf("PORTC_PCR6:  %08x\n", PORTC_PCR6);
+       printf("PORTD_PCR0:  %08x\n", PORTD_PCR0);
 
        asm("mrs %0, BASEPRI" : "=r"(ret));
-       printf("BASEPRI: %d\n", ret);
+       printf("BASEPRI: %d, SHPR: %08x %08x %08x\n",
+               ret, SCB_SHPR1, SCB_SHPR2, SCB_SHPR3);
 
        edge_cnt_last = g.edge_cnt;