/** * @brief Initializes the TLSF based PAL dynamic memory subsystem. * * FYI: TLSF == Two-Level Segregated Fit * * Initialize Heap with static pool if it isn't already initialized. * * @return SIRF_SUCCESS if successful, SIRF_FAILURE otherwise. */ tSIRF_RESULT SIRF_PAL_OS_MEM_Init(void) { tSIRF_RESULT result = SIRF_SUCCESS; if (SIRF_FALSE == s_mem_initialized) { result = SIRF_PAL_OS_MUTEX_Create(&s_MemoryMutex); if (SIRF_SUCCESS != result) { return result; } s_MemoryHeap = Heap_Create(NullHeapNotify, s_HeapMem, sizeof(s_HeapMem)); if (NULL == s_MemoryHeap) { result = SIRF_FAILURE; } else { s_mem_initialized = SIRF_TRUE; } } return result; }
/** * 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()*/
tSIRF_RESULT SIRF_EXT_AUX_Create(tSIRF_UINT32 port, tSIRF_UINT32 baud_rate) { tSIRF_RESULT tRet; /* Create write mutex */ tRet = SIRF_PAL_OS_MUTEX_Create(&c_AUX_COM_WRITE_Critical); if (SIRF_SUCCESS == tRet) { /* programmers note: this allocates a COM channel for each potential input port; * right now this is always a COM port, but when we go to LPL, it will become * a programmatic interface. Also, fyi, we only support one COM port here for now. */ tRet = SIRF_PAL_OS_SEMAPHORE_Create(&c_aux_open_sem, 0); if (SIRF_SUCCESS == tRet) { tRet = SIRF_PAL_COM_Create(&c_ExtAuxHandle); if (SIRF_SUCCESS == tRet) { /* rds programmers note; c_auxno_set is really a counting semaphore * that clears when the thread starts running in context */ c_auxno_set = 1; #if defined(TOOLCHAIN_VC8) #pragma warning (disable : 4054) /* cast from function to data pointer */ #endif tRet = SIRF_PAL_OS_THREAD_Create(SIRF_EXT_AUX_THREAD_1, (tSIRF_HANDLE)SIRF_EXT_AUX_CommThread, &c_hCommReaderThread); #if defined(TOOLCHAIN_VC8) #pragma warning (default : 4054) /* cast from function to data pointer */ #endif if (SIRF_SUCCESS == tRet) { SIRF_PAL_OS_THREAD_Sleep ( 10 ); tRet = SIRF_EXT_AUX_Open( 0, port, baud_rate ); while (c_auxno_set) { SIRF_PAL_OS_THREAD_Sleep(100); } } else { SIRF_PAL_OS_SEMAPHORE_Delete(c_aux_open_sem); SIRF_PAL_COM_Delete(c_ExtAuxHandle); SIRF_EXT_AUX_Close(0); } /* Thread Create */ } else { SIRF_PAL_OS_SEMAPHORE_Delete(c_aux_open_sem); } /* COM_Create */ } /* SEMAPHORE_Create */ } /* Mutex create */ return tRet; } /* SIRF_EXT_AUX_Create */