Diff: ILinterpreter.h
- Revision:
- 0:684b6fdf080c
- Child:
- 1:f8c5afc27878
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ILinterpreter.h Sun Jun 26 12:02:32 2011 +0000
@@ -0,0 +1,103 @@
+/** @file
+ * @brief Instruction List interpreter
+ */
+
+#ifndef ILinterpreter_H
+#define ILinterpreter_H
+
+#include "mbed.h"
+#include "Stack.h"
+
+#define IL_NUM 100
+#define IL_RELAY_NUM 10
+#define IL_TIMER_NUM 10
+#define IL_COUNTER_NUM 10
+#define IL_STACK 40
+
+enum eMNEMONIC {
+ MNE_NULL,
+ MNE_DEF,
+ MNE_LD, MNE_LDI, MNE_LDP, MNE_LDF,
+ MNE_ALD, MNE_ALDI, MNE_ALDP, MNE_ALDF,
+ MNE_OR, MNE_ORI, MNE_ORP, MNE_ORF,
+ MNE_AND, MNE_ANI, MNE_ANDP, MNE_ANDF,
+ MNE_ORB, MNE_ANB,
+ MNE_INV,
+ MNE_MPS, MNE_MRD, MNE_MPP,
+ MNE_OUT, MNE_SET, MNE_RST,
+ MNE_END,
+};
+
+enum eEXPRESSION {
+ EXP_NULL,
+ EXP_EQ, EXP_NE,
+ EXP_LE, EXP_LT,
+ EXP_GE, EXP_GT,
+ EXP_MOD, EXP_NMOD,
+};
+
+struct tIL {
+ enum eMNEMONIC mnemonic;
+ char key;
+ int keynum;
+ enum eEXPRESSION expression;
+ float value;
+};
+
+struct tInOut {
+ time_t sec;
+ int relay[IL_RELAY_NUM];
+ int timer_flg[IL_TIMER_NUM];
+ unsigned int timer_set[IL_TIMER_NUM], timer_cnt[IL_TIMER_NUM];
+ unsigned int count_set[IL_COUNTER_NUM], count_cnt[IL_COUNTER_NUM], count_rev[IL_COUNTER_NUM];
+};
+
+
+/** ILinterpreter class
+ */
+class ILinterpreter {
+public:
+ ILinterpreter ();
+
+ /** exec IL sequence
+ * @retval 0 success
+ * @retval -1 error
+ */
+ int exec ();
+
+ /** set call back function
+ * @param pf_i input function (input relay)
+ * @param pf_o output function (output relay)
+ * @return pointer of tInOut (internal relay)
+ */
+ void attach (struct tInOut **io, float (*pf_i)(char, int, eEXPRESSION, int), void (*pf_o)(char, int, int, eMNEMONIC));
+
+ /** timer interval (call 10Hz)
+ */
+ void pool ();
+
+ /** load IL file
+ * @param file file name
+ * @retval 0 success
+ * @retval -1 error
+ */
+ int load (char *file);
+
+protected:
+ int il_count;
+ struct tIL il[IL_NUM];
+ struct tInOut inout, inout_old;
+ Stack<int> stack;
+
+ int input (tInOut *io, int i, int old = 0);
+ void output (int i, int reg, eMNEMONIC mne);
+ void load_exp (int i, char *buf);
+
+ float (*cb_input)(char key, int keynum, eEXPRESSION exp, int old);
+ void (*cb_output)(char key, int keynum, int reg, eMNEMONIC mne);
+
+private:
+
+};
+
+#endif