예제 #1
0
/*
*********************************************************************************************************
*                                   WF_RxDataReadPacket()
*    
* Description : Reads all or part of an Rx data packet from MRF24WB0M memory to Host CPU memory.
*
* Argument(s) : p_rxData   - pointer to where Rx data packet will be written
*               length     - Number of bytes to read from MRF24WB0M memory
*               startIndex - start index within MRF24WB0M memory to start read from
*
* Return(s)   : None
*
* Caller(s)   : Application
*
* Notes:      : None
*
*********************************************************************************************************
*/
void WF_RxDataReadPacket(uint8_t  *p_rxData,
                         uint16_t length,
                         uint16_t startIndex)
{
#if !defined(USE_WF_HOST_BUFFER)    
    uint16_t byteCount;
#endif
         
    SYS_ASSERT(startIndex == 0);
    
    /* if application calls this function, and gHostRAWDataPacketReceived is not true, then error, because */
    /* driver has not received a data packet.                                                              */
    if (!g_HostRAWDataPacketReceived)
    {
        SYS_ASSERT(false);
    }  
    
    g_HostRAWDataPacketReceived = false;     /* clear flag for next data packet */
    
    /* Ensure the MRF24WB0M is awake (only applies if PS-Poll was enabled) */    
    EnsureWFisAwake();
    
#if !defined(USE_WF_HOST_BUFFER)  /* when testing with MCHP stack the packet is already mounted */
    /* Mount Read FIFO to RAW Rx window. Size of Rx data packet is returned */
    byteCount = RawMountRxBuffer();
    SYS_ASSERT(byteCount > 0);
#endif
        
    /* now that buffer mounted it is safe to reenable interrupts */
    WF_EintEnable();
    
    /* read the requested bytes into callers buffer */
    RawRead(RAW_RX_ID, RAW_RX_DEST_ADD_INDEX + startIndex, length, p_rxData); 
}      
예제 #2
0
static void startStroke( uint pointIndex, uint pointCount )
{
    SYS_ASSERT( pointCount >= 2u );

    Stroke* pStroke = &s_renderer.currentStroke;

    pStroke->progress           = 0.0f;
    pStroke->activeSegment      = 0u;
    pStroke->segmentProgress    = 0.0f;

    // compute total length of this stroke:
    float strokeLength = 0.0f;

    float2 segmentStart = s_renderer.strokeBuffer.points[ pointIndex ];
    for( uint i = 1u; i < pointCount; ++i )
    {
        const float2 segmentEnd = s_renderer.strokeBuffer.points[ pointIndex + i ];
        float segmentLength = float2_distance( &segmentStart, &segmentEnd );

        strokeLength += segmentLength;
        segmentStart = segmentEnd;
    }
    pStroke->length = strokeLength;

	SYS_ASSERT( strokeLength < 100000.0f );

    //SYS_TRACE_DEBUG( "Starting new stroke (length=%.2f #segments=%i)\n", strokeLength, pointCount - 1u );
}
void DRV_USART_BufferEventHandlerSet
(
    const DRV_HANDLE hClient,
    const DRV_USART_BUFFER_EVENT_HANDLER eventHandler,
    const uintptr_t context
)
{
    DRV_USART_CLIENT_OBJ * clientObj;

    /* Validate the driver handle */
    if((DRV_HANDLE_INVALID == hClient) || (0 == hClient))
    {
        /* This means the handle is invalid */
        SYS_ASSERT(false, "Driver Handle is invalid");
        return;
    }

    clientObj = (DRV_USART_CLIENT_OBJ *)hClient;

    if(!clientObj->inUse)
    {
        SYS_ASSERT(false, "Invalid driver handle");
        return;
    }

    /* Register the event handler with the client */
    clientObj->eventHandler = eventHandler;
    clientObj->context = context;
}
예제 #4
0
파일: drv_usb.c 프로젝트: ctapang/v0_70_01b
void DRIVER DRV_USB_ClientEventCallBackSet
( 
    DRV_HANDLE   client          ,
    uintptr_t    hReferenceData ,
    DRV_USB_EVENT_CALLBACK eventCallBack 
)
{
    DRV_USB_CLIENT_OBJ * hClient;

    if(client == DRV_HANDLE_INVALID)
    {
        SYS_ASSERT(false, "Bad Client Handle");
        return;
    }

    hClient = (DRV_USB_CLIENT_OBJ *) client;
    
    if(!hClient->inUse)
    {
        SYS_ASSERT(false, "Invalid client handle");
        return;
    }

    /* Assign event call back and reference data */
    hClient->hClientArg = hReferenceData;
    hClient->pEventCallBack = eventCallBack;
   
    return;
    
}
예제 #5
0
int StreamStart(V3XA_STREAM handle)
{
	DS_stream       *pStr = g_pDSStreams + handle;
	LPDIRECTSOUNDBUFFER pSrc = g_pDSHandles[pStr->channel].pbuffer;
	SYS_ASSERT(pSrc);
	SYS_ASSERT(pStr->nState & 1);
	if (((pStr->nState&1)==0)||(!pSrc))
	{
		return 0;
	}

	if (SYS_DXTRACE(pSrc->Play(0, 0, DSBPLAY_LOOPING))!=DS_OK)
		return 0;

	SYS_DXTRACE(pSrc->SetCurrentPosition( 0 ));
	SYS_DXTRACE(pSrc->SetFrequency( pStr->sample.samplingRate ));

	pStr->m_nPreviousPosition = 0;
	pStr->m_nUploadedBytes = 0;
	pStr->m_nWritePosition = 0;
	pStr->m_nStreamState = 1;
	pStr->m_nTotalBytes = 0;
	pStr->m_nUploadedBytes = 0;
	pStr->m_nWriteBytes = 0;
	return 0;
}
예제 #6
0
USB_ERROR DRIVER _DRV_USB_MAKE_NAME(DEVICE_IRPCancelAll)
(
    DRV_HANDLE client,
    USB_ENDPOINT endpointAndDirection
)
{
    int     direction;
    uint8_t endpoint;
    DRV_USB_OBJ     * hDriver;
    DRV_USB_BDT_ENTRY * pBDT;
    DRV_USB_DEVICE_ENDPOINT_OBJ * endpointObject;
    bool interruptWasEnabled = false;

    endpoint = endpointAndDirection & 0xF;
    direction = ((endpointAndDirection & 0x80) != 0);

    if(endpoint >= DRV_USB_ENDPOINTS_NUMBER)
    {
        SYS_ASSERT(false,"Unsupported endpoint");
        return USB_ERROR_DEVICE_ENDPOINT_INVALID;
    }

    if(DRV_HANDLE_INVALID == client)
    {
        SYS_ASSERT(false, "Driver Handle is invalid");
        return USB_ERROR_PARAMETER_INVALID;
    }

    hDriver = _DRV_USB_OBJ;

    /* Get the endpoint object */
    endpointObject = _DRV_USB_ENDPOINT_OBJ(endpoint, direction);

    /* Get the BDT entry for this endpoint */
    pBDT = hDriver->pBDT + (4 * endpoint) + (2 * direction);

    if(!hDriver->isInInterruptContext)
    {
        //OSAL : Get mutex
        interruptWasEnabled = _DRV_USB_InterruptSourceDisable(DRV_USB_INTERRUPT_SOURCE);
    }

    /* Get the odd and even endpoint BDT back */
    pBDT->byte[0] = 0x0;
    (pBDT + 1)->byte[0] = 0x0;

    /* Flush the endpoint */
    _DRV_USB_DEVICE_IRPQueueFlush(endpointObject);

    if(!hDriver->isInInterruptContext)
    {
        if(interruptWasEnabled)
        {
            _DRV_USB_InterruptSourceEnable(DRV_USB_INTERRUPT_SOURCE);
        }
        // OSAL: Release Mutex
    }

    return(USB_ERROR_NONE);
}
예제 #7
0
파일: drv_usb.c 프로젝트: ctapang/v0_70_01b
void DRIVER DRV_USB_Close( DRV_HANDLE client )
{
    DRV_USB_CLIENT_OBJ * hClient;
    DRV_USB_OBJ * hDriver;

    if(client == DRV_HANDLE_INVALID)
    {
        SYS_ASSERT(false, "Bad Client Handle");
        return;
    }

    hClient = (DRV_USB_CLIENT_OBJ *) client;
    
    if(!hClient->inUse)
    {
        SYS_ASSERT(false, "Invalid client handle");
        return;
    }
    
    hDriver = (DRV_USB_OBJ *)hClient->hDriver;

    /* Remove this client from the driver client
     * table */

    hDriver->nClients--;
    hDriver->pDrvUSBClientObj = (DRV_USB_CLIENT_OBJ *)DRV_HANDLE_INVALID;

    /* Give back the client */
    hClient->inUse = false;
    hClient->pEventCallBack = NULL;
}
예제 #8
0
void APP_NVM_Write1(void)
{
    int i;
    uint8_t buf_t[10];

    char c_tmp = 0;
    for(i = 0;i<DRV_NVM_PAGE_SIZE;i++)
    {
        NVM_DATA_TEST_BUFF[i] = 0x55;
    }
    SYS_CONSOLE_MESSAGE("1. Open\r\n");
    if(wifi_nvm_handle.nvmHandle == 0)
    {
        wifi_nvm_handle.nvmHandle = DRV_NVM_Open(0, DRV_IO_INTENT_READWRITE);
        if(DRV_HANDLE_INVALID == wifi_nvm_handle.nvmHandle){ SYS_ASSERT(DRV_HANDLE_INVALID != wifi_nvm_handle.nvmHandle,"Error Opening Driver");}
    }
    SYS_CONSOLE_MESSAGE("2. erase\r\n");
    wifi_nvm_handle.nvmbufferHandle = DRV_NVM_Erase(wifi_nvm_handle.nvmHandle,(uint8_t*)NVM_WF_CONFIG__ADDRESS, DRV_NVM_PAGE_SIZE);
    if(DRV_NVM_BUFFER_HANDLE_INVALID == wifi_nvm_handle.nvmbufferHandle){SYS_ASSERT(false, "Driver Erase Failed");}
    while(DRV_NVM_BUFFER_COMPLETED != DRV_NVM_BufferStatus(wifi_nvm_handle.nvmHandle, wifi_nvm_handle.nvmbufferHandle))  { ;}
    SYS_CONSOLE_MESSAGE("3. Write\r\n");
    wifi_nvm_handle.nvmbufferHandle = DRV_NVM_Write(wifi_nvm_handle.nvmHandle, (uint8_t *)(NVM_WF_CONFIG__ADDRESS), (uint8_t *)NVM_DATA_TEST_BUFF, DRV_NVM_ROW_SIZE);
    if(DRV_NVM_BUFFER_HANDLE_INVALID == wifi_nvm_handle.nvmbufferHandle){SYS_ASSERT(false, "Driver Writing Failed");}
    while(DRV_NVM_BUFFER_COMPLETED != DRV_NVM_BufferStatus(wifi_nvm_handle.nvmHandle, wifi_nvm_handle.nvmbufferHandle)){;}
    SYS_CONSOLE_MESSAGE("4. Done\r\n");
}
예제 #9
0
void wifi_nvm_erase(int size)
{
    if(wifi_nvm_handle.nvmHandle == 0)
    {
        wifi_nvm_handle.nvmHandle = DRV_NVM_Open(0, DRV_IO_INTENT_READWRITE);
        if(DRV_HANDLE_INVALID == wifi_nvm_handle.nvmHandle){ SYS_ASSERT(DRV_HANDLE_INVALID != wifi_nvm_handle.nvmHandle,"Error Opening Driver");}
    }
    wifi_nvm_handle.nvmbufferHandle = DRV_NVM_Erase(wifi_nvm_handle.nvmHandle,(uint8_t*)NVM_WF_CONFIG__ADDRESS, DRV_NVM_PAGE_SIZE);
    if(DRV_NVM_BUFFER_HANDLE_INVALID == wifi_nvm_handle.nvmbufferHandle){SYS_ASSERT(false, "Driver Erase Failed");}
    while(DRV_NVM_BUFFER_COMPLETED != DRV_NVM_BufferStatus(wifi_nvm_handle.nvmHandle, wifi_nvm_handle.nvmbufferHandle))  { ;}
}
예제 #10
0
void wifi_nvm_read(uint8_t *data_comfig, int size)
{
    if(wifi_nvm_handle.nvmHandle == 0)
     {
         wifi_nvm_handle.nvmHandle = DRV_NVM_Open(0, DRV_IO_INTENT_READWRITE);
         if(DRV_HANDLE_INVALID == wifi_nvm_handle.nvmHandle){ SYS_ASSERT(DRV_HANDLE_INVALID != wifi_nvm_handle.nvmHandle,"Error Opening Driver");}
     }

     wifi_nvm_handle.nvmbufferHandle = DRV_NVM_Read(wifi_nvm_handle.nvmHandle, data_comfig, (uint8_t*)NVM_WF_CONFIG__ADDRESS, size);
     if(DRV_NVM_BUFFER_HANDLE_INVALID == wifi_nvm_handle.nvmbufferHandle){ SYS_ASSERT(false, "Driver Read Failed");}
     while(DRV_NVM_BUFFER_COMPLETED != DRV_NVM_BufferStatus(wifi_nvm_handle.nvmHandle, wifi_nvm_handle.nvmbufferHandle)){;}
}
예제 #11
0
파일: drv_usb.c 프로젝트: ctapang/v0_70_01b
void DRIVER DRV_USB_Deinitialize 
( 
    const SYS_MODULE_INDEX  object
)
{
    DRV_USB_OBJ * drvObj;
    USBHS_MODULE_ID  usbID;
    
    if(object == SYS_MODULE_OBJ_INVALID)
    { 
	    /* Invalid object */
	    
	    SYS_ASSERT(false, "Invalid object");
	    return ;
	} 
    
    if( object >= DRV_USB_INSTANCES_NUMBER)
    {
        SYS_ASSERT(false,"Invalid driver Index");
        return  ;
    }

    if(gDrvUSBObj[object].inUse == false)
    {
        /* Cannot deinitialize an object that is 
         * not already in use. */

        SYS_ASSERT(false, "Instance not in use");
        return  ;
    }

    drvObj = &gDrvUSBObj[object]; 
    usbID  = drvObj->usbID;

    /* Populate the driver object with
     * the required data */

    drvObj->inUse   = false;
    drvObj->status  = SYS_STATUS_UNINITIALIZED; 

    /* Clear and disable the interrupts */
    _DRV_USB_InterruptSourceDisable(drvObj->interruptSource);
    _DRV_USB_InterruptSourceClear(drvObj->interruptSource);

    /* Set number of clients to zero */

    drvObj->nClients = 0;
    drvObj->pDrvUSBClientObj = (DRV_USB_CLIENT_OBJ*)DRV_HANDLE_INVALID;

    return;

} /* DRV_USB_Initialize */
예제 #12
0
파일: drv_usb.c 프로젝트: ctapang/v0_70_01b
DRV_HANDLE DRIVER _DRV_USB_MAKE_NAME(Open)
(
    const DRV_IO_INTENT    ioIntent 
)
{
    DRV_USB_CLIENT_OBJ * hClient;
    DRV_USB_OBJ * drvObj;

    drvObj = &gDrvUSBGroup.gDrvUSBObj;

    if(drvObj->status != SYS_STATUS_READY)
    {
        /* The USB module should be ready */

        SYS_ASSERT(false, "Was the driver initialized?");
        return DRV_HANDLE_INVALID;
    }

    if(ioIntent != (DRV_IO_INTENT_EXCLUSIVE|DRV_IO_INTENT_NONBLOCKING
                |DRV_IO_INTENT_READWRITE))
    {
        /* The driver only supports this mode */

        SYS_ASSERT(false, "IO intent mode not supported");
        return DRV_HANDLE_INVALID;
    }	

    if(drvObj->nClients > 0)
    {
        /* Driver supports exclusive open only */
        SYS_ASSERT(false, "Driver already opened once. Cannot open again");
        return DRV_HANDLE_INVALID;
    }

    /* One to One mapping between client object
     * and driver object */

    hClient = &gDrvUSBGroup.gDrvUSBClientObj;

    /* Clear prior value */

    hClient->pEventCallBack = NULL;
    
    /* Let the driver know that it has been opened once */ 
    drvObj->nClients ++;

    /* Return the client object */

    return ( ( DRV_HANDLE ) hClient );

}
예제 #13
0
void SYS_Initialize ( void* data )
{
	unsigned int cache_status;
    
   /* enable cache */
    cache_status = CHECON;
    cache_status |= (3 << _CHECON_PREFEN_POSITION);
    CHECON = cache_status;
    CheKseg0CacheOn();
    
    /* Initialize the BSP */
    BSP_Initialize( );

    /* Initialize the USB Controller driver */
    appDrvObject.usbCDObject = DRV_USB_Initialize (DRV_USB_INDEX_0 ,
                                                   ( SYS_MODULE_INIT* ) & usbCDInitData);

    /* check if the object returned by the controller driver is valid */
    SYS_ASSERT((SYS_MODULE_OBJ_INVALID != appDrvObject.usbCDObject), "Invalid USB CD object");
	
     /* Initialize the USB device layer */
	appDrvObject.usbDevObject = USB_DEVICE_Initialize (USB_DEVICE_INDEX_0 ,
                                                    ( SYS_MODULE_INIT* ) & usbDevInitData);
    
    /* check if the object returned by the device layer is valid */
    SYS_ASSERT((SYS_MODULE_OBJ_INVALID != appDrvObject.usbDevObject), "Invalid USB DEVICE object");
    
    /* open an instance of the device layer */
    appData.usbDevHandle = USB_DEVICE_Open( USB_DEVICE_INDEX_0, DRV_IO_INTENT_READWRITE );
    
    /* Register a callback with device layer to get event notification (for end point 0) */
    USB_DEVICE_EventCallBackSet(appData.usbDevHandle, APP_UsbDeviceEventCallBack);

    /* Initialize the Application */
    APP_Initialize ( );

    /* Initializethe interrupt system  */
    SYS_INT_Initialize();
    
     /* set priority for USB interrupt source */
    SYS_INT_PrioritySet(INT_SOURCE_USB_1, INT_PRIORITY_LEVEL3);
    
    /* set sub-priority for USB interrupt source */
    SYS_INT_SubprioritySet(INT_SOURCE_USB_1, INT_SUBPRIORITY_LEVEL3);

    /* Initialize the global interrupts */
    SYS_INT_Enable();
    
   
}
예제 #14
0
void APP_NVM_READ(uint32_t flag)
{
    int i;
    uint8_t buf_t[30];
    uint32_t Source_Addr;
    switch(flag)
        {
        case 0:
            Source_Addr = NVM_WF_CONFIG__ADDRESS - DRV_NVM_PAGE_SIZE;
            break;
        case 1:
            Source_Addr = NVM_WF_CONFIG__ADDRESS ;
            break;
        case 2:
            Source_Addr = NVM_WF_CONFIG__ADDRESS + DRV_NVM_PAGE_SIZE;
            break;
        case 3:
            Source_Addr = NVM_WF_CONFIG__ADDRESS + 2*DRV_NVM_PAGE_SIZE;
            break;
        case 4:
            Source_Addr = NVM_WF_CONFIG__ADDRESS + 3*DRV_NVM_PAGE_SIZE;
            break;
        case 5:
            Source_Addr = NVM_WF_CONFIG__ADDRESS + 4*DRV_NVM_PAGE_SIZE;
            break;
        default:
            Source_Addr = NVM_WF_CONFIG__ADDRESS;
            break;
        }
    if(wifi_nvm_handle.nvmHandle == 0)
    {
        wifi_nvm_handle.nvmHandle = DRV_NVM_Open(0, DRV_IO_INTENT_READWRITE);
        if(DRV_HANDLE_INVALID == wifi_nvm_handle.nvmHandle){ SYS_ASSERT(DRV_HANDLE_INVALID != wifi_nvm_handle.nvmHandle,"Error Opening Driver");}
    }

    wifi_nvm_handle.nvmbufferHandle = DRV_NVM_Read(wifi_nvm_handle.nvmHandle, NVM_DATA_TEST_BUFF, (uint8_t*)Source_Addr, DRV_NVM_PAGE_SIZE);
    if(DRV_NVM_BUFFER_HANDLE_INVALID == wifi_nvm_handle.nvmbufferHandle){ SYS_ASSERT(false, "Driver Read Failed");}
    while(DRV_NVM_BUFFER_COMPLETED != DRV_NVM_BufferStatus(wifi_nvm_handle.nvmHandle, wifi_nvm_handle.nvmbufferHandle)){;}

    SYS_CONSOLE_MESSAGE("\r\n---------");
    for(i=0;i<DRV_NVM_PAGE_SIZE;i++)
    {
        if(i%64 == 0) {sprintf(buf_t,"\r\n[%08x]:",i+Source_Addr);SYS_CONSOLE_MESSAGE(buf_t);}
        sprintf(buf_t,"%02x ",NVM_DATA_TEST_BUFF[i]);
        SYS_CONSOLE_MESSAGE(buf_t);
    }

    SYS_CONSOLE_MESSAGE("\r\n---------");
}
예제 #15
0
/****************************************************************************
  Function:
    bool DRV_SPI_Initialize(SpiChannel chn, SpiOpenFlags oFlags, unsigned int fpbDiv)

  Summary:
    This function initializes the SPI channel and also sets the brg register.

  Description:
    This function initializes the SPI channel and also sets the brg register.
 	The SPI baudrate BR is given by: BR=Fpb/(2*(SPIBRG+1))
 	The input parametes fpbDiv specifies the Fpb divisor term (2*(SPIBRG+1)),
 	so the BRG is calculated as SPIBRG=fpbDiv/2-1.

    
  Precondition:
    None

  Parameters:
	chn 	- the channel to set
	oFlags	- a SpiOpenFlags or __SPIxCONbits_t structure that sets the module behavior
	fpbDiv	- Fpb divisor to extract the baud rate: BR=Fpb/fpbDiv.


  Returns:
     true if success
     false otherwise

  Remarks:
    - The baud rate is always obtained by dividing the Fpb to an even number
      between 2 and 1024.
	- When selecting the number of bits per character, SPI_OPEN_MODE32 has the highest priority.
	  If SPI_OPEN_MODE32 is not set, then SPI_OPEN_MODE16 selects the character width.
 	- The SPI_OPEN_SSEN is taken into account even in master mode. If it is set the library
      will properly se the SS pin as an digital output.
  ***************************************************************************/	
