Contiki 3.x
contiki-main.c
1 /*
2  * Copyright (C) 2015-2016, Intel Corporation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * 3. Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include <stdio.h>
32 
33 #include "contiki.h"
34 #include "contiki-net.h"
35 #include "cpu.h"
36 #include "eth.h"
37 #include "eth-conf.h"
38 #include "galileo-pinmux.h"
39 #include "gpio.h"
40 #include "helpers.h"
41 #include "i2c.h"
42 #include "imr-conf.h"
43 #include "interrupt.h"
44 #include "irq.h"
45 #include "pci.h"
46 #include "prot-domains.h"
47 #include "shared-isr.h"
48 #include "uart.h"
49 
50 PROCINIT( &etimer_process
51  , &tcpip_process
52 #if WITH_DNS
53  , &resolv_process
54 #endif
55  );
56 
57 extern int _sdata_kern_startup_func, _edata_kern_startup_func;
58 
59 /*---------------------------------------------------------------------------*/
60 void
61 app_main(void)
62 {
63  printf("Starting Contiki\n");
64 
65  process_init();
66  procinit_init();
67  ctimer_init();
68  autostart_start(autostart_processes);
69 
70  eth_init();
71 
72  while(1) {
73  process_run();
74  }
75 
76  halt();
77 }
78 /*---------------------------------------------------------------------------*/
79 /* Kernel entrypoint */
80 int
81 main(void)
82 {
83  uintptr_t *func_ptr;
84 
85 #ifdef X86_CONF_RESTRICT_DMA
86  quarkX1000_imr_conf();
87 #endif
88  irq_init();
89  /* Initialize UART connected to Galileo Gen2 FTDI header */
90  quarkX1000_uart_init(QUARK_X1000_UART_1);
91  clock_init();
92  rtimer_init();
93 
94  pci_root_complex_init();
95  quarkX1000_eth_init();
96  quarkX1000_i2c_init();
97  quarkX1000_i2c_configure(QUARKX1000_I2C_SPEED_STANDARD,
98  QUARKX1000_I2C_ADDR_MODE_7BIT);
99  /* use default pinmux configuration */
100  if(galileo_pinmux_initialize() < 0) {
101  fprintf(stderr, "Failed to initialize pinmux\n");
102  }
103  quarkX1000_gpio_init();
104  shared_isr_init();
105 
106  /* The ability to remap interrupts is not needed after this point and should
107  * thus be disabled according to the principle of least privilege.
108  */
109  pci_root_complex_lock();
110 
111  func_ptr = (uintptr_t *)&_sdata_kern_startup_func;
112  while(func_ptr != (uintptr_t *)&_edata_kern_startup_func) {
113  ((void (*)(void))*func_ptr)();
114 
115  func_ptr++;
116  }
117 
118  prot_domains_leave_main();
119 
120  return 0;
121 }
122 /*---------------------------------------------------------------------------*/
void clock_init(void)
Initialize the clock library.
Definition: clock.c:76
int process_run(void)
Run the system once - call poll handlers and process one event.
Definition: process.c:302
int main(void)
This is main...
Definition: contiki-main.c:456
void rtimer_init(void)
Initialize the real-time scheduler.
Definition: rtimer.c:61
void process_init(void)
Initialize the process module.
Definition: process.c:208
void ctimer_init(void)
Initialize the callback timer library.
Definition: ctimer.c:91