OSDN Git Service

c3985b748c9a41724b4d3a9ef1dd945ff8571c36
[mimic/MiMicSDK.git] / misc / MiMicVM / api.js / LPCXpresso1769.Peripheral.js
1 (function(){\r
2 var DEV=LPCXpresso1769;\r
3 var BCF=DEV._BCF;\r
4 var EE=DEV._EE;\r
5 var isUndef=MiMicLib.isUndef;\r
6 /**\r
7  * @see API manual\r
8  */\r
9 DEV.Peripheral=function(i_mcu,i_phy,i_opt)\r
10 {\r
11         try{\r
12                 if(isUndef(i_phy)){\r
13                         throw new MiMicException(EE.INVALID_PHY);\r
14                 }\r
15                 this._mcu=i_mcu;\r
16                 this._phy=i_phy;\r
17                 //オプション設定するならする。\r
18                 if(!isUndef(i_opt)){\r
19                         this.setOpt(i_opt);\r
20                 }\r
21         }catch(e){\r
22                 throw new MiMicException(e);\r
23         }       \r
24 }\r
25 DEV.Peripheral.prototype=\r
26 {\r
27         _PCLKSEL:[0x400FC1A8,0x400FC1AC],\r
28         _PCONP:0x400FC0C4,\r
29         _phy:null,\r
30         _mif:null,\r
31         BCF_setOpt:function BCF_setOpt(i_opt,i_db)\r
32         {\r
33                 try{\r
34                         var bc="";\r
35                         //pconp\r
36                         if(!isUndef(i_opt.power)){\r
37                                 if(this._phy[2]==null){\r
38                                         throw new MiMicException(EE.INVALID_CFG,"The pin does not support PCONP.");\r
39                                 }\r
40                                 //pinselAddrを得る\r
41                                 bc+=BCF.setBit(this._PCONP,0x00000001,i_opt.power,this._phy[2],i_db);\r
42                         }\r
43                         //clock\r
44                         if(!isUndef(i_opt.clock)){\r
45                                 if(this._phy[0]==null){\r
46                                         throw new MiMicException(EE.INVALID_CFG,"The pin does not support PCLKSEL.");\r
47                                 }\r
48                                 bc+=BCF.setBit(this._PCLKSEL[this._phy[0]],0x00000003,i_opt.clock,this._phy[1],i_db);\r
49                         }\r
50                         return bc;\r
51                 }catch(e){\r
52                         throw new MiMicException(e);\r
53                 }               \r
54         },\r
55         /**\r
56          * @see API manual
57          */\r
58         setOpt:function setOpt(i_opt)\r
59         {\r
60                 try{\r
61                         var db=new Array();\r
62                         var bc=this.BCF_setOpt(i_opt,db);\r
63                         if(bc.length==0){\r
64                                 throw new MiMicException("i_opt is empty or invalid.");\r
65                         }\r
66                         //MiMicBCを生成して実行\r
67                         this._mcu.callMiMicWithCheck(bc+BCF.END,db);\r
68 \r
69                 }catch(e){\r
70                         throw new MiMicException(e);\r
71                 }\r
72                 return;         \r
73         }\r
74 }\r
75 \r
76 }());