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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cli_uart.cpp Source File

cli_uart.cpp

00001 
00002 #include "mbed.h"
00003 
00004 // Standard includes
00005 #include <stdarg.h>
00006 
00007 #include "myBoardInit.h"
00008 #include "cli_uart.h"
00009 #include "osi.h"
00010 
00011 OsiLockObj_t    g_printLock;
00012 
00013 #if (THIS_BOARD == Seeed_Arch_Max)
00014 Serial uart(PC_6, PC_7);//uart 6
00015 //Serial uart(USBTX, USBRX);
00016 #elif (THIS_BOARD == EA_MBED_LPC4088)
00017 Serial uart(p37, p31);
00018 #endif
00019 
00020 int Uart_Write(unsigned char *inBuff)
00021 {
00022     uint16_t ret, ecount, usLength = strlen((const char *)inBuff);
00023     ecount = 0;
00024     ret = 0;
00025     
00026     while(!(uart.writeable())){ecount++;if(ecount>3000)break;};
00027 
00028     if(uart.writeable()) {
00029 
00030         if(inBuff == NULL) {
00031             printf("Uart Write buffer empty\r\n");
00032             return -1;
00033         }
00034 
00035         RTOS_MUTEX_ACQUIRE(&g_printLock);
00036         ret = usLength;
00037 
00038         while (usLength) {
00039             uart.putc(*inBuff);
00040             usLength--;
00041             inBuff++;
00042         }
00043 
00044         RTOS_MUTEX_RELEASE(&g_printLock);
00045     } else {
00046         printf("Uart Write failed [uart not writeable] now trying printf\r\n");
00047         while (usLength) {
00048             printf("%c",*inBuff);
00049             usLength--;
00050             inBuff++;
00051         }
00052         return -1;
00053     }
00054     
00055     return (int)ret;
00056 
00057 }
00058 
00059 void CLI_Configure(void)
00060 {
00061     uart.baud(115200);
00062     
00063     RTOS_MUTEX_CREATE(&g_printLock);
00064 
00065 }
00066 
00067 //*****************************************************************************
00068 //
00069 //!    prints the formatted string on to the console
00070 //!
00071 //! \param format is a pointer to the character string specifying the format in
00072 //!           the following arguments need to be interpreted.
00073 //! \param [variable number of] arguments according to the format in the first
00074 //!         parameters
00075 //! This function
00076 //!        1. prints the formatted error statement.
00077 //!
00078 //! \return count of characters printed
00079 //
00080 //*****************************************************************************
00081 int Report(const char *pcFormat, ...)
00082 {
00083  int iRet = 0;
00084 //#ifndef NOTERM
00085 
00086   char *pcBuff, *pcTemp;
00087   int iSize = 256;
00088  
00089   va_list list;
00090   pcBuff = (char*)malloc(iSize);
00091   if(pcBuff == NULL)
00092   {
00093       return -1;
00094   }
00095   while(1)
00096   {
00097       va_start(list,pcFormat);
00098       iRet = vsnprintf((char*)pcBuff,iSize,pcFormat,list);
00099       va_end(list);
00100       if(iRet > -1 && iRet < iSize)
00101       {
00102           break;
00103       }
00104       else
00105       {
00106           iSize*=2;
00107           if((pcTemp=(char*)realloc(pcBuff,iSize))==NULL)
00108           { 
00109               Message("Could not reallocate memory\n\r");
00110               iRet = -1;
00111               break;
00112           }
00113           else
00114           {
00115               pcBuff=pcTemp;
00116           }
00117           
00118       }
00119   }
00120   Message(pcBuff);
00121   free(pcBuff);
00122   
00123 //#endif
00124   return iRet;
00125 }
00126 
00127 //*****************************************************************************
00128 //
00129 //!    Outputs a character string to the console
00130 //!
00131 //! \param str is the pointer to the string to be printed
00132 //!
00133 //! This function
00134 //!        1. prints the input string character by character on to the console.
00135 //!
00136 //! \return none
00137 //
00138 //*****************************************************************************
00139 void 
00140 Message(const char *str)
00141 {
00142     
00143     uint16_t ecount = 0;
00144     
00145 //#ifndef NOTERM
00146     while(!(uart.writeable())){ecount++;if(ecount>3000)break;};
00147 
00148     if(uart.writeable()) {
00149 
00150        if(str != NULL){
00151           RTOS_MUTEX_ACQUIRE(&g_printLock);
00152           while(*str!='\0')
00153           {
00154             uart.putc(*str++);
00155           }
00156           RTOS_MUTEX_RELEASE(&g_printLock);
00157        }
00158    }    
00159 //#endif
00160 }
00161 
00162