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

Files at this revision

API Documentation at this revision

Comitter:
dflet
Date:
Thu Sep 03 20:10:39 2015 +0000
Parent:
17:acc075ff3fcb
Child:
19:3dd3e7f30f8b
Commit message:
Some debug removed still have some random failures with SPI?? MT9D111 cam still not working.

Changed in this revision

camera_app/camera_app.cpp Show annotated file Show diff for this revision Revisions of this file
camera_app/httpserverapp/httpserverapp.cpp Show annotated file Show diff for this revision Revisions of this file
camera_app/mt9d111/mt9d111.cpp Show annotated file Show diff for this revision Revisions of this file
http/server/HttpCore.cpp Show annotated file Show diff for this revision Revisions of this file
http/server/HttpSocket.cpp Show annotated file Show diff for this revision Revisions of this file
http/server/WebSockHandler.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
simplelink/cc3100_driver.cpp Show annotated file Show diff for this revision Revisions of this file
utils/app_config.h Show annotated file Show diff for this revision Revisions of this file
utils/i2cconfig.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/camera_app/camera_app.cpp	Mon Aug 31 15:20:36 2015 +0000
+++ b/camera_app/camera_app.cpp	Thu Sep 03 20:10:39 2015 +0000
@@ -82,15 +82,14 @@
 //*****************************************************************************
 
 unsigned int g_frame_size_in_bytes;
-//unsigned int g_uiDeviceModeConfig = ROLE_AP; //default is AP mode
 extern volatile unsigned char g_CaptureImage;
 extern int g_uiIpObtained = 0;
 extern int g_uiSimplelinkRole = ROLE_INVALID;
 unsigned int g_uiIpAddress = 0;
-//static unsigned char g_dma_txn_done;
+uint32_t picLoop = 0;
 volatile static unsigned char g_frame_end;
 volatile static uint16_t g_lines;
-//static unsigned int g_total_dma_intrpts;
+
 
 DCMI_HandleTypeDef phdcmi;
 DMA_HandleTypeDef phdma_dcmi;
@@ -250,7 +249,6 @@
 
 uint32_t StartCamera(char **WriteBuffer)
 {
-//	Uart_Write((uint8_t*)"StartCamera \n\r");
     uint32_t Writelength;
     //
     // Waits in the below loop till Capture button is pressed
@@ -350,16 +348,19 @@
 
     uint32_t g_header_length = 0;
     uint32_t *pbuffer = &(g_image.g_image_buffer[0]);
-    int32_t lRetVal= -1;
+//    int32_t lRetVal= -1;
     int32_t err = 0;
-    
+#ifdef MT9D111_CAM     
+    uint8_t jpeg_end[] = {0xFF, 0xD9};
+#endif
+    picLoop++;    
     DMAConfig();
     
-    wait(2);
-    
+    wait(1);
+#ifdef MT9D111_CAM    
     /* Send cam capture request, value in frames */
-//    Start_still_capture(1);// Switch to context b
-
+    Start_still_capture(1);// Switch to context b
+#endif
     //
     // DCMI Perform Image Capture
     //
@@ -370,7 +371,7 @@
 #endif
 
     while(g_frame_end == 0);//Set in the Frame complete callback function 
-    HttpDebug("lines %d\r\n",g_lines);
+
 #ifdef MT9D111_CAM    
     Stop_still_capture();// Switch to context a
 #endif    
@@ -388,44 +389,17 @@
 #endif        
       	HAL_DCMI_MspDeInit(&phdcmi);
         HttpDebug("Image Capture failed\n\r");
-#if 1
-        for(int i =0; i< 100; i++) {
-            HttpDebug("0x%x ",(uint8_t*)*pbuffer++);
-        }
-        HttpDebug("\r\n");
-#endif//if 0 
         while(1) {
             wait(0.5);
         }
-    }
-    err = HAL_DMA_GetState(&phdma_dcmi);
-    if(0x11 != err || 0x31 != err){
-       HttpDebug("\r\nDMA state! 0x%x\r\n",err);
-//       while(1);
-    }
-    err = HAL_DMA_GetError(&phdma_dcmi);
-    if(0x00 != err ){
-       HttpDebug("\r\nDMA error! 0x%x\r\n",err);      
-//       while(1);
-    }
-    HttpDebug("g_frame_size_in_bytes %d\n\r",g_frame_size_in_bytes);
-    
-#if 0
-    for(int i =0; i< 100; i++) {
-        HttpDebug("0x%x ",(uint8_t*)*pbuffer++);
-    }
-    HttpDebug("\r\n");
-#endif//if 0    
+    } 
     
     uint8_t* Image = reinterpret_cast<uint8_t*>(pbuffer);
     
