X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=examples%2Flm3s1968%2Flm3s1968.c;h=826bd3e4099d97509d7400f5ba83fd773bb4eebc;hb=e9bfc5ac6ebabbcf2a0f387e490286165409e6d7;hp=68da7cda74bd0dc7f6b7834fa8dbf38f1f4a19c6;hpb=73a7e9cb144007905b5b9de8e3086423e79b6d71;p=bertos.git diff --git a/examples/lm3s1968/lm3s1968.c b/examples/lm3s1968/lm3s1968.c index 68da7cda..826bd3e4 100644 --- a/examples/lm3s1968/lm3s1968.c +++ b/examples/lm3s1968/lm3s1968.c @@ -36,15 +36,15 @@ */ #include +#include #include "io/lm3s.h" -#include "drv/timer_lm3s.h" -extern unsigned long ticks; +static Process *hp_proc, *lp_proc; -int main(void) -{ - timer_hw_init(); +static hptime_t start, end; +static void led_init(void) +{ /* Enable the GPIO port that is used for the on-board LED */ SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOG; /* @@ -55,14 +55,87 @@ int main(void) /* Enable the GPIO pin for the LED */ GPIO_PORTG_DIR_R = 0x04; GPIO_PORTG_DEN_R = 0x04; +} + +INLINE void led_on(void) +{ + GPIO_PORTG_DATA_R |= 0x04; +} + +INLINE void led_off(void) +{ + GPIO_PORTG_DATA_R &= ~0x04; +} + +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; + + for(i = 0; ; i++) + { + 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); + } +} - while(1) +static void NORETURN lp_process(void) +{ + while (1) { - /* Turn on the LED */ - if ((ticks & 0x04) == 0x04) - GPIO_PORTG_DATA_R |= 0x04; - /* Turn off the LED */ - else if ((ticks & 0x04) == 0) - GPIO_PORTG_DATA_R &= ~0x04; + 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"); + + kputs("Check scheduling functionality\n"); + proc_testRun(); + + 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(); +}