David Fletcher / Mbed 2 deprecated cc3100_Test_websock_Camera_CM4F

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //*****************************************************************************
00002 // main.c
00003 //
00004 // Reference code to demonstrate getting the current time using an NTP server.
00005 //
00006 // Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
00007 //
00008 //
00009 //  Redistribution and use in source and binary forms, with or without
00010 //  modification, are permitted provided that the following conditions
00011 //  are met:
00012 //
00013 //    Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 //
00016 //    Redistributions in binary form must reproduce the above copyright
00017 //    notice, this list of conditions and the following disclaimer in the
00018 //    documentation and/or other materials provided with the
00019 //    distribution.
00020 //
00021 //    Neither the name of Texas Instruments Incorporated nor the names of
00022 //    its contributors may be used to endorse or promote products derived
00023 //    from this software without specific prior written permission.
00024 //
00025 //  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00026 //  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00027 //  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00028 //  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00029 //  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00030 //  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00031 //  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00032 //  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00033 //  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00034 //  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00035 //  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 //*****************************************************************************
00038 
00039 //****************************************************************************
00040 //
00041 //! \addtogroup main
00042 //! @{
00043 //
00044 //****************************************************************************
00045 
00046 #include "mbed.h"
00047 
00048 // SimpleLink include
00049 #include "cc3100_simplelink.h"
00050 #include "cc3100.h"
00051 
00052 /* Free-RTOS includes */
00053 #include "FreeRTOS.h"
00054 #include "osi.h"
00055 
00056 #include "cli_uart.h"
00057 #include "app_config.h"
00058 #include "myBoardInit.h"
00059 #include "httpserverapp.h"
00060 #include "camera_app.h"
00061 
00062 using namespace mbed_cc3100;
00063 
00064 extern DCMI_HandleTypeDef hdcmi;
00065 extern DMA_HandleTypeDef hdma_dcmi;
00066 
00067 /* Warning if pin changes are made below then the same changes have to be made in the following files.
00068  * httpserverapp.cpp
00069  * HttpCore.cpp
00070  * HttpSocket.cpp
00071  * HttpStatic.cpp
00072  * fPtr_func.cpp
00073  * cc3100_spawn.cpp
00074  */ 
00075 
00076 /* Off board leds */
00077   DigitalOut led1(PB_15);
00078   DigitalOut led2(PB_14);
00079 cc3100 _cc3100(NC, NC, PD_12, PD_13, PD_11, SPI(PC_3, PC_2, PB_10));//Seeed_Arch_Max  irq, nHib, cs, mosi, miso, sck
00080 
00081 static void Start_MCO1(void);
00082 void initLEDs(void);
00083 void toggleLed(int ind);
00084 static void DisplayBanner(char * AppName);
00085 
00086 #define PRINT_BUF_LEN    128
00087 int8_t print_buf[PRINT_BUF_LEN];
00088 
00089 //*****************************************************************************
00090 //                          LOCAL DEFINES
00091 //*****************************************************************************
00092 #define APP_NAME                "WebSocket"
00093 
00094 void initLEDs(void){
00095       
00096 #if (THIS_BOARD == Seeed_Arch_Max)
00097     led1 = 0;
00098     led2 = 0;
00099 #endif      
00100     
00101 }
00102 
00103 static void Start_MCO1()
00104 {
00105     
00106     GPIO_InitTypeDef GPIO_InitStruct;
00107     __GPIOA_CLK_ENABLE();
00108     
00109     //Configure GPIO pin : GPIO_AF0_MCO PA8      
00110     GPIO_InitStruct.Pin       = GPIO_PIN_8;
00111     GPIO_InitStruct.Mode      = GPIO_MODE_AF_PP;
00112     GPIO_InitStruct.Pull      = GPIO_PULLUP;
00113     GPIO_InitStruct.Speed     = GPIO_SPEED_HIGH;
00114     GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
00115     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
00116     
00117 #ifndef MT9D111_CAM 
00118     /* MCO1 output 16MHz */   
00119     HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1);
00120 #else 
00121     /* MCO1 output 8MHz */   
00122     HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_2);
00123 #endif
00124     wait_ms(500);
00125     
00126 }
00127 
00128 void toggleLed(int ind){
00129     
00130     if(ind == 1){
00131         led1 = !led1;
00132     }
00133     if(ind == 2){
00134         led2 = !led2;
00135     }   
00136     
00137 }   
00138 
00139 //*****************************************************************************
00140 //
00141 //! Application startup display on UART
00142 //!
00143 //! \param  none
00144 //!
00145 //! \return none
00146 //!
00147 //*****************************************************************************
00148 
00149 //#ifndef NOTERM
00150 static void
00151 DisplayBanner(char * AppName)
00152 {
00153 
00154     Report("\n\n\n\r");
00155     Report(" *************************************************\n\r");
00156     Report("      CC3100 %s Application       \n\r", AppName);
00157     Report(" *************************************************\n\r");
00158     Report("\n\n\n\r");
00159 }
00160 //#endif
00161 
00162 //****************************************************************************
00163 //                          MAIN FUNCTION
00164 //****************************************************************************
00165 int main(void) {
00166  
00167    int rv = 0;
00168 
00169    //
00170    // Configuring UART
00171    //
00172    CLI_Configure();
00173    
00174 #if defined OV5642_CAM   
00175    Uart_Write((uint8_t*)"\n\rOV5642 Camera \n\r");
00176 #elif defined OV2640_CAM 
00177    Uart_Write((uint8_t*)"\n\rOV2640 Camera \n\r");
00178 #elif defined MT9D111_CAM     
00179    Uart_Write((uint8_t*)"\n\rMT9D111 Camera \n\r");
00180 #endif
00181    
00182    /* Start Camera Master Clock */
00183    Start_MCO1();
00184    
00185    
00186    
00187    initLEDs();
00188 
00189 //#ifndef NOTERM    
00190     memset(print_buf, 0x00, PRINT_BUF_LEN);
00191     sprintf((char*) print_buf, " \r\nSystemCoreClock = %dMHz\r\n ", SystemCoreClock /1000000);
00192     rv = Uart_Write((uint8_t *) print_buf);
00193     if(rv < 0){
00194         while(1){
00195         toggleLed(1);
00196         wait(0.1);
00197         }
00198     }
00199     
00200     //
00201     // Display Application Banner
00202     //
00203     DisplayBanner(APP_NAME);
00204     
00205 //    createMutex();
00206     
00207 //#endif
00208 
00209     //
00210     // Start the SimpleLink Host
00211     //
00212     VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
00213     //
00214     // Start the HttpServer Task
00215     //
00216     //
00217     osi_TaskCreate(HttpServerAppTask,
00218                     "WebSocketApp",
00219                         OSI_STACK_SIZE,
00220                         NULL,
00221                         HTTP_SERVER_APP_TASK_PRIORITY,
00222                         NULL );
00223 
00224     Uart_Write((uint8_t*)"HttpServerApp Initializing \n\r");
00225     
00226     //
00227     // Start the task scheduler
00228     //
00229     osi_start();
00230 
00231     return 0;
00232 }
00233 
00234 
00235 //*****************************************************************************
00236 //
00237 // Close the Doxygen group.
00238 //! @}
00239 //
00240 //*****************************************************************************
00241 
00242 
00243 
00244