bool DRV_SPI_Initialize(SpiChannel chn, SpiOpenFlags oFlags, unsigned int fpbDiv)
{
#if defined (__C32__)
    SpiChnOpen(chn, oFlags, fpbDiv);
#elif defined (__C30__) 
    volatile uint16_t con1 = 0; 
    uint16_t con2 = 0;
    uint16_t con3 = 0;
    uint8_t i;

    if((SYS_CLK_PeripheralClockGet()/fpbDiv) > 10000000ul)
    {
        SYS_ASSERT(false, "Requested SPI frequency is not supported!");
        return false;
        // the SPI clock is selected more than 10MHz.
        // Select the frequency as per the data sheet of the particular 16bit device.	
    }

    for(i = 0; i < SPI_CLK_TBL_ELEMENT_COUNT; i++)
    {
        if((SYS_CLK_PeripheralClockGet()/fpbDiv) <= SpiClkTbl[i].clock)
        {
            con1 = SpiClkTbl[i].scale;
            break;
        }
    }
	
	con1 |= oFlags;
	con3 |= SPI_EN;

    switch(chn)
    {
        case 1:
			OpenSPI1(con1,con2,con3); 
            break;
            
        case 2:
            SPI2STAT &= 0x7FFF;
            OpenSPI2(con1,con2,con3);
            break;

        default:
            SYS_ASSERT(false, "Requested SPI channel is not supported!");
            return false;
    }
#endif

    return true;
}
예제 #16
0
/*****************************************************************************
 * FUNCTION: RawGetByte
 *
 * RETURNS: error code
 *
 * PARAMS:
 *      rawId   - RAW ID
 *      pBuffer - Buffer to read bytes into
 *      length  - number of bytes to read
 *
 *  NOTES: Reads bytes from the RAW engine
 *****************************************************************************/
