lm3s1968: enable kernel preemption in the example.
authorarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 6 Apr 2010 09:28:23 +0000 (09:28 +0000)
committerarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 6 Apr 2010 09:28:23 +0000 (09:28 +0000)
Moreover, add a simple testcase to measure the voluntary context switch
overhead.

git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3398 38d2e660-2303-0410-9eaa-f027e97ec537

examples/lm3s1968/cfg/cfg_proc.h
examples/lm3s1968/lm3s1968.c

index 0f47739d77c513d61bb249bc96fe95e5edf38dfc..eb5506b412d165af24b1abe1b55542deb7ce2f85 100644 (file)
@@ -58,7 +58,7 @@
  * $WIZ$ type = "boolean"
  * $WIZ$ conditional_deps = "timer"
  */
-#define CONFIG_KERN_PREEMPT 0
+#define CONFIG_KERN_PREEMPT 1
 
 /**
  * Time sharing quantum (a prime number prevents interference effects) [ms].
@@ -86,7 +86,7 @@
  * $WIZ$ type = "int"
  * $WIZ$ min = 0
  */
-#define CONFIG_KERN_HEAP_SIZE 8192L
+#define CONFIG_KERN_HEAP_SIZE 16384L
 
 /**
  * Module logging level.
index edf7211071c1951f4e4d385c7ae91d5f357b4193..826bd3e4099d97509d7400f5ba83fd773bb4eebc 100644 (file)
 #include <drv/timer.h>
 #include "io/lm3s.h"
 
+static Process *hp_proc, *lp_proc;
+
+static hptime_t start, end;
+
 static void led_init(void)
 {
        /* Enable the GPIO port that is used for the on-board LED */
@@ -53,44 +57,85 @@ static void led_init(void)
        GPIO_PORTG_DEN_R = 0x04;
 }
 
-static void led_on(void)
+INLINE void led_on(void)
 {
        GPIO_PORTG_DATA_R |= 0x04;
 }
 
-static void led_off(void)
+INLINE void led_off(void)
 {
        GPIO_PORTG_DATA_R &= ~0x04;
 }
 
-static NORETURN void spinner_thread(void)
+INLINE hptime_t get_hp_ticks(void)
+{
+       return (TIMER_HW_CNT - timer_hw_hpread()) +
+                       timer_clock_unlocked() * TIMER_HW_CNT;
+}
+
+#if CONFIG_KERN_HEAP
+#define hp_stack NULL
+#define HP_STACK_SIZE  KERN_MINSTACKSIZE * 2
+#else
+static PROC_DEFINE_STACK(hp_stack, KERN_MINSTACKSIZE * 2);
+#define HP_STACK_SIZE  sizeof(hp_stack)
+#endif
+
+static void NORETURN hp_process(void)
 {
        char spinner[] = {'/', '-', '\\', '|'};
        int i;
 
-       kputs("\n");
        for(i = 0; ; i++)
        {
-               kprintf("BeRTOS is up & running: %c\r",
-                               spinner[i % countof(spinner)]);
-               timer_delay(100);
+               sig_wait(SIG_USER0);
+               end = get_hp_ticks();
+               kprintf("%c context switch in %lu clock cycles (~%lu us)    \r",
+                               spinner[i % countof(spinner)],
+                               end - start,
+                               ((end - start) * 1000000 / CPU_FREQ));
+               led_off();
+               timer_delay(50);
+               sig_send(lp_proc, SIG_USER0);
+       }
+}
+
+static void NORETURN lp_process(void)
+{
+       while (1)
+       {
+               led_on();
+               timer_delay(50);
+               start = get_hp_ticks();
+               sig_send(hp_proc, SIG_USER0);
+               sig_wait(SIG_USER0);
        }
 }
 
 int main(void)
 {
        IRQ_ENABLE;
+       kdbg_init();
+
+       kputs("Init LED..");
        led_init();
+       kputs("Done.\n");
+       kputs("Init Timer..");
+       timer_init();
+       kputs("Done.\n");
+       kputs("Init Process..");
+       proc_init();
+       kputs("Done.\n");
 
-       proc_testSetup();
+       kputs("Check scheduling functionality\n");
        proc_testRun();
 
-       proc_new(spinner_thread, NULL, KERN_MINSTACKSIZE, NULL);
-       while(1)
-       {
-               led_on();
-               timer_delay(250);
-               led_off();
-               timer_delay(250);
-       }
+       kputs("BeRTOS is up & running\n\n");
+       hp_proc = proc_new(hp_process, NULL, HP_STACK_SIZE, hp_stack);
+       lp_proc = proc_current();
+
+       proc_setPri(hp_proc, 2);
+       proc_setPri(lp_proc, 1);
+
+       lp_process();
 }