Curtis Mattull
/
NN_FG_final
software implementing neural network trained with sine, tri, square wave inputs.
main.cpp@0:34aeffc5e6f0, 2016-10-04 (annotated)
- Committer:
- cpm219
- Date:
- Tue Oct 04 23:31:44 2016 +0000
- Revision:
- 0:34aeffc5e6f0
update to implement C++ instead of C.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cpm219 | 0:34aeffc5e6f0 | 1 | // |
cpm219 | 0:34aeffc5e6f0 | 2 | // File: ert_main.cpp |
cpm219 | 0:34aeffc5e6f0 | 3 | // |
cpm219 | 0:34aeffc5e6f0 | 4 | // Code generated for Simulink model 'neural_network3'. |
cpm219 | 0:34aeffc5e6f0 | 5 | // |
cpm219 | 0:34aeffc5e6f0 | 6 | // Model version : 1.7 |
cpm219 | 0:34aeffc5e6f0 | 7 | // Simulink Coder version : 8.10 (R2016a) 10-Feb-2016 |
cpm219 | 0:34aeffc5e6f0 | 8 | // C/C++ source code generated on : Tue Oct 04 18:06:54 2016 |
cpm219 | 0:34aeffc5e6f0 | 9 | // |
cpm219 | 0:34aeffc5e6f0 | 10 | // Target selection: ert.tlc |
cpm219 | 0:34aeffc5e6f0 | 11 | // Embedded hardware selection: ARM Compatible->ARM Cortex |
cpm219 | 0:34aeffc5e6f0 | 12 | // Code generation objectives: Unspecified |
cpm219 | 0:34aeffc5e6f0 | 13 | // Validation result: Not run |
cpm219 | 0:34aeffc5e6f0 | 14 | // |
cpm219 | 0:34aeffc5e6f0 | 15 | #include <stddef.h> |
cpm219 | 0:34aeffc5e6f0 | 16 | #include <stdio.h> // This ert_main.c example uses printf/fflush |
cpm219 | 0:34aeffc5e6f0 | 17 | #include "neural_network3.h" // Model's header file |
cpm219 | 0:34aeffc5e6f0 | 18 | #include "rtwtypes.h" |
cpm219 | 0:34aeffc5e6f0 | 19 | #include "mbed.h" |
cpm219 | 0:34aeffc5e6f0 | 20 | |
cpm219 | 0:34aeffc5e6f0 | 21 | // |
cpm219 | 0:34aeffc5e6f0 | 22 | // Associating rt_OneStep with a real-time clock or interrupt service routine |
cpm219 | 0:34aeffc5e6f0 | 23 | // is what makes the generated code "real-time". The function rt_OneStep is |
cpm219 | 0:34aeffc5e6f0 | 24 | // always associated with the base rate of the model. Subrates are managed |
cpm219 | 0:34aeffc5e6f0 | 25 | // by the base rate from inside the generated code. Enabling/disabling |
cpm219 | 0:34aeffc5e6f0 | 26 | // interrupts and floating point context switches are target specific. This |
cpm219 | 0:34aeffc5e6f0 | 27 | // example code indicates where these should take place relative to executing |
cpm219 | 0:34aeffc5e6f0 | 28 | // the generated code step function. Overrun behavior should be tailored to |
cpm219 | 0:34aeffc5e6f0 | 29 | // your application needs. This example simply sets an error status in the |
cpm219 | 0:34aeffc5e6f0 | 30 | // real-time model and returns from rt_OneStep. |
cpm219 | 0:34aeffc5e6f0 | 31 | // |
cpm219 | 0:34aeffc5e6f0 | 32 | void rt_OneStep(void); |
cpm219 | 0:34aeffc5e6f0 | 33 | void rt_OneStep(void) |
cpm219 | 0:34aeffc5e6f0 | 34 | { |
cpm219 | 0:34aeffc5e6f0 | 35 | static boolean_T OverrunFlag = false; |
cpm219 | 0:34aeffc5e6f0 | 36 | |
cpm219 | 0:34aeffc5e6f0 | 37 | // '<Root>/In1' |
cpm219 | 0:34aeffc5e6f0 | 38 | static real_T arg_In1[200] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
cpm219 | 0:34aeffc5e6f0 | 39 | 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
cpm219 | 0:34aeffc5e6f0 | 40 | 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
cpm219 | 0:34aeffc5e6f0 | 41 | 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0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 | 52 | |
cpm219 | 0:34aeffc5e6f0 | 53 | // '<Root>/Out1' |
cpm219 | 0:34aeffc5e6f0 | 54 | static real_T arg_Out1[2]; |
cpm219 | 0:34aeffc5e6f0 | 55 | |
cpm219 | 0:34aeffc5e6f0 | 56 | // Disable interrupts here |
cpm219 | 0:34aeffc5e6f0 | 57 | |
cpm219 | 0:34aeffc5e6f0 | 58 | // Check for overrun |
cpm219 | 0:34aeffc5e6f0 | 59 | if (OverrunFlag) { |
cpm219 | 0:34aeffc5e6f0 | 60 | rtmSetErrorStatus(neural_network3_M, "Overrun"); |
cpm219 | 0:34aeffc5e6f0 | 61 | return; |
cpm219 | 0:34aeffc5e6f0 | 62 | } |
cpm219 | 0:34aeffc5e6f0 | 63 | |
cpm219 | 0:34aeffc5e6f0 | 64 | OverrunFlag = true; |
cpm219 | 0:34aeffc5e6f0 | 65 | |
cpm219 | 0:34aeffc5e6f0 | 66 | // Save FPU context here (if necessary) |
cpm219 | 0:34aeffc5e6f0 | 67 | // Re-enable timer or interrupt here |
cpm219 | 0:34aeffc5e6f0 | 68 | // Set model inputs here |
cpm219 | 0:34aeffc5e6f0 | 69 | |
cpm219 | 0:34aeffc5e6f0 | 70 | // Step the model |
cpm219 | 0:34aeffc5e6f0 | 71 | neural_network3_custom(arg_In1, arg_Out1); |
cpm219 | 0:34aeffc5e6f0 | 72 | |
cpm219 | 0:34aeffc5e6f0 | 73 | // Get model outputs here |
cpm219 | 0:34aeffc5e6f0 | 74 | printf("output: %f", arg_Out1); |
cpm219 | 0:34aeffc5e6f0 | 75 | // Indicate task complete |
cpm219 | 0:34aeffc5e6f0 | 76 | OverrunFlag = false; |
cpm219 | 0:34aeffc5e6f0 | 77 | |
cpm219 | 0:34aeffc5e6f0 | 78 | // Disable interrupts here |
cpm219 | 0:34aeffc5e6f0 | 79 | // Restore FPU context here (if necessary) |
cpm219 | 0:34aeffc5e6f0 | 80 | // Enable interrupts here |
cpm219 | 0:34aeffc5e6f0 | 81 | } |
cpm219 | 0:34aeffc5e6f0 | 82 | |
cpm219 | 0:34aeffc5e6f0 | 83 | // |
cpm219 | 0:34aeffc5e6f0 | 84 | // The example "main" function illustrates what is required by your |
cpm219 | 0:34aeffc5e6f0 | 85 | // application code to initialize, execute, and terminate the generated code. |
cpm219 | 0:34aeffc5e6f0 | 86 | // Attaching rt_OneStep to a real-time clock is target specific. This example |
cpm219 | 0:34aeffc5e6f0 | 87 | // illustrates how you do this relative to initializing the model. |
cpm219 | 0:34aeffc5e6f0 | 88 | // |
cpm219 | 0:34aeffc5e6f0 | 89 | int_T main(int_T argc, const char *argv[]) |
cpm219 | 0:34aeffc5e6f0 | 90 | { |
cpm219 | 0:34aeffc5e6f0 | 91 | // Unused arguments |
cpm219 | 0:34aeffc5e6f0 | 92 | (void)(argc); |
cpm219 | 0:34aeffc5e6f0 | 93 | (void)(argv); |
cpm219 | 0:34aeffc5e6f0 | 94 | |
cpm219 | 0:34aeffc5e6f0 | 95 | // Initialize model |
cpm219 | 0:34aeffc5e6f0 | 96 | neural_network3_initialize(); |
cpm219 | 0:34aeffc5e6f0 | 97 | |
cpm219 | 0:34aeffc5e6f0 | 98 | // Attach rt_OneStep to a timer or interrupt service routine with |
cpm219 | 0:34aeffc5e6f0 | 99 | // period 0.2 seconds (the model's base sample time) here. The |
cpm219 | 0:34aeffc5e6f0 | 100 | // call syntax for rt_OneStep is |
cpm219 | 0:34aeffc5e6f0 | 101 | // |
cpm219 | 0:34aeffc5e6f0 | 102 | for(;;) |
cpm219 | 0:34aeffc5e6f0 | 103 | { |
cpm219 | 0:34aeffc5e6f0 | 104 | rt_OneStep(); |
cpm219 | 0:34aeffc5e6f0 | 105 | wait(0.2); |
cpm219 | 0:34aeffc5e6f0 | 106 | } |
cpm219 | 0:34aeffc5e6f0 | 107 | // printf("Warning: The simulation will run forever. " |
cpm219 | 0:34aeffc5e6f0 | 108 | // "Generated ERT main won't simulate model step behavior. " |
cpm219 | 0:34aeffc5e6f0 | 109 | // "To change this behavior select the 'MAT-file logging' option.\n"); |
cpm219 | 0:34aeffc5e6f0 | 110 | fflush((NULL)); |
cpm219 | 0:34aeffc5e6f0 | 111 | while (rtmGetErrorStatus(neural_network3_M) == (NULL)) { |
cpm219 | 0:34aeffc5e6f0 | 112 | // Perform other application tasks here |
cpm219 | 0:34aeffc5e6f0 | 113 | } |
cpm219 | 0:34aeffc5e6f0 | 114 | |
cpm219 | 0:34aeffc5e6f0 | 115 | // Disable rt_OneStep() here |
cpm219 | 0:34aeffc5e6f0 | 116 | |
cpm219 | 0:34aeffc5e6f0 | 117 | // Terminate model |
cpm219 | 0:34aeffc5e6f0 | 118 | neural_network3_terminate(); |
cpm219 | 0:34aeffc5e6f0 | 119 | return 0; |
cpm219 | 0:34aeffc5e6f0 | 120 | } |
cpm219 | 0:34aeffc5e6f0 | 121 | |
cpm219 | 0:34aeffc5e6f0 | 122 | // |
cpm219 | 0:34aeffc5e6f0 | 123 | // File trailer for generated code. |
cpm219 | 0:34aeffc5e6f0 | 124 | // |
cpm219 | 0:34aeffc5e6f0 | 125 | // [EOF] |
cpm219 | 0:34aeffc5e6f0 | 126 | // |