void RawGetByte(uint16_t rawId, uint8_t *pBuffer, uint16_t length)
{
    uint8_t regId;
#if defined(OUTPUT_RAW_TX_RX)
    uint16_t i;
#endif

    /* if reading a data message do following check */
    if (!g_WaitingForMgmtResponse)
    {
        // if RAW index previously set out of range and caller is trying to do illegal read
        if ( (rawId==RAW_RX_ID)         && 
              g_rxIndexSetBeyondBuffer  && 
              (GetRawWindowState(RAW_RX_ID) == WF_RAW_DATA_MOUNTED) ) 
        {
            SYS_ASSERT(false, "");  /* attempting to read past end of RAW buffer */
        }
    }

    regId = (rawId==RAW_ID_0)?RAW_0_DATA_REG:RAW_1_DATA_REG;
    ReadWFArray(regId, pBuffer, length);

#if defined(OUTPUT_RAW_TX_RX)
    for (i = 0; i < length; ++i)
    {
        char buf[16];
        sprintf(buf,"R: %#x\r\n", pBuffer[i]);
        SYS_CONSOLE_MESSAGE(buf);
    }    
#endif

}
예제 #17
0
bool AllocateDataTxBuffer(uint16_t bytesNeeded)
{
    uint16_t bufAvail;
    uint16_t byteCount;
    
    /* Ensure the MRF24W is awake (only applies if PS-Poll was enabled) */
    EnsureWFisAwake();
    
    /* get total bytes available for DATA tx memory pool */
    bufAvail = Read16BitWFRegister(WF_HOST_WFIFO_BCNT0_REG) & 0x0fff; /* LS 12 bits contain length */                    
    
        /* if enough bytes available to allocate */
    if ( bufAvail >= bytesNeeded )
    {
        /* allocate and create the new Tx buffer (mgmt or data) */
        byteCount = RawMove(RAW_TX_ID, RAW_DATA_POOL, true, bytesNeeded);
        SYS_ASSERT(byteCount != 0, "");
    }
    /* else not enough bytes available at this time to satisfy request */
    else
    {
        return false;
    }
    
    RawWindowReady[RAW_TX_ID] = true;
    SetRawWindowState(RAW_TX_ID, WF_RAW_DATA_MOUNTED);
    return true;

}    
예제 #18
0
/*******************************************************************************
  Function:    
    void WF_MulticastGetConfig(uint8_t filterId, t_wfMultiCastConfig *p_config);

  Summary:
    Gets a multicast address filter from one of the two multicast filters.

  Description:
    Gets the current state of the specified Multicast Filter. 

    Normally would call SendGetParamMsg, but this GetParam returns all 6 address 
    filters + 2 more bytes for a total of 48 bytes plus header. So, doing this 
    msg manually to not require a large stack allocation to hold all the data.                                                                                  
    
    Exact format of management message stored on device is:                                                                
    [0]     -- always mgmt response (2)
    [1]     -- always WF_GET_PARAM_SUBTYPE (16)
    [2]     -- result (1 if successful)
    [3]     -- mac state (not used)
    [4]     -- data length (length of response data starting at index 6)
    [5]     -- not used
    
    [6-11]  -- Compare Address 0 address
    [12]    -- Compare Address 0 group
    [13]    -- Compare Address 0 type
    [14]    -- Compare Address 0 macBitMask
    [15-17] -- Not used
    
    [18-23] -- Compare Address 1 address
    [24]    -- Compare Address 1 group
    [25]    -- Compare Address 1 type
    [26]    -- Compare Address 1 macBitMask
    [27-29] -- Not used
    
    [30-35] -- Compare Address 2 address
    [36]    -- Compare Address 2 group
    [37]    -- Compare Address 2 type
    [38]    -- Compare Address 2 macBitMask
    [39-41] -- Not used
    
    [42-47] -- Compare Address 3 address
    [48]    -- Compare Address 3 group
    [49]    -- Compare Address 3 type
    [50]    -- Compare Address 3 macBitMask
    [51-53] -- Not used
    
    [54-59] -- Compare Address 4 address
    [60]    -- Compare Address 4 group
    [61]    -- Compare Address 4 type
    [62]    -- Compare Address 4 macBitMask
    [63-65] -- Not used
    
    [66-71] -- Compare Address 5 address
    [72]    -- Compare Address 5 group
    [73]    -- Compare Address 5 type
    [74]    -- Compare Address 5 macBitMask
    [75-77] -- Not used

  Precondition:
    MACInit must be called first.  

  Parameters:
    filterId -- ID of filter being retrieved.  Must be:
                  DRV_WIFI_MULTICAST_FILTER_1 or DRV_WIFI_MULTICAST_FILTER_2
    
    p_config -- Pointer to config structure filled in by this function.

  Returns:
    None.
      
  Remarks:
    None.
 *****************************************************************************/
void WF_MulticastGetConfig(uint8_t filterId, DRV_WIFI_SWMULTICAST_CONFIG *p_config)
{
    uint8_t  hdr[4];
    uint8_t  paramData[12];

    SYS_ASSERT( (filterId <= DRV_WIFI_MULTICAST_FILTER_16), "");

    hdr[0] = WF_MGMT_REQUEST_TYPE;
    hdr[1] = WF_GET_PARAM_SUBTYPE;
    hdr[2] = 0x00;                      /* MS 8 bits of param Id, always 0 */
    hdr[3] = PARAM_COMPARE_ADDRESS;     /* LS 8 bits of param ID           */
    
    SendMgmtMsg(hdr,             /* header              */
                sizeof(hdr),     /* size of header      */
                &filterId,       /* multicast filter id */
                1);              /* length is 1         */

    WaitForMgmtResponseAndReadData(WF_GET_PARAM_SUBTYPE,       /* expected subtype                           */ 
                                   sizeof(paramData),          /* num data bytes to read                     */
                                   MSG_PARAM_START_DATA_INDEX, /* starting at this index                     */
                                   paramData);                 /* write the response data here               */
    
    /* put param data into return structure */
    p_config->filterId = filterId;
    memcpy((void *)p_config->macBytes, (void *)&paramData[0], 6);
    p_config->action = paramData[7];
    p_config->macBitMask = paramData[8];
}                                   
예제 #19
0
/*******************************************************************************
  Function:
    void DRV_WIFI_HWMulticastFilterSet(uint8_t multicastFilterId,
                                       uint8_t multicastAddress[6])

  Summary:
    Sets a multicast address filter using one of the two hardware multicast filters.

  Description:
    This function allows the application to configure up to two hardware Multicast
    Address Filters on the MRF24W.  If two active multicast filters are set
    up they are OR’d together – the MRF24W will receive and pass to the Host
    CPU received packets from either multicast address.
    The allowable values for the multicast filter are:
    * DRV_WIFI_MULTICAST_FILTER_1
    * DRV_WIFI_MULTICAST_FILTER_2

    By default, both Multicast Filters are inactive.

  Parameters:
    multicastFilterId - DRV_WIFI_MULTICAST_FILTER_1 or DRV_WIFI_MULTICAST_FILTER_2
    multicastAddress  - 6-byte address (all 0xFF will inactivate the filter)

  Returns:
  	None.
  *****************************************************************************/
