gusucode.com > target工具箱matlab源码程序 > target/codertarget/rtos/targetservices/Services.cpp

    /* Copyright 2013-2016 The MathWorks, Inc. */
#include "MemoryService.hpp"
#include "CommService.hpp"
#include <coder/target_services/coder_target_services_spec.h>

namespace coder { namespace tgtsvc {

static MemoryService *theMemSvc = NULL;
static CommService *theCommSvc = NULL;
static StatusFlags theStatFlags;

MemoryService &MemoryService::instance()
{
    if (theMemSvc == NULL) {
        theMemSvc = new MemoryService();
    }
    return *theMemSvc;
}
CommService &CommService::instance(uint16_t portNo)
{
    if (theCommSvc == NULL) {
        theCommSvc = new CommService(portNo);
        theCommSvc->initialize();
    }
    return *theCommSvc;
}
CommService &CommService::instance()
{
    if (theCommSvc == NULL) {
        theCommSvc = new CommService();
        theCommSvc->initialize();
    }
    return *theCommSvc;
}

StatusFlags &StatusFlags::instance()
{
    return theStatFlags;
}

CODER_TARGET_SERVICES_EXPORT_FCN void resetServices()
{
    if (theCommSvc) delete theCommSvc;
    if (theMemSvc) delete theMemSvc;

    theCommSvc = NULL;
    theMemSvc = NULL;
    theStatFlags.clear();
}

}}


CODER_TARGET_SERVICES_EXPORT_EXTERN_C void* getMemoryService() { return &coder::tgtsvc::MemoryService::instance(); }
CODER_TARGET_SERVICES_EXPORT_EXTERN_C void initializeCommService(uint16_t portNo) 
{ 
    if (coder::tgtsvc::theCommSvc != NULL) 
    {
        delete coder::tgtsvc::theCommSvc;
    }
	coder::tgtsvc::CommService::instance(portNo);
}
CODER_TARGET_SERVICES_EXPORT_EXTERN_C int makeCSTaskIdle()
{
    return coder::tgtsvc::CommService::instance().makeCommServiceTaskIdle();
}
CODER_TARGET_SERVICES_EXPORT_EXTERN_C void terminateCommService()
{
    if (coder::tgtsvc::theCommSvc != NULL) 
    {
        delete coder::tgtsvc::theCommSvc;
    }
}
CODER_TARGET_SERVICES_EXPORT_EXTERN_C void* getStatusFlags() { return &coder::tgtsvc::StatusFlags::instance(); }