예제 #1
0
파일: main.c 프로젝트: atiselsts/osw
// Application entry point
void appMain(void)
{
    // Initialize and start timer #1 (after 700 milliseconds)
    alarmInit(&timer1, onTimer1, NULL);
    alarmSchedule(&timer1, 700);

    // Initialize and start timer #2  (after 1000 milliseconds)
    alarmInit(&timer2, onTimer2, NULL);
    alarmSchedule(&timer2, 1000);

    // Enter infinite low-power loop
    for (;;) {
        msleep(2000);
    }
}
예제 #2
0
파일: amb8420.c 프로젝트: placidrage/mansos
void amb8420Init(void)
{
    RPRINTF("amb8420Init...\n");

    amb8420InitSerial();

    pinAsOutput(AMB8420_RESET_PORT, AMB8420_RESET_PIN);
    pinAsOutput(AMB8420_CONFIG_PORT, AMB8420_CONFIG_PIN);
    pinAsOutput(AMB8420_SLEEP_PORT, AMB8420_SLEEP_PIN);
    pinAsOutput(AMB8420_TRX_DISABLE_PORT, AMB8420_TRX_DISABLE_PIN);
    // pinAsOutput(AMB8420_DATA_REQUEST_PORT, AMB8420_DATA_REQUEST_PIN);
    pinAsInput(AMB8420_RTS_PORT, AMB8420_RTS_PIN);
    // pinAsInput(AMB8420_DATA_INDICATE_PORT, AMB8420_DATA_INDICATE_PIN);

    pinSet(AMB8420_CONFIG_PORT, AMB8420_CONFIG_PIN);
    // pinClear(AMB8420_DATA_REQUEST_PORT, AMB8420_DATA_REQUEST_PIN);

    // in case interrupts are used (for non-command mode):
    //pinIntRising(AMB8420_DATA_INDICATE_PORT, AMB8420_DATA_INDICATE_PIN);
    //pinEnableInt(AMB8420_DATA_INDICATE_PORT, AMB8420_DATA_INDICATE_PIN);

    initResult = amb8420Reset();

    // make sure low power mode is enabled
    pinSet(AMB8420_TRX_DISABLE_PORT, AMB8420_TRX_DISABLE_PIN);
    pinSet(AMB8420_SLEEP_PORT, AMB8420_SLEEP_PIN);

    alarmInit(&radioResetTimer, onRadioReset, NULL);
    alarmSchedule(&radioResetTimer, RADIO_RESET_INTERVAL);

    RPRINTF("..done\n");
}
예제 #3
0
파일: main.c 프로젝트: KuanYuChen/mansos
void appMain(void)
{
    timerBInit();

    alarmInit(&blinkTimer, onBlinkTimer, NULL);
    alarmInit(&randTimer, onRandTimer, NULL);

    alarmSchedule(&blinkTimer, 100);
    alarmSchedule(&randTimer, 101);

    PRINTF("\n*** starting the app ***\n\n");

    for (;;) {
       msleep(1000);
    }
}
예제 #4
0
파일: main.c 프로젝트: KuanYuChen/mansos
// -------------------------------------
// Main function
// -------------------------------------
void appMain(void)
{
    uint16_t i;

    // timers (used to get an extra interrupt context)
    alarmInit(&timer, onTimer, NULL);
    alarmSchedule(&timer, 1000);

    // radio
    radioSetReceiveHandle(radioRecvCb);
    radioOn();

    for (i = 0; i < BUFFER_SIZE; i++) {
        buffer[i] = i;
    }

    randomInit();

    // SELECT_FLASH;
    // extFlashBulkErase();
    // UNSELECT_FLASH;

    for (i = 0; ; i++) {
        uint32_t address = i * 64ul;

        SELECT_FLASH;

        if (IS_ALIGNED(address, EXT_FLASH_SECTOR_SIZE)) {
            PRINTF("erase address %lu\n", address);
            flashErase(address);
        }

        PRINTF("write address %lu\n", address);
        flashWrite(address);

        if (address > 0) {
            PRINTF("verify...\n");
            flashRead(address - 64);
        }

        UNSELECT_FLASH;

        msleep(randomInRange(400, 1000));

        PRINTF("send smth to radio...\n");
        radioSend("hello world", sizeof("hello world"));

        greenLedToggle();
    }
}
예제 #5
0
파일: main.c 프로젝트: atiselsts/osw
void appMain(void)
{
    alarmInit(&alarm, alarmCallback, (void *) 0);
    alarmSchedule(&alarm, 10);

    for (;;) {
//        PRINT("in app main...\n");
        redLedToggle();
#if 1 // will get different error messages depending on whether in mdelay or in msleep
        msleep(1000);
#else
        mdelay(1000);
#endif
    }
}
예제 #6
0
파일: main.c 프로젝트: KuanYuChen/mansos
void appMain(void)
{
    redLedToggle();

    // initialize and schedule the alarm
    alarmInit(&alarm, onAlarm, NULL);
    nextPeriod = PERIOD;
    // jiffie counter starts from 0 (zero) after reset
    alarmSchedule(&alarm, PERIOD - getJiffies());


    // enter infinite low-power loop
    for (;;) {
        sleep(10);
    }
}
예제 #7
0
void routingInit(void)
{
    socketOpen(&roSocket, routingReceive);
    socketBind(&roSocket, ROUTING_PROTOCOL_PORT);

    alarmInit(&roCheckTimer, roCheckTimerCb, NULL);
    alarmInit(&roForwardTimer, roForwardTimerCb, NULL);
    alarmInit(&roOutOfOrderForwardTimer, roOutOfOrderForwardTimerCb, NULL);
    alarmInit(&roRequestTimer, roRequestTimerCb, NULL);
    alarmInit(&roStopListeningTimer, roStopListeningTimerCb, NULL);
    alarmInit(&roStartListeningTimer, roStartListeningTimerCb, NULL);
    alarmInit(&roGreenLedTimer, roGreenLedTimerCb, NULL);
    alarmInit(&watchdogTimer, watchdogTimerCb, NULL);
    alarmSchedule(&roCheckTimer, randomInRange(1000, 3000));
    alarmSchedule(&roForwardTimer, calcNextForwardTime(0));
    alarmSchedule(&roStartListeningTimer, 110);
    alarmSchedule(&roGreenLedTimer, 10000);
//    alarmSchedule(&watchdogTimer, 1000);
}
예제 #8
0
파일: main.c 프로젝트: Paolo-Maffei/mansos
void appMain(void)
{
    // initialize the alarm
    alarmInit(&alarm, alarmCallback, NULL);
    // schedule the alarm after specific interval
    alarmSchedule(&alarm, ALARM_INTERVAL);

    for (;;) {
        ledToggle();

        // lock the mutex in user context
        uint32_t start, end;
        start = getJiffies();
        mutexLock(&testMutex);
        end = getJiffies();
        PRINTF("in user main, mutex lock time=%lu\n", end - start);
        mdelay(1000);
        mutexUnlock(&testMutex);
    }
}
예제 #9
0
void hwInit(void)
{
	_delay_ms(250);

	ds18x20SearchDevices();
	bmp180Init();
	dht22Init();

	displayInit();

	mTimerInit();

	matrixScrollAndADCInit();

	alarmInit();

	rtc.etm = RTC_NOEDIT;

	sei();

	return;
}
예제 #10
0
/*
 * 获得一条报警信息,先到内存中找,如果没有就到数据库中取1000条,放在内存中慢慢发
 *  LBSU,ALARM,htgl,0000000004,13911447899;20120627113703;A;113.252432;22.564152;30;270;130;100;7,END
 */
