OSDN Git Service

git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@90 47198e57-cb75-475f-84c4-a814cd6...
authornyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Sun, 6 Nov 2011 16:06:02 +0000 (16:06 +0000)
committernyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Sun, 6 Nov 2011 16:06:02 +0000 (16:06 +0000)
misc/MiMicVM/api.js/LPCXPresso1769.All.js
misc/MiMicVM/api.js/LPCXPresso1769.Gpio.js
misc/MiMicVM/api.js/LPCXpresso1769.Adc.js
misc/MiMicVM/api.js/LPCXpresso1769.Mcu.js
misc/MiMicVM/api.js/LPCXpresso1769.Peripheral.js
misc/MiMicVM/api.js/LPCXpresso1769.js
misc/MiMicVM/api.js/MiMicCore.js
misc/MiMicVM/api.js/test.html

index 63507a3..cbe70d1 100644 (file)
@@ -103,14 +103,14 @@ var LPCXpresso1769;
                /**\r
                 * @see API manual\r
                 */\r
-               PHY_NAME:[\r
+               PHL_NAME:[\r
                        "GPIO","ADC","DAC"\r
                ],\r
                /**\r
                 * @see API manual\r
-                PHY:{PHY_NAME:[PCLKSELreg#PCLKSELbit,PCONPbit]}\r
+                PHL:{PHL_NAME:[PCLKSELreg#PCLKSELbit,PCONPbit]}\r
                 */\r
-               PHY:{\r
+               PHL:{\r
                        WDT:    [0,0,null],\r
                        TIMER0: [0,2,1],\r
                        TIMER1: [0,4,2],\r
@@ -387,7 +387,7 @@ LPCXpresso1769=DEV;
        /**\r
         * PIN機能名から使用するペリフェラルシンボルを推定する。
         */\r
-       function pinFuncName2PhyName(i_pinfuncname)\r
+       function pinFuncName2PhlName(i_pinfuncname)\r
        {\r
                try{\r
                        //Pin function nameプレフィクスとペリフェラル名の対比表\r
@@ -454,7 +454,7 @@ LPCXpresso1769=DEV;
                 * ペリフェラルオブジェクトのホルダ。ペリフェラル名をキーにした、ペリフェラルオブジェクトの連想配列。\r
                 MCUが、自身のペリフェラルオブジェクトを管理する為に使う。\r
                 */\r
-               _phy_holder:[],\r
+               _phl_holder:[],\r
                /**\r
                 * @see API manual
                 */\r
@@ -551,13 +551,13 @@ LPCXpresso1769=DEV;
                                //pin_functionを持ってるPINを探す。\r
                                var pin=getPinByFuncName(arguments[0]);\r
                                //function名からペリフェラル名を得る。\r
-                               var phy_name=pinFuncName2PhyName(arguments[0]);\r
+                               var phl_name=pinFuncName2PhlName(arguments[0]);\r
                                //ピンコンストラクタとペリフェラルを使ってピンを生成。\r
-                               return this.getPeripheral(phy_name).getPin(pin);\r
+                               return this.getPeripheral(phl_name).getPin(pin);\r
                        case 2://getPin:function getPin(i_pin,i_function_name)\r
                                //function名からペリフェラル名を得る。(PINシンボル変換を流用)\r
-                               var phy_name=pinFuncName2PhyName(arguments[1]);\r
-                               return this.getPeripheral(phy_name).getPin(arguments[0]);\r
+                               var phl_name=pinFuncName2PhlName(arguments[1]);\r
+                               return this.getPeripheral(phl_name).getPin(arguments[0]);\r
                        default:\r
                                throw new MiMicException();\r
                        }\r
@@ -572,33 +572,33 @@ LPCXpresso1769=DEV;
                /**\r
                 * @see API manual
                 */\r
-               getPeripheral:function getPeripheral(i_phy_symbol)\r
+               getPeripheral:function getPeripheral(i_phl_symbol)\r
                {\r
                        //ペリフェラルアイテムが生成済か確認\r
-                       if(isUndef(this._phy_holder[i_phy_symbol])){\r
+                       if(isUndef(this._phl_holder[i_phl_symbol])){\r
                                //存在しなければPhyを生成。\r
-                               var phy;\r
-                               switch(i_phy_symbol){\r
+                               var phl;\r
+                               switch(i_phl_symbol){\r
                                case "GPIO":new DEV.Gpio(this);break;\r
                                case "ADC":new DEV.Adc(this);break;\r
                                default:\r
-                                       throw new MiMicException("Unknown peripheral symbol "+i_phy_symbol);\r
+                                       throw new MiMicException("Unknown peripheral symbol "+i_phl_symbol);\r
                                }\r
                        }\r
-                       //phyからregisterのコールバックがかかるはず。\r
-                       return this._phy_holder[i_phy_symbol];\r
+                       //phlからregisterのコールバックがかかるはず。\r
+                       return this._phl_holder[i_phl_symbol];\r
                },\r
                /**\r
                 * [forSystem]システム関数。MCU依存のペリフェラルオブジェクトを登録する。
                 */\r
-               registerPhy:function registerPhy(i_phy,i_symbol)\r
+               registerPhl:function registerPhy(i_phl,i_symbol)\r
                {\r
                        try{\r
                                //登録済みのシンボルは登録できない。\r
-                               if(!isUndef(this._phy_holder[i_symbol])){\r
+                               if(!isUndef(this._phl_holder[i_symbol])){\r
                                        throw new MiMicException("Peripheral symbol "+i_symbol+" is already exist on mcu.");\r
                                }\r
-                               this._phy_holder[i_symbol]=i_phy;\r
+                               this._phl_holder[i_symbol]=i_phl;\r
                        }catch(e){\r
                                throw new MiMicException(e);\r
                        }\r
@@ -684,14 +684,14 @@ var isUndef=MiMicLib.isUndef;
 /**\r
  * @see API manual\r
  */\r
-DEV.Peripheral=function(i_mcu,i_phy,i_opt)\r
+DEV.Peripheral=function(i_mcu,i_phl,i_opt)\r
 {\r
        try{\r
-               if(isUndef(i_phy)){\r
-                       throw new MiMicException(EE.INVALID_PHY);\r
+               if(isUndef(i_phl)){\r
+                       throw new MiMicException(EE.INVALID_PHL);\r
                }\r
                this._mcu=i_mcu;\r
-               this._phy=i_phy;\r
+               this._phl=i_phl;\r
                //オプション設定するならする。\r
                if(!isUndef(i_opt)){\r
                        this.setOpt(i_opt);\r
@@ -704,7 +704,7 @@ DEV.Peripheral.prototype=
 {\r
        _PCLKSEL:[0x400FC1A8,0x400FC1AC],\r
        _PCONP:0x400FC0C4,\r
-       _phy:null,\r
+       _phl:null,\r
        _mif:null,\r
        BCF_setOpt:function BCF_setOpt(i_opt,i_db)\r
        {\r
@@ -712,18 +712,18 @@ DEV.Peripheral.prototype=
                        var bc="";\r
                        //pconp\r
                        if(!isUndef(i_opt.power)){\r
-                               if(this._phy[2]==null){\r
+                               if(this._phl[2]==null){\r
                                        throw new MiMicException(EE.INVALID_CFG,"The pin does not support PCONP.");\r
                                }\r
                                //pinselAddrを得る\r
-                               bc+=BCF.setBit(this._PCONP,0x00000001,i_opt.power,this._phy[2],i_db);\r
+                               bc+=BCF.setBit(this._PCONP,0x00000001,i_opt.power,this._phl[2],i_db);\r
                        }\r
                        //clock\r
                        if(!isUndef(i_opt.clock)){\r
-                               if(this._phy[0]==null){\r
+                               if(this._phl[0]==null){\r
                                        throw new MiMicException(EE.INVALID_CFG,"The pin does not support PCLKSEL.");\r
                                }\r
-                               bc+=BCF.setBit(this._PCLKSEL[this._phy[0]],0x00000003,i_opt.clock,this._phy[1],i_db);\r
+                               bc+=BCF.setBit(this._PCLKSEL[this._phl[0]],0x00000003,i_opt.clock,this._phl[1],i_db);\r
                        }\r
                        return bc;\r
                }catch(e){\r
@@ -860,24 +860,24 @@ var isUndef=MiMicLib.isUndef;
 /**\r
  * このクラスは、ADCペリフェラルを管理します。\r
  @param i_opt\r
- オプション値です。省略時は、{phy:{power:1}}を指定します。\r
- {phy:{ペリフェラルオプション}}\r
+ オプション値です。省略時は、{phl:{power:1}}を指定します。\r
+ {phl:{ペリフェラルオプション}}\r
  */\r
 DEV.Adc=function Adc(i_mcu,i_opt)\r
 {\r
        try{\r
                this._mcu=i_mcu;\r
-               var phyopt=isUndef(i_opt)?{power:1}:i_opt.phy;\r
-               //PHY生成。\r
-               this._phy=new DEV.Peripheral(i_mcu,DEV.PHY.ADC);\r
+               var phlopt=isUndef(i_opt)?{power:1}:i_opt.phl;\r
+               //PHL生成。\r
+               this._phl=new DEV.Peripheral(i_mcu,DEV.PHL.ADC);\r
                //初期化。\r
                var bc="";\r
                var db=new Array();\r
                if(isUndef(i_opt)){\r
                        //パワーONのみ\r
-                       bc+=this._phy.BCF_setOpt({power:1},db);\r
+                       bc+=this._phl.BCF_setOpt({power:1},db);\r
                }else{\r
-                       bc+=this._phy.BCF_setOpt(i_opt.phy,db);\r
+                       bc+=this._phl.BCF_setOpt(i_opt.phl,db);\r
                }\r
                //0x00210000(PDN,BURSTを1)\r
                bc+=BCF.setMem(this._AD0CR,0x00200500,db);\r
@@ -885,7 +885,7 @@ DEV.Adc=function Adc(i_mcu,i_opt)
                //\r
                this._mcu.callMiMicWithCheck(bc+BCF.END,db);\r
                //ペリフェラルをMCUに登録\r
-               this._mcu.registerPhy(this,"ADC");\r
+               this._mcu.registerPhl(this,"ADC");\r
        }catch(e){\r
                throw new MiMicException(e);\r
        }\r
@@ -895,7 +895,7 @@ DEV.Adc.prototype=
 {\r
        _AD0CR:0x40034000,\r
        _AD0DR:[0x40034010,0x40034014,0x40034018,0x4003401C,0x40034020,0x40034024,0x40034028,0x4003402C],\r
-       _phy:null,\r
+       _phl:null,\r
        _mcu:null,\r
        /**\r
         * AD0CRのSELフィールドの値を更新するBC\r
index 86a37a9..0f8f9e1 100644 (file)
@@ -3,6 +3,7 @@ var DEV=LPCXpresso1769;
 var BCF=DEV._BCF;\r
 var EE=DEV._EE;\r
 var isUndef=MiMicLib.isUndef;\r
+var cloneAssoc=MiMicLib.cloneAssoc;\r
 \r
 /**\r
  * このクラスは、GPIOペリフェラルを管理します。
@@ -11,7 +12,7 @@ DEV.Gpio=function Gpio(i_mcu)
 {\r
        try{\r
                this._mcu=i_mcu;\r
-               i_mcu.registerPhy(this,"GPIO");\r
+               i_mcu.registerPhl(this,"GPIO");\r
        }catch(e){\r
                throw new MiMicException(e);\r
        }\r
@@ -109,13 +110,16 @@ DEV.GpioPin=function GpioPin(i_gpio,i_pin,i_opt)
                        }\r
                        throw new MiMicException(EE.INVALID_CFG,"The pin has not GPIO fuction.");\r
                }(i_pin);\r
-               if(isUndef(i_opt)){\r
-                       //optionが無いときは、GPIO化だけ。\r
-                       this.setOpt({sel:this._gpioinfo.pin_sel});\r
-               }else{\r
-                       //optionがあるときはGPIO化と、pinコンフィギュレーションの継承\r
-                       this.setOpt(i_opt);\r
+               //optの構成\r
+               var opt=isUndef(i_opt)?{pin:{}}:\r
+               {\r
+                       dir:i_opt.dir,\r
+                       pin:isUndef(i_opt.pin)?{}:cloneAssoc(i_opt.pin)\r
                }\r
+               //デフォルト値\r
+               if(isUndef(opt.pin.sel)){opt.pin.sel=this._gpioinfo.pin_sel;}\r
+               //Pinのコンフィギュレーション\r
+               this.setOpt(opt);\r
        }catch(e){\r
                throw new MiMicException(e);\r
        }\r
@@ -124,7 +128,7 @@ DEV.GpioPin.prototype=
 {\r
        _gpio:null,\r
        _pin:null,//LPCXpressoのpin\r
-       _gpioinfo:null,//GPIOの情報{port,bit}\r
+       _gpioinfo:null,//GPIOの情報{port,bit,pin_sel}\r
        /**\r
         * @see API manual
         */\r
@@ -138,17 +142,9 @@ DEV.GpioPin.prototype=
                                bc+=this._gpio.BCF_setDir(this._gpioinfo.port,this._gpioinfo.bit,i_opt.dir,db);\r
                        }\r
                        //pinselの値\r
-                       if(isUndef(i_opt.pin)){\r
-                               //pinコンフィギュレーションが無いとき\r
-                               bc+=this._pin.BCF_setOpt({sel:this._gpioinfo.pin_sel},db);\r
-                       }else{\r
-                               //pinコンフィギュレーションがあるとき\r
-                               var t=i_opt.pin.sel;//待避\r
-                               i_opt.pin.sel=this._gpioinfo.pin_sel;//selの上書き\r
+                       if(!isUndef(i_opt.pin)){\r
                                bc+=this._pin.BCF_setOpt(i_opt.pin,db);\r
-                               i_opt.pin.sel=t;\r
                        }\r
-                       //実行なう\r
                        //MiMicBCを生成して実行\r
                        this._gpio._mcu.callMiMicWithCheck(bc+BCF.END,db);\r
                }catch(e){\r
index b4f1258..a097a03 100644 (file)
@@ -14,34 +14,31 @@ var isUndef=MiMicLib.isUndef;
 \r
 \r
 /**\r
- * このクラスは、ADCペリフェラルを管理します。\r
- @param i_opt\r
- オプション値です。省略時は、{phy:{power:1}}を指定します。\r
- {phy:{ペリフェラルオプション}}\r
+ * see API manual.\r
  */\r
 DEV.Adc=function Adc(i_mcu,i_opt)\r
 {\r
        try{\r
                this._mcu=i_mcu;\r
-               var phyopt=isUndef(i_opt)?{power:1}:i_opt.phy;\r
-               //PHY生成。\r
-               this._phy=new DEV.Peripheral(i_mcu,DEV.PHY.ADC);\r
+               //phl値の決定\r
+               var phlopt=this._PHL_DEF;\r
+               //optにphlが指定されていたら、それを採用。\r
+               if(!isUndef(i_opt) && !isUndef(i_opt.phl)){\r
+                       phlopt=i_opt.phl;\r
+               }\r
+               //PHL生成。\r
+               this._phl=new DEV.Peripheral(i_mcu,DEV.PHL.ADC);\r
                //初期化。\r
                var bc="";\r
                var db=new Array();\r
-               if(isUndef(i_opt)){\r
-                       //パワーONのみ\r
-                       bc+=this._phy.BCF_setOpt({power:1},db);\r
-               }else{\r
-                       bc+=this._phy.BCF_setOpt(i_opt.phy,db);\r
-               }\r
+               bc+=this._phl.BCF_setOpt(phlopt,db);\r
                //0x00210000(PDN,BURSTを1)\r
-               bc+=BCF.setMem(this._AD0CR,0x00200500,db);\r
-               bc+=BCF.setMem(this._AD0CR,0x00210500,db);\r
+               bc+=BCF.setMem(this._AD0CR,0x00200400,db);\r
+               bc+=BCF.setMem(this._AD0CR,0x00210400,db);\r
                //\r
                this._mcu.callMiMicWithCheck(bc+BCF.END,db);\r
                //ペリフェラルをMCUに登録\r
-               this._mcu.registerPhy(this,"ADC");\r
+               this._mcu.registerPhl(this,"ADC");\r
        }catch(e){\r
                throw new MiMicException(e);\r
        }\r
@@ -49,9 +46,10 @@ DEV.Adc=function Adc(i_mcu,i_opt)
 }\r
 DEV.Adc.prototype=\r
 {\r
+       _PHL_DEF:{power:1},\r
        _AD0CR:0x40034000,\r
        _AD0DR:[0x40034010,0x40034014,0x40034018,0x4003401C,0x40034020,0x40034024,0x40034028,0x4003402C],\r
-       _phy:null,\r
+       _phl:null,\r
        _mcu:null,\r
        /**\r
         * AD0CRのSELフィールドの値を更新するBC\r
@@ -89,13 +87,7 @@ DEV.Adc.prototype=
 }\r
 \r
 /**\r
- * このクラスは、ADCペリフェラルとPin識別子から、ADCピンを構成します。\r
- @param i_adc\r
- ADCペリフェラル\r
- @param i_pin\r
- ADCを構成するピン番号\r
- @param i_opt\r
- ピンオプション。省略してください。\r
+ * see API manual.\r
  */\r
 DEV.AdcPin=function AdcPin(i_adc,i_pin,i_opt)\r
 {\r
@@ -115,15 +107,16 @@ DEV.AdcPin=function AdcPin(i_adc,i_pin,i_opt)
                        }\r
                        throw new MiMicException(EE.INVALID_CFG,"The pin has not AD fuction.");\r
                }(i_pin);\r
-               //設定用のBCを作って実行\r
+               var opt=isUndef(i_opt)?{pin:{}}:\r
                {\r
-                       var bc="";\r
-                       var db=new Array();\r
-                       bc+=this._pin.BCF_setOpt({sel:this._adinfo.pin_sel},db);\r
-                       //AD0CRに値設定\r
-                       bc+=this._adc.BCF_setSel(this._adinfo.ch,1,db);\r
-                       var ret=this._adc._mcu.callMiMicWithCheck(bc+BCF.END,db);\r
-               }\r
+                       pin:isUndef(i_opt.pin)?{}:cloneAssoc(i_opt.pin)\r
+               };\r
+               //AD0CR-SELの値(強制0)\r
+               opt.sel=1;\r
+               //デフォルト値\r
+               if(isUndef(opt.pin.sel)){opt.pin.sel=this._adinfo.pin_sel;}\r
+               //オプション設定\r
+               this.setOpt(opt);\r
        }catch(e){\r
                throw new MiMicException(e);\r
        }\r
@@ -150,8 +143,28 @@ DEV.AdcPin.prototype=
                }catch(e){\r
                        throw new MiMicException(e);\r
                }\r
-\r
-       }       \r
+       },\r
+       /**\r
+        * {sel:1bit,pin:{pin option}}
+        */\r
+       setOpt:function setOpt(i_opt)\r
+       {\r
+               try{\r
+                       var bc="";\r
+                       var db=new Array();\r
+                       if(!isUndef(i_opt.pin)){\r
+                               bc+=this._pin.BCF_setOpt(i_opt.pin,db);\r
+                       }\r
+                       //enable\r
+                       if(!isUndef(i_opt.sel)){\r
+                               bc+=this._adc.BCF_setSel(this._adinfo.ch,i_opt.sel,db);\r
+                       }\r
+                       this._adc._mcu.callMiMicWithCheck(bc+BCF.END,db);\r
+                       return;\r
+               }catch(e){\r
+                       throw new MiMicException(e);\r
+               }\r
+       }\r
 }\r
        \r
 \r
index 9333adb..680d136 100644 (file)
@@ -24,7 +24,7 @@
                        }\r
                        return p;\r
                }catch(e){\r
-                       throw MiMicException(e);\r
+                       throw new MiMicException(e);\r
                }\r
        }\r
        \r
@@ -61,7 +61,7 @@
        /**\r
         * PIN機能名から使用するペリフェラルシンボルを推定する。
         */\r
-       function pinFuncName2PhyName(i_pinfuncname)\r
+       function pinFuncName2PhlName(i_pinfuncname)\r
        {\r
                try{\r
                        //Pin function nameプレフィクスとペリフェラル名の対比表\r
                 * ペリフェラルオブジェクトのホルダ。ペリフェラル名をキーにした、ペリフェラルオブジェクトの連想配列。\r
                 MCUが、自身のペリフェラルオブジェクトを管理する為に使う。\r
                 */\r
-               _phy_holder:[],\r
+               _phl_holder:[],\r
+               /**\r
+                * Clockに関する情報を返す。
+                */\r
+               getClockInfo:function getClockProperty()\r
+               {\r
+                       //CCLCK値(RemoteMCU側と合わせること。将来的にはactivateの時に決定する。)\r
+                       return {cclk:100*1000*1000};\r
+               },\r
                /**\r
                 * @see API manual
                 */\r
                                }\r
                                return ret;\r
                        }catch(e){\r
-                               throw MiMicException(e);\r
+                               throw new MiMicException(e);\r
                        }\r
                },\r
                /**\r
                                //pin_functionを持ってるPINを探す。\r
                                var pin=getPinByFuncName(arguments[0]);\r
                                //function名からペリフェラル名を得る。\r
-                               var phy_name=pinFuncName2PhyName(arguments[0]);\r
+                               var phl_name=pinFuncName2PhlName(arguments[0]);\r
                                //ピンコンストラクタとペリフェラルを使ってピンを生成。\r
-                               return this.getPeripheral(phy_name).getPin(pin);\r
+                               return this.getPeripheral(phl_name).getPin(pin);\r
                        case 2://getPin:function getPin(i_pin,i_function_name)\r
                                //function名からペリフェラル名を得る。(PINシンボル変換を流用)\r
-                               var phy_name=pinFuncName2PhyName(arguments[1]);\r
-                               return this.getPeripheral(phy_name).getPin(arguments[0]);\r
+                               var phl_name=pinFuncName2PhlName(arguments[1]);\r
+                               return this.getPeripheral(phl_name).getPin(arguments[0]);\r
                        default:\r
                                throw new MiMicException();\r
                        }\r
                /**\r
                 * @see API manual
                 */\r
-               getPeripheral:function getPeripheral(i_phy_symbol)\r
+               getPeripheral:function getPeripheral(i_phl_symbol)\r
                {\r
                        //ペリフェラルアイテムが生成済か確認\r
-                       if(isUndef(this._phy_holder[i_phy_symbol])){\r
-                               //存在しなければPhyを生成。\r
-                               var phy;\r
-                               switch(i_phy_symbol){\r
+                       if(isUndef(this._phl_holder[i_phl_symbol])){\r
+                               //存在しなければPhlを生成。\r
+                               var phl;\r
+                               switch(i_phl_symbol){\r
                                case "GPIO":new DEV.Gpio(this);break;\r
                                case "ADC":new DEV.Adc(this);break;\r
                                default:\r
-                                       throw new MiMicException("Unknown peripheral symbol "+i_phy_symbol);\r
+                                       throw new MiMicException("Unknown peripheral symbol "+i_phl_symbol);\r
                                }\r
                        }\r
-                       //phyからregisterのコールバックがかかるはず。\r
-                       return this._phy_holder[i_phy_symbol];\r
+                       //phlからregisterのコールバックがかかるはず。\r
+                       return this._phl_holder[i_phl_symbol];\r
                },\r
                /**\r
                 * [forSystem]システム関数。MCU依存のペリフェラルオブジェクトを登録する。
                 */\r
-               registerPhy:function registerPhy(i_phy,i_symbol)\r
+               registerPhl:function registerPhl(i_phl,i_symbol)\r
                {\r
                        try{\r
                                //登録済みのシンボルは登録できない。\r
-                               if(!isUndef(this._phy_holder[i_symbol])){\r
+                               if(!isUndef(this._phl_holder[i_symbol])){\r
                                        throw new MiMicException("Peripheral symbol "+i_symbol+" is already exist on mcu.");\r
                                }\r
-                               this._phy_holder[i_symbol]=i_phy;\r
+                               this._phl_holder[i_symbol]=i_phl;\r
                        }catch(e){\r
                                throw new MiMicException(e);\r
                        }\r
index c3985b7..f5f94a2 100644 (file)
@@ -6,14 +6,14 @@ var isUndef=MiMicLib.isUndef;
 /**\r
  * @see API manual\r
  */\r
-DEV.Peripheral=function(i_mcu,i_phy,i_opt)\r
+DEV.Peripheral=function(i_mcu,i_phl,i_opt)\r
 {\r
        try{\r
-               if(isUndef(i_phy)){\r
-                       throw new MiMicException(EE.INVALID_PHY);\r
+               if(isUndef(i_phl)){\r
+                       throw new MiMicException(EE.INVALID_PHL);\r
                }\r
                this._mcu=i_mcu;\r
-               this._phy=i_phy;\r
+               this._phl=i_phl;\r
                //オプション設定するならする。\r
                if(!isUndef(i_opt)){\r
                        this.setOpt(i_opt);\r
@@ -26,26 +26,34 @@ DEV.Peripheral.prototype=
 {\r
        _PCLKSEL:[0x400FC1A8,0x400FC1AC],\r
        _PCONP:0x400FC0C4,\r
-       _phy:null,\r
-       _mif:null,\r
+       _phl:null,\r
+       _mcu:null,\r
+       _cache:{\r
+               pclk:0\r
+       },\r
+       /**\r
+        * BCフラグメントを生成して、_cacheを更新します。
+        */\r
        BCF_setOpt:function BCF_setOpt(i_opt,i_db)\r
        {\r
                try{\r
                        var bc="";\r
                        //pconp\r
                        if(!isUndef(i_opt.power)){\r
-                               if(this._phy[2]==null){\r
+                               if(this._phl[2]==null){\r
                                        throw new MiMicException(EE.INVALID_CFG,"The pin does not support PCONP.");\r
                                }\r
                                //pinselAddrを得る\r
-                               bc+=BCF.setBit(this._PCONP,0x00000001,i_opt.power,this._phy[2],i_db);\r
+                               bc+=BCF.setBit(this._PCONP,0x00000001,i_opt.power,this._phl[2],i_db);\r
                        }\r
                        //clock\r
                        if(!isUndef(i_opt.clock)){\r
-                               if(this._phy[0]==null){\r
+                               if(this._phl[0]==null){\r
                                        throw new MiMicException(EE.INVALID_CFG,"The pin does not support PCLKSEL.");\r
                                }\r
-                               bc+=BCF.setBit(this._PCLKSEL[this._phy[0]],0x00000003,i_opt.clock,this._phy[1],i_db);\r
+                               //キャッシュ更新\r
+                               this._cache.pclk=i_opt.clock;\r
+                               bc+=BCF.setBit(this._PCLKSEL[this._phl[0]],0x00000003,i_opt.clock,this._phl[1],i_db);\r
                        }\r
                        return bc;\r
                }catch(e){\r
@@ -70,6 +78,32 @@ DEV.Peripheral.prototype=
                        throw new MiMicException(e);\r
                }\r
                return;         \r
+       },\r
+       /**\r
+        * ペリフェラルのクロックを返す。\r
+        Table 42. Peripheral Clock Selection register bit valuesの変換テーブルです。\r
+        クロックは、最後のキャッシュ値から計算します。\r
+        */\r
+       getPCLK:function getPCLK()\r
+       {\r
+               try{\r
+                       //倍率変換テーブル\r
+                       var m=[4,1,2,0];\r
+                       var t=m[this._cache.pclk];\r
+                       var r;\r
+                       if(t==0){\r
+                               if(this._phl===DEV.PHL.CAN1 || this._phl===DEV.PHL.CAN2){\r
+                                       r=this._mcu.getClockInfo().cclk/6;\r
+                               }else{\r
+                                       r=this._mcu.getClockInfo().cclk/8;\r
+                               }\r
+                       }else{\r
+                               r=this._mcu.getClockInfo().cclk/t;\r
+                       }\r
+                       return Math.round(r);\r
+               }catch(e){\r
+                       throw new MiMicException(e);\r
+               }\r
        }\r
 }\r
 \r
index 3a2ce94..acdeb6f 100644 (file)
@@ -103,14 +103,14 @@ var LPCXpresso1769;
                /**\r
                 * @see API manual\r
                 */\r
-               PHY_NAME:[\r
+               PHL_NAME:[\r
                        "GPIO","ADC","DAC"\r
                ],\r
                /**\r
                 * @see API manual\r
-                PHY:{PHY_NAME:[PCLKSELreg#PCLKSELbit,PCONPbit]}\r
+                PHL:{PHL_NAME:[PCLKSELreg#PCLKSELbit,PCONPbit]}\r
                 */\r
-               PHY:{\r
+               PHL:{\r
                        WDT:    [0,0,null],\r
                        TIMER0: [0,2,1],\r
                        TIMER1: [0,4,2],\r
@@ -303,10 +303,7 @@ DEV.I2c=function I2c()
 {\r
        throw new MiMicException("Not imprement.");\r
 }\r
-DEV.Pwm=function Pwm()\r
-{\r
-       throw new MiMicException("Not imprement.");\r
-}\r
+\r
 DEV.Dma=function Dma()\r
 {\r
        throw new MiMicException("Not imprement.");\r
index e050796..296e299 100644 (file)
@@ -5,7 +5,15 @@
  */\r
 var MiMicLib=\r
 {\r
-       isUndef:function isUndef(a){return typeof a==="undefined"}\r
+       isUndef:function isUndef(a){return typeof a==="undefined"},\r
+       cloneAssoc:function cloneAssoc(a)\r
+       {\r
+               var r={};\r
+               for(var i in a){\r
+                       r[i]=a[i];\r
+               }\r
+               return r;\r
+       }\r
 }\r
 \r
 \r
index 7f19409..d92a214 100644 (file)
@@ -9,6 +9,7 @@
 <script src="LPCXpresso1769.Gpio.js"></script>\r
 <script src="LPCXpresso1769.Peripheral.js"></script>   \r
 <script src="LPCXpresso1769.Adc.js"></script>  \r
+<script src="LPCXpresso1769.Pwm.js"></script>  \r
 <script type="text/javascript">\r
 function init(){\r
 try{\r
@@ -16,11 +17,11 @@ try{
         * MCUにあるピンに機能を割り当る為の手順。
         */\r
        \r
-       \r
+               var     mcu=new LPCXpresso1769.Mcu("192.168.128.39",true);\r
+       var pwmpin;\r
        //オーソドックスな方法\r
        function case1()\r
        {\r
-               var     mcu=new LPCXpresso1769.Mcu("192.168.0.39",true);\r
                //ADCペリフェラルを作る。\r
                var adc=new LPCXpresso1769.Adc(mcu);\r
                //ペリフェラルからピンに接続\r
@@ -28,7 +29,7 @@ try{
                //GPIOペリフェラルを作る。\r
                var gpio=new LPCXpresso1769.Gpio(mcu);\r
                //ペリフェラルからピンに接続\r
-               var gpiopin=new LPCXpresso1769.GpioPin(gpio,LPCXpresso1769.P0[0]);\r
+               var gpiopin=new LPCXpresso1769.GpioPin(gpio,LPCXpresso1769.P0[0],{dir:1});\r
                alert(adpin.getValue()+","+gpiopin.getValue());\r
        }\r
        \r
@@ -36,7 +37,6 @@ try{
        function case2()\r
        {\r
                //MCU生成\r
-               var     mcu=new LPCXpresso1769.Mcu("192.168.0.39");\r
                //機能名でPINを作る。(物理PINは自動)\r
                var gpiopin=mcu.getPin("GPIO0.0");\r
                var gpiopin2=mcu.getPin("GPIO0.1");\r
@@ -48,14 +48,23 @@ try{
        function case3()\r
        {\r
                //MCU生成\r
-               var     mcu=new LPCXpresso1769.Mcu("192.168.128.39");\r
                //PIN0[0]をGPIO機能を割り当て\r
                var gpiopin=mcu.getPin(LPCXpresso1769.P0[0],"GPIO");\r
                //PIN0[0]をAD機能を割り当て\r
                var adpin=mcu.getPin(LPCXpresso1769.P0[23],"AD");\r
                alert(adpin.getValue()+","+gpiopin.getValue());\r
        }\r
-       //case3();\r
+       function test()\r
+       {\r
+//             var gpiopin=mcu.getPin(LPCXpresso1769.P2[0],"GPIO");\r
+//             gpiopin.setOpt({dir:1,pin:{mode:1,od:0}});\r
+               var i=0;\r
+//             setInterval(function(){gpiopin.setValue((i++)%2);},500);\r
+               var pwm=new LPCXpresso1769.Pwm(mcu,{freq:100});\r
+               pwmpin=new LPCXpresso1769.PwmPin(pwm,LPCXpresso1769.P2[0],{duty:0.0});\r
+               \r
+       }\r
+       test();\r
        /*\r
 var mcu=new LPCXpresso1769.Mcu("192.168.128.39");\r
 var gpiopin=mcu.getPin(LPCXpresso1769.P0[0],"GPIO");\r
@@ -63,7 +72,7 @@ gpiopin.setOpt({dir:1,pin:{mode:1,od:0}});
 var i=0;\r
 setInterval(function(){gpiopin.setValue((i++)%2);},30);\r
 \r
-\r
+*/\r
        \r
 \r
 }catch(e){\r
@@ -71,13 +80,25 @@ setInterval(function(){gpiopin.setValue((i++)%2);},30);
        //e.alert();    \r
        throw e;\r
 }\r
+document.getElementById("ga").onmousemove=onpos;\r
+function onpos(e)\r
+{\r
+       var d=document.getElementById("ga");\r
+       var v=(e.pageX-d.style.left);\r
+       if(v>300)v=300;\r
+       d.innerHTML=(v/6);\r
+       pwmpin.setDuty(v/600);\r
+       \r
+}\r
 }      \r
+\r
 </script>\r
 </head>\r
 <body onload="init();">\r
-<h1>MiMic demo</h1>\r
+<h1>MiMic test</h1>\r
 <hr/>\r
 MiMic Copyright (C) 2011 nyatla.jp All Rights Reserved.<br/>\r
+<div id="ga" style="width:300;height:100px;border-style:solid;border-color:black">aaa</div>\r
 <a href="http://nyatla.jp/mimic/wp">http://nyatla.jp/mimic/wp</a>\r
 </div>\r
 </body>\r