Skip to content

Commit dc01762

Browse files
moving thread helpers
1 parent 2645a58 commit dc01762

4 files changed

Lines changed: 95 additions & 0 deletions

File tree

threadX/inc/threadX_utils.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
#ifndef __U_THREADX_H
3+
#define __U_THREADX_H
4+
5+
#include "tx_api.h"
6+
#include "u_threads.h"
7+
#include <stdint.h>
8+
9+
uint8_t _create_thread(TX_BYTE_POOL *byte_pool, thread_t *thread);
10+
11+
#endif

threadX/inc/u_general.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#ifndef __U_GENERAL_H
3+
#define __U_GENERAL_H
4+
5+
#include <string.h>
6+
#include <stdio.h>
7+
/* This file (and u_general.c) contain miscellaneous macros, functions, and configuration settings that can be used throughout the project. */
8+
9+
/* General-purpose status macros. */
10+
#define U_SUCCESS 0
11+
#define U_ERROR 1
12+
#define U_QUEUE_EMPTY 2
13+
14+
#endif

threadX/inc/u_threads.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "tx_api.h"
2+
#include <stdint.h>
3+
#include <stdio.h>
4+
5+
/* Initializes all threads. Called from app_threadx.c */
6+
uint8_t threads_init(TX_BYTE_POOL *byte_pool);
7+
8+
typedef struct {
9+
/* PUBLIC: Thread Configuration Settings */
10+
/* Set these when defining an instance of this struct. */
11+
const CHAR *name; /* Name of Thread */
12+
const ULONG thread_input; /* Thread Input. You can put whatever you want in here. Defaults to zero. */
13+
const ULONG size; /* Stack Size (in bytes) */
14+
const UINT priority; /* Priority */
15+
const UINT threshold; /* Preemption Threshold */
16+
const ULONG time_slice; /* Time Slice */
17+
const UINT auto_start; /* Auto Start */
18+
const UINT sleep; /* Sleep (in ticks) */
19+
VOID (*function)(ULONG); /* Thread Function */
20+
21+
/* PRIVATE: Internal implementation - DO NOT ACCESS DIRECTLY */
22+
/* (should only be accessed by functions in u_threads.c) */
23+
TX_THREAD _TX_THREAD;
24+
} thread_t;

threadX/src/threadX_utils.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
#include "threadX_utils.h"
3+
#include "u_threads.h"
4+
#include "u_threads.h"
5+
#include "u_general.h"
6+
7+
uint8_t _create_thread(TX_BYTE_POOL *byte_pool, thread_t *thread) {
8+
/* Create Threads */
9+
//CATCH_ERROR(_create_thread(byte_pool, &_default_thread), 0); // Create Default thread.
10+
11+
/*
12+
CATCH_ERROR(_create_thread(byte_pool, &_can_thread), U_SUCCESS);
13+
CATCH_ERROR(_create_thread(byte_pool, &_faults_thread), U_SUCCESS);
14+
CATCH_ERROR(_create_thread(byte_pool, &_statemachine_thread), U_SUCCESS);
15+
CATCH_ERROR(_create_thread(byte_pool, &_nonfunctional_data_thread), U_SUCCESS);
16+
CATCH_ERROR(_create_thread(byte_pool, &_tsms_thread), U_SUCCESS);
17+
CATCH_ERROR(_create_thread(byte_pool, &_control_thread), U_SUCCESS);
18+
CATCH_ERROR(_create_thread(byte_pool, &_pedals_thread), U_SUCCESS);
19+
*/
20+
// add more threads here if need
21+
22+
DEBUG_PRINTLN("Ran threads_init().");
23+
return U_SUCCESS;
24+
}
25+
26+
uint8_t threads_init(TX_BYTE_POOL *byte_pool);
27+
28+
uint8_t threads_init(TX_BYTE_POOL *byte_pool) {
29+
30+
/* Create Threads */
31+
//CATCH_ERROR(_create_thread(byte_pool, &_default_thread), U_SUCCESS); // Create Default thread.
32+
/*
33+
CATCH_ERROR(_create_thread(byte_pool, &_can_thread), U_SUCCESS); // Create CAN thread.
34+
CATCH_ERROR(_create_thread(byte_pool, &_faults_thread), U_SUCCESS); // Create Faults thread.
35+
CATCH_ERROR(_create_thread(byte_pool, &_statemachine_thread), U_SUCCESS); // Create State Machine thread.
36+
CATCH_ERROR(_create_thread(byte_pool, &_nonfunctional_data_thread), U_SUCCESS); // Create Nonfunctional Data thread.
37+
CATCH_ERROR(_create_thread(byte_pool, &_tsms_thread), U_SUCCESS); // Create TSMS thread.
38+
CATCH_ERROR(_create_thread(byte_pool, &_control_thread), U_SUCCESS); // Create Control thread.
39+
CATCH_ERROR(_create_thread(byte_pool, &_pedals_thread), U_SUCCESS); // Create Pedals thread.
40+
*/
41+
// add more threads here if need
42+
43+
DEBUG_PRINTLN("Ran threads_init().");
44+
return U_SUCCESS;
45+
}
46+

0 commit comments

Comments
 (0)