lpcmanager
Clone
Summary
Browse
Changes
Graph
Change Device Bus task priority
2023-08-30, Edouard Tisserant
967430460440
Parents
2bf67e608136
Children
5ccb381c307c
Change Device Bus task priority
2 files changed, 32 insertions(+), 3 deletions(-)
+0
-2
LPCBus/SOM_Devices_decl.c
+32
-1
LPCBus/SOM_Devices_init.c
--- a/LPCBus/SOM_Devices_decl.c Thu Aug 10 10:56:51 2023 +0200
+++ b/LPCBus/SOM_Devices_decl.c Wed Aug 30 12:04:45 2023 +0200
@@ -138,11 +138,9 @@
uint64_t actTime;
static uint64_t lastCommTime=0;
- struct sched_param param = { .sched_priority = 10 };
#ifdef _GNU_SOURCE
pthread_setname_np(pthread_self(), "UART_task");
#endif
- pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
while (1){
int active;
--- a/LPCBus/SOM_Devices_init.c Thu Aug 10 10:56:51 2023 +0200
+++ b/LPCBus/SOM_Devices_init.c Wed Aug 30 12:04:45 2023 +0200
@@ -1,5 +1,8 @@
int err;
char *serialdev = LPCBUS_DEVICES_PORT;
+struct sched_param param;
+pthread_attr_t attr;
+
uartDevWriteBuf_plc_state = EMPTY;
uartDevReadBuf_plc_state = EMPTY;
@@ -31,8 +34,36 @@
else
InitUartPortDevices_shortBuffer();
+/* Initialize pthread attributes (default values) */
+err = pthread_attr_init(&attr);
+if (err) {
+ fprintf(stderr,"init pthread attributes failed\n");
+ return err;
+}
+
+/* Set scheduler policy and priority of pthread */
+err = pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
+if (err) {
+ fprintf(stderr,"pthread setschedpolicy failed\n");
+ return err;
+}
+param.sched_priority = 95 /* 10 higher than PLC *//*PLC_THREAD_PRIORITY + 1*/;
+err = pthread_attr_setschedparam(&attr, ¶m);
+if (err) {
+ fprintf(stderr,"pthread setschedparam failed\n");
+ return err;
+}
+
+/* Use scheduling parameters of attr */
+err = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+if (err) {
+ fprintf(stderr,"pthread setinheritsched failed\n");
+ return err;
+}
+
+UART_WakeCondValue = 0;
UART_task_active = 1;
-if(err = pthread_create(&UART_task, NULL, &UART_task_proc, NULL));
+if(err = pthread_create(&UART_task, &attr, &UART_task_proc, NULL));
return err;