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-08-25
Revision:
14:90603ea1e85b
Parent:
13:bf45f592c2b6
Child:
15:5433f9d94cd7

File content as of revision 14:90603ea1e85b:

//*****************************************************************************
// 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"
#include "camera_app.h"

using namespace mbed_cc3100;

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
 * HttpSocket.cpp
 * HttpStatic.cpp
 * fPtr_func.cpp
 */ 

/* Off board leds */
  DigitalOut led1(PB_15);
  DigitalOut led2(PB_14);
//Serial pc(USBTX, USBRX);
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

static void Start_MCO1(void);
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    	
	
}

static void Start_MCO1()
{
    
    GPIO_InitTypeDef GPIO_InitStruct;
    __GPIOA_CLK_ENABLE();
    
    /*Configure GPIO pin : GPIO_AF0_MCO PA8 */     
    GPIO_InitStruct.Pin = GPIO_PIN_8;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
    
#if defined OV5642_CAM || defined OV2640_CAM
    /* MCO1 output 16MHz */   
    HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_1);
#else 
    /* MCO1 output 8MHz */   
    HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_2);
#endif
    wait_ms(500);
}

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) {

   SCB->SHCSR |= 0x00070000; 
   int rv = 0;
   
   //
   // Configuring UART
   //
   CLI_Configure();
   
#if defined OV5642_CAM   
   Uart_Write((uint8_t*)"\n\rOV5642 Camera \n\r");
#elif defined OV2640_CAM 
   Uart_Write((uint8_t*)"\n\rOV2640 Camera \n\r");
#elif defined MT9D111_CAM     
   Uart_Write((uint8_t*)"\n\rMT9D111 Camera \n\r");
#endif
   
   /* Start Camera Master Clock */
   Start_MCO1();
   
   
   
   initLEDs();

//   toggleLed(1);
//#ifndef NOTERM
    
    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 Initializing \n\r");

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

	return 0;
}

/**
  * @brief  This function handles Hard Fault exception.
  * @param  None
  * @retval None
  */
extern "C" void HardFault_Handler(void)
{
  /* Go to infinite loop when Hard Fault exception occurs */
  Uart_Write((uint8_t*)"\n\rHardFault_Handler \n\r");
  printf("Hard Fault Register SCB->HSFR     0x%X \r\n",SCB->HFSR);
  printf("Fault bits set SCB->CFSR          0x%X \r\n",SCB->CFSR);
  printf("Call to Memory Address SCB->BFAR  0x%X ERROR!\r\n",SCB->BFAR);
  printf("Call to Memory Address SCB->MMFAR 0x%X ERROR!\r\n",SCB->MMFAR);
  Uart_Write((uint8_t*)"HardFault_Handler \n\r");
  while (1)
  {
  }
}

/**
  * @brief  This function handles Memory Manage exception.
  * @param  None
  * @retval None
  */
extern "C" void MemManage_Handler(void)
{ 
  Uart_Write((uint8_t*)"\n\rMemManage_Handler \n\r");
  printf("Fault bits set SCB->CFSR          0x%X \r\n",SCB->CFSR); 
  printf("Call to Memory Address SCB->BFAR  0x%X ERROR!\r\n",SCB->BFAR);
  printf("Call to Memory Address SCB->MMFAR 0x%X ERROR!\r\n",SCB->MMFAR);
  Uart_Write((uint8_t*)"MemManage_Handler \n\r");
  /* Go to infinite loop when Memory Manage exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles Bus Fault exception.
  * @param  None
  * @retval None
  */
extern "C" void BusFault_Handler(void)
{
  Uart_Write((uint8_t*)"\n\rBusFault_Handler \n\r");
  printf("Fault bits set SCB->CFSR          0x%X \r\n",SCB->CFSR); 
  printf("Call to Memory Address SCB->BFAR  0x%X ERROR!\r\n",SCB->BFAR);
  printf("Call to Memory Address SCB->MMFAR 0x%X ERROR!\r\n",SCB->MMFAR);
  Uart_Write((uint8_t*)"BusFault_Handler \n\r");
  /* Go to infinite loop when Bus Fault exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles Usage Fault exception.
  * @param  None
  * @retval None
  */
extern "C" void UsageFault_Handler(void)
{
  Uart_Write((uint8_t*)"UsageFault_Handler \n\r");
  /* Go to infinite loop when Usage Fault exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles SVCall exception.
  * @param  None
  * @retval None
  */
/*  
extern "C" void SVC_Handler(void)
{
	Uart_Write((uint8_t*)"SVC_Handler \n\r");
}
*/
/**
  * @brief  This function handles Debug Monitor exception.
  * @param  None
  * @retval None
  */
extern "C" void DebugMon_Handler(void)
{
	Uart_Write((uint8_t*)"DebugMon_Handler \n\r");
}

/**
  * @brief  This function handles PendSVC exception.
  * @param  None
  * @retval None
  */
/*  
extern "C" void PendSV_Handler(void)
{
	Uart_Write((uint8_t*)"PendSV_Handler \n\r");
}
*/
/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
/*  
extern "C" void SysTick_Handler(void)
{
  Uart_Write((uint8_t*)"SysTick_Handler \n\r");
  HAL_IncTick();
}
*/
/**
  * @brief  DMA interrupt handler.
  * @param  None
  * @retval None
  */
/*    
void DMA2_Stream1_IRQHandler(void)
{
  Uart_Write((uint8_t*)"DMA2_Stream1_IRQHandler \n\r");
  HAL_DMA_IRQHandler(&hdma_dcmi);  
}
*/
/**
  * @brief  DCMI interrupt handler.
  * @param  None
  * @retval None
  */ 
 /* 
void DCMI_IRQHandler(void)
{
  Uart_Write((uint8_t*)"DCMI_IRQHandler \n\r");
  HAL_DCMI_IRQHandler(&hdcmi);
}
*/
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************