/* * Copyright (c) 2010-2015, Texas Instruments Incorporated * All rights reserved. * * 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 platform.h * * @brief The Platform Library is a thin utility * layer on top of CSL and other board utilities. It provides uniform APIs * for all supported platforms. It aims to assist user to quickly write portable * applications for its supported platforms by hiding board level details * from the user. * * */ #ifndef PLATFORM_UTILS_H_ #define PLATFORM_UTILS_H_ /** * @mainpage Platform Utility APIs * Defines a set of APIs for accessing and working with the various platform peripherals. * */ /** @defgroup Platform_standard_data_types Standard Data Types */ /*@{*/ /** * @brief Platform Library uses basic C99 data types. The basic types used are * uint32_t, int32_t, uint8_t, int8_t, uint16_t and int16_t. The standard * C char is used for strings. Complex types (or typdefs) if used are defined * within this header file. */ #include #define EXAMPLE_VARIABLE uint32_t /*@}*/ /* defgroup */ /** @defgroup Platform_memory_section Linker Memory Sections */ /*@{*/ /** * @brief Memory Sections. You need to place these in your application linker map. * * Section name: PLATFORM_LIB_SECTION * * All of the static information used within the platform library is stored * within this section. */ #define PLATFORM_LIB_SECTION "This section defines the memory section for the platform library" /*@}*/ /* defgroup */ /** @defgroup Platform_cache Platform Cache */ /*@{*/ /** * @brief The following definitions are for handling cache alignment on the platform. * * MAX_CACHE_LINE must be set to the cache line size of the platform. * * When allocating memory that must be cache aligned, it must be a multiple of * the cache line size. Use platform_roundup to get the appropriate size. * * As an example to allocate a cache aligned block of memory you would do * something like: * * buffer_len_aligned = platform_roundup (buffer_len, MAX_CACHE_LINE) * Malloc (buffer_len_aligned) * */ /* w should be power of 2 */ #define PLATFORM_CACHE_LINE_SIZE (128) #define platform_roundup(n,w) (((n) + (w) - 1) & ~((w) - 1)) /** * @n@b Convert_CoreLocal2GlobalAddr * * @b Description * @n This API converts a core local L2 address to a global L2 address. * * @param[in] addr L2 address to be converted to global. * * @return uint32_t >0 Global L2 address * */ uint32_t Convert_CoreLocal2GlobalAddr (uint32_t addr); /*@}*/ /* defgroup */ /** @defgroup Compilation_Flags Compilation Flags */ /*@{*/ /*** * @brief Flags for compiling the library. * * The file paltform_internal.h has compilation flags that can be set. */ /*@}*/ /* defgroup */ /** @defgroup Platform_common Common */ /*@{*/ /** * Error codes used by Platform functions. Negative values are errors, * while positive values indicate success. */ #define Platform_STATUS int32_t /** Platform API return type */ #define Platform_EINVALID -3 /**< Error code for invalid parameters */ #define Platform_EUNSUPPORTED -2 /**< Error code for unsupported feature */ #define Platform_EFAIL -1 /**< General failure code */ #define Platform_EOK 0 /**< General success code */ /* Set the endianess for the platform */ #define PLATFORM_LE 1 #define PLATFORM_BE 0 #define PLATFORM_MAX_EMAC_PORT_NUM 2 /**< Maximum number of EMAC ports */ /** * @brief This structure contains multicore processor information, e.g. # of the core, processor name, etc. */ typedef struct { int32_t core_count; /** C64x CPU, 10h -> C64x+ CPU).*/ uint16_t revision_id; /** Wait for ever. * * @retval Platform_EOK on Success * */ Platform_STATUS platform_uart_read(uint8_t *buf, uint32_t delay); /** * @brief Write a character to the UART * * @param[in] chr character to write * * * @retval Platform_EOK on Success * */ Platform_STATUS platform_uart_write(uint8_t chr); /** * @brief Platform Write * * @param[in] *fmt printf style vararg * * @retval Nothing (but platform_errno may get set) * * @remark This routine will output the printf style string * to one or both of the UART and/or through a printf * call (in CCS this is mapped to the console window). * By default, both are written. This can be controlled * by setting write_type in the paltform_init structure. * By default, both the UART and printf outputs are used. * * The largest string size you can write is 80 characters. * Some checking is performed (on the fmt string only) to be * sure it is under that length. Note that expansion could * set the string higher and therefore corrupt memory. * * User platform_write_configure to control where the * output appears. The call retturns the previous setting. * * This call is not intended to be used for serious debugging. * Its purpose is light duty writing of messages. It should not * be called from an interrupt context as it uses printf when * writing to the console. The following wiki articles are good * write ups on printf vs. system_printf vs. real time tracing * http://processors.wiki.ti.com/index.php/Printf_support_in_compiler * http://processors.wiki.ti.com/index.php/Tips_for_using_printf */ void platform_write(const char *fmt, ...); WRITE_info platform_write_configure (WRITE_info write_type); /** * \brief Reads input from scanf or UART or both * * This function uses the same configuration as platform_write which is * set using platform_write_configure() * * \param data [OUT] Buffer to store the user input * \param length [IN] Number of bytes to read * * \return - Number of bytes read successfully */ uint32_t platform_read(uint8_t *data, uint32_t length); #ifdef DEVICE_K2G /** * \brief Connfigures the input source for platform_read * * \param rdype [IN] Input source for read * * \return - Input source for read before applying new configuration */ READ_info platform_read_configure (READ_info rdype); #endif /*@}*/ /* defgroup */ /** * ============================================================================ * @n@b platform_fpgaWriteConfigReg * * @brief This function writes to spicified FPGA configuration reg. * * @param[in] uchAddress The FPGA offset address that you want to write * * @param[in] uchValue The value you want to write * * @retval 0 on Success * * @remark Please refer to the specific EVM technical reference manual for a full list of FPGA register offset address. * @verbatim uint8_t uchValue = 0; uint8_t uchAdd = (0x08); ret = platform_fpgaWriteConfigReg(uchAdd, uchValue); * @return None * ============================================================================= */ uint32_t platform_fpgaWriteConfigReg(uint8_t uchAddress, uint8_t uchValue); /** * ============================================================================ * @n@b platform_fpgaReadConfigReg * * @brief This function reads spicified FPGA configuration reg. * * @param[in] uchAddress The FPGA offset address that you want to read * * @param[in] uchValue The pointer to store the read value * * @retval 0 on Success * * @remark Please refer to the specific EVM technical reference manual for a full list of FPGA register offset address. * @verbatim uint8_t uchValue = 0; uint8_t uchAdd = (0x08); ret = platform_fpgaReadConfigReg(uchAdd, &uchValue); * @return None * ============================================================================= */ uint32_t platform_fpgaReadConfigReg(uint8_t uchAddress, uint8_t *puchValue); /** @defgroup Utility_functions Utility Functions */ /*@{*/ /** LED operation */ typedef enum { /** Turn off LED */ PLATFORM_LED_OFF = 0, /** Turn on LED */ PLATFORM_LED_ON = 1 } PLATFORM_LED_OP; /** * @brief Perform LED operation * * @param[in] led_id LED ID * * @param[in] operation LED operation * * @param[in] led_class LED Class * * @retval Platform_EOK on Success * */ Platform_STATUS platform_led(uint32_t led_id, PLATFORM_LED_OP operation, LED_CLASS_E led_class); /** * @brief Get user switch state * * @param[in] switch_id Switch ID * * @retval returns switch state (0 or 1) * */ uint32_t platform_get_switch_state(uint32_t id); /** * @brief Delay function. The call to this function returns after * specified amount of time. * * @param[in] usecs Delay value in micro-seconds * * @retval Platform_EOK on Success * */ Platform_STATUS platform_delay(uint32_t usecs); /** * @brief Delay function. The call to this function returns after * specified amount of time. It uses the TSCL where 1 TCSL * tick is 1 cycle. * * @param[in] cycles Delay value in clock cycles * * @retval None * */ void platform_delaycycles(uint32_t cycles); /*@}*/ /* defgroup */ /** @defgroup OSAL_functions OSAL Functions * These routines are called from Platform Library and must be implemented by the Application. */ /*@{*/ /** * ============================================================================ * @n@b Osal_platformMalloc * * @b brief * @n This API is used by platform_library to allocate memory. Applications * must provide this function and attach it to their memory allocator. * * @param[in] num_bytes * Number of bytes to be allocated. * @param[in] alignment * byte alignment needed * * @return * Allocated block address * ============================================================================= */ uint8_t *Osal_platformMalloc (uint32_t num_bytes, uint32_t alignment); /** * ============================================================================ * @n@b Osal_platformFree * * @b brief * @n Frees up memory allocated using * @a Osal_platformMalloc () * * Applications must provide this function and attach it to ther memory * free handler. * * @param[in] dataPtr * Pointer to the memory block to be cleaned up. * * @param[in] num_bytes * Size of the memory block to be cleaned up. * * @return * Not Applicable * ============================================================================= */ void Osal_platformFree (uint8_t *dataPtr, uint32_t num_bytes); /** * ============================================================================ * @n@b Osal_platformSpiCsEnter * * @b brief * @n This API ensures multi-core and multi-threaded * synchronization for the SPI bus. * * This is a BLOCKING API. * * * @return * @n Handle used to lock critical section * ============================================================================= */ void Osal_platformSpiCsEnter(void); /** * ============================================================================ * @n@b Osal_platformSpiCsExit * * @b brief * @n This API needs to be called to exit a previously * acquired critical section lock using @a Osal_platformSpiCsEnter () * API. It resets the multi-core and multi-threaded lock, * enabling another process/core to grab the SPI bus. * * * @return None * ============================================================================= */ void Osal_platformSpiCsExit (void); /*@}*/ /* defgroup */ /** @defgroup Error_handling Error Handling (Errno values) */ /*@{*/ /** * @brief platform_errno variable may be set to a non-zero value when * a platform library call returns an error. * * The errno value is not preserved. The calling application must * save off the value if the platform function call fails. */ extern uint32_t platform_errno; /** Platform errno values */ #define PLATFORM_ERRNO_RESET 0 /**< No error */ #define PLATFORM_ERRNO_GENERIC 0x00000001 #define PLATFORM_ERRNO_INVALID_ARGUMENT 0x00000002 /**< NULL pointer, argument out of range, etc */ #define PLATFORM_ERRNO_PLL_SETUP 0x00000003 /**< Error initializing */ #define PLATFORM_ERRNO_EEPROM 0x00000004 /**< Error initializing */ #define PLATFORM_ERRNO_UART 0x00000005 /**< Error initializing */ #define PLATFORM_ERRNO_LED 0x00000006 /**< Error initializing */ #define PLATFORM_ERRNO_I2C 0x00000007 /**< Error initializing */ #define PLATFORM_ERRNO_MEMTEST 0x00000008 /**< Error initializing */ #define PLATFORM_ERRNO_PHY 0x00000009 /**< Error initializing */ #define PLATFORM_ERRNO_NAND 0x0000000a /**< Error initializing */ #define PLATFORM_ERRNO_NOR 0x0000000b /**< Generic error in NOR */ #define PLATFORM_ERRNO_UNSUPPORTED 0x0000000c /**< Functionality not supported */ #define PLATFORM_ERRNO_ECC_FAIL 0x00000010 /**< The ECC calculation for the page read doesn't match. The application can try re-reading. */ #define PLATFORM_ERRNO_BADFLASHDEV 0x00000011 /**< The flash routines did no not recognize the flash manufacturer */ #define PLATFORM_ERRNO_FLASHADDR 0x00000012 /**< The block or page number specified does not exist for the Flash */ #define PLATFORM_ERRNO_NANDBBT 0x00000013 /**< Could not update the NAND Bad Block Table */ #define PLATFORM_ERRNO_NORADDR 0x00000014 /**< Address for NOR does not exist */ #define PLATFORM_ERRNO_NOFREEBLOCKS 0x00000015 /**< There were not enough consecutive free blocks to write the data (based on your starting block number)*/ #define PLATFORM_ERRNO_DEV_TIMEOUT 0x00000020 /**< There was an idle timeout waiting on a device action */ #define PLATFORM_ERRNO_DEV_NAK 0x00000021 /**< The device NAK'd the command */ #define PLATFORM_ERRNO_DEV_BUSY 0x00000022 /**< The device reported a busy state and could not complete the operation */ #define PLATFORM_ERRNO_DEV_FAIL 0x00000023 /**< Device returned a failed status */ #define PLATFORM_ERRNO_PSCMOD_ENABLE 0x00000024 /**< Unable to enable the PSC Module */ #define PLATFORM_ERRNO_OOM 0x00000030 /**< Out of memory.. tried to allocate RAM but could not. */ #define PLATFORM_ERRNO_READTO 0x00000040 /**< UART read timeout */ #define PLATFORM_ERRNO_AUDIO 0x00000050 /**< Generic in Audio module */ #define PLATFORM_ERRNO_AUDIO_INIT 0x00000051 /**< Error in Audio module initialization */ #define PLATFORM_ERRNO_AUDIO_CFG 0x00000052 /**< Error in Audio module configuration */ #define PLATFORM_ERRNO_AUDIO_STATUS 0x00000053 /**< Error in readig Audio module status */ /*@}*/ /* defgroup */ /** @defgroup Platform_common Common */ /*@{*/ /** * @brief Platform PLL init sequence return code * * @remark This might be deprecated in future release of platform library */ extern uint32_t platform_init_return_code; /*@}*/ /* defgroup */ #ifdef DEVICE_K2G /** @defgroup k2g Platform Specific function */ /*@{*/ /** * @brief Prints MMC/SD card information * * @param[in] handle Flash device handle from the open * * @retval Platform_EOK on Success * */ Platform_STATUS platform_device_print_info(PLATFORM_DEVHANDLE handle); /** * @brief Configures MMC/SD card speed * * @param[in] handle Flash device handle from the open * * @param[in] speed Device speed value to set * * @retval Platform_EOK on Success * */ Platform_STATUS platform_device_set_speed(PLATFORM_DEVHANDLE deviceid, uint32_t speed); /** * @brief Configures MMC/SD bus width * * @param[in] handle Flash device handle from the open * * @param[in] width Bus width * * @retval Platform_EOK on Success * */ Platform_STATUS platform_device_set_bus_width(PLATFORM_DEVHANDLE deviceid, PLATFORM_MMCSD_BUS_WIDTH width); /** * @brief Sets flash device parameters * * Function to set configuration parameters for different flash devices * supported by the platform library. * * This API is intended to be extended for different devices and flexible to * to add new members to the supported device parameter structures. * For better portability and extendability, it is recommended that any * implementation in this API shall access the individual members of the * device parameter structure and avoid any memory operations that will be * done on the structure as a whole. * * Devices supported by this API and parameters structure are listed below * QSPI flash - PLATFORM_QSPI_Params * By default platform library sets Read and write IO modes * of QSPI flash to 'quad mode' which cab be modified using * this structure. * * @param[in] handle Flash device handle from the open * * @param[in] params Pointer to parameter structure * * @retval Platform_EOK on Success * */ Platform_STATUS platform_device_set_params(PLATFORM_DEVHANDLE deviceid, void *params); /*@}*/ /* defgroup */ #endif /* #ifdef DEVICE_K2G */ #endif