Dependents:   WeatherStation

Committer:
okini3939
Date:
Sun Jun 26 16:53:49 2011 +0000
Revision:
1:f8c5afc27878
Parent:
0:684b6fdf080c
Child:
2:64bc38078592

        

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