aboutsummaryrefslogtreecommitdiffstats
path: root/demos/STM32/RT-STM32F103-OLIMEX_STM32_P103/main.c
blob: 414ed96b744262679f55cc2ac13c52852bcde61f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
    ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

#include "ch.h"
#include "hal.h"
#include "ch_test.h"

/*
 * Blinker thread.
 */
static THD_WORKING_AREA(waThread1, 128);
static THD_FUNCTION(Thread1, arg) {

  (void)arg;

  chRegSetThreadName("blinker");
  while (true) {
    palSetPad(GPIOC, GPIOC_LED);
    chThdSleepMilliseconds(500);
    palClearPad(GPIOC, GPIOC_LED);
    chThdSleepMilliseconds(500);
  }
}

/*
 * Application entry point.
 */
int main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Activates the serial driver 1 using the driver default configuration.
   * PA9(TX) and PA10(RX) are routed to USART1.
   */
  sdStart(&SD2, NULL);

  /*
   * Creates the example thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+1, Thread1, NULL);

  /*
   * Normal main() thread activity, in this demo it does nothing except
   * sleeping in a loop and check the button state, when the button is
   * pressed the test procedure is launched.
   */
  while (true) {
    if (palReadPad(GPIOA, GPIOA_BUTTON))
      test_execute((BaseSequentialStream *)&SD2);
    chThdSleepMilliseconds(500);
  }
}
<types.h> #include <lib.h> /* * Shared page for communicating with the hypervisor. * Events flags go here, for example. */ shared_info_t *HYPERVISOR_shared_info; /* * This structure contains start-of-day info, such as pagetable base pointer, * address of the shared_info structure, and things like that. */ union start_info_union start_info_union; /* * Just allocate the kernel stack here. SS:ESP is set up to point here * in head.S. */ char stack[8192]; /* Assembler interface fns in entry.S. */ void hypervisor_callback(void); void failsafe_callback(void); /* default event handlers */ static void exit_handler(int ev, struct pt_regs *regs); static void debug_handler(int ev, struct pt_regs *regs); extern char shared_info[PAGE_SIZE]; static shared_info_t *map_shared_info(unsigned long pa) { if ( HYPERVISOR_update_va_mapping( (unsigned long)shared_info, pa | 7, UVMF_INVLPG) ) { printk("Failed to map shared_info!!\n"); *(int*)0=0; } return (shared_info_t *)shared_info; } /* * INITIAL C ENTRY POINT. */ void start_kernel(start_info_t *si) { static char hello[] = "Bootstrapping...\n"; (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello); /* Copy the start_info struct to a globally-accessible area. */ memcpy(&start_info, si, sizeof(*si)); /* Grab the shared_info pointer and put it in a safe place. */ HYPERVISOR_shared_info = map_shared_info(start_info.shared_info); /* Set up event and failsafe callback addresses. */ #ifdef __i386__ HYPERVISOR_set_callbacks( __KERNEL_CS, (unsigned long)hypervisor_callback, __KERNEL_CS, (unsigned long)failsafe_callback); #else HYPERVISOR_set_callbacks( (unsigned long)hypervisor_callback, (unsigned long)failsafe_callback, 0); #endif trap_init(); /* ENABLE EVENT DELIVERY. This is disabled at start of day. */ __sti(); /* print out some useful information */ printk("Xen Minimal OS!\n"); printk("start_info: %p\n", si); printk(" nr_pages: %lu", si->nr_pages); printk(" shared_inf: %08lx\n", si->shared_info); printk(" pt_base: %p", (void *)si->pt_base); printk(" mod_start: 0x%lx\n", si->mod_start); printk(" mod_len: %lu\n", si->mod_len); printk(" flags: 0x%x\n", (unsigned int)si->flags); printk(" cmd_line: %s\n", si->cmd_line ? (const char *)si->cmd_line : "NULL"); /* * If used for porting another OS, start here to figure out your * guest os entry point. Otherwise continue below... */ /* init memory management */ init_mm(); /* set up events */ // init_events(); /* * These need to be replaced with event-channel/control-interface * equivalents. */ #if 0 /* Install some handlers. */ add_ev_action(EV_DIE, &exit_handler); enable_ev_action(EV_DIE); enable_hypervisor_event(EV_DIE); add_ev_action(EV_DEBUG, &debug_handler); enable_ev_action(EV_DEBUG); enable_hypervisor_event(EV_DEBUG); #endif /* init time and timers */ // init_time(); /* do nothing */ for ( ; ; ) HYPERVISOR_yield(); } /* * do_exit: This is called whenever an IRET fails in entry.S. * This will generally be because an application has got itself into * a really bad state (probably a bad CS or SS). It must be killed. * Of course, minimal OS doesn't have applications :-) */ void do_exit(void) { printk("do_exit called!\n"); for ( ;; ) HYPERVISOR_shutdown(); } static void exit_handler(int ev, struct pt_regs *regs) { do_exit(); } /* * a debug handler to print out some state from the guest */ static void debug_handler(int ev, struct pt_regs *regs) { dump_regs(regs); }