You are on page 1of 18

Adc1.c #include <mqx.h> #include <bsp.h> #include <adc.h>//adc.

h para los operadores y funciones de los driver del ADC #if MQX_USE_LWEVENTS #include <lwevent.h>//inclusin de archivos para descargas de procesador #endif //--------------------------------etiquetas necesarias #if ! BSPCFG_ENABLE_IO_SUBSYSTEM #error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined non-zero in user_config.h. Please recompile BSP with this option. #endif #ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED #error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in user_config.h and recompile BSP with this option. #endif #if ! BSPCFG_ENABLE_ADC #error This application requires BSPCFG_ENABLE_ADC defined non-zero in user_config.h. Please recompile BSP with this option. #endif //---------------------------------------- Declaracin de la tarea /* Task IDs */ #define MAIN_TASK 5 /* Function prototypes */ extern void main_task(uint_32); const TASK_TEMPLATE_STRUCT MQX_template_list[] = { /* Task Index, Function, Stack, Priority, Param, Time Slice */ {MAIN_TASK, main_task, 800, 5, 0, 0 }, {0} }; //-----------------------------------/* ADC device init struct */ const ADC_INIT_STRUCT adc_init = { ADC_RESOLUTION_DEFAULT, /* resolution */ }; #if MQX_USE_LWEVENTS static LWEVENT_STRUCT evn; #endif /* Logical channel #1 init struct */ const ADC_INIT_CHANNEL_STRUCT adc_channel_param1 = { BSP_ADC_CH_POT, /* physical ADC channel */ ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */ 10, /* number of samples in one run sequence */ 0, /* time offset from trigger point in us */

Name, "Main",

Attributes, MQX_AUTO_START_TASK,

600000, /* 0x10000, /* 10, /* ADC_TRIGGER_1, /* #if MQX_USE_LWEVENTS &evn #endif };

period in us (= 0.6 sec) */ scale range of result (not used now) */ circular buffer size (sample count) */ logical trigger ID that starts this ADC channel */

