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.

Dependencies:   mbed

main.cpp

Committer:
dflet
Date:
2015-06-25
Revision:
1:1a80c1529aa3
Parent:
0:50cedd586816
Child:
2:b92db44a29b4

File content as of revision 1:1a80c1529aa3:

//*****************************************************************************
// main.c
//
// Reference code to demonstrate getting the current time using an NTP server.
//
// 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 main
//! @{
//
//****************************************************************************

#include "mbed.h"

// SimpleLink include
#include "cc3100_simplelink.h"
#include "cc3100.h"

#include "httpserverapp.h"

#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_rcc.h"

/* Free-RTOS includes */
#include "osi.h"

#include "cli_uart.h"
#include "app_config.h"
#include "myBoardInit.h"

using namespace mbed_cc3100;

static void SystemClock_Config(void);
static void MX_DMA_Init(void);
static void MX_DCMI_Init(void);
 
 /**
  * Initializes the Global MSP.
  */
//void HAL_MspInit(void)
//{
  /* USER CODE BEGIN MspInit 0 */

  /* USER CODE END MspInit 0 */

//  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);

  /* System interrupt init*/
/* SysTick_IRQn interrupt configuration */
//  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

  /* USER CODE BEGIN MspInit 1 */

  /* USER CODE END MspInit 1 */
//}
 
DCMI_HandleTypeDef hdcmi;
DMA_HandleTypeDef hdma_dcmi;

/** System Clock Configuration
*/
static void SystemClock_Config(void)
{
  
  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  __PWR_CLK_ENABLE();

  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 7;
  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
                              |RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
  
  /* RCC_MCODIV_5 33.6MHz mco output on pin PC_9 (cam xclk) */
  /* RCC_MCODIV_4 42MHz mco output on pin PC_9 (cam xclk) */
  /* RCC_MCODIV_3 56MHz mco output on pin PC_9 (cam xclk) */
  HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_3);

  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);



}
 
void MX_DCMI_Init()
{

  hdcmi.Instance = DCMI;
  hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE;
  hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING;
  hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_LOW;
  hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_LOW;
  hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME;
  hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B;
#ifdef ENABLE_JPEG  
  hdcmi.Init.JPEGMode = DCMI_JPEG_ENABLE;
#else
  hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE;
#endif    
  HAL_DCMI_Init(&hdcmi);

}

/** 
  * Enable DMA controller clock
  */
void MX_DMA_Init(void) 
{
  /* DMA controller clock enable */
   __DMA2_CLK_ENABLE();

  /* DMA interrupt init */
  HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);

}

/* Warning if pin changes are made below then the same changes have to be made in the following files.
 * httpserverapp.cpp
 * HttpCore.cpp
 * HttpSocket.cpp
 * HttpStatic.cpp
 * fPtr_func.cpp
 */ 

/* Off board leds */
  DigitalOut led1(PB_15);
  DigitalOut led2(PB_14);
//cc3100 _cc3100(NC, NC, PE_5, PE_4, PE_6, SPI(PB_5, PB_4, PB_3));//Seeed_Arch_Max  irq, nHib, cs, mosi, miso, sck
cc3100 _cc3100(NC, NC, PD_12, PD_13, PD_11, SPI(PB_5, PB_4, PB_3));//Seeed_Arch_Max  irq, nHib, cs, mosi, miso, sck

void initLEDs(void);
void toggleLed(int ind);
static void DisplayBanner(char * AppName);

#define PRINT_BUF_LEN    128
int8_t print_buf[PRINT_BUF_LEN];

//*****************************************************************************
//                          LOCAL DEFINES
//*****************************************************************************
#define APP_NAME		        "WebSocket"

void initLEDs(void){
	  
#if (THIS_BOARD == Seeed_Arch_Max)
    led1 = 0;
    led2 = 0;
#endif    	
	
}

void toggleLed(int ind){
	
	if(ind == 1){
		led1 = !led1;
	}
	if(ind == 2){
		led2 = !led2;
	}	
	
}	

//*****************************************************************************
//
//! Application startup display on UART
//!
//! \param  none
//!
//! \return none
//!
//*****************************************************************************

//#ifndef NOTERM
static void
DisplayBanner(char * AppName)
{

    Report("\n\n\n\r");
    Report(" *************************************************\n\r");
    Report("	  CC3100 %s Application       \n\r", AppName);
    Report(" *************************************************\n\r");
    Report("\n\n\n\r");
}
//#endif

//****************************************************************************
//							MAIN FUNCTION
//****************************************************************************
int main(void) {

   int rv = 0;
   SystemClock_Config();
   //
   // Configuring UART
   //
   CLI_Configure();
   
/* Initialize all configured peripherals */
   MX_DMA_Init();
   MX_DCMI_Init();
//   Uart_Write((uint8_t*)"Initialize all configured peripherals complete \n\r");
   initLEDs();

   toggleLed(1);
//#ifndef NOTERM

	//
	// Configuring UART
	//
//    CLI_Configure();
    
    memset(print_buf, 0x00, PRINT_BUF_LEN);
    sprintf((char*) print_buf, " \r\nSystemCoreClock = %dMHz\r\n ", SystemCoreClock /1000000);
    rv = Uart_Write((uint8_t *) print_buf);
    if(rv < 0){
    	while(1){
    	toggleLed(1);
    	wait(0.1);
    	}
    }
    
    //
    // Display Application Banner
    //
    DisplayBanner(APP_NAME);
    
//#endif

    //
    // Start the SimpleLink Host
    //
    VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
    //
    // Start the HttpServer Task
    //
    //

    osi_TaskCreate(HttpServerAppTask,
                    "WebSocketApp",
                        OSI_STACK_SIZE,
                        NULL,
                        HTTP_SERVER_APP_TASK_PRIORITY,
                        NULL );

    Uart_Write((uint8_t*)"HttpServerApp Initialized \n\r");

    //
    // Start the task scheduler
    //
    osi_start();

	return 0;
}

//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************