Skip to content

Commit

Permalink
Create hw/threads.c
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed May 24, 2021
1 parent 7455eb5 commit 191088d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 35 deletions.
1 change: 1 addition & 0 deletions examples/xcpsim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ set(SOURCES
../../src/xcp_util.c
../../src/hw/terminal.c
../../src/hw/options.c
../../src/hw/threads.c
../../flsemu/common.c
app_config.c
appl1.c
Expand Down
26 changes: 1 addition & 25 deletions examples/xcpsim/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,14 @@
*/


#include <pthread.h>
#include <signal.h>

#include "xcp.h"
#include "terminal.h"
#include "app_config.h"


//////////////

pthread_t threads[NUM_THREADS];
Xcp_OptionsType Xcp_Options = {0};

void parse_options(int argc, char ** argv, Xcp_OptionsType * options);
//////////////

void * XcpTl_Thread(void * param);
void * Xcp_Thread(void * param);

void AppTask(void);

int main(int argc, char **argv)
Expand All @@ -54,12 +43,7 @@ int main(int argc, char **argv)
Xcp_Init();
Xcp_DisplayInfo();

pthread_create(&threads[UI_THREAD], NULL, &XcpTerm_Thread, NULL);
pthread_create(&threads[TL_THREAD], NULL, &XcpTl_Thread, NULL);
pthread_create(&threads[XCP_THREAD], NULL, &Xcp_Thread, NULL);
pthread_join(threads[UI_THREAD], NULL);
pthread_kill(threads[TL_THREAD], SIGINT);
pthread_kill(threads[XCP_THREAD], SIGINT);
XcpThrd_RunThreads();

FlsEmu_DeInit();
XcpHw_Deinit();
Expand All @@ -68,11 +52,3 @@ int main(int argc, char **argv)
return 0;
}

void * Xcp_Thread(void * param)
{
XCP_UNREFERENCED_PARAMETER(param);
XCP_FOREVER {
Xcp_MainFunction();
}
return NULL;
}
9 changes: 0 additions & 9 deletions inc/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,5 @@

#include "xcp.h"

#define XCP_THREAD (0)
#define UI_THREAD (1)
#define APP_THREAD (2)
#define TL_THREAD (3)

#define NUM_THREADS (4)


void * XcpTerm_Thread(void * param);

#endif /* __TERMINAL_H */
7 changes: 6 additions & 1 deletion inc/xcp_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ extern "C"
#endif /* __cplusplus */
#endif /* XCP_EXTERN_C_GUARDS */


/*
** Global Functions.
*/
Expand All @@ -45,6 +44,12 @@ void XcpHw_SignalApplicationState(uint32_t state, uint8_t signal_all);
uint32_t XcpHw_WaitApplicationState(uint32_t mask);
void XcpHw_ResetApplicationState(uint32_t mask);

void XcpThrd_RunThreads(void);
void * XcpTerm_Thread(void * param);
void * Xcp_Thread(void * param);
void * XcpTl_Thread(void * param);
void * Xcp_Thread(void * param);

#if XCP_ENABLE_EXTERN_C_GUARDS == XCP_ON
#if defined(__cplusplus)
}
Expand Down
59 changes: 59 additions & 0 deletions src/hw/threads.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* BlueParrot XCP
*
* (C) 2021 by Christoph Schueler <github.com/Christoph2,
* cpu12.gems@googlemail.com>
*
* All Rights Reserved
*
* This program is free 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 2 of the License, or
* (at your option) any later version.
*
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* s. FLOSS-EXCEPTION.txt
*/

#include <pthread.h>
#include <signal.h>

#include "xcp.h"
#include "xcp_hw.h"

#define XCP_THREAD (0)
#define UI_THREAD (1)
#define APP_THREAD (2)
#define TL_THREAD (3)

#define NUM_THREADS (4)

pthread_t threads[NUM_THREADS];

void XcpThrd_RunThreads(void)
{
pthread_create(&threads[UI_THREAD], NULL, &XcpTerm_Thread, NULL);
pthread_create(&threads[TL_THREAD], NULL, &XcpTl_Thread, NULL);
pthread_create(&threads[XCP_THREAD], NULL, &Xcp_Thread, NULL);
pthread_join(threads[UI_THREAD], NULL);
pthread_kill(threads[TL_THREAD], SIGINT);
pthread_kill(threads[XCP_THREAD], SIGINT);
}


void * Xcp_Thread(void * param)
{
XCP_UNREFERENCED_PARAMETER(param);
XCP_FOREVER {
Xcp_MainFunction();
}
return NULL;
}

0 comments on commit 191088d

Please sign in to comment.