beremiz

Make online debug optional

2019-01-06, Andrey Skvortsov
eba2bbb2dd9a
Make online debug optional

It could be useful for very small targets like Atmega (Arduino) and
for target bring-up there developer want to have running PLC program,
but has not implemented runtime communication yet.


TARGET_DEBUG_AND_RETAIN_DISABLE - completely disable debug and retain
functionality. Previously named TARGET_DEBUG_DISABLE.

TARGET_ONLINE_DEBUG_DISABLE - can be used to enable retain
functionality (no define TARGET_DEBUG_AND_RETAIN_DISABLE is used), but disable
online debug with corresponding RAM/FLASH overhead.

TARGET_LOGGING_DISABLE - disables logging functionality from runtime and PLC program

TARGET_EXT_SYNC_DISABLE - disables PLC program synchronization with
external events. For example, it could be used to synchronize several
PLCs that control motors for different axes.

By default all these options are off.

To test generate program for Generic target, put following files in
project files directory and run build.sh after generating PLC program.
This is very easy to integrate into makefile (Generic target).

[------------- build.sh --------------------------]
files=$(find $PWD/../build -iname '*.c' | grep -v POUS.c)
arm-none-eabi-gcc \
-DTARGET_DEBUG_AND_RETAIN_DISABLE \
-DTARGET_ONLINE_DEBUG_DISABLE \
-DTARGET_LOGGING_DISABLE \
-DTARGET_EXT_SYNC_DISABLE \
-flto -ffunction-sections -fdata-sections -I../../../../matiec/lib/C \
$files \
main.c \
-Wl,--Map=./program.map,--cref \
-nodefaultlibs --specs=nano.specs -Wl,--static -Wl,--gc-section -Wl,--start-group -lc -lm -lnosys -lgcc -Wl,--end-group
[------------------------------------------------]

[------------- main.c --------------------------]
#ifndef TARGET_DEBUG_AND_RETAIN_DISABLE
void Retain(void){}
void InValidateRetainBuffer(void){}
void ValidateRetainBuffer(void){}
#endif

extern void __run(void);
int main(void)
{
for(;;) {
__run();
// sleep common_ticktime__ ns
// add common_ticktime__ ns to __CURRENT_TIME
}
return 0;
}
[------------------------------------------------]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<PyFile>
<variables>
<variable name="WiiNunchuckStickX" type="INT"/>
<variable name="WiiNunchuckStickY" type="INT"/>
<variable name="WiiNunchuckAccX" type="INT"/>
<variable name="WiiNunchuckAccY" type="INT"/>
<variable name="WiiNunchuckAccZ" type="INT"/>
<variable name="WiiNunchuckButtons" type="WORD"/>
<variable name="WiiButtons" type="WORD"/>
</variables>
<globals>
<![CDATA[
import cwiid,commands,sys,re,os,time
wiimote = None
WIIMOTE_ADDR_MODEL = re.compile("((?:[0-9A-F]{2})(?::[0-9A-F]{2}){5})\s*Nintendo")
nunchuckzero = None
def Wiimote_cback(messages, time):
global nunchuckzero
state = dict(messages)
bts = state.get(cwiid.MESG_BTN, None)
if bts is not None:
PLCGlobals.WiiButtons = bts
nunchuck = state.get(cwiid.MESG_NUNCHUK, None)
if nunchuck is not None:
PLCGlobals.WiiNunchuckButtons = nunchuck['buttons']
X,Y = nunchuck['stick']
PLCGlobals.WiiNunchuckAccX = nunchuck['acc'][cwiid.X]
PLCGlobals.WiiNunchuckAccY = nunchuck['acc'][cwiid.Y]
PLCGlobals.WiiNunchuckAccZ = nunchuck['acc'][cwiid.Z]
if nunchuckzero is None:
nunchuckzero = X,Y
(PLCGlobals.WiiNunchuckStickX,
PLCGlobals.WiiNunchuckStickY) = X-nunchuckzero[0],Y-nunchuckzero[1]
def Connect_Wiimote(connected_callback):
global wiimote,nunchuckzero
mac_addr = ''
try:
mac_addr = file("wiimac.txt","rt").read()
except:
PLCObject.LogMessage("Wiimote MAC unknown, scanning bluetooth")
output = commands.getoutput("hcitool scan")
result = WIIMOTE_ADDR_MODEL.search(output)
if result is not None:
mac_addr = result.group(1)
PLCObject.LogMessage("Found Wiimote with MAC %s"%mac_addr)
file("wiimac.txt","wt").write(mac_addr)
# Connect to wiimote
if not mac_addr:
PLCObject.LogMessage("Connection to unknown Wiimote...")
wiimote = cwiid.Wiimote()
else:
PLCObject.LogMessage("Connection to Wiimote %s..."%mac_addr)
wiimote = cwiid.Wiimote(mac_addr)
if wiimote is not None:
nunchuckzero = None
wiimote.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_EXT
# use the callback interface
wiimote.mesg_callback = Wiimote_cback
wiimote.enable(cwiid.FLAG_MESG_IFC)
connected_callback(mac_addr)
PLCObject.LogMessage("Wiimote %s Connected"%mac_addr)
else:
PLCObject.LogMessage("Wiimote %s not found"%mac_addr)
os.remove("wiimac.txt")
connected_callback(None)
def Disconnect_Wiimote():
global wiimote
if wiimote is not None:
wiimote.disable(cwiid.FLAG_MESG_IFC)
time.sleep(0.1)
wiimote.close()
wiimote = None
PLCObject.LogMessage("Wiimote disconnected")
]]>
</globals>
<init>
<![CDATA[
]]>
</init>
<cleanup>
<![CDATA[
Disconnect_Wiimote()
]]>
</cleanup>
<start>
<![CDATA[
]]>
</start>
<stop>
<![CDATA[
]]>
</stop>
</PyFile>