TODOPIC

Microcontroladores PIC => Lenguaje C para microcontroladores PIC => Mensaje iniciado por: Darukur en 27 de Junio de 2009, 13:25:18

Título: Driver de USART para FreeRTOS con at91sam7
Publicado por: Darukur en 27 de Junio de 2009, 13:25:18
Siguiendo con el post del Driver Grafico LCD para FreeRTOS (http://www.sistemasembebidos.com.ar/forum/index.php?topic=651.msg2693#msg2693), complete un driver de USART de at91sam7 para FreeRTOS (con irqs anidables).

Funciona casi todo con codigo por interrupciones, salvo obvio las llamadas a los metodos (init send y receive), no necesita una tarea de Freertos para correr.
Es thread safe ya que usa mutexes.


Saludos espero que les guste.

(Disculpen lo malo de la grabacion y el tipeado, tenia la camara en una mano y con la otra hacia el resto :))
Título: Re: Driver de USART para FreeRTOS con at91sam7
Publicado por: Darukur en 27 de Junio de 2009, 13:54:24
Para que vean lo simple de su uso dejo el codigo del ejemplo (la parte del uso de USART):

Inicializacion
Código: C
  1. tUsartInitData usInitdata;
  2.  
  3. /*Initialize USART data*/
  4. usInitdata.eSerialPort = serCOM2;
  5. usInitdata.ulBauds = 56000;
  6. usInitdata.bufferSizeTX = 256;
  7. usInitdata.bufferSizeRX = 256;
  8.  
  9. /*Initialize USART peripherial*/
  10. vUsartInit(&usInitdata);

Recepcion y transmision
Código: C
  1. tUsartSendData usSendData;
  2. tUsartReceiveData usRecvData;
  3. portCHAR textBuffer[100];
  4.  
  5. /*Prepare to send messages*/
  6. usSendData.port = serCOM2;
  7. usSendData.size = nullTerminatedMax(100); //Null termination limit
  8. usSendData.xBlockTime = 200;
  9.  
  10. /*Prepare to receive a message*/
  11. usRecvData.port = usSendData.port;      //Same as send
  12. usRecvData.size = nullTerminatedMax(100); //Null termination limit
  13. usRecvData.data = (unsigned portCHAR *) textBuffer;
  14. usRecvData.xBlockTime = portMAX_DELAY; //Wait forever a replay
  15.  
  16. while (1)
  17. {
  18.     /*Receive message*/
  19.     cUSartReceive(&usRecvData);
  20.  
  21.     /*Replay with the same message using the usart*/
  22.     usSendData.data = "You sent \"";
  23.     cUSartSend(&usSendData);
  24.     usSendData.data = (unsigned portCHAR *) textBuffer;
  25.     cUSartSend(&usSendData);
  26.     usSendData.data = "\"\n\r";
  27.     cUSartSend(&usSendData);
  28. }