?? timer2.c
字號:
/****************************************************************************
*
* MODULE: Timer2.c
*
* COMPONENT: $RCSfile: $
*
* VERSION: $Name: $
*
* REVISION: $Revision: $
*
* DATED: $Date: 30/06/06 $
*
* STATUS: $State: $
*
* AUTHOR: Gordon MacNee
*
* DESCRIPTION
* code segment to demonstrate the operation of the timers
* running in two modes of PWM
* the TICK_TIMER is used to cause an interrupt every 10mS
* during the Tick Timer interrupt the PWM SPACE values is
* incremented by 0x200
* the SPACE value held in u16Offset is output to UART0
* at 19K2 8 N 1
*
* CHANGE HISTORY:
*
* $Log: $
*
*
* LAST MODIFIED BY: $Author: pc1 $
* $Modtime: $
*
*
****************************************************************************
*
* (c) Copyright 2006 JENNIC Ltd
*
****************************************************************************/
/****************************************************************************/
/*** Include files ***/
/****************************************************************************/
#include <jendefs.h>
#include <AppHardwareApi.h>
/****************************************************************************/
/*** Macro Definitions ***/
/****************************************************************************/
/****************************************************************************/
/*** Type Definitions ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Function Prototypes ***/
/****************************************************************************/
/****************************************************************************/
/*** Exported Variables ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Variables ***/
/****************************************************************************/
uint16 u16Offset = 0x0800;
/****************************************************************************/
/*** Exported Functions ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Functions ***/
/****************************************************************************/
PRIVATE void vTimerConfig(void);
PRIVATE void vTickTimerISR(uint32 u32DeviceId, uint32 u32ItemBitmap);
PRIVATE void vUART_Init(void);
PRIVATE void vDebug(char *pcMessage);
PRIVATE void vDisplayHex(uint32 u32Data, int iSize);
/****************************************************************************
*
* NAME: vTimerConfig
*
* DESCRIPTION:
* PWM output from timer0 in Delta Sigma mode
* with a low period of 0x8000 and a high of (0xffff - 0x8000)
*
* PWM output from timer1 in standard mode
* with a low period of 0x8000 and a high of (0xffff - 0x8000)
*
* PARAMETERS: Name RW Usage
* None.
*
* RETURNS:
* None.
*
* NOTES:
* In this mode the period of timer0 is fixed at 2^16 or 2^17
* and the u16Lo is the SPACE period
****************************************************************************/
PRIVATE void vTimerConfig(void)
{
/* set up timer 0 for Sigma Delta PWM */
vAHI_TimerEnable(E_AHI_TIMER_0,
0x00,
FALSE,
FALSE,
TRUE);
vAHI_TimerClockSelect(E_AHI_TIMER_0,
FALSE,
TRUE);
vAHI_TimerStartDeltaSigma(E_AHI_TIMER_0,
0x0000, // null value
0x8000, // u16Lo SPACE period
FALSE);
/* set up timer 1 for PWM */
vAHI_TimerEnable(E_AHI_TIMER_1,
0x00,
FALSE,
FALSE,
TRUE);
vAHI_TimerClockSelect(E_AHI_TIMER_1,
FALSE,
TRUE);
vAHI_TimerStartRepeat(E_AHI_TIMER_1,
0x8000, // SPACE period
0xffff); // period
/* set up Tick Timer to interrupt */
vAHI_TickTimerConfigure(E_AHI_TICK_TIMER_DISABLE);
/* vTickTimerISR is the function that is called when we get a TickTimer Interrupt */
vAHI_TickTimerInit(vTickTimerISR);
vAHI_TickTimerWrite(0);
vAHI_TickTimerInterval(160000); // for 10ms
vAHI_TickTimerConfigure(E_AHI_TICK_TIMER_RESTART);
vAHI_TickTimerIntEnable(TRUE);
}
/****************************************************************************
*
* NAME: vTickTimerISR handle interrupts from the tick timer
*
* DESCRIPTION:
* This is where we end up when we have an interrupt from Timer0
*
* PARAMETERS: Name RW Usage
* None.
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PRIVATE void vTickTimerISR(uint32 u32DeviceId, uint32 u32ItemBitmap)
{
u16Offset = u16Offset + 0x200;
vAHI_TimerStartDeltaSigma(E_AHI_TIMER_0,
0x0000, // null value
u16Offset,// SPACE value
FALSE);
vAHI_TimerStartRepeat(E_AHI_TIMER_1,
u16Offset, // SPACE value
0xffff); // period
vDebug("\n\ru16Offset = ");
vDisplayHex(u16Offset,4);
}
/****************************************************************************
*
* 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)u32AHI_Init();
/* Initialise the serial port and rx/tx queues */
vUART_Init();
/* select which timer0 configuration you want to use here */
vTimerConfig();
u16Offset = 0x0800;
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();
}
/****************************************************************************
*
* NAME: vUART_Init
*
* DESCRIPTION:
*
* PARAMETERS: Name RW Usage
* None.
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
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);
vAHI_UartSetControl(E_AHI_UART_0, FALSE, FALSE, E_AHI_UART_WORD_LEN_8, TRUE, FALSE);
vAHI_UartSetInterrupt(E_AHI_UART_0, FALSE, FALSE, FALSE, FALSE, E_AHI_UART_FIFO_LEVEL_1);
}
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 + -