NesC.docx
- 文档编号:10179535
- 上传时间:2023-02-09
- 格式:DOCX
- 页数:97
- 大小:44.76KB
NesC.docx
《NesC.docx》由会员分享,可在线阅读,更多相关《NesC.docx(97页珍藏版)》请在冰豆网上搜索。
NesC
1.Lesson_1—MyApp.nc
/*
*Copyright(c)2004-2007CrossbowTechnology,Inc.
*Allrightsreserved.
*Seelicense.txtfileincludedwiththedistribution.
*
*$Id:
MyApp.nc,v1.1.2.22007/04/2619:
59:
01njainExp$
*/
/**
*ThisconfigurationshowshowtousetheTimerandLEDcomponents
*
**/
configurationMyApp{
}
implementation{
componentsMain,MyAppM,TimerC,LedsC;
Main.StdControl->TimerC.StdControl;
Main.StdControl->MyAppM.StdControl;
MyAppM.Timer->TimerC.Timer[unique("Timer")];
MyAppM.Leds->LedsC.Leds;
}
2.Lesson_1—MyAppM.nc
/*
*Copyright(c)2004-2007CrossbowTechnology,Inc.
*Allrightsreserved.
*Seelicense.txtfileincludedwiththedistribution.
*
*$Id:
MyAppM.nc,v1.1.2.22007/04/2619:
59:
09njainExp$
*/
/**
*ThismoduleshowshowtousetheTimerandLEDcomponents
**/
moduleMyAppM{
provides{
interfaceStdControl;
}
uses{
interfaceTimer;
interfaceLeds;
}
}
implementation{
/**
*Initializethecomponents.
*
*@returnAlwaysreturnsSUCCESS
**/
commandresult_tStdControl.init(){
callLeds.init();
returnSUCCESS;
}
/**
*Startthingsup.Thisjustsetstheratefortheclockcomponent.
*
*@returnAlwaysreturnsSUCCESS
**/
commandresult_tStdControl.start(){
//Startarepeatingtimerthatfiresevery1000ms
returncallTimer.start(TIMER_REPEAT,1000);
}
/**
*Haltexecutionoftheapplication.
*Thisjustdisablestheclockcomponent.
*
*@returnAlwaysreturnsSUCCESS
**/
commandresult_tStdControl.stop(){
returncallTimer.stop();
}
/**
*ToggletheredLEDinresponsetotheTimer.fired
event.
*
*@returnAlwaysreturnsSUCCESS
**/
eventresult_tTimer.fired()
{
callLeds.redToggle();
returnSUCCESS;
}
}
3.Lesson_2—MyApp.nc
/*
*Copyright(c)2004-2007CrossbowTechnology,Inc.
*Allrightsreserved.
*Seelicense.txtfileincludedwiththedistribution.
*
*$Id:
MyApp.nc,v1.1.2.22007/04/2619:
59:
29njainExp$
*/
includessensorboardApp;
/**
*ThismoduleshowshowtousetheTimer,LED,ADCandMessagingcomponents.
*Sensormessagesaresenttotheserialport
**/
configurationMyApp{
}
implementation{
componentsMain,MyAppM,TimerC,LedsC,Photo,GenericCommasComm;
Main.StdControl->TimerC.StdControl;
Main.StdControl->MyAppM.StdControl;
Main.StdControl->Comm.Control;
MyAppM.Timer->TimerC.Timer[unique("Timer")];
MyAppM.Leds->LedsC.Leds;
MyAppM.PhotoControl->Photo.PhotoStdControl;
MyAppM.Light->Photo.ExternalPhotoADC;
MyAppM.SendMsg->Comm.SendMsg[AM_XSXMSG];
}
4.Lesson_2—MyAppM.nc
/*
*Copyright(c)2004-2007CrossbowTechnology,Inc.
*Allrightsreserved.
*Seelicense.txtfileincludedwiththedistribution.
*
*$Id:
MyAppM.nc,v1.1.2.42007/04/2619:
59:
38njainExp$
*/
includessensorboardApp;
/**
*ThismoduleshowshowtousetheTimer,LED,ADCandMessagingcomponents
*Sensormessagesaresenttotheserialport
*
**/
moduleMyAppM{
provides{
interfaceStdControl;
}
uses{
interfaceTimer;
interfaceLeds;
interfaceStdControlasPhotoControl;
interfaceADCasLight;
interfaceSendMsg;
}
}
implementation{
boolsending_packet=FALSE;
TOS_Msgmsg_buffer;
XDataMsg*pack;
/**
*Initializethecomponent.
*
*@returnAlwaysreturnsSUCCESS
**/
commandresult_tStdControl.init(){
callLeds.init();
callPhotoControl.init();
//Initializethemessagepacketwithdefaultvalues
atomic{
pack=(XDataMsg*)&(msg_buffer.data);
pack->xSensorHeader.board_id=SENSOR_BOARD_ID;
pack->xSensorHeader.packet_id=2;
pack->xSensorHeader.node_id=TOS_LOCAL_ADDRESS;
pack->xSensorHeader.rsvd=0;
}
returnSUCCESS;
}
/**
*Startthingsup.Thisjustsetstheratefortheclockcomponent.
*
*@returnAlwaysreturnsSUCCESS
**/
commandresult_tStdControl.start(){
//Startarepeatingtimerthatfiresevery1000ms
returncallTimer.start(TIMER_REPEAT,1000);
}
/**
*Haltexecutionoftheapplication.
*Thisjustdisablestheclockcomponent.
*
*@returnAlwaysreturnsSUCCESS
**/
commandresult_tStdControl.stop(){
returncallTimer.stop();
}
/**
*ToggletheredLEDinresponsetotheTimer.fired
event.
*StarttheLightsensorcontrolandsamplethedata
*
*@returnAlwaysreturnsSUCCESS
**/
eventresult_tTimer.fired()
{
callLeds.redToggle();
callPhotoControl.start();
callLight.getData();
returnSUCCESS;
}
/**
*StoptheLightsensorcontrol,buildthemessagepacketandsend
**/
voidtaskSendData()
{
callPhotoControl.stop();
if(sending_packet)return;
atomicsending_packet=TRUE;
//sendmessagetoUART(serial)port
if(callSendMsg.send(TOS_UART_ADDR,sizeof(XDataMsg),&msg_buffer)!
=SUCCESS)
sending_packet=FALSE;
return;
}
/**
*LightADCdataready
*ToggleyellowLEDtosignalLightsensordatasampled
*
*@returnAlwaysreturnsSUCCESS
**/
asynceventresult_tLight.dataReady(uint16_tdata){
atomicpack->xData.datap1.light=data;
atomicpack->xData.datap1.vref=417;//adummy3Vreferencevoltage,1252352/3000=417
postSendData();
callLeds.yellowToggle();
returnSUCCESS;
}
/**
*SensordatahasbeensucessfullysentovertheUART(serialport)
*TogglegreenLEDtosignalmessagesent
*
*@returnAlwaysreturnsSUCCESS
**/
eventresult_tSendMsg.sendDone(TOS_MsgPtrmsg,result_tsuccess){
callLeds.greenToggle();
atomicsending_packet=FALSE;
returnSUCCESS;
}
}
5.Lesson_2—Photo.nc
/*
*Copyright(c)2002-2005IntelCorporation
*Copyright(c)2000-2005TheRegentsoftheUniversityofCalifornia
*Copyright(c)2003bySensicast,Inc.
*Allrightsreserved.
*Seelicense.txtfileincludedwiththedistribution.
*
*$Id:
Photo.nc,v1.1.2.22007/04/2619:
59:
46njainExp$
*/
/*
*
*Authors:
JasonHill,DavidGay,PhilipLevis
*Datelastmodified:
6/25/02
*
*Modifications:
*20Oct03MJNewman:
Addtimerusedfordelayswhensensorisswitched.
*
*/
/**
*@authorJasonHill
*@authorDavidGay
*@authorPhilipLevis
*@authorMichaelNewman
*/
//includessensorboard;
configurationPhoto
{
providesinterfaceADCasExternalPhotoADC;
providesinterfaceStdControlasPhotoStdControl;
}
implementation
{
componentsPhotoM,ADCC,TimerC;
PhotoStdControl=PhotoM.PhotoStdControl;
ExternalPhotoADC=PhotoM.ExternalPhotoADC;
PhotoM.InternalPhotoADC->ADCC.ADC[TOS_ADC_PHOTO_PORT];
PhotoM.ADCControl->ADCC;
PhotoM.TimerControl->TimerC;
PhotoM.PhotoTimer->TimerC.Timer[unique("Timer")];
}
6.Lesson_2—PhotoM.nc
/*
*Copyright(c)2002-2005IntelCorporation
*Copyright(c)2000-2005TheRegentsoftheUniversityofCalifornia
*Copyright(c)2003bySensicast,Inc.
*Allrightsreserved.
*Seelicense.txtfileincludedwiththedistribution.
*
*$Id:
PhotoM.nc,v1.1.2.22007/04/2619:
59:
54njainExp$
*/
#definePhotoMedit3
/*
*ModificationHistory:
*11Nov03MJNewman3:
TinyOS1.1atomicupdates.
*20Oct03MJNewman2:
Redocopyrightandinitialcomments.
*7May03MJNewman1:
Addproperdelayswhensensorisswitched.
*Itisimportanttowaitabout10msfrom
*startingasensortoreadingdatafromthe
*sensor.
*7May03MJNewman1:
Created.
*
*ThismoduleisarewriteofthePhotoM.ncmodulewrittenby
*JasonHill,DavidGayandPhilipLevis.Thismodulesolves
*fundamentalsamplingproblemsintheirmodulehavingtodowith
*waitingforlogictosettlewhenchangingbetweenthephotoand
*temperaturesensors.
*
*ISSUE:
ContinuousdatainADCCissupposedtosampleatsomerate
*controlledbyADCControl.setSamplingRate.TheoriginalPhoto
*exampledoesnotappeartodothis.Nosupporthasbeenadded.The
*implementationofgetContinuousDatainthecurrentcodewillsample
*asfastasitcan.WhenbothPhotoandTempsamplesarerequested
*theywillalternateproducingonesampleevery10ms.
*/
//OScomponentabstractionoftheanalogphotosensorandtemperature
//sensorwithassociatedA/Dsupport.Thiscodeprovidesan
//asynchronousinterfacetothephotoandtemperaturesensors.One
//TimerCtimerisused,certainformsofclockusearenotcompatible
//withusingatimer.(i.e.theClockCcomponent)
//
//Itisimportanttonotethatthetemperatureandphotosensorsshare
//hardwareandcannotbeusedatthesametime.Properdelaysare
//implementedhere.UsingExternalXxxADC.getDatawillinitiatethe
//appropriatedelayspriortosamplingdata.getDatafortemperature
//andlightmaybothbeinvokedinanyorderandatanytime.A
//correctsamplewillbesignalledbythecorrespondingdataReady.
//
//PhotoandTempprovidethesameinterfaces.Exposedinterfacesare
//ExternalPhotoADCandExternalPhotoADCaswellasPhotoStdControland
//PhotoStdControl.Thefollowingroutinesarethepublicinterface:
//
//xxxStdControl.initinitializesthedevice
//xxxADC.startstartsaparticularsensor
//xxxADC.stopstopsaparticularsensor,thiswillalsostop
//anygetContinuousDataonthatsensor.
//xxxADC.getDatareadsdatafromasensor.Thismaybecalledin
//anyorder.AdataReadyeventissignalled
//whenthedataisready.TemperatureandPhoto
//willwaitforeachotherasneeded.
//xxxADC.getContinuousDatareadsdatafromasensorandwhenthe
//readcompletestriggersanadditionalgetData.
//Continuousdatafrombothsensorswillworkbut
//a10msdelaywi
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- NesC
![提示](https://static.bdocx.com/images/bang_tan.gif)