Honza T. / Mbed 2 deprecated EXAMPLE_Nucleo_mbed_RTOS_test_code

Dependencies:   DS1620_improved TextLCD_improved mbed-rtos mbed

tsk_main.cpp

Committer:
dzoni
Date:
2015-12-14
Revision:
12:1de8b271e292
Parent:
11:e89f89c0920b
Child:
13:f62b10a6e1c5

File content as of revision 12:1de8b271e292:

#include "mbed.h"
#include "rtos.h"

#include "tsk_button.h"
#include "tsk_display.h"
#include "tsk_dist.h"
#include "tsk_led.h"
#include "tsk_temp.h"

#define TASKS_NUMBER    (sizeof(taskList)/sizeof(taskList[0]))

uint32_t uiCnt = 0;

struct task_definition_struct {
    void(*task)(void const *args);
    uint32_t(*init)(void const *args); // 1 = OK, 0 = FAIL
    void *task_args;                   // NULL For DEFAULT (NULL)
    void *init_args;                   // NULL For DEFAULT (NULL)
    osPriority priority;
//    uint32_t stack_size;               // 0 for DEFAULT (DEFAULT_STACK_SIZE)
//    unsigned char *stack_pointer;      // NULL for DEFAULT (NULL)
    uint32_t delay;                    // Delay on start from previous task
    Thread *thread;                    // To be filled in during runtime
    uint32_t retVal;                   // Return Value - to be filled in during runtime
};

static struct task_definition_struct taskList[] = {
    { dist_thread,   NULL,            NULL, NULL, osPriorityRealtime,    0, NULL, 0 },
    { temp_thread,   &initDS1620Temp, NULL, NULL, osPriorityLow,         0, NULL, 0 },
    { button_thread, NULL,            NULL, NULL, osPriorityAboveNormal, 0, NULL, 0 },
    { led_thread,    NULL,            NULL, NULL, osPriorityNormal,      0, NULL, 0 },
    { disp_thread,   NULL,            NULL, NULL, osPriorityLow,         0, NULL, 0 },
};

static uint32_t initTasks(void) {
    uint32_t i;
    uint32_t retval = 1;
    
    for (i = 0; i < TASKS_NUMBER; i++) {
        if (taskList[i].init != NULL) {
            if ((taskList[i].retVal = ((*taskList[i].init)(taskList[i].init_args))) == 0)
                retval = 0;
        }
    }
            
    for (i = 0; i < TASKS_NUMBER; i++) {
        Thread::wait(taskList[i].delay);

        if (taskList[i].retVal == 1) {
            taskList[i].thread = new Thread(taskList[i].task, taskList[i].task_args, taskList[i].priority );
        }
    }
    
    return retval;
}


int main() {
    
//    Thread::wait(1000);

//    initDS1620Temp(NULL);
      initDisplay(NULL);
      
//    Thread tempThread(temp_thread, NULL, osPriorityLow);
//    Thread distThread(dist_thread, NULL, osPriorityRealtime);
//    Thread ledThread(led_thread, NULL, osPriorityNormal);
//    Thread buttonThread(button_thread, NULL, osPriorityAboveNormal);
//    Thread dispThread(disp_thread, NULL, osPriorityNormal);


//    initTasks();

    Thread::wait(osWaitForever);
}