📄 main.c
字号:
/*
Main.c
This file contains the main function, which kicks off the headset
application.
*/
#include "demohs.h"
#include "hal.h"
#include <batt.h>
#include <button.h>
#include <message.h>
#include <pio.h>
#include <print.h>
#include <sched.h>
#include <event.h>
#include <vm.h>
/*
This is a global variable used to maintain the state of the
headset device itself. The structure is defined in demohs.h and
includes information such as which state the device is in (idle,
connecting, etc.), whether or not it is paired, if there is a
button press pending, and if there is a slave connection pending.
All of these states are explained more in the structure definition
of Headset in demohs.h.
*/
HeadsetState hsState;
int main(void)
{
/*
Initialize the timer subsystem. Now we can use timers in the
application.
*/
PRINT(("This is headset!/n"));
TimerInit();
/* Tell the button library we are interested in these buttons */
ButtonInit(HS_BUTTONS_USED, ButtonDirect);
/*
When the connection manager has indicated it is running, then
this function is called to complete powerup procedures. The
openReq() function only sets the duration of the ring
indication for incoming calls.
*/
openReq();
/*
Start polling the voltage level on TEST_A and deliver the
readings to battery.c every 4 * 10sec = 40 seconds.
*/
BattInit(VM_ADC_TEST_A, BATT_MONITOR_PERIOD);
#ifdef DEV_BOARD_HS
/* init some flags we will use */
hsState.turnOffHs = 0;
/* flash some lights */
flashInit();
/* use PIO to turn codec on and off initially its turned off */
PioSetDir(PIO_CODEC, ~0);
PioSet(PIO_CODEC, CODEC_OFF);
#endif
/*
Kick off the Virtual Machine scheduler. This is what calls
each of the tasks in the application.
*/
Sched();
return 0;
}
/*
This function is used to put a message in the message queue to be
delivered to another task. In this case, the message is always
delivered to task #1. In the scope of the Headset demo, task #1
is the Headset Framework Handler (hsf_handler.c).
*/
void putMsg(void *msg)
{
MessagePut(HEADSET_FRAMEWORK_TASK, msg);
}
/*
This is the declaration of the headset task. This loop is called
by the scheduler to process any incoming messages/events from
external tasks. Many of the events may be the result of an action
started by this task (the headset task).
*/
DECLARE_TASK(2)
{
/* Need a void msg pointer for incoming messages */
void * msg;
/* Need to know what type of message was sent. This type may be
different depending on the library used.
*/
MessageType type;
/*
Get the message, if any, from the queue so that we can process
it. Notice that only one message is processed at a time.
*/
msg = MessageGet(HEADSET_TASK, &type);
if(msg)
{
switch (type)
{
/*
The actions taken by openReq(), which was called in
main() have finished.
*/
case HS_OPEN_CFM:
openCfm((HS_OPEN_CFM_T*) msg);
break;
/*
The pairing operation has completed. Success or failure
is not known until you look into the inner workings of
pairCfm().
*/
case HS_PAIR_CFM:
pairCfm((HS_PAIR_CFM_T*) msg);
break;
/*
The connect operation has completed. Success or failure
is not known until you look into the inner workings of
connectCfm()
*/
case HS_CONNECT_CFM:
connectCfm((HS_CONNECT_CFM_T *) msg);
break;
/*
Indication that the RFCOMM connection has been
diconnected This can be due to a user action or to a
failure resulting in the disconnection.
*/
case HS_CONNECT_STATUS_IND:
connectStatusInd((HS_CONNECT_STATUS_IND_T*) msg);
break;
/*
There is an incoming call. This is the indication that
should cause the headset to "ring" or otherwise indicate
to the user that there is an incoming call.
*/
case HS_RING_IND:
ringInd((HS_RING_IND_T*) msg);
break;
/*
This event indicates news about the SCO connection.
Generally the news informs the application of a SCO
disconnection.
*/
case HS_SCO_STATUS_IND:
scoStatusInd((HS_SCO_STATUS_IND_T*) msg);
break;
/*
This event relays information about volume/microphone
gain adjustments.
*/
case HS_VGS_IND:
vgsInd((HS_VGS_IND_T*) msg);
break;
/*
This event relays information about an incoming command
that is unrecognized.
*/
case HS_CMD_IND:
cmdInd((HS_CMD_IND_T*) msg);
break;
/*
This event indicates that an error has occurred and
gives an error code to indicate what went wrong.
*/
case HS_ERROR_IND:
errorInd((HS_ERROR_IND_T *) msg);
break;
/*
This event informs the headset app that the software reset
(i.e. writes to PS) has completed
*/
case HS_RESET_CFM:
resetCfm();
break;
case HS_MIC_IND:
microphoneGainInd((HS_MIC_IND_T*) msg);
break;
default :
PRINT(("headset: Unrecognised msg type 0x%x\n",type));
break;
}
/* Done with the message. Free the memory. */
MessageDestroy(msg);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -