sys_arch.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @file - sys_arch.c
  3. * System Architecture support routines for Sitara devices.
  4. *
  5. */
  6. /*
  7. * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without modification,
  11. * are permitted provided that the following conditions are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. The name of the author may not be used to endorse or promote products
  19. * derived from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  22. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  23. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  24. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  26. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  29. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. * OF SUCH DAMAGE.
  31. *
  32. * This file is part of the lwIP TCP/IP stack.
  33. *
  34. * Author: Adam Dunkels <adam@sics.se>
  35. *
  36. */
  37. /* Copyright (c) 2010 Texas Instruments Incorporated */
  38. /* lwIP includes. */
  39. #include "lwip/opt.h"
  40. #include "lwip/sys.h"
  41. #if SYS_LIGHTWEIGHT_PROT
  42. /* Sitara header files required for this interface driver. */
  43. #include "interrupt.h"
  44. /**
  45. * This function is used to lock access to critical sections when lwipopt.h
  46. * defines SYS_LIGHTWEIGHT_PROT. It disables interrupts and returns a value
  47. * indicating the interrupt enable state when the function entered. This
  48. * value must be passed back on the matching call to sys_arch_unprotect().
  49. *
  50. * @return the interrupt level when the function was entered.
  51. */
  52. sys_prot_t
  53. sys_arch_protect(void)
  54. {
  55. sys_prot_t status;
  56. #ifdef _TMS320C6X
  57. status = (sys_prot_t)IntGlobalDisable();
  58. #else
  59. status = (IntMasterStatusGet() & 0xFF);
  60. IntMasterIRQDisable();
  61. #endif
  62. return status;
  63. }
  64. /**
  65. * This function is used to unlock access to critical sections when lwipopt.h
  66. * defines SYS_LIGHTWEIGHT_PROT. It enables interrupts if the value of the lev
  67. * parameter indicates that they were enabled when the matching call to
  68. * sys_arch_protect() was made.
  69. *
  70. * @param lev is the interrupt level when the matching protect function was
  71. * called
  72. */
  73. void
  74. sys_arch_unprotect(sys_prot_t lev)
  75. {
  76. #ifdef _TMS320C6X
  77. IntGlobalRestore((unsigned int)lev);
  78. #else
  79. /* Only turn interrupts back on if they were originally on when the matching
  80. sys_arch_protect() call was made. */
  81. if((lev & 0x80) == 0) {
  82. IntMasterIRQEnable();
  83. }
  84. #endif
  85. }
  86. #endif /* SYS_LIGHTWEIGHT_PROT */