lunes, 27 de enero de 2014

Semáforos (Código)

Código del programa.

#include"Cpu.h"
#include"Events.h"
#include"mqx_tasks.h"
#include"CsIO1.h"
#include"IO1.h"

voiduart_putchar (int, char );
charuart_getchar (int );
#define t_out      500
LWSEM_STRUCT my_lwsem;

voidCrea_Sem(uint32_t task_init_data)
{
//_mqx_uint result;
//printf("CreandoSemaforo");
                _lwsem_create(&my_lwsem, 1);

//result = _lwsem_wait(&my_lwsem);
  _task_abort(_task_get_id());

}

voidLed_Rojo(uint32_t task_init_data)
{
                _mqx_uint result;
               
while(1)
  {
                //printf("TareaRojo");
               
                result = _lwsem_wait(&my_lwsem);
                uart_putchar(0,'R');
                Red_LED_ClrVal(Red_LED_DeviceData);
    Blue_LED_SetVal(Blue_LED_DeviceData);
    Green_LED_SetVal(Green_LED_DeviceData);
_time_delay_ticks(t_out);   //suspendelatareapor el numerode ticks especificadopor el argumento
_lwsem_post(&my_lwsem);   
  }
}



voidLed_Verde(uint32_t task_init_data)
{
                _mqx_uint result;
                              
                while(1) {
                               result = _lwsem_wait(&my_lwsem);
                               uart_putchar(0, 'V');                                                          
                               Red_LED_SetVal(Red_LED_DeviceData);
                    Blue_LED_SetVal(Blue_LED_DeviceData);
                    Green_LED_ClrVal(Green_LED_DeviceData);
                _time_delay_ticks(t_out);   //suspendelatareapor el numerode ticks especificado                           _lwsem_post(&my_lwsem);   
                  }
}

voidLed_Azul(uint32_t task_init_data)
{
                _mqx_uint result;

                while(1)
                  {
                result = _lwsem_wait(&my_lwsem);
                uart_putchar(0,'A');
                Red_LED_SetVal(Red_LED_DeviceData);
                    Blue_LED_ClrVal(Blue_LED_DeviceData);
                    Green_LED_SetVal(Green_LED_DeviceData);
                _time_delay_ticks(t_out);   //suspendelatareapor el numerode ticks especificado                                           _lwsem_post(&my_lwsem);   
                  }
}


voiduart_putchar (int uart_port_num, char ch)
{
                if (uart_port_num == 0)
                {
/* Wait until space is available in the FIFO */
while(!(UART0_S1 & UART_S1_TDRE_MASK));

/* Send the character */
      UART0_D = (uint8)ch;
                }
                elseif (uart_port_num == 1)
                {
                /* Wait until space is available in the FIFO */
                while(!(UART1_S1 & UART_S1_TDRE_MASK));
               
                /* Send the character */
                  UART1_D = (uint8)ch;
                }
                else
                {
                /* Wait until space is available in the FIFO */
                while(!(UART2_S1 & UART_S1_TDRE_MASK));
               
                /* Send the character */
                  UART2_D = (uint8)ch;
                }
 }



charuart_getchar (int uart_port_num)
{
                if (uart_port_num == 0)
                {
/* Wait until space is available in the FIFO */
while(!(UART0_S1 & UART_S1_RDRF_MASK));

/* Send the character */
return (uint8)UART0_D;
                }
                elseif (uart_port_num == 1)
                {
                /* Wait until space is available in the FIFO */
                while(!(UART1_S1 & UART_S1_RDRF_MASK));
               
                /* Send the character */
                return (uint8)UART1_D;
                }
                else
                {
                /* Wait until space is available in the FIFO */
                while(!(UART2_S1 & UART_S1_RDRF_MASK));
               
                /* Send the character */
                return (uint8)UART2_D;
                }
}


No hay comentarios:

Publicar un comentario