1 |
786 |
skrzyp |
// ==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// pdcecos_app.c
|
4 |
|
|
//
|
5 |
|
|
// Public Domain Curses for eCos
|
6 |
|
|
//
|
7 |
|
|
// ===========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 2009 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
// ===========================================================================
|
40 |
|
|
// ===========================================================================
|
41 |
|
|
// #####DESCRIPTIONBEGIN####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): Sergei Gavrikov
|
44 |
|
|
// Contributors: Sergei Gavrikov
|
45 |
|
|
// Date: 2009-03-26
|
46 |
|
|
// Purpose: Early startup for PDCurses stuff
|
47 |
|
|
// Description:
|
48 |
|
|
//
|
49 |
|
|
// ####DESCRIPTIONEND####
|
50 |
|
|
//
|
51 |
|
|
// ========================================================================*/
|
52 |
|
|
|
53 |
|
|
// ---------------------------------------------------------------------------
|
54 |
|
|
// CONFIGURATION CHECKS
|
55 |
|
|
//
|
56 |
|
|
|
57 |
|
|
#include <pkgconf/system.h> // which packages are enabled/disabled
|
58 |
|
|
#ifdef CYGPKG_KERNEL
|
59 |
|
|
# include <pkgconf/kernel.h>
|
60 |
|
|
#endif
|
61 |
|
|
#ifdef CYGPKG_LIBC
|
62 |
|
|
# include <pkgconf/libc.h>
|
63 |
|
|
#endif
|
64 |
|
|
#ifdef CYGPKG_IO_SERIAL
|
65 |
|
|
# include <pkgconf/io_serial.h>
|
66 |
|
|
#endif
|
67 |
|
|
#ifdef CYGPKG_FS_JFFS2
|
68 |
|
|
# include <pkgconf/io_flash.h>
|
69 |
|
|
#define USE_JFFS2
|
70 |
|
|
#endif
|
71 |
|
|
|
72 |
|
|
#ifndef CYGFUN_KERNEL_API_C
|
73 |
|
|
# error Kernel API must be enabled to build this application
|
74 |
|
|
#endif
|
75 |
|
|
|
76 |
|
|
#ifndef CYGPKG_LIBC_STDIO
|
77 |
|
|
# error C library standard I/O must be enabled to build this application
|
78 |
|
|
#endif
|
79 |
|
|
|
80 |
|
|
#ifndef CYGPKG_IO_SERIAL_HALDIAG
|
81 |
|
|
# error I/O HALDIAG pseudo-device driver must be enabled to build this application
|
82 |
|
|
#endif
|
83 |
|
|
|
84 |
|
|
#include <pkgconf/pdcurses.h>
|
85 |
|
|
|
86 |
|
|
// ---------------------------------------------------------------------------
|
87 |
|
|
// INCLUDES
|
88 |
|
|
//
|
89 |
|
|
|
90 |
|
|
#include <stdio.h> // printf
|
91 |
|
|
#include <stdlib.h> // printf
|
92 |
|
|
|
93 |
|
|
#include <cyg/kernel/kapi.h> // All the kernel specific stuff
|
94 |
|
|
#include <cyg/hal/hal_arch.h> // CYGNUM_HAL_STACK_SIZE_TYPICAL
|
95 |
|
|
|
96 |
|
|
#include "pdcecos_app.h"
|
97 |
|
|
|
98 |
|
|
// Define table boundaries
|
99 |
|
|
CYG_HAL_TABLE_BEGIN(__PDC_APP_TAB__, _pdc_apps);
|
100 |
|
|
CYG_HAL_TABLE_END(__PDC_APP_TAB_END__, _pdc_apps);
|
101 |
|
|
extern struct _pdc_app_entry __PDC_APP_TAB__[],
|
102 |
|
|
__PDC_APP_TAB_END__;
|
103 |
|
|
|
104 |
|
|
// ---------------------------------------------------------------------------
|
105 |
|
|
// PDCurses startup thread.
|
106 |
|
|
//
|
107 |
|
|
static char startup_stack[STACKSIZE];
|
108 |
|
|
cyg_handle_t startup_thread;
|
109 |
|
|
cyg_thread startup_thread_obj;
|
110 |
|
|
|
111 |
|
|
static void
|
112 |
|
|
startup(CYG_ADDRESS data)
|
113 |
|
|
{
|
114 |
|
|
cyg_ucount32 pdc_data_index;
|
115 |
|
|
struct _pdc_app_entry *pdc;
|
116 |
|
|
|
117 |
|
|
printf("SYSTEM INITIALIZATION in progress\n");
|
118 |
|
|
|
119 |
|
|
#ifdef USE_JFFS2
|
120 |
|
|
{
|
121 |
|
|
int res;
|
122 |
|
|
printf("... Mounting JFFS2 on \"/\"\n");
|
123 |
|
|
res = mount(CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2");
|
124 |
|
|
if (res < 0) {
|
125 |
|
|
printf("Mount \"/\" failed - res: %d\n", res);
|
126 |
|
|
}
|
127 |
|
|
chdir("/");
|
128 |
|
|
}
|
129 |
|
|
#endif
|
130 |
|
|
|
131 |
|
|
pdc_data_index = cyg_thread_new_data_index();
|
132 |
|
|
printf("data index = %d\n", pdc_data_index);
|
133 |
|
|
|
134 |
|
|
printf("Creating system threads\n");
|
135 |
|
|
for (pdc = __PDC_APP_TAB__; pdc != &__PDC_APP_TAB_END__; pdc++) {
|
136 |
|
|
printf("Creating %s thread\n", pdc->name);
|
137 |
|
|
cyg_thread_create(pdc->prio,
|
138 |
|
|
pdc->entry,
|
139 |
|
|
(cyg_addrword_t) pdc_data_index,
|
140 |
|
|
pdc->name,
|
141 |
|
|
(void *) pdc->stack, STACKSIZE,
|
142 |
|
|
&pdc->t, &pdc->t_obj);
|
143 |
|
|
}
|
144 |
|
|
printf("Starting threads\n");
|
145 |
|
|
for (pdc = __PDC_APP_TAB__; pdc != &__PDC_APP_TAB_END__; pdc++) {
|
146 |
|
|
printf("Starting %s\n", pdc->name);
|
147 |
|
|
cyg_thread_resume(pdc->t);
|
148 |
|
|
if (pdc->init) {
|
149 |
|
|
(pdc->init) (pdc_data_index);
|
150 |
|
|
}
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
printf("SYSTEM THREADS STARTED!\n");
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
void
|
157 |
|
|
cyg_user_start(void)
|
158 |
|
|
{
|
159 |
|
|
// Create the initial thread and start it up
|
160 |
|
|
cyg_thread_create(PDC_ECOS_STARTUP_PRIORITY,
|
161 |
|
|
startup,
|
162 |
|
|
(cyg_addrword_t) 0,
|
163 |
|
|
"System startup",
|
164 |
|
|
(void *) startup_stack, STACKSIZE,
|
165 |
|
|
&startup_thread, &startup_thread_obj);
|
166 |
|
|
cyg_thread_resume(startup_thread);
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
// ---------------------------------------------------------------------------
|
170 |
|
|
// EOF pdcecos_app.c
|