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

📄 timer6.c

📁 Zigbee无线收发控制芯片JN5121C语言例程
💻 C
字号:
/****************************************************************************
 *
 * MODULE:             Timer2.c
 *
 * COMPONENT:          $RCSfile: $
 *
 * VERSION:            $Name: $
 *
 * REVISION:           $Revision: $
 *
 * DATED:              $Date: 20/06/06  $
 *
 * STATUS:             $State: $
 *
 * AUTHOR:             Gordon MacNee
 *
 * DESCRIPTION
 * code segment to demonstrate the operation of the timers
 * in counter mode
 * We generate a pulse train with a M/S ratio of 50%/50%
 * with timer1 and feed this into timer0
 * When timer0 counts enough pulse to match its Fall Register
 * it will generate an interrupt and send a message to UART0
 * at 19K2 8 N 1
 *
 * CHANGE HISTORY:
 *
 * $Log: $
 *
 *
 * LAST MODIFIED BY:   $Author: pc1 $
 *                     $Modtime: $
 *
 * Note: with the values chosen we expect a message on the uart every ~33.5 secs
 ****************************************************************************
 *
 *  (c) Copyright 2006 JENNIC Ltd
 *
 ****************************************************************************/

/****************************************************************************/
/***        Include files                                                 ***/
/****************************************************************************/

#include <jendefs.h>
#include <AppHardwareApi.h>
#include <AppQueueApi.h>

/****************************************************************************/
/***        Macro Definitions                                             ***/
/****************************************************************************/


/****************************************************************************/
/***        Type Definitions                                              ***/
/****************************************************************************/


/****************************************************************************/
/***        Local Function Prototypes                                     ***/
/****************************************************************************/

/****************************************************************************/
/***        Exported Variables                                            ***/
/****************************************************************************/

/****************************************************************************/
/***        Local Variables                                               ***/
/****************************************************************************/

/****************************************************************************/
/***        Exported Functions                                            ***/
/****************************************************************************/

/****************************************************************************/
/***        Local Functions                                               ***/
/****************************************************************************/

PRIVATE void vTimerConfig(void);

PRIVATE void vTimer0ISR(uint32 u32DeviceId, uint32 u32ItemBitmap);

PRIVATE void vUART_Init(void);
PRIVATE void vDebug(char *pcMessage);
PRIVATE void vDisplayHex(uint32 u32Data, int iSize);


/****************************************************************************
 *
 * NAME: vTimerConfig
 *
 * DESCRIPTION:
 * Running Timer0 in counter Mode with no prescalar
 *
 * PARAMETERS:      Name            RW  Usage
 * None.
 *
 * RETURNS:
 * None.
 *
 * Notes:
  ****************************************************************************/
PRIVATE void vTimerConfig(void)
{
/* set up timer 0 for count */
    vAHI_TimerEnable(E_AHI_TIMER_0,
                     16,      // prescalar value 2^16
                     FALSE,
                     TRUE,
                     FALSE);
    vAHI_TimerClockSelect(E_AHI_TIMER_0,
                          FALSE,
                          TRUE);    // gate input pin active high
    vAHI_TimerStartRepeat(E_AHI_TIMER_0,
                          0x0000,       // null value
                          122);         // number of pulses to count

    /* register Timer0 interrupt */
    vAHI_Timer0RegisterCallback(vTimer0ISR);
}


/****************************************************************************
 *
 * NAME: vTimer0ISR
 *
 * DESCRIPTION: routine to handle interrupt from timer0
 *
 *
 *
 * PARAMETERS:      Name            RW  Usage
 * None.
 *
 * RETURNS:
 * None.
 *
 * NOTES:
 * None.
 ****************************************************************************/
PRIVATE void vTimer0ISR(uint32 u32DeviceId, uint32 u32ItemBitmap)
{
    vDebug("\n\rinterrupt from timer0");
}




/****************************************************************************
 *
 * NAME: AppColdStart
 *
 * DESCRIPTION:
 *
 * PARAMETERS:      Name            RW  Usage
 * None.
 *
 * RETURNS:
 * None.
 *
 * NOTES:
 * Entry point for a power on reset or wake from sleep mode.
 ****************************************************************************/
PUBLIC void AppColdStart(void)
{

    /* Initialise stack and hardware interfaces.  */
    (void)u32AppApiInit(NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    (void)u32AHI_Init();

    /* Initialise the serial port and rx/tx queues */
    vUART_Init();

    vTimerConfig();

    vDebug("\n\rready to start\n\r");


    while(1)
    {
    }
}

/****************************************************************************
 *
 * NAME: AppWarmStart
 *
 * DESCRIPTION:
 * Entry point for a wake from sleep mode with the memory contents held. We
 * are not using this mode and so should never get here.
 *
 * PARAMETERS:      Name            RW  Usage
 * None.
 *
 * RETURNS:
 * None.
 *
 * NOTES:
 * None.
 ****************************************************************************/
PUBLIC void AppWarmStart(void)
{
    AppColdStart();
}




/****************************************************************************/
/***        Debug and UART drivers                                        ***/
/****************************************************************************/

/****************************************************************************
 *
 * NAME: vUART_Init, vDebug, vDisplayHex
 *
 * DESCRIPTION:
 *
 * PARAMETERS:      Name            RW  Usage
 * None.
 *
 * RETURNS:
 * None.
 *
 * NOTES:
 * used for simple debug
 ****************************************************************************/
PUBLIC void vUART_Init(void)
{
    /* Enable UART 0: 19200-8-N-1 */
    vAHI_UartEnable(E_AHI_UART_0);
    vAHI_UartReset(E_AHI_UART_0, TRUE, TRUE);
    vAHI_UartReset(E_AHI_UART_0, FALSE, FALSE);
    vAHI_UartSetClockDivisor(E_AHI_UART_0, E_AHI_UART_RATE_19200);
}


PRIVATE void vDebug(char *pcMessage)
{
    while (*pcMessage)
    {
        while ((u8AHI_UartReadLineStatus(0) & 0x20) == 0);
        vAHI_UartWriteData(0, *pcMessage);
        pcMessage++;
    }
}

PRIVATE void vDisplayHex(uint32 u32Data, int iSize)
{
    char acValue[9];
    char *pcString = acValue;
    uint8 u8Nybble;
    int i, j;

    j = 0;
    for (i = (iSize << 2) - 4; i >= 0; i -= 4)
    {
        u8Nybble = (uint8)((u32Data >> i) & 0x0f);
        u8Nybble += 0x30;
        if (u8Nybble > 0x39)
            u8Nybble += 7;

        *pcString = u8Nybble;
        pcString++;
    }
    *pcString = '\0';

    vDebug(acValue);
}

/****************************************************************************/
/***        END OF FILE                                                   ***/
/****************************************************************************/

⌨️ 快捷键说明

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