Port of TI's CC3100 Websock camera demo. Using FreeRTOS, mbedTLS, also parts of Arducam for cams ov5642 and 0v2640. Can also use MT9D111. Work in progress. Be warned some parts maybe a bit flacky. This is for Seeed Arch max only, for an M3, see the demo for CM3 using the 0v5642 aducam mini.
Revision 15:5433f9d94cd7, committed 2015-08-28
- Comitter:
- dflet
- Date:
- Fri Aug 28 21:04:44 2015 +0000
- Parent:
- 14:90603ea1e85b
- Child:
- 16:7e5aab2fabba
- Commit message:
- Cam ov2640 working correctly, didnt know it also gave a jpeg header. App still not stable. Still a lot of work needed.
Changed in this revision
--- a/FreeRTOS/FreeRTOSConfig.h Tue Aug 25 22:03:00 2015 +0000 +++ b/FreeRTOS/FreeRTOSConfig.h Fri Aug 28 21:04:44 2015 +0000 @@ -86,7 +86,7 @@ #define configCPU_CLOCK_HZ ( ( unsigned long ) SystemCoreClock ) #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 130 ) -#define configTOTAL_HEAP_SIZE ( ( size_t ) (36 * 1024) ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) (48 * 1024) ) #define configMAX_TASK_NAME_LEN ( 24 ) #define configUSE_TRACE_FACILITY 1 #define configUSE_16_BIT_TICKS 0
--- a/camera_app/camera_app.cpp Tue Aug 25 22:03:00 2015 +0000 +++ b/camera_app/camera_app.cpp Fri Aug 28 21:04:44 2015 +0000 @@ -423,11 +423,13 @@ for(int i =0; i< 100; i++) { HttpDebug("0x%x ",*Image++); } - HttpDebug("\r\n"); + HttpDebug("\r\n"); #endif//if 0 + // // Create JPEG Header // +#ifndef OV2640_CAM #ifdef ENABLE_JPEG memset(g_image.g_header, '\0', sizeof(g_image.g_header)); g_header_length = CreateJpegHeader((char *)&(g_image.g_header[0]), PIXELS_IN_X_AXIS, PIXELS_IN_Y_AXIS, 0, 0x0020, 9); @@ -445,10 +447,12 @@ #endif//if 0 #endif//ENABLE_JPEG - + *WriteBuffer = (char*)Image; + return(g_header_length += g_frame_size_in_bytes); +#endif//OV2640_CAM *WriteBuffer = (char*)Image; - return(g_header_length += g_frame_size_in_bytes); + return(g_frame_size_in_bytes); } //***************************************************************************** //
--- a/camera_app/httpserverapp/httpserverapp.cpp Tue Aug 25 22:03:00 2015 +0000 +++ b/camera_app/httpserverapp/httpserverapp.cpp Fri Aug 28 21:04:44 2015 +0000 @@ -50,7 +50,9 @@ #include "cc3100_sl_common.h" // Free-RTOS/TI-RTOS include +#include "FreeRTOS.h" #include "osi.h" +#include "semphr.h" // HTTP lib includes #include "HttpCore.h" @@ -84,6 +86,13 @@ UINT16 g_uConnection; OsiTaskHandle g_iCameraTaskHdl = 0; +SemaphoreHandle_t xSemaphore = NULL; +void createMutex() +{ + + xSemaphore = xSemaphoreCreateMutex(); +} + void WebSocketCloseSessionHandler() { @@ -193,13 +202,14 @@ int32_t lRetVal = -1; //Start SimpleLink in AP Mode - lRetVal = _cc3100_Mod.Network_IF_InitDriver(ROLE_AP); + lRetVal = _cc3100_Mod.Network_AP_InitDriver(); +// lRetVal = _cc3100_Mod.Network_IF_InitDriver(ROLE_AP); if(lRetVal < 0) { Uart_Write((uint8_t*)"Start SimpleLink in AP Mode Failed \n\r"); LOOP_FOREVER(); } - + osi_Sleep(2); //Stop Internal HTTP Server lRetVal = _cc3100_Mod._netapp.sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID); if(lRetVal < 0)
--- a/camera_app/httpserverapp/httpserverapp.h Tue Aug 25 22:03:00 2015 +0000 +++ b/camera_app/httpserverapp/httpserverapp.h Fri Aug 28 21:04:44 2015 +0000 @@ -52,7 +52,7 @@ }t_mDNSService; - +void createMutex(void); //extern void HttpServerAppTask(void *); //extern void Init3200SimpleLink ( void ); //void InitCameraComponents(int width, int height);
--- a/camera_app/mt9d111/i2cconfig.cpp Tue Aug 25 22:03:00 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,173 +0,0 @@ -//***************************************************************************** -// i2cconfig.c -// -// I2C features APIs -// -// Copyright (C) 2014 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. -// -//***************************************************************************** -//***************************************************************************** -// -//! \addtogroup i2cconfig -//! @{ -// -//***************************************************************************** -#include <stdbool.h> -#include <stdint.h> -#include "mbed.h" - -#include "i2cconfig.h" -#include "cli_uart.h" -#include "myBoardInit.h" - - - -I2C i2c(PB_9, PB_8); - - -//***************************************************************************** -// -//! I2CInit -//! -//! \param Delay -//! \return None -// -//***************************************************************************** -uint32_t I2CInit() -{ - - i2c.frequency (100000); - - return 0; -} -//**************************************************************************** -// -//! Invokes the I2C driver APIs to read from the device. This assumes the -//! device local address to read from is set using the I2CWrite API. -//! -//! \param ucDevAddr is the device I2C slave address -//! \param ucBuffer is the pointer to the read data to be placed -//! \param ulSize is the length of data to be read -//! \param ucFlags Flag -//! -//! This function works in a polling mode, -//! 1. Writes the device register address to be written to. -//! 2. In a loop, reads all the bytes over I2C -//! -//! \return 0: Success, < 0: Failure. -// -//**************************************************************************** -int32_t I2CBufferRead(int32_t ucDevAddr, uint8_t *ucBuffer, - int32_t ulSize, unsigned char ucFlags) -{ -// Uart_Write((uint8_t*)"I2CBufferRead \n\r"); -/* - i2c.start(); - - // Set I2C slave read address - i2c.write(ucDevAddr); - if(ulSize == 1){ - ucBuffer[0] = i2c.read(0); - }else{ - for(int i=0;i<ulSize;i++){ - ucBuffer[i] = i2c.read(0); - } - } - - i2c.stop(); -*/ - int32_t err = 0; - - err = i2c.read(ucDevAddr,(char*)ucBuffer,ulSize); - if(err == 1){ - Uart_Write((uint8_t*)"Return error I2C read\n\r"); - return -1; - } - wait_ms(1); - return 0; -} -//**************************************************************************** -// -//! Invokes the I2C driver APIs to write to the specified address -//! -//! \param ucDevAddr is the device I2C slave address -//! \param ucBuffer is the pointer to the data to be written -//! \param ulSize is the length of data to be written -//! \param ucFlags -//! -//! This function works in a polling mode, -//! 1. Writes the device register address to be written to. -//! 2. In a loop, writes all the bytes over I2C -//! -//! \return 0: Success, < 0: Failure. -// -//**************************************************************************** - -int32_t I2CBufferWrite(int32_t ucDevAddr, uint8_t *ucBuffer, - int32_t ulSize,unsigned char ucFlags) -{ -// Uart_Write((uint8_t*)"I2CBufferWrite \n\r"); -/* - i2c.start(); - - // Set I2C slave write address - i2c.write(ucDevAddr); - - if(ulSize == 1){ - i2c.write(ucBuffer[0]); - }else{ - for(int i=0;i<ulSize;i++){ - i2c.write(ucBuffer[i]); - } - } - - i2c.stop(); -*/ - int32_t err = 0; - - err = i2c.write(ucDevAddr,(char*)ucBuffer,ulSize); - if(err == 1){ - Uart_Write((uint8_t*)"Return error I2C write\n\r"); - return -1; - } - wait_ms(1); - return 0; -} - -//***************************************************************************** -// -// Close the Doxygen group. -//! @} -// -//***************************************************************************** - -
--- a/camera_app/mt9d111/i2cconfig.h Tue Aug 25 22:03:00 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -//***************************************************************************** -// i2cconfig.h -// -// Function prototype for I2c interface APIs -// -// Copyright (C) 2014 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. -// -//***************************************************************************** - -#ifndef __I2CCONFIG_H__ -#define __I2CCONFIG_H__ - -//***************************************************************************** -// -// If building with a C++ compiler, make all of the definitions in this header -// have a C binding. -// -//***************************************************************************** -#ifdef __cplusplus -extern "C" -{ -#endif - -//****************************************************************************** -// Macros -//****************************************************************************** -#define I2C_SEND_STOP 0x01 -#define I2C_SEND_START 0x02 - -//****************************************************************************** -// APIs -//****************************************************************************** -uint32_t I2CInit(void); -int32_t I2CBufferRead(int32_t ucDevAddr, uint8_t *ucBuffer, - int32_t ulSize,unsigned char ucFlags); -int32_t I2CBufferWrite(int32_t ucDevAddr, uint8_t *ucBuffer, - int32_t ulSize,unsigned char ucFlags); -//***************************************************************************** -// -// Mark the end of the C bindings section for C++ compilers. -// -//***************************************************************************** -#ifdef __cplusplus -} -#endif - -#endif //__I2CCONFIG_H__ -
--- a/http/server/HttpCore.cpp Tue Aug 25 22:03:00 2015 +0000 +++ b/http/server/HttpCore.cpp Fri Aug 28 21:04:44 2015 +0000 @@ -189,6 +189,7 @@ { if(g_state.listenSocket < 0) { + HttpDebug("Closed Http Server \n\r"); return; } @@ -196,6 +197,7 @@ { g_state.listenSocket = -1; } + HttpDebug("Closed Http Server \n\r"); } void HttpServerInitAndRun(void * param) @@ -205,7 +207,7 @@ #ifdef HTTP_CORE_ENABLE_AUTH struct HttpBlob user,pass; - user.pData = (UINT8*)"cc3200"; + user.pData = (UINT8*)"cc3100"; user.uLength= 6; pass.pData = (UINT8*)"admin"; pass.uLength = 5; @@ -301,7 +303,7 @@ } } // else if((iRecvLen != SL_EAGAIN) && (iRecvLen != SL_POOL_IS_EMPTY)) - else if((iRecvLen == SL_EAGAIN) && (ResponseComplete) && (!ws_Flag)) + else if((iRecvLen == SL_EAGAIN) && (iRecvLen != SL_POOL_IS_EMPTY) && (ResponseComplete) && (!ws_Flag)) { // HttpDebug("\r\n Http Client close\n\r"); HttpCore_CloseConnection(uConnection); @@ -309,7 +311,7 @@ } else { - HttpDebug(","); + HttpDebug("*"); // HttpDebug("Http receive retry %d\n\r",iRecvLen); g_state.connections[uConnection].timeout++; if(g_state.connections[uConnection].connectionState != WebSocketDataRecv)
--- a/main.cpp Tue Aug 25 22:03:00 2015 +0000 +++ b/main.cpp Fri Aug 28 21:04:44 2015 +0000 @@ -55,6 +55,11 @@ #include "stm32f4xx_hal_rcc.h" /* Free-RTOS includes */ +#include "FreeRTOS.h" +#include "task.h" +#include "semphr.h" +#include "portmacro.h" + #include "osi.h" #include "cli_uart.h" @@ -67,9 +72,6 @@ extern DCMI_HandleTypeDef hdcmi; extern DMA_HandleTypeDef hdma_dcmi; -void DCMI_IRQHandler(void); -void DMA2_Stream1_IRQHandler(void); - /* Warning if pin changes are made below then the same changes have to be made in the following files. * httpserverapp.cpp * HttpCore.cpp @@ -120,7 +122,7 @@ GPIO_InitStruct.Alternate = GPIO_AF0_MCO; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); -#if defined OV5642_CAM || defined OV2640_CAM +#if defined OV5642_CAM /* MCO1 output 16MHz */ HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_1); #else @@ -210,6 +212,8 @@ // DisplayBanner(APP_NAME); + createMutex(); + //#endif //
--- a/mbed.bld Tue Aug 25 22:03:00 2015 +0000 +++ b/mbed.bld Fri Aug 28 21:04:44 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/bad568076d81 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/8ed44a420e5c \ No newline at end of file
--- a/simplelink/G_functions/fPtr_func.cpp Tue Aug 25 22:03:00 2015 +0000 +++ b/simplelink/G_functions/fPtr_func.cpp Fri Aug 28 21:04:44 2015 +0000 @@ -1205,7 +1205,7 @@ void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent) { /* - * Most of the general errors are not FATAL are are to be handled + * Most of the general errors are not FATAL and are to be handled * appropriately by the application */ memset(print_buf, 0x00, PRINT_BUF_LEN);
--- a/simplelink/cc3100.cpp Tue Aug 25 22:03:00 2015 +0000 +++ b/simplelink/cc3100.cpp Fri Aug 28 21:04:44 2015 +0000 @@ -141,6 +141,68 @@ return SUCCESS; } +int32_t cc3100::Network_AP_InitDriver(){ + + SlPingStartCommand_t PingParams = {0}; + SlPingReport_t Report = {0}; + + uint8_t SecType = 0; + int32_t role = ROLE_STA; + int32_t retVal = -1; + + /* + * Assumption is that the device is configured in station mode already + * and it is in its default state + */ + role = sl_Start(0, 0, 0); + if (ROLE_AP == role) { + /* If the device is in AP mode, we need to wait for this event before doing anything */ + while(!IS_IP_ACQUIRED(g_Status,STATUS_BIT_IP_ACQUIRED)) { + _nonos._SlNonOsMainLoopTask(); + } + } else { + /* Configure CC3100 to start in AP mode */ + retVal = _wlan.sl_WlanSetMode(ROLE_AP); + if(retVal < 0) + LOOP_FOREVER(); + + /* Configure the SSID of the CC3100 */ + retVal = _wlan.sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID, + strlen(SSID_AP_MODE), (uint8_t *)SSID_AP_MODE); + if(retVal < 0) + LOOP_FOREVER(); + + SecType = SEC_TYPE_AP_MODE; + /* Configure the Security parameter the AP mode */ + retVal = _wlan.sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SECURITY_TYPE, 1, (uint8_t *)&SecType); + if(retVal < 0) + LOOP_FOREVER(); + + retVal = _wlan.sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_PASSWORD, strlen(PASSWORD_AP_MODE), (uint8_t *)PASSWORD_AP_MODE); + if(retVal < 0) + LOOP_FOREVER(); + + retVal = sl_Stop(SL_STOP_TIMEOUT); + if(retVal < 0) + LOOP_FOREVER(); + + CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED); + + role = sl_Start(0, 0, 0); + if (ROLE_AP == role) { + /* If the device is in AP mode, we need to wait for this event before doing anything */ + while(!IS_IP_ACQUIRED(g_Status,STATUS_BIT_IP_ACQUIRED)) { + _nonos._SlNonOsMainLoopTask(); + } + } else { + printf(" Device couldn't be configured in AP mode \n\r"); + LOOP_FOREVER(); + } + } + printf(" Device started as Access Point\r\n"); + return 0; +} + //***************************************************************************** // //! Network_IF_InitDriver @@ -167,6 +229,7 @@ // Note that all profiles and persistent settings that were done on the // device will be lost // + Uart_Write((uint8_t*)"Starting configureSimpleLinkToDefaultState \n\r"); lRetVal = configureSimpleLinkToDefaultState(); if(lRetVal < 0) { @@ -283,7 +346,7 @@ { SlVersionFull ver = {0}; _WlanRxFilterOperationCommandBuff_t RxFilterIdMask = {0}; - + uint8_t val = 1; uint8_t configOpt = 0; uint8_t configLen = 0; @@ -1131,8 +1194,7 @@ #if _SL_INCLUDE_FUNC(sl_Start) int16_t cc3100::sl_Start(const void* pIfHdl, int8_t* pDevName, const P_INIT_CALLBACK pInitCallBack) { - - + int16_t ObjIdx = MAX_CONCURRENT_ACTIONS; InitComplete_t AsyncRsp; @@ -1151,7 +1213,7 @@ { g_pCB->FD = (_SlFd_t)pIfHdl; } - + ObjIdx = _driver._SlDrvProtectAsyncRespSetting((uint8_t *)&AsyncRsp, START_STOP_ID, SL_MAX_SOCKETS); if (MAX_CONCURRENT_ACTIONS == ObjIdx) @@ -1166,11 +1228,11 @@ g_pCB->pInitCallback = pInitCallBack; _spi.CC3100_enable(); - + if (NULL == pInitCallBack) { _driver._SlDrvSyncObjWaitForever(&g_pCB->ObjPool[ObjIdx].SyncObj); /*release Pool Object*/ - _driver._SlDrvReleasePoolObj(g_pCB->FunctionParams.AsyncExt.ActionIndex); + _driver._SlDrvReleasePoolObj(g_pCB->FunctionParams.AsyncExt.ActionIndex); return _sl_GetStartResponseConvert(AsyncRsp.Status); } else
--- a/simplelink/cc3100.h Tue Aug 25 22:03:00 2015 +0000 +++ b/simplelink/cc3100.h Fri Aug 28 21:04:44 2015 +0000 @@ -423,7 +423,9 @@ /*****************************************************************************/ /* Function prototypes */ /*****************************************************************************/ - int32_t initializeAppVariables(); + int32_t initializeAppVariables(void); + + int32_t Network_AP_InitDriver(void); int32_t establishConnectionWithAP(void);
--- a/simplelink/cc3100_spi.cpp Tue Aug 25 22:03:00 2015 +0000 +++ b/simplelink/cc3100_spi.cpp Fri Aug 28 21:04:44 2015 +0000 @@ -55,13 +55,13 @@ { _wlan_spi.format(8,1); - _wlan_spi.frequency(16000000); + _wlan_spi.frequency(12000000); _wlan_irq.rise(this, &cc3100_spi::IntSpiGPIOHandler); //_SlDrvRxIrqHandler is called from IntSpiGPIOHandler // _sw1_irq.rise(this, &cc3100_spi::buttonHandler_1); // _sw2_irq.rise(this, &cc3100_spi::buttonHandler_2); _wlan_nHIB = 0; _wlan_cs = 1; -// wait_ms(100); + wait_ms(100); }
--- a/simplelink/cc3100_wlan.cpp Tue Aug 25 22:03:00 2015 +0000 +++ b/simplelink/cc3100_wlan.cpp Fri Aug 28 21:04:44 2015 +0000 @@ -680,7 +680,6 @@ WLAN_SET_STA_MODE = 1 WLAN_SET_AP_MODE = 2 WLAN_SET_P2P_MODE = 3 */ - #if _SL_INCLUDE_FUNC(sl_WlanSetMode) int16_t cc3100_wlan::sl_WlanSetMode(const uint8_t mode) {
--- a/utils/app_config.h Tue Aug 25 22:03:00 2015 +0000 +++ b/utils/app_config.h Fri Aug 28 21:04:44 2015 +0000 @@ -35,9 +35,9 @@ #endif #define SPAWN_TASK_PRIORITY 7//9 -#define HTTP_SERVER_APP_TASK_PRIORITY 5//1 -#define CAMERA_SERVICE_PRIORITY 5 -#define OSI_STACK_SIZE 8 * 1024 +#define HTTP_SERVER_APP_TASK_PRIORITY 3//1 +#define CAMERA_SERVICE_PRIORITY 3 +#define OSI_STACK_SIZE 12 * 1024 //***************************************************************************** //
--- a/utils/cli_uart.cpp Tue Aug 25 22:03:00 2015 +0000 +++ b/utils/cli_uart.cpp Fri Aug 28 21:04:44 2015 +0000 @@ -58,7 +58,7 @@ void CLI_Configure(void) { - uart.baud(460800); + uart.baud(115200); RTOS_MUTEX_CREATE(&g_printLock);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils/i2cconfig.cpp Fri Aug 28 21:04:44 2015 +0000 @@ -0,0 +1,173 @@ +//***************************************************************************** +// i2cconfig.c +// +// I2C features APIs +// +// Copyright (C) 2014 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. +// +//***************************************************************************** +//***************************************************************************** +// +//! \addtogroup i2cconfig +//! @{ +// +//***************************************************************************** +#include <stdbool.h> +#include <stdint.h> +#include "mbed.h" + +#include "i2cconfig.h" +#include "cli_uart.h" +#include "myBoardInit.h" + + + +I2C i2c(PB_9, PB_8); + + +//***************************************************************************** +// +//! I2CInit +//! +//! \param Delay +//! \return None +// +//***************************************************************************** +uint32_t I2CInit() +{ + + i2c.frequency (100000); + + return 0; +} +//**************************************************************************** +// +//! Invokes the I2C driver APIs to read from the device. This assumes the +//! device local address to read from is set using the I2CWrite API. +//! +//! \param ucDevAddr is the device I2C slave address +//! \param ucBuffer is the pointer to the read data to be placed +//! \param ulSize is the length of data to be read +//! \param ucFlags Flag +//! +//! This function works in a polling mode, +//! 1. Writes the device register address to be written to. +//! 2. In a loop, reads all the bytes over I2C +//! +//! \return 0: Success, < 0: Failure. +// +//**************************************************************************** +int32_t I2CBufferRead(int32_t ucDevAddr, uint8_t *ucBuffer, + int32_t ulSize, unsigned char ucFlags) +{ +// Uart_Write((uint8_t*)"I2CBufferRead \n\r"); +/* + i2c.start(); + + // Set I2C slave read address + i2c.write(ucDevAddr); + if(ulSize == 1){ + ucBuffer[0] = i2c.read(0); + }else{ + for(int i=0;i<ulSize;i++){ + ucBuffer[i] = i2c.read(0); + } + } + + i2c.stop(); +*/ + int32_t err = 0; + + err = i2c.read(ucDevAddr,(char*)ucBuffer,ulSize); + if(err == 1){ + Uart_Write((uint8_t*)"Return error I2C read\n\r"); + return -1; + } +// wait_ms(1); + return 0; +} +//**************************************************************************** +// +//! Invokes the I2C driver APIs to write to the specified address +//! +//! \param ucDevAddr is the device I2C slave address +//! \param ucBuffer is the pointer to the data to be written +//! \param ulSize is the length of data to be written +//! \param ucFlags +//! +//! This function works in a polling mode, +//! 1. Writes the device register address to be written to. +//! 2. In a loop, writes all the bytes over I2C +//! +//! \return 0: Success, < 0: Failure. +// +//**************************************************************************** + +int32_t I2CBufferWrite(int32_t ucDevAddr, uint8_t *ucBuffer, + int32_t ulSize,unsigned char ucFlags) +{ +// Uart_Write((uint8_t*)"I2CBufferWrite \n\r"); +/* + i2c.start(); + + // Set I2C slave write address + i2c.write(ucDevAddr); + + if(ulSize == 1){ + i2c.write(ucBuffer[0]); + }else{ + for(int i=0;i<ulSize;i++){ + i2c.write(ucBuffer[i]); + } + } + + i2c.stop(); +*/ + int32_t err = 0; + + err = i2c.write(ucDevAddr,(char*)ucBuffer,ulSize); + if(err == 1){ + Uart_Write((uint8_t*)"Return error I2C write\n\r"); + return -1; + } +// wait_ms(1); + return 0; +} + +//***************************************************************************** +// +// Close the Doxygen group. +//! @} +// +//***************************************************************************** + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils/i2cconfig.h Fri Aug 28 21:04:44 2015 +0000 @@ -0,0 +1,77 @@ +//***************************************************************************** +// i2cconfig.h +// +// Function prototype for I2c interface APIs +// +// Copyright (C) 2014 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. +// +//***************************************************************************** + +#ifndef __I2CCONFIG_H__ +#define __I2CCONFIG_H__ + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//****************************************************************************** +// Macros +//****************************************************************************** +#define I2C_SEND_STOP 0x01 +#define I2C_SEND_START 0x02 + +//****************************************************************************** +// APIs +//****************************************************************************** +uint32_t I2CInit(void); +int32_t I2CBufferRead(int32_t ucDevAddr, uint8_t *ucBuffer, + int32_t ulSize,unsigned char ucFlags); +int32_t I2CBufferWrite(int32_t ucDevAddr, uint8_t *ucBuffer, + int32_t ulSize,unsigned char ucFlags); +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif //__I2CCONFIG_H__ +