// we should only send data to the controller and the
// refinement corresponding to current state.
for (int m = 0; m < 2; m++) {
IOPort sinkPort = sinkPorts[m];
CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper(sinkPort
.getContainer());
code.append(CodeGeneratorHelper
.generateName(sinkPort));
if (sinkPort.isMultiport()) {
code.append("[" + i + "]");
}
int sinkPortBufferSize = helper
.getBufferSize(sinkPort);
if (sinkPortBufferSize > 1) {
String temp = "";
Object offsetObject = helper.getWriteOffset(
sinkPort, i);
if (offsetObject instanceof Integer) {
int offset = ((Integer) offsetObject)
.intValue()
+ k;
offset %= helper.getBufferSize(sinkPort, i);
temp = Integer.toString(offset);
} else {
int modulo = helper.getBufferSize(sinkPort,
i) - 1;
temp = "("
+ (String) helper.getWriteOffset(
sinkPort, i) + " + " + k
+ ")&" + modulo;
}
code.append("[" + temp + "]");
}
code.append(" = ");
}
code.append(containerHelper
.getReference(name + "," + k));
code.append(";" + _eol);
}
// Only update the port write offsets of the
// controller and the current refinement. The
// offset of the input port itself is updated by
// outside director.
for (int m = 0; m < 2; m++) {
IOPort sinkPort = sinkPorts[m];
CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper(sinkPort
.getContainer());
Object offsetObject = helper
.getWriteOffset(sinkPort, i);
if (offsetObject instanceof Integer) {
int offset = ((Integer) offsetObject).intValue();
offset = (offset + rate)
% helper.getBufferSize(sinkPort, i);
helper.setWriteOffset(sinkPort, i, Integer
.valueOf(offset));
} else {
int modulo = helper.getBufferSize(sinkPort, i) - 1;
String offsetVariable = (String) helper
.getWriteOffset(sinkPort, i);
code.append(offsetVariable + " = ("
+ offsetVariable + " + " + rate + ")&"
+ modulo + ";" + _eol);
}