Add preprocessor FOR macro.
[bertos.git] / bertos / benchmark / context_switch.c
index a09a61461853157777267fead2660ef49f58f8b7..12298892a9c9bfebd15724ded8674b52d65e149f 100644 (file)
 #include <cpu/power.h>
 
 #include <drv/timer.h>
+#if CONFIG_USE_HP_TIMER
 #include <drv/ser.h>
+static Serial out;
+#endif
 
 #include <kern/proc.h>
 
@@ -57,8 +60,6 @@ static PROC_DEFINE_STACK(hp_stack, PROC_STACK_SIZE);
 static PROC_DEFINE_STACK(lp_stack, PROC_STACK_SIZE);
 
 static Process *hp_proc, *lp_proc, *main_proc;
-static Serial out;
-
 #if CONFIG_USE_HP_TIMER
 static hptime_t start, end;
 #endif
@@ -68,12 +69,12 @@ static void NORETURN hp_process(void)
        while (1)
        {
                sig_wait(SIG_USER0);
-               #if CONFIG_USE_HP_TIMER
-                       end = timer_hw_hpread();
-               #endif
                #if CONFIG_USE_LED
                        LED_ON();
                #endif
+               #if CONFIG_USE_HP_TIMER
+                       end = timer_hw_hpread();
+               #endif
                sig_send(main_proc, SIG_USER0);
        }
 }
@@ -83,13 +84,13 @@ static void NORETURN lp_process(void)
        while (1)
        {
                sig_wait(SIG_USER0);
-               #if CONFIG_USE_HP_TIMER
-                       start = timer_hw_hpread();
-               #endif
                #if CONFIG_USE_LED
                        LED_ON();
                        LED_OFF();
                #endif
+               #if CONFIG_USE_HP_TIMER
+                       start = timer_hw_hpread();
+               #endif
                sig_send(hp_proc, SIG_USER0);
        }
 }
@@ -101,22 +102,27 @@ void NORETURN context_switch(void)
        timer_init();
        proc_init();
 
-       ser_init(&out, CONFIG_CTX_DEBUG_PORT);
-       ser_setbaudrate(&out, CONFIG_CTX_DEBUG_BAUDRATE);
+       #if CONFIG_USE_HP_TIMER
+               ser_init(&out, CONFIG_CTX_DEBUG_PORT);
+               ser_setbaudrate(&out, CONFIG_CTX_DEBUG_BAUDRATE);
+       #endif
 
        #if CONFIG_USE_LED
                LED_INIT();
        #endif
 
+       proc_forbid();
        hp_proc = proc_new(hp_process, NULL, PROC_STACK_SIZE, hp_stack);
        lp_proc = proc_new(lp_process, NULL, PROC_STACK_SIZE, lp_stack);
        main_proc = proc_current();
-
        proc_setPri(hp_proc, 2);
        proc_setPri(lp_proc, 1);
+       proc_permit();
 
        while (1)
        {
+               timer_delay(100);
+
                sig_send(lp_proc, SIG_USER0);
                sig_wait(SIG_USER0);
 
@@ -126,7 +132,5 @@ void NORETURN context_switch(void)
                                hptime_to_us((end - start)),
                                hptime_to_us((end - start) * 1000) % 1000);
                #endif
-               timer_delay(100);
        }
-
 }