Customized SNICInterface

Fork of NySNICInterface by Ryo Iizuka

Revision:
43:d80bbb12ffe6
Parent:
41:1c1b5ad4d491
--- a/SNIC/SNIC_Core.cpp	Fri Sep 19 01:46:17 2014 +0000
+++ b/SNIC/SNIC_Core.cpp	Fri Nov 14 00:52:31 2014 +0000
@@ -42,12 +42,15 @@
 unsigned char  gUART_TEMP_BUF[UART_RECVBUF_SIZE]                __attribute__((section("AHBSRAM1")));
 unsigned char  gUART_COMMAND_BUF[UART_REQUEST_PAYLOAD_MAX]      __attribute__((section("AHBSRAM1")));
 /** MemoryPool for payload of UART response */
-MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_PAYLOAD_NUM>     mMemPoolPayload  __attribute__((section("AHBSRAM1")));
+//MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_PAYLOAD_NUM>     mMemPoolPayload  __attribute__((section("AHBSRAM1")));
+MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_PAYLOAD_NUM>     mMemPoolPayload  __attribute__((section("AHBSRAM0")));
 /** MemoryPool for UART receive */
-MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_UART_RECV_NUM>   mMemPoolUartRecv __attribute__((section("AHBSRAM1")));
+MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_UART_RECV_NUM>   mMemPoolUartRecv __attribute__((section("AHBSRAM0")));
 Queue<tagMEMPOOL_BLOCK_T, MEMPOOL_UART_RECV_NUM>        mUartRecvQueue;
 
 tagMEMPOOL_BLOCK_T   *gUART_RCVBUF_p;
+int gUART_RECV_COUNT = 0;
+
 C_SNIC_Core *C_SNIC_Core::mInstance_p = NULL;
 
 C_SNIC_Core *C_SNIC_Core::getInstance()
@@ -68,6 +71,7 @@
     {
         mConnectInfo[i].recvbuf_p    = NULL;
         mConnectInfo[i].is_connected = false;
+        mConnectInfo[i].is_receive_complete = true;
         
         mUdpRecvInfo[i].recvbuf_p    = NULL;
         mUdpRecvInfo[i].is_received  = false;
@@ -86,9 +90,9 @@
     DigitalOut reset_pin( reset );
 
     reset_pin = 0;
-    wait(0.1);
+    wait(0.3);
     reset_pin = 1;
-    wait(0.1);
+    wait(0.3);
     
     return 0;
 }
@@ -200,6 +204,16 @@
     return gUART_COMMAND_BUF;
 }
 
+void C_SNIC_Core::lockAPI( void )
+{
+    mAPIMutex.lock();
+}
+
+void C_SNIC_Core::unlockAPI( void )
+{
+    mAPIMutex.unlock();
+}
+
 void C_SNIC_Core::uartRecvCallback( void )
 {
     C_SNIC_Core *instance_p = C_SNIC_Core::getInstance();
@@ -240,11 +254,15 @@
                         
                         gUART_RCVBUF_p = NULL;
                     
+                        if( gUART_RECV_COUNT >= MEMPOOL_UART_RECV_NUM )
+                        {
+                            instance_p->mUart_p->attach( NULL );
+                        }
                         // set signal for dispatch thread
                         instance_p->mUartRecvDispatchThread_p->signal_set( UART_DISPATCH_SIGNAL );
+                        break;
                     }
                 }
-
             }
             else
             {
@@ -252,8 +270,10 @@
                 if( recvdata == UART_CMD_SOM )
                 {
                     gUART_RCVBUF_p = instance_p->allocUartRcvBuf();
+                    gUART_RECV_COUNT++;
                     gUART_RCVBUF_p->size = 0;
                     gUART_RCVBUF_p->demand_size = 0;
+
                     // get buffer for Uart receive
                     gUART_RCVBUF_p->buf[ 0 ] = (unsigned char)recvdata;
                     
@@ -340,11 +360,16 @@
                 }
                 else
                 {
-                    DEBUG_PRINT(" The received data is not expected.\r\n");
+                    //DEBUG_PRINT(" The received data is not expected.\r\n");
                 }
                 
                 // 
                 instance_p->freeUartRecvBuf( uartRecvBuf_p );
+                gUART_RECV_COUNT--;
+                if( gUART_RECV_COUNT == (MEMPOOL_UART_RECV_NUM-1) )
+                {
+                    instance_p->mUart_p->attach( C_SNIC_Core::uartRecvCallback );   //debug
+                }
                 
                 evt = mUartRecvQueue.get(500);
             } while( evt.status == osEventMessage );