コード例 #1
0
/*******************************************************************************
 * FUNCTION: uiUART2Write
 *
 * PARAMETERS:
 * ~ *pucBuffer	- Buffer for the data to send.
 * ~ uiLength	- Number of bytes to send.
 *
 * RETURN:
 * ~ Number of bytes sent.
 *
 * DESCRIPTIONS:
 * Transmit data via UART.
 *
 *******************************************************************************/
unsigned int uiUART2Write(const unsigned char *pucBuffer, unsigned char uiLength)
{
    unsigned char ucActualLength = 0;

    while (uiLength-- > 0) {
        // Make sure there is empty space in the buffer.
        if (uiUART2GetTxSpace() > 0) {

            // Copy the data to the buffer.
            prv_xTx.pucBuffer[prv_xTx.uiWritePt] = *pucBuffer++;

            // Increase the number of transmitted data.
            ucActualLength++;

            // Increase the write pointer and data count.
            prv_vIncPointer(&prv_xTx.uiWritePt, prv_xTx.uiBufferSize);

            unsigned int iStatus = INTDisableInterrupts();
            prv_xTx.uiDataCount++;
            INTRestoreInterrupts(iStatus);
        }

        else {
            break;
        }
    }

    // Enable the Tx interrupt if there is new data.
    if (ucActualLength > 0) {
        INTEnable(INT_U2TX, INT_ENABLED);
    }

    return ucActualLength;
}
コード例 #2
0
/*******************************************************************************
 * FUNCTION: vUART2FlushRxBuffer
 *
 * PARAMETERS:
 * ~ void
 *
 * RETURN:
 * ~ void
 *
 * DESCRIPTIONS:
 * Flush all the data in the Rx buffer.
 *
 *******************************************************************************/
void vUART2FlushRxBuffer(void)
{
    unsigned char ucReceivedData;

    unsigned int iStatus = INTDisableInterrupts();
    
    prv_xRx.uiDataCount = 0;
    prv_xRx.uiReadPt = 0;
    prv_xRx.uiWritePt = 0;
    
    // Discard all data available in the UART receive buffer.
    while (UARTReceivedDataIsAvailable(UART2)) {
        // Read the received data.
        ucReceivedData = UARTGetDataByte(UART2);
    }

    // Clear the overrun flag.
    if (UARTGetLineStatus(UART2) & UART_OVERRUN_ERROR) {
        U2STAbits.OERR = 0;
    }

    // Clear the semaphore.
    xSemaphoreTake(xBluetoothRxSemaphore, 0);

    INTRestoreInterrupts(iStatus);
}
コード例 #3
0
/*******************************************************************************
 * FUNCTION: uiUART2Read
 *
 * PARAMETERS:
 * ~ *pucBuffer	- Buffer to store the received data.
 * ~ uiLength	- Number of bytes to read.
 *
 * RETURN:
 * ~ Number of bytes read.
 *
 * DESCRIPTIONS:
 * Read the data from UART.
 *
 *******************************************************************************/
unsigned int uiUART2Read(unsigned char *pucBuffer, unsigned char uiLength)
{
    unsigned int uiActualLength = 0;

    while (uiLength-- > 0) {
        // Make sure there is data available in the buffer.
        if (uiUART2GetRxDataCount() > 0) {
            // Copy the data to the buffer.
            *pucBuffer++ = prv_xRx.pucBuffer[prv_xRx.uiReadPt];

            // Increase the number of data read.
            uiActualLength++;

            // Increase the read pointer and decrease the data count.
            prv_vIncPointer(&prv_xRx.uiReadPt, prv_xRx.uiBufferSize);

            unsigned int iStatus = INTDisableInterrupts();
            prv_xRx.uiDataCount--;
            INTRestoreInterrupts(iStatus);
        }	
        else {
            break;
        }
    }

    return uiActualLength;
}
コード例 #4
0
void Servo::writeMicroseconds(int value)
{
  // calculate and store the values for the given channel
  byte channel = this->servoIndex;
  if( (channel >= 0) && (channel < MAX_SERVOS) )   // ensure channel is valid
  {  
    if( value < SERVO_MIN() )          // ensure pulse width is valid
      value = SERVO_MIN();
    else if( value > SERVO_MAX() )
      value = SERVO_MAX();   
    
  	value = value - TRIM_DURATION;
    value = usToTicks(value);  // convert to ticks after compensating for interrupt overhead 

   

    unsigned int status;
    status = INTDisableInterrupts();
    servos[channel].ticks = value;

    INTRestoreInterrupts(status);
  } 
     
    
}
コード例 #5
0
/*******************************************************************************
 * FUNCTION: uiUART2GetRxDataCount
 *
 * PARAMETERS:
 * ~ void
 *
 * RETURN:
 * ~ Number of bytes available.
 *
 * DESCRIPTIONS:
 * Read the number of bytes available in the Rx buffer.
 *
 *******************************************************************************/
volatile unsigned int uiUART2GetRxDataCount(void)
{
    unsigned int iStatus = INTDisableInterrupts();
    unsigned int uiDataCount = prv_xRx.uiDataCount;
    INTRestoreInterrupts(iStatus);

    return uiDataCount;
}
コード例 #6
0
/*******************************************************************************
 * FUNCTION: uiUART2GetTxSpace
 *
 * PARAMETERS:
 * ~ void
 *
 * RETURN:
 * ~ Remaining space in TX buffer.
 *
 * DESCRIPTIONS:
 * Read the remaining empty space in the TX buffer.
 *
 *******************************************************************************/
volatile unsigned int uiUART2GetTxSpace(void)
{
    unsigned int iStatus = INTDisableInterrupts();
    unsigned int uiTxSpace = prv_xTx.uiBufferSize - prv_xTx.uiDataCount;
    INTRestoreInterrupts(iStatus);

    return uiTxSpace;
}
コード例 #7
0
ファイル: commsToRPi.c プロジェクト: MattAtHazmat/TRISThis
inline BOOL SPIFUBAR(void)
{
    BOOL returnValue;
    unsigned int intEnabled;
    intEnabled=INTDisableInterrupts();
    returnValue=FALSE;
    INTRestoreInterrupts(intEnabled);
    return returnValue;
}
コード例 #8
0
ファイル: commsToRPi.c プロジェクト: MattAtHazmat/TRISThis
BOOL SPIDataReady(void)
{
    BOOL returnValue;
    unsigned int intTemp;
    intTemp = INTDisableInterrupts();
    returnValue=SPI.status.RXDataReady;
    SPI.status.RXDataReady=FALSE;
    INTRestoreInterrupts(intTemp);
    return returnValue;
}
コード例 #9
0
ファイル: MyCyclone.c プロジェクト: lechienv/ProgSandbot
void MyCyclone_Write(unsigned int theAddress, unsigned int theData)
{
    unsigned int intStatus;

    intStatus = INTDisableInterrupts();
    mPORTEClearBits(CS_FPGA);
    MySPI_PutC(theAddress | 0x8000); // Bit 7 = R/W = 1
    MySPI_PutC(theData);
    mPORTESetBits(CS_FPGA);
    INTRestoreInterrupts(intStatus);
}
コード例 #10
0
ファイル: test_main.c プロジェクト: nsaspook/mbmc
void DelayMs(WORD delay) {
    unsigned int int_status;
    while (delay--) {
        int_status = INTDisableInterrupts();
        OpenCoreTimer(500000 / 2000);
        INTRestoreInterrupts(int_status);
        mCTClearIntFlag();
        while (!mCTGetIntFlag());
    }
    mCTClearIntFlag();
}
コード例 #11
0
ファイル: NVMem.c プロジェクト: sidwarkd/waterworx-device
/********************************************************************
* Function: 	NVMemOperation()
*
* Precondition: 
*
* Input: 		NV operation
*
* Output:		NV eror
*
* Side Effects:	This function must generate MIPS32 code only and 
				hence the attribute (nomips16)
*
* Overview:     Performs reuested operation.
*
*			
* Note:		 	None.
********************************************************************/
UINT __attribute__((nomips16)) NVMemOperation(UINT nvmop)
{
    int	int_status;
    int	susp;

    // Disable DMA & Disable Interrupts
	#ifdef _DMAC
	int_status = INTDisableInterrupts();
	susp = DmaSuspend();
	#else
	int_status = INTDisableInterrupts(); 
	#endif	// _DMAC

    // Enable Flash Write/Erase Operations
    NVMCON = NVMCON_WREN | nvmop;
    // Data sheet prescribes 6us delay for LVD to become stable.
    // To be on the safer side, we shall set 7us delay.
    delay_us(7);

    NVMKEY 		= 0xAA996655;
    NVMKEY 		= 0x556699AA;
    NVMCONSET 	= NVMCON_WR;

    // Wait for WR bit to clear
    while(NVMCON & NVMCON_WR);
    
    // Disable Flash Write/Erase operations
    NVMCONCLR = NVMCON_WREN;  


	// Enable DMA & Enable Interrupts
	#ifdef _DMAC
	DmaResume(susp);
	INTRestoreInterrupts(int_status);
	#else
	INTRestoreInterrupts(int_status);
	#endif // _DMAC

	// Return Error Status
    return(NVMemIsError());
}
コード例 #12
0
ファイル: MyCyclone.c プロジェクト: lechienv/ProgSandbot
unsigned int MyCyclone_Read(unsigned int theAddress)
{
    unsigned int theData;
    unsigned int intStatus;

    intStatus = INTDisableInterrupts();
    mPORTEClearBits(CS_FPGA);
    MySPI_PutC(theAddress & 0x7FFF);   // Bit 7 = R/W = 0
    theData = MySPI_GetC();
    mPORTESetBits(CS_FPGA);
    INTRestoreInterrupts(intStatus);
    return(theData);
}
コード例 #13
0
ファイル: commsToRPi.c プロジェクト: MattAtHazmat/TRISThis
BOOL SPIGet(uint8_t *tempSPIRX)
{
    BOOL returnValue;
    unsigned int index;
    unsigned int intTemp;
    intTemp = INTDisableInterrupts();
    for(index=0;index<sizeof(SPI.RXData);index++)
    {
        tempSPIRX[index]=SPI.RXData[index];
    }
    INTRestoreInterrupts(intTemp);
    return returnValue;
}
コード例 #14
0
void DelayMs(WORD time)
{
    while(time--)
    {
        unsigned int    int_status;

        int_status = INTDisableInterrupts();
        OpenCoreTimer(GetSystemClock() / 2000); // core timer is at 1/2 system clock
        INTRestoreInterrupts(int_status);

        mCTClearIntFlag();

        while(!mCTGetIntFlag());
    }

    mCTClearIntFlag();
}