Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review PCB driver de EEZY MK3 #5

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ USE_SAPI=y
DEFINES+=SAPI_USE_INTERRUPTS
DEFINES+=OVERRIDE_SAPI_HCSR04_GPIO_IRQ

# For LCD connected via I2C PCF8574T I/O expander
DEFINES+=LCD_HD44780_I2C_PCF8574T

# Use FreeRTOS
USE_FREERTOS=y
FREERTOS_HEAP_TYPE=1
Expand Down
2 changes: 2 additions & 0 deletions app/inc/FreeRTOSPriorities.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@

#define priorityEncoderTask ( configMAX_PRIORITIES - 5 )

#define priorityDisplayTask ( configMAX_PRIORITIES - 6 )

#endif /* FREERTOSPRIORITIES_H_ */
111 changes: 111 additions & 0 deletions app/inc/buffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*! \file buffer.h
\brief Descripción del archivo.
\author Gonzalo G. Fernández
\version 1.0
\date Septiembre 2020

Detalle.
*/

#ifndef BUFFER_H_
#define BUFFER_H_

/*! \def bufferLENGTH
\brief Cantidad de mensajes que puede guardar el buffer circular.
*/
#define bufferLENGTH 10

/*! \def bufferMSG_LENGTH
\brief Cantidad máxima de caracteres que puede tener un mensaje.
*/
#define bufferMSG_LENGTH 10

/*! \typedef xBuffer_t
\brief Estructura del buffer circular.
*/
typedef struct xBuffer_t xBuffer_t;

/*! \typedef xBufferHandle_t
\brief Handle para permitir la interacción del usuario
con la API.
*/
typedef xBuffer_t* xBufferHandle_t;

/*! \fn BaseType_t xBufferCreate( void )
\brief Creación de buffer circular para mensajes de la
aplicación.
\return pdPASS si la creación se realizó con éxito.
*/
BaseType_t xBufferCreate( void );

/*! \fn xBufferHandle_t xBufferInit(uint8_t* pcBuffer, size_t size)
\brief Inicialización del buffer circular.
\param ppcBuffer
\param xSize
\return Handle del buffer circular
*/
xBufferHandle_t xBufferInit( uint8_t** ppcBuffer, size_t xSize );

/*! \fn void vBufferFree( xBufferHandle_t xBuffer )
\brief Eliminación del buffer circular.
Liberación de memoria.
\param xBufferHandle Handle del buffer a eliminar.
*/
void vBufferFree( xBufferHandle_t xBufferHandle );

/*! \fn void vBufferReset( xBufferHandle_t xBuffer )
\brief Reseteo del buffer circular para vaciarlo.
(head == tail).
\param xBufferHandle Handle del buffer a resetear.
*/
void vBufferReset( xBufferHandle_t xBufferHandle );

/*! \fn BaseType_t xBufferPut( xBufferHandle_t xBufferHandle, uint8_t *pcData )
\brief Colocar elemento en el buffer circular.
\param xBufferHandle Handle de buffer a modificar.
\param pcData Elemento a escribir en el buffer.
\return pdFAIL si el buffer se encuentra lleno (no se produce escritura).
*/
BaseType_t xBufferPut( xBufferHandle_t xBufferHandle, uint8_t *pcData );

/*! \fn BaseType_t xBufferGet( xBufferHandle_t xBufferHandle, uint8_t *pcData )
\brief Leer elemento del buffer circular.
\param xBufferHandle Handle de buffer a modificar.
\param pcData Elemento a leer del buffer.
\return pdFAIL si el buffer se encuentra vacío (no se produce escritura).
*/
BaseType_t xBufferGet( xBufferHandle_t xBufferHandle, uint8_t* pcData );

/*! \fn BaseType_t xBufferEmpty( xBufferHandle_t xBufferHandle )
\brief Verificación de buffer circular vacío.
\param xBufferHandle Handle de buffer a verificar.
\return Verdadero si el buffer esta vacío.
*/
BaseType_t xBufferEmpty( xBufferHandle_t xBufferHandle );

/*! \fn BaseType_t xBufferFull( xBufferHandle_t xBuffer )
\brief Verificación de buffer circular lleno.
\param xBufferHandle Handle de buffer a verificar.
\return Verdadero si el buffer esta lleno.
*/
BaseType_t xBufferFull( xBufferHandle_t xBufferHandle );

/*! \fn size_t xBufferCapacity( xBufferHandle_t xBufferHandle )
\brief Obtener capacidad del buffer circular.
\param xBufferHandle Handle de buffer a verificar.
\return Capacidad del buffer (size_t)
*/
size_t xBufferCapacity( xBufferHandle_t xBufferHandle );

/*! \fn size_t xBufferSize( xBufferHandle_t xBufferHandle )
\brief Obtener cantidad de elementos en el buffer.
\param xBufferHandle Handle de buffer a verificar.
\return Cantidad de elementos en buffer (size_t)
*/
size_t xBufferSize( xBufferHandle_t xBufferHandle );

void vBufferReadMsg( char* pcMsgToRead );

void vBufferWriteMsg( char* pcMsgToWrite );

#endif /* APP_INC_BUFFER_H_ */
28 changes: 28 additions & 0 deletions app/inc/display_lcd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*! \file display_lcd.h
\brief Descripción del archivo.
\author Gonzalo G. Fernández
\version 1.0
\date Septiembre 2020

Detalle.
*/

