I have built-in C for a TI processor that needs to be tested in a block.
IAR is used for target compilation, but I run tests on a Win7 machine using MinGW GCC.
C code has functions that contain state machines, which sometimes need to be reset between tests. These state machines often keep their state variable locally static, which complicates the task, if not impossible.
I am not very versed in the C ++ class, but I had the idea of ββ"importing" C functions into the C ++ class for packaging, because it allows you to simply create a new object whenever you need to reset. The code below does not work, but it illustrates my idea.
in main.cpp:
#include "statemachine.h"
using namespace std;
class stateMachineWrapper {
public:
extern void stateMachine(void);
};
int main() {
stateMachineWrapper myObject;
myObject.stateMachine();
myObject.stateMachine();
stateMachineWrapper myNewObject;
myNewObject.stateMachine();
myNewObject.stateMachine();
return 0;
}
in statemachine.h:
void stateMachine(void);
in statemachine.c:
#include <stdio.h>
void stateMachine(void)
{
static int myState = 0;
switch(myState)
{
case 0:
{
printf("Init State");
myState = 1;
break;
}
case 1:
{
printf("Second state");
break;
}
default:
{
printf("Default");
break;
}
}
}
statemachine.c/.h , "".
, , !