bool read_registers_uint16_le(uint8_t addr, uint8_t reg, uint16_t* data, uint8_t size) { QASSERT(s_is_initialized); QASSERT(s_is_locked); QASSERT(data && size > 0); if (!data || size == 0) { return 0; } uint8_t* data_ptr8 = reinterpret_cast<uint8_t*>(data) + 1; //the data_ptr8 will advance like this //1, 0, 3, 2, 5, 4, 7, 6, 9, 8 if (!_start()) goto error; if (!_send_address(SLA_W(addr))) goto error; if (!_send_byte(reg)) goto error; if (!_start()) goto error; if (!_send_address(SLA_R(addr))) goto error; { uint8_t i = size - 1; while (i > 0) { if (!_receive_byte_ack()) goto error; *data_ptr8 = TWDR; data_ptr8 -= 1; if (!_receive_byte_ack()) goto error; *data_ptr8 = TWDR; data_ptr8 += 3; --i; } } //last bytes { if (!_receive_byte_ack()) goto error; *data_ptr8 = TWDR; data_ptr8 -= 1; if (!_receive_byte()) goto error; *data_ptr8 = TWDR; //data_ptr8 += 3; } if (!_stop()) goto error; return true; error: s_lockup_count++; return false; }
bool read_registers(uint8_t addr, uint8_t reg, uint8_t* data, uint8_t size) { QASSERT(s_is_initialized); QASSERT(s_is_locked); QASSERT(size > 0); if (size == 0) { return 0; } if (!_start()) goto error; if (!_send_address(SLA_W(addr))) goto error; if (!_send_byte(reg)) goto error; if (!_start()) goto error; if (!_send_address(SLA_R(addr))) goto error; if (data) { uint8_t i = size - 1; while (i > 0) { if (!_receive_byte_ack()) goto error; *data++ = TWDR; --i; } //last item { if (!_receive_byte()) goto error; *data = TWDR; } } else { uint8_t i = size - 1; while (i > 0) { if (!_receive_byte_ack()) goto error; s_i2c_null_sink = TWDR; --i; } //last item { if (!_receive_byte()) goto error; s_i2c_null_sink = TWDR; } } if (!_stop()) goto error; return true; error: s_lockup_count++; return false; }
int i2c_write_regs(i2c_t dev, uint8_t address, uint8_t reg, const void *data, int length) { I2C_TypeDef *i2c; switch (dev) { #if I2C_0_EN case I2C_0: i2c = I2C_0_DEV; break; #endif #if I2C_1_EN case I2C_1: i2c = I2C_1_DEV; break; #endif default: return -1; } /* start transmission and send slave address */ _start(i2c, address, I2C_FLAG_WRITE); _clear_addr(i2c); /* send register address and wait for complete transfer to be finished*/ _write(i2c, ®, 1); /* write data to register */ _write(i2c, data, length); /* finish transfer */ _stop(i2c); /* return number of bytes send */ return length; }
int i2c_read_bytes(i2c_t dev, uint8_t address, void *data, int length) { assert(length > 0); if (!(dev < I2C_NUMOF)) { return -1; } uint8_t *my_data = data; /* send start condition and slave address */ if (_start(address, I2C_FLAG_READ) != 0) { return 0; } for (int i = 0; i < length; i++) { /* Send NACK for last received byte */ if ((length - i) == 1) { TWCR = (1 << TWEN) | (1 << TWINT); } else { TWCR = (1 << TWEA) | (1 << TWEN) | (1 << TWINT); } DEBUG("Wait for byte %i\n", i+1); /* Wait for TWINT Flag set. This indicates that DATA has been received.*/ while (!(TWCR & (1 << TWINT))) {} /* receive data byte */ my_data[i] = TWDR; DEBUG("Byte %i received\n", i+1); } /* end transmission */ _stop(); return length; }
bool DepthCamera::start() { if (isRunning()) { logger(LOG_ERROR) << "DepthCamera: Camera is already running. Please stop it before calling start() again." << std::endl; return false; } wait(); if (_captureThread && _captureThread->joinable()) { logger(LOG_ERROR) << "DepthCamera: Camera is still running. Please wait for the current capture loop to complete before calling start() again." << std::endl; return false; } if(!_callBackTypesRegistered) { logger(LOG_ERROR) << "DepthCamera: Please register a callback to " << _id << " before starting capture" << std::endl; return false; } resetFilters(); if(!_start()) return false; _running = true; _isPaused = false; //_captureThreadWrapper(); _captureThread = ThreadPtr(new Thread(&DepthCamera::_captureThreadWrapper, this)); return true; }
void IntersectionPointsAlongLine::execute() { std::vector<Elem *> intersected_elems; std::vector<LineSegment> segments; std::unique_ptr<PointLocatorBase> pl = _fe_problem.mesh().getPointLocator(); Moose::elementsIntersectedByLine(_start, _end, _fe_problem.mesh(), *pl, intersected_elems, segments); const unsigned int num_elems = intersected_elems.size(); // Quick return in case no elements were found if (num_elems == 0) return; for (unsigned int i = 0; i < LIBMESH_DIM; i++) _intersections[i]->resize(num_elems+1); // Add the beginning point for (unsigned int i = 0; i < LIBMESH_DIM; i++) (*_intersections[i])[0] = _start(i); // Add the ending point of every segment for (unsigned int i = 0; i < num_elems; i++) { LineSegment & segment = segments[i]; const Point & end_point = segment.end(); for (unsigned int j = 0; j < LIBMESH_DIM; j++) (*_intersections[j])[i+1] = end_point(j); } }
int i2c_read_bytes(i2c_t dev, uint16_t addr, void *data, size_t len, uint8_t flags) { int ret; assert(dev < I2C_NUMOF); /* Check for unsupported operations */ if (flags & I2C_ADDR10) { return -EOPNOTSUPP; } /* Check for wrong arguments given */ if (data == NULL || len == 0) { return -EINVAL; } if (!(flags & I2C_NOSTART)) { /* start transmission and send slave address */ ret = _start(bus(dev), (addr << 1) | I2C_READ); if (ret < 0) { DEBUG("Start command failed\n"); return ret; } } /* read data to register and issue stop if needed */ ret = _read(bus(dev), data, len, (flags & I2C_NOSTOP) ? 0 : 1); if (ret < 0) { DEBUG("Read command failed\n"); return ret; } /* Ensure all bytes has been read */ while ((bus(dev)->STATUS.reg & SERCOM_I2CM_STATUS_BUSSTATE_Msk) != BUSSTATE_IDLE) {} /* return number of bytes sent */ return 0; }
void Tween::complete(timeMS deltaTime) { if (_loops == -1) return; //if already done if (_status >= status_done) return; OX_ASSERT(_client); //OX_ASSERT(!"not implemented"); //not started yet because has delay if (_status == status_delayed) { _start(*_client); _status = status_started; } OX_ASSERT(_status == status_started); //while (_status != status_remove) { UpdateState us; us.dt = deltaTime; update(*_client, us); } OX_ASSERT(_status == status_done); //_client->removeTween(this); }
//***************************************************************************** // //! \brief This is the code that gets called when the processor first //! starts execution following a reset event. Only the absolutely //! necessary set is performed, after which the application //! supplied main() routine is called. //! \param None //! \retval None //! //***************************************************************************** void Default_Reset_Handler(void) { /* Initialize data and bss */ unsigned long *pulSrc, *pulDest; /* Copy the data segment initializers from flash to SRAM */ pulSrc = &_sidata; for(pulDest = &_sdata; pulDest < &_edata; ) { *(pulDest++) = *(pulSrc++); } /* Zero fill the bss segment. */ for(pulDest = &_sbss; pulDest < &_ebss; ) { *(pulDest++) = 0; } /* Setup the microcontroller system. */ SystemInit(); /* Call the application's entry point.*/ _start(); }
bool Journal::PlayNext() { if (_State == PlayState) { _start(); Id id; mFile->read(&id); Functor* jrn = _create(id); AssertFatal(jrn,"Journal: Undefined function found in journal"); jrn->read(mFile); _finish(); _Dispatching = true; jrn->dispatch(); _Dispatching = false; delete jrn; if (_Count) return true; Stop(); //debugBreak(); } return false; }
void __attribute__ ((naked)) Reset_Handler( void ) { register uint32_t *pSrc, *pDest; // Initialize the relocate segment pSrc = &_etext; pDest = &_srelocate; if (pSrc != pDest) { for (; pDest < &_erelocate;) { *pDest++ = *pSrc++; } } // Set the vector table base address pSrc = (uint32_t *) & _sfixed; SCB->VTOR = ((uint32_t) pSrc & SCB_VTOR_TBLOFF_Msk); // Branch to the start function in the library. If it is not // there, we use the _alt_start function in this module. // _start(); }
int scheduler_start(lua_State *L) { luaL_checktype(L,1,LUA_TTABLE); hive_createenv(L); struct global_queue * gmq = lua_newuserdata(L, sizeof(*gmq)); globalmq_init(gmq); lua_pushvalue(L,-1); hive_setenv(L, "message_queue"); lua_State *sL; sL = scheduler_newtask(L); luaL_requiref(sL, "cell.system", cell_system_lib, 0); lua_pop(sL,1); struct cell * sys = cell_new(sL, "system.lua"); if (sys == NULL) { return 0; } scheduler_starttask(sL); lua_getfield(L,1, "thread"); int thread = luaL_optinteger(L, -1, DEFAULT_THREAD); lua_pop(L,1); struct timer * t = lua_newuserdata(L, sizeof(*t)); timer_init(t,sys,gmq); _start(gmq,thread,t); cell_close(sys); return 0; }
int i2c_read_regs(i2c_t dev, uint8_t address, uint8_t reg, void *data, int length) { I2C_TypeDef *i2c; switch (dev) { #if I2C_0_EN case I2C_0: i2c = I2C_0_DEV; break; #endif #if I2C_1_EN case I2C_1: i2c = I2C_1_DEV; break; #endif default: return -1; } /* send start condition and slave address */ DEBUG("Send slave address and clear ADDR flag\n"); _start(i2c, address, I2C_FLAG_WRITE); _clear_addr(i2c); DEBUG("Write reg into DR\n"); i2c->DR = reg; _stop(i2c); DEBUG("Now start a read transaction\n"); return i2c_read_bytes(dev, address, data, length); }
int i2c_write_bytes(i2c_t dev, uint16_t addr, const void *data, size_t len, uint8_t flags) { int ret; assert(dev < I2C_NUMOF); /* Check for unsupported operations */ if (flags & I2C_ADDR10) { return -EOPNOTSUPP; } /* Check for wrong arguments given */ if (data == NULL || len == 0) { return -EINVAL; } if (!(flags & I2C_NOSTART)) { ret = _start(bus(dev), (addr<<1)); if (ret < 0) { DEBUG("Start command failed\n"); return ret; } } ret = _write(bus(dev), data, len, (flags & I2C_NOSTOP) ? 0 : 1); if (ret < 0) { DEBUG("Write command failed\n"); return ret; } return 0; }
int i2c_write_bytes(i2c_t dev, uint8_t address, const void *data, int length) { I2C_TypeDef *i2c; switch (dev) { #if I2C_0_EN case I2C_0: i2c = I2C_0_DEV; break; #endif #if I2C_1_EN case I2C_1: i2c = I2C_1_DEV; break; #endif default: return -1; } /* start transmission and send slave address */ DEBUG("sending start sequence\n"); _start(i2c, address, I2C_FLAG_WRITE); _clear_addr(i2c); /* send out data bytes */ _write(i2c, data, length); /* end transmission */ DEBUG("Ending transmission\n"); _stop(i2c); DEBUG("STOP condition was send out\n"); return length; }
void die ( /* Stop with dying message */ FRESULT rc /* FatFs return value */ ) { printf("Failed with rc=%u.\n", rc); _start(); while(1); }
const CByteArray &IISCPacketCreator::kick() { _start(ISCC_KICK); _finish(); return ms_packet; }
static gboolean _load_queue (LogQueueDisk *s, const gchar *filename) { /* qdisk portion is not yet started when this happens */ g_assert(!qdisk_initialized (s->qdisk)); return _start(s, filename); }
bool Apsis::Backend::Sdl::_initialize() { if (_start()) { return true; } fprintf(stderr, "SDL backend cannot initialize."); return false; }
bool Streamer::start() { if(!isInitialized() || !_start()) return false; _currentID = 0; return _isRunning = true; }
void Tween::update(Actor& actor, const UpdateState& us) { _elapsed += us.dt; switch (_status) { case status_delayed: { if (_elapsed >= _delay) { _status = status_started; _start(*_client); } } break; case status_started: { if (_duration) { timeMS localElapsed = _elapsed - _delay; if (_globalEase != ease_linear) { float p = localElapsed / float(_duration * _loops); timeMS nv = static_cast<timeMS>(calcEase(_globalEase, std::min(p, 1.0f)) * _duration * _loops); localElapsed = nv; } int loopsDone = localElapsed / _duration; _percent = _calcEase(((float)(localElapsed - loopsDone * _duration)) / _duration); while(_loopsDone < loopsDone) { _loopDone(actor, us); _loopsDone++; } if (_loops > 0 && int(loopsDone) >= _loops) { if (_twoSides) _percent = 0; else _percent = 1; _status = status_done; } } _update(*_client, us); } break; case status_done: { done(*_client, us); } break; } }
const CByteArray &IISCPacketCreator::logout(ID _sid) { _start(ISCC_LOGOUT); ms_packet.addInt(_sid); _finish(); return ms_packet; }
void init_fan_rpm(void) /***************************************************************************** * Function : See module specification (.h-file). *****************************************************************************/ { fan_port_setup(); fan_int_setup(); disable_fan_rpm_int(); _start(FAN_RPM_TASK, MILLI_SEC(0)); }
void Tween::start(Actor& actor) { _client = &actor; _status = status_delayed; if (_delay == 0) { _status = status_started; _start(actor); } }
// // startList() // void XHTMLR::startList(const std::string &key){ _indent(); _start(key); _setAsListContainer(); _ss << "<" << _startListTag << " class=\"" << key << "\">" << std::endl; }
const CByteArray &IISCPacketCreator::authAnswer(ID _sid, E_AUTH_ANSWER _answer) { _start(ISCC_AUTH_ANSWER); ms_packet.addInt(_sid); ms_packet.addInt(_answer); _finish(); return ms_packet; }
/** * \brief This is the code that gets called on processor reset. */ void Reset_Handler(void) { /* Disable register write-protection function */ SYS_UnlockReg(); /* Disable Power-on Reset function */ SYS_DISABLE_POR(); /* HXT Crystal Type Select: INV */ CLK->PWRCTL &= ~CLK_PWRCTL_HXTSELTYP_Msk; /** * NOTE 1: Unlock is required for perhaps some register access in SystemInit(). * NOTE 2: Because EBI (external SRAM) init is done in SystemInit(), SystemInit() must be called at the very start. */ SystemInit(); /* Enable register write-protection function */ SYS_LockReg(); #if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) __main(); #elif defined(__ICCARM__) __iar_program_start(); #elif defined(__GNUC__) uint32_t *src_ind = (uint32_t *) &__etext; uint32_t *dst_ind = (uint32_t *) &__data_start__; uint32_t *dst_end = (uint32_t *) &__data_end__; /* Move .data section from ROM to RAM */ if (src_ind != dst_ind) { for (; dst_ind < dst_end;) { *dst_ind ++ = *src_ind ++; } } /* Initialize .bss section to zero */ dst_ind = (uint32_t *) &__bss_start__; dst_end = (uint32_t *) &__bss_end__; if (dst_ind != dst_end) { for (; dst_ind < dst_end;) { *dst_ind ++ = 0; } } _start(); #endif /* Infinite loop */ while (1); }
void PmTimer::start(int minimumInterval, int maximumInterval) { IFDEBUG(qDebug("%s PmTimerUShort::start() called with %d/%d", qPrintable(QDateTime::currentDateTime().toString()), minimumInterval, maximumInterval)); if (_timer.isActive()) { IFDEBUG(qDebug("PmTimerUShort::start() was active, stopping")); _timer.stop(); } _minimumInterval = minimumInterval; _maximumInterval = maximumInterval; _start(minimumInterval, maximumInterval); }
const CByteArray &IISCPacketCreator::channelInfos(s32 _currplayers, s32 _maxplayers) { _start(ISCC_CHANNEL_INFOS); ms_packet.addInt(_currplayers); ms_packet.addInt(_maxplayers); _finish(); return ms_packet; }
static PyObject* _resume(PyObject *self, PyObject *args) { if (paused) { paused = 0; if (!_start()) // error return NULL; } Py_RETURN_NONE; }