/**************************************************************************** Function ES_DeQueue Parameters unsigned char * pBlock : pointer to the block of memory in use as the Queue ES_Event * pReturnEvent : used to return the event pulled from the queue Returns The number of entries remaining in the Queue Description pulls next available entry from Queue, EF_NO_EVENT if Queue was empty and copies it to *pReturnEvent. Notes Author J. Edward Carryer, 08/09/11, 19:11 ****************************************************************************/ uint8_t ES_DeQueue( ES_Event * pBlock, ES_Event * pReturnEvent ) { pQueue_t pThisQueue; uint8_t NumLeft; pThisQueue = (pQueue_t)pBlock; if ( pThisQueue->NumEntries > 0) { EnterCritical(); // save interrupt state, turn ints off *pReturnEvent = pBlock[ 1 + pThisQueue->CurrentIndex ]; // inc the index pThisQueue->CurrentIndex++; // this way we only do the modulo operation when we really need to if (pThisQueue->CurrentIndex >= pThisQueue->QueueSize) pThisQueue->CurrentIndex = (uint8_t)(pThisQueue->CurrentIndex % pThisQueue->QueueSize); //dec number of elements since we took 1 out NumLeft = --pThisQueue->NumEntries; ExitCritical(); // restore saved interrupt state }else { // no items left in the queue (*pReturnEvent).EventType = ES_NO_EVENT; (*pReturnEvent).EventParam = 0; NumLeft = 0; } return NumLeft; }
void NativeSoundMix::DoPlay() { while ( true ) { // Wait for a buffer done event WaitForSingleObject(playEvent, 10*1000); EnterCritical(); if ( !hWaveOut || !playEvent ) { LeaveCritical(); return; } // If a buffer is done, fill it... int nSent = 0; for ( int i = 0; i < nBuffers; i++ ) { WAVEHDR* hdr = waveHDR+i; if ( (hdr->dwFlags & WHDR_DONE) || !(hdr->dwFlags & WHDR_PREPARED) ) { if ( buffer[i] ) { BuildAndWrite( &waveHdr[i], false ); } // SendBuffer(i); nSent++; } } if ( nSent > nBuffers-2 ) EnlargeBuffers(); if ( nSilent > nBuffers ) CloseDevice(); LeaveCritical(); } }
/* ** =================================================================== ** Method : SetCV (component FreeCntr8) ** ** Description : ** Sets compare or preload register value. The method is called ** automatically as a part of several internal methods. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ static void SetCV(word Val) { EnterCritical(); /* Disable global interrupts */ setReg(TMR0_CMPLD1,Val); /* Store given value to the compare preload 1 register */ setReg(TMR0_CMPLD2,Val); /* Store given value to the compare preload 2 register */ ExitCritical(); /* Enable global interrupts */ }
/* add an ip_addr to the table. Usually done via IPC */ int ipc_arp_add_entry(char ip_addr[4],int ifnum) { arp_entry_p e; //printf("IPC_ARP_ADD_ENTRY %s\n",pripaddr(ip_addr)); if ((e = arp_search_entry_by_ip(ip_addr)) != NULL) { /* entry is not FREE */ if (arp_entry_valid(e)) { /* the entry is valid */ if (EISPENDING(e) || EISRESOLVED(e)) return ARP_SUCCESS; if (EISTIMEOUT(e)) return ARP_TIMEDOUT; assert(0); } else { /* entry is not valid */ if (EISPENDING(e) && e->count == 0 && TICKS >= e->ticks) { arp_set_timeout(e); return ARP_SUCCESS; } /* refresh entry since it is not valid */ arp_set_pending(e,ip_addr,ifnum); return ARP_SUCCESS; } } else { /* there is no entry */ EnterCritical(); e = arp_search_free_entry(); if (e == NULL) { ExitCritical(); return ARP_RETRY; } arp_set_pending(e,ip_addr,ifnum); ExitCritical(); return ARP_SUCCESS; } }
U8 FCALC_GFD_DutyCycle_Decode(U8 frequency){ U16 local_DutyCycleCopy = 0; EnterCritical(); local_DutyCycleCopy = M_PE6_Frequency_calc_DutyCycle; ExitCritical(); switch (frequency) { case 50: return 100-local_DutyCycleCopy / 50; break; case 40: return 100-local_DutyCycleCopy / 62; break; case 30: return 100-local_DutyCycleCopy / 83; break; case 20: return 100-local_DutyCycleCopy / 125; break; case 10: return 100-local_DutyCycleCopy / 250; break; default: return 0; } }
/* ** =================================================================== ** Method : LoadTicks (component FreeCntr8) ** ** Description : ** Loads actual number of timer ticks from internal variable. The ** method is called automatically as a part of several internal ** methods. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ static void LoadTicks(void) { EnterCritical(); /* Disable global interrupts */ LTicks = TTicks; /* Loading actual number of timer ticks */ LOvf = TOvf; /* Loading actual state of "overflow flag" */ ExitCritical(); /* Enable global interrupts */ }
int route_delete(ipaddr_t net, ipaddr_t netmask) { int i,ret; route_entry_p routep; mk_ip_table_rw(); EnterCritical(); i = get_routen(net,netmask); if (i == -1) { /* not found */ fprintf(stderr,"Route not found\n"); ret = -1; } else if (i == GETNUMROUTEENTRIES - 1) { /* last route */ DECNUMROUTEENTRIES; ret = 0; } else { /* shift up all entries */ for ( ; i < GETNUMROUTEENTRIES ; i++) { routep = GETROUTEP(i); *routep = *(GETROUTEP(i + 1)); } DECNUMROUTEENTRIES; ret = 0; } ExitCritical(); mk_ip_table_ro(); return ret; }
//Returns 0 on succses. //Returns size of file if non-empty //If positive, populates mfi. //Returns -1 if can't find file or reached end of file list. int8_t MFSOpenFile( const char * fname, struct MFSFileInfo * mfi ) { if( mfs_at == 0 ) { FindMPFS(); } if( mfs_at == 0 ) { return -1; } EnterCritical(); flashchip->chip_size = 0x01000000; uint32 ptr = mfs_at; struct MFSFileEntry e; while(1) { spi_flash_read( ptr, (uint32*)&e, sizeof( e ) ); ptr += sizeof(e); if( e.name[0] == 0xff || ets_strlen( e.name ) == 0 ) break; if( ets_strcmp( e.name, fname ) == 0 ) { mfi->offset = e.start; mfi->filelen = e.len; flashchip->chip_size = 0x00080000; ExitCritical(); return 0; } } flashchip->chip_size = 0x00080000; ExitCritical(); return -1; }
unsigned TimerStartKernelTimer (TTimer *pThis, unsigned nDelay, TKernelTimerHandler *pHandler, void *pParam, void *pContext) { assert (pThis != 0); EnterCritical (); unsigned hTimer; for (hTimer = 0; hTimer < KERNEL_TIMERS; hTimer++) { if (pThis->m_KernelTimer[hTimer].m_pHandler == 0) { break; } } if (hTimer >= KERNEL_TIMERS) { LeaveCritical (); LoggerWrite (LoggerGet (), "timer", LogPanic, "System limit of kernel timers exceeded"); return 0; } assert (pHandler != 0); pThis->m_KernelTimer[hTimer].m_pHandler = pHandler; pThis->m_KernelTimer[hTimer].m_nElapsesAt = pThis->m_nTicks+nDelay; pThis->m_KernelTimer[hTimer].m_pParam = pParam; pThis->m_KernelTimer[hTimer].m_pContext = pContext; LeaveCritical (); return hTimer+1; }
/* INTERFACE MANAGEMENT */ int ifconfig(char *name, int flags, ipaddr_t ipaddr, ipaddr_t netmask, ipaddr_t broadcast) { if_entry_p ife; int ret; mk_ip_table_rw(); EnterCritical(); if ((ife = get_if_by_name(name))) { bcopy(ipaddr, ife->ipaddr, 4); bcopy(netmask, ife->netmask, 4); bcopy(broadcast, ife->broadcast, 4); apply_netmask(ife->net, ipaddr, netmask); ife->flags = flags; ret = 0; } else { fprintf(stderr,"ifconfig: Device not found: %s\n",name); ret = -1; } ExitCritical(); mk_ip_table_ro(); return ret; }
TString *TimerGetTimeString (TTimer *pThis) { assert (pThis != 0); EnterCritical (); unsigned nTime = pThis->m_nTime; unsigned nTicks = pThis->m_nTicks; LeaveCritical (); if (nTicks == 0) { return 0; } unsigned nSecond = nTime % 60; nTime /= 60; unsigned nMinute = nTime % 60; nTime /= 60; unsigned nHours = nTime; nTicks %= HZ; #if (HZ != 100) nTicks = nTicks * 100 / HZ; #endif TString *pString = malloc (sizeof (TString)); assert (pString != 0); String (pString); StringFormat (pString, "%02u:%02u:%02u.%02lu", nHours, nMinute, nSecond, nTicks); return pString; }
/* ===================================================================*/ LDD_TError SMasterLdd3_SendBlock(LDD_TDeviceData *DeviceDataPtr, LDD_TData *BufferPtr, uint16_t Size) { /* Clock configuration test - this test can be disabled by setting the "Ignore clock configuration test" property to the "yes" value in the "Configuration inspector" */ if (!((SMasterLdd3_TDeviceDataPtr)DeviceDataPtr)->EnMode) { /* Is the device disabled in the actual speed CPU mode? */ return ERR_SPEED; /* If yes then error */ } /* Device state test - this test can be disabled by setting the "Ignore enable test" property to the "yes" value in the "Configuration inspector" */ if (!((SMasterLdd3_TDeviceDataPtr)DeviceDataPtr)->EnUser) { /* Is the device disabled by user? */ return ERR_DISABLED; /* If yes then error */ } if (((SMasterLdd3_TDeviceDataPtr)DeviceDataPtr)->OutDataNumReq != 0x00U) { /* Is the previous transmit operation pending? */ return ERR_BUSY; /* If yes then error */ } /* {Default RTOS Adapter} Critical section begin, general PE function is used */ EnterCritical(); ((SMasterLdd3_TDeviceDataPtr)DeviceDataPtr)->OutDataPtr = (uint8_t*)BufferPtr; /* Set a pointer to the output data. */ ((SMasterLdd3_TDeviceDataPtr)DeviceDataPtr)->OutDataNumReq = Size; /* Set the counter of characters to be sent. */ ((SMasterLdd3_TDeviceDataPtr)DeviceDataPtr)->OutSentDataNum = 0x00U; /* Clear the counter of sent characters. */ SPI_PDD_EnableDmasInterrupts(SPI2_BASE_PTR, SPI_PDD_TX_FIFO_FILL_INT_DMA); /* Enable TX interrupt */ /* {Default RTOS Adapter} Critical section end, general PE function is used */ ExitCritical(); return ERR_OK; /* OK */ }
/** * \brief Touch Task. Starts and stops walking Task by touchsensor. * @param TouchTask Taskname * @param pvParameters Not used * @return void */ static portTASK_FUNCTION(TouchTask, pvParameters) { uint8_t errCode; uint16_t touchStatus; (void)pvParameters; TOUCH_init(); WAIT1_WaitOSms(10); for(;;) { errCode=TOUCH_getELE(&touchStatus); if(errCode != ERR_OK) { for(;;) {} /* error occurred!*/ } if(touchStatus!=0) { if (enabledWalking) { EnterCritical(); if(enabledWalking) { /* stop walking*/ enabledWalking = FALSE; } else { /* start walking*/ enabledWalking = TRUE; } ExitCritical(); } WAIT1_WaitOSms(1000); } WAIT1_WaitOSms(16); /* 16ms sampling time*/ } }
void free (void *pBlock) { assert (pBlock != 0); TBlockHeader *pBlockHeader = (TBlockHeader *) ((unsigned long) pBlock - sizeof (TBlockHeader)); assert (pBlockHeader->nMagic == BLOCK_MAGIC); for (TBlockBucket *pBucket = s_BlockBucket; pBucket->nSize > 0; pBucket++) { if (pBlockHeader->nSize == pBucket->nSize) { EnterCritical (); pBlockHeader->pNext = pBucket->pFreeList; pBucket->pFreeList = pBlockHeader; #ifdef MEM_DEBUG pBucket->nCount--; #endif LeaveCritical (); break; } } }
void *PageAlloc(void) { EnterCritical (); #ifdef MEM_DEBUG if (++s_PageBucket.nCount > s_PageBucket.nMaxCount) { s_PageBucket.nMaxCount = s_PageBucket.nCount; } #endif TFreePage *pFreePage; if ((pFreePage = s_PageBucket.pFreeList) != 0) { s_PageBucket.pFreeList = pFreePage->pNext; pFreePage->nMagic = 0; } else { pFreePage = (TFreePage *) s_pNextPage; s_pNextPage += PAGE_SIZE; if (s_pNextPage > s_pPageLimit) { LeaveCritical (); return 0; // TODO: system should panic here } } LeaveCritical (); return pFreePage; }
void CPollQProducer::Run() { unsigned short usValue = ( unsigned short ) 0; BaseType_t xError = pdFALSE, xLoop; for( ;; ) { for( xLoop = 0; xLoop < pollqVALUES_TO_PRODUCE; xLoop++ ) { /* Send an incrementing number on the queue without blocking. */ if( m_pQueue->Send((void*)&usValue, pollqNO_DELAY ) != pdPASS ) { /* We should never find the queue full so if we get here there has been an error. */ xError = pdTRUE; } else { if( xError == pdFALSE ) { /* If an error has ever been recorded we stop incrementing the check variable. */ EnterCritical(); m_nPollingCount++; ExitCritical(); } /* Update the value we are going to post next time around. */ usValue++; } } /* Wait before we start posting again to ensure the consumer runs and empties the queue. */ Delay(pollqPRODUCER_DELAY); } }
/* ===================================================================*/ LDD_TError RealTimeLdd1_GetTimeMS(LDD_TDeviceData *DeviceDataPtr, uint16_t *TimePtr) { RealTimeLdd1_TDeviceData *DeviceDataPrv = (RealTimeLdd1_TDeviceData *)DeviceDataPtr; uint32_t CopyTicks; /* Working copy of variable TimerTicks */ bool CopyOverflow; /* Working copy of variable Overflow */ LDD_RealTime_Tfloat rtval; /* Result of multiplication */ /* {Default RTOS Adapter} Critical section begin, general PE function is used */ EnterCritical(); CopyTicks = DeviceDataPrv->TimerTicks; /* Loading actual number of timer ticks */ CopyOverflow = DeviceDataPrv->Overflow; /* Loading actual state of "overflow flag" */ /* {Default RTOS Adapter} Critical section end, general PE function is used */ ExitCritical(); if (CopyOverflow) { /* Testing counter overflow */ return ERR_OVERFLOW; /* If yes then error */ } rtval = CopyTicks * 6.25F; /* Multiply ticks and clock configuration 0 coefficient */ if (rtval > 0xFFFFUL) { /* Is the result greater than 65535 ? */ return ERR_MATH; /* If yes then error */ } else { *TimePtr = (uint16_t)rtval; } return ERR_OK; }
/* ** =================================================================== ** Method : WriteWord (bean IntFLASH) ** ** Description : ** This method is internal. ** =================================================================== */ byte WriteWord(word *Address,word Data16) { byte err; word Addr=(word)Address; EnterCritical(); /* Enter critical section */ FSTAT = 48; /* Clear all flags */ if (FSTAT_CBEIF == 0) { /* Is command buffer full ? */ ExitCritical(); /* Exit critical section */ return ERR_BUSY; /* If yes then error */ } *(volatile word *) Addr = Data16; /* Array address and program data */ FCMD = 32; /* Word program command */ FSTAT = 128; /* Clear flag command buffer empty */ asm { /* Jump to Wait in RAM code */ CLRB JSR WaitInRAMcode STAB err } ExitCritical(); /* Exit critical section */ if (err) return ERR_NOTAVAIL; /* Return error code if previous operation finished not correctly */ if (*(volatile word *) Addr != Data16) /* Was attempt to write data to the given address errorneous? */ return ERR_VALUE; /* If yes then error */ return ERR_OK; /* OK */ }
/* ** =================================================================== ** Method : HWEnDi (bean AsynchroSerial) ** ** Description : ** Enables or disables the peripheral(s) associated with the bean. ** The method is called automatically as a part of the Enable and ** Disable methods and several internal methods. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ static void HWEnDi(void) { EnterCritical(); /* Save the PS register */ if(EnMode && EnUser) { /* Enable device? */ SCI2BDH = 0x00; /* Set high divisor register (enable device) */ SCI2BDL = 0xA4; /* Set low divisor register (enable device) */ /* SCI2C3: ORIE=1,NEIE=1,FEIE=1,PEIE=1 */ SCI2C3 |= 0x0F; /* Enable error interrupts */ SCI2C2 |= ( SCI2C2_TE_MASK | SCI2C2_RE_MASK | SCI2C2_RIE_MASK | SCI2C2_ILIE_MASK); /* Enable transmitter, Enable receiver, Enable receiver interrupt, Enable idle interrupt */ if(SerFlag & FULL_TX) { /* Is any char in the transmit buffer? */ (void)SCI2S1; /* Reset interrupt request flag */ while(!SCI2S1_TDRE) {} /* Wait for transmitter empty */ SCI2D = (byte)BufferWrite; /* Store char to the transmitter register */ SCI2C2_TIE = 1; /* Enable transmit interrupt */ } } else { /* SCI2C3: ORIE=0,NEIE=0,FEIE=0,PEIE=0 */ SCI2C3 &= ~0x0F; /* Disable error interrupts */ SCI2C2 &= ( (~SCI2C2_RE_MASK) & (~SCI2C2_TE_MASK) & (~SCI2C2_TIE_MASK) & (~SCI2C2_RIE_MASK) & (~SCI2C2_ILIE_MASK)); /* Disable receiver, Disable transmitter, Disable transmit interrupt, Disable receiver interrupt, Disable idle interrupt */ SCI2BDH = 0x00; /* Set high divisor register to zero (disable device) */ SCI2BDL = 0x00; /* Set low divisor register to zero (disable device) */ } ExitCritical(); /* Restore the PS register */ }
/* ** =================================================================== ** Method : RestoreSector (bean IntFLASH) ** ** Description : ** This method is internal. ** =================================================================== */ byte WriteArray(void * Address,word From, word To, word* Array) { word Addr=(word)Address; byte err; word i; EnterCritical(); /* Enter critical section */ FSTAT = 48; /* Clear all flags */ for (i = From; i < To; i+=2) { *(volatile word *) (Addr+i) = Array[i/2]; FCMD = 32; /* Word program command */ FSTAT = 128; /* Clear flag command buffer empty */ asm { /* Jump to Wait in RAM code */ CLRB JSR WaitInRAMcode STAB err } if (err) { ExitCritical(); /* Exit critical section */ return ERR_NOTAVAIL; /* Return error code if previous operation finished not correctly */ } if (*(volatile word *) (Addr+i) != Array[i/2]) { /* Was attempt to write data to the given address errorneous? */ ExitCritical(); /* Exit critical section */ return ERR_VALUE; /* If yes then error */ } } ExitCritical(); /* Exit critical section */ return ERR_OK; /* OK */ }
/* ** =================================================================== ** Method : EraseSectorInternal (bean IntFLASH) ** ** Description : ** This method is internal. ** =================================================================== */ byte EraseSectorInternal(void * Address) { word Addr =(word)Address; byte err; EnterCritical(); /* Enter critical section */ FSTAT = 48; /* Clear all flags */ if (FSTAT_CBEIF == 0) { /* Is command buffer full ? */ ExitCritical(); /* Exit critical section */ return ERR_BUSY; /* If yes then error */ } *(volatile word *) (Addr & 65024) = IFsh10_DummyData; /* Write eny word to FLASH buffer */ FCMD = 64; /* Initiate Sector Erase commamd */ FSTAT = 128; /* Clear flag command buffer empty */ asm { /* Jump to Wait in RAM code */ CLRB JSR WaitInRAMcode STAB err } ExitCritical(); /* Exit critical section */ if (err) return err; /* Return error code if previous operation finished not correctly */ return ERR_OK; /* OK */ }
/* ** =================================================================== ** Method : SM1_SendBlock (component SynchroMaster) ** Description : ** Send a block of characters to the channel. This method is ** only available if a non-zero length of output buffer is ** defined. ** Parameters : ** NAME - DESCRIPTION ** * Ptr - Pointer to the block of data to send ** Size - Size of the block ** * Snd - Pointer to number of data that are sent ** (moved to buffer) ** Returns : ** --- - Error code, possible codes: ** ERR_OK - OK ** ERR_SPEED - This device does not work in ** the active speed mode ** ERR_DISABLED - Device is disabled (only if ** output DMA is supported and enabled) ** ERR_TXFULL - It was not possible to send ** requested number of bytes ** =================================================================== */ byte SM1_SendBlock(SM1_TComData *Ptr, word Size, word *Snd) { word count = 0x00U; /* Number of sent chars */ SM1_TComData *TmpPtr = Ptr; /* Temporary output buffer pointer */ bool tmpOnFreeTxBufSemaphore = OnFreeTxBufSemaphore; /* Local copy of OnFreeTxBufSemaphore state */ while((count < Size) && (SM1_OutLen < SM1_OUT_BUF_SIZE)) { /* While there is some char desired to send left and output buffer is not full do */ EnterCritical(); /* Enter the critical section */ OnFreeTxBufSemaphore = TRUE; /* Set the OnFreeTxBufSemaphore to block OnFreeTxBuf calling */ SM1_OutLen++; /* Increase number of bytes in the transmit buffer */ OutBuffer[OutIndexW++] = *TmpPtr++; /* Store char to buffer */ if (OutIndexW >= SM1_OUT_BUF_SIZE) { /* Is the index out of the transmit buffer? */ OutIndexW = 0x00U; /* Set index to the first item in the transmit buffer */ } count++; /* Increase the count of sent data */ if ((count == Size) || (SM1_OutLen == SM1_OUT_BUF_SIZE)) { /* Is the last desired char put into buffer or the buffer is full? */ if (!tmpOnFreeTxBufSemaphore) { /* Was the OnFreeTxBufSemaphore clear before enter the method? */ OnFreeTxBufSemaphore = FALSE; /* If yes then clear the OnFreeTxBufSemaphore */ } } if ((EnUser) && ((SerFlag & RUNINT_FROM_TX) == 0U)) { /* Is the device enabled by user? */ SerFlag |= RUNINT_FROM_TX; /* Set flag "running int from TX"? */ (void)SMasterLdd1_SendBlock(SMasterLdd1_DeviceDataPtr, (LDD_TData *)&OutBuffer[OutIndexR], 1U); /* Send one data byte */ } ExitCritical(); /* Exit the critical section */ } *Snd = count; /* Return number of sent chars */ if (count != Size) { /* Is the number of sent chars less then desired number of chars */ return ERR_TXFULL; /* If yes then error */ } return ERR_OK; /* OK */ }
/* ** =================================================================== ** Method : AS1_SendBlock (component AsynchroSerial) ** Description : ** Sends a block of characters to the channel. ** This method is available only if non-zero length of the ** output buffer is defined and the transmitter property is ** enabled. ** Parameters : ** NAME - DESCRIPTION ** * Ptr - Pointer to the block of data to send ** Size - Size of the block ** * Snd - Pointer to number of data that are sent ** (moved to buffer) ** Returns : ** --- - Error code, possible codes: ** ERR_OK - OK ** ERR_SPEED - This device does not work in ** the active speed mode ** ERR_TXFULL - It was not possible to send ** requested number of bytes ** =================================================================== */ byte AS1_SendBlock(AS1_TComData *Ptr, word Size, word *Snd) { word count = 0x00U; /* Number of sent chars */ AS1_TComData *TmpPtr = Ptr; /* Temporary output buffer pointer */ while ((count < Size) && (AS1_OutLen < AS1_OUT_BUF_SIZE)) { /* While there is some char desired to send left and output buffer is not full do */ EnterCritical(); /* Enter the critical section */ AS1_OutLen++; /* Increase number of bytes in the transmit buffer */ OutBuffer[OutIndexW++] = *TmpPtr++; /* Store char to buffer */ if (OutIndexW >= AS1_OUT_BUF_SIZE) { /* Is the index out of the transmit buffer? */ OutIndexW = 0x00U; /* Set index to the first item in the transmit buffer */ } count++; /* Increase the count of sent data */ if ((SerFlag & RUNINT_FROM_TX) == 0U) { SerFlag |= RUNINT_FROM_TX; /* Set flag "running int from TX"? */ (void)ASerialLdd1_SendBlock(ASerialLdd1_DeviceDataPtr, (LDD_TData *)&OutBuffer[OutIndexR], 1U); /* Send one data byte */ } ExitCritical(); /* Exit the critical section */ } *Snd = count; /* Return number of sent chars */ if (count != Size) { /* Is the number of sent chars less then desired number of chars */ return ERR_TXFULL; /* If yes then error */ } return ERR_OK; /* OK */ }
void I2C_StoreCmd(void) { #if PL_HAS_UI unsigned char buf[32]; uint8_t strSize; #if PL_HAS_RUNNER buf[0] = '@'; buf[1] = '\0'; RUNNER_GetCmdString(buf, sizeof(buf)); #elif PL_HAS_SLIDER SLIDER_GetCmdString(buf, sizeof(buf)); #else buf[0] = '\0'; #endif if (buf[0]!='\0') { uint8_t cnt=3; while(cnt>0 && memDevice.u.data.cmdLength!=0) { /* poll cmdLength: this will be set to zero by the master if it is ok to place the string */ FRTOS1_vTaskDelay(50/portTICK_RATE_MS); /* give master some time to clear the flasg */ cnt--; } if (cnt==0) { /* timeout. Will loose that command. Not ideal, but simple :-) */ return; /* get out here */ } strSize = (uint8_t)(UTIL1_strlen(buf)+1); /* size of string including zero byte */ if (strSize>sizeof(memDevice.u.data.cmd)) { strSize = sizeof(memDevice.u.data.cmd); } EnterCritical(); memDevice.u.data.cmdLength = strSize; UTIL1_strcpy(memDevice.u.data.cmd, sizeof(memDevice.u.data.cmd), buf); ExitCritical(); } #endif /* PL_HAS_UI */ }
int32_t I2C_GetMotorPID_D(void) { int32_t val; EnterCritical(); val = memDevice.u.data.motorPID_D; ExitCritical(); return val; }
int32_t I2C_GetMotorDesiredSpeed(void) { int32_t val; EnterCritical(); val = memDevice.u.data.motorDesiredSpeed; ExitCritical(); return val; }
int8_t I2C_GetMotorPWMPercent(void) { int8_t val; EnterCritical(); val = memDevice.u.data.motorPWM; ExitCritical(); return val; }
bool I2C_GetEKGIsDataReady(void) { bool val; EnterCritical(); val = (bool)(memDevice.u.data.ekgNewReady!=0); ExitCritical(); return val; }
uint8_t I2C_GetEKGHeartRate(void) { uint8_t val; EnterCritical(); val = memDevice.u.data.ekgHeartRate; ExitCritical(); return val; }
int16_t I2C_GetAccelZ(void) { int16_t val; EnterCritical(); val = memDevice.u.data.accelZ; ExitCritical(); return val; }