static void write_at_offset(const char *key, const void *buffer, int buf_len, unsigned int sector_offset) { int key_len = strlen(key) + 1; unsigned int record_size = key_len + buf_len + sizeof(record_size); unsigned int flash_addr = (unsigned int)STORAGE_ADDRESS + sector_offset; write_to_flash(flash_addr, (unsigned char *)&record_size, sizeof(record_size)); write_to_flash(flash_addr+sizeof(record_size), (unsigned char *)key, key_len); write_to_flash(flash_addr+sizeof(record_size)+key_len, buffer, buf_len); flush_cpu_dcache(); }
//Writes new serial number to flash space from ptr void write_serialnumber(char* new_serialnumber) { int i; char new_settings[256]; char *current_settings_ptr; current_settings_ptr = (char*)SETTINGS_ADDR_L; //Read the current settings for(i = 0 ; i < 256 ; i++) { new_settings[i] = current_settings_ptr[i]; } //Splice in new serial number //Move 16 bytes of serial number data to settings array for(i = 0 ; i < 16 ; i++) { new_settings[i + (256-16)] = new_serialnumber[i]; } //Record settings to memory write_to_flash(new_settings); }
//Writes a blank record to flash void erase_settings(void) { int i; char new_settings[256]; //Read the current settings for(i = 0 ; i < 256 ; i++) { new_settings[i] = 0xFF; } //Record settings to memory write_to_flash(new_settings); }
//Writes a given option setting to flash void write_option(int spot_number, unsigned char user_byte) { int i; char new_settings[256]; char *current_settings_ptr; current_settings_ptr = (char*)USER_SETTING_START; //Read the current settings for(i = 0 ; i < 256 ; i++) { new_settings[i] = current_settings_ptr[i]; } //Splice in new byte new_settings[spot_number] = user_byte; //Record settings to memory write_to_flash(new_settings); }
static int secure_writer_monitor(void *arg) { struct secure_monitor_arg *parg = (struct secure_monitor_arg*)arg; unsigned char *pfbuf = parg->pfbuf; unsigned long flags; NS_SHARE_MEM_HEAD *pshead = (NS_SHARE_MEM_HEAD*)(parg->psbuf+SHARE_MEM_HEAD_OFFSET); unsigned char *psdata = parg->psbuf + SHARE_MEM_DATA_OFFSET; bool w_busy = false; while(1){ if(w_busy){ write_to_flash(pfbuf, FLASH_BUF_SIZE); w_busy=false; } //arch_local_irq_save(); local_fiq_disable(); lock_mutex(&(pshead->cmdlock)); if(pshead->cmd == SHARE_MEM_CMD_WRITE){ memcpy(pfbuf, psdata, FLASH_BUF_SIZE); pshead->cmd=SHARE_MEM_CMD_FREE; w_busy = true; printk("************kernel detect write flag*****\n"); } unlock_mutex(&(pshead->cmdlock)); //arch_local_irq_restore(flags); local_fiq_enable(); if(!w_busy){ if(kthread_should_stop()) break; else msleep(200); } } return 0; }
static void run_routine(void) { static uint8_t running_queue_index = 0; static uint8_t beat_count = 0 ; static uint8_t rever_heartled = 0 ; uint16_t co2_temp ; if(task_ready_num == 0) { return; } if(running_queue_index == TASK_END) { running_queue_index = 0; } switch(ready_task_queue[running_queue_index]) { case TASK_OUTPUT: Press_Task(); break; case TASK_HUM: HTU21_TASK(); break; case TASK_AQ: AD1_CreateSampleGroup(AdDataPTR, (LDD_ADC_TSample *)&ADC_AQ_Sample, 1U); AD1_StartSingleMeasurement(AdDataPTR); while(AD1_GetMeasurementCompleteStatus(AdDataPTR) != TRUE); AD1_GetMeasuredValues(AdDataPTR, (LDD_TData *)&modbus.Aq_Ad) ; aq_analog_input = modbus.Aq_Ad /64; check_Air_Quality(); // if(rever_heartled) // { // GPIO1_SetFieldValue(GPIO1_Ptr, AQ_CTR, 1); // rever_heartled = 0 ; // } // else // { // GPIO1_ClearFieldBits(GPIO1_Ptr, AQ_CTR, 1); // rever_heartled = 1 ; // } break; case TASK_RTD: AD1_CreateSampleGroup(AdDataPTR, (LDD_ADC_TSample *)&ADC_TEMP_Sample, 1U); AD1_StartSingleMeasurement(AdDataPTR); while(AD1_GetMeasurementCompleteStatus(AdDataPTR) != TRUE); AD1_GetMeasuredValues(AdDataPTR, (LDD_TData *)&modbus.Rtd_Ad) ; break; case TASK_FLASH: write_to_flash(); break; case TASK_CO2: if(modbus.co2_fac_cus_table == 0) { co2_temp= Calculate(modbus.Co2_Ad, modbus.co2_fac_ad, modbus.co2_fac_ppm, modbus.co2_fac_point); modbus.Co2= Filter(co2_temp ) ; } //// else if(modbus.co2_fac_cus_table == 1) //// modbus.Co2 = Calculate(modbus.Co2_Ad, modbus.co2_cus_ad, modbus.co2_cus_ppm, modbus.co2_cus_point); break; default: break; } reset_task_tick(ready_task_queue[running_queue_index]); running_queue_index++; task_ready_num--; }