?? app.c
字號:
#include "type.h"
#include "global.h"
#include "message.h"
#include "sensor.h"
#include "timer.h"
#include "os.h"
#include "uartDebug.h"
#include "app.h"
#include "led.h"
#include "mac.h"
OSMACMsg uartMsg;
uint8_t LLCpacketReadingNumber;
uint8_t LLCPacketNumber;
OSMACMsg LLCmsg[2];
uint8_t LLCcurrentMsg;
result_t Init(void){
////下面是配置節點的一些數據,需要在節點初始化之前定義,因為
//有些數據是在初始化的時候直接賦值給相關的寄存器
{
POWERLEVEL = 0X01; //射頻的功率
OS_LOCAL_ADDRESS = 3; //本地節點的地址
OS_BCAST_ADDR = 0xEE; //廣播地址
ACK_ON = 0; //使用ack機制,建議不要使用,1表示開啟,0表示關閉
ACKTIME = 5; //ack等待時間=ACKTIME*16ms
}
//////////
LedInit();
LedRedOff();
LedGreenOff();
LedYellowOff();
SensorPhoOStdControlInit();
//SensorTempStdControlInit();
TimerStdControlInit();
// 初始化UART debugging
uartDebug_init();
MACInit();
LLCpacketReadingNumber = 0;
LLCPacketNumber = 0;
LLCcurrentMsg = 0;
return SUCCESS;
}
result_t Start(void){
SensorPhoOStdControlStart();
//SensorTempStdControlStart();
TimerTimerStart(0, TIMER_REPEAT, 125); //定時采集數據
return SUCCESS;
}
result_t Timer0_0_Fired(void){
//一次中斷,采樣一次
SensorExternalPhotoADCGetData();
//SensorExternalTempADCGetData();
return SUCCESS;
}
result_t Timer0_1_Fired(void){
return SUCCESS;
}
result_t SensordataReady(uint16_t data){
SensorMsg *pack;
if ( OS_LOCAL_ADDRESS == SINKNODE ){
LedRedOn();
return SUCCESS;
} else {
uint8_t atomicState = AtomicStart();
{
pack = (SensorMsg *)LLCmsg[LLCcurrentMsg].data;
pack->data[LLCpacketReadingNumber++] = data;
if (LLCpacketReadingNumber == BUFFER_LEN) {
OSPostTask(LLCdataTask); // 如果緩存區已滿,則發送
LLCPacketNumber++;
}
}
AtomicEnd(atomicState); }
if (data < 0x0230) {
LedRedOff();
LedGreenOn();
}
else {
LedRedOn();
LedGreenOff();
}
return SUCCESS;
}
/*************************************************************************
*功能描述:發送任務處理
*參數說明:
*返回值:
**************************************************************************/
void LLCdataTask(void)
{
SensorMsg *pack;
{ uint8_t atomicState = AtomicStart();
{
pack = (SensorMsg *)LLCmsg[LLCcurrentMsg].data;
LLCpacketReadingNumber = 0;
pack->seqNo = LLCPacketNumber;
}
AtomicEnd(atomicState); }
if (LLCDataMsgSend(OS_BCAST_ADDR,
sizeof(SensorMsg), &LLCmsg[LLCcurrentMsg]))
{
{ uint8_t atomicState = AtomicStart();
{
LLCcurrentMsg ^= 0x1;
}
AtomicEnd(atomicState); }
}
}
result_t LLCDataMsgSend(uint8_t addr, uint8_t length, OSMACMsgPtr data)
{
unsigned char result;
if (length > APP_PKT_LEN)
{
return FALSE;
}
if (addr == OS_BCAST_ADDR)
{
result = MACUnicastMsg(data, length,SINKNODE,1);
}
else
result = 1;
return result;
}
result_t ReceiveDone(OSMACMsgPtr packet){ // 接收包完成
uartMsg = *packet;
if( OS_LOCAL_ADDRESS == SINKNODE ){
LedYellowToggle();
uartDebug_txPacket(&uartMsg);
}
return SUCCESS;
}
result_t TransmitDone(OSMACMsgPtr msg){ // 發送完成
LedYellowToggle();
return SUCCESS;
}
result_t GetFreeQueueLength(void){
return 1;
}
void SendFail(OSMACMsgPtr receivemsg){
//RouteChangeP(receivemsg->toAddr);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -