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 11:404bd8bb7fa6, committed 2015-07-07
- Comitter:
- dflet
- Date:
- Tue Jul 07 22:56:31 2015 +0000
- Parent:
- 10:f2447c682c0f
- Child:
- 12:7d75ba5deed1
- Commit message:
- WIP commit 12
Changed in this revision
--- a/camera_app/camera_app.cpp Mon Jul 06 23:20:14 2015 +0000
+++ b/camera_app/camera_app.cpp Tue Jul 07 22:56:31 2015 +0000
@@ -326,29 +326,32 @@
//!
//
//*****************************************************************************
-DCMI_HandleTypeDef phdcmi;
-DMA_HandleTypeDef hdma_dcmi;
static unsigned short CaptureImage(char** WriteBuffer)
{
+ DCMI_HandleTypeDef phdcmi;
+ DMA_HandleTypeDef hdma_dcmi;
// Uart_Write((uint8_t*)"CaptureImage \n\r");
-// memset(g_image.g_image_buffer,0xF80F,sizeof(g_image.g_image_buffer));
- memset(g_image.g_image_buffer,0x0F,sizeof(g_image.g_image_buffer));
+ memset(g_image.g_image_buffer,0xF80F,sizeof(g_image.g_image_buffer));
+// memset(g_image.g_image_buffer,0x0F,sizeof(g_image.g_image_buffer));
p_buffer = &(g_image.g_image_buffer[0]);
DMAConfig();
-
+
//
// Perform Image Capture
//
// wait_ms(500);
+#ifdef ENABLE_JPEG
HAL_DCMI_Start_DMA(&phdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)p_buffer, NUM_OF_4B_CHUNKS);
-// HAL_DCMI_Start_DMA(&phdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)p_buffer, FRAME_SIZE_IN_BYTES/4);
+#else
+ HAL_DCMI_Start_DMA(&phdcmi, DCMI_MODE_CONTINUOUS, (uint32_t)p_buffer, NUM_OF_4B_CHUNKS);
+#endif
+ HttpDebug("CaptureImage Complete\n\r");
g_frame_end = 1;
- /* Read the number of data items transferred (4 x uints = bytes)*/
-// g_frame_size_in_bytes = (FRAME_SIZE_IN_BYTES - (hdma_dcmi.Instance->NDTR*4));
+ /* Read the number of data items transferred (4 x uint = 4 bytes) */
g_frame_size_in_bytes = 4*(NUM_OF_4B_CHUNKS - hdma_dcmi.Instance->NDTR);
- if(NUM_OF_4B_CHUNKS == hdma_dcmi.Instance->NDTR){
+ if(g_frame_size_in_bytes <= 0){
HttpDebug("\r\nFailed to capture any data, check camera connections!\r\n");
HAL_DCMI_MspDeInit(&phdcmi);
while(1){
@@ -360,12 +363,12 @@
HttpDebug("g_frame_size_in_bytes = 0x%x \r\n",g_frame_size_in_bytes);
- uint8_t* Image_Array = reinterpret_cast<uint8_t*>(&g_image.g_image_buffer);
-#if 0
+ uint8_t* Image = reinterpret_cast<uint8_t*>(&g_image.g_image_buffer);
+//#if 0
for(int i =0;i< 10;i++){
- HttpDebug("0x%x ",Image_Array[i]);
+ HttpDebug("0x%x ",Image[i]);
}
-#endif//if 0
+//#endif//if 0
//
// Create JPEG Header
//
@@ -375,17 +378,17 @@
PIXELS_IN_Y_AXIS, 0, 0x0020, 9);
// This pushes the header to the start of the array so that the entire picture can be contiguous in memory
- memcpy(Image_Array + g_header_length,Image_Array,g_frame_size_in_bytes);
- memcpy(Image_Array,g_image.g_header,g_header_length);
+ memcpy(Image + g_header_length, Image, g_frame_size_in_bytes);
+ memcpy(Image, g_image.g_header, g_header_length);
#if 0
- for(int i =625;i< 725;i++){
- HttpDebug("0x%x ",Image_Array[i]);
+ for(int i =624;i< 725;i++){
+ HttpDebug("0x%x ",Image[i]);
}
#endif//if 0
#endif//ENABLE_JPEG
- *WriteBuffer = (char*)Image_Array;
+ *WriteBuffer = (char*)Image;
return(g_header_length + g_frame_size_in_bytes);
}
@@ -400,6 +403,8 @@
//*****************************************************************************
static void DMAConfig()
{
+ DCMI_HandleTypeDef phdcmi;
+ DMA_HandleTypeDef hdma_dcmi;
// Uart_Write((uint8_t*)"DMAConfig \n\r");
/* Peripheral DMA init*/
@@ -410,20 +415,20 @@
hdma_dcmi.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_dcmi.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_dcmi.Init.MemInc = DMA_MINC_ENABLE;
- hdma_dcmi.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;//Cam is 1 byte wide data (8 bits) should this be word as well?????
+ hdma_dcmi.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;//Cam is 1 byte wide data (8 bits) should this be word?????
hdma_dcmi.Init.MemDataAlignment = DMA_PDATAALIGN_WORD;//Memory is defined as uint (1 word)
hdma_dcmi.Init.Mode = DMA_CIRCULAR;
hdma_dcmi.Init.Priority = DMA_PRIORITY_HIGH;
- hdma_dcmi.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
+ hdma_dcmi.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
hdma_dcmi.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
hdma_dcmi.Init.MemBurst = DMA_MBURST_SINGLE;
hdma_dcmi.Init.PeriphBurst = DMA_PBURST_SINGLE;
hdma_dcmi.Instance = DMA2_Stream1;
- __HAL_LINKDMA(&phdcmi,DMA_Handle,hdma_dcmi);
+ __HAL_LINKDMA(&phdcmi, DMA_Handle, hdma_dcmi);
/* DMA interrupt init */
- HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 1, 0);
+ HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);
/* Peripheral DCMI init*/
@@ -520,7 +525,7 @@
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* System interrupt init*/
- HAL_NVIC_SetPriority(DCMI_IRQn, 1, 0);
+ HAL_NVIC_SetPriority(DCMI_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(DCMI_IRQn);
HAL_DMA_Init(&hdma_dcmi);
--- a/camera_app/httpserverapp/httpserverapp.cpp Mon Jul 06 23:20:14 2015 +0000
+++ b/camera_app/httpserverapp/httpserverapp.cpp Tue Jul 07 22:56:31 2015 +0000
@@ -209,7 +209,8 @@
Uart_Write((uint8_t*)"HttpServerAppTask \n\r");
//Run APPS HTTP Server
HttpServerInitAndRun(NULL);
-
+
+ Uart_Write((uint8_t*)"HttpServerAppTask has returned for some reason\n\r");
LOOP_FOREVER();
}
--- a/http/server/HttpCore.cpp Mon Jul 06 23:20:14 2015 +0000
+++ b/http/server/HttpCore.cpp Tue Jul 07 22:56:31 2015 +0000
@@ -143,10 +143,10 @@
* This structure holds all of the global state of the HTTP server
*/
//#ifdef __CCS__
-typedef struct __attribute__ ((__packed__)) HttpGlobalState
+//typedef struct __attribute__ ((__packed__)) HttpGlobalState
//#elif __IAR_SYSTEMS_ICC__
//#pragma pack(1)
-//typedef struct //HttpGlobalState
+struct HttpGlobalState
//#endif
{
/// The listening socket
@@ -163,7 +163,7 @@
UINT8 packetSend[HTTP_CORE_MAX_PACKET_SIZE_SEND];
/// Size of data in the packet-send buffer
UINT16 packetSendSize;
-}HttpGlobalState;
+};
/// The global state of the HTTP server
struct HttpGlobalState g_state;
@@ -219,7 +219,7 @@
RunHttpServer();
}
-void RunHttpServer(void)
+void RunHttpServer()
{
int iRecvLen = 0, sock = -1, uConnection = 0;
struct HttpBlob blob;
@@ -327,7 +327,7 @@
else if(g_state.uOpenConnections == 0)
{
/* wait 500ms */
- wait(0.5);
+ wait_ms(500);
}
}
}
@@ -1420,12 +1420,12 @@
HttpResponse_AddStringToResponseHeaders(EncOutKey, strlen(EncOutKey));
HttpResponse_AddStringToResponseHeaders(HTTP_HEADER_DELIMITER, strlen(HTTP_HEADER_DELIMITER));
- // Server : CC3200
+ // Server : CC3100
// This field informs the client the server name
HttpResponse_AddStringToResponseHeaders("Server", strlen("Server"));
HttpResponse_AddCharToResponseHeaders(':');
HttpResponse_AddCharToResponseHeaders(' ');
- HttpResponse_AddStringToResponseHeaders("CC3200", strlen("CC3200"));
+ HttpResponse_AddStringToResponseHeaders("CC3100", strlen("CC3100"));
HttpResponse_AddStringToResponseHeaders(HTTP_HEADER_DELIMITER, strlen(HTTP_HEADER_DELIMITER));
// This is the same origin supplied by the client. The origin tells the server whether the client is a browser or not.
--- a/main.cpp Mon Jul 06 23:20:14 2015 +0000
+++ b/main.cpp Tue Jul 07 22:56:31 2015 +0000
@@ -77,7 +77,7 @@
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
- RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;//Used for ov7670 test
+// RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;//Used for ov7670 test
__PWR_CLK_ENABLE();
// __GPIOH_CLK_ENABLE(); //Enable HSE Clock 8MHz
@@ -102,10 +102,10 @@
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
//Used for ov7670 test
- PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_PLLI2S;//|RCC_PERIPHCLK_I2S;
- PeriphClkInitStruct.PLLI2S.PLLI2SN = 192;
- PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
- HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
+// PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_PLLI2S;//|RCC_PERIPHCLK_I2S;
+// PeriphClkInitStruct.PLLI2S.PLLI2SN = 192;
+// PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
+// HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
/* RCC_MCODIV_5 33.6MHz mco2 output on pin PC_9 (cam xclk) */
/* RCC_MCODIV_4 42MHz mco2 output on pin PC_9 (cam xclk) */
@@ -113,16 +113,16 @@
// HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_4);
/* RCC_MCODIV_1 16MHz mco1 output on pin PA_8 (cam xclk) */
- HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1);
+// HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1);
/* RCC_MCODIV_1 8MHz mco2 output on pin PC_9 (cam xclk) */
/* RCC_MCODIV_2 4MHz mco2 output on pin PC_9 (cam xclk) */
/* RCC_MCODIV_4 2MHz mco2 output on pin PC_9 (cam xclk) */
-// HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_HSE, RCC_MCODIV_1);
+ HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_HSE, RCC_MCODIV_4);
//Used for ov7670 test
/* RCC_MCODIV_4 24MHz mco2 output on pin PC_9 (cam xclk) */
- HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_PLLI2SCLK, RCC_MCODIV_4);
+// HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_PLLI2SCLK, RCC_MCODIV_4);
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
@@ -384,27 +384,27 @@
* @param None
* @retval None
*/
+/*
void DMA2_Stream1_IRQHandler(void)
{
- DCMI_HandleTypeDef hdcmi;
DMA_HandleTypeDef hdma_dcmi;
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)
{
DCMI_HandleTypeDef hdcmi;
- DMA_HandleTypeDef hdma_dcmi;
Uart_Write((uint8_t*)"DCMI_IRQHandler \n\r");
HAL_DCMI_IRQHandler(&hdcmi);
}
-
+*/
//*****************************************************************************
//
// Close the Doxygen group.
--- a/utils/app_config.h Mon Jul 06 23:20:14 2015 +0000 +++ b/utils/app_config.h Tue Jul 07 22:56:31 2015 +0000 @@ -4,8 +4,8 @@ #define SPAWN_TASK_PRIORITY 7//9 -#define HTTP_SERVER_APP_TASK_PRIORITY 2//1 -#define CAMERA_SERVICE_PRIORITY 2 +#define HTTP_SERVER_APP_TASK_PRIORITY 1//1 +#define CAMERA_SERVICE_PRIORITY 1 #define OSI_STACK_SIZE 2048