// `$INSTANCE_NAME`_UpdateLeds - This function writes to the row and column PINs with the // current row/column values. Notice that the columns are active low. It then goes // onto the next row inline static void `$INSTANCE_NAME`_UpdateLeds() { static int currentRow = 0; `$RowComponent`_Write(1<<currentRow); // turn on the current row `$ColComponent`_Write(~`$INSTANCE_NAME`_ledRows[currentRow]); // the columns are active LOW currentRow = (currentRow + 1) % `$INSTANCE_NAME`_NUMROWS ; // wrap around at the end }
status_t Header::Write(int fd) { // Try to write the protective MBR PartitionMap partitionMap; PrimaryPartition *partition = NULL; uint32 index = 0; while ((partition = partitionMap.PrimaryPartitionAt(index)) != NULL) { if (index == 0) { uint64 deviceSize = fHeader.AlternateBlock() * fBlockSize; partition->SetTo(fBlockSize, deviceSize, 0xEE, false, fBlockSize); } else partition->Unset(); ++index; } PartitionMapWriter writer(fd, fBlockSize); writer.WriteMBR(&partitionMap, true); // We also write the bootcode, so we can boot GPT disks from BIOS status_t status = _Write(fd, fHeader.EntriesBlock() * fBlockSize, fEntries, _EntryArraySize()); if (status != B_OK) return status; // First write the header, so that we have at least one completely correct // data set status = _WriteHeader(fd); // Write backup entries status_t backupStatus = _Write(fd, fBackupHeader.EntriesBlock() * fBlockSize, fEntries, _EntryArraySize()); return status == B_OK ? backupStatus : status; }
status_t Header::_WriteHeader(int fd) { _UpdateCRC(); status_t status = _Write(fd, fHeader.AbsoluteBlock() * fBlockSize, &fHeader, sizeof(efi_table_header)); if (status != B_OK) return status; return _Write(fd, fBackupHeader.AbsoluteBlock() * fBlockSize, &fBackupHeader, sizeof(efi_table_header)); }
int DBObjData::Write (FILE *file) { RecalcExtent (); if (DBDataHeader::Write (file) == DBFault) return (DBFault); return (_Write (file)); }
/********************************************************************* * * I2C_Write * * Function description * Writes to a device on I2C. */ U8 I2C_Write(U32 I2CBaseAddr, U8 Addr, U8 * pData, U16 NumBytesToWrite) { U8 r; SET_BASE_ADDR(I2CBaseAddr); r = _Write(Addr << 1, pData, NumBytesToWrite, 0); return r; }
int fwt_write(int fd, const void *buffer, long nbytes) { if (!current_write_ignored) { return _Write(fd, buffer, nbytes); } fwt_bytes_written += nbytes; return (int)nbytes; // "everything's written" }
nOS_Error nOS_QueueRead (nOS_Queue *queue, void *block, nOS_TickCounter timeout) { nOS_Error err; nOS_StatusReg sr; nOS_Thread *thread; #if (NOS_CONFIG_SAFE > 0) if (queue == NULL) { err = NOS_E_INV_OBJ; } else if (block == NULL) { err = NOS_E_NULL; } else #endif { nOS_EnterCritical(sr); #if (NOS_CONFIG_SAFE > 0) if (queue->e.type != NOS_EVENT_QUEUE) { err = NOS_E_INV_OBJ; } else #endif { /* No chance a thread waiting to read from queue if count is higher than 0 */ if (queue->bcount > 0) { _Read(queue, block); /* Check if thread waiting to write in queue */ thread = nOS_SendEvent((nOS_Event*)queue, NOS_OK); if (thread != NULL) { /* Write thread's block in queue */ _Write(queue, thread->ext); #if (NOS_CONFIG_HIGHEST_THREAD_PRIO > 0) && (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0) if ((thread->state == NOS_THREAD_READY) && (thread->prio > nOS_runningThread->prio)) { nOS_Schedule(); } #endif } err = NOS_OK; } else if (timeout == NOS_NO_WAIT) { err = NOS_E_EMPTY; } else if (nOS_isrNestingCounter > 0) { err = NOS_E_ISR; } #if (NOS_CONFIG_SCHED_LOCK_ENABLE > 0) else if (nOS_lockNestingCounter > 0) { err = NOS_E_LOCKED; } #endif else if (nOS_runningThread == &nOS_idleHandle) { err = NOS_E_IDLE; } else { nOS_runningThread->ext = block; err = nOS_WaitForEvent((nOS_Event*)queue, NOS_THREAD_READING_QUEUE, timeout); } } nOS_LeaveCritical(sr); } return err; }
status_t Header::Write(int fd) { status_t status = _Write(fd, fHeader.EntriesBlock() * fBlockSize, fEntries, _EntryArraySize()); if (status != B_OK) return status; // First write the header, so that we have at least one completely correct // data set status = _WriteHeader(fd); // Write backup entries status_t backupStatus = _Write(fd, fBackupHeader.EntriesBlock() * fBlockSize, fEntries, _EntryArraySize()); return status == B_OK ? backupStatus : status; }
/********************************************************************* * * I2C_WriteRead * * Function description: * Writes and reads from a device on I2C. */ U8 I2C_WriteRead(U32 I2CBaseAddr, U8 Addr, U8 * pData, U16 NumBytesToWrite, U8 * pBuf, U16 NumBytesToRead) { U8 r; SET_BASE_ADDR(I2CBaseAddr); r = _Write(Addr << 1, pData, NumBytesToWrite, 1); if (r == I2C_CODE_OK) { r = _Read(Addr << 1, pBuf, NumBytesToRead, 1); } return r; }
nOS_Error nOS_QueueRead (nOS_Queue *queue, void *block, nOS_TickCounter timeout) { nOS_Error err; nOS_StatusReg sr; nOS_Thread *thread; #if (NOS_CONFIG_SAFE > 0) if (queue == NULL) { err = NOS_E_INV_OBJ; } else if (block == NULL) { err = NOS_E_NULL; } else #endif { nOS_EnterCritical(sr); #if (NOS_CONFIG_SAFE > 0) if (queue->e.type != NOS_EVENT_QUEUE) { err = NOS_E_INV_OBJ; } else #endif /* No chance a thread waiting to read from queue if count is higher than 0 */ if (queue->bcount > 0) { _Read(queue, block); /* Check if thread waiting to write in queue */ thread = nOS_SendEvent((nOS_Event*)queue, NOS_OK); if (thread != NULL) { /* Write thread's block in queue */ _Write(queue, thread->ext); #if (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0) /* Verify if a highest prio thread is ready to run */ nOS_Schedule(); #endif } err = NOS_OK; } else if (timeout == NOS_NO_WAIT) { err = NOS_E_EMPTY; } else { nOS_runningThread->ext = block; err = nOS_WaitForEvent((nOS_Event*)queue, NOS_THREAD_READING_QUEUE #if (NOS_CONFIG_WAITING_TIMEOUT_ENABLE > 0) ,timeout #elif (NOS_CONFIG_SLEEP_ENABLE > 0) || (NOS_CONFIG_SLEEP_UNTIL_ENABLE > 0) ,NOS_WAIT_INFINITE #endif ); } nOS_LeaveCritical(sr); } return err; }
void INetPacket::WritePacket(const INetPacket& r) { uint32 opcode = r.GetOpcode(); NetPacketHeader Header; Header.size = _BITSWAP32((uint32)( r.Size() + PACKET_HEADER_SIZE ) ); Header.cmd = _BITSWAP32(opcode); _Write((uint8*)&Header, PACKET_HEADER_SIZE); size_t size = r.GetRemainSize(); Append(r.GetReadBuffer(), size); };
/********************************************************************* * * USBHID_Write * * Function description * Writes an output report to device. * * Return value: * On Error: -1, No valid device Id used or the report size does not match with device. * On success: Number of bytes that have be written. * */ int USBHID_Write(unsigned Id, const void * pBuffer, unsigned NumBytes) { CONN_INFO * pConnInfo; pConnInfo = _apConnInfo[Id]; if (pConnInfo == NULL) { return -1; // Error device Id does not exist. } if (NumBytes != (pConnInfo->InputReportByteLength - 1)) { return -1; // Error report size does not match } return _Write(pConnInfo, pBuffer, NumBytes); }
status_t Header::WriteEntry(int fd, uint32 entryIndex) { off_t entryOffset = entryIndex * fHeader.EntrySize(); status_t status = _Write(fd, fHeader.EntriesBlock() * fBlockSize + entryOffset, fEntries + entryOffset, fHeader.EntrySize()); if (status != B_OK) return status; // Update header, too -- the entries CRC changed status = _WriteHeader(fd); // Write backup status_t backupStatus = _Write(fd, fBackupHeader.EntriesBlock() * fBlockSize + entryOffset, fEntries + entryOffset, fHeader.EntrySize()); return status == B_OK ? backupStatus : status; }
status_t Header::WriteEntry(int fd, uint32 entryIndex) { // Determine block to write off_t blockOffset = + entryIndex * fHeader.EntrySize() / fBlockSize; uint32 entryOffset = entryIndex * fHeader.EntrySize() % fBlockSize; status_t status = _Write(fd, (fHeader.EntriesBlock() + blockOffset) * fBlockSize, fEntries + entryOffset, fBlockSize); if (status != B_OK) return status; // Update header, too -- the entries CRC changed status = _WriteHeader(fd); // Write backup status_t backupStatus = _Write(fd, (fBackupHeader.EntriesBlock() + blockOffset) * fBlockSize, fEntries + entryOffset, fBlockSize); return status == B_OK ? backupStatus : status; }
int write (int fd, void *buffer, long nbytes) { return _Write(fd, buffer, nbytes); }
nOS_Error nOS_QueueWrite (nOS_Queue *queue, void *block, nOS_TickCounter timeout) { nOS_Error err; nOS_StatusReg sr; nOS_Thread *thread; #if (NOS_CONFIG_SAFE > 0) if (queue == NULL) { err = NOS_E_INV_OBJ; } else if (block == NULL) { err = NOS_E_NULL; } else #endif { nOS_EnterCritical(sr); #if (NOS_CONFIG_SAFE > 0) if (queue->e.type != NOS_EVENT_QUEUE) { err = NOS_E_INV_OBJ; } else #endif { /* If count equal 0, there are chances some threads can wait to read from queue */ if (queue->bcount == 0) { /* Check if thread waiting to read from queue */ thread = nOS_SendEvent((nOS_Event*)queue, NOS_OK); if (thread != NULL) { /* Direct copy between thread's buffers */ memcpy(thread->ext, block, queue->bsize); #if (NOS_CONFIG_HIGHEST_THREAD_PRIO > 0) && (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0) if ((thread->state == NOS_THREAD_READY) && (thread->prio > nOS_runningThread->prio)) { nOS_Schedule(); } #endif err = NOS_OK; } else if (queue->buffer != NULL) { /* No thread waiting to read from queue, then store it */ _Write(queue, block); err = NOS_OK; } else { /* No thread waiting to consume message, inform producer */ err = NOS_E_NO_CONSUMER; } } else if (queue->bcount < queue->bmax) { /* No chance a thread waiting to read from queue if count is higher than 0 */ _Write(queue, block); err = NOS_OK; } else if (timeout == NOS_NO_WAIT) { err = NOS_E_FULL; } else if (nOS_isrNestingCounter > 0) { err = NOS_E_ISR; } #if (NOS_CONFIG_SCHED_LOCK_ENABLE > 0) else if (nOS_lockNestingCounter > 0) { err = NOS_E_LOCKED; } #endif else if (nOS_runningThread == &nOS_idleHandle) { /* Main threadv can't wait. */ err = NOS_E_IDLE; } else { nOS_runningThread->ext = block; err = nOS_WaitForEvent((nOS_Event*)queue, NOS_THREAD_WRITING_QUEUE, timeout); } } nOS_LeaveCritical(sr); } return err; }
nOS_Error nOS_QueueWrite (nOS_Queue *queue, void *block, nOS_TickCounter timeout) { nOS_Error err; nOS_StatusReg sr; nOS_Thread *thread; #if (NOS_CONFIG_SAFE > 0) if (queue == NULL) { err = NOS_E_INV_OBJ; } else if (block == NULL) { err = NOS_E_NULL; } else #endif { nOS_EnterCritical(sr); #if (NOS_CONFIG_SAFE > 0) if (queue->e.type != NOS_EVENT_QUEUE) { err = NOS_E_INV_OBJ; } else #endif /* If count equal 0, there are chances some threads can wait to read from queue */ if (queue->bcount == 0) { /* Check if thread waiting to read from queue */ thread = nOS_SendEvent((nOS_Event*)queue, NOS_OK); if (thread != NULL) { /* Direct copy between thread's buffers */ memcpy(thread->ext, block, queue->bsize); #if (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0) /* Verify if a highest prio thread is ready to run */ nOS_Schedule(); #endif err = NOS_OK; } else if (queue->buffer != NULL) { /* No thread waiting to read from queue, then store it */ _Write(queue, block); err = NOS_OK; } else { /* No thread waiting to consume message, inform producer */ err = NOS_E_NO_CONSUMER; } } else if (queue->bcount < queue->bmax) { /* No chance a thread waiting to read from queue if count is higher than 0 */ _Write(queue, block); err = NOS_OK; } else if (timeout == NOS_NO_WAIT) { err = NOS_E_FULL; } else { nOS_runningThread->ext = block; err = nOS_WaitForEvent((nOS_Event*)queue, NOS_THREAD_WRITING_QUEUE #if (NOS_CONFIG_WAITING_TIMEOUT_ENABLE > 0) ,timeout #elif (NOS_CONFIG_SLEEP_ENABLE > 0) || (NOS_CONFIG_SLEEP_UNTIL_ENABLE > 0) ,NOS_WAIT_INFINITE #endif ); } nOS_LeaveCritical(sr); } return err; }
int I2C::Write( uint8_t reg, void* buf, uint32_t len ) { return _Write( mAddr, reg, buf, len ); }
size_t GPFileWStream::vWrite(const void* buffer, size_t size) { return _Write(mF, buffer, size); }