-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNuttxPortingGuide.html
7022 lines (6609 loc) · 290 KB
/
NuttxPortingGuide.html
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<head>
<title>NuttX Porting Guide</title>
<meta name="author" content="Gregory Nutt">
</head>
<body background="backgd.gif">
<hr><hr>
<table width ="100%">
<tr align="center" bgcolor="#e4e4e4">
<td>
<h1><big><font color="#3c34ec">
<i>NuttX RTOS Porting Guide</i>
</font></big></h1>
<p>Last Updated: January 31, 2018</p>
</td>
</tr>
</table>
<hr><hr>
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<h1>Table of Contents</h1>
</td>
</tr>
</table>
<ul>
<a href="#Introduction">1.0 Introduction</a><br>
<a href="#DirectoryStructure">2.0 Directory Structure</a>
<ul>
<a href="#DirStructDocumentation">2.1 nuttx/Documentation</a><br>
<a href="#DirStructArch">2.2 nuttx/arch/</a>
<ul>
<a href="#archdirectorystructure">2.2.1 Subdirectory Structure</a><br>
<a href="#summaryofarchfiles">2.2.2 Summary of Files</a><br>
<a href="#supportedarchitectures">2.2.3 Supported Architectures</a>
</ul>
<a href="#DirStructBinFmt">2.3 nuttx/binfmt/</a><br>
<a href="#DirStructAudio">2.4 nuttx/audio/</a><br>
<a href="#DirStructConfigs">2.5 nuttx/configs/</a>
<ul>
<a href="#configsdirectorystructure">2.5.1 Subdirectory Structure</a><br>
<a href="#summaryofconfigfiles">2.5.2 Summary of Files</a>
<ul>
<a href="#boardlogic">2.5.2.1 Board Specific Logic</a><br>
<a href="#boardconfigsubdirs">2.5.2.2 Board Specific Configuration Sub-Directories</a>
</ul>
<a href="#supportedboards">2.5.3 Supported Boards</a><br>
<a href="#newboardconfig">2.5.4 Adding a New Board Configuration</a>
</ul>
<a href="#DirStructDrivers">2.6 nuttx/drivers/</a><br>
<a href="#DirStructCrypto">2.7 nuttx/crypto/</a><br>
<a href="#DirStructFs">2.8 nuttx/fs/</a><br>
<a href="#DirStructGraphics">2.9 nuttx/graphics/</a><br>
<a href="#DirStructInclude">2.10 nuttx/include/</a><br>
<a href="#DirStructLib">2.11 nuttx/lib/</a><br>
<a href="#DirStructLibC">2.12 nuttx/libc/</a><br>
<a href="#DirStructLibXX">2.13 nuttx/libxx/</a><br>
<a href="#DirStructMm">2.14 nuttx/mm/</a><br>
<a href="#DirStructNet">2.15 nuttx/net</a><br>
<a href="#DirStructSched">2.16 nuttx/sched/</a><br>
<a href="#DirStructSyscall">2.17 nuttx/syscall/</a><br>
<a href="#DirStructTools">2.18 nuttx/tools/</a><br>
<a href="#DirStructWireless">2.19 nuttx/wireless/</a><br>
<a href="#topmakefile">2.20 nuttx/Makefile</a><br>
</ul>
<a href="#configandbuild">3.0 Configuring and Building</a>
<ul>
<a href="#configuringnuttx">3.1 Configuring NuttX</a><br>
<a href="#buildingnuttx">3.2 Building NuttX</a>
</ul>
<a href="#ArchAPIs">4.0 Architecture APIs</a>
<ul>
<a href="#naming">4.1 Naming and Header File Conventions</a><br>
<a href="#imports">4.2 APIs Exported by Architecture-Specific Logic to NuttX</a>
<ul>
<a href="#upinitialize">4.2.1 <code>up_initialize()</code></a><br>
<a href="#upidle">4.2.2 <code>up_idle()</code></a><br>
<a href="#upinitialstate">4.2.3 <code>up_initial_state()</code></a><br>
<a href="#upcreatestack">4.2.4 <code>up_create_stack()</code></a><br>
<a href="#upusestack">4.2.5 <code>up_use_stack()</code></a><br>
<a href="#upstackframe">4.2.6 <code>up_stack_frame()</code></a><br>
<a href="#upreleasestack">4.2.7 <code>up_release_stack()</code></a><br>
<a href="#upunblocktask">4.2.8 <code>up_unblock_task()</code></a><br>
<a href="#upblocktask">4.2.9 <code>up_block_task()</code></a><br>
<a href="#upreleasepending">4.2.10 <code>up_release_pending()</code></a><br>
<a href="#upreprioritizertr">4.2.11 <code>up_reprioritize_rtr()</code></a><br>
<a href="#_exit">4.2.12 <code>_exit()</code></a><br>
<a href="#upassert">4.2.13 <code>up_assert()</code></a><br>
<a href="#upschedulesigaction">4.2.14 <code>up_schedule_sigaction()</code></a><br>
<a href="#upallocateheap">4.2.15 <code>up_allocate_heap()</code></a><br>
<a href="#upinterruptcontext">4.2.16 <code>up_interrupt_context()</code></a><br>
<a href="#updisableirq">4.2.17 <code>up_disable_irq()</code></a><br>
<a href="#upenableirq">4.2.18 <code>up_enable_irq()</code></a><br>
<a href="#upprioritizeirq">4.2.19 <code>up_prioritize_irq()</code></a><br>
<a href="#upputc">4.2.20 <code>up_putc()</code></a><br>
</ul>
<a href="#systemtime">4.3 System Time and Clock</a>
<ul>
<a href="#basictimer">4.3.1 Basic System Timer</a><br>
<a href="#timerhw">4.3.2 Hardware</a><br>
<a href="#systcktime">4.3.3 System Tick and Time</a><br>
<a href="#tickless">4.3.4 Tickless OS</a><br>
<a href="#Watchdogs">4.3.5 Watchdog Timer Interfaces</a>
</ul>
<a href="#workqueues">4.4 Work Queues</a>
<ul>
<a href="#wqclasses">4.4.1 Classes of Work Queues</a>
<ul>
<a href="#hpwork">4.4.1.1 High Priority Kernel Work queue</a><br>
<a href="#lpwork">4.4.1.2 Low Priority Kernel Work Queue</a><br>
<a href="#usrwork">4.4.1.3 User-Mode Work Queue</a>
</ul>
<a href="#cmnwqifs">4.4.2 Common Work Queue Interfaces</a>
<ul>
<a href="#wqids">4.4.2.1 Work Queue IDs</a><br>
<a href="#wqiftypes">4.4.2.2 Work Queue Interface Types</a><br>
<a href="#wqintfs">4.4.2.3 Work Queue Interfaces</a>
<ul>
<a href="#workqueue">4.4.2.3.1 <code>work_queue()</code></a><br>
<a href="#workcancel">4.4.2.3.2 <code>work_cancel()</code></a><br>
<a href="#worksignal">4.4.2.3.3 <code>work_signal()</code></a><br>
<a href="#workavailable">4.4.2.3.4 <code>work_available()</code></a><br>
<a href="#workusrstart">4.4.2.3.5 <code>work_usrstart()</code></a><br>
<a href="#lpworkboostpriority">4.4.2.3.6 <code>lpwork_boostpriority()</code></a><br>
<a href="#lpworkrestorepriority">4.4.2.3.7 <code>lpwork_restorepriority()</code></a>
</ul>
</ul>
</ul>
<a href="#addrenv">4.5 Address Environments</a>
<ul>
<a href="#up_addrenv_create">4.5.1 <code>up_addrenv_create()</code></a><br>
<a href="#up_addrenv_destroy">4.5.2 <code>up_addrenv_destroy()</code></a><br>
<a href="#up_addrenv_vtext">4.5.3 <code>up_addrenv_vtext()</code></a><br>
<a href="#up_addrenv_vdata">4.5.4 <code>up_addrenv_vdata()</code></a><br>
<a href="#up_addrenv_heapsize">4.5.5 <code>up_addrenv_heapsize()</code></a><br>
<a href="#up_addrenv_select">4.5.6 <code>up_addrenv_select()</code></a><br>
<a href="#up_addrenv_restore">4.5.7 <code>up_addrenv_restore()</code></a><br>
<a href="#up_addrenv_clone">4.5.8 <code>up_addrenv_clone()</code></a><br>
<a href="#up_addrenv_attach">4.5.9 <code>up_addrenv_attach()</code></a><br>
<a href="#up_addrenv_detach">4.5.10 <code>up_addrenv_detach()</code></a><br>
<a href="#up_addrenv_ustackalloc">4.5.11 <code>up_addrenv_ustackalloc()</code></a><br>
<a href="#up_addrenv_ustackfree">4.5.12 <code>up_addrenv_ustackfree()</code></a><br>
<a href="#up_addrenv_vustack">4.5.13 <code>up_addrenv_vustack()</code></a><br>
<a href="#up_addrenv_ustackselect">4.5.14 <code>up_addrenv_ustackselect()</code></a><br>
<a href="#up_addrenv_kstackalloc">4.5.15 <code>up_addrenv_kstackalloc()</code></a><br>
<a href="#up_addrenv_kstackfree">4.5.16 <code>up_addrenv_kstackfree()</code></a>
</ul>
<a href="#exports">4.6 APIs Exported by NuttX to Architecture-Specific Logic</a>
<ul>
<a href="#osstart">4.6.1 <code>os_start()</code></a><br>
<a href="#listmgmt">4.6.2 OS List Management APIs</a><br>
<a href="#schedprocesstimer">4.6.3 <code>sched_process_timer()</code></a><br>
<a href="#schedtimerexpiration">4.6.4 <code>sched_timer_expiration()</code></a><br>
<a href="#schedalarmexpiration">4.6.5 <code>sched_alarm_expiration()</code></a><br>
<a href="#irqdispatch">4.6.6 <code>irq_dispatch()</code></a>
</ul>
<a href="#internalOS">4.7 Application OS vs. Internal OS Interfaces</a><br>
<a href="#boardctl">4.8 <code>boardctl()</code> Application Interface</a><br>
<a href="#boardsmp">4.9 Symmetric Multiprocessing (SMP) Application Interface</a>
<ul>
<a href="#uptestset">4.9.1 <code>up_testset()</code></a><br>
<a href="#upcpuindex">4.9.2 <code>up_cpu_index()</code></a><br>
<a href="#upcpustart">4.9.3 <code>up_cpu_start()</code></a><br>
<a href="#upcpupause">4.9.4 <code>up_cpu_pause()</code></a><br>
<a href="#upcpuresume">4.9.5 <code>up_cpu_resume()</code></a>
</ul>
<a href="#shm">4.10 Shared Memory</a>
<ul>
<a href="#upshmat">4.10.1 <code>up_shmat()</code></a><br>
<a href="#upshmdt">4.10.2 <code>up_shmdt()</code></a><br>
</ul>
<a href="#demandpaging">4.11 On-Demand Paging</a><br>
<a href="#ledsupport">4.12 LED Support</a>
<ul>
<a href="#ledheaders">4.12.1 Header Files</a><br>
<a href="#leddefinitions">4.12.2 LED Definitions</a><br>
<a href="#ledapis">4.12.3 Common LED interfaces</a>
</ul>
<a href="#iobs">4.13 I/O Buffer Management</a>
<ul>
<a href="#iobconfig">4.13.1 Configuration Options</a><br>
<a href="#iobthrottle">4.13.2 Throttling</a><br>
<a href="#iobtypes">4.13.3 Public Types</a><br>
<a href="#iobprotos">4.13.4 Public Function Prototypes</a>
</ul>
</ul>
<a href="#NxFileSystem">5.0 NuttX File System</a><br>
<a href="#DeviceDrivers">6.0 NuttX Device Drivers</a>
<ul>
<a href="#chardrivers">6.1 Character Device Drivers</a><br>
<ul>
<a href="#serialdrivers">6.1.1 Serial Device Drivers</a><br>
<a href="#tscdrivers">6.1.2 Touchscreen Device Drivers</a><br>
<a href="#analogdrivers">6.1.3 Analog (ADC/DAC) Drivers</a><br>
<a href="#pwmdrivers">6.1.4 PWM Drivers</a><br>
<a href="#candrivers">6.1.5 CAN Drivers</a><br>
<a href="#quadencoder">6.1.6 Quadrature Encoder Drivers</a><br>
<a href="#timerdriver">6.1.7 Timer Drivers</a><br>
<a href="#rtcriver">6.1.8 RTC Drivers</a><br>
<a href="#wdogdriver">6.1.9 Watchdog Timer Drivers</a><br>
<a href="#kbddriver">6.1.10 Keyboard/Keypad Drivers</a><br>
</ul>
<a href="#blockdrivers">6.2 Block Device Drivers</a><br>
<a href="#specdrivers">6.3 Specialized Device Drivers</a>
<ul>
<a href="#ethdrivers">6.3.1 Ethernet Device Drivers</a><br>
<a href="#spidrivers">6.3.2 SPI Device Drivers</a><br>
<a href="#i2cdrivers">6.3.3 I2C Device Drivers</a><br>
<a href="#fbdrivers">6.3.4 Frame Buffer Drivers</a><br>
<a href="#lcddrivers">6.3.5 LCD Drivers</a><br>
<a href="#mtddrivers">6.3.6 Memory Technology Device Drivers</a><br>
<a href="#sdiodrivers">6.3.7 SDIO Device Drivers</a><br>
<a href="#usbhostdrivers">6.3.8 USB Host-Side Drivers</a><br>
<a href="#usbdevdrivers">6.3.9 USB Device-Side Drivers</a><br>
</ul>
<a href="#syslog">6.4 SYSLOG</a>
<ul>
<a href="#syslogif">6.4.1 SYSLOG Interfaces</a><br>
<a href="#syslogchannels">6.4.2 SYSLOG Channels</a><br>
<a href="#syslogoptions">6.4.3 SYSLOG Channel Options</a><br>
<a href="#ramlog">6.4.4 RAM Logging Device</a>
</ul>
<a href="#pwrmgmt">6.5 Power Management</a>
<ul>
<a href="#pmoverview">6.5.1 Overview</a><br>
<a href="#pminterfaces">6.5.2 Interfaces</a><br>
<a href="#pmcallbacks">6.5.3 Callbacks</a>
</ul>
</ul>
<a href="#apndxconfigs">Appendix A: NuttX Configuration Settings</a><br>
<a href="#apndxtrademarks">Appendix B: Trademarks</a>
</ul>
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<h1>1.0 <a name="Introduction">Introduction</a></h1>
</td>
</tr>
</table>
<p><b>Overview</b>
This document provides and overview of the NuttX build and configuration
logic and provides hints for the incorporation of new processor/board architectures
into the build.
</p>
<p>
See also <code>arch/README.txt</code> and <code>configs/README.txt</code>.
</p>
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<h1>2.0 <a name="DirectoryStructure">Directory Structure</a></h1>
</td>
</tr>
</table>
<p>
<b>Directory Structure</b>.
The general directory layout for NuttX is very similar to the directory structure
of the Linux kernel -- at least at the most superficial layers.
At the top level is the main makefile and a series of sub-directories identified
below and discussed in the following paragraphs:
</p>
<ul><pre>
.
|- nuttx
| |-- <a href="#topmakefile">Makefile</a>
| |-- Kconfig
| |-- <a href="#DirStructDocumentation">Documentation</a>
| | `-- <i>(documentation files)</i>/
| |-- <a href="#DirStructArch">arch</a>/
| | |-- Kconfig
| | |-- <i><arch-name></i>/
| | | |-- include/
| | | | |--<i><chip-name></i>/
| | | | | `-- <i>(chip-specific header files)</i>
| | | | |--<i><other-chips></i>/
| | | | `-- <i>(architecture-specific header files)</i>
| | | `-- src/
| | | |--<i><chip-name></i>/
| | | | `-- <i>(chip-specific source files)</i>
| | | |--<i><other-chips></i>/
| | | `-- <i>(architecture-specific source files)</i>
| | `-- <i><other-architecture directories></i>/
| |-- <a href="#DirStructAudio">audio</a>/
| | |-- Makefile
| | |-- Kconfig
| | `-- <i>(common audio source files)</i>
| |-- <a href="#DirStructBinFmt">binfmt</a>/
| | |-- Makefile
| | |-- Kconfig
| | |-- <i>(binfmt-specific sub-directories)</i>/
| | | `-- <i>(binfmt-specific source files)</i>
| | `-- <i>(common binfmt source files)</i>
| |-- <a href="#DirStructConfigs">configs</a>/
| | |-- <i><board-name></i>/
| | | |-- include/
| | | | `-- <i>(other board-specific header files)</i>
| | | |-- src/
| | | | `-- <i>(board-specific source files)</i>
| | | |---<i><config-name></i>/
| | | | `-- <i>(board configuration-specific source files)</i>
| | | `---<i>(other configuration sub-directories for this board)</i>/
| | `-- <i><(other board directories)></i>/
| |-- <a href="#DirStructDrivers">drivers</a>/
| | |-- Makefile
| | |-- Kconfig
| | |-- <i>(driver-specific sub-directories)/</i>
| | | `-- <i>(driver-specific source files)</i>
| | `-- <i>(common driver source files)</i>
| |-- <a href="#DirStructFs">fs</a>/
| | |-- Makefile
| | |-- Kconfig
| | |-- <i>(file system-specific sub-directories)</i>/
| | | `-- <i>(file system-specific source files)</i>
| | `-- <i>(common file system source files)</i>
| |-- <a href="#DirStructGraphics">graphics</a>/
| | |-- Makefile
| | |-- Kconfig
| | |-- <i>(feature-specific sub-directories)</i>/
| | | `-- <i>(feature-specific source files library source files)</i>
| | `-- <i>(common graphics-related source files)</i>
| |-- <a href="#DirStructInclude">include</a>/
| | |-- <i>(standard header files)</i>
| | |-- <i>(standard include sub-directories)</i>
| | | `-- <i>(more standard header files)</i>
| | |-- <i>(non-standard include sub-directories)</i>
| | `-- <i>(non-standard header files)</i>
| |-- <a href="#DirStructLibC">libc</a>/
| | |-- Makefile
| | |-- Kconfig
| | `-- <i>(libc source files)</i>
| |-- <a href="#DirStructLibXX">libxx</a>/
| | |-- Makefile
| | |-- Kconfig
| | `-- <i>(libxx management source files)</i>
| |-- <a href="#DirStructMm">mm</a>/
| | |-- Makefile
| | |-- Kconfig
| | `-- <i>(memory management source files)</i>
| |-- <a href="#DirStructNet">net</a>/
| | |-- Makefile
| | |-- Kconfig
| | |-- arp/
| | | `-- <i>(ARP source files)</i>
| | |-- devif/
| | | `-- <i>(Ethernet device interface source files)</i>
| | |-- icmp/
| | | `-- <i>(ICMP source files)</i>
| | |-- igmp/
| | | `-- <i>(IGMP source files)</i>
| | |-- iob/
| | | `-- <i>(I/O buffering source files)</i>
| | |-- ipv6/
| | | `-- <i>(IPv6 source files)</i>
| | |-- netdev/
| | | `-- <i>(Socket device interface source files)</i>
| | |-- pkt/
| | | `-- <i>(Packet socket source files)</i>
| | |-- route/
| | | `-- <i>(Routing table source files)</i>
| | |-- socket/
| | | `-- <i>(BSD socket source files)</i>
| | |-- tcp/
| | | `-- <i>(TCP source files)</i>
| | |-- udp/
| | | `-- <i>(UDP source files)</i>
| | `-- utils/
| | `-- <i>(Miscellaneous, utility source files)</i>
| |-- <a href="#DirStructSched">sched</a>/
| | |-- Makefile
| | |-- Kconfig
| | `-- <i>(sched source files)</i>
| |-- <a href="#DirStructSysCall">syscall</a>/
| | |-- Makefile
| | |-- Kconfig
| | `-- <i>(syscall source files)</i>
| |-- <a href="#DirStructTools">tools</a>/
| | `-- <i>(miscellaneous scripts and programs)</i>
| `-- <a href="#DirStructWireless">tools</a>/
| |-- Makefile
| |-- Kconfig
| `-- <i>(wireless management source files)</i>
`- apps
|-- <a href="#DirStructNetUtils">netutils</a>/
| |-- Makefile
| |-- Kconfig
| |-- <i>(network feature sub-directories)</i>/
| | `-- <i>(network feature source files)</i>
| `-- <i>(netutils common files)</i>
|-- <a href="#DirStructNshLib">nshlib</a>/
| |-- Makefile
| |-- Kconfig
| `-- <i>NuttShell (NSH) files</i>
|-- <i>(Board-specific applications)</i>/
| |-- Makefile
| |-- Kconfig
| |-- <i>(Board-specific application sub-directories)</i>/
| | `-- <i>(Board-specific application source files)</i>
| `-- <i>(Board-specific common files)</i>
`-- <a href="#DirStructExamples">examples</a>/
`-- <i>(example)</i>/
|-- Makefile
|-- Kconfig
`-- <i>(example source files)</i>
</pre></ul>
<p>
<b>Configuration Files</b>.
The NuttX configuration consists of:
</p>
<ul>
<li>
<i>Processor architecture specific files</i>.
These are the files contained in the <code>arch/</code><i><arch-name></i><code>/</code> directory
and are discussed in a paragraph <a href="#archdirectorystructure">below</a>.
</li>
<li>
<i>Chip/SoC specific files</i>.
Each processor processor architecture is embedded in chip or <i>System-on-a-Chip</i> (SoC) architecture.
The full chip architecture includes the processor architecture plus chip-specific interrupt logic,
clocking logic, general purpose I/O (GPIO) logic, and specialized, internal peripherals (such as UARTs, USB, etc.).
<p>
These chip-specific files are contained within chip-specific sub-directories in the
<code>arch/</code><i><arch-name></i><code>/</code> directory and are selected via
the <code>CONFIG_ARCH_name</code> selection.
</p>
</li>
<li>
<i>Board specific configurations</i>.
In order to be usable, the chip must be contained in a board environment.
The board configuration defines additional properties of the board including such things as
peripheral LEDs, external peripherals (such as network, USB, etc.).
<p>
These board-specific configuration files can be found in the
<code>configs/</code><i><board-name></i><code>/</code> sub-directories and are discussed
in a paragraph <a href="#configsdirectorystructure">below</a>.
</p>
</li>
</ul>
<h2>2.1 <a name="DirStructDocumentation">Documentation</a></h2>
<p>
General documentation for the NuttX OS resides in this directory.
</p>
<h2>2.2 <a name="DirStructArch">nuttx/arch</a></h2>
<h3><a name="archdirectorystructure">2.2.1 Subdirectory Structure</a></h3>
<p>
This directory contains several sub-directories, each containing
architecture-specific logic.
The task of porting NuttX to a new processor consists of
add a new subdirectory under <code>arch/</code> containing logic specific
to the new architecture.
The complete board port in is defined by the architecture-specific code in this
directory (plus the board-specific configurations in the <code>config/</code>
subdirectory).
Each architecture must provide a subdirectory, <i><arch-name></i>
under <code>arch/</code> with the following characteristics:
</p>
<ul><pre>
<i><arch-name></i>/
|-- include/
| |--<i><chip-name></i>/
| | `-- <i>(chip-specific header files)</i>
| |--<i><other-chips></i>/
| |-- arch.h
| |-- irq.h
| |-- types.h
| |-- limits.h
| `-- syscall.h
`-- src/
|--<i><chip-name></i>/
| `-- <i>(chip-specific source files)</i>
|--<i><other-chips></i>/
|-- Makefile
`-- <i>(architecture-specific source files)</i>
</pre></ul>
<h3><a name="summaryofarchfiles">2.2.2 Summary of Files</a></h3>
<ul>
<li>
<code>include/</code><i><chip-name></i><code>/</code>
This sub-directory contains chip-specific header files.
</li>
<li>
<code>include/arch.h</code>:
This is a hook for any architecture specific definitions that may
be needed by the system. It is included by <code>include/nuttx/arch.h</code>.
</li>
<li>
<code>include/types.h</code>:
This provides architecture/toolchain-specific definitions for
standard types. This file should <code>typedef</code>:
<ul><code>
_int8_t, _uint8_t, _int16_t, _uint16_t, _int32_t, _uint32_t_t
</code></ul>
<p>and if the architecture supports 24- or 64-bit integers</p>
<ul><code>
_int24_t, _uint24_t, int64_t, uint64_t
</code></ul>
<p>
NOTE that these type names have a leading underscore character. This
file will be included(indirectly) by include/stdint.h and typedef'ed to
the final name without the underscore character. This roundabout way of
doings things allows the stdint.h to be removed from the include/
directory in the event that the user prefers to use the definitions
provided by their toolchain header files
</p>
<p>
And finally
</p>
<ul><code>
irqstate_t
</code></ul>
<p>
Must be defined to the be the size required to hold the interrupt
enable/disable state.
</p>
<p>
This file will be included by include/sys/types.h and be made
available to all files.
</p>
</li>
<li>
<code>include/irq.h</code>:
This file needs to define some architecture specific functions (usually
inline if the compiler supports inlining) and some structures. These include:
<ul>
<li>
<code>struct xcptcontext</code>:
This structures represents the saved context of a thread.
</li>
<li>
<code>irqstate_t up_irq_save(void)</code>:
Used to disable all interrupts.
In the case of multi-CPU platforms, this function disables interrupts on CPUs.
</li>
<li>
<code>void up_irq_restore(irqstate_t flags)</code>:
Used to restore interrupt enables to the same state as before <code>up_irq_save()</code> was called.
</li>
</ul>
<p>
This file must also define <code>NR_IRQS</code>, the total number of IRQs supported
by the board.
</p>
</li>
<li>
<code>include/syscall.h</code>:
This file needs to define some architecture specific functions (usually
inline if the compiler supports inlining) to support software interrupts
or <i>syscall</i>s that can be used all from user-mode applications into
kernel-mode NuttX functions.
This directory must always be provided to prevent compilation errors.
However, it need only contain valid function declarations if the architecture
supports the <code>CONFIG_BUILD_PROTECTED</code> or <code>CONFIG_BUILD_KERNEL</code>configurations.
<ul>
<li>
<code>uintptr_t sys_call0(unsigned int nbr)</code>:
<code>nbr</code> is one of the system call numbers that can be found in <code>include/sys/syscall.h</code>.
This function will perform a system call with no (additional) parameters.
</li>
<li>
<code>uintptr_t sys_call1(unsigned int nbr, uintptr_t parm1)</code>:
<code>nbr</code> is one of the system call numbers that can be found in <code>include/sys/syscall.h</code>.
This function will perform a system call with one (additional) parameter.
</li>
<li>
<code>uintptr_t sys_call2(unsigned int nbr, uintptr_t parm1, uintptr_t parm2)</code>:
<code>nbr</code> is one of the system call numbers that can be found in <code>include/sys/syscall.h</code>.
This function will perform a system call with two (additional) parameters.
</li>
<li>
<code>uintptr_t sys_call3(unsigned int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3)</code>:
<code>nbr</code> is one of the system call numbers that can be found in <code>include/sys/syscall.h</code>.
This function will perform a system call with three (additional) parameters.
</li>
<li>
<code>uintptr_t sys_call4(unsigned int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3, uintptr_t parm4)</code>:
<code>nbr</code> is one of the system call numbers that can be found in <code>include/sys/syscall.h</code>.
This function will perform a system call with four (additional) parameters.
</li>
<li>
<code>uintptr_t sys_call5(unsigned int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3, uintptr_t parm4, uintptr_t parm5)</code>:
<code>nbr</code> is one of the system call numbers that can be found in <code>include/sys/syscall.h</code>.
This function will perform a system call with five (additional) parameters.
</li>
<li>
<code>uintptr_t sys_call6(unsigned int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3, uintptr_t parm4, uintptr_t parm5, uintptr_t parm6)</code>:
<code>nbr</code> is one of the system call numbers that can be found in <code>include/sys/syscall.h</code>.
This function will perform a system call with six (additional) parameters.
</li>
</ul>
<p>
This file must also define <code>NR_IRQS</code>, the total number of IRQs supported
by the board.
</p>
</li>
<li>
<code>src/</code><i><chip-name></i><code>/</code>
This sub-directory contains chip-specific source files.
</li>
<li>
<code>src/Makefile</code>:
This makefile will be executed to build the targets <code>src/libup.a</code> and
<code>src/up_head.o</code>. The <code>up_head.o</code> file holds the entry point into the system
(power-on reset entry point, for example). It will be used in
the final link with <code>libup.a</code> and other system archives to generate the
final executable.
</li>
<li>
<i>(architecture-specific source files)</i>.
The file <code>include/nuttx/arch.h</code> identifies all of the APIs that must
be provided by the architecture specific logic. (It also includes
<code>arch/</code><i><arch-name></i><code>/arch.h</code> as described above).
</li>
</ul>
<h3><a name="supportedarchitectures">2.2.3 Supported Architectures</a></h3>
<p>
<b>Architecture- and Chip-Specific Directories</b>.
All processor architecture-specific directories are maintained in sub-directories of
the <code>arch/</code> directory.
Different chips or SoC's may implement the same processor core.
Chip-specific logic can be found in sub-directories under the architecture
directory.
Current architecture/chip directories are summarized below:
</p>
<ul>
<li><code>arch/sim</code>:
A user-mode port of NuttX to the x86 Linux platform is available.
The purpose of this port is primarily to support OS feature development.
This port does not support interrupts or a real timer (and hence no
round robin scheduler) Otherwise, it is complete.
</li>
<p>NOTE: This target will not run on Cygwin probably for many reasons but
first off because it uses some of the same symbols as does cygwind.dll.
</p>
<li><code>arch/arm</code>:
This directory holds common ARM architectures.
</li>
<li><code>configs/mcu123-lpc214x</code>:
The mcu123.com lpc214x development board.
This is a work in progress.
</li>
<li><code>arch/z16f</code>:
Zilog z16f Microcontroller.
This port uses the Zilog z16f2800100zcog Development Kit.
This port was released with nuttx-0.3.7.
</li>
<li><code>arch/z80</code>:
This directory holds 8-bit ZiLOG architectures. At present, this includes the
Zilog z80, ez80Acclaim! and z8Encore! Microcontrollers.
<ul>
<li><code>arch/z80/include</code> and <code>arch/z80/src/common</code>:
Common logic.
</li>
<li><code>arch/z80/include/z80</code> and <code>arch/z80/src/z80</code>:
The Z80 port was released in nuttx-0.3.6 has been verified using only a
z80 instruction simulator called z80sim.
This port also uses the SDCC toolchain (http://sdcc.sourceforge.net/)
(verified with version 2.6.0 and 2.7.0).
</li>
<li><code>arch/z80/include/ez80</code> and <code>arch/z80/src/ez80</code>:
The ez80Acclaim! port uses the ZiLOG ez80f0910200kitg development kit, eZ80F091 part,
with the Zilog ZDS-II Windows command line tools.
The development environment is Cygwin under WinXP.
This is a work in progress. Verified ez80 support will be announced in a future NuttX release.
</li>
<li><code>arch/z80/include/z8</code> and <code>arch/z80/src/z8</code>:
The Z8Encore! port uses either the ZiLOG z8encore000zco development kit, Z8F6403 part,
or the z8f64200100kit development kit, Z8F6423 part with the Zilog ZDS-II Windows command line
tools. The development environment is Cygwin under WinXP.
The initial release, verified only on the ZDS-II ez8 simulator, was released in nuttx-0.3.9.
</li>
</ul>
</li>
</ul>
<p>
<b>Deprecated Architecture Directories</b>.
The following architecture directories are deprecated. They have been
replaced by the logic in <code>arm/arm</code> and will deleted when
<code>arch/arm</code> is fully verified.
</p>
<ul>
<li><code>arch/c5471</code>:
Replaced with <code>arch/arm/include/c5471</code> and
<code>arch/arm/src/c5471</code>.
</li>
<li><code>arch/dm320</code>:
Replaced with <code>arch/arm/include/dm320</code> and
<code>arch/arm/src/dm320</code>.
</li>
</ul>
<p>
Other ports for the for the TI TMS320DM270 and for MIPS are in various states
of progress
</p>
<h2>2.3 <a name="DirStructBinFmt">nuttx/binfmt</a></h2>
<p>
The <code>binfmt/</code> subdirectory contains logic for loading binaries in the file
system into memory in a form that can be used to execute them.
</p>
<h2>2.4 <a name="DirStructAudio">nuttx/audio</a></h2>
<p>
The <code>audio/</code> subdirectory contains the NuttX audio sub-system.
</p>
<h2>2.5 <a name="DirStructConfigs">nuttx/configs</a></h2>
<p>
The <code>configs/</code> subdirectory contains configuration data for each board.
These board-specific configurations plus the architecture-specific configurations in
the <code>arch/</code> subdirectory complete define a customized port of NuttX.
</p>
<h3><a name="configsdirectorystructure">2.5.1 Subdirectory Structure</a></h3>
<p>
The configs directory contains board specific configuration files. Each board must
provide a subdirectory <board-name> under <code>configs/</code> with the following characteristics:
</p>
<ul><pre>
<i><board-name></i>
|-- Kconfig
|-- include/
| |-- board.h
| `-- <i>(board-specific header files)</i>
|-- src/
| |-- Makefile
| `-- <i>(board-specific source files)</i>
|-- <i><config1-dir></i>
| |-- Make.defs
| `-- defconfig
|-- <i><config2-dir></i>
| |-- Make.defs
| `-- defconfig
| ...
|-- scripts/
| |-- <i>(linker script files)</i>
| `-- Make.defs <i>(optional</i>
`-- <i>(other board-specific configuration sub-directories)</i>/
</pre></ul>
<h3><a name="summaryofconfigfiles">2.5.2 Summary of Files</a></h3>
<h4><a name="boardlogic">2.5.2.1 Board Specific Logic</a></h4>
<ul>
<li>
<code>include/</code>:
This directory contains board specific header files.
This directory will be linked as <code>include/arch/board</code> at configuration time
and can be included via <code>#include <arch/board/header.h></code>.
These header file can only be included by files in <code>arch/</code><i><arch-name></i><code>/include/</code>
and <code>arch/</code><i><arch-name></i><code>/src/</code>.
</li>
<li>
<code>src/</code>:
This directory contains board specific drivers.
This directory will be linked as <i><config></i><code>/arch/</code><i><arch-name></i><code>/src/board</code> at configuration
time and will be integrated into the build system.
</li>
<li>
<code>src/Makefile</code>:
This makefile will be invoked to build the board specific drivers.
It must support the following targets: <code>libext$(LIBEXT)</code>, <code>clean</code>, and <code>distclean</code>.
</li>
</ul>
<h4><a name="boardconfigsubdirs">2.5.2.2 Board Specific Configuration Sub-Directories</a></h4>
<p>
The <code>configs/</code><i><board-name></i><code>/</code> sub-directory holds all of the
files that are necessary to configure NuttX for the particular board.
A board may have various different configurations using the common source files.
Each board configuration is described by two files: <code>Make.defs</code> and <code>defconfig</code>.
Typically, each set of configuration files is retained in a separate configuration sub-directory
(<i><config1-dir></i>, <i><config2-dir></i>, .. in the above diagram).
</p>
<p>
NOTE: That the <code>Make.defs</code> file may reside in one of two locations:
There may be a unique Make.defs file for each configuration in the configuration directory <i>OR</i>
if that file is absent, there may be a common board <code>Make.defs</code> file in the <code>/scripts</code> directory.
The <code>Make.defs</code> file in the configuration takes precedence if it is present.
</p>
<p>
The procedure for configuring NuttX is described <a href="#configuringnuttx">below</a>,
This paragraph will describe the contents of these configuration files.
</p>
<ul>
<li>
<code>Make.defs</code>: This makefile fragment provides architecture and
tool-specific build options. It will be included by all other
makefiles in the build (once it is installed). This make fragment
should define:
<ul>
<li>Tools: <code>CC</code>, <code>LD</code>, <code>AR</code>, <code>NM</code>, <code>OBJCOPY</code>, <code>OBJDUMP</code></li>
<li>Tool options: <code>CFLAGS</code>, <code>LDFLAGS</code></li>
</ul>
<p>
When this makefile fragment runs, it will be passed <code>TOPDIR</code> which
is the path to the root directory of the build. This makefile
fragment should include:
</p>
<ul>
<li><code>$(TOPDIR)/.config </code> : Nuttx configuration</li>
<li><code>$(TOPDIR)/tools/Config.mk</code> : Common definitions</li>
</ul>
<p>
Definitions in the <code>Make.defs</code> file probably depend on some of the
settings in the .<code>config</code> file. For example, the <code>CFLAGS</code> will most likely be
different if <code>CONFIG_DEBUG_FEATURES=y</code>.
</p>
<p>
The included <code>tools/Config.mk</code> file contains additional definitions that may
be overridden in the architecture-specific Make.defs file as necessary:
</p>
<ul>
<li><code>COMPILE</code>, <code>ASSEMBLE</code>, <code>ARCHIVE</code>, <code>CLEAN</code>, and <code>MKDEP</code> macros</li>
</ul>
</li>
<li>
<p>
<code>defconfig</code>: This is a configuration file similar to the Linux
configuration file. In contains variable/value pairs like:
</p>
<ul>
<li><code>CONFIG_VARIABLE</code>=value</li>
</ul>
<p>
This configuration file will be used at build time:
</p>
<ol>
<li>As a makefile fragment included in other makefiles, and</li>
<li>to generate <code>include/nuttx/config.h</code> which is included by
most C files in the system.</li>
</ol>
</li>
</ul>
<h3><a name="supportedboards">2.5.3 Supported Boards</a></h3>
<p>
All of the specific boards supported by NuttX are identified in the <a href="https://bitbucket.org/nuttx/nuttx/configs/src/master/README.txt" target="_blank">README.txt</a> file.
</p>
<h3><a name="newboardconfig">2.5.4 Adding a New Board Configuration</a></h3>
<p>
Okay, so you have created a new board configuration directory.
Now, how do you hook this board into the configuration system so that you can select with <code>make menuconfig</code>?
</p>
<p>
You will need modify the file <code>configs/Kconfig</code>.
Let's look at the STM32F4-Discovery configuration in the <code>Kconfig</code> file and see how we would add a new board directory to the configuration.
For this configuration let's say that you new board resides in the directory <code>configs/myboard</code>;
It uses an MCU selected with <code>CONFIG_ARCH_CHIP_MYMCU</code>; and you want the board to be selected with <code>CONFIG_ARCH_BOARD_MYBOARD</code>.
Then here is how you can clone the STM32F4-Discovery configuration in <code>configs/Kconfig</code> to support your new board configuration.
</p>
<p>
In <code>configs/Kconfig</code> for the stm32f4-discovery, you will see a configuration definition like this:
<p>
<ul><pre>
config ARCH_BOARD_STM32F4_DISCOVERY
bool "STMicro STM32F4-Discovery board"
depends on ARCH_CHIP_STM32F407VG
select ARCH_HAVE_LEDS
select ARCH_HAVE_BUTTONS
select ARCH_HAVE_IRQBUTTONS
---help---
STMicro STM32F4-Discovery board based on the STMicro STM32F407VGT6 MCU.
</pre></ul>
<p>
The above selects the STM32F4-Discovery board.
The <code>select</code> lines say that the board has both LEDs and buttons and that the board can generate interrupts from the button presses.
You can just copy the above configuration definition to a new location (notice that they the configurations are in alphabetical order).
Then you should edit the configuration to support your board.
The final configuration definition might look something like:
</p>
<ul><pre>
config ARCH_BOARD_MYBOARD
bool "My very own board configuration"
depends on ARCH_CHIP_MYMCU
select ARCH_HAVE_LEDS
select ARCH_HAVE_BUTTONS
select ARCH_HAVE_IRQBUTTONS
---help---
This options selects the board configuration for my very own board
based on the MYMCU processor.
</pre></ul>
<p>
Later in the <code>configs/Kconfig</code> file, you will see a long, long string configuration with lots of defaults like this:
</p>
<ul><pre>
config ARCH_BOARD
string
default "amber" if ARCH_BOARD_AMBER
default "avr32dev1" if ARCH_BOARD_AVR32DEV1
default "c5471evm" if ARCH_BOARD_C5471EVM
...
default "stm32f4discovery" if ARCH_BOARD_STM32F4_DISCOVERY
...
</pre></ul>
<p>
This logic will assign string value to a configuration variable called <code>CONFIG_ARCH_BOARD</code> that will name the directory where the board-specific files reside.
In our case, these files reside in <code>configs/myboard</code> and we add the following to the long list of defaults (again in alphabetical order):
</p>
<ul><pre>
default "myboard" if ARCH_BOARD_MYBOARD
</pre></ul>
<p>
Now the build system knows where to find your board configuration!
</p>
<p>
And finally, add something like this near the bottom of <code>configs/myboard</code>:
</p>
<ul><pre>
if ARCH_BOARD_MYBOARD
source "configs/myboard/Kconfig"
endif
</pre></ul>
<p>
This includes additional, board-specific configuration variable definitions in <code>configs/myboard/Kconfig</code>.
</p>
<h2>2.6 <a name="DirStructCrypto">nuttx/crypto</a></h2>
<p>
This sub-directory holds the NuttX cryptographic sub-system.
</p>
<h2>2.7 <a name="DirStructDrivers">nuttx/drivers</a></h2>
<p>
This directory holds architecture-independent device drivers.
</p>
<ul><pre>
drivers/
|-- Kconfig
|-- Makefile
|-- analog/
| |-- Kconfig
| |-- Make.defs
| `-- <i>(Common ADC and DAC driver source files)</i>
|-- audio/
| |-- Kconfig
| |-- Make.defs
| `-- <i>(Common audio device source files)</i>
|-- bch/
| |-- Kconfig
| |-- Make.defs
| `-- <i>(bch driver source files)</i>
|-- contactless/
| |-- Kconfig
| |-- Make.defs
| `-- <i>(Common contactless device driver source files)</i>
|-- input/
| |-- Kconfig
| |-- Make.defs
| `-- <i>(Common touchscreen and keypad driver source files)</i>
|-- ioexpander/
| |-- Kconfig
| |-- Make.defs
| `-- <i>(Common I/O expander and GPIO-related driver source files)</i>
|-- lcd/
| |-- Kconfig
| |-- Make.defs
| `-- <i>(Common LCD driver source files)</i>
|-- leds/
| |-- Kconfig
| |-- Make.defs
| `-- <i>(Common LED device driver source files)</i>
|-- loop/
| |-- Kconfig
| |-- Make.defs
| `-- <i>(Common loop device driver source files)</i>
|-- mmcsd/
| |-- Kconfig
| |-- Make.defs
| `-- <i>(Common MMC/SD card driver source files)</i>
|-- modem/
| |-- Kconfig
| |-- Make.defs
| `-- <i>(Common modem driver source files)</i>
|-- mtd/
| |-- Kconfig
| |-- Make.defs