software implementing neural network trained with sine, tri, square wave inputs.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
cpm219
Date:
Tue Oct 04 23:31:44 2016 +0000
Commit message:
update to implement C++ instead of C.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
neural_net_cpp_v1.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 04 23:31:44 2016 +0000
@@ -0,0 +1,126 @@
+//
+// File: ert_main.cpp
+//
+// Code generated for Simulink model 'neural_network3'.
+//
+// Model version                  : 1.7
+// Simulink Coder version         : 8.10 (R2016a) 10-Feb-2016
+// C/C++ source code generated on : Tue Oct 04 18:06:54 2016
+//
+// Target selection: ert.tlc
+// Embedded hardware selection: ARM Compatible->ARM Cortex
+// Code generation objectives: Unspecified
+// Validation result: Not run
+//
+#include <stddef.h>
+#include <stdio.h>                     // This ert_main.c example uses printf/fflush 
+#include "neural_network3.h"           // Model's header file
+#include "rtwtypes.h"
+#include "mbed.h"
+
+//
+// Associating rt_OneStep with a real-time clock or interrupt service routine
+// is what makes the generated code "real-time".  The function rt_OneStep is
+// always associated with the base rate of the model.  Subrates are managed
+// by the base rate from inside the generated code.  Enabling/disabling
+// interrupts and floating point context switches are target specific.  This
+// example code indicates where these should take place relative to executing
+// the generated code step function.  Overrun behavior should be tailored to
+// your application needs.  This example simply sets an error status in the
+// real-time model and returns from rt_OneStep.
+//
+void rt_OneStep(void);
+void rt_OneStep(void)
+{
+  static boolean_T OverrunFlag = false;
+
+  // '<Root>/In1'
+  static real_T arg_In1[200] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
+
+  // '<Root>/Out1'
+  static real_T arg_Out1[2];
+
+  // Disable interrupts here
+
+  // Check for overrun
+  if (OverrunFlag) {
+    rtmSetErrorStatus(neural_network3_M, "Overrun");
+    return;
+  }
+
+  OverrunFlag = true;
+
+  // Save FPU context here (if necessary)
+  // Re-enable timer or interrupt here
+  // Set model inputs here
+
+  // Step the model
+  neural_network3_custom(arg_In1, arg_Out1);
+
+  // Get model outputs here
+    printf("output: %f", arg_Out1);
+  // Indicate task complete
+  OverrunFlag = false;
+
+  // Disable interrupts here
+  // Restore FPU context here (if necessary)
+  // Enable interrupts here
+}
+
+//
+// The example "main" function illustrates what is required by your
+// application code to initialize, execute, and terminate the generated code.
+// Attaching rt_OneStep to a real-time clock is target specific.  This example
+// illustrates how you do this relative to initializing the model.
+//
+int_T main(int_T argc, const char *argv[])
+{
+  // Unused arguments
+  (void)(argc);
+  (void)(argv);
+
+  // Initialize model
+  neural_network3_initialize();
+
+  // Attach rt_OneStep to a timer or interrupt service routine with
+  //  period 0.2 seconds (the model's base sample time) here.  The
+  //  call syntax for rt_OneStep is
+  //
+    for(;;)
+    {
+        rt_OneStep();
+        wait(0.2);
+    }
+//  printf("Warning: The simulation will run forever. "
+//         "Generated ERT main won't simulate model step behavior. "
+//         "To change this behavior select the 'MAT-file logging' option.\n");
+  fflush((NULL));
+  while (rtmGetErrorStatus(neural_network3_M) == (NULL)) {
+    //  Perform other application tasks here
+  }
+
+  // Disable rt_OneStep() here
+
+  // Terminate model
+  neural_network3_terminate();
+  return 0;
+}
+
+//
+// File trailer for generated code.
+//
+// [EOF]
+//
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Oct 04 23:31:44 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/neural_net_cpp_v1.lib	Tue Oct 04 23:31:44 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/cpm219/code/neural_net_cpp_test_v1/#7363365590dd