/** die wichtigsten (zeitkritischen) Cmds, die in jedem State gelten */ static boolean handleMsg(int val) { int data; if (val == BBSys.CMD_STATUS) { Msg.write(state); return true; } if (val == BBSys.CMD_STOP) { state = BBSys.MS_RDY; Triac.stop(); Msg.write(0); return true; } if (val == BBSys.CMD_UP) { if (state == BBSys.MS_RDY) { state = BBSys.MS_UP; Triac.rauf(); Msg.write(0); } else { Msg.err(1); } return true; } if (val == BBSys.CMD_DOWN) { if (state == BBSys.MS_RDY) { state = BBSys.MS_DOWN; Triac.runter(); Msg.write(0); } else { Msg.err(1); } return true; } if (val == BBSys.CMD_PAUSE) { if (state == BBSys.MS_UP || state == BBSys.MS_DOWN) { Triac.pause(); Msg.write(0); } else { Msg.err(1); } return true; } if (val == BBSys.CMD_INP) { Msg.write((JopSys.rd(BBSys.IO_SENSOR) << 4) + JopSys.rd(BBSys.IO_TAST)); return true; } if (val == BBSys.CMD_OPTO) { Msg.write(Triac.getOpto()); return true; } if (val == BBSys.CMD_CNT) { Msg.write(Triac.getCnt()); return true; } return false; }
/* disp_d(7 downto 4) <= disp(3 downto 0); disp_rs <= disp(4); disp_e <= disp(5); disp_nwr <= '1'; */ private static void nibble(int val) { JopSys.wr(val, IO_DISP); wait1us(); JopSys.wr(0x20 | val, IO_DISP); // set e to 1 wait1us(); JopSys.wr(val, IO_DISP); // set e back to 0 wait1us(); }
public static void init() { nibble(0x20); // function mode 4-bit, only one nibble!!! data(0x00); // brightness (0..100%, 3..25%) cmd(0x02); // cursor home cmd(0x06); // entry mode cmd(0x0c); // display on cmd(0x14); // shift cursor cmd(0x080); // set dd ram address cmd(0x01); // display clear for (int j = 0; j < 3; ++j) { // wait 3 ms int i = JopSys.rd(JopSys.IO_CNT) + JopSys.MS; while (i - JopSys.rd(JopSys.IO_CNT) >= 0) ; } buf = new int[COLS]; }
/** main loop. */ public static void loop() { int cmd; Msg.loop(); // for exact msg timing first entry Triac.loop(); // should be also exact, but 1ms jitter is ok // TODO measure jitter with osci if (Msg.available) { cmd = Msg.readCmd(); if (!handleMsg(cmd)) { handleRest(cmd); if (state == BBSys.MS_SERVICE) { doService(); // never return! } } lastMsgCnt = 0; } else { chkMsgTimeout(); } if (blinkCnt == 100) { KflTimer.wd(); blinkCnt = 0; } ++blinkCnt; int used = KflTimer.usedTime(); if (maxTime < used) maxTime = used; JopSys.benchLoop(); }
private static void doTemp() { int data = (46000 - JopSys.rd(BBSys.IO_ADC)) - 17000 + 4; // 4 for rounding if (data < 0) data = 0; data >>>= 3; // only 12 Bit Msg.write(data); }
public static void main(String[] args) { state = BBSys.MS_RESET; lastErr = 0; maxTime = 0; lastMsgCnt = 0; JopSys.initBench(); // added for benchmarking KflTimer.init(); // wd Triac.init(); int addr = 1; // Flash.getStationAddress(); Msg.init(addr); init(addr); JopSys.wr(0x02, BBSys.IO_LED); // Betrieb KflTimer.start(); /* forever(); */ }
// // Service loop: // local control of triacs. // never return => switch power off to resume from service // private static void doService() { // we need this to avoid a simple goto in the CFG boolean exit = false; JopSys.wr(0x01, BBSys.IO_LED); for (; exit; ) { // @WCA loop=1 Msg.loop(); // only for replay to set state Triac.loop(); int val = JopSys.rd(BBSys.IO_TAST); if (val == BBSys.BIT_TAB) { Triac.runter(); } else if (val == BBSys.BIT_TAUF) { Triac.rauf(); } else { Triac.stop(); } KflTimer.wd(); KflTimer.waitForNextInterval(); } }
private static void wait1us() { int i = JopSys.rd(JopSys.IO_CNT) + JopSys.USEC; while (i - JopSys.rd(JopSys.IO_CNT) >= 0) ; }