/README.md

https://github.com/maniacbug/ncore · Markdown · 212 lines · 157 code · 55 blank · 0 comment · 0 complexity · 751a04218366871e4fcbe8b98749b415 MD5 · raw file

  1. # NCORE: Native Core for Arduino
  2. ## What is a 'Native Core'?
  3. The native core allows you to compile and run Arduino sketches on the PC, generally with no modification. It provides native versions of standard Arduino functions, and a command-line interepreter to give inputs to your sketch that would normally come from the hardware itself.
  4. ## Why is that useful?
  5. You can...
  6. * Run full-fledged Arduino sketches without any hardware. Perhaps you're away from your desk and didn't bring the hardware. Maybe you're on a plane? Or maybe the hardware isn't done yet.
  7. * Get a trace of exactly what your sketch is doing to the hardware and when it happened, to help debug your logic.
  8. * Use the debugger on Mac & Linux where there is no WinAVR.
  9. * Run automated tests using normal frameworks, such as cxxtest.
  10. * Run a script which pretends to be the hardware and see how your sketch reacts.
  11. * Make sure your sketch behaves properly under hardware error conditions which are impossible to trigger normally. (e.g. bad SD media)
  12. ## What do I need to use it?
  13. NCORE runs on Linux and Mac. I use it on Ubuntu 11.04 and Mac OSX 10.6 (Snow Leopard).
  14. NCORE runs from the command-line. It requires an understanding of build scripts and running build tools from the command-line.
  15. Beyond that, the requirements are pretty simple. It just needs gcc and the 'ftjam' build tool.
  16. If you want to build the tests, you'll need cxxtest from http://cxxtest.tigris.org. NCORE has been tested with cxxtest 3.10.1.
  17. ## How do I get it?
  18. Clone it from github. Create a 'hardware' directory off your sketches directory, and clone into 'native' under that. For example...
  19. $ cd ~/Source/Arduino
  20. $ mkdir hardware
  21. $ cd hardware
  22. $ git clone git://github.com/maniacbug/ncore.git native
  23. ## How do I build the examples?
  24. NCORE has been tested against all examples shipped with Arduino 1.0, plus many libraries which are handled by NCORE such as EEPROM and SPI.
  25. All are working without modification, except to forward-declare functions and fix bugs. Some bugs became much more obvious once they were running under NCORE.
  26. The examples are in their own repository. To get them:
  27. $ cd ~/Source/Arduino
  28. $ git clone git://github.com/maniacbug/ncore-examples.git
  29. $ cd ncore-examples
  30. Edit Jamrules, and change the first line, CORE\_DIR to point to where you installed the native core, and ARDUINO\_DIR to where you installed Arduino.
  31. First, build one of the examples. The following will build the 'Blink' example:
  32. $ jam Blink
  33. Then build all of the examples in one go:
  34. $ jam -j10
  35. Just be sure to have built ONE example first, or it takes forever to compile.
  36. Also, the -j10 is optional. It goes faster that way.
  37. ## How do I launch it?
  38. From the examples directory, after building Blink, type:
  39. $ out/Blink
  40. ## How do I run it?
  41. After a few seconds, type 'list' to see a log of activity.
  42. Type 'help' for a complete list of commands.
  43. Type 'quit' when you're done.
  44. ## Do I have to modify my sketches?
  45. Generally not. To compile for the command line, you do need to forward declare any functions because the Arduino IDE magically does that for you, and there's no IDE to do it here.
  46. There is a compiler define 'NATIVE' which you can use to add native-only chunks of code to your sketch. Try to avoid that, but sometimes there's no way around it.
  47. ## How do I build my own sketches?
  48. When setting up a sketch for NCORE, it's important to maintain interoperability with the Arduino IDE. Here's an example of how I set it up.
  49. My "Sketch Directory" in the Arduino IDE is ~/Source/Arduino. Let's say we're setting up the "HelloWorld" sketch.
  50. 1. Create the HelloWorld sketch in the IDE the normal way.
  51. 2. This creates ~/Source/Arduino/HelloWorld/HelloWorld.pde.
  52. 3. Create a 'native' directory underneath, e.g. ~/Source/Arduino/HelloWorld/native
  53. 4. Copy Jamrules and Jamfile from ~/Source/Arduino/hardware/native/samples into ~/Source/Arduino/HelloWorld/native
  54. 5. From a command prompt, cd to ~/Source/Arduino/HelloWorld/native, and type 'jam'
  55. 6. Run out/HelloWorld
  56. In your sketch, use the ".INO" extension for anything that should be included in both Arduino hardware builds and native builds. Use ".CPP" for files
  57. that should only be in the Arduino hardware build. The native build will not pick those up. In the 'native' directory off your sketch, include any files
  58. that should be only in the native build. The Arduino hardware build will not pick those up. This allows you to substitute native versions of any of your
  59. functions if you need it. This avoids lots of "#if NATIVE" everywhere in your sketch.
  60. ## Examples of output
  61. ### Blink
  62. NCORE: Arduino Native Core
  63. Copyright (C) 2011 maniacbug@ymail.com GPLv2
  64. ncore 6$ at 5000 list
  65. ncore 8$ at 5001 quit
  66. NCORE: 000006 IN CORE Started
  67. NCORE: 000008 SK AT 5000 list
  68. NCORE: 000009 SK AT 5001 quit
  69. NCORE: 000057 SK PINS 13 OUTPUT
  70. NCORE: 000057 SK PINS 13 HIGH
  71. NCORE: 000057 SK CLOK delay 1000
  72. NCORE: 001057 SK PINS 13 LOW
  73. NCORE: 001057 SK CLOK delay 1000
  74. NCORE: 002057 SK PINS 13 HIGH
  75. NCORE: 002057 SK CLOK delay 1000
  76. NCORE: 003057 SK PINS 13 LOW
  77. NCORE: 003057 SK CLOK delay 1000
  78. NCORE: 004057 SK PINS 13 HIGH
  79. NCORE: 004057 SK CLOK delay 1000
  80. ### Button
  81. NCORE: Arduino Native Core
  82. Copyright (C) 2011 maniacbug@ymail.com GPLv2
  83. ncore 1$ log rate 50
  84. ncore 4$ at 100 pin 2 press
  85. ncore 6$ at 200 list
  86. ncore 7$ at 201 quit
  87. NCORE: 000001 IN CORE Started
  88. NCORE: 000004 IN LOG set rate limit to 50ms
  89. NCORE: 000006 SK AT 100 pin 2 press
  90. NCORE: 000007 SK AT 200 list
  91. NCORE: 000007 SK AT 201 quit
  92. NCORE: 000051 SK PINS 13 OUTPUT
  93. NCORE: 000051 SK PINS 2 INPUT
  94. NCORE: 000051 SK PINS 13 LOW
  95. NCORE: 000051 SK PINS 13 LOW
  96. NCORE: 000052 SK PINS 13 LOW
  97. NCORE: 000052 SK PINS 13 LOW
  98. NCORE: 000052 SK PINS 13 LOW
  99. NCORE: 000052 SK PINS 13 LOW
  100. NCORE: 000052 SK PINS 13 LOW
  101. NCORE: 000052 SK PINS 13 LOW
  102. NCORE: 000052 SK PINS 13 LOW
  103. NCORE: 000052 SK PINS 13 LOW
  104. NCORE: 000052 SK PINS 13 LOW
  105. NCORE: 000052 SK PINS 13 LOW
  106. NCORE: 000052 SK PINS 13 LOW
  107. NCORE: 000052 SK PINS 13 LOW
  108. NCORE: 000052 SK PINS 13 LOW
  109. NCORE: 000052 IN LOG delay 50 (rate limit)
  110. NCORE: 000100 IN PINS 2 HIGH
  111. NCORE: 000102 SK PINS 13 HIGH
  112. NCORE: 000102 SK PINS 13 HIGH
  113. NCORE: 000102 SK PINS 13 HIGH
  114. NCORE: 000102 SK PINS 13 HIGH
  115. NCORE: 000102 SK PINS 13 HIGH
  116. NCORE: 000102 SK PINS 13 HIGH
  117. NCORE: 000102 SK PINS 13 HIGH
  118. NCORE: 000102 SK PINS 13 HIGH
  119. NCORE: 000102 SK PINS 13 HIGH
  120. NCORE: 000102 SK PINS 13 HIGH
  121. NCORE: 000102 IN LOG delay 50 (rate limit)
  122. NCORE: 000150 IN PINS 2 LOW
  123. NCORE: 000152 SK PINS 13 LOW
  124. NCORE: 000152 SK PINS 13 LOW
  125. NCORE: 000152 SK PINS 13 LOW
  126. NCORE: 000152 SK PINS 13 LOW
  127. NCORE: 000152 SK PINS 13 LOW
  128. NCORE: 000152 SK PINS 13 LOW
  129. NCORE: 000152 SK PINS 13 LOW
  130. NCORE: 000152 SK PINS 13 LOW
  131. NCORE: 000152 SK PINS 13 LOW
  132. NCORE: 000152 SK PINS 13 LOW
  133. NCORE: 000152 IN LOG delay 50 (rate limit)
  134. ### StringToIntRGB
  135. NCORE: Arduino Native Core
  136. Copyright (C) 2011 maniacbug@ymail.com GPLv2
  137. ncore 1$ log rate 0
  138. ncore 3$ at 100 send 0,64,128 cr
  139. ncore 3$ at 110 list
  140. ncore 4$ at 111 quit
  141. ncore 4$
  142. NCORE: 000001 IN CORE Started
  143. NCORE: 000003 IN LOG set rate limit to 0ms
  144. NCORE: 000003 SK AT 100 send 0,64,128 cr
  145. NCORE: 000004 SK AT 110 list
  146. NCORE: 000004 SK AT 111 quit
  147. NCORE: 000051 SK CORE Serial started.
  148. NCORE: 000051 SK PINS 9 OUTPUT
  149. NCORE: 000051 SK PINS 10 OUTPUT
  150. NCORE: 000051 SK PINS 11 OUTPUT
  151. NCORE: 000051 SK PINS 13 OUTPUT
  152. NCORE: 000051 SK PINS 13 HIGH
  153. NCORE: 000100 IN SERL send 0,64,128 (with CR)
  154. NCORE: 000100 SK PINS 11: 255
  155. NCORE: 000100 SK PINS 9: 191
  156. NCORE: 000100 SK PINS 10: 127
  157. NCORE: 000100 SK SERL Red: 0, Green: 64, Blue: 128