string getAlaData(int &minAla_id,int &act_Ala_id,int &serivalnum){
	if(act_Ala_id==0){           // 最多获取1000条
		alarmInit();
		db.getData(motorid2,lat2,lon2,dis2,a2,gprs2,speed2,dir2,gpsLocate2,weekday2,state_id2,sys_state_id2,uploadTime2,createTime2,minAla_id,ArraySize,"alarm");
	}
	if(motorid2.size()==0)//如果没有取到数据,就直接返回
		return "nodata";

	//从内存中读,直到ArraySize条都读完
	string result = "";
	stringstream ss; //流水号固定格式
	ss<<setfill('0')<<setw(10)<<serivalnum;
	string serival = ss.str();

	string locate="A";// 定位标志。。偶数的时候表示定位精确
	int locate_int = atoi(gpsLocate2[act_Ala_id].c_str());
	if(locate_int%2==0)
		locate = "A";
	else
		locate ="V";
	
	char al[14];
	memset(al,'0',sizeof(al));
	vector<string> alarminfors = getSubString(state_id2[act_Ala_id],",");
	vector<string>::iterator iter1 = alarminfors.begin(), iter2 = alarminfors.end();
	while (iter1 != iter2)
	{
		if(*iter1=="6")//超速
			al[11] ='1';
		else if(*iter1=="4")//入界
			al[9] = '1';
		else if(*iter1=="5")//出界
			al[8] = '1';
		else if(*iter1=="3")//碰撞,震动
			al[4] = '1';
		else if(*iter1=="13")//剪线,断电
			al[2] = '1';
		++iter1;
	}
	al[13]='\0';
	char al_state[8];
	memset(al_state,'0',sizeof(al_state));
	vector<string> al_state_infors = getSubString(sys_state_id2[act_Ala_id],",");
	vector<string>::iterator iter3 = al_state_infors.begin(), iter4 = al_state_infors.end();
	while (iter3 != iter4)
	{
		if(*iter3=="5")  //ACC开
			al_state[5] ='1';
		else if(locate == "A") //判断设备是否准确定位
			al_state[6] = '1';
		else if(state_id2[act_Ala_id].find("12")>0) //到报警字段中找是否设防
			al_state[4] = '1';
		++iter3;
	}
	//车子没有熄火的时候一直保持acc开的,就是状态中有5这个标志位,若没有,则表示车辆熄火,这个记录一下。
	if(al_state[5] !='1'){
		al_state[0] = '1';
	}
	al_state[7]='\0';
	string al_infor = binaryToHex(al);//传入2进制表示的   char 数组
	string al_state_result = binaryToHex(al_state);//传入2进制表示的  char数组

	if(al_infor=="0"||al_infor==""){
		al_infor = "0";
	}
	if(al_state_result=="0"||al_state_result==""){
		al_state_result = "0";
	}
	result="LBSU,ALARM,ctsm,"+serival+","+motorid2[act_Ala_id]+";"+uploadTime2[act_Ala_id]+";"+locate
			+";"+lon2[act_Ala_id]+";"+lat2[act_Ala_id]+";"+speed2[act_Ala_id]+";"+dir2[act_Ala_id]
			+";"+dis2[act_Ala_id]+";"+al_infor+";"+al_state_result+",END";

	act_Ala_id++;
	serivalnum++;
	if(act_Ala_id==motorid2.size()){//内存中的数据都读过了,就重置0,重新到数据库中加载。
		act_Ala_id=0;
	}

	return result;
}
예제 #11
0
int main(void)
{
//***********************************DEBUG********************************************/
#if 0

nmeaPOS p1,p2;
nmeaINFO info;
info.lat = 5547.1206;
info.lon = 4906.2111;
nmea_info2pos(&info, &p1);
info.lat = 5547.1221;
info.lon = 4906.208;
nmea_info2pos(&info, &p2);

m += 23;

u32 t    = nmea_distance(&p1, &p2);
if(m)
#endif
//***********************************END OF DEBUG********************************************/
  NVIC_Configuration();	//for  all peripheria
  if (SysTick_Config(SystemCoreClock / 1000))  //1ms
     { 
       /* Capture error */ 
       while (1);
     }
  Delay(500);


  USBIniPin();
  	  
  signUSBMass = USBDetectPin();
  signUSBMass = 0;  //deb
  #if not defined (VER_3)
    USBCommonIni(); 
  #endif
  if(signUSBMass)
    {
	 #if defined (VER_3)
	 USBCommonIni();
	 #endif
     while (bDeviceState != CONFIGURED);
	}
  else //if(!signUSBMass)
   {

  	 /* Flash unlock */
     FLASH_Unlock();
     /* Clear All pending flags */
     FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);	

//***********************************DEBUG********************************************/

     
//***********************************END OF DEBUG********************************************/
  /* Enable CRC clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);
    
  ledDioGPIOInit();
  led_dn(BOARD_LED_ON);
  led_mid(BOARD_LED_ON);
#if defined (VER_3)
  led_up(BOARD_LED_ON);
  ibuttonInit();
  rfmodemInit();
#endif
  Delay(1000);
  alarmInit();
  BKPInit();

  //timer6Init();

  //rs485Init();
#if not defined (VER_3)
  ais326dq_init();
#endif

  //ais326dq_data(&ais326dq_out);
  /*ADC*/
  adcInit();
  /*GPS*/
  gpsInit();

  /* reading settings */
  readConfig();
  /*MODEM*/
  gprsModemInit();
  gprsModemOn(innerState.activeSIMCard);
//***********************************DEBUG********************************************/
  //GSMSpeaker(1);
//***********************************END OF DEBUG********************************************/

#ifndef BRIDGE_USB_GSM
  setupGSM();
  ftpGSMPrepare();
  packetsIni();
#endif

  led_dn(BOARD_LED_OFF);
  led_mid(BOARD_LED_OFF);
#if defined (VER_3)
  led_up(BOARD_LED_OFF);
#endif

  rtc_init();
  rtc_gettime(&rtc);

#if 1			  /* WATCH DOG */
  /* IWDG timeout equal to 3.27 sec (the timeout may varies due to LSI frequency dispersion) */
  /* Enable write access to IWDG_PR and IWDG_RLR registers */
  IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
  /* IWDG counter clock: 40KHz(LSI) / 32 = 1.25 KHz */
  IWDG_SetPrescaler(IWDG_Prescaler_64);	//32
  /* Set counter reload value to 0xFFF */
  IWDG_SetReload(0xFFF);
  /* Reload IWDG counter */
  IWDG_ReloadCounter();
  /* Enable IWDG (the LSI oscillator will be enabled by hardware) */
  IWDG_Enable();
  setTimerIWDG(ONE_SEC);
#endif

  initSD();
#if defined (VER_3)
  //DACInit();
#endif

  /* Log  */
  saveSDInfo((u8 *)"TURN ON BLOCK ",strlen((u8 *)"TURN ON BLOCK "), SD_SENDED, SD_TYPE_MSG_LOG );
  //saveSDInfo((u8 *)readRTCTime(&rtc),strlen((const char *)readRTCTime(&rtc)), SD_SENDED, SD_TYPE_MSG_LOG );
#if defined (VER_3)  
  //DACSpeaker(1);
  //wp_play("0:/sound.wav");
  //DACSpeaker(0);
#endif 

  }	 //if(!signUSBMass)

  while (1)
  {
    if(!signUSBMass)
	  {
		 monitorWatchDog();

		 #ifndef BRIDGE_USB_GPS
	     if(!innerState.bootFTPStarted)
	         gpsHandling();
		 #endif

		 #ifndef BRIDGE_USB_GSM
		 if(!innerState.flagTmpDebug)
		    loopGSM();
			loopFTP();
            UpdatingFlash();
			if(!innerState.bootFTPStarted)
			   naviPacketHandle();
			rcvPacketHandle();
            rcvPacketHandleUSB();
		 #endif 

		 #if !defined (VER_3)
			 buttonScan();
		     accelScan();
		 #endif
		 
		 //rs485Analyse();
		 handleFOS();
		 executeDelayedCmd();
#if defined (VER_3)
		 #if 0 
		 if(innerState.flagDebug)
		 {
  			DACSpeaker(1);
	        /* Start DAC Channel1 conversion by software */
		    //a += 300;
    		//DAC_SetChannel1Data(DAC_Align_12b_R, 4000);
    		//DAC_SetChannel1Data(DAC_Align_12b_L, a);  //for saw
    		//DAC_SetChannel1Data(DAC_Align_8b_R, a);
			
			//DAC_SetChannel1Data(DAC_Align_12b_R, 4095);
			//DAC_SetChannel1Data(DAC_Align_12b_R, 0);
			//for (a = 0; a<4095; ++a)
			//for(;;)
			//  DAC_SetChannel1Data(DAC_Align_12b_R, 0);

			//DAC_SetChannel1Data(DAC_Align_12b_R, 0);
			//for ( ; ; )
			//{
			//   DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
			//}
 

	        DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);  //debugga
		 }
		 else
		 {
		     DACSpeaker(0);
		 }
	  #endif
#endif
	 }
	else
	  handleUSBPresent();
  }	   //while(1)
}