| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- /*
- * 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"
- #include "gd32e230x_conf.h"
- /* ----------------------- static functions ---------------------------------*/
- static void prvvTIMERExpiredISR( void );
- /* ----------------------- Start implementation -----------------------------*/
- BOOL
- xMBPortTimersInit(USHORT usTim1Timerout50us)
- {
- timer_parameter_struct timer_initpara; //timer_initpara用于存放定时器的参数
- //使能RCU相关时钟
- rcu_periph_clock_enable(RCU_TIMER13); //使能TIMER13的时钟
- timer_deinit(TIMER13); //设置TIMER13参数恢复默认值
- timer_struct_para_init(&timer_initpara); //初始化timer_initpara
-
- //配置TIMER16
- timer_initpara.prescaler = 3599; //设置预分频器值 //72M/3600=20Khz 对应基准50us
- timer_initpara.counterdirection = TIMER_COUNTER_UP; //设置向上计数模式
- timer_initpara.period = usTim1Timerout50us -1; //设置自动重装载值
- timer_initpara.clockdivision = TIMER_CKDIV_DIV1; //设置时钟分割
- timer_init(TIMER13, &timer_initpara); //根据参数初始化定时器
- timer_interrupt_enable(TIMER13, TIMER_INT_UP); //使能定时器的更新中断
- nvic_irq_enable(TIMER13_IRQn, 1); //配置NVIC设置优先级
- timer_enable(TIMER13); //使能定时器
- return TRUE;
- //return FALSE;
- }
- inline void
- vMBPortTimersEnable( )
- {
- /* Enable the timer with the timeout passed to xMBPortTimersInit( ) */
- timer_counter_value_config(TIMER13,0); //清零定时器
- timer_interrupt_flag_clear(TIMER13,TIMER_INT_UP); //清除定时器更新中断
- timer_interrupt_enable(TIMER13,TIMER_INT_UP); //使能定时器更新中断
- timer_enable(TIMER13); //使能定时器
- }
- inline void
- vMBPortTimersDisable( )
- {
- /* Disable any pending timers. */
- timer_counter_value_config(TIMER13,0); //清零定时器
- timer_interrupt_flag_clear(TIMER13,TIMER_INT_UP); //清除定时器更新中断
- timer_interrupt_disable(TIMER13,TIMER_INT_UP); //禁用定时器更新中断
- timer_disable(TIMER13); //失能定时器
- }
- /* 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( );
- }
- void TIMER13_IRQHandler(void)
- {
- if(RESET != timer_interrupt_flag_get(TIMER13, TIMER_INT_UP))
- {
- /* clear timer update interrupt bit */
- timer_interrupt_flag_clear(TIMER13, TIMER_INT_UP);
- /* clear count number*/
- timer_counter_value_config(TIMER13,0);
- /* use this function to call pxMBPortCBTimerExpired( ) */
- prvvTIMERExpiredISR();
- }
- }
|