/** * init * * Initialize register */ void REGISTER::init(void) { // Does the value need to be read from EEPROM? if (eepromAddress >= 0) { STORAGE nvMem; // Read from info memory nvMem.read(value, eepromBank, eepromAddress, length); } }
/** * setData * * Set register value * * @param data New register value */ void REGISTER::setData(unsigned char *data) { // Update register value if (setValue != NULL) setValue(id, data); // Send SWAP status message sendSwapStatus(); // Does the value need to be saved in info memory (flash)? if (eepromAddress >= 0) { STORAGE nvMem; // Write info memory nvMem.write(value, eepromBank, eepromAddress, length); } }
uint8_t Encoder<POT,STORAGE, LOG>::saveSettings(STORAGE& storage, int addr) { uint8_t rvalue = true; storage.write(addr, 179); addr++; JTIncrementalEncoder::saveSettings(storage, this->state.channels.a, addr); JTIncrementalEncoder::saveSettings(storage, this->state.channels.b, addr); return rvalue; }
int main(int argc, char **argv) { STORAGE store; SOLVE_BASE *solve; EOS_BASE *equation_of_state; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&store.NumOfCpu); MPI_Comm_rank(MPI_COMM_WORLD,&store.id); // MPI::Init ( argc, argv ); // // store.id = MPI::COMM_WORLD.Get_rank ( ); // // store.NumOfCpu = MPI::COMM_WORLD.Get_size ( ); istringstream line; if (argv[1][1] == 'i') { string input(argv[2]); store.PN = 1; store.PM = 1; store.PL = 1; store.Initialization(input); } else { if (argv[2][0] == '3') { //store.PN = argv[4][0] - 48; //store.PM = argv[5][0] - 48; //store.PL = argv[6][0] - 48; string input = argv[4]; line.clear(); line.str(input); line>>store.PN; line.clear(); input = argv[5]; line.clear(); line.str(input); line>>store.PM; line.clear(); store.PL = argv[6][0] - 48; input=argv[8]; store.Initialization(input); } else if (argv[2][0] == '2')
/** * nvolatToFactoryDefaults * * Write default config values in non-volatile memory */ void SWAP::nvolatToFactoryDefaults(void) { STORAGE nvMem; // Signature uint8_t signature[] = {NVOLAT_SIGNATURE_HIGH, NVOLAT_SIGNATURE_LOW}; nvMem.write(signature, DEFAULT_NVOLAT_SECTION, NVOLAT_SIGNATURE, sizeof(signature)); // Frequency channel uint8_t channel[] = {CCDEF_CHANNR}; nvMem.write(channel, DEFAULT_NVOLAT_SECTION, NVOLAT_FREQ_CHANNEL, sizeof(channel)); // Sync word uint8_t syncW[] = {CCDEF_SYNC1, CCDEF_SYNC0}; nvMem.write(syncW, DEFAULT_NVOLAT_SECTION, NVOLAT_SYNC_WORD, sizeof(syncW)); // SWAP address (pseudo-random number) uint16_t random = panstamp.GET_RANDOM(); uint8_t addr[] = {(random >> 8) & 0xFF, random & 0xFF}; nvMem.write(addr, DEFAULT_NVOLAT_SECTION, NVOLAT_DEVICE_ADDR, sizeof(addr)); // TX interval uint8_t txInt[] = {0xFF, 0}; nvMem.write(txInt, DEFAULT_NVOLAT_SECTION, NVOLAT_TX_INTERVAL, sizeof(txInt)); }
uint8_t Encoder<POT,STORAGE, LOG>::loadSettings(STORAGE& storage, int addr) { uint8_t rvalue = true; // load settings from EEPROM if( 179 == storage.read(addr) ) { // Okay, we've written here before, w00t! addr++; JTIncrementalEncoder::loadSettings(storage, this->state.channels.a, addr); JTIncrementalEncoder::loadSettings(storage, this->state.channels.b, addr); } else { rvalue = false; } return rvalue; }
//----------------------------------------------------------------- //! //! \brief get value at i //! //! Return the value of element i. This method //! performs index checking. //! \throws index_error if i exceeds array size //! \param i linear index of element //! \return value at i //! value_type at(size_t i) const { try { return _data.at(i); } catch(std::out_of_range &) { std::stringstream ss; ss<<"Index "<<i<<" is out of range ("<<size()<<")!"; throw index_error(EXCEPTION_RECORD,ss.str()); } }
/** * init * * Initialize SWAP registers and stack */ void SWAP::init(void) { uint8_t i; STORAGE nvMem; // Read signature from info/eeprom memory uint8_t signature[2]; nvMem.read(signature, DEFAULT_NVOLAT_SECTION, NVOLAT_SIGNATURE, sizeof(signature)); // Correct signature in non-volatile memory? if ((signature[0] != NVOLAT_SIGNATURE_HIGH) || (signature[1] != NVOLAT_SIGNATURE_LOW)) nvolatToFactoryDefaults(); // Copy default settings in non-volatile memory // Intialize registers for(i=0 ; i<regTableSize ; i++) regTable[i]->init(); // Config radio settings panstamp.radio.devAddress = devAddress & 0xFF; panstamp.radio.setCCregs(); // Attach RF ISR panstamp.attachInterrupt(pacKetReceived); }
//----------------------------------------------------------------- //! //! \brief return const reverse iterator to 0-1 element //! const_reverse_iterator rend() const { return _data.rend(); }
static inline void eepromWriteInt(STORAGE& storage, int addr, int value) { uint8_t low = lowByte(value); uint8_t high = highByte(value); storage.write(addr++, low); storage.write(addr, high); }
//----------------------------------------------------------------- //! //! \brief return reverse iterator to last element //! reverse_iterator rbegin() { return _data.rbegin(); }
//----------------------------------------------------------------- //! //! \brief return const reverse iterator to last element //! const_reverse_iterator rbegin() const { return _data.rbegin(); }
//----------------------------------------------------------------- //! //! \brief const-iterator to first element //! //! Returns a const-iterator to the first element in the array. //! \return iterator to first element //! const_iterator begin() const { return _data.begin(); }
//----------------------------------------------------------------- //! //! \brief const-iterator to last element //! //! Returns a const-iterator to the last element in the array. //! //! \return iterator to last element //! const_iterator end() const { return _data.end(); }
//----------------------------------------------------------------- //! //! \brief iterator to first element //! //! Returns a non-const iterator to the first element in the array. //! \return iterator to first element //! iterator begin() { return _data.begin(); }
//----------------------------------------------------------------- //! //! \brief return const pointer //! //! Return a const pointer to the data stored in the array. //! //! \return pointer to data //! const value_type *data() const { return _data.data(); }
//----------------------------------------------------------------- //! //! \brief reference to last element //! //! Return a reference to the last element in the linear view of //! the array. //! //! \return reference to last element //! value_type &back() { return _data.back(); }
//----------------------------------------------------------------- //! //! \brief value of last element //! //! Return the value of the last element in the linear view of //! the array. //! //! \return value of last element //! value_type back() const { return _data.back(); }
explicit mdarray(const array_view<ATYPE> &view): _imap(map_utils<map_type>::create(view.template shape<shape_t>())), _data(container_utils<storage_type>::create(view.size())) { std::copy(view.begin(),view.end(),_data.begin()); }
//----------------------------------------------------------------- //! //! \brief reference to first element //! //! Return a reference to the first element in the linear view of //! the array. //! //! \return reference to first element //! value_type &front() { return _data.front(); }
//----------------------------------------------------------------- //! //! \brief return pointer //! //! Return a pointer to the data stored in the array. //! //! \return pointer to data //! value_type *data() { return _data.data(); }
static inline int eepromReadInt(STORAGE& storage, int addr) { uint8_t low = storage.read(addr++); uint8_t high = storage.read(addr); return word(high, low); }
//----------------------------------------------------------------- //! //! \brief iterator to last element //! //! Returns a non-const iterator to the last element in the array. //! //! \return iterator to last element //! iterator end() { return _data.end(); }
//----------------------------------------------------------------- //! //! \brief value of first element //! //! Return the value of the first element in the linear view of //! the array. //! //! \return value of the first element //! value_type front() const { return _data.front(); }
//----------------------------------------------------------------- //! //! \brief get size of array //! //! Returns the total number of elements stored in the array. //! \return total number of elements //! size_t size() const { return _data.size(); }