Dependents:   WeatherStation

Committer:
okini3939
Date:
Fri Oct 07 14:53:44 2011 +0000
Revision:
3:ed09123d603f
Parent:
2:64bc38078592

        

Who changed what in which revision?

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