📄 dc550_controller.c
字号:
/*****************************************************************************/
/* CONFIDENTIAL */
/* Sigpro Copyright 2003, All rights reserved */
/*****************************************************************************/
/* CLIENT: Telematrix */
/* PROJECT: DC550 Digital Centrex Phone */
/* FILE: dc550_controller.c */
/*****************************************************************************/
/* The Software Controller is responsible for interpreting and processing */
/* keypad commands and MDC switch commands properly and promptly */
/*****************************************************************************/
#define __DC550_CONTROLLER_EXTERN__
#include "dc550_controller.h"
#include "dc550_interrupt.h"
#include "dc550_hookswitchmonitor.h"
#include "dc550_phonesm.h"
#include "dc550_usartdriver.h"
/******************************************************************************
* GLOBAL VARIABLES
*****************************************************************************/
// Externally accessible global variables
unsigned int controller_keypress_keys[4];
unsigned int controller_keypress_states[4];
unsigned int controller_keypress_index;
unsigned int controller_modemreceive_commands[8];
unsigned int controller_modemreceive_index;
// Internally accessible global variables
unsigned int controller_hookswitch_updown;
unsigned int controller_periodiclastinterruptcounter;
/******************************************************************************
* FUNCTION: void controller_init(void)
******************************************************************************
* DESCRIPTION:
* This function is called during the initialization phase to initialize all
* of the software controller variables.
*****************************************************************************/
void controller_init(void) {
controller_keypress_index = 0;
controller_hookswitch_updown = hookswitchmonitor_gethookswitchstate();
controller_periodiclastinterruptcounter = interrupt_counter;
phonesm_init();
}
/******************************************************************************
* FUNCTION: void controller_exec(void)
******************************************************************************
* DESCRIPTION:
* This function is called to execute the software controller task. The
* function makes three inquiries:
* 1) If a message was received through the modem, it calls
* phonesm_exec_modemcommand(.)
* 2) If the hookswitch was toggles or keys were pressed or unpressed, it
* calls phonesm_exec_hookswitch(.) and/or phonesm_exec_keypress(.)
* 3) If ten milliseconds have passed since the phonesm_exec_periodic(.)
* was last called, it calls phonesm_exec_periodic(.)
*****************************************************************************/
void controller_exec(void) {
// Declare counter and temporary variable
unsigned int i;
// Part 1: Check if a message was received through the modem
for(i=0; i < controller_modemreceive_index; i++)
phonesm_exec_modemcommand(controller_modemreceive_commands[i]);
controller_modemreceive_index = 0;
// Part 2A: Check if hookswitch changed states
i = hookswitchmonitor_gethookswitchstate();
if(controller_hookswitch_updown != i) {
controller_hookswitch_updown = i;
phonesm_exec_hookswitch(i);
}
// Part 2B: Check if any keys changed states
for(i=0; i < controller_keypress_index; i++)
phonesm_exec_keypress(controller_keypress_keys[i],
controller_keypress_states[i]);
controller_keypress_index = 0;
// Part 3: Check if it's time to call phonesm_exec_periodic(.)
if((interrupt_counter - controller_periodiclastinterruptcounter) >=
CONTROLLER_DURATION_PERIODIC) {
phonesm_exec_periodic();
controller_periodiclastinterruptcounter += CONTROLLER_DURATION_PERIODIC;
}
}
/******************************************************************************
* FUNCTION:
* void controller_report_keypress(unsigned int key, unsigned int updown)
******************************************************************************
* DESCRIPTION:
* This function assumes that indicator is a valid index between 0 and
* 39, and updown is either 1 or 0.
*****************************************************************************/
void controller_report_keypress(unsigned int key, unsigned int updown) {
controller_keypress_keys[controller_keypress_index] = key;
controller_keypress_states[controller_keypress_index] = updown;
controller_keypress_index++;
// We may wish to check for overflow during the debugging process
}
/******************************************************************************
* FUNCTION: void controller_report_modemcommand(DC550MDCMessage command)
******************************************************************************
* DESCRIPTION:
* This function assumes that indicator is a valid index between 0 and
* 39, and updown is either 1 or 0.
*****************************************************************************/
void controller_report_modemcommand(DC550MDCMessage command) {
controller_modemreceive_commands[controller_modemreceive_index] = command;
controller_modemreceive_index++;
}
/******************************************************************************
* FUNCTION: unsigned int controller_gethookswitchstate(void)
******************************************************************************
* DESCRIPTION:
* This is an accessor function for the Phone State Machine's hookswitch
* state.
*****************************************************************************/
unsigned int controller_gethookswitchstate(void) {
return controller_hookswitch_updown;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -