示例#1
0
tSIRF_RESULT SIRF_EXT_AUX_Delete( void )
{
   tSIRF_RESULT result = SIRF_PAL_COM_ERROR;

   if ( SIRF_FALSE == b_Aux_Thread_Running )
      return SIRF_FAILURE;

   b_Aux_Thread_Running = SIRF_FALSE;
   SIRF_PAL_OS_THREAD_Delete(c_hCommReaderThread);
   SIRF_EXT_AUX_Close(0);

   if (c_ExtAuxHandle)
   {
      result = SIRF_PAL_COM_Delete(c_ExtAuxHandle);
      c_ExtAuxHandle = 0;
   }
   SIRF_PAL_OS_SEMAPHORE_Delete(c_aux_open_sem);

   /* Delete Write Mutex */
   result = SIRF_PAL_OS_MUTEX_Delete(c_AUX_COM_WRITE_Critical);
   c_AUX_COM_WRITE_Critical = 0;

   return result;

} /* SIRF_EXT_AUX_Delete */
示例#2
0
/**
 * @brief Teardown the TLSF based PAL dynamic memory subsystem
 *
 * Mark subsystem as uninitialized if currently initialized.
 *
 * @return SIRF_SUCCESS if successful, SIRF_FAILURE otherwise
 */
tSIRF_RESULT SIRF_PAL_OS_MEM_Destroy(void)
{
   tSIRF_RESULT result = SIRF_SUCCESS;
   if (SIRF_TRUE == s_mem_initialized)
   {
      result = SIRF_PAL_OS_MUTEX_Delete(s_MemoryMutex);
      s_mem_initialized = SIRF_FALSE;
   }

   return result;
}
/** 
 * Delete the AT command server instance and release all allocated resources
 * 
 * @return Any error codes that occur during deletion, SIRF_SUCCESS otherwise
 */
tSIRF_RESULT SIRF_GPRS_AT_COMMAND_SERVER_Delete( tSIRF_VOID )
{
   tSIRF_RESULT result;
   tSIRF_RESULT ret_val = SIRF_SUCCESS;
   tSIRF_UINT32 handle;

   if (NULL == gprs_at_command.listener_mx)
   {
      return SIRF_GPRS_AT_COMMAND_SERVER_NOT_CREATED;
   }

   /* Just in case we were in data mode, which out.  */
   gprs_switch_from_data_mode();
   /* Now shutdown the modem */
   result = gprs_stop(gprs_at_command.uartno);
   if (SIRF_SUCCESS == ret_val)
   {
      ret_val = result;
   }

   /* Close port in case it is still open*/
   for ( handle=0; handle < SIRF_GPRS_AT_COMMAND_MAX_HANDLES; handle++ )
   {
      /* ignore the return code and close all handles */
      (void)SIRF_GPRS_AT_COMMAND_SERVER_Close( (tSIRF_GPRS_HANDLE)handle );
   }

   /* Close the thread */
   gprs_at_command.thread_running = SIRF_FALSE;
   result = SIRF_PAL_OS_SEMAPHORE_Release(gprs_at_command.semaphore);
   if (SIRF_SUCCESS == ret_val)
   {
      ret_val = result;
   }

   result = SIRF_PAL_OS_THREAD_Delete(gprs_at_command.server_thread);
   if (SIRF_SUCCESS == ret_val)
   {
      ret_val = result;
   }

   /* Close the UART */
   result = SIRF_EXT_UART_Close(gprs_at_command.uartno);
   if (SIRF_SUCCESS == ret_val)
   {
      ret_val = result;
   }

   result = SIRF_PAL_OS_MUTEX_Delete(gprs_at_command.queue_mx);
   if (SIRF_SUCCESS == ret_val)
   {
      ret_val = result;
   }
      /* Close the Mutex */
   result = SIRF_PAL_OS_MUTEX_Delete( gprs_at_command.listener_mx );
   if (SIRF_SUCCESS == ret_val)
   {
      ret_val = result;
   }
   /* Close the semaphore */
   result = SIRF_PAL_OS_SEMAPHORE_Delete(gprs_at_command.semaphore);
   if (SIRF_SUCCESS == ret_val)
   {
      ret_val = result;
   }

   /* Set the initialization flag to NULL */
   gprs_at_command.listener_mx = NULL;
   gprs_at_command.queue_mx = NULL;

   return result;

} /* SIRF_GPRS_AT_COMMAND_Delete()*/
/** 
 * Create the AT Command server instance
 * 
 * @param port_name Name of the uart port the Modem is connected
 * 
 * @return Success if the port was opened successfully
 */
