/*
|
* FreeModbus Libary: BARE Port
|
* Copyright (C) 2006 Christian Walter <wolti@sil.at>
|
*
|
* This library is free software; you can redistribute it and/or
|
* modify it under the terms of the GNU Lesser General Public
|
* License as published by the Free Software Foundation; either
|
* version 2.1 of the License, or (at your option) any later version.
|
*
|
* This library is distributed in the hope that it will be useful,
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* Lesser General Public License for more details.
|
*
|
* You should have received a copy of the GNU Lesser General Public
|
* License along with this library; if not, write to the Free Software
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
*
|
* File: $Id$
|
*/
|
|
/* ----------------------- Platform includes --------------------------------*/
|
#include "port.h"
|
|
/* ----------------------- Modbus includes ----------------------------------*/
|
#include "mb.h"
|
#include "mbport.h"
|
|
/* ----------------------- static functions ---------------------------------*/
|
static void prvvTIMERExpiredISR( void );
|
|
/* ----------------------- Start implementation -----------------------------*/
|
BOOL
|
xMBPortTimersInit( USHORT usTim1Timerout50us )
|
{
|
u16 PrescalerValue;
|
|
// TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
// NVIC_InitTypeDef NVIC_InitStructure;
|
|
// //´ò¿ªTIM4ʱÖÓ
|
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
|
|
// //TIM4·ÖƵϵÊýΪ3599,ʱ»ùƵÂÊΪ72 / (1 + Prescaler) = 20KHz,»ù׼Ϊ50us
|
// PrescalerValue = (u16) (SystemCoreClock / 20000) - 1;
|
|
// //TIM4³õʼ»¯
|
// TIM_TimeBaseStructure.TIM_Period = (u16) usTim1Timerout50us;
|
// TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; //¶¨Ê±Æ÷·ÖƵ 50us
|
// TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
// TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
// TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);//³õʼ»¯TIM
|
|
// //ʹÄÜTIM4Ô¤×°ÔØ
|
// TIM_ARRPreloadConfig(TIM4, ENABLE);
|
|
// //TIM4ÖжÏÅäÖÃ
|
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);
|
// NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
|
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
// NVIC_Init(&NVIC_InitStructure);
|
|
// //Çå³ý¸üÐÂÖжϱêÖ¾
|
// TIM_ClearITPendingBit(TIM4,TIM_IT_Update);
|
|
// //ʧÄÜTIM4¸üÐÂÖжÏ
|
// TIM_ITConfig(TIM4, TIM_IT_Update, DISABLE);
|
|
// //¹Ø±ÕTIM4¶¨Ê±Æ÷
|
// TIM_Cmd(TIM4, DISABLE);
|
|
return TRUE;
|
}
|
|
|
inline void
|
vMBPortTimersEnable( )
|
{
|
// /* Enable the timer with the timeout passed to xMBPortTimersInit( ) */
|
// //Çå³ý¸üÐÂÖжϱêÖ¾
|
// TIM_ClearITPendingBit(TIM4,TIM_IT_Update);
|
//
|
// //ÔÊÐíTIM4¸üÐÂÖжÏ
|
// TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE);
|
//
|
// //½«TIM4¼ÆÊýÖµÇåÁã
|
// TIM_SetCounter(TIM4,0);
|
//
|
// //¿ªÆôTIM4¶¨Ê±Æ÷
|
// TIM_Cmd(TIM4,ENABLE);
|
}
|
|
inline void
|
vMBPortTimersDisable( )
|
{
|
// /* Disable any pending timers. */
|
// //Çå³ý¸üÐÂÖжϱêÖ¾
|
// TIM_ClearITPendingBit(TIM4,TIM_IT_Update);
|
//
|
// //½ûÖ¹TIM4¸üÐÂÖжÏ
|
// TIM_ITConfig(TIM4,TIM_IT_Update,DISABLE);
|
//
|
// //½«TIM4¼ÆÊýÖµÇåÁã
|
// TIM_SetCounter(TIM4,0);
|
//
|
// //¹Ø±ÕTIM4¶¨Ê±Æ÷
|
// TIM_Cmd(TIM4,DISABLE);
|
}
|
|
/* Create an ISR which is called whenever the timer has expired. This function
|
* must then call pxMBPortCBTimerExpired( ) to notify the protocol stack that
|
* the timer has expired.
|
*/
|
static void prvvTIMERExpiredISR( void )
|
{
|
( void )pxMBPortCBTimerExpired( );
|
}
|
|
/**
|
* @brief TIM4ÖжϺ¯Êý
|
* @param ÎÞ
|
* @retval ÎÞ
|
*/
|
void TIM4_IRQHandler(void)
|
{
|
// //ÊÇ·ñ·¢ËÍTIM4¸üÐÂÖжÏ
|
// if (TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET)
|
// {
|
// //Çå³ýTIM4¸üÐÂÖжϱêÖ¾
|
// TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
|
|
// prvvTIMERExpiredISR( );
|
// }
|
}
|