diag temporel
This commit is contained in:
parent
f1ebf554d1
commit
82106f6327
52 changed files with 791 additions and 0 deletions
0
T2/tp/T2-TP_suite/.DS_Store
vendored
Executable file
0
T2/tp/T2-TP_suite/.DS_Store
vendored
Executable file
0
T2/tp/T2-TP_suite/._.DS_Store
Executable file
0
T2/tp/T2-TP_suite/._.DS_Store
Executable file
0
T2/tp/T2-TP_suite/._Makefile
Executable file
0
T2/tp/T2-TP_suite/._Makefile
Executable file
0
T2/tp/T2-TP_suite/._acquisitionManager.h
Executable file
0
T2/tp/T2-TP_suite/._acquisitionManager.h
Executable file
0
T2/tp/T2-TP_suite/._acquisitionManagerAtomic.c
Executable file
0
T2/tp/T2-TP_suite/._acquisitionManagerAtomic.c
Executable file
0
T2/tp/T2-TP_suite/._acquisitionManagerPOSIX.c
Executable file
0
T2/tp/T2-TP_suite/._acquisitionManagerPOSIX.c
Executable file
0
T2/tp/T2-TP_suite/._acquisitionManagerTestAndSet.c
Executable file
0
T2/tp/T2-TP_suite/._acquisitionManagerTestAndSet.c
Executable file
0
T2/tp/T2-TP_suite/._debug.h
Executable file
0
T2/tp/T2-TP_suite/._debug.h
Executable file
0
T2/tp/T2-TP_suite/._diagrams
Executable file
0
T2/tp/T2-TP_suite/._diagrams
Executable file
0
T2/tp/T2-TP_suite/._display.c
Executable file
0
T2/tp/T2-TP_suite/._display.c
Executable file
0
T2/tp/T2-TP_suite/._displayManager.c
Executable file
0
T2/tp/T2-TP_suite/._displayManager.c
Executable file
0
T2/tp/T2-TP_suite/._displayManager.h
Executable file
0
T2/tp/T2-TP_suite/._displayManager.h
Executable file
0
T2/tp/T2-TP_suite/._iAcquisitionManager.h
Executable file
0
T2/tp/T2-TP_suite/._iAcquisitionManager.h
Executable file
0
T2/tp/T2-TP_suite/._iDisplay.h
Executable file
0
T2/tp/T2-TP_suite/._iDisplay.h
Executable file
0
T2/tp/T2-TP_suite/._iMessageAdder.h
Executable file
0
T2/tp/T2-TP_suite/._iMessageAdder.h
Executable file
0
T2/tp/T2-TP_suite/._iSensor.h
Executable file
0
T2/tp/T2-TP_suite/._iSensor.h
Executable file
0
T2/tp/T2-TP_suite/._messageAdder.c
Executable file
0
T2/tp/T2-TP_suite/._messageAdder.c
Executable file
0
T2/tp/T2-TP_suite/._messageAdder.h
Executable file
0
T2/tp/T2-TP_suite/._messageAdder.h
Executable file
0
T2/tp/T2-TP_suite/._msg.c
Executable file
0
T2/tp/T2-TP_suite/._msg.c
Executable file
0
T2/tp/T2-TP_suite/._msg.h
Executable file
0
T2/tp/T2-TP_suite/._msg.h
Executable file
0
T2/tp/T2-TP_suite/._multitaskingAccumulator.c
Executable file
0
T2/tp/T2-TP_suite/._multitaskingAccumulator.c
Executable file
0
T2/tp/T2-TP_suite/._multitaskingAccumulator.h
Executable file
0
T2/tp/T2-TP_suite/._multitaskingAccumulator.h
Executable file
0
T2/tp/T2-TP_suite/._preambule.c
Executable file
0
T2/tp/T2-TP_suite/._preambule.c
Executable file
0
T2/tp/T2-TP_suite/._sensorManager.c
Executable file
0
T2/tp/T2-TP_suite/._sensorManager.c
Executable file
0
T2/tp/T2-TP_suite/._tp.pdf
Executable file
0
T2/tp/T2-TP_suite/._tp.pdf
Executable file
44
T2/tp/T2-TP_suite/Makefile
Executable file
44
T2/tp/T2-TP_suite/Makefile
Executable file
|
@ -0,0 +1,44 @@
|
||||||
|
.POSIX:
|
||||||
|
CC = cc
|
||||||
|
CFLAGS = -std=c11 -Wall -Wextra -O3 -mcx16 -pthread #-DDEBUG
|
||||||
|
LDFLAGS = -pthread
|
||||||
|
#LDLIBS = -latomic
|
||||||
|
|
||||||
|
C= $(wildcard *.c)
|
||||||
|
H= $(wildcard *.h)
|
||||||
|
PREAMBULE_SRCS := preambule.c
|
||||||
|
POSIX_SRCS := $(filter-out %preambule.c %Atomic.c %TestAndSet.c, $(C))
|
||||||
|
ATOMIC_SRCS := $(filter-out %preambule.c %POSIX.c %TestAndSet.c, $(C))
|
||||||
|
TESTANDSET_SRCS := $(filter-out %preambule.c %POSIX.c %Atomic.c, $(C))
|
||||||
|
DEPS= $(H:.h)
|
||||||
|
PREAMBULE_OBJS= $(PREAMBULE_SRCS:.c=.o)
|
||||||
|
POSIX_OBJS= $(POSIX_SRCS:.c=.o)
|
||||||
|
ATOMIC_OBJS= $(ATOMIC_SRCS:.c=.o)
|
||||||
|
TESTANDSET_OBJS= $(TESTANDSET_SRCS:.c=.o)
|
||||||
|
|
||||||
|
preambule: $(PREAMBULE_OBJS) $(DEPS)
|
||||||
|
$(CC) $(LDFLAGS) -o preambule $(PREAMBULE_OBJS) $(LDLIBS)
|
||||||
|
|
||||||
|
posix: $(POSIX_OBJS) $(DEPS)
|
||||||
|
$(CC) $(LDFLAGS) -o multitaskingAccumulatorPosix $(POSIX_OBJS) $(LDLIBS)
|
||||||
|
|
||||||
|
atomic: $(ATOMIC_OBJS) $(DEPS)
|
||||||
|
$(CC) $(LDFLAGS) -o multitaskingAccumulatorAtomic $(ATOMIC_OBJS) $(LDLIBS)
|
||||||
|
|
||||||
|
testandset: $(TESTANDSET_OBJS) $(DEPS)
|
||||||
|
$(CC) $(LDFLAGS) -o multitaskingAccumulatorTestAndSet $(TESTANDSET_OBJS) $(LDLIBS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f preambule multitaskingAccumulatorPosix multitaskingAccumulatorAtomic multitaskingAccumulatorTestAndSet $(PREAMBULE_OBJS) $(POSIX_OBJS) $(ATOMIC_OBJS) $(TESTANDSET_OBJS)
|
||||||
|
|
||||||
|
runpreambule: clean preambule
|
||||||
|
./preambule
|
||||||
|
|
||||||
|
runposix: clean posix
|
||||||
|
./multitaskingAccumulatorPosix
|
||||||
|
|
||||||
|
runatomic: clean atomic
|
||||||
|
./multitaskingAccumulatorAtomic
|
||||||
|
|
||||||
|
runtestandset: clean testandset
|
||||||
|
./multitaskingAccumulatorTestAndSet
|
14
T2/tp/T2-TP_suite/acquisitionManager.h
Executable file
14
T2/tp/T2-TP_suite/acquisitionManager.h
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef ACQUISITION_MANAGER_H
|
||||||
|
#define ACQUISITION_MANAGER_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the acquisitions
|
||||||
|
*/
|
||||||
|
unsigned int acquisitionManagerInit(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Waits that acquisitions terminate
|
||||||
|
*/
|
||||||
|
void acquisitionManagerJoin(void);
|
||||||
|
|
||||||
|
#endif
|
104
T2/tp/T2-TP_suite/acquisitionManagerAtomic.c
Executable file
104
T2/tp/T2-TP_suite/acquisitionManagerAtomic.c
Executable file
|
@ -0,0 +1,104 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <semaphore.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include "acquisitionManager.h"
|
||||||
|
#include "msg.h"
|
||||||
|
#include "iSensor.h"
|
||||||
|
#include "multitaskingAccumulator.h"
|
||||||
|
#include "iAcquisitionManager.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//producer count storage
|
||||||
|
volatile unsigned int produceCount = 0;
|
||||||
|
|
||||||
|
pthread_t producers[4];
|
||||||
|
|
||||||
|
static void *produce(void *params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Semaphores and Mutex
|
||||||
|
*/
|
||||||
|
//TODO
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Creates the synchronization elements.
|
||||||
|
* @return ERROR_SUCCESS if the init is ok, ERROR_INIT otherwise
|
||||||
|
*/
|
||||||
|
static unsigned int createSynchronizationObjects(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Increments the produce count.
|
||||||
|
*/
|
||||||
|
static void incrementProducerCount(void);
|
||||||
|
|
||||||
|
static unsigned int createSynchronizationObjects(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
printf("[acquisitionManager]Semaphore created\n");
|
||||||
|
return ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void incrementProducerCount(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int getProducerCount(void)
|
||||||
|
{
|
||||||
|
unsigned int p = 0;
|
||||||
|
//TODO
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO create accessors to limit semaphore and mutex usage outside of this C module.
|
||||||
|
|
||||||
|
unsigned int acquisitionManagerInit(void)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
printf("[acquisitionManager]Synchronization initialization in progress...\n");
|
||||||
|
fflush( stdout );
|
||||||
|
if (createSynchronizationObjects() == ERROR_INIT)
|
||||||
|
return ERROR_INIT;
|
||||||
|
|
||||||
|
printf("[acquisitionManager]Synchronization initialization done.\n");
|
||||||
|
|
||||||
|
for (i = 0; i < PRODUCER_COUNT; i++)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
return ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void acquisitionManagerJoin(void)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < PRODUCER_COUNT; i++)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
printf("[acquisitionManager]Semaphore cleaned\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void *produce(void* params)
|
||||||
|
{
|
||||||
|
D(printf("[acquisitionManager]Producer created with id %d\n", gettid()));
|
||||||
|
unsigned int i = 0;
|
||||||
|
while (i < PRODUCER_LOOP_LIMIT)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
sleep(PRODUCER_SLEEP_TIME+(rand() % 5));
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
printf("[acquisitionManager] %d termination\n", gettid());
|
||||||
|
//TODO
|
||||||
|
}
|
106
T2/tp/T2-TP_suite/acquisitionManagerPOSIX.c
Executable file
106
T2/tp/T2-TP_suite/acquisitionManagerPOSIX.c
Executable file
|
@ -0,0 +1,106 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <semaphore.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include "acquisitionManager.h"
|
||||||
|
#include "msg.h"
|
||||||
|
#include "iSensor.h"
|
||||||
|
#include "multitaskingAccumulator.h"
|
||||||
|
#include "iAcquisitionManager.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
|
//producer count storage
|
||||||
|
volatile unsigned int produceCount = 0;
|
||||||
|
|
||||||
|
pthread_t producers[4];
|
||||||
|
|
||||||
|
static void *produce(void *params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Semaphores and Mutex
|
||||||
|
*/
|
||||||
|
//TODO
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Creates the synchronization elements.
|
||||||
|
* @return ERROR_SUCCESS if the init is ok, ERROR_INIT otherwise
|
||||||
|
*/
|
||||||
|
static unsigned int createSynchronizationObjects(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Increments the produce count.
|
||||||
|
*/
|
||||||
|
static void incrementProducedCount(void);
|
||||||
|
|
||||||
|
static unsigned int createSynchronizationObjects(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
printf("[acquisitionManager]Semaphore created\n");
|
||||||
|
return ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void incrementProducedCount(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int getProducedCount(void)
|
||||||
|
{
|
||||||
|
unsigned int p = 0;
|
||||||
|
//TODO
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
MSG_BLOCK getMessage(void){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO create accessors to limit semaphore and mutex usage outside of this C module.
|
||||||
|
|
||||||
|
unsigned int acquisitionManagerInit(void)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
printf("[acquisitionManager]Synchronization initialization in progress...\n");
|
||||||
|
fflush( stdout );
|
||||||
|
if (createSynchronizationObjects() == ERROR_INIT)
|
||||||
|
return ERROR_INIT;
|
||||||
|
|
||||||
|
printf("[acquisitionManager]Synchronization initialization done.\n");
|
||||||
|
|
||||||
|
for (i = 0; i < PRODUCER_COUNT; i++)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
return ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void acquisitionManagerJoin(void)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < PRODUCER_COUNT; i++)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
printf("[acquisitionManager]Semaphore cleaned\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void *produce(void* params)
|
||||||
|
{
|
||||||
|
D(printf("[acquisitionManager]Producer created with id %d\n", gettid()));
|
||||||
|
unsigned int i = 0;
|
||||||
|
while (i < PRODUCER_LOOP_LIMIT)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
sleep(PRODUCER_SLEEP_TIME+(rand() % 5));
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
printf("[acquisitionManager] %d termination\n", gettid());
|
||||||
|
//TODO
|
||||||
|
}
|
107
T2/tp/T2-TP_suite/acquisitionManagerTestAndSet.c
Executable file
107
T2/tp/T2-TP_suite/acquisitionManagerTestAndSet.c
Executable file
|
@ -0,0 +1,107 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <semaphore.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include "acquisitionManager.h"
|
||||||
|
#include "msg.h"
|
||||||
|
#include "iSensor.h"
|
||||||
|
#include "multitaskingAccumulator.h"
|
||||||
|
#include "iAcquisitionManager.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
|
//producer count storage
|
||||||
|
volatile unsigned int producedCount = 0;
|
||||||
|
|
||||||
|
pthread_t producers[4];
|
||||||
|
|
||||||
|
static void *produce(void *params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Semaphores and Mutex
|
||||||
|
*/
|
||||||
|
//TODO
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Creates the synchronization elements.
|
||||||
|
* @return ERROR_SUCCESS if the init is ok, ERROR_INIT otherwise
|
||||||
|
*/
|
||||||
|
static unsigned int createSynchronizationObjects(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Increments the produce count.
|
||||||
|
*/
|
||||||
|
static void incrementProducedCount(void);
|
||||||
|
|
||||||
|
static unsigned int createSynchronizationObjects(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
printf("[acquisitionManager]Semaphore created\n");
|
||||||
|
return ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void incrementProducedCount(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int getProducedCount(void)
|
||||||
|
{
|
||||||
|
unsigned int p = 0;
|
||||||
|
//TODO
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MSG_BLOCK getMessage(void){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO create accessors to limit semaphore and mutex usage outside of this C module.
|
||||||
|
|
||||||
|
unsigned int acquisitionManagerInit(void)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
printf("[acquisitionManager]Synchronization initialization in progress...\n");
|
||||||
|
fflush( stdout );
|
||||||
|
if (createSynchronizationObjects() == ERROR_INIT)
|
||||||
|
return ERROR_INIT;
|
||||||
|
|
||||||
|
printf("[acquisitionManager]Synchronization initialization done.\n");
|
||||||
|
|
||||||
|
for (i = 0; i < PRODUCER_COUNT; i++)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
return ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void acquisitionManagerJoin(void)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < PRODUCER_COUNT; i++)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
printf("[acquisitionManager]Semaphore cleaned\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void *produce(void* params)
|
||||||
|
{
|
||||||
|
D(printf("[acquisitionManager]Producer created with id %d\n", gettid()));
|
||||||
|
unsigned int i = 0;
|
||||||
|
while (i < PRODUCER_LOOP_LIMIT)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
sleep(PRODUCER_SLEEP_TIME+(rand() % 5));
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
printf("[acquisitionManager] %d termination\n", gettid());
|
||||||
|
//TODO
|
||||||
|
}
|
6
T2/tp/T2-TP_suite/debug.h
Executable file
6
T2/tp/T2-TP_suite/debug.h
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
//C macro to active debug printf
|
||||||
|
#ifdef DEBUG
|
||||||
|
# define D(x) x
|
||||||
|
#else
|
||||||
|
# define D(x)
|
||||||
|
#endif
|
BIN
T2/tp/T2-TP_suite/diagrams/._conception.drawio
Executable file
BIN
T2/tp/T2-TP_suite/diagrams/._conception.drawio
Executable file
Binary file not shown.
1
T2/tp/T2-TP_suite/diagrams/conception.drawio
Executable file
1
T2/tp/T2-TP_suite/diagrams/conception.drawio
Executable file
File diff suppressed because one or more lines are too long
18
T2/tp/T2-TP_suite/display.c
Executable file
18
T2/tp/T2-TP_suite/display.c
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#include "iDisplay.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
void messageDisplay(volatile MSG_BLOCK* mBlock){
|
||||||
|
unsigned int i;
|
||||||
|
messageCheck(mBlock);
|
||||||
|
printf("Message\n");
|
||||||
|
D(printf("["));
|
||||||
|
for(i=0;i < DATA_SIZE;i++)
|
||||||
|
D(printf("%u ",mBlock->mData[i]));
|
||||||
|
D(printf("]\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(unsigned int producedCount, unsigned int consumedCount){
|
||||||
|
printf("[displayManager]Produced messages: %d, Consumed messages: %d, Messages left: %d\n", producedCount, consumedCount, producedCount - consumedCount);
|
||||||
|
}
|
39
T2/tp/T2-TP_suite/displayManager.c
Executable file
39
T2/tp/T2-TP_suite/displayManager.c
Executable file
|
@ -0,0 +1,39 @@
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include "displayManager.h"
|
||||||
|
#include "iDisplay.h"
|
||||||
|
#include "iAcquisitionManager.h"
|
||||||
|
#include "iMessageAdder.h"
|
||||||
|
#include "msg.h"
|
||||||
|
#include "multitaskingAccumulator.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
// DisplayManager thread.
|
||||||
|
pthread_t displayThread;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display manager entry point.
|
||||||
|
* */
|
||||||
|
static void *display( void *parameters );
|
||||||
|
|
||||||
|
|
||||||
|
void displayManagerInit(void){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayManagerJoin(void){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *display( void *parameters )
|
||||||
|
{
|
||||||
|
D(printf("[displayManager]Thread created for display with id %d\n", gettid()));
|
||||||
|
unsigned int diffCount = 0;
|
||||||
|
while(diffCount < DISPLAY_LOOP_LIMIT){
|
||||||
|
sleep(DISPLAY_SLEEP_TIME);
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
printf("[displayManager] %d termination\n", gettid());
|
||||||
|
//TODO
|
||||||
|
}
|
14
T2/tp/T2-TP_suite/displayManager.h
Executable file
14
T2/tp/T2-TP_suite/displayManager.h
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef MESSAGE_DISPLAY_H
|
||||||
|
#define MESSAGE_DISPLAY_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes display manager
|
||||||
|
*/
|
||||||
|
void displayManagerInit(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Waits that display manager terminates
|
||||||
|
*/
|
||||||
|
void displayManagerJoin(void);
|
||||||
|
|
||||||
|
#endif
|
18
T2/tp/T2-TP_suite/iAcquisitionManager.h
Executable file
18
T2/tp/T2-TP_suite/iAcquisitionManager.h
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef I_ACQUISITION_MANAGER_H
|
||||||
|
#define I_ACQUISITION_MANAGER_H
|
||||||
|
|
||||||
|
#include "msg.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of produced messages.
|
||||||
|
*/
|
||||||
|
unsigned int getProducedCount(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a message if any, otherwise waits for a message.
|
||||||
|
*/
|
||||||
|
MSG_BLOCK getMessage(void);
|
||||||
|
|
||||||
|
//TODO create message accessors prototype here.
|
||||||
|
|
||||||
|
#endif
|
19
T2/tp/T2-TP_suite/iDisplay.h
Executable file
19
T2/tp/T2-TP_suite/iDisplay.h
Executable file
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef I_DISPLAY_H
|
||||||
|
#define I_DISPLAY_H
|
||||||
|
|
||||||
|
#include "msg.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays the message content
|
||||||
|
* @param mBlock the message pointer
|
||||||
|
*/
|
||||||
|
void messageDisplay(volatile MSG_BLOCK* mBlock);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the number of produced and consumed messages. It prints also the difference.
|
||||||
|
* @param producedCount the number of produced messages
|
||||||
|
* @param consumedCount the number of consumed messages
|
||||||
|
*/
|
||||||
|
void print(unsigned int producedCount, unsigned int consumedCount);
|
||||||
|
|
||||||
|
#endif
|
16
T2/tp/T2-TP_suite/iMessageAdder.h
Executable file
16
T2/tp/T2-TP_suite/iMessageAdder.h
Executable file
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef I_MESSAGE_ADDER_H
|
||||||
|
#define I_MESSAGE_ADDER_H
|
||||||
|
|
||||||
|
#include "msg.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a message that represents the current value of the sum.
|
||||||
|
*/
|
||||||
|
MSG_BLOCK getCurrentSum();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of consumed messages.
|
||||||
|
*/
|
||||||
|
unsigned int getConsumedCount();
|
||||||
|
|
||||||
|
#endif
|
13
T2/tp/T2-TP_suite/iSensor.h
Executable file
13
T2/tp/T2-TP_suite/iSensor.h
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#ifndef I_SENSOR_H
|
||||||
|
#define I_SENSOR_H
|
||||||
|
|
||||||
|
#include "msg.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the input message.
|
||||||
|
* @param input the input number
|
||||||
|
* @param mBlock the message pointer returned
|
||||||
|
*/
|
||||||
|
void getInput(const unsigned int input, volatile MSG_BLOCK* mBlock);
|
||||||
|
|
||||||
|
#endif
|
66
T2/tp/T2-TP_suite/messageAdder.c
Executable file
66
T2/tp/T2-TP_suite/messageAdder.c
Executable file
|
@ -0,0 +1,66 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <semaphore.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include "messageAdder.h"
|
||||||
|
#include "msg.h"
|
||||||
|
#include "iMessageAdder.h"
|
||||||
|
#include "multitaskingAccumulator.h"
|
||||||
|
#include "iAcquisitionManager.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
//consumer thread
|
||||||
|
pthread_t consumer;
|
||||||
|
//Message computed
|
||||||
|
volatile MSG_BLOCK out;
|
||||||
|
//Consumer count storage
|
||||||
|
volatile unsigned int consumeCount = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments the consume count.
|
||||||
|
*/
|
||||||
|
static void incrementConsumeCount(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consumer entry point.
|
||||||
|
*/
|
||||||
|
static void *sum( void *parameters );
|
||||||
|
|
||||||
|
|
||||||
|
MSG_BLOCK getCurrentSum(){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int getConsumedCount(){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void messageAdderInit(void){
|
||||||
|
out.checksum = 0;
|
||||||
|
for (size_t i = 0; i < DATA_SIZE; i++)
|
||||||
|
{
|
||||||
|
out.mData[i] = 0;
|
||||||
|
}
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void messageAdderJoin(void){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *sum( void *parameters )
|
||||||
|
{
|
||||||
|
D(printf("[messageAdder]Thread created for sum with id %d\n", gettid()));
|
||||||
|
unsigned int i = 0;
|
||||||
|
while(i<ADDER_LOOP_LIMIT){
|
||||||
|
i++;
|
||||||
|
sleep(ADDER_SLEEP_TIME);
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
printf("[messageAdder] %d termination\n", gettid());
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
|
14
T2/tp/T2-TP_suite/messageAdder.h
Executable file
14
T2/tp/T2-TP_suite/messageAdder.h
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef MESSAGE_ADDER_H
|
||||||
|
#define MESSAGE_ADDER_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes message adder module
|
||||||
|
*/
|
||||||
|
void messageAdderInit(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Waits that message adder terminates
|
||||||
|
*/
|
||||||
|
void messageAdderJoin(void);
|
||||||
|
|
||||||
|
#endif
|
37
T2/tp/T2-TP_suite/msg.c
Executable file
37
T2/tp/T2-TP_suite/msg.c
Executable file
|
@ -0,0 +1,37 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "msg.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add to the src message the content of add message
|
||||||
|
* @param src the message pointer
|
||||||
|
* @param add the message to add
|
||||||
|
*/
|
||||||
|
void messageAdd(volatile MSG_BLOCK* src, volatile MSG_BLOCK* add){
|
||||||
|
unsigned int i;
|
||||||
|
src->checksum = 0;
|
||||||
|
for(i=0;i < DATA_SIZE;i++){
|
||||||
|
src->mData[i] += add->mData[i];
|
||||||
|
src->checksum ^= src->mData[i];
|
||||||
|
}
|
||||||
|
D(printf("[msg]....Sum done...\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the message content
|
||||||
|
* @param mBlock the message pointer
|
||||||
|
*/
|
||||||
|
unsigned int messageCheck(volatile MSG_BLOCK* mBlock){
|
||||||
|
unsigned int i, tcheck=0;
|
||||||
|
for(i=0;i < DATA_SIZE;i++)
|
||||||
|
tcheck ^= mBlock->mData[i];
|
||||||
|
if(tcheck == mBlock->checksum){
|
||||||
|
printf("[OK ] Checksum validated\n");
|
||||||
|
return 1;
|
||||||
|
}else{
|
||||||
|
printf("[ FAILED] Checksum failed, message corrupted\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
28
T2/tp/T2-TP_suite/msg.h
Executable file
28
T2/tp/T2-TP_suite/msg.h
Executable file
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef MSG_H
|
||||||
|
#define MSG_H
|
||||||
|
|
||||||
|
//Message data size
|
||||||
|
#define DATA_SIZE 256
|
||||||
|
|
||||||
|
//message type definition
|
||||||
|
typedef struct MSG_BLOCK_TAG
|
||||||
|
{
|
||||||
|
unsigned int checksum;
|
||||||
|
unsigned int mData[DATA_SIZE];
|
||||||
|
} MSG_BLOCK;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays the message content
|
||||||
|
* @param mBlock the message pointer
|
||||||
|
* @return 1 if the checksum is ok, 0 otherwise
|
||||||
|
*/
|
||||||
|
unsigned int messageCheck(volatile MSG_BLOCK* mBlock);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds to the src message the content of add message
|
||||||
|
* @param src the message pointer
|
||||||
|
* @param add the message to add
|
||||||
|
*/
|
||||||
|
void messageAdd(volatile MSG_BLOCK* src, volatile MSG_BLOCK* add);
|
||||||
|
|
||||||
|
#endif
|
34
T2/tp/T2-TP_suite/multitaskingAccumulator.c
Executable file
34
T2/tp/T2-TP_suite/multitaskingAccumulator.c
Executable file
|
@ -0,0 +1,34 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <semaphore.h>
|
||||||
|
#include "multitaskingAccumulator.h"
|
||||||
|
#include "acquisitionManager.h"
|
||||||
|
#include "displayManager.h"
|
||||||
|
#include "messageAdder.h"
|
||||||
|
#include "displayManager.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
|
//The entry point of the process
|
||||||
|
int main( void )
|
||||||
|
{
|
||||||
|
printf("[multitaskingAccumulator]Software initialization in progress...\n");
|
||||||
|
acquisitionManagerInit();
|
||||||
|
messageAdderInit();
|
||||||
|
displayManagerInit();
|
||||||
|
printf("[multitaskingAccumulator]Task initialization done.\n");
|
||||||
|
|
||||||
|
printf("[multitaskingAccumulator]Scheduling in progress...\n");
|
||||||
|
|
||||||
|
displayManagerJoin();
|
||||||
|
messageAdderJoin();
|
||||||
|
acquisitionManagerJoin();
|
||||||
|
|
||||||
|
printf("[multitaskingAccumulator]Threads terminated\n");
|
||||||
|
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
|
||||||
|
}
|
24
T2/tp/T2-TP_suite/multitaskingAccumulator.h
Executable file
24
T2/tp/T2-TP_suite/multitaskingAccumulator.h
Executable file
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef MULTITASKING_ACCUMULATOR_H
|
||||||
|
#define MULTITASKING_ACCUMULATOR_H
|
||||||
|
|
||||||
|
#include "msg.h"
|
||||||
|
|
||||||
|
//The application return code
|
||||||
|
#define ERROR_INIT 1
|
||||||
|
#define ERROR_SUCCESS 0
|
||||||
|
//The number of producers
|
||||||
|
#define PRODUCER_COUNT 4
|
||||||
|
//The number of second the producer shall sleep
|
||||||
|
#define PRODUCER_SLEEP_TIME 1
|
||||||
|
//The number producer iterations
|
||||||
|
#define PRODUCER_LOOP_LIMIT 2
|
||||||
|
//The number of second the display shall sleep
|
||||||
|
#define DISPLAY_SLEEP_TIME 3
|
||||||
|
//The number display iterations
|
||||||
|
#define DISPLAY_LOOP_LIMIT 2
|
||||||
|
//The number of second the adder shall sleep
|
||||||
|
#define ADDER_SLEEP_TIME 2
|
||||||
|
//The number adder iterations
|
||||||
|
#define ADDER_LOOP_LIMIT PRODUCER_LOOP_LIMIT * PRODUCER_COUNT * PRODUCER_SLEEP_TIME
|
||||||
|
|
||||||
|
#endif
|
52
T2/tp/T2-TP_suite/preambule.c
Executable file
52
T2/tp/T2-TP_suite/preambule.c
Executable file
|
@ -0,0 +1,52 @@
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <semaphore.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#define ERROR_INIT 1
|
||||||
|
#define ERROR_SUCCESS 0
|
||||||
|
#define SEMAPHORE_INITIAL_VALUE 0
|
||||||
|
#define SEM_NAME "/preambule_sem"
|
||||||
|
|
||||||
|
pthread_t thread_1;
|
||||||
|
sem_t *semaphore;
|
||||||
|
|
||||||
|
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
void *produce(void *params)
|
||||||
|
{
|
||||||
|
printf("Trying to own the mutex\n");
|
||||||
|
pthread_mutex_lock(&mutex);
|
||||||
|
printf("Owns the mutex\n");
|
||||||
|
pthread_mutex_unlock(&mutex);
|
||||||
|
printf("Mutex released\n");
|
||||||
|
sem_post(semaphore);
|
||||||
|
printf("Semaphore posted\n");
|
||||||
|
printf("Trying to gets the semaphore\n");
|
||||||
|
sem_wait(semaphore);
|
||||||
|
printf("Semaphore taken\n");
|
||||||
|
printf("Thread ended\n");
|
||||||
|
pthread_exit(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
|
||||||
|
sem_unlink(SEM_NAME);
|
||||||
|
semaphore = sem_open(SEM_NAME, O_CREAT, 0644, SEMAPHORE_INITIAL_VALUE);
|
||||||
|
if (semaphore == SEM_FAILED)
|
||||||
|
{
|
||||||
|
perror("[sem_open");
|
||||||
|
return ERROR_INIT;
|
||||||
|
}
|
||||||
|
printf("Creating the thread\n");
|
||||||
|
pthread_create(&thread_1, NULL, produce, NULL);
|
||||||
|
|
||||||
|
printf("Waiting the thread end\n");
|
||||||
|
pthread_join(thread_1, NULL);
|
||||||
|
printf("Deleting the semaphore\n");
|
||||||
|
sem_destroy(semaphore);
|
||||||
|
printf("Process ended\n");
|
||||||
|
return ERROR_SUCCESS;
|
||||||
|
}
|
17
T2/tp/T2-TP_suite/sensorManager.c
Executable file
17
T2/tp/T2-TP_suite/sensorManager.c
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
#include "iSensor.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
|
void getInput(const unsigned int input, volatile MSG_BLOCK* mBlock){
|
||||||
|
unsigned int i;
|
||||||
|
unsigned int j = input;
|
||||||
|
D(printf("Get message for input %u \n",j));
|
||||||
|
mBlock->checksum = 0;
|
||||||
|
for(i=0;i < DATA_SIZE;i++){
|
||||||
|
mBlock->mData[i] = rand();
|
||||||
|
mBlock->checksum ^= mBlock->mData[i];
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
BIN
T2/tp/T2-TP_suite/tp.pdf
Executable file
BIN
T2/tp/T2-TP_suite/tp.pdf
Executable file
Binary file not shown.
BIN
T2/tp/exercice-1/acquisitionManagerTestAndSet.o
Normal file
BIN
T2/tp/exercice-1/acquisitionManagerTestAndSet.o
Normal file
Binary file not shown.
BIN
T2/tp/exercice-1/diagramme_temporel.png
Normal file
BIN
T2/tp/exercice-1/diagramme_temporel.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 142 KiB |
BIN
T2/tp/exercice-1/multitaskingAccumulatorTestAndSet
Executable file
BIN
T2/tp/exercice-1/multitaskingAccumulatorTestAndSet
Executable file
Binary file not shown.
Loading…
Reference in a new issue