void DRV_WIFI_HWMulticastFilterSet(uint8_t multicastFilterId,
                                   uint8_t multicastAddress[6])
{
    int i;
    bool deactivateFlag = true;
    uint8_t msgData[8];
    
    SYS_ASSERT( ((multicastFilterId == DRV_WIFI_MULTICAST_FILTER_1) || (multicastFilterId == DRV_WIFI_MULTICAST_FILTER_2)), "" );
    
    /* check if all 6 bytes of the address are 0xff, implying that the caller wants to deactivate */
    /* the multicast filter.                                                                      */
    for (i = 0; i < 6; ++i)
    {
        /* if any byte is not 0xff then a presume a valid multicast address */
        if (multicastAddress[i] != 0xff)
        {
            deactivateFlag = false;
            break;
        }    
    }  
    
    msgData[0] = multicastFilterId;     /* Address Compare Register number to use   */
    if (deactivateFlag)
    {
        msgData[1] = ADDRESS_FILTER_DEACTIVATE;
    }    
    else
    {
        msgData[1] = MULTICAST_ADDRESS;     /* type of address being used in the filter */  
    }
    memcpy(&msgData[2], (void *)multicastAddress, WF_MAC_ADDRESS_LENGTH);

    SendSetParamMsg(PARAM_COMPARE_ADDRESS, msgData, sizeof(msgData) ); 
}    
예제 #20
0
void SYS_Initialize ( void * data )
{
    /* Configure the cache and flash wait
     * states for 80MHz. */

    SYSTEMConfigPerformance(80000000);

    /* Initializethe interrupt system  */
    SYS_INT_Initialize();

    /* Initialize the global interrupts */
    SYS_INT_Enable();

    SYS_INT_VectorPrioritySet(INT_VECTOR_USB, INT_PRIORITY_LEVEL4);
    SYS_INT_VectorSubprioritySet(INT_VECTOR_USB, INT_SUBPRIORITY_LEVEL0);
    SYS_INT_VectorPrioritySet(INT_VECTOR_CT, INT_PRIORITY_LEVEL3);
    SYS_INT_VectorSubprioritySet(INT_VECTOR_USB, INT_SUBPRIORITY_LEVEL0);

    BSP_Initialize();

    /* Initialize the USB device layer */
    deviceLayerObject = USB_DEVICE_Initialize (USB_DEVICE_INDEX_0 ,
            ( SYS_MODULE_INIT* ) & usbDevInitData);

    /* check if the object returned by the device layer is valid */
    SYS_ASSERT((SYS_MODULE_OBJ_INVALID != deviceLayerObject), "Invalid USB DEVICE object");

    /* Initialize the Application */
    APP_Initialize ( );
}
예제 #21
0
파일: drv_usb.c 프로젝트: ctapang/v0_70_01b
void DRIVER DRV_USB_Tasks_ISR( SYS_MODULE_OBJ object )
{
    DRV_USB_OBJ * 	hDriver; 
    hDriver = &gDrvUSBObj[object];
    hDriver->isInInterruptContext = true;

	switch(hDriver->operationMode)
	{
	case USB_OPMODE_DEVICE:
            _DRV_USB_DEVICE_TASKS_ISR(hDriver);
            break;
        case USB_OPMODE_HOST:
            _DRV_USB_HOST_TASKS_ISR(hDriver);
            break;
        case USB_OPMODE_OTG:
            break;
        default:
            SYS_ASSERT(false, "What mode are you trying?");
            break;
	}	
  
    /* Clear the interrupt */
    _DRV_USB_InterruptSourceClear(hDriver->interruptSource);
    hDriver->isInInterruptContext = false;
}
예제 #22
0
/*****************************************************************************
 * Function:
 * SYS_FS_MEDIA_BUFFER_HANDLE SYS_FS_MEDIA_MANAGER_SectorWrite
 *   (
 *       uint16_t diskNo,
 *       uint32_t sector,
 *       uint8_t * dataBuffer,
 *       uint32_t noSectors
 *   )
 *
 * Description:
 * Function to write to a sector of specified media (disk). This is the function in
 * media manager layer. This function in turn call the specific sector write function from
 * the list of function pointer of media driver.
 *
 * Precondition:
 *   None
 *
 * Parameters:
 *   diskNo         - media number
 *   sector         - Sector # to which data to be written
 *   dataBuffer     - pointer to buffer which holds the data to be written
 *   noSectors      - Number of sectors to be written
 *
 * Returns:
 *   Buffer handle of type SYS_FS_MEDIA_BUFFER_HANDLE
*/
SYS_FS_MEDIA_BUFFER_HANDLE SYS_FS_MEDIA_MANAGER_SectorWrite
(
    uint16_t diskNo,        /* SYS_FS_MEDIA disk no */
    uint32_t sector,        /* Start sector */
    uint8_t * dataBuffer,   /* Application buffer */
    uint32_t noSectors      /* Number of sectors to write */
)
{
	volatile SYS_FS_MEDIA *media;
	
	if(diskNo >= SYS_FS_VOLUME_NUMBER)
	{
		SYS_ASSERT(false, "Invalid Disk");
		return SYS_FS_MEDIA_BUFFER_HANDLE_INVALID;
	}	
	
	media = &gSYSFSMediaObject[diskNo];

        if(media->mediaDriverClientHandle == DRV_HANDLE_INVALID)
        {
            return SYS_FS_MEDIA_HANDLE_INVALID;
        }
                
        return(media->mediaDriverFunctions->sectorWrite(media->mediaDriverClientHandle,
                                                          sector, dataBuffer, noSectors));

}
예제 #23
0
bool DRIVER _DRV_USB_MAKE_NAME(DEVICE_EndpointIsStalled)(DRV_HANDLE client,
                                        USB_ENDPOINT endpointAndDirection)
{
    /* Return the state of the endpoint */

    DRV_USB_DEVICE_ENDPOINT_OBJ * endpointObj;
    uint8_t endpoint = endpointAndDirection & 0xF;
    int direction = ((endpointAndDirection & 0x80) != 0);

    if(DRV_HANDLE_INVALID == client)
    {
        SYS_ASSERT(false, "Driver Handle is invalid");
        return false;
    }

    endpointObj = _DRV_USB_ENDPOINT_OBJ(endpoint, direction);
    
    if((endpointObj->endpointState & 
                DRV_USB_DEVICE_ENDPOINT_STATE_STALLED) != 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}
예제 #24
0
void SYS_CLK_Initialize ( const SYS_CLK_INIT *clkInit )
{
    CLK_SOURCES_SYSTEM systemSource;
    uint32_t clockClosest = 0;

    /* If the user has not passed anything that means he want to retain the
     * configuration bit settings  */
    if ( clkInit != NULL )
    {
        systemSource = PLIB_OSC_CurrentSysClockGet ( OSC_PLIB_ID );

        if (!_SYS_CLK_SystemClockSet ( systemSource, clkInit->systemClockFrequencyHz,
                clkInit->waitTillComplete, &clockClosest ))
        {
            SYS_ASSERT(false, "Critical failure when setting system clock");
            return;
        }
        
        #if defined(PLIB_OSC_ExistsOnWaitAction)
        if ( PLIB_OSC_ExistsOnWaitAction ( OSC_PLIB_ID ) )
        {
            /* Sets the oscillator's response to a 'Wait' instruction */
            PLIB_OSC_OnWaitActionSet ( OSC_PLIB_ID, clkInit->onWaitInstruction );
        }
        #endif
    }
    else
    {
        clkObject.systemClock = _SYS_CLK_SystemClockRead ();
    }

    clkObject.callback=NULL;
}
예제 #25
0
static void renderer_addSingleStroke( const float2* pStrokePoints, uint strokePointCount )
{
    SYS_ASSERT( s_renderer.pageState == PageState_BeforeDraw );
    if( !pStrokePoints || strokePointCount < 2u )
    {
        return;
    }
    
    const int isCycle=float2_isEqual(&pStrokePoints[0u],&pStrokePoints[strokePointCount-1u]);
    
    StrokeCommand command;
    createDrawCommand( &command );

    const float variance = s_renderer.currentVariance;

    // transform, randomize and copy positions
    for( uint i = 0u; i < strokePointCount; ++i )
    {
        const float2 strokePoint = pStrokePoints[ i ];

        // reduced variance in the beginning
        const int isFirstVertexInStroke = command.data.draw.pointCount == 0u;

        float2 point;
        transformPoint( &point, &strokePoint, isFirstVertexInStroke ? variance / 4.0f : variance );
        if( pushStrokePoint( &point ) )
        {
            command.data.draw.pointCount++;
        }
    }
   
    computeStrokeNormals( &command, isCycle );
    pushStrokeCommand( &command );
}
예제 #26
0
static int Open(void * hwnd)
{
    CGLRendererInfoObj renderer;
    long numRenderer;
	CGDirectDisplayID l[32];
	CGDisplayCount count;

	SYS_ASSERT(g_pCGLC == 0);
	UNUSED(hwnd);
	CGGetActiveDisplayList (sizeof(l), l, &count);

#ifdef _DEBUG
	// Debug in multiple monitor. Use the secondary monitor for rendering
	g_cgDisplayID = l[count-1];
#else
	g_cgDisplayID = CGMainDisplayID ();
#endif

	g_cgPrevDisplayMode = CGDisplayCurrentMode (g_cgDisplayID);
	g_cgDisplayModeList = CGDisplayAvailableModes (g_cgDisplayID);

    CGLQueryRendererInfo(CGDisplayIDToOpenGLDisplayMask(g_cgDisplayID), &renderer, &numRenderer);
    CGLDestroyRendererInfo(renderer);

    return 0;
}
예제 #27
0
void NG_FXLoadList()
{
	FILE *in = FIO_cur->fopen(".\\anim\\anim.lst", "rb");
	SYS_ASSERT(in);
    g_pszAnimList = array_loadtext(in, 32, -1);
    FIO_cur->fclose(in);
}
예제 #28
0
/*****************************************************************************
 * FUNCTION: RawSetByte
 *
 * RETURNS: None
 *
 * PARAMS:
 *      rawId   - RAW ID
 *      pBuffer - Buffer containing bytes to write
 *      length  - number of bytes to read
 *
 *  NOTES: Writes bytes to RAW window
 *****************************************************************************/
void RawSetByte(uint16_t rawId, uint8_t *pBuffer, uint16_t length)
{
    uint8_t regId;
#if defined(OUTPUT_RAW_TX_RX)
    uint16_t i;
#endif    


    /* if previously set index past legal range and now trying to write to RAW engine */
    if ( (rawId == 0) && g_rxIndexSetBeyondBuffer && (GetRawWindowState(RAW_TX_ID) == WF_RAW_DATA_MOUNTED) )
    {
        SYS_ASSERT(false, "");  /* attempting to write past end of RAW window */
    }

    /* write RAW data to chip */
    regId = (rawId==RAW_ID_0)?RAW_0_DATA_REG:RAW_1_DATA_REG;
    WriteWFArray(regId, pBuffer, length);

#if defined(OUTPUT_RAW_TX_RX)
    for (i = 0; i < length; ++i)
    {
        char buf[16];
        sprintf(buf,"T: %#x\r\n", pBuffer[i]);
        SYS_CONSOLE_MESSAGE(buf);
    }    
#endif

}
예제 #29
0
bool AllocateMgmtTxBuffer(uint16_t bytesNeeded)
{
    uint16_t bufAvail;
    uint16_t byteCount;
    
    /* get total bytes available for MGMT tx memory pool */
    bufAvail = Read16BitWFRegister(WF_HOST_WFIFO_BCNT1_REG) & 0x0fff; /* LS 12 bits contain length */                    
    
    /* if enough bytes available to allocate */
    if ( bufAvail >= bytesNeeded )
    {
        /* allocate and create the new Tx buffer (mgmt or data) */
        byteCount = RawMove(RAW_TX_ID, RAW_MGMT_POOL, true, bytesNeeded);
        SYS_ASSERT(byteCount != 0, "");
    }
    /* else not enough bytes available at this time to satisfy request */
    else
    {
        return false;
    }
    
    RawWindowReady[RAW_TX_ID] = true;
    SetRawWindowState(RAW_TX_ID, WF_RAW_MGMT_MOUNTED);
    
    return true;
}    
예제 #30
0
int32_t DRV_SPI1_ISRErrorTasks(struct DRV_SPI_OBJ * dObj)
{

    if (dObj->currentJob == NULL)
    {
        return 0;
    }

    register DRV_SPI_JOB_OBJECT * currentJob = dObj->currentJob;

    if (PLIB_SPI_ReceiverHasOverflowed(SPI_ID_2))
    {
        if (currentJob->completeCB != NULL)
        {
            (*currentJob->completeCB)(DRV_SPI_BUFFER_EVENT_ERROR, (DRV_SPI_BUFFER_HANDLE)currentJob, currentJob->context);
        }
        currentJob->status = DRV_SPI_BUFFER_EVENT_ERROR;
        if (dObj->operationEnded != NULL)
        {
            (*dObj->operationEnded)(DRV_SPI_BUFFER_EVENT_ERROR, (DRV_SPI_BUFFER_HANDLE)currentJob, currentJob->context);
        }
        if (DRV_SPI_SYS_QUEUE_FreeElement(dObj->queue, currentJob) != DRV_SPI_SYS_QUEUE_SUCCESS)
        {
            SYS_ASSERT(false, "\r\nSPI Driver: Queue free element error.");
            return 0;
        }
        dObj->currentJob = NULL;
        PLIB_SPI_BufferClear(SPI_ID_2);
        PLIB_SPI_ReceiverOverflowClear (SPI_ID_2 );
        SYS_INT_SourceStatusClear(INT_SOURCE_SPI_2_ERROR);

    }
    return 0;
}