//............................................................................ void BSP::displayPhilStat(uint8_t n, char const *stat) { // exercise the FPU with some floating point computations float volatile x; x = 3.1415926F; x = x + 2.7182818F; if (stat[0] == 'h') { LED_GPIO_PORT->BSRRL = LED3_PIN; // turn LED on } else { LED_GPIO_PORT->BSRRH = LED3_PIN; // turn LED off } if (stat[0] == 'e') { LED_GPIO_PORT->BSRRL = LED5_PIN; // turn LED on } else { LED_GPIO_PORT->BSRRH = LED5_PIN; // turn LED on } (void)n; // unused parameter (in all but Spy build configuration) QS_BEGIN(PHILO_STAT, AO_Philo[n]) // application-specific record begin QS_U8(1, n); // Philosopher number QS_STR(stat); // Philosopher status QS_END() }
/*..........................................................................*/ void BSP_displayPhilStat(uint8_t n, char const *stat) { printf("Philosopher %2d is %s\n", (int)n, stat); QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
/*..........................................................................*/ void BSP_displyPhilStat(uint8_t n, char const *stat) { Video_printStrAt(17, 12 + n, VIDEO_FGND_YELLOW, stat); QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
/*..........................................................................*/ void BSP_displayPhilStat(uint8_t n, char const *stat) { GPIOF->DATA_Bits[LED_BLUE] = ((stat[0] == 'e') ? LED_BLUE : 0U); QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
////////////////////////////////////////////////////////////////////////////// // Product: DPP example with emWin/uC/GUI, WITH Window Manager // Last updated for version 6.2.0 // Last updated on 2018-03-16 // // Q u a n t u m L e a P s // --------------------------- // innovating embedded systems // // Copyright (C) Quantum Leaps, LLC. All rights reserved. // // This program is open source software: you can redistribute it and/or // modify it under the terms of the GNU General Public License as published // by the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Alternatively, this program may be distributed and modified under the // terms of Quantum Leaps commercial licenses, which expressly supersede // the GNU General Public License and are specifically designed for // licensees interested in retaining the proprietary status of their code. // // This program 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 General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // // Contact information: // https://www.state-machine.com // mailto:[email protected] ////////////////////////////////////////////////////////////////////////////// #include "qpcpp.h" #include "dpp.h" #include "bsp.h" extern "C" { #include "GUI.h" #include "WM.h" // emWin Windows Manager #include "DIALOG.h" #include "SIM.h" } Q_DEFINE_THIS_FILE // Active object class ------------------------------------------------------- class Table : public QActive { private: uint8_t m_fork[N_PHILO]; uint8_t m_isHungry[N_PHILO]; public: Table(); private: static QState initial(Table *me, QEvt const *e); static QState ready (Table *me, QEvt const *e); static QState serving(Table *me, QEvt const *e); static QState paused (Table *me, QEvt const *e); }; #define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1)) % N_PHILO)) #define LEFT(n_) ((uint8_t)(((n_) + 1) % N_PHILO)) enum m_forkState { FREE, USED }; // Local objects ------------------------------------------------------------- static Table l_table; // local Table object #ifdef Q_SPY enum QSUserRecords { PHILO_STAT = QS_USER, TABLE_STAT }; static uint8_t const l_onDialogGUI = 0U; #endif // Public-scope objects ------------------------------------------------------ QActive * const AO_Table = &l_table; // "opaque" AO pointer // GUI definition ============================================================ static WM_HWIN l_hDlg; static WM_CALLBACK *l_cb_WM_HBKWIN; static const GUI_WIDGET_CREATE_INFO l_dialog[] = { { &FRAMEWIN_CreateIndirect, "Dining Philosopher Problem", 0, 30, 30, 260, 180, FRAMEWIN_CF_MOVEABLE }, { &TEXT_CreateIndirect, "Philosopher 0", GUI_ID_TEXT9, 50, 10, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "Philosopher 1", GUI_ID_TEXT9, 50, 30, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "Philosopher 2", GUI_ID_TEXT9, 50, 50, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "Philosopher 3", GUI_ID_TEXT9, 50, 70, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "Philosopher 4", GUI_ID_TEXT9, 50, 90, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "Table", GUI_ID_TEXT9, 50, 110, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "thinking", GUI_ID_TEXT0, 130, 10, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "thinking", GUI_ID_TEXT1, 130, 30, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "thinking", GUI_ID_TEXT2, 130, 50, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "thinking", GUI_ID_TEXT3, 130, 70, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "thinking", GUI_ID_TEXT4, 130, 90, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "serving", GUI_ID_TEXT5, 130, 110, 0, 0, TEXT_CF_LEFT }, { &BUTTON_CreateIndirect,"PAUSE", GUI_ID_BUTTON0, 160, 130, 80, 30 } }; //..........................................................................*/ static void onMainWndGUI(WM_MESSAGE* pMsg) { switch (pMsg->MsgId) { case WM_PAINT: { GUI_SetBkColor(GUI_GRAY); GUI_Clear(); GUI_SetColor(GUI_BLACK); GUI_SetFont(&GUI_Font24_ASCII); GUI_DispStringHCenterAt("Dining Philosophers - Demo", 160, 5); break; } default: { WM_DefaultProc(pMsg); break; } } } //..........................................................................*/ static void onDialogGUI(WM_MESSAGE * pMsg) { switch (pMsg->MsgId) { case WM_INIT_DIALOG: { break; } case WM_NOTIFY_PARENT: { switch (pMsg->Data.v) { case WM_NOTIFICATION_RELEASED: { // react only if released */ switch (WM_GetId(pMsg->hWinSrc)) { case GUI_ID_BUTTON0: { // static PAUSE event for the Table AO */ static QEvent const pauseEvt = { PAUSE_SIG, 0 }; AO_Table->POST(&pauseEvt, &l_onDialogGUI); break; } } break; } } break; } default: { WM_DefaultProc(pMsg); break; } } } //..........................................................................*/ static void displyPhilStat(uint8_t n, char const *stat) { TEXT_SetText(WM_GetDialogItem(l_hDlg, GUI_ID_TEXT0 + n), stat); WM_Exec(); // update the screen and invoke WM callbacks */ QS_BEGIN(PHILO_STAT, AO_Philo[n]) // application-specific record begin */ QS_U8(1, n); // Philosopher number */ QS_STR(stat); // Philosopher status */ QS_END() } //..........................................................................*/ static void displyTableStat(char const *stat) { TEXT_SetText(WM_GetDialogItem(l_hDlg, GUI_ID_TEXT5), stat); WM_Exec(); // update the screen and invoke WM callbacks */ QS_BEGIN(TABLE_STAT, AO_Table) // application-specific record begin */ QS_STR(stat); // Philosopher status */ QS_END() }
/*..........................................................................*/ void BSP_displayPhilStat(uint8_t n, char const *stat) { LCD_DisplayChar(Line5, (3*16*n + 5*16), stat[0]); QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
////////////////////////////////////////////////////////////////////////////// // Product: DPP example with emWin/uC/GUI, WITH Window Manager // Last updated for version 6.2.0 // Last updated on 2018-03-16 // // Q u a n t u m L e a P s // --------------------------- // innovating embedded systems // // Copyright (C) Quantum Leaps, LLC. All rights reserved. // // This program is open source software: you can redistribute it and/or // modify it under the terms of the GNU General Public License as published // by the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Alternatively, this program may be distributed and modified under the // terms of Quantum Leaps commercial licenses, which expressly supersede // the GNU General Public License and are specifically designed for // licensees interested in retaining the proprietary status of their code. // // This program 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 General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // // Contact information: // https://www.state-machine.com // mailto:[email protected] ////////////////////////////////////////////////////////////////////////////// #include "qpcpp.h" #include "dpp.h" #include "bsp.h" extern "C" { #include "GUI.h" #include "WM.h" // emWin Windows Manager #include "DIALOG.h" #include "SIM.h" } Q_DEFINE_THIS_FILE // Active object class ------------------------------------------------------- class Table : public QActive { private: uint8_t m_fork[N_PHILO]; uint8_t m_isHungry[N_PHILO]; public: Table(); private: static QState initial(Table *me, QEvt const *e); static QState ready (Table *me, QEvt const *e); static QState serving(Table *me, QEvt const *e); static QState paused (Table *me, QEvt const *e); }; #define RIGHT(n_) ((uint8_t)(((n_) + (N_PHILO - 1)) % N_PHILO)) #define LEFT(n_) ((uint8_t)(((n_) + 1) % N_PHILO)) enum m_forkState { FREE, USED }; // Local objects ------------------------------------------------------------- static Table l_table; // local Table object #ifdef Q_SPY enum QSUserRecords { PHILO_STAT = QS_USER, TABLE_STAT }; static uint8_t const l_onDialogGUI = 0U; #endif // Public-scope objects ------------------------------------------------------ QActive * const AO_Table = &l_table; // "opaque" AO pointer // GUI definition ============================================================ static WM_HWIN l_hDlg; static WM_CALLBACK *l_cb_WM_HBKWIN; static const GUI_WIDGET_CREATE_INFO l_dialog[] = { { &FRAMEWIN_CreateIndirect, "Dining Philosopher Problem", 0, 30, 30, 260, 180, FRAMEWIN_CF_MOVEABLE }, { &TEXT_CreateIndirect, "Philosopher 0", GUI_ID_TEXT9, 50, 10, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "Philosopher 1", GUI_ID_TEXT9, 50, 30, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "Philosopher 2", GUI_ID_TEXT9, 50, 50, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "Philosopher 3", GUI_ID_TEXT9, 50, 70, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "Philosopher 4", GUI_ID_TEXT9, 50, 90, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "Table", GUI_ID_TEXT9, 50, 110, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "thinking", GUI_ID_TEXT0, 130, 10, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "thinking", GUI_ID_TEXT1, 130, 30, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "thinking", GUI_ID_TEXT2, 130, 50, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "thinking", GUI_ID_TEXT3, 130, 70, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "thinking", GUI_ID_TEXT4, 130, 90, 0, 0, TEXT_CF_LEFT }, { &TEXT_CreateIndirect, "serving", GUI_ID_TEXT5, 130, 110, 0, 0, TEXT_CF_LEFT }, { &BUTTON_CreateIndirect,"PAUSE", GUI_ID_BUTTON0, 160, 130, 80, 30 } }; //..........................................................................*/ static void onMainWndGUI(WM_MESSAGE* pMsg) { switch (pMsg->MsgId) { case WM_PAINT: { GUI_SetBkColor(GUI_GRAY); GUI_Clear(); GUI_SetColor(GUI_BLACK); GUI_SetFont(&GUI_Font24_ASCII); GUI_DispStringHCenterAt("Dining Philosophers - Demo", 160, 5); break; } default: { WM_DefaultProc(pMsg); break; } } } //..........................................................................*/ static void onDialogGUI(WM_MESSAGE * pMsg) { switch (pMsg->MsgId) { case WM_INIT_DIALOG: { break; } case WM_NOTIFY_PARENT: { switch (pMsg->Data.v) { case WM_NOTIFICATION_RELEASED: { // react only if released */ switch (WM_GetId(pMsg->hWinSrc)) { case GUI_ID_BUTTON0: { // static PAUSE event for the Table AO */ static QEvent const pauseEvt = { PAUSE_SIG, 0 }; AO_Table->POST(&pauseEvt, &l_onDialogGUI); break; } } break; } } break; } default: { WM_DefaultProc(pMsg); break; } } } //..........................................................................*/ static void displyPhilStat(uint8_t n, char const *stat) { TEXT_SetText(WM_GetDialogItem(l_hDlg, GUI_ID_TEXT0 + n), stat); WM_Exec(); // update the screen and invoke WM callbacks */ QS_BEGIN(PHILO_STAT, AO_Philo[n]) // application-specific record begin */ QS_U8(1, n); // Philosopher number */ QS_STR(stat); // Philosopher status */ QS_END() }
/*..........................................................................*/ void BSP_displyPhilStat(uint8_t n, char const *stat) { if (n < Q_DIM(l_userLED)) { ULED_set(n, (stat[0] == 'e') ? ULED_ON : ULED_OFF); } QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
/*..........................................................................*/ void BSP_displayPhilStat(uint8_t n, char const *stat) { (void)n; (void)stat; LED0_toggle(); QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
//............................................................................ void BSP_displyPhilStat(uint8_t n, char const *stat) { char str[2]; str[0] = stat[0]; str[1] = '\0'; Display96x16x1StringDraw(str, (3*6*n + 6), 1); QS_BEGIN(PHILO_STAT, AO_Philo[n]) // application-specific record begin QS_U8(1, n); // Philosopher number QS_STR(stat); // Philosopher status QS_END() }
/*..........................................................................*/ void BSP_displyPhilStat(uint8_t n, char const Q_ROM *stat) { if (stat[0] == (char const)'e') { /* is this Philosopher eating? */ LED_ON(n); } else { /* this Philosopher is not eating */ LED_OFF(n); } QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
//............................................................................ void BSP_displayPhilStat(uint8_t const n, char_t const * const stat) { char_t str[2]; str[0] = *stat; str[1] = '\0'; Display96x16x1StringDraw(&str[0], (3U*6U*static_cast<uint32_t>(n)) + 6U, 1U); QS_BEGIN(PHILO_STAT, AO_Philo[n]) // application-specific record begin QS_U8(1U, n); // Philosopher number QS_STR(stat); // Philosopher status QS_END() }
//............................................................................ void BSP::displayPhilStat(uint8_t n, char const *stat) { if (stat[0] == 'e') { BSP_LED_On(LED1); } else { BSP_LED_Off(LED1); } QS_BEGIN(PHILO_STAT, AO_Philo[n]) // application-specific record begin QS_U8(1, n); // Philosopher number QS_STR(stat); // Philosopher status QS_END() // application-specific record end }
/*..........................................................................*/ void BSP_displayPhilStat(uint8_t n, char const *stat) { if (stat[0] == 'h') { GPIOA->BSRRL |= LED_LD2; /* turn LED on */ } else { GPIOA->BSRRH |= LED_LD2; /* turn LED off */ } QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
/*..........................................................................*/ void BSP_displayPhilStat(uint8_t n, char const *stat) { if (stat[0] == 'h') { /* is Philo hungry? */ P1OUT |= LED1; /* turn LED1 on */ } else { P1OUT &= ~LED1; /* turn LED1 off */ } QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
/*..........................................................................*/ void BSP_displayPhilStat(uint8_t n, char const *stat) { if (stat[0] == 'h') { PORTB |= LED_L; } else { PORTB &= ~LED_L; } QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
/*..........................................................................*/ void BSP_displyPhilStat(uint8_t n, char const *stat) { uint8_t led_status = (stat[0] == 'e' ? LED_ON : LED_OFF); switch (n) { case 0: LED0 = led_status; break; case 1: LED1 = led_status; break; case 2: LED2 = led_status; break; case 3: LED3 = led_status; break; } QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
/*..........................................................................*/ void BSP_displayPhilStat(uint8_t n, char const *stat) { if (stat[0] == 'e') { GPIOSetValue(LED_PORT, LED_BIT, LED_ON); /* LED on */ } else { GPIOSetValue(LED_PORT, LED_BIT, LED_OFF); /* LED off */ } QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
/*..........................................................................*/ void BSP_displyPhilStat(uint8_t n, char const *stat) { /* turn LED on when eating and off when not eating */ uint8_t on_off = (stat[0] == 'e' ? LED_ON : LED_OFF); switch (n) { case 0: LED04 = on_off; break; case 1: LED05 = on_off; break; case 2: LED06 = on_off; break; case 3: LED07 = on_off; break; case 4: LED08 = on_off; break; default: Q_ERROR(); break; } QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
//............................................................................ void BSP_displayPhilStat(uint8_t n, char const *stat) { UINT bitmapNum = 0; Q_REQUIRE(n < N_PHILO); switch (stat[0]) { case 't': bitmapNum = 0U; break; case 'h': bitmapNum = 1U; break; case 'e': bitmapNum = 2U; break; default: Q_ERROR(); break; } // set the "segment" # n to the bitmap # 'bitmapNum' l_philos.setSegment((UINT)n, bitmapNum); QS_BEGIN(PHILO_STAT, AO_Philo[n]) // application-specific record begin QS_U8(1, n); // Philosopher number QS_STR(stat); // Philosopher status QS_END() }
/*..........................................................................*/ void BSP_displayPhilStat(uint8_t n, char const *stat) { if (stat[0] == 'h') { LPC_GPIO1->FIOSET = LED_1; /* turn LED on */ } else { LPC_GPIO1->FIOCLR = LED_1; /* turn LED off */ } if (stat[0] == 'e') { LPC_GPIO1->FIOSET = LED_2; /* turn LED on */ } else { LPC_GPIO1->FIOCLR = LED_2; /* turn LED off */ } QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
/*AO内部打印调试信息*/ void BSP_Trace(u8 eState, QActive* pAO, char* const str) { QS_BEGIN(eState, pAO) /* application-specific record begin */ QS_STR(str); /* Philosopher status */ QS_END() }