firmware: gave all apps a proper hello message and let them print their git revision
[osmocom-bb.git] / src / target / firmware / apps / hello_world / main.c
1 /* main program of Free Software for Calypso Phone */
2
3 /* (C) 2010 by Harald Welte <laforge@gnumonks.org>
4  *
5  * All Rights Reserved
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22
23 #include <stdint.h>
24 #include <stdio.h>
25 #include <string.h>
26
27 #include <debug.h>
28 #include <memory.h>
29 #include <delay.h>
30 #include <rffe.h>
31 #include <keypad.h>
32 #include <board.h>
33 #include <abb/twl3025.h>
34 #include <display.h>
35 #include <rf/trf6151.h>
36 #include <calypso/clock.h>
37 #include <calypso/tpu.h>
38 #include <calypso/tsp.h>
39 #include <calypso/dsp.h>
40 #include <calypso/irq.h>
41 #include <calypso/misc.h>
42 #include <comm/sercomm.h>
43 #include <comm/timer.h>
44
45 /* Main Program */
46 const char *hr = "======================================================================\n";
47
48 void key_handler(enum key_codes code, enum key_states state);
49
50 static void console_rx_cb(uint8_t dlci, struct msgb *msg)
51 {
52         if (dlci != SC_DLCI_CONSOLE) {
53                 printf("Message for unknown DLCI %u\n", dlci);
54                 return;
55         }
56
57         printf("Message on console DLCI: '%s'\n", msg->data);
58         display_puts((char *) msg->data);
59         msgb_free(msg);
60 }
61
62 static void l1a_l23_rx_cb(uint8_t dlci, struct msgb *msg)
63 {
64         int i;
65         puts("l1a_l23_rx_cb: ");
66         for (i = 0; i < msg->len; i++)
67                 printf("%02x ", msg->data[i]);
68         puts("\n");
69 }
70
71 int main(void)
72 {
73         board_init();
74
75         puts("\n\nOSMOCOM Hello World (revision " GIT_REVISION ")\n");
76         puts(hr);
77
78         /* Dump device identification */
79         dump_dev_id();
80         puts(hr);
81
82         /* Dump clock config before PLL set */
83         calypso_clk_dump();
84         puts(hr);
85
86         keypad_set_handler(&key_handler);
87
88         /* Dump clock config aftee PLL set */
89         calypso_clk_dump();
90         puts(hr);
91
92         /* Dump all memory */
93         //dump_mem();
94 #if 0
95         /* Dump Bootloader */
96         memdump_range((void *)0x00000000, 0x2000);
97         puts(hr);
98 #endif
99
100         display_set_attr(DISP_ATTR_INVERT);
101         display_puts("Hello World");
102
103         sercomm_register_rx_cb(SC_DLCI_CONSOLE, console_rx_cb);
104         sercomm_register_rx_cb(SC_DLCI_L1A_L23, l1a_l23_rx_cb);
105
106         /* beyond this point we only react to interrupts */
107         puts("entering interrupt loop\n");
108         while (1) {
109                 update_timers();
110         }
111
112         twl3025_power_off();
113
114         while (1) {}
115 }
116
117 void key_handler(enum key_codes code, enum key_states state)
118 {
119         char test[16];
120
121         if (state != PRESSED)
122                 return;
123
124         switch (code) {
125         case KEY_0:
126         case KEY_1:
127         case KEY_2:
128         case KEY_3:
129         case KEY_4:
130         case KEY_5:
131         case KEY_6:
132         case KEY_7:
133         case KEY_8:
134         case KEY_9:
135                 sprintf(test, "%d", code - KEY_0);
136                 display_puts(test);
137                 break;
138         case KEY_STAR:
139                 sprintf(test, "*", 0);
140                 display_puts(test);
141                 break;
142         case KEY_HASH:
143                 sprintf(test, "#", 0);
144                 display_puts(test);
145                 break;
146         default:
147                 break;
148         }
149 }