tSIRF_RESULT SIRF_GPRS_AT_COMMAND_SERVER_Create( 
   tSIRF_CHAR const * const port_name,
   tSIRF_CHAR const * const apn )
{
   tSIRF_RESULT result;
   tSIRF_MSG_SSB_EXT_UART_OPEN_PORT port_settings;

   /* This only works initially if gprs_at_command is in ZI data */
   if (NULL != gprs_at_command.listener_mx)
   {
      return SIRF_GPRS_AT_COMMAND_SERVER_ALREADY_CREATED;
   }

   /* This is necessar if Create is ever called a second time */
   memset( &gprs_at_command, 0, sizeof(gprs_at_command) );

   /* Initialize the queues.  These fucntion cannot fail */
   fifo_queue_init( &gprs_at_command.msg_queue_gprs );
   fifo_queue_init( &gprs_at_command.msg_queue_gprs_input );
   gprs_at_command.command_timeout = DEFAULT_GPRS_RESPONSE_TIMEOUT;

   /* Open a uart port to the modem */
   strlcpy(port_settings.port_name,port_name,sizeof(port_settings.port_name));
   port_settings.baud_rate    = SIRF_GPRS_AT_COMMAND_BAUD_RATE;
   port_settings.flow_control = SIRF_GPRS_AT_COMMAND_FLOW_CONTROL;

   /* Create the semaphore */
   result = SIRF_PAL_OS_SEMAPHORE_Create(&gprs_at_command.semaphore,0);
   if ( SIRF_SUCCESS != result )
   {
      return result;
   }

   result = SIRF_PAL_OS_MUTEX_Create( &gprs_at_command.listener_mx );
   if ( SIRF_SUCCESS != result )
   {
      goto GPRS_ERROR_1;
   }

   result = SIRF_PAL_OS_MUTEX_Create( &gprs_at_command.queue_mx );
   if ( SIRF_SUCCESS != result )
   {
      goto GPRS_ERROR_2;
   }

   gprs_at_command.msg_heap = Heap_Create( GprsMsgQueueHeap_notify,
                                           gprs_heap_space,
                                           sizeof(gprs_heap_space) );
   if (NULL == gprs_at_command.msg_heap)
   {
      goto GPRS_ERROR_3;
   }

   /* Must open the UART last since it might call the callback fuctnion which
    * uses the heap and queues mutex's and semaphores, but before the 
    * queue reading thread since the queue reading thread calls into the
    * uart */
   result = SIRF_EXT_UART_Open(&gprs_at_command.uartno,
                               &port_settings,
                               SIRF_GPRS_AT_COMMAND_UartPacketCallbackATCommand,
                               SIRF_PROTO_GPRS_AT_COMMAND_Parser);

   if ( SIRF_SUCCESS != result )
   {
      goto GPRS_ERROR_4;
   }

   gprs_at_command.thread_running = SIRF_TRUE;
   result = SIRF_PAL_OS_THREAD_Create( 
      SIRFLPL_THREAD_GPRS, 
      (tSIRF_HANDLE)SIRF_GPRS_AT_COMMAND_ReadThread, 
      &gprs_at_command.server_thread );

   if (SIRF_SUCCESS != result)
   {
      goto GPRS_ERROR_5;
   }

   result = gprs_start(gprs_at_command.uartno,
                       SIRF_GPRS_AT_COMMAND_FLOW_CONTROL,
                       apn);
   if (SIRF_SUCCESS != result)
   {
      goto GPRS_ERROR_5;
   }

   return SIRF_SUCCESS;

   

GPRS_ERROR_5:
   /* Must kill our own thread and delete it */
   gprs_at_command.thread_running = SIRF_FALSE;
   (void)SIRF_PAL_OS_SEMAPHORE_Release(gprs_at_command.semaphore);
   (void)SIRF_PAL_OS_THREAD_Delete(gprs_at_command.server_thread);

GPRS_ERROR_4:
   /* Heap_Create doesn't have a Heap Destroy */

GPRS_ERROR_3:
   (void)SIRF_PAL_OS_MUTEX_Delete(gprs_at_command.queue_mx);
   gprs_at_command.queue_mx = NULL;

GPRS_ERROR_2:
   (void)SIRF_PAL_OS_MUTEX_Delete(gprs_at_command.listener_mx);
   gprs_at_command.listener_mx = NULL;

GPRS_ERROR_1:
   (void)SIRF_PAL_OS_SEMAPHORE_Delete(gprs_at_command.semaphore);
   gprs_at_command.semaphore = NULL;
   return result;

} /* SIRF_GPRS_AT_COMMAND_Create()*/