Dependents:   WeatherStation

Committer:
okini3939
Date:
Sun Jun 26 12:02:32 2011 +0000
Revision:
0:684b6fdf080c
Child:
1:f8c5afc27878

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okini3939 0:684b6fdf080c 1 /** @file
okini3939 0:684b6fdf080c 2 * @brief Instruction List interpreter
okini3939 0:684b6fdf080c 3 */
okini3939 0:684b6fdf080c 4
okini3939 0:684b6fdf080c 5 #ifndef ILinterpreter_H
okini3939 0:684b6fdf080c 6 #define ILinterpreter_H
okini3939 0:684b6fdf080c 7
okini3939 0:684b6fdf080c 8 #include "mbed.h"
okini3939 0:684b6fdf080c 9 #include "Stack.h"
okini3939 0:684b6fdf080c 10
okini3939 0:684b6fdf080c 11 #define IL_NUM 100
okini3939 0:684b6fdf080c 12 #define IL_RELAY_NUM 10
okini3939 0:684b6fdf080c 13 #define IL_TIMER_NUM 10
okini3939 0:684b6fdf080c 14 #define IL_COUNTER_NUM 10
okini3939 0:684b6fdf080c 15 #define IL_STACK 40
okini3939 0:684b6fdf080c 16
okini3939 0:684b6fdf080c 17 enum eMNEMONIC {
okini3939 0:684b6fdf080c 18 MNE_NULL,
okini3939 0:684b6fdf080c 19 MNE_DEF,
okini3939 0:684b6fdf080c 20 MNE_LD, MNE_LDI, MNE_LDP, MNE_LDF,
okini3939 0:684b6fdf080c 21 MNE_ALD, MNE_ALDI, MNE_ALDP, MNE_ALDF,
okini3939 0:684b6fdf080c 22 MNE_OR, MNE_ORI, MNE_ORP, MNE_ORF,
okini3939 0:684b6fdf080c 23 MNE_AND, MNE_ANI, MNE_ANDP, MNE_ANDF,
okini3939 0:684b6fdf080c 24 MNE_ORB, MNE_ANB,
okini3939 0:684b6fdf080c 25 MNE_INV,
okini3939 0:684b6fdf080c 26 MNE_MPS, MNE_MRD, MNE_MPP,
okini3939 0:684b6fdf080c 27 MNE_OUT, MNE_SET, MNE_RST,
okini3939 0:684b6fdf080c 28 MNE_END,
okini3939 0:684b6fdf080c 29 };
okini3939 0:684b6fdf080c 30
okini3939 0:684b6fdf080c 31 enum eEXPRESSION {
okini3939 0:684b6fdf080c 32 EXP_NULL,
okini3939 0:684b6fdf080c 33 EXP_EQ, EXP_NE,
okini3939 0:684b6fdf080c 34 EXP_LE, EXP_LT,
okini3939 0:684b6fdf080c 35 EXP_GE, EXP_GT,
okini3939 0:684b6fdf080c 36 EXP_MOD, EXP_NMOD,
okini3939 0:684b6fdf080c 37 };
okini3939 0:684b6fdf080c 38
okini3939 0:684b6fdf080c 39 struct tIL {
okini3939 0:684b6fdf080c 40 enum eMNEMONIC mnemonic;
okini3939 0:684b6fdf080c 41 char key;
okini3939 0:684b6fdf080c 42 int keynum;
okini3939 0:684b6fdf080c 43 enum eEXPRESSION expression;
okini3939 0:684b6fdf080c 44 float value;
okini3939 0:684b6fdf080c 45 };
okini3939 0:684b6fdf080c 46
okini3939 0:684b6fdf080c 47 struct tInOut {
okini3939 0:684b6fdf080c 48 time_t sec;
okini3939 0:684b6fdf080c 49 int relay[IL_RELAY_NUM];
okini3939 0:684b6fdf080c 50 int timer_flg[IL_TIMER_NUM];
okini3939 0:684b6fdf080c 51 unsigned int timer_set[IL_TIMER_NUM], timer_cnt[IL_TIMER_NUM];
okini3939 0:684b6fdf080c 52 unsigned int count_set[IL_COUNTER_NUM], count_cnt[IL_COUNTER_NUM], count_rev[IL_COUNTER_NUM];
okini3939 0:684b6fdf080c 53 };
okini3939 0:684b6fdf080c 54
okini3939 0:684b6fdf080c 55
okini3939 0:684b6fdf080c 56 /** ILinterpreter class
okini3939 0:684b6fdf080c 57 */
okini3939 0:684b6fdf080c 58 class ILinterpreter {
okini3939 0:684b6fdf080c 59 public:
okini3939 0:684b6fdf080c 60 ILinterpreter ();
okini3939 0:684b6fdf080c 61
okini3939 0:684b6fdf080c 62 /** exec IL sequence
okini3939 0:684b6fdf080c 63 * @retval 0 success
okini3939 0:684b6fdf080c 64 * @retval -1 error
okini3939 0:684b6fdf080c 65 */
okini3939 0:684b6fdf080c 66 int exec ();
okini3939 0:684b6fdf080c 67
okini3939 0:684b6fdf080c 68 /** set call back function
okini3939 0:684b6fdf080c 69 * @param pf_i input function (input relay)
okini3939 0:684b6fdf080c 70 * @param pf_o output function (output relay)
okini3939 0:684b6fdf080c 71 * @return pointer of tInOut (internal relay)
okini3939 0:684b6fdf080c 72 */
okini3939 0:684b6fdf080c 73 void attach (struct tInOut **io, float (*pf_i)(char, int, eEXPRESSION, int), void (*pf_o)(char, int, int, eMNEMONIC));
okini3939 0:684b6fdf080c 74
okini3939 0:684b6fdf080c 75 /** timer interval (call 10Hz)
okini3939 0:684b6fdf080c 76 */
okini3939 0:684b6fdf080c 77 void pool ();
okini3939 0:684b6fdf080c 78
okini3939 0:684b6fdf080c 79 /** load IL file
okini3939 0:684b6fdf080c 80 * @param file file name
okini3939 0:684b6fdf080c 81 * @retval 0 success
okini3939 0:684b6fdf080c 82 * @retval -1 error
okini3939 0:684b6fdf080c 83 */
okini3939 0:684b6fdf080c 84 int load (char *file);
okini3939 0:684b6fdf080c 85
okini3939 0:684b6fdf080c 86 protected:
okini3939 0:684b6fdf080c 87 int il_count;
okini3939 0:684b6fdf080c 88 struct tIL il[IL_NUM];
okini3939 0:684b6fdf080c 89 struct tInOut inout, inout_old;
okini3939 0:684b6fdf080c 90 Stack<int> stack;
okini3939 0:684b6fdf080c 91
okini3939 0:684b6fdf080c 92 int input (tInOut *io, int i, int old = 0);
okini3939 0:684b6fdf080c 93 void output (int i, int reg, eMNEMONIC mne);
okini3939 0:684b6fdf080c 94 void load_exp (int i, char *buf);
okini3939 0:684b6fdf080c 95
okini3939 0:684b6fdf080c 96 float (*cb_input)(char key, int keynum, eEXPRESSION exp, int old);
okini3939 0:684b6fdf080c 97 void (*cb_output)(char key, int keynum, int reg, eMNEMONIC mne);
okini3939 0:684b6fdf080c 98
okini3939 0:684b6fdf080c 99 private:
okini3939 0:684b6fdf080c 100
okini3939 0:684b6fdf080c 101 };
okini3939 0:684b6fdf080c 102
okini3939 0:684b6fdf080c 103 #endif