static unsigned int get_fota_cookie(void) { struct ptentry *ptn; struct ptable *ptable; unsigned int cookie = 0; ptable = flash_get_ptable(); if (ptable == NULL) { dprintf(CRITICAL, "ERROR: Partition table not found\n"); return 0; } ptn = ptable_find(ptable, "fota"); if (ptn == NULL) { dprintf(CRITICAL, "ERROR: No fota partition found\n"); return 0; } if(read_from_flash(ptn, 0, sizeof(unsigned int), &cookie) == -1){ dprintf(CRITICAL,"ERROR: failed to read fota cookie from flash"); return 0; } return cookie; }
/*lint -save -e970 Disable MISRA rule (6.3) checking. */ int main(void) /*lint -restore Enable MISRA rule (6.3) checking. */ { /* Write your local variable definition here */ uint8_t i ; //uint8_t send_buf[50] ; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ GPIO1_ClearFieldBits(GPIO1_Ptr, LAMP_CTR, 1); //turn off the lamp modbus_init(); Ram_Init(); read_from_flash(); task_init(); bmp180_init(); opa_init(); Aq_Init(); /* Write your code here */ /* For example: */ for(;;) { // sprintf((char*)send_buf,"#C%05u P%07u TP%04d TH%04d H%04u AQ%04u\n\r", modbus.Co2, modbus.PP, modbus.PT, modbus.HT, modbus.HH, modbus.Aq); // AS1_SendBlock(AS1_ptr, send_buf, strlen((char*)send_buf)) ; // Delay(6); if(heartbeat == TRUE) //tick = 1ms { heartbeat = FALSE; if(serial_receive_timeout_count > 0) { serial_receive_timeout_count--; if(serial_receive_timeout_count == 0) { revce_count = 0; } } if(serial_response_delay > 0) serial_response_delay--; if((dealwithTag == TRUE) && (serial_response_delay == 0)) { dealwithTag = FALSE; dealwithData(); } heartbeat_counter++; if(heartbeat_counter >= OS_TICK) // 1 * 10 = 10ms { heartbeat_counter = 0; task_manage(); } } Co2_Detect(); // // AS2_SendBlock(AS2_ptr, "start\n\r", sizeof("start\n\r")) ; // print_status = AD1_CreateSampleGroup(AdDataPTR, &ADC_CO2_Sample, 1) ; // Delay(300); // // sprintf((void*)str, "P = %u\n\r", (uint16_t)print_status); // AS1_SendBlock(AS1_ptr, str, sizeof(str)) ; // Delay(300); // if(enter_adc) // { // enter_adc = 0 ; // AS2_SendBlock(AS2_ptr, "enteradc\n\r", sizeof("enteradc\n\r")) ; // } // Delay(300); // switch(print_status) // { // case ERR_PARAM_SAMPLE_COUNT: // AS2_SendBlock(AS2_ptr, "Para\n\r", sizeof("Para\n\r")) ; // break; // case ERR_BUSY: // AS2_SendBlock(AS2_ptr, "BSY\n\r", sizeof("BSY\n\r")) ; // break; // case ERR_OK: // AS2_SendBlock(AS2_ptr, "OK\n\r", sizeof("OK\n\r")) ; // break ; // case ERR_PARAM_INDEX: // AS2_SendBlock(AS2_ptr, "index\n\r", sizeof("index\n\r")) ; // break ; // } // AD1_CreateSampleGroup(AdDataPTR, (LDD_ADC_TSample *)&ADC_PM25_Sample, 1U); // AD1_StartSingleMeasurement(AdDataPTR); // while(AD1_GetMeasurementCompleteStatus(AdDataPTR) != TRUE); // AD1_GetMeasuredValues(AdDataPTR, (LDD_TData *)&PM25_AD) ; // sprintf((void*)str, "P%u\n\r", (uint16_t)PM25_AD); // AS1_SendBlock(AS1_ptr, str, strlen((const char*)str)) ; // Delay(3000) ; } /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/ #ifdef PEX_RTOS_START PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of RTOS startup code. ***/ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){} /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/