/* Logical channel #2 init struct */ /*const ADC_INIT_CHANNEL_STRUCT adc_channel_param2 = { ADC_SOURCE_AN1, /* physical ADC channel */ /* ADC_CHANNEL_MEASURE_ONCE | ADC_CHANNEL_START_NOW, /* one sequence is sampled after fopen */ /*10, /* number of samples in one run sequence */ /*500000, /* time offset from trigger point in us */ /*500000, /* period in us (= 0.5 sec) */ /*0x10000, /* scale range of result (not used now) */ /*10, /* circular buffer size (sample count) */ /*ADC_TRIGGER_2, /* logical trigger ID that starts this ADC channel */ /*#if MQX_USE_LWEVENTS NULL #endif }; */ /*TASK*----------------------------------------------------** ** Task Name : main_task ** Comments : ** *END*-----------------------------------------------------*/ void main_task (uint_32 initial_data) { ADC_RESULT_STRUCT data;//guardar los resultados de la conversin FILE_PTR f, f1; //f2;//apuntadores de archivos f,f1,f2 _mqx_int i = 0;//variable entera 32 bits printf("\n\n-------------- Begin ADC example --------------\n\n"); #if MQX_USE_LWEVENTS//creando y corriendo event if (_lwevent_create(&evn, 0) != MQX_OK) { printf("\nMake event failed!\n"); _task_block(); } #endif //generar archivo de adc_init en f printf("Opening ADC device ..."); f = fopen("adc:", (const char*)&adc_init); if(f != NULL) { printf("done\n"); } else { printf("failed\n"); _task_block(); } //generar archivo de adc_init en f printf("Opening channel #1 ...");

f1 = fopen("adc:1", (const char*)&adc_channel_param1); if(f1 != NULL) { printf("done, prepared to start by trigger\n"); } else { printf("failed\n"); _task_block(); } //generar archivo del potenciometro en f2 //printf("Opening channel #2 ..."); /*f2 = fopen("adc:2", (const char*)&adc_channel_param2); /* adc:2 is running now */ /*if(f2 != NULL) { printf("done, one sequence started automatically\n"); } else { printf("failed\n"); _task_block(); } */ _time_delay(1000); printf("Triggering channel #1..."); ioctl(f, IOCTL_ADC_FIRE_TRIGGER, (pointer) ADC_TRIGGER_1); printf("triggered!\n"); for(i = 0;i<20 ; i++) { /* channel 1 sample ready? */ while (!(read(f1, &data, sizeof(data) ))); printf("ADC ch 1: %4d \n", data.result); // else // printf(" "); //} /* channel 2 sample ready? */ /* if (read(f2, &data, sizeof(data) )) printf("ADC ch 2: %d\n", data.result); else printf("\n");*/ /* if (i== 21) { printf("Pausing channel #1..."); ioctl (f, IOCTL_ADC_PAUSE_CHANNELS, (pointer) ADC_TRIGGER_1); printf("stopped!\n"); } if (i == 22) { printf("Resuming channel #1..."); ioctl (f, IOCTL_ADC_RESUME_CHANNELS, (pointer) ADC_TRIGGER_1); printf("resumed!\n"); }*/ _time_delay(100); } #if MQX_USE_LWEVENTS

printf("Waiting for event..."); if (_lwevent_wait_ticks(&evn, 0x01, TRUE, 0) != MQX_OK) { printf("failed!\n"); } else printf("succeed!\n"); #endif /* close all ADC channels */ printf("Closing channels..."); fclose(f1); /*fclose(f2);*/ fclose(f); printf("done!\n"); _mqx_exit(0); } /* EOF */

Adc.c #include <mqx.h> #include <bsp.h> #include <adc.h>//adc.h para los operadores y funciones de los driver del ADC #if MQX_USE_LWEVENTS #include <lwevent.h>//inclusin de archivos para descargas de procesador #endif //--------------------------------etiquetas necesarias #if ! BSPCFG_ENABLE_IO_SUBSYSTEM #error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined non-zero in user_config.h. Please recompile BSP with this option. #endif #ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED #error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in user_config.h and recompile BSP with this option. #endif #if ! BSPCFG_ENABLE_ADC #error This application requires BSPCFG_ENABLE_ADC defined non-zero in user_config.h. Please recompile BSP with this option. #endif //---------------------------------------- Declaracin de la tarea /* Task IDs */ #define MAIN_TASK 5 /* Function prototypes */ extern void main_task(uint_32); const TASK_TEMPLATE_STRUCT MQX_template_list[] = { /* Task Index, Function, Stack, Priority, Param, Time Slice */

Name,

Attributes,

0, };

{MAIN_TASK, 0 {0}

main_task, },

800,

5,

"Main",

MQX_AUTO_START_TASK,