-#if 0
-    for(int i =0; i< 100; i++) {
-        HttpDebug("0x%x ",*Image++);
-    }
-    HttpDebug("\r\n");    
-#endif//if 0
-    
+#ifdef MT9D111_CAM
+    memcpy(Image + g_frame_size_in_bytes, jpeg_end, 2);
+    g_frame_size_in_bytes += 2;
+#endif    
     //
     // Create JPEG Header
     //
@@ -433,23 +407,20 @@
 #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);
-//    HttpDebug("g_header_length = 0x%x \r\n",g_header_length);
+
     // This pushes the header to the start of the array so that the entire picture can be contiguous in memory
     memcpy(Image + g_header_length, Image, g_frame_size_in_bytes);
     memcpy(Image, g_image.g_header, g_header_length);
+    
     // This pushes the header to the end of the array so that the entire picture can be contiguous in memory
 //    memcpy((Image + g_frame_size_in_bytes ), g_image.g_header, g_header_length);
-#if 0
-    for(int i =0; i< g_header_length + 100 ; i++) {
-        HttpDebug("0x%x ",*Image++);
-    }
-    HttpDebug("\r\n");
-#endif//if 0
-
+    wait_ms(100);
+    HttpDebug("Capture Image %d\n\r",picLoop);
 #endif//ENABLE_JPEG
     *WriteBuffer = (char*)Image;
     return(g_header_length += g_frame_size_in_bytes);
-#endif//MT9D111_CAM    
+#endif//MT9D111_CAM
+    HttpDebug("\r\nCapture Image %d\r\n",picLoop);    
     *WriteBuffer = (char*)Image;
 
     return(g_frame_size_in_bytes);
@@ -465,8 +436,6 @@
 //*****************************************************************************
 void DMAConfig()
 {
-    HttpDebug("DMAConfig \n\r");
-//	DCMI_HandleTypeDef phdcmi;
 
     phdcmi.Init.SynchroMode      = DCMI_SYNCHRO_HARDWARE;
 #ifdef OV5642_CAM       
@@ -498,22 +467,10 @@
     HAL_DCMI_Init(&phdcmi);
      
 }
-/*
-void DCMI_IRQHandler(void) {
-	
-	HAL_DCMI_IRQHandler(&hdcmi);
-}
 
-void DMA2_Stream1_IRQHandler(void){
-	
-	HAL_DMA_IRQHandler(&hdma_dcmi);
-}		
-*/
 void DCMI_MspInit(DCMI_HandleTypeDef* hdcmi)
 {
 
-//   Uart_Write((uint8_t*)"DCMI_MspInit\n\r");
-
     /* Peripheral DCMI init*/
 
     GPIO_InitTypeDef GPIO_InitStruct;
@@ -662,14 +619,14 @@
 
 void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi)
 {
-    g_lines++;
+    //g_lines++;
     //HttpDebug("\r\nDCMI_LineEventCallback! 0x%x\r\n",hdcmi->ErrorCode);
 
 }
 
 void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi)
 {
-    g_lines = 0;
+    //g_lines = 0;
 //    printf("\r\nVsyncEventCallback\r\n");
 
 }
@@ -679,7 +636,7 @@
     HAL_DMA_Abort(&phdma_dcmi);
     g_frame_end = 1;
     
-    HttpDebug("\r\nDCMI Frame Capture complete! \r\n");
+    //HttpDebug("\r\nDCMI Frame Capture complete! \r\n");
 
 }
 
--- a/camera_app/httpserverapp/httpserverapp.cpp	Mon Aug 31 15:20:36 2015 +0000
+++ b/camera_app/httpserverapp/httpserverapp.cpp	Thu Sep 03 20:10:39 2015 +0000
@@ -96,8 +96,8 @@
 	UINT8 Opcode = 0x02;
 	struct HttpBlob Write;
 #ifdef ENABLE_JPEG
-	InitCameraComponents(640, 480);
-//	InitCameraComponents(320, 240);
+//	InitCameraComponents(640, 480);
+	InitCameraComponents(320, 240);
 #else
     InitCameraComponents(240, 256);
 #endif    
@@ -107,7 +107,6 @@
 		if(g_close == 0)
 		{
 			Write.uLength = StartCamera((char **)&Write.pData);
-            HttpDebug("Data Len = 0x%x \n\r",Write.uLength);
 			if(!sl_WebSocketSend(g_uConnection, Write, Opcode))
 			{
 				Uart_Write((uint8_t*)"sl_WebSocketSend failed.\n\r");
--- a/camera_app/mt9d111/mt9d111.cpp	Mon Aug 31 15:20:36 2015 +0000
+++ b/camera_app/mt9d111/mt9d111.cpp	Thu Sep 03 20:10:39 2015 +0000
@@ -402,7 +402,7 @@
     {1, 0xBE, 0x0004        }, // YUV_YCBCR_CONTROL
 /**/    {0, 0x65, 0xA000        }, // PLL CLOCK_ENABLING
 /**/    {100, 0x00, 0x0064      }, // Delay =100ms
-    {1, 0xC6, 0x104C        }, // MCU_ADDRESS
+/*    {1, 0xC6, 0x104C        }, // MCU_ADDRESS
     {1, 0xC8, 0x0000        }, // MCU_DATA_0
     {1, 0xC6, 0x0400        }, // MCU_ADDRESS
     {1, 0xC8, 0x3736        }, // MCU_DATA_0
@@ -946,7 +946,7 @@
     {1, 0xCF, 0xDD58        }, // MCU_DATA_7
     {1, 0xC6, 0x07C0        }, // MCU_ADDRESS
     {1, 0xC8, 0x3838        }, // MCU_DATA_0
-    {1, 0xC9, 0x3139        }, // MCU_DATA_1
+    {1, 0xC9, 0x3139        }, // MCU_DATA_1   */
     {1, 0xC6, 0x2003        }, //MON_ARG1
     {1, 0xC8, 0x0748        }, //MON_ARG1
     {1, 0xC6, 0xA002        }, //MON_CMD
@@ -1470,7 +1470,7 @@
         return err;
     }
     /* need a few frames delay to stablize the output */
-    wait_ms(500);
+//    wait_ms(500);
 
     return 0;
 }
--- a/http/server/HttpCore.cpp	Mon Aug 31 15:20:36 2015 +0000
+++ b/http/server/HttpCore.cpp	Thu Sep 03 20:10:39 2015 +0000
@@ -1132,6 +1132,7 @@
           sent = ClientSocketSend(g_state.connections[uConnection].dataSocket, (char*)g_state.packetSend, HTTP_CORE_MAX_PACKET_SIZE_SEND);
           if (sent <= 0)
           {
+            Uart_Write((uint8_t*)"ClientSocketSend failed \n\r");
             // Connection must be closed if send has failed
             return 0;
           }
@@ -1146,6 +1147,7 @@
 			sent = ClientSocketSend(g_state.connections[uConnection].dataSocket, (char*)g_state.packetSend, buffer.uLength);
 			if (sent <= 0)
 			{
+				Uart_Write((uint8_t*)"ClientSocketSend failed \n\r");
 				// Connection must be closed if send has failed
 				return 0;
 			}
--- a/http/server/HttpSocket.cpp	Mon Aug 31 15:20:36 2015 +0000
+++ b/http/server/HttpSocket.cpp	Thu Sep 03 20:10:39 2015 +0000
@@ -215,7 +215,6 @@
 
 int ClientSocketSend(long socket, char * buffer, unsigned int len)
 {
-//  HttpDebug("\r\n ClientSocketSend\n\r");
   int send_len = 0, Ittr = 0;
 
   do
--- a/http/server/WebSockHandler.cpp	Mon Aug 31 15:20:36 2015 +0000
+++ b/http/server/WebSockHandler.cpp	Thu Sep 03 20:10:39 2015 +0000
@@ -290,7 +290,6 @@
  */
 int WSCore_DataSend(UINT16 uConnection, struct HttpBlob PayLoad, UINT8 Opcode)
 {
-	Uart_Write((uint8_t*)"WSCore_DataSend\n\r");
 	UINT16 usTotalLength;
 	UINT8 usNextBlock;
 	UINT16 usPayloadLen;	// The heap cannot support beyond 65kb
@@ -304,7 +303,7 @@
 		usTotalLength = PayLoad.uLength;
 
 	do{
-
+        wait_ms(10);
 		///Is this the final packet?
 		if(usTotalLength < FRAGMENT_LENGTH)
 		{
@@ -316,7 +315,7 @@
 
 		/// Add this byte to the sendpacket
 		HttpResponse_AddCharToResponseHeaders(usNextBlock);
-
+        
 		///Reset byte
 		usNextBlock = 0x0;
 		///Mask bit is always set to 0 from server to client
@@ -331,7 +330,7 @@
 
 		/// Add this byte to the sendpacket
 		HttpResponse_AddCharToResponseHeaders(usNextBlock);
-
+    
 		/// If payload length is more than 125 bytes, we need 16 bits to represent it.
 		if(usPayloadLen == (126))
 		{
@@ -351,12 +350,14 @@
 		}
 
 		HttpResponse_AddStringToResponseHeaders(pucPayLoadData,(usPayloadLen));
-
-		if(!WS_SendPacket(uConnection))
+        wait_ms(2);
+		if(!WS_SendPacket(uConnection)){
+		    Uart_Write((uint8_t*)"WS_SendPacket error \n\r");
 			return 0;
-
+        }
 		if(Opcode == WS_CLOSE)
 		{
+			Uart_Write((uint8_t*)"WS_Close \n\r");
 			sl_WebSocketCloseEvtHdlr();
 			wait(1);
 			(HttpCore_CloseConnection(uConnection));
@@ -364,7 +365,6 @@
 		}
 
 		usTotalLength -= (usPayloadLen);
-
 		// Reset to continuation frame if packet is larger than max fragment size
 		Opcode = WS_CONTINUATION;
 
--- a/mbed.bld	Mon Aug 31 15:20:36 2015 +0000
+++ b/mbed.bld	Thu Sep 03 20:10:39 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/8ed44a420e5c
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/ba1f97679dad
\ No newline at end of file
--- a/simplelink/cc3100_driver.cpp	Mon Aug 31 15:20:36 2015 +0000
+++ b/simplelink/cc3100_driver.cpp	Thu Sep 03 20:10:39 2015 +0000
@@ -515,10 +515,10 @@
     g_pCB->FlowContCB.TxPoolCnt--;
 
     _SlDrvObjUnLock(&g_pCB->FlowContCB.TxLockObj);
-    
+
     /* send the message */
     RetVal =  _SlDrvMsgWrite(pCmdCtrl, pCmdExt, (uint8_t*)pTxRxDescBuff);
-
+    
     _SlDrvObjUnLock(&g_pCB->GlobalLockObj);
 
     return RetVal;
--- a/utils/app_config.h	Mon Aug 31 15:20:36 2015 +0000
+++ b/utils/app_config.h	Thu Sep 03 20:10:39 2015 +0000
@@ -24,20 +24,19 @@
 //#define QCIF_FRAME
 
 #ifdef MT9D111_CAM
-#define sensor_addr  0x0
+#define sensor_addr  0xBA//Dummy
 #endif
 #ifdef OV2640_CAM
-//#define sensor_addr  ((0x60 << 1))
 #define sensor_addr  0x60
 #endif
 #ifdef OV5642_CAM
 #define sensor_addr  0x78
 #endif
 
-#define SPAWN_TASK_PRIORITY            9//9
-#define HTTP_SERVER_APP_TASK_PRIORITY  1//1
-#define CAMERA_SERVICE_PRIORITY        1
-#define OSI_STACK_SIZE                 12 * 1024
+#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
 
 //*****************************************************************************
 //
--- a/utils/i2cconfig.cpp	Mon Aug 31 15:20:36 2015 +0000
+++ b/utils/i2cconfig.cpp	Thu Sep 03 20:10:39 2015 +0000
@@ -45,6 +45,9 @@
 #include <stdint.h>
 #include "mbed.h"
 
+#include "cli_uart.h"
+#include "osi.h"
+
 #include "i2cconfig.h"
 #include "cli_uart.h"
 #include "myBoardInit.h"
@@ -53,6 +56,8 @@
 
 I2C i2c(PB_9, PB_8);
 
+OsiLockObj_t    g_i2cLock;
+
 
 //*****************************************************************************
 //
@@ -107,12 +112,16 @@
 */
     int32_t err = 0;
     
+//    RTOS_MUTEX_ACQUIRE(&g_i2cLock);
+        
     err = i2c.read(ucDevAddr,(char*)ucBuffer,ulSize);
     if(err == 1){
        Uart_Write((uint8_t*)"Return error I2C read\n\r");
+//       RTOS_MUTEX_RELEASE(&g_i2cLock);
        return -1;
     }
-//    wait_ms(1);   
+//    wait_ms(1);
+//    RTOS_MUTEX_RELEASE(&g_i2cLock);   
     return 0;
 }
 //****************************************************************************
@@ -153,13 +162,16 @@
         i2c.stop();
 */        
     int32_t err = 0;
-          
+    
+//    RTOS_MUTEX_ACQUIRE(&g_i2cLock);      
     err = i2c.write(ucDevAddr,(char*)ucBuffer,ulSize);
     if(err == 1){
     	Uart_Write((uint8_t*)"Return error I2C write\n\r");
+//    	RTOS_MUTEX_RELEASE(&g_i2cLock);
     	return -1;   	
     }
-//    wait_ms(1);		
+//    wait_ms(1);
+//    RTOS_MUTEX_RELEASE(&g_i2cLock);		
     return 0;
 }