porttimer.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * File : porttimer.c
  3. * This file is part of freemodbus in RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-04-04 yi.qiu first version
  13. */
  14. /* ----------------------- Platform includes --------------------------------*/
  15. #include <rtthread.h>
  16. #include <s3c24x0.h>
  17. #include "port.h"
  18. /* ----------------------- Modbus includes ----------------------------------*/
  19. #include "mb.h"
  20. #include "mbport.h"
  21. /* ----------------------- static functions ---------------------------------*/
  22. static void prvvTIMERExpiredISR( void );
  23. extern rt_uint32_t PCLK;
  24. /* ----------------------- Start implementation -----------------------------*/
  25. BOOL xMBPortTimersInit(USHORT usTim1Timerout50us)
  26. {
  27. /* all are interrupt mode,set Timer 3 MUX 1/4 */
  28. TCFG1 &= 0xffff0fff;
  29. TCFG1 |= 0x00001000;
  30. TCNTB3 = (rt_int32_t)(usTim1Timerout50us*(PCLK/ (4 *16* 1000))) - 1;
  31. /* manual update */
  32. TCON = TCON & (~(0x0f<<16)) | (0x02<<16);
  33. /* install interrupt handler */
  34. rt_hw_interrupt_install(INTTIMER3, prvvTIMERExpiredISR, RT_NULL);
  35. rt_hw_interrupt_umask(INTTIMER3);
  36. /* start timer3, reload */
  37. TCON = TCON & (~(0x0f<<16)) | (0x09<<16);
  38. return TRUE;
  39. }
  40. void vMBPortTimersEnable(void)
  41. {
  42. /* start timer4, reload */
  43. TCON = TCON & (~(0x0f<<16)) | (0x09<<16);
  44. }
  45. void vMBPortTimersDisable(void)
  46. {
  47. TCON = TCON & (~(0x01<<16));
  48. }
  49. static void prvvTIMERExpiredISR( void )
  50. {
  51. (void)pxMBPortCBTimerExpired();
  52. }