//-----------------------------------/* ADC device init struct */ const ADC_INIT_STRUCT adc_init = {//conversor ADC ADC_RESOLUTION_DEFAULT, /* resolution */ }; #if MQX_USE_LWEVENTS static LWEVENT_STRUCT evn; #endif /* Logical channel #1 init struct */ const ADC_INIT_CHANNEL_STRUCT adc_channel_param1 = { BSP_ADC_CH_POT, /* physical ADC channel */ ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */ 10, /* number of samples in one run sequence */ 0, /* time offset from trigger point in us */ 600000, /* period in us (= 0.6 sec) */ 0x10000, /* scale range of result (not used now) */ 10, /* circular buffer size (sample count) */ ADC_TRIGGER_1, /* logical trigger ID that starts this ADC channel */ #if MQX_USE_LWEVENTS &evn #endif }; /*TASK*----------------------------------------------------** ** Task Name : main_task ** Comments : ** *END*-----------------------------------------------------*/ void main_task (uint_32 initial_data) { ADC_RESULT_STRUCT data;//guardar los resultados de la conversin FILE_PTR f, f1;//apuntadores de archivos f,f1,f2 _mqx_int i = 0;//variable entera 32 bits printf("\n\n-------------- Begin ADC example --------------\n\n"); #if MQX_USE_LWEVENTS//creando y corriendo event if (_lwevent_create(&evn, 0) != MQX_OK) { printf("\nMake event failed!\n"); _task_block(); } #endif //generar archivo de adc_init en f printf("Opening ADC device ..."); f = fopen("adc:", (const char*)&adc_init); if(f != NULL) { printf("done\n");

} else { printf("failed\n"); _task_block(); } //generar archivo de adc_init en f1 printf("Opening channel #1 ..."); f1 = fopen("adc:1", (const char*)&adc_channel_param1); if(f1 != NULL) { printf("done, prepared to start by trigger\n"); } else { printf("failed\n"); _task_block(); } //---------------------------------------------------//es decir, se inicia conversin en el potenciometro _time_delay(1000); //disparar el canal de lazo infinito con trigger1 printf("Triggering channel #1..."); ioctl(f, IOCTL_ADC_FIRE_TRIGGER, (pointer) ADC_TRIGGER_1); printf("triggered!\n"); //--------------------------------------------------for(i = 0; i< 50 ; i++) { /* channel 1 sample ready? */ if (read(f1, &data, sizeof(data) )) printf("ADC ch 1: %4d ", data.result); else printf("\n"); _time_delay(100); } #if MQX_USE_LWEVENTS printf("Waiting for event..."); if (_lwevent_wait_ticks(&evn, 0x01, TRUE, 0) != MQX_OK) { printf("failed!\n"); } else printf("succeed!\n"); #endif /* close all ADC channels */ printf("Closing channels..."); fclose(f1); fclose(f); printf("done!\n"); _mqx_exit(0); } /* EOF */

Gpio.c #include "main.h" /*TASK*----------------------------------------------------** ** Task Name : main_task ** Comments : ** This task performs various open - close operation on ** several sets of pins. The purpose of this demo is to ** explain and demonstrate the use of "pin files" as the output ** of GPIO fopen command. The demonstration is focused mainly ** on debugging and realising what we are performing on which ** set of pins. ** At the end of this task, neverending loop runs and reads ** status of pin connected to SWITCH_1 and the same value writes ** on output pin connected to LED D10. *END*-----------------------------------------------------*/ void main_task (uint_32 initial_data) { FILE_PTR port_file1, port_file2, port_file3; #if defined BSP_LED2 && defined BSP_LED3 && #define PINS1 GPIO_PIN_STRUCT pins1[] = { /* when opening, explicitly set BSP_LED1 | GPIO_PIN_STATUS_0, /* when opening, explicitly set BSP_LED2 | GPIO_PIN_STATUS_1, /* when opening, implicitly set BSP_LED4, GPIO_LIST_END }; #endif #if defined BSP_LED2 #define PINS2 GPIO_PIN_STRUCT pins2[] = { BSP_LED2, GPIO_LIST_END }; #endif #if defined BSP_LED1 #define PINS3 GPIO_PIN_STRUCT pins3[] = { BSP_LED1, GPIO_LIST_END }; #endif #if defined BSP_BUTTON1 && defined BSP_BUTTON2 #define PINS4 GPIO_PIN_STRUCT pins4[] = { BSP_BUTTON1, BSP_BUTTON2, GPIO_LIST_END }; #endif uint_8 set_value = 0; /************************************************ defined BSP_LED4 output to 0 */ output to 1 */ output to 0 */

Opening file for write with associated pins, write LOG 0 and LOG 1 to file. *************************************************/ #if defined PINS1 && defined PINS2 /* open file containing pin1 set of pins/signals */ if (NULL == (port_file1 = fopen("gpio:write", (char_ptr) &pins1 ))) { printf("Opening file1 GPIO for pins1 failed.\n"); _mqx_exit(-1); } /* write logical 1 to all signals in the file (fast) */ if (IO_OK != ioctl(port_file1, GPIO_IOCTL_WRITE_LOG1, NULL )) { printf("Writing to whole file1 failed.\n"); _mqx_exit(-1); } /* write logical 0 to the pins/signals listed in pins2 array (slow) */ if (IO_OK != ioctl(port_file1, GPIO_IOCTL_WRITE_LOG0, &pins2 )) { printf("Writing to pins2 of file1 failed.\n"); _mqx_exit(-1); } /* close file1 */ fclose(port_file1); #endif /************************************************ Opening file for write without associated pins, pins are added later via IOCTL commans, write LOG 0 and LOG 1 to file. ************************************************/ #ifdef PINS3 /* open file not containing any pin/signal */ if (NULL == (port_file2 = fopen("gpio:write", (char_ptr) NULL))) { printf("Opening file2 GPIO without associated pins failed.\n"); _mqx_exit(-1); } /* add pins/signals to the existing file */ if (IO_OK != ioctl(port_file2, GPIO_IOCTL_ADD_PINS, &pins3 )) { printf("Adding pins3 to file2 failed.\n"); _mqx_exit(-1); } /* write logical 0 to all signals in the file (fast) */ if (IO_OK != ioctl(port_file2, GPIO_IOCTL_WRITE_LOG0, NULL )) { printf("Writing to pins3 of file2 failed.\n"); _mqx_exit(-1); } /* close port 2 */ fclose(port_file2); #endif /************************************************ Opening file for read with associated pins(buttons), Opening file for write with associated pins(LEDs), After pressing button LED is activated. ************************************************/ #if defined PINS4 && defined PINS2 /* opening pins/signals for input */ if (NULL == (port_file3 = fopen("gpio:read", (char_ptr) &pins4 )))

{ printf("Opening file3 GPIO with associated pins failed.\n"); _mqx_exit(-1); } /* prepare new file with only one pin output */ /* and open with new specification */ if (NULL == (port_file1 = fopen("gpio:write", (char_ptr) &pins2 ))) { printf("Opening file1 GPIO for pins2 failed.\n"); _mqx_exit(-1); } /* It is not easy to generalize switch: every board has its own switch names */ printf("Use SWITCH on board to switch LED on or off\n"); while (TRUE) { /* read pin/signal status to pin list */ if (IO_OK != ioctl(port_file3, GPIO_IOCTL_READ, (char_ptr) &pins4)) { printf("Reading pin status from file3 to pins4 list failed.\n"); _mqx_exit(-1); } /* test first's pin of file binary value */ if (pins4[0] & GPIO_PIN_STATUS) { printf("LED OFF.\n"); /* clear pin to 0 (fast) */ if (IO_OK != ioctl(port_file1, GPIO_IOCTL_WRITE_LOG0, NULL)) { printf("Clearing pins2 to log 0 failed.\n"); _mqx_exit(-1); } } else { printf("LED ON.\n"); /* set pin to 1 (fast) */ if (IO_OK != ioctl(port_file1, GPIO_IOCTL_WRITE_LOG1, NULL)) { printf("Setting pins2 to log 1 failed.\n"); _mqx_exit(-1); } } } /************************************************ In case board does not have BUTTONS, Only blink with LED. ************************************************/ #elif defined PINS3 /* if we don't have PINS4 set, blink */ /* open file not containing any pin/signal */ if (NULL == (port_file3 = fopen("gpio:write", (char_ptr) &pins3))) { printf("Opening file2 GPIO without associated pins failed.\n"); _mqx_exit(-1); } while(TRUE){

/* write logical 0 to all signals in the file (fast) */ if (IO_OK != ioctl(port_file3, GPIO_IOCTL_WRITE_LOG0, NULL )) { printf("Writing to pins3 of file2 failed.\n"); _mqx_exit(-1); } _time_delay(1000); /* write logical 1 to all signals in the file (fast) */ if (IO_OK != ioctl(port_file3, GPIO_IOCTL_WRITE_LOG1, NULL )) { printf("Writing to pins3 of file2 failed.\n"); _mqx_exit(-1); } _time_delay(1000); } #endif _mqx_exit(-1); } /* EOF */