#ifndef DISPLAY_LCD_H_
#define DISPLAY_LCD_H_

/*! \var TaskHandle_t xDisplayTaskHandle
\brief Handle de la tarea de control del Display LCD.
*/
extern TaskHandle_t xDisplayTaskHandle;

/*! \fn void vDisplayTask( void *pvParameters )
\brief Tarea para control de display LCD.
*/
void vDisplayTask( void *pvParameters );

/*! \fn BaseType_t xDisplayInit( void )
\brief Inicialización de módulo LCD
*/
BaseType_t xDisplayInit( void );

#endif /* DISPLAY_LCD_H_ */
6 changes: 6 additions & 0 deletions app/inc/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
#define vEncoderSW_IRQ_HANDLER GPIO2_IRQHandler // GPIO interrupt IRQ function name
#define PININT2_NVIC_NAME PIN_INT2_IRQn // GPIO interrupt NVIC interrupt name

/*! \var QueueHandle_t xEncoderChoiceMailbox
\brief Mailbox con la selección actual de motor mediante
pulsador de encoder.
*/
extern QueueHandle_t xEncoderChoiceMailbox;

/*! \fn BaseType_t xEncoderInit( void )
\brief Inicialización de encoder rotativo de la aplicación.
*/
Expand Down
2 changes: 1 addition & 1 deletion app/inc/stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/*! \def stepperAPP_NUM
\brief Cantidad de motores en la aplicación
*/
#define stepperAPP_NUM 3
#define stepperAPP_NUM 2

/*! \def stepperTIMER_PERIOD
\brief Periodo de pasos de los motores (velocidad del motor)
Expand Down
9 changes: 9 additions & 0 deletions app/inc/uart.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*! \file uart.h
\brief Descripción del archivo.
\author Gonzalo G. Fernández
\version 1.0
\date Julio 2020

Detalle.
*/

#ifndef UART_H
#define UART_H

Expand Down
41 changes: 16 additions & 25 deletions app/src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,23 @@
#include "FreeRTOSConfig.h"
#include "FreeRTOSPriorities.h"
#include "task.h"
#include "queue.h"

/* EDU-CIAA firmware_v3 includes */
#include "sapi.h"

/* Aplicación includes */
#include "uart.h"
#include "buffer.h"
#include "encoder.h"
#include "stepper.h"
#include "servo.h"

/*! \def appQUEUE_MSG_LENGTH
\brief Longitud de cola de mensajes recibidos.
*/
#define appQUEUE_MSG_LENGTH 50
#include "display_lcd.h"

/*! \var TaskHandle_t xAppSyncTaskHandle
\brief Handle de la tarea que sincroniza mensajes.
*/
TaskHandle_t xAppSyncTaskHandle = NULL;

/*! \var QueueHandle_t xMsgQueue
\brief Cola de mensajes recibidos.
*/
QueueHandle_t xMsgQueue;

/*! \fn vErrorNotifHandling( uint32_t ulNotifError )
\brief Gestió de errores obtenidos por notificación de tarea.
*/
Expand Down Expand Up @@ -70,7 +61,7 @@ void vErrorNotifHandling( uint32_t ulNotifError )
}
}

/*! \fn vAppSyncTask( void *pvParameters )
/*! \fn void vAppSyncTask( void *pvParameters )
\brief Tarea de sincronización de mensajes.
*/
void vAppSyncTask( void *pvParameters )
Expand All @@ -83,15 +74,9 @@ void vAppSyncTask( void *pvParameters )
char *pcErrorMsg = "Error en mensaje previo";

for ( ;; ) {
xQueueReceive(
/* Handle de la cola a leer */
xMsgQueue,
/* Puntero a la memoria donde guardar lectura */
&pcMsgReceived,
/* Máximo tiempo que la tarea puede estar bloqueada
esperando que haya información a leer */
portMAX_DELAY
);
printf("APP");
/* Lectura de mensaje recibido */
vBufferReadMsg( pcMsgReceived );

/* Verificación de inicio de trama */
if ( pcMsgReceived[0] != ':' ) {
Expand Down Expand Up @@ -124,6 +109,7 @@ void vAppSyncTask( void *pvParameters )
void vLedBlinkTask( void *pvParameters )
{
for ( ;; ) {
printf("BLINK");
/* Indicador en LED1 */
gpioToggle( LED1 );
/* Parpadeo de medio segundo */
Expand Down Expand Up @@ -174,10 +160,15 @@ int main( void )
/* Obtener información del espacio libre */
xPreviousSize = xPrintModuleSize( "Servo", xPreviousSize);

/* Creación de cola de mensajes recibidos */
xMsgQueue = xQueueCreate( appQUEUE_MSG_LENGTH, sizeof( char * ) );
/* Verificación de cola creada con éxito */
configASSERT( xMsgQueue != NULL );
/* Inicialización de display LCD */
xStatus = xDisplayInit(); configASSERT( xStatus == pdPASS );
xPreviousSize = xPrintModuleSize( "Display", xPreviousSize);

/* Creación de buffer circular para los mensajes de la aplicación */
xStatus = xBufferCreate(); configASSERT( xStatus == pdPASS );
xPreviousSize = xPrintModuleSize( "Buffer", xPreviousSize);

printf( "Espacio disponible: %d\n", xPreviousSize );

/* Creación de tarea de control de flujo de trabajo del programa */
xStatus = xTaskCreate(
Expand Down
Loading