main.c 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*****************************************************************************
  2. * Last updated for: @ref qpc_7_0_0
  3. * Last updated on 2021-12-05
  4. *
  5. * Q u a n t u m L e a P s
  6. * ------------------------
  7. * Modern Embedded Software
  8. *
  9. * Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
  10. *
  11. * This program is open source software: you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as published
  13. * by the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * Alternatively, this program may be distributed and modified under the
  17. * terms of Quantum Leaps commercial licenses, which expressly supersede
  18. * the GNU General Public License and are specifically designed for
  19. * licensees interested in retaining the proprietary status of their code.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <www.gnu.org/licenses/>.
  28. *
  29. * Contact information:
  30. * <www.state-machine.com/licensing>
  31. * <info@state-machine.com>
  32. *****************************************************************************/
  33. #include "qpc.h"
  34. #include "dpp.h"
  35. #include "bsp.h"
  36. Q_DEFINE_THIS_FILE
  37. /* Local-scope objects -----------------------------------------------------*/
  38. static QEvt const *l_tableQueueSto[N_PHILO];
  39. static QEvt const *l_philoQueueSto[N_PHILO][N_PHILO];
  40. static QSubscrList l_subscrSto[MAX_PUB_SIG];
  41. static union SmallEvents {
  42. void *e0; /* minimum event size */
  43. uint8_t e1[sizeof(TableEvt)];
  44. /* ... other event types to go into this pool */
  45. } l_smlPoolSto[2*N_PHILO + 10]; /* storage for the small event pool */
  46. static ULONG l_philoStk[N_PHILO][256]; /* stacks for the Philosophers */
  47. static ULONG l_tableStk[256]; /* stack for the Table */
  48. /*..........................................................................*/
  49. int main() {
  50. Philo_ctor(); /* instantiate all Philosopher active objects */
  51. Table_ctor(); /* instantiate the Table active object */
  52. tx_kernel_enter();
  53. return 0; /* tx_kernel_enter() does not return */
  54. }
  55. /*..........................................................................*/
  56. void tx_application_define(void *first_unused_memory) {
  57. uint8_t n;
  58. (void)first_unused_memory; /* unused parameter */
  59. BSP_init(); /* initialize the Board Support Package */
  60. QF_init(); /* initialize the framework and the underlying RT kernel */
  61. QF_psInit(l_subscrSto, Q_DIM(l_subscrSto)); /* init publish-subscribe */
  62. /* initialize event pools... */
  63. QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
  64. QS_OBJ_DICTIONARY(l_smlPoolSto);
  65. QS_OBJ_DICTIONARY(AO_Table);
  66. QS_OBJ_DICTIONARY(AO_Philo[0]);
  67. QS_OBJ_DICTIONARY(AO_Philo[1]);
  68. QS_OBJ_DICTIONARY(AO_Philo[2]);
  69. QS_OBJ_DICTIONARY(AO_Philo[3]);
  70. QS_OBJ_DICTIONARY(AO_Philo[4]);
  71. for (n = 0; n < N_PHILO; ++n) { /* start the active objects... */
  72. QActive_setAttr(AO_Philo[n], THREAD_NAME_ATTR, "Philo");
  73. QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
  74. l_philoQueueSto[n], Q_DIM(l_philoQueueSto[n]),
  75. l_philoStk[n], sizeof(l_philoStk[n]), (QEvt *)0);
  76. }
  77. QActive_setAttr(AO_Table, THREAD_NAME_ATTR, "Table");
  78. QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
  79. l_tableQueueSto, Q_DIM(l_tableQueueSto),
  80. l_tableStk, sizeof(l_tableStk), (QEvt *)0);
  81. (void)QF_run();
  82. }