Holamundo.c #include <mqx.h> #include <bsp.h> #include <fio.h> #if ! BSPCFG_ENABLE_IO_SUBSYSTEM #error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined non-zero in user_config.h. Please recompile BSP with this option. #endif #ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED #error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in user_config.h and recompile BSP with this option. #endif /* Task IDs */ #define HELLO_TASK #define WORLD_TASK

5 6

extern void hello_task(uint_32); extern void world_task(uint_32); const TASK_TEMPLATE_STRUCT MQX_template_list[] = { /* Task Index, Function, Stack, Priority, Name, Time Slice */

Attributes,

Param,

{ WORLD_TASK, }, { HELLO_TASK, }, { 0 } };

world_task, 1000, hello_task, 1000,

4, 5,

"world", "hello",

MQX_AUTO_START_TASK, 0, 0, 0,

0 0

/*TASK*----------------------------------------------------* * Task Name : world_task * Comments : * This task creates hello_task and then prints " World ". * *END*-----------------------------------------------------*/ void world_task (uint_32 initial_data) { _task_id hello_task_id;//task_id apunta a una tarea hello_task_id = _task_create(0, HELLO_TASK, 0); if (hello_task_id == MQX_NULL_TASK_ID) { printf ("\n Could not create hello_task\n"); } else { printf(" World \n"); } /* /* ** ** ** ** */ // /* Start CR 1764 */ This example uses polled serial I/O by default. Should it be modified to use interrupt driven serial drivers, you will need to uncomment the following delay code to insure serial communication completes before _mqx_exit() disables all interrupts. _time_delay(200); End CR 1764 */

_mqx_exit(0); } /*TASK*----------------------------------------------------* * Task Name : hello_task * Comments : * This task prints " Hello". * *END*-----------------------------------------------------*/ void hello_task (uint_32 initial_data) { printf("\n Hello\n"); //_task_block(); _mqx_exit(0); } /* EOF */

Pininos.c #include "main.h" /* ADC device init struct */ const ADC_INIT_STRUCT adc_init = { ADC_RESOLUTION_DEFAULT, /* resolution */ }; #if MQX_USE_LWEVENTS static LWEVENT_STRUCT evn; #endif /* Logical channel #1 init struct */ const ADC_INIT_CHANNEL_STRUCT adc_channel_param1 = { BSP_ADC_CH_POT, /* physical ADC channel */ ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */ 10, /* number of samples in one run sequence */ 0, /* time offset from trigger point in us */ 600000, /* period in us (= 0.6 sec) */ 0x10000, /* scale range of result (not used now) */ 10, /* circular buffer size (sample count) */ ADC_TRIGGER_1, /* logical trigger ID that starts this ADC channel */ #if MQX_USE_LWEVENTS &evn #endif }; GPIO_PIN_STRUCT led2[] = { BSP_LED2, GPIO_LIST_END }; GPIO_PIN_STRUCT led3[] = { BSP_LED3, GPIO_LIST_END }; void main_task (uint_32 initial_data) { ADC_RESULT_STRUCT data;//guardar los resultados de la conversin FILE_PTR fdevic, fpot, fled; //f2;//apuntadores de archivos f,f1,f2 _mqx_int i = 0;//variable entera 32 bits /* open file containing pin1 set of pins/signals */ if (NULL == (fled = fopen("gpio:write", (char_ptr) &led2 ))) { printf("Opening file1 GPIO for pins1 failed.\n"); _task_block(); } /* write logical 1 to all signals in the file (fast) */ if (IO_OK != ioctl(fled, GPIO_IOCTL_WRITE_LOG1, &led2 )) {

printf("Writing to whole file1 failed.\n"); _task_block(); } _time_delay(1000); /* write logical 0 to the pins/signals listed in pins2 array (slow) */ if (IO_OK != ioctl(fled, GPIO_IOCTL_WRITE_LOG0, &led2 )) { printf("Writing to pins2 of file1 failed.\n"); _task_block(); } /* close file1 */ fclose(fled); /* open file containing pin1 set of pins/signals */ if (NULL == (fled = fopen("gpio:write", (char_ptr) &led3 ))) { printf("Opening file1 GPIO for pins1 failed.\n"); _task_block(); } //generar archivo de adc_init en f printf("Opening ADC device ..."); fdevic = fopen("adc:", (const char*)&adc_init); if(fdevic != NULL) { printf("done\n"); } else { printf("failed\n"); _task_block(); } //generar archivo de adc_init en f printf("Opening channel #1 ..."); fpot = fopen("adc:1", (const char*)&adc_channel_param1); if(fpot != NULL) { printf("done, prepared to start by trigger\n"); } else { printf("failed\n"); _task_block(); } printf("Triggering channel #1..."); ioctl(fdevic, IOCTL_ADC_FIRE_TRIGGER, (pointer) ADC_TRIGGER_1); printf("triggered!\n"); for (i=0; i<20; i++) { while (!(read(fpot, &data, sizeof(data) ))); printf("ADC ch 1: %4d \n", data.result); if (data.result<2048) { if (IO_OK != ioctl(fled, GPIO_IOCTL_WRITE_LOG0, &led3 )) { printf("Writing to whole file1 failed.\n"); _task_block(); }

}// if (data.result<2048) else{ if (IO_OK != ioctl(fled, GPIO_IOCTL_WRITE_LOG1, &led3 )) { printf("Writing to whole file1 failed.\n"); _task_block(); } }// else (data.result<2048) }// end for i.. _time_delay(100); printf ("\n fin aplicacin\n"); fclose (fdevic); fclose (fpot); fclose (fled); printf ("\n Programa terminado\n"); }//final de tarea Pininos.h (main.h) #include <mqx.h> #include <bsp.h> #include <adc.h>//adc.h para los operadores y funciones de los driver del ADC #include <io_gpio.h>//para puertos de proposito gral #if MQX_USE_LWEVENTS #include <lwevent.h>//inclusin de archivos para descargas de procesador #endif //Etiquetas del BSP #if ! BSPCFG_ENABLE_GPIODEV #error This application requires BSPCFG_ENABLE_GPIODEV defined non-zero in user_config.h. Please recompile BSP with this option. #endif #if ! BSPCFG_ENABLE_IO_SUBSYSTEM #error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined non-zero in user_config.h. Please recompile BSP with this option. #endif #ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED #error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in user_config.h and recompile BSP with this option. #endif #if ! BSPCFG_ENABLE_ADC #error This application requires BSPCFG_ENABLE_ADC defined non-zero in user_config.h. Please recompile BSP with this option. #endif //ndice de la tarea #define MAIN_TASK 5 /* Function prototypes */ extern void main_task(uint_32); //plantilla para las tareas const TASK_TEMPLATE_STRUCT MQX_template_list[] = { /* Task Index, Function, Stack, Priority, Param, Time Slice */

