⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 bc5_stereo:bluetooth stereo Headset CODE 支持A2DP HSP 和 HSP 。可作为车载免提。BlueLab 2007环境下编译
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2007

FILE NAME
    main.c
    
DESCRIPTION
    Main entry point for the application.
    
*/


#include "headset_a2dp_msg_handler.h"
#include "headset_a2dp_stream_control.h"
#include "headset_amp.h"
#include "headset_avrcp_event_handler.h"
#include "headset_avrcp_msg_handler.h"
#include "headset_cl_msg_handler.h"
#include "headset_codec_msg_handler.h"
#include "headset_debug.h"
#include "headset_event_handler.h"
#include "headset_events.h"
#include "headset_hfp_msg_handler.h"
#include "headset_init.h"
#include "headset_LEDmanager.h"
#include "headset_private.h"

#include <a2dp.h>
#include <avrcp.h>
#include <boot.h>
#include <codec.h>
#include <connection.h>
#include <hfp.h>
#include <panic.h>
#include <stdlib.h>

#ifdef TEST_HARNESS
#include "test_bc5_stereo.h"
#endif

#ifdef DEBUG_MAIN
#define MAIN_DEBUG(x) DEBUG(x)
#else
#define MAIN_DEBUG(x) 
#endif


/* Single instance of the Headset state */
static hsTaskData theHeadset;


/****************************************************************************
  FUNCTIONS
*/


/* Handle any application messages */
static void handleAppMessage( Task task, MessageId id, Message message )
{
	hsTaskData * lApp = (hsTaskData *) getAppTask() ;
	
	switch (id)
    {        
    case APP_RESUME_A2DP:
        MAIN_DEBUG(("APP_RESUME_A2DP\n"));		
        streamControlBeginA2dpStreaming( lApp );
        break;
	case APP_AVRCP_CONTROLS:
		MAIN_DEBUG(("APP_AVRCP_CONTROLS\n"));
		avrcpEventHandleControls(lApp, (APP_AVRCP_CONTROLS_T*)message);
		break;
	case APP_AVRCP_CONNECT_REQ:
		MAIN_DEBUG(("APP_AVRCP_CONNECT_REQ\n"));
		handleAVRCPConnectReq(lApp, (APP_AVRCP_CONNECT_REQ_T*)message);
		break;
	case APP_AMP_OFF:
		MAIN_DEBUG(("APP_AMP_OFF\n"));
		AmpOff(lApp);
		break;
	case APP_SEND_PLAY:
		MAIN_DEBUG(("APP_SEND_PLAY\n"));
		if (lApp->autoSendAvrcp)
			avrcpSendPlay(lApp);
		break;
		
	default:
		MAIN_DEBUG(("APP UNHANDLED MSG: 0x%x\n",id));
		break;
	}
}


/* Pass the message to the test harness if running in test mode. */
#ifdef TEST_HARNESS
	#define TEST_HANDLE_LIB_MESSAGE(t,i,m) test_handle_lib_message(t, i,  m);
#else
	#define TEST_HANDLE_LIB_MESSAGE(t,i,m)
#endif

/*************************************************************************
NAME    
    app_handler
    
DESCRIPTION
    This is the main message handler for the Headset Application.  All
    messages pass through this handler to the subsequent handlers.

RETURNS

*/
static void app_handler(Task task, MessageId id, Message message)
{
    /* Determine the message type based on base and offset */
    if ( ( id >= EVENTS_EVENT_BASE ) && ( id <= EVENTS_LAST_EVENT ) )
    {
        /* Message is a User Generated Event */
        handleUEMessage(task, id,  message);
    }
    else if ( (id >= CL_MESSAGE_BASE) && (id <= CL_MESSAGE_TOP) )
    {
        handleCLMessage(task, id,  message);
        TEST_HANDLE_LIB_MESSAGE(task, id,  message);
    }
    else if ( (id >= CODEC_MESSAGE_BASE ) && (id <= CODEC_MESSAGE_TOP) )
    {     
        handleCodecMessage(task, id,  message);
    }
    else if ( (id >= HFP_MESSAGE_BASE ) && (id <= HFP_MESSAGE_TOP) )
    {     
        handleHFPMessage(task, id,  message);
        TEST_HANDLE_LIB_MESSAGE(task, id,  message);
    }      
    else if ( (id >= A2DP_MESSAGE_BASE ) && (id <= A2DP_MESSAGE_TOP) )
    {     
        handleA2DPMessage(task, id,  message);
        TEST_HANDLE_LIB_MESSAGE(task, id,  message);
    }      
    else if ( (id >= AVRCP_MESSAGE_BASE ) && (id <= AVRCP_MESSAGE_TOP) )
    {     
        handleAVRCPMessage(task, id,  message);
        TEST_HANDLE_LIB_MESSAGE(task, id,  message);
    }      
	else if ( (id >= HEADSET_MSG_BASE ) && (id <= HEADSET_MSG_TOP) )
    {     
        handleAppMessage(task, id,  message);
    }  
    else /* This message is not one of the above */
    {
        /* Pass this message to default handler */
        MAIN_DEBUG(("MSGTYPE ? [%x]\n", id)) ;
    }
}


Task getAppTask(void)
{
    return &theHeadset.task;
}


int main(void)
{
    MAIN_DEBUG(("Main entered\n")); 
    
	PROFILE_MEMORY(("InitStart"))
	PROFILE_TIME(("InitStart"))
	
    LEDManagerSetPowerPin ( &theHeadset , POWER_ON ) ;
    
    /* Set up the Application task handler */
    theHeadset.task.handler = app_handler;
    
    /* Initialise the data contained in the hsTaskData structure */
    InitHeadsetData(&theHeadset);

    /* Initialise the Codec Library */
    InitCodec();

#ifdef TEST_HARNESS
    test_register(&theHeadset.task);
#endif

    /* Start the message scheduler loop */
    MessageLoop();
    
    /* Never get here...*/
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -