rtGetNaN.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * rtGetNaN.c
  3. *
  4. * Code generation for model "PMSM_Motor_TL3_sf".
  5. *
  6. * Model version : 1.825
  7. * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. * C source code generated on : Fri Apr 14 12:51:02 2023
  9. *
  10. * Target selection: rtwsfcn.tlc
  11. * Note: GRT includes extra infrastructure and instrumentation for prototyping
  12. * Embedded hardware selection: ARM Compatible->ARM Cortex-M
  13. * Emulation hardware selection:
  14. * Differs from embedded hardware (MATLAB Host)
  15. * Code generation objectives:
  16. * 1. Execution efficiency
  17. * 2. RAM efficiency
  18. * Validation result: Not run
  19. */
  20. /*
  21. * Abstract:
  22. * Function to initialize non-finite, NaN
  23. */
  24. #include "rtGetNaN.h"
  25. #define NumBitsPerChar 8U
  26. /*
  27. * Initialize rtNaN needed by the generated code.
  28. * NaN is initialized as non-signaling. Assumes IEEE.
  29. */
  30. real_T rtGetNaN(void)
  31. {
  32. size_t bitsPerReal = sizeof(real_T) * (NumBitsPerChar);
  33. real_T nan = 0.0;
  34. if (bitsPerReal == 32U) {
  35. nan = rtGetNaNF();
  36. } else {
  37. uint16_T one = 1U;
  38. enum {
  39. LittleEndian,
  40. BigEndian
  41. } machByteOrder = (*((uint8_T *) &one) == 1U) ? LittleEndian : BigEndian;
  42. switch (machByteOrder) {
  43. case LittleEndian:
  44. {
  45. union {
  46. LittleEndianIEEEDouble bitVal;
  47. real_T fltVal;
  48. } tmpVal;
  49. tmpVal.bitVal.words.wordH = 0xFFF80000U;
  50. tmpVal.bitVal.words.wordL = 0x00000000U;
  51. nan = tmpVal.fltVal;
  52. break;
  53. }
  54. case BigEndian:
  55. {
  56. union {
  57. BigEndianIEEEDouble bitVal;
  58. real_T fltVal;
  59. } tmpVal;
  60. tmpVal.bitVal.words.wordH = 0x7FFFFFFFU;
  61. tmpVal.bitVal.words.wordL = 0xFFFFFFFFU;
  62. nan = tmpVal.fltVal;
  63. break;
  64. }
  65. }
  66. }
  67. return nan;
  68. }
  69. /*
  70. * Initialize rtNaNF needed by the generated code.
  71. * NaN is initialized as non-signaling. Assumes IEEE.
  72. */
  73. real32_T rtGetNaNF(void)
  74. {
  75. IEEESingle nanF = { { 0 } };
  76. uint16_T one = 1U;
  77. enum {
  78. LittleEndian,
  79. BigEndian
  80. } machByteOrder = (*((uint8_T *) &one) == 1U) ? LittleEndian : BigEndian;
  81. switch (machByteOrder) {
  82. case LittleEndian:
  83. {
  84. nanF.wordL.wordLuint = 0xFFC00000U;
  85. break;
  86. }
  87. case BigEndian:
  88. {
  89. nanF.wordL.wordLuint = 0x7FFFFFFFU;
  90. break;
  91. }
  92. }
  93. return nanF.wordL.wordLreal;
  94. }