Name,

Attributes,

0, };

{MAIN_TASK, 0 {0}

main_task, },

800,

5,

"Main",

MQX_AUTO_START_TASK,

Tareas.c #include "main.h" uint_8 x, y; //to create the variables //Tarea Main imprime hola mundo void Main_task(uint_32 initial_data) { printf("\n Hello World \n"); _mqx_exit(0); } //tarea print imrpime el valor x,y void Print_task(uint_32 initial_data) { while(x<20){ printf("\n X=%d, Y=%d \n", x, y); _sched_yield();//token es de 10 ms } _mqx_exit(0); } // tarea math incrementa x,y void Math_task(uint_32 initial_data) { while(x<10){ x++; y++; _sched_yield();//token es de 10 ms } _mqx_exit(0); }

Task2.c #include <mqx.h> #include <bsp.h> /*etiquetas de soporte*/ #ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED #error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in user_config.h and recompile BSP with this option. #endif /*Definicion de tareas*/ #define MAIN_TASK 1 #define PRINT_TASK 2 #define MATH_TASK 3

extern void Main_task(uint_32); extern void Print_task(uint_32); extern void Math_task(uint_32); const TASK_TEMPLATE_STRUCT MQX_template_list[] = { /* Task Index, Function, Stack, Priority, Param, Time Slice */ {MAIN_TASK, Main_task, 1500, 9, 0, 0}, {PRINT_TASK, Print_task,1500, 8, 0, 0}, {MATH_TASK, Math_task, 1500, 8, 0, 0}, {0, 0, 0, 0, 0, 0, } }; _task_id printtask_id,printtask_id2,mathtask_id; uint_8 x, y; LWSEM_STRUCT sem; TASK_TEMPLATE_STRUCT_PTR tdptr; void Main_task(uint_32 initial_data) { //_task_id printtask_id,printtask_id2,mathtask_id; _lwsem_create(&sem,1); //direccion a semaforo, contador printtask_id= _task_create_blocked(0,PRINT_TASK,1); printtask_id2= _task_create_blocked(0,PRINT_TASK,2); mathtask_id= _task_create_blocked(0,MATH_TASK,0); tdptr= _task_get_td(printtask_id); _task_ready( tdptr); _task_ready(_task_get_td(mathtask_id)); _task_ready(_task_get_td(printtask_id2)); _task_block(); } void Print_task(uint_32 initial_data) { while(1) { if (initial_data == 1) { _lwsem_wait(&sem); printf(" Instance 1: X=%d \n", x); _time_delay(500); _lwsem_post(&sem); } if (initial_data==2) { _lwsem_wait(&sem); printf(" Instance 2: Y=%d \n", y); _time_delay(500); _lwsem_post(&sem); } } _mqx_exit(0); } void Math_task(uint_32 initial_data) { while(1){ _lwsem_wait(&sem); x++;

Name, "main",

Attributes, MQX_AUTO_START_TASK,

"Print_Task", 0, "Math_Task", 0,

y++; _time_delay(500); _lwsem_post(&sem); } _mqx_exit(0); }

Tareas.c #include <mqx.h> #include <bsp.h> /*etiquetas de soporte*/ #ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED #error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in user_config.h and recompile BSP with this option. #endif /*Definicion de tareas*/ #define MAIN_TASK 1 #define PRINT_TASK 2 #define MATH_TASK 3 extern void Main_task(uint_32); extern void Print_task(uint_32); extern void Math_task(uint_32); const TASK_TEMPLATE_STRUCT MQX_template_list[] = { /* Task Index, Function, Stack, Priority, Param, Time Slice */ {MAIN_TASK, Main_task, 1500, 10, 0, 0}, {PRINT_TASK, Print_task,1500, 9, 0, 0}, {MATH_TASK, Math_task, 1500, 9, 0, 0}, {0, 0, 0, 0, 0, 0, } }; uint_8 x, y; //to create the variables //Tarea Main imprime hola mundo void Main_task(uint_32 initial_data) { printf("\n Hello World \n"); _mqx_exit(0); } //tarea print imrpime el valor x,y void Print_task(uint_32 initial_data) { while(x<20){ printf("\n X=%d, Y=%d \n", x, y); _sched_yield();//token es de 10 ms } _mqx_exit(0); }

Name, "main",

Attributes, MQX_AUTO_START_TASK,

"Print_Task",MQX_AUTO_START_TASK, "Math_Task", MQX_AUTO_START_TASK,

// tarea math incrementa x,y void Math_task(uint_32 initial_data) { while(x<10){ x++; y++; _sched_yield();//token es de 10 ms } _mqx_exit(0); }

You might also like