/*
 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ 
 * 
 *  Redistribution and use in source and binary forms, with or without 
 *  modification, are permitted provided that the following conditions 
 *  are met:
 *
 *    Redistributions of source code must retain the above copyright 
 *    notice, this list of conditions and the following disclaimer.
 *
 *    Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the 
 *    documentation and/or other materials provided with the   
 *    distribution.
 *
 *    Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

/**
 *   @file  emac_osal.h
 *
 *   @brief   
 *      This is the sample OS Adaptation layer which is used by the EMAC 
 *      low level driver. 
 *    
 *   @details The OSAL layer can be ported to a native OS:
 */
#ifndef _EMAC_OSAL_H
#define _EMAC_OSAL_H

/** @addtogroup EMAC_LLD_OSAL
 @{ */
 
/**********************************************************************
 ************************* Extern Declarations ************************
 **********************************************************************/
extern void* Osal_emacMalloc(Uint32 size);
extern void  Osal_emacFree (void* ptr, Uint32 size);
extern void  Osal_emacBeginMemAccess (void* addr, Uint32 size);
extern void  Osal_emacEndMemAccess   (void* addr, Uint32 size);
extern void  Osal_emacEnterSingleCoreCriticalSection(Uint32 port_num);
extern void  Osal_emacExitSingleCoreCriticalSection(Uint32 port_num);
extern void  Osal_emacEnterMultipleCoreCriticalSection(Uint32 port_num);
extern void  Osal_emacExitMultipleCoreCriticalSection(Uint32 port_num);


/**
 * @brief   The macro is used by the EMAC driver to allocate memory
 * The EMAC driver uses this macro to allocate memory for its internal 
 * driver structures. This is invoked during the driver initialization
 * and startup process.
 *
 * <b> Prototype: </b>
 *  The following is the C prototype for the expected OSAL API.
 *
 *  @verbatim
       void* Osal_emacMalloc(Uint32 size)
    @endverbatim
 *      
 *  <b> Parameter </b>
 *  @n  Number of bytes to be allocated
 *
 *  <b> Return Value </b>
 *  @n  Pointer to the allocated block size
 *
 *  @sa
 *      Emac_osalFree
 */
#define Emac_osalMalloc(X)      Osal_emacMalloc(X)

/**
 * @brief   The macro is used by the EMAC driver to free a previously
 * allocated block of memory
 *
 * <b> Prototype: </b>
 *  The following is the C prototype for the expected OSAL API.
 *
 *  @verbatim
       void Osal_emacFree(void* ptr, Uint32 size)
    @endverbatim
 *      
 *  <b> Parameter </b>
 *  @n  Pointer to the block of memory to be cleaned up.
 *  @n  Size of the allocated memory in bytes which is being freed.
 *
 *  <b> Return Value </b>
 *  @n  Not applicable.
 */
#define Emac_osalFree(X, Y)     Osal_emacFree(X, Y)

/**
 * @brief  This macro is used to alert the application that the EMAC is
 *         going to access common data memory. The application must ensure
 *         cache coherency and semaphores for multi-core applications
 *
 *
 * <b> Prototype: </b>
 *  The following is the C prototype for the expected OSAL API.
 *
 *  @verbatim
        void Osal_emacBeginMemAccess (void* addr, Uint32 size)
    @endverbatim
 *
 *  <b> Parameters </b>
 *  @n  The address of the memory to be accessed
 *  @n  The number of bytes in the memory
 */

#define Emac_osalBeginMemAccess   Osal_emacBeginMemAccess


/**
 * @brief  This macro is used to alert the application that the EMAC
 *         has completed access to common data memory. This call will always
 *         be made following a call to Osal_emacBeginMemAccess and have
 *         the same parameters
 *
 * <b> Prototype: </b>
 *  The following is the C prototype for the expected OSAL API.
 *
 *  @verbatim
        void Osal_emacEndMemAccess (void* addr, Uint32 size)
    @endverbatim
 *
 *  <b> Parameters </b>
 *  @n The address of the memory to be accessed
 *  @n The number of bytes in the memory
 */
 
#define Emac_osalEndMemAccess   Osal_emacEndMemAccess


/**
 * @brief   The macro is used by the EMAC driver to protect its internal shared
 * resources from SINGLE CORE MULTIPLE CONTEXT (thread or ISR) access. If all 
 * the EMAC Driver APIs are being called from threads then this API could 
 * use semaphores. However if the EMAC driver API's are being called from 
 * both ISR & Thread context then the critical section here would need to 
 * disable/enable interrupts. 
 *
 * <b> Prototype: </b>
 *  The following is the C prototype for the expected OSAL API.
 *
 *  @verbatim
       void* Osal_emacEnterSingleCoreCriticalSection(Uint32 port_num)
    @endverbatim
 *
 *  <b> Parameter </b>
 *  @n  EMAC port number 
 *
 *  <b> Return Value </b>
 *  @n  none
 */
#define Emac_osalEnterSingleCoreCriticalSection     Osal_emacEnterSingleCoreCriticalSection


/**
 * @brief   The macro is used to denote the end of the protection of the internal
 * shared resource from SINGLE CORE MULTIPLE CONTEXT access.
 *
 * <b> Prototype: </b>
 *  The following is the C prototype for the expected OSAL API.
 *
 *  @verbatim
       void  Osal_emacExitSingleCoreCriticalSection(Uint32 port_num)
    @endverbatim
 *
 *  <b> Parameter </b>
 *  @n  EMAC port number 
 *
 *  <b> Return Value </b>
 *  @n  None
 */
#define Emac_osalExitSingleCoreCriticalSection      Osal_emacExitSingleCoreCriticalSection


/**
 * @brief   The macro is used by the EMAC Driver to protect its shared resources
 * access from MULTIPLE CORES. This is required if the EMAC Driver API's are being
 * invoked from multiple cores. If this is not the case then these macros can be
 * defined to be NOP.
 *
 * <b> Prototype: </b>
 *  The following is the C prototype for the expected OSAL API.
 *
 *  @verbatim
       void* Osal_emacEnterMultipleCoreCriticalSection(Uint32 port_num)
    @endverbatim
 *
 *  <b> Parameter </b>
 *  @n  EMAC port number 
 *
 *  <b> Return Value </b>
 *  @n  None
 */
#define Emac_osalEnterMultipleCoreCriticalSection      Osal_emacEnterMultipleCoreCriticalSection

/**
 * @brief   The macro is used by the EMAC driver to end the protection of its 
 * internal shared "resources" from MULTIPLE CORE access.
 *
 * <b> Prototype: </b>
 *  The following is the C prototype for the expected OSAL API.
 *
 *  @verbatim
       void  Osal_emacExitMultipleCoreCriticalSection(Uint32 port_num)
    @endverbatim
 *
 *  <b> Parameter </b>
 *  @n  EMAC port number 
 *
 *  <b> Return Value </b>
 *  @n  None
 */
#define Emac_osalExitMultipleCoreCriticalSection      Osal_emacExitMultipleCoreCriticalSection

/**
@}
*/
#endif /* _EMAC_OSAL_H */

