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

📄 tick.c

📁 凌阳 Web服务器应用采用Microchip TCP / IP协议栈介绍
💻 C
字号:
/*********************************************************************
 *
 *                  Tick Manager for PIC18
 *
 *********************************************************************
 * FileName:        Tick.c
 * Dependencies:    stackTSK.h
 *                  Tick.h
 * Processor:       PIC18
 * Complier:        MCC18 v1.00.50 or higher
 *                  HITECH PICC-18 V8.10PL1 or higher
 * Company:         Microchip Technology, Inc.
 *
 * Software License Agreement
 *
 * This software is owned by Microchip Technology Inc. ("Microchip") 
 * and is supplied to you for use exclusively as described in the 
 * associated software agreement.  This software is protected by 
 * software and other intellectual property laws.  Any use in 
 * violation of the software license may subject the user to criminal 
 * sanctions as well as civil liability.  Copyright 2006 Microchip
 * Technology Inc.  All rights reserved.
 *
 * This software is provided "AS IS."  MICROCHIP DISCLAIMS ALL 
 * WARRANTIES, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, NOT LIMITED 
 * TO MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND 
 * INFRINGEMENT.  Microchip shall in no event be liable for special, 
 * incidental, or consequential damages.
 *
 *
 * Author               Date        Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Nilesh Rajbharti     6/28/01     Original        (Rev 1.0)
 * Nilesh Rajbharti     2/9/02      Cleanup
 * Nilesh Rajbharti     5/22/02     Rev 2.0 (See version.log for detail)
********************************************************************/

#define TICK_INCLUDE

#include "StackTsk.h"
#include "Tick.h"

#define TICK_TEMP_VALUE_1       \
        ((CLOCK_FREQ / 4) / (TICKS_PER_SECOND * TICK_PRESCALE_VALUE))

#if TICK_TEMP_VALUE_1 > 60000
#error TICK_PER_SECOND value cannot be programmed with current CLOCK_FREQ
#error Either lower TICK_PER_SECOND or manually configure the Timer
#endif

#define TICK_TEMP_VALUE         (65535 - TICK_TEMP_VALUE_1)

#define TICK_COUNTER_HIGH       ((TICK_TEMP_VALUE >> 8) & 0xff)
#define TICK_COUNTER_LOW        (TICK_TEMP_VALUE & 0xff)

#if (TICK_PRESCALE_VALUE == 2)
    #define TIMER_PRESCALE  (0)
#elif ( TICK_PRESCALE_VALUE == 4 )
    #define TIMER_PRESCALE  (1)
#elif ( TICK_PRESCALE_VALUE == 8 )
    #define TIMER_PRESCALE  (2)
#elif ( TICK_PRESCALE_VALUE == 16 )
    #define TIMER_PRESCALE  (3)
#elif ( TICK_PRESCALE_VALUE == 32 )
    #define TIMER_PRESCALE  (4)
#elif ( TICK_PRESCALE_VALUE == 64 )
    #define TIMER_PRESCALE  (5)
#elif ( TICK_PRESCALE_VALUE == 128 )
    #define TIMER_PRESCALE  (6)
#elif ( TICK_PRESCALE_VALUE == 256 )
    #define TIMER_PRESCALE  (7)
#else
    #error Invalid TICK_PRESCALE_VALUE specified.
#endif


#define CKGBASE					0x88210000		
	#define P_TIMER0_CLK_CONF		(DWORD*)(CKGBASE + 0x0000006c)				
	#define P_TIMER_CLK_SEL			(DWORD*)(CKGBASE + 0x000000e4)
		
/**
 * TIMER1: 0x0816_0000 ~ 0x0816_0FFF
 */
#define TM0BASE					0x88160000
	#define P_TIMER0_MODE_CTRL				(DWORD*)(TM0BASE + 0x00000000)
	#define P_TIMER0_CCP_CTRL				(DWORD*)(TM0BASE + 0x00000004)
	#define P_TIMER0_PRELOAD_DATA			(DWORD*)(TM0BASE + 0x00000008)
	#define P_TIMER0_CCP_DATA				(DWORD*)(TM0BASE + 0x0000000c)
	#define P_TIMER0_COUNT_DATA				(DWORD*)(TM0BASE + 0x00000010)

#define TIMER_ON		0x80000000
#define TIMER_OFF		0x00000000
#define TIMER_IRQ_ON	0x08000000
#define TIMER_IRQ_OFF	0x00000000
#define TIMER_IRQ_CLR	0x04000000
#define TIMER_CPPNOR	0x00000000
#define TIMER_CCPCAP	0x40000000
#define TIMER_CCPCMP	0x80000000
#define TIMER_CCPPWM	0xc0000000
#define TIMER_CAPCS0	0x00000000
#define TIMER_CAPCS1	0x08000000
#define TIMER_CMPCS0	0x00000000
#define TIMER_CMPCS1	0x04000000
#define TIMER_PWMCS0	0x00000000
#define TIMER_PWMCS1	0x02000000

TICK TickCount = 0;	// 10ms/unit


/*********************************************************************
 * Function:        void TickInit(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          Tick manager is initialized.
 *
 * Side Effects:    None
 *
 * Overview:        Initializes Timer0 as a tick counter.
 *
 * Note:            None
 ********************************************************************/
void TickInit(void)
{
	
	unsigned int *port;
	port = 0x880a0020;	*port = 0xffffff7f;		// IRQ Mask Enable
	port = 0x880a0024;	*port = 0xffffffff;		// IRQ Mask Enable
	port = 0x88210114;	*port = 1;

	*P_TIMER0_CLK_CONF = 0x00000000;
	*P_TIMER0_CLK_CONF = 0x00000003;
	*P_TIMER_CLK_SEL = 0x00000008;
	*P_TIMER0_PRELOAD_DATA = 0x0000; // set timer cycle
	*P_TIMER0_CCP_CTRL = TIMER_CPPNOR; // normal mode
	*P_TIMER0_MODE_CTRL = TIMER_ON | TIMER_IRQ_ON | TIMER_IRQ_CLR;
	
}


/*********************************************************************
 * Function:        TICK TickGet(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          Current tick value is given
 *					1 tick represents approximately 10ms
 *
 * Side Effects:    None
 *
 * Overview:        None
 *
 * Note:            None
 ********************************************************************/
TICK TickGet(void)
{
    return TickCount;
}


/*********************************************************************
 * Function:        void TickUpdate(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Internal Tick and Seconds count are updated.
 *
 * Note:            None
 ********************************************************************/
void TickUpdate(void)
{
	  TickCount++;

}









⌨️ 快捷键说明

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