📄 onboard_xbee.c
字号:
TurnOffBigLight;
}
/*********************************************************************
* Keypad Support
*/
#if defined ( KB_INT )
/*
* Keyboard Interrupt Module Interrupt Service Routine
*/
void interrupt Keyboard_ISR( void )
{
// disable key interrupts
KBIntSetup( false );
// Allow other interrupts, assuming only other interrupt is MAC
EnableInts;
// Wait to avoid the key bouncing
osal_set_event( OnBoard_TaskID, KEYPRESS_DEBOUNCE_EVT );
// Disable interrupts before returning from ISR
DisableInts;
}
#endif // KB_INT
/*********************************************************************
* Keyboard Register function
*
* The keyboard handler is setup to send all keyboard changes to
* one task (if a task is registered).
*
* If a task registers, it will get all the keys. You can change this
* to register for individual keys.
*/
byte RegisterForKeys( byte task_id )
{
// Allow only the first task
if ( registeredKeysTaskID == 0xFF )
{
registeredKeysTaskID = task_id;
return ( true );
}
else
return ( false );
}
#if defined ( KB_INT )
void KBIntSetup( byte state_on )
{
// Clear any pending
KBISC = (KBISC & 0xF1) | KBACK;
// Initialize the Control Register
if ( state_on )
KBISC = (KBISC & 0xF1) | KBIE; // KBIE - Turn interrupt on
else
KBISC = KBISC & 0xF1; // KBIE - Turn interrupt off
}
#endif
/*
* Initialize the Keyboard Module
*/
void KBInit( void )
{
// Initialize the Port for Keyboard
#if defined ( KB_INT )
KBISC = 0x00;
// Initialize the Pin Enable Register
KBIPE = EVAL_SW_MASK;
#endif // KB_INT
_SavedKeys = 0;
}
byte DetermineKeyShift( void )
{
byte shift = false;
return ( shift );
}
// Send "Key Pressed" message to application
byte OnBoard_SendKeys( byte shift, byte keys )
{
byte *msgPtr;
byte *pBuf;
if ( registeredKeysTaskID != 0xFF )
{
// Send the address to the task
if ( osal_msg_allocate( &msgPtr, 3 ) == ZSUCCESS )
{
pBuf = msgPtr;
*pBuf++ = KEY_CHANGE; // Command ID
*pBuf++ = shift;
*pBuf = keys;
osal_msg_send( registeredKeysTaskID, msgPtr, 3 );
}
return ( ZSuccess );
}
else
return ( ZFailure );
}
/*
* Routine to poll for key presses
*/
void OnBoard_read_keys( void )
{
byte keys;
keys = OnBoard_GetKeys();
if ( (keys & EVAL_SW_MASK) == 0 )
return;
// Try to send a key
if ( OnBoard_SendKeys( DetermineKeyShift(), keys ) != ZSuccess )
{
if ( keys & EVAL_SW4 ) // Switch 4
{
}
else if ( keys & EVAL_SW3 ) // Switch 3
{
}
else if ( keys & EVAL_SW2 ) // Switch 2
{
}
else if ( keys & EVAL_SW1 ) // Switch 1
{
}
}
}
/*
* Read the keys from the evaluation board
*/
byte OnBoard_GetKeys( void )
{
byte keys;
keys = PTBD;
// Flip the keys bits
keys = ~keys & EVAL_SW_MASK;
#if !defined ( KB_INT )
if ( keys == _SavedKeys )
return ( 0 );
_SavedKeys = keys;
#endif
return ( keys );
}
/*********************************************************************
* @fn SerialSetRxFlow
*
* @brief Set serial port Rx flow control
* @param port: serial port bit(s)
* on: 0=OFF, !0=ON
* @return none
*/
void SerialSetRxFlow( byte port, byte on )
{
#if defined ( FS_RX_FLOWCONTROL )
#if defined (SERIAL_PORT1)
if ( port & SERIAL_PORT1 )
{
if ( on )
{
// Enable RX flow
SERIAL_PORT1_RX_RTS_ENABLE;
osal_start_timerEx( OnBoard_TaskID, RX1_FLOW_TIMER_EVT, 1000 );
}
else
{
// Disable RX flow
SERIAL_PORT1_RX_RTS_DISABLE;
osal_stop_timerEx( OnBoard_TaskID, RX1_FLOW_TIMER_EVT );
}
}
#endif // SERIAL_PORT1
#if defined (SERIAL_PORT2)
if ( port & SERIAL_PORT2 )
{
if ( on )
{
// Enable RX flow
SERIAL_PORT2_RX_RTS_ENABLE;
osal_start_timerEx( OnBoard_TaskID, RX2_FLOW_TIMER_EVT, 1000 );
}
else
{
// Disable RX flow
SERIAL_PORT2_RX_RTS_DISABLE;
osal_stop_timerEx( OnBoard_TaskID, RX2_FLOW_TIMER_EVT );
}
}
#endif // SERIAL_PORT2
#endif // FS_RX_FLOWCONTROL
}
#ifdef POWER_SAVING
/*********************************************************************
* @fn OnBoard_Sleep
*
* @brief Enter specified sleep mode.
*
* @param mode - sleep mode
* 1 = LITE
* 2 = DEEP
* @return None
*/
void OnBoard_Sleep( byte mode )
{
osal_sleep_timers();
__asm WAIT;
osal_adjust_timers();
osal_unsleep_timers();
}
#endif /* POWER_SAVING */
/*********************************************************************
* TIMER CONTROL FUNCTIONS
*
* This development board uses Motorola HCS08 Timer/PWM 1 to provide
* system clock ticks for the OSAL scheduler. These functions perform
* the hardware specific actions required by the OSAL_Timers module.
*/
/*********************************************************************
* @fn TimerSetControls
*
* @brief Sets various time control registers
* @param turnOn - 0=disable, !0=enable
* @param count - Output Compare A pre-load
* @return none
*/
void TimerSetControls( byte turnOn, uint16 count )
{
#ifndef WIN32
// Timer 1 - System Timer
TPM1C0SC = 0;
TPM1C1SC = 0;
TPM1C2SC = 0;
#if !defined( TIMER_INT )
if ( turnOn )
#if defined( CPU16MHZ )
TPM1SC = (TSC_BUSRATE_ON | TSC_PS_DIV16);
#elif defined( CPU8MHZ )
TPM1SC = (TSC_BUSRATE_ON | TSC_PS_DIV8); // @8 Mhz
#else
TPM1SC = (TSC_BUSRATE_ON | TSC_PS_DIV4);
#endif
else
TPM1SC = (TSC_STOP);
#else
if ( turnOn )
#if defined( CPU16MHZ )
TPM1SC = (TSC_TOIE | TSC_BUSRATE_ON | TSC_PS_DIV16);
#elif defined( CPU8MHZ )
TPM1SC = (TSC_TOIE | TSC_BUSRATE_ON | TSC_PS_DIV8); // @8 Mhz
#else
TPM1SC = (TSC_TOIE | TSC_BUSRATE_ON | TSC_PS_DIV4);
#endif
else
TPM1SC = (TSC_TOIE | TSC_STOP);
#endif // TIMER_INT
// timer value
TPM1MODH = HI_UINT16(count);
TPM1MODL = LO_UINT16(count);
#endif // NOT WIN32
}
/*********************************************************************
* @fn TimerSetInterrupt
*
* @brief Enables or disables timer interrupts
* @param 0=disable, !0=enable
* @return none
*/
void TimerSetInterrupt( byte turnOn )
{
if ( turnOn )
// Enable Output Compare interrupts
TPM1SC |= TSC_TOIE;
else
// Disable Output Compare A interrupts
TPM1SC &= ~TSC_TOIE;
}
/*********************************************************************
* @fn TimerTickCheck
*
* @brief Checks for, and clears the timer's Compare Interrupt Flag
* @param none
* @return 0x00=no interrupt, 0x40=Compare A Match interrupt
*/
byte TimerTickCheck( void )
{
byte stat;
stat = TPM1SC; // Timer status
if ( stat & TSC_TOF )
TPM1SC = stat & ~TSC_TOF; // Reset TOF flag
else
stat = 0; // No tick this time
return ( stat );
}
#ifdef POWER_SAVING
/*********************************************************************
* @fn TimerElapsed
*
* @brief Gets elapsed timer clock counts
* @param reset - reset counter if !0
* @return elapsed clock ticks
*/
uint16 TimerElapsed( byte reset )
{
uint16 count;
IntsStorage;
StoreDisableInts;
// Get elapsed count
count = (TPM1CNTH << 8) | TPM1CNTL;
if ( reset )
{
// Reset counter
TPM1CNTH = 0;
TPM1CNTL = 0;
}
RestoreInts;
return ( count );
}
#endif
/*********************************************************************
* @fn osal_timer_ISR_TIM1
*
* @brief Interrupt Service for the Hardware Timer interrupt.
* @param void
* @return void
*/
void INTERRUPT osal_timer_ISR_TIM1(void)
{
if ( TimerTickCheck() )
{
// Don't disable IRQ for more than 10us
_asm CLI;
// Process the timer interrupt
osal_timer_ISR();
}
}
/*********************************************************************
* Memory Support
*/
/*********************************************************************
* @fn OnBoard_stack_used()
*
* @brief
*
* Runs through the stack looking for touched memory.
*
* @param none
*
* @return number of bytes used by the stack
*/
uint16 OnBoard_stack_used( void )
{
byte *pStack = ONBOARD_STACK_START;
while ( (*pStack == STACK_INIT_VALUE) && (pStack < ONBOARD_STACK_END) )
{
pStack++;
}
return ( (uint16)(ONBOARD_STACK_END - pStack) );
}
/*********************************************************************
* A to D Support
*/
uint16 ReadAtoD( byte channel )
{
uint16 reading = 0;
// Setup
ATDC = (ATDC_ATDPU | ATDC_DJM_RIGHT | ATDC_PRS);
ATDPE = 0xFF;
ATDSC = channel;
// Wait for A/D to settle
while( (ATDSC & ATDSC_CCF) == 0 );
// Return finding
reading = (ATDRH << 8);
reading |= ATDRL;
// Turn off the A/D converter
ATDC = 0;
ATDPE = 0x00;
return ( reading );
}
byte ReadAtoD8bit( byte channel )
{
byte reading = 0;
// Setup
ATDC = (ATDC_ATDPU | ATDC_RES8 | ATDC_PRS_XBEE);
//ATDPE = 0xFF;
ATDPE |= (1 << channel);
ATDSC = channel;
// Wait for A/D to settle
while( (ATDSC & ATDSC_CCF) == 0 );
// Return finding
reading = ATDRH;
ATDPE ^= (1 << channel);
return ( reading );
}
/*********************************************************************
* LCD Support
*/
void LCDWaitLong( int w )
{
int x;
int y;
for ( y = 0; y < w; y++ )
{
for ( x = 0; x < 0x7FF; x++ );
}
}
void LCDWaitShort( int w )
{
int x;
int y;
for ( y = 0; y < w; y++ )
{
for ( x = 0; x < 0x001F; x++ );
}
}
/*********************************************************************
* Unused Functions
*/
void BuzzerControl( byte on ) {}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -