x3828643 wrote:
I want to created a main.c file with MatIEC's ANSI-C file to generate a binary application.
Is there any examples can refer to it?
This is actually pretty easy.
On Beremiz mailing list there was discussion about porting Beremz to AVR and examples posted
there may be useful to get idea how matiec work and how it can be used in in a standalone application
Here is direct link to the post with simplest runtime for AVR 8-bit microcontroller.
I wanted to attach C and Makefile for similar simple runtime for GNU/Linux system, but this forum doesn't allow these types for some reason.
extern void __run(void);
extern int __init(int argc,char **argv);
extern void __cleanup(void);
#include <time.h>
#include <math.h>
#include <stdint.h>
#include <unistd.h>
#include "iec_types.h"
#include "iec_std_lib.h"
extern TIME __CURRENT_TIME;
extern unsigned long __tick;
TIME __PLC_PRG_TIME;
void PLC_GetTime(IEC_TIME *CURRENT_TIME)
{
struct timespec tmp;
clock_gettime(CLOCK_REALTIME, &tmp);
CURRENT_TIME->tv_sec = tmp.tv_sec;
CURRENT_TIME->tv_nsec = tmp.tv_nsec;
}
int main(int argc,char **argv)
{
__init(argc,argv);
for(;;) {
PLC_GetTime(&__CURRENT_TIME);
__run();
TIME now;
PLC_GetTime(&now);
__PLC_PRG_TIME = __time_sub(now, __CURRENT_TIME);
STRING s = __time_to_string(__PLC_PRG_TIME);
printf("%s\n", s.body);
sleep(1);
#ifdef PROFILE_PROGRAM_TICKS
if (__tick > PROFILE_PROGRAM_TICKS)
break;
#endif
}
__cleanup();
return 0;
}
PLC cycle is this example fixed and is not taken from the project in PLCOpenEditor, but this is enough to get the idea.
Beremiz does have proper handling for PLC cycle on GNU/Linux targets of course.
So you may be interested in looking into that.
Most of the code is needed for Debug and Logging, so you don't need it.
# Hey Emacs, this is a -*- makefile -*-
BEREMIZ_OBJS = $(BEREMIZSRC:.c=.o)
CC=gcc
CFLAGS+= -O2
CFLAGS+= -flto
CFLAGS+=-DTARGET_DEBUG_DISABLE
CFLAGS+=-DTARGET_LOGGING_DISABLE
CFLAGS+=-DTARGET_EXT_SYNC_DISABLE
CFLAGS+=-DTARGET_RETAIN_DISABLE
CFLAGS+=-DPROFILE_PROGRAM_TICKS=5
CFLAGS+=-I../project_files
CFLAGS+=-I../../../matiec/lib/C
CFLAGS+= -g
LDFLAGS=
debug:
$(CC) $(CFLAGS) -E resource1.c > resource1.C
all:
@echo "*** all done ***"
$(CC) $(CFLAGS) $(BEREMIZSRC) ../project_files/main.c -o PLC_PRG $(LDFLAGS)
Anyway because your questions are not related to OpenPLC it's may be better to ask on Beremiz mailing list.