⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 app.c

📁 基于cc1000和avr128处理器的的星形网络的通信实验程序源代码
💻 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 + -