diff --git a/examples/freertos/inc/FreeRTOSConfig.h b/examples/freertos/delay_until/inc/FreeRTOSConfig.h similarity index 100% rename from examples/freertos/inc/FreeRTOSConfig.h rename to examples/freertos/delay_until/inc/FreeRTOSConfig.h diff --git a/examples/freertos/inc/bsp.h b/examples/freertos/delay_until/inc/bsp.h similarity index 100% rename from examples/freertos/inc/bsp.h rename to examples/freertos/delay_until/inc/bsp.h diff --git a/examples/freertos/delay_until/makefile b/examples/freertos/delay_until/makefile new file mode 100644 index 0000000..a5e0b48 --- /dev/null +++ b/examples/freertos/delay_until/makefile @@ -0,0 +1,30 @@ +################################################################################################## +# Copyright (c) 2022-2023, Laboratorio de Microprocesadores +# Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +# https://www.microprocesadores.unt.edu.ar/ +# +# Copyright (c) 2022-2023, Esteban Volentini +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +# associated documentation files (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, publish, distribute, +# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial +# portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT +################################################################################################## + +BOARD := edu-ciaa-nxp +MUJU := ../../.. +MODULES := module/hal module/freertos + +include $(MUJU)/module/base/makefile diff --git a/examples/freertos/src/bsp.c b/examples/freertos/delay_until/src/bsp.c similarity index 100% rename from examples/freertos/src/bsp.c rename to examples/freertos/delay_until/src/bsp.c diff --git a/examples/freertos/delay_until/src/main.c b/examples/freertos/delay_until/src/main.c new file mode 100644 index 0000000..3753240 --- /dev/null +++ b/examples/freertos/delay_until/src/main.c @@ -0,0 +1,143 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** @file + ** @brief Simple sample of use FreeROTS with MUJU hal functions + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#include "bsp.h" +#include "FreeRTOS.h" +#include "task.h" +#include "event_groups.h" + +/* === Macros definitions ====================================================================== */ + +#define EVENT_TEC1_ON (1 << 0) +#define EVENT_TEC2_ON (1 << 1) +#define EVENT_TEC3_ON (1 << 2) +#define EVENT_TEC4_ON (1 << 3) + +#define EVENT_TEC1_OFF (1 << 4) +#define EVENT_TEC2_OFF (1 << 5) +#define EVENT_TEC3_OFF (1 << 6) +#define EVENT_TEC4_OFF (1 << 7) + +/* === Private data type declarations ========================================================== */ + +typedef struct flash_options_s { + hal_gpio_bit_t led; + uint32_t delay; +} * flash_options_s; + +/* === Private variable declarations =========================================================== */ + +/* === Private function declarations =========================================================== */ + +/** + * @brief Function to flash a led for a while + * + * @param object Pointer to task parameters structure, used as parameter when task created + */ +static void FlashTask(void * object); + +/** + * @brief Function to scan keyboard and send events to another tasks + * + * @param gpio Gpio input used by the key that rise event + * @param rissing Flag to indicate if is an rissing edge or and falling edge + * @param data Pointer to board structure, used as parameter when handler installed + */ +static void KeyboardTask(void * object); + +/* === Public variable definitions ============================================================= */ + +/* === Private variable definitions ============================================================ */ + +/** + * @brief Events group to comunicate key actions + */ +EventGroupHandle_t key_events; + +/* === Private function implementation ========================================================= */ + +static void FlashTask(void * object) { + flash_options_s options = object; + TickType_t last_value = xTaskGetTickCount(); + + while (true) { + GpioBitSet(options->led); + vTaskDelay(pdMS_TO_TICKS(options->delay)); + GpioBitClear(options->led); + xTaskDelayUntil(&last_value, pdMS_TO_TICKS(1000)); + // vTaskDelay(pdMS_TO_TICKS(500)); + } + vTaskDelete(NULL); +} + +static void KeyboardTask(void * object) { +} + +/* === Public function implementation ========================================================= */ + +int main(void) { + static struct flash_options_s flash_options[3]; + + /* Inicializaciones y configuraciones de dispositivos */ + board_t board = BoardCreate(); + + flash_options[0].led = board->led_1; + flash_options[0].delay = 500; + + flash_options[1].led = board->led_2; + flash_options[1].delay = 250; + + flash_options[2].led = board->led_3; + flash_options[2].delay = 750; + + /* Creación de las tareas */ + xTaskCreate(FlashTask, "RedTask", 256, &flash_options[0], tskIDLE_PRIORITY + 3, NULL); + xTaskCreate(FlashTask, "YellowTask", 256, &flash_options[1], tskIDLE_PRIORITY + 2, NULL); + xTaskCreate(FlashTask, "GreenTask", 256, &flash_options[2], tskIDLE_PRIORITY + 1, NULL); + + /* Arranque del sistema operativo */ + vTaskStartScheduler(); + + /* vTaskStartScheduler solo retorna si se detiene el sistema operativo */ + while (true) { + } + + /* El valor de retorno es solo para evitar errores en el compilador*/ + return 0; +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/freertos/events/inc/FreeRTOSConfig.h b/examples/freertos/events/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..cb2cbfd --- /dev/null +++ b/examples/freertos/events/inc/FreeRTOSConfig.h @@ -0,0 +1,171 @@ +/* + * FreeRTOS Kernel V10.2.0 + * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + */ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +#include + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html + *----------------------------------------------------------*/ + +/* clang-format off */ + +#define configSUPPORT_STATIC_ALLOCATION 0 + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICKLESS_IDLE 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ (SystemCoreClock) +#define configTICK_RATE_HZ ((TickType_t)1000) // 1000 ticks per second => 1ms tick rate +#define configMAX_PRIORITIES (15) +#define configMINIMAL_STACK_SIZE ((uint16_t)128) +#define configAPPLICATION_ALLOCATED_HEAP 0 +#define configTOTAL_HEAP_SIZE ((size_t)(16 * 1024)) /* 16 Kbytes. */ +#define configMAX_TASK_NAME_LEN (16) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES (2) + +/* Software timer definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 3) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 4) + +/* Set the following definitions to 1 to include the API function, or zero + * to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_xSemaphoreGetMutexHolder 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS +/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ +#define configPRIO_BITS __NVIC_PRIO_BITS +#else +#define configPRIO_BITS 3 /* 8 priority levels. */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" + * function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY ((1 << configPRIO_BITS) - 1) + +/* The highest interrupt priority that can be used by any interrupt service + * routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL + * INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER + * PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 + +/* Interrupt priorities used by the kernel port layer itself. These are generic + * to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY \ + (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) + +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! + * See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY \ + (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) + +/* Normal assert() semantics without relying on the provision of an assert.h + * header file. */ +#define configASSERT(x) \ + if ((x) == 0) { \ + taskDISABLE_INTERRUPTS(); \ + for (;;) { \ + ; \ + } \ + } + +/* Map the FreeRTOS printf() to the logging task printf. */ +#define configPRINTF(x) vLoggingPrintf x + +/* Map the logging task's printf to the board specific output function. */ +#define configPRINT_STRING DbgConsole_Printf + +/* Sets the length of the buffers into which logging messages are written - so + * also defines the maximum length of each log message. */ +#define configLOGGING_MAX_MESSAGE_LENGTH 100 + +/* Set to 1 to prepend each log message with a message number, the task name, + * and a time stamp. */ +#define configLOGGING_INCLUDE_TIME_AND_TASK_NAME 1 + +/* Demo specific macros that allow the application writer to insert code to be + * executed immediately before the MCU's STOP low power mode is entered and exited + * respectively. These macros are in addition to the standard + * configPRE_SLEEP_PROCESSING() and configPOST_SLEEP_PROCESSING() macros, which are + * called pre and post the low power SLEEP mode being entered and exited. These + * macros can be used to turn turn off and on IO, clocks, the Flash etc. to obtain + * the lowest power possible while the tick is off. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) +void vMainPreStopProcessing(void); +void vMainPostStopProcessing(void); +#endif /* defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) */ + +#define configPRE_STOP_PROCESSING vMainPreStopProcessing +#define configPOST_STOP_PROCESSING vMainPostStopProcessing + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS + * standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler +#define xPortSysTickHandler SysTick_Handler +#define vHardFault_Handler HardFault_Handler + +/* IMPORTANT: This define MUST be commented when used with STM32Cube firmware, + * to prevent overwriting SysTick_Handler defined within STM32Cube HAL. */ +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ diff --git a/examples/freertos/events/inc/bsp.h b/examples/freertos/events/inc/bsp.h new file mode 100644 index 0000000..f1b05d2 --- /dev/null +++ b/examples/freertos/events/inc/bsp.h @@ -0,0 +1,94 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +#ifndef BSP_H +#define BSP_H + +/** @file + ** @brief Board support hardware abstraction layer declarations + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions ================================================================ */ + +#include "hal.h" + +/* === Cabecera C++ ============================================================================ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* === Public macros definitions =============================================================== */ + +/* === Public data type declarations =========================================================== */ + +/** + * @brief Structure with gpio outputs to drive an RGB led + */ +typedef struct led_rgb_s { + hal_gpio_bit_t red; /**< Gpio output used to drive red channel of RGB led */ + hal_gpio_bit_t green; /**< Gpio output used to drive green channel of RGB led */ + hal_gpio_bit_t blue; /**< Gpio output used to drive blue channel of RGB led */ +} const * const led_rgb_t; + +/** + * @brief Structure with gpio terminals usted by board + */ +typedef struct board_s { + struct led_rgb_s led_rgb[1]; /**< Structure with gpio output used by RGB led */ + hal_gpio_bit_t led_1; /**< Gpio output used to drive led 1 on board */ + hal_gpio_bit_t led_2; /**< Gpio output used to drive led 2 on board */ + hal_gpio_bit_t led_3; /**< Gpio output used to drive led 3 on board */ + hal_gpio_bit_t tec_1; /**< Gpio output used to read status of key 1 on board */ + hal_gpio_bit_t tec_2; /**< Gpio output used to read status of key 2 on board */ + hal_gpio_bit_t tec_3; /**< Gpio output used to read status of key 3 on board */ + hal_gpio_bit_t tec_4; /**< Gpio output used to read status of key 4 on board */ + hal_sci_t console; /**< Serial port used as console on board */ +} const * const board_t; + +/* === Public variable declarations ============================================================ */ + +/* === Public function declarations ============================================================ */ + +/** + * @brief Function to initialize the board and create an descriptor to his resources + * + * @return board_t Pointer to descriptor with board resources + */ +board_t BoardCreate(void); + +/* === End of documentation ==================================================================== */ + +#ifdef __cplusplus +} +#endif + +/** @} End of module definition for doxygen */ + +#endif /* BSP_H */ diff --git a/examples/freertos/events/makefile b/examples/freertos/events/makefile new file mode 100644 index 0000000..f7b3118 --- /dev/null +++ b/examples/freertos/events/makefile @@ -0,0 +1,31 @@ +################################################################################################## +# Copyright (c) 2022-2023, Laboratorio de Microprocesadores +# Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +# https://www.microprocesadores.unt.edu.ar/ +# +# Copyright (c) 2022-2023, Esteban Volentini +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +# associated documentation files (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, publish, distribute, +# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial +# portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT +################################################################################################## + +MUJU ?= ../../.. +BUILD_DIR := $(MUJU)/build +MODULES := module/hal module/freertos +BOARD ?= edu-ciaa-nxp + +include $(MUJU)/module/base/makefile diff --git a/examples/freertos/events/src/bsp.c b/examples/freertos/events/src/bsp.c new file mode 100644 index 0000000..943b344 --- /dev/null +++ b/examples/freertos/events/src/bsp.c @@ -0,0 +1,132 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** @file + ** @brief Board support hardware abstraction layer implementation + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#include "bsp.h" +#include "board.h" +#include + +/* === Macros definitions ====================================================================== */ + +/* === Private data type declarations ========================================================== */ + +/* === Private variable declarations =========================================================== */ + +/* === Private function declarations =========================================================== */ + +/* === Public variable definitions ============================================================= */ + +/* === Private variable definitions ============================================================ */ + +/* === Private function implementation ========================================================= */ + +static board_t AssignResources(struct hal_sci_pins_s * console_pins) { + static struct board_s board = {0}; + +#ifdef EDU_CIAA_NXP + board.led_rgb[0].red = HAL_GPIO5_0; + board.led_rgb[0].green = HAL_GPIO5_1; + board.led_rgb[0].blue = HAL_GPIO5_2; + + board.led_1 = HAL_GPIO0_14; + board.led_2 = HAL_GPIO1_11; + board.led_3 = HAL_GPIO1_12; + + board.tec_1 = HAL_GPIO0_4; + board.tec_2 = HAL_GPIO0_8; + board.tec_3 = HAL_GPIO0_9; + board.tec_4 = HAL_GPIO1_9; + + board.console = HAL_SCI_USART2; + console_pins->txd_pin = HAL_PIN_P7_1; + console_pins->rxd_pin = HAL_PIN_P7_2; +#elif BLUE_PILL + board.led_2 = HAL_GPIO_PB9; + board.tec_3 = HAL_GPIO_PB13; + + board.console = HAL_SCI_USART1; + console_pins->txd_pin = HAL_PIN_PA9; + console_pins->rxd_pin = HAL_PIN_PA10; +#elif POSIX + board.led_rgb[0].red = HAL_GPIO3_7; + board.led_rgb[0].green = HAL_GPIO3_6; + board.led_rgb[0].blue = HAL_GPIO3_5; + + board.led_1 = HAL_GPIO3_2; + board.led_2 = HAL_GPIO3_1; + board.led_3 = HAL_GPIO3_0; + + board.tec_1 = HAL_GPIO0_0; + board.tec_2 = HAL_GPIO0_1; + board.tec_3 = HAL_GPIO0_2; + board.tec_4 = HAL_GPIO0_3; +#else +#error "This program does not have support for the selected board" +#endif + return (board_t)&board; +} + +/* === Public function implementation ========================================================= */ + +board_t BoardCreate(void) { + static const struct hal_sci_line_s console_config = { + .baud_rate = 115200, + .data_bits = 8, + .parity = HAL_SCI_NO_PARITY, + }; + struct hal_sci_pins_s console_pins = {0}; + + BoardSetup(); + board_t board = AssignResources(&console_pins); + + GpioSetDirection(board->led_rgb->red, true); + GpioSetDirection(board->led_rgb->green, true); + GpioSetDirection(board->led_rgb->blue, true); + + GpioSetDirection(board->led_1, true); + GpioSetDirection(board->led_2, true); + GpioSetDirection(board->led_3, true); + + GpioSetDirection(board->tec_1, false); + GpioSetDirection(board->tec_2, false); + GpioSetDirection(board->tec_3, false); + GpioSetDirection(board->tec_4, false); + + SciSetConfig(board->console, &console_config, &console_pins); + return board; +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/freertos/events/src/main.c b/examples/freertos/events/src/main.c new file mode 100644 index 0000000..be7d83a --- /dev/null +++ b/examples/freertos/events/src/main.c @@ -0,0 +1,208 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** @file + ** @brief Simple sample of use FreeROTS with MUJU hal functions + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#include "bsp.h" +#include "FreeRTOS.h" +#include "task.h" +#include "event_groups.h" + +/* === Macros definitions ====================================================================== */ + +#define EVENT_TEC1_ON (1 << 0) +#define EVENT_TEC2_ON (1 << 1) +#define EVENT_TEC3_ON (1 << 2) +#define EVENT_TEC4_ON (1 << 3) + +#define EVENT_TEC1_OFF (1 << 4) +#define EVENT_TEC2_OFF (1 << 5) +#define EVENT_TEC3_OFF (1 << 6) +#define EVENT_TEC4_OFF (1 << 7) + +/* === Private data type declarations ========================================================== */ + +typedef struct flash_s { + uint8_t key; + hal_gpio_bit_t led; + uint32_t delay; +} * flash_s; + +/* === Private variable declarations =========================================================== */ + +/* === Private function declarations =========================================================== */ + +/** + * @brief Function to inform an error and stop program execution + * + * @param board Pointer to board descriptor + * @param code Code of error ocurred + */ +void StopByError(board_t board, uint8_t code); + +/** + * @brief Function to flash a led for a while + * + * @param object Pointer to task parameters structure, used as parameter when task created + */ +static void FlashTask(void * object); + +/** + * @brief Function to scan keyboard and send events to another tasks + * + * @param object Pointer to board descriptor, used as parameter when task created + */ +static void KeyTask(void * object); + +/* === Public variable definitions ============================================================= */ + +/* === Private variable definitions ============================================================ */ + +/** + * @brief Events group to comunicate key actions + */ +EventGroupHandle_t key_events; + +/* === Private function implementation ========================================================= */ + +void StopByError(board_t board, uint8_t code) { + // Signal error condition + GpioBitSet(board->led_rgb->red); + + // Show error code + GpioSetState(board->led_1, code & (1 << 0)); + GpioSetState(board->led_2, code & (1 << 1)); + GpioSetState(board->led_3, code & (1 << 2)); + + // Stop program execution + while (true) { + }; +} + +static void FlashTask(void * object) { + flash_s options = object; + // TickType_t last_value = xTaskGetTickCount(); + + while (true) { + xEventGroupWaitBits(key_events, options->key, TRUE, FALSE, portMAX_DELAY); + + GpioBitSet(options->led); + vTaskDelay(pdMS_TO_TICKS(options->delay)); + GpioBitClear(options->led); + vTaskDelay(pdMS_TO_TICKS(options->delay)); + // xTaskDelayUntil(&last_value, pdMS_TO_TICKS(1000)); + } +} + +static void KeyTask(void * object) { + board_t board = object; + uint8_t last_state, current_state, changes, events; + + while (true) { + vTaskDelay(pdMS_TO_TICKS(150)); + + current_state = 0; + if (!GpioGetState(board->tec_1)) { + current_state |= EVENT_TEC1_ON; + }; + if (!GpioGetState(board->tec_2)) { + current_state |= EVENT_TEC2_ON; + }; + if (!GpioGetState(board->tec_3)) { + current_state |= EVENT_TEC3_ON; + }; + if (!GpioGetState(board->tec_4)) { + current_state |= EVENT_TEC4_ON; + }; + + changes = current_state ^ last_state; + last_state = current_state; + events = ((changes & !current_state) << 4) | (changes & current_state); + + xEventGroupSetBits(key_events, events); + } +} + +/* === Public function implementation ========================================================= */ + +int main(void) { + static struct flash_s flash[3]; + + /* Inicializaciones y configuraciones de dispositivos */ + board_t board = BoardCreate(); + + flash[0].key = EVENT_TEC2_ON | EVENT_TEC1_OFF; + flash[0].led = board->led_1; + flash[0].delay = 500; + + flash[1].key = EVENT_TEC3_ON; + flash[1].led = board->led_2; + flash[1].delay = 250; + + flash[2].key = EVENT_TEC4_ON; + flash[2].led = board->led_3; + flash[2].delay = 750; + + key_events = xEventGroupCreate(); + if (key_events == NULL) { + StopByError(board, 0); + } + + /* Creación de las tareas */ + if (xTaskCreate(KeyTask, "Keys", 256, (void *)board, tskIDLE_PRIORITY + 2, NULL) != pdPASS) { + StopByError(board, 1); + } + if (xTaskCreate(FlashTask, "Red", 256, &flash[0], tskIDLE_PRIORITY + 1, NULL) != pdPASS) { + StopByError(board, 2); + } + if (xTaskCreate(FlashTask, "Yellow", 256, &flash[1], tskIDLE_PRIORITY + 1, NULL) != pdPASS) { + StopByError(board, 3); + } + if (xTaskCreate(FlashTask, "Green", 256, &flash[2], tskIDLE_PRIORITY + 1, NULL) != pdPASS) { + StopByError(board, 4); + } + + /* Arranque del sistema operativo */ + vTaskStartScheduler(); + + /* vTaskStartScheduler solo retorna si se detiene el sistema operativo */ + while (true) { + } + + /* El valor de retorno es solo para evitar errores en el compilador*/ + return 0; +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/freertos/hal/inc/FreeRTOSConfig.h b/examples/freertos/hal/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..cb2cbfd --- /dev/null +++ b/examples/freertos/hal/inc/FreeRTOSConfig.h @@ -0,0 +1,171 @@ +/* + * FreeRTOS Kernel V10.2.0 + * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + */ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +#include + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html + *----------------------------------------------------------*/ + +/* clang-format off */ + +#define configSUPPORT_STATIC_ALLOCATION 0 + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICKLESS_IDLE 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ (SystemCoreClock) +#define configTICK_RATE_HZ ((TickType_t)1000) // 1000 ticks per second => 1ms tick rate +#define configMAX_PRIORITIES (15) +#define configMINIMAL_STACK_SIZE ((uint16_t)128) +#define configAPPLICATION_ALLOCATED_HEAP 0 +#define configTOTAL_HEAP_SIZE ((size_t)(16 * 1024)) /* 16 Kbytes. */ +#define configMAX_TASK_NAME_LEN (16) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES (2) + +/* Software timer definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 3) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 4) + +/* Set the following definitions to 1 to include the API function, or zero + * to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_xSemaphoreGetMutexHolder 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS +/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ +#define configPRIO_BITS __NVIC_PRIO_BITS +#else +#define configPRIO_BITS 3 /* 8 priority levels. */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" + * function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY ((1 << configPRIO_BITS) - 1) + +/* The highest interrupt priority that can be used by any interrupt service + * routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL + * INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER + * PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 + +/* Interrupt priorities used by the kernel port layer itself. These are generic + * to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY \ + (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) + +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! + * See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY \ + (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) + +/* Normal assert() semantics without relying on the provision of an assert.h + * header file. */ +#define configASSERT(x) \ + if ((x) == 0) { \ + taskDISABLE_INTERRUPTS(); \ + for (;;) { \ + ; \ + } \ + } + +/* Map the FreeRTOS printf() to the logging task printf. */ +#define configPRINTF(x) vLoggingPrintf x + +/* Map the logging task's printf to the board specific output function. */ +#define configPRINT_STRING DbgConsole_Printf + +/* Sets the length of the buffers into which logging messages are written - so + * also defines the maximum length of each log message. */ +#define configLOGGING_MAX_MESSAGE_LENGTH 100 + +/* Set to 1 to prepend each log message with a message number, the task name, + * and a time stamp. */ +#define configLOGGING_INCLUDE_TIME_AND_TASK_NAME 1 + +/* Demo specific macros that allow the application writer to insert code to be + * executed immediately before the MCU's STOP low power mode is entered and exited + * respectively. These macros are in addition to the standard + * configPRE_SLEEP_PROCESSING() and configPOST_SLEEP_PROCESSING() macros, which are + * called pre and post the low power SLEEP mode being entered and exited. These + * macros can be used to turn turn off and on IO, clocks, the Flash etc. to obtain + * the lowest power possible while the tick is off. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) +void vMainPreStopProcessing(void); +void vMainPostStopProcessing(void); +#endif /* defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) */ + +#define configPRE_STOP_PROCESSING vMainPreStopProcessing +#define configPOST_STOP_PROCESSING vMainPostStopProcessing + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS + * standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler +#define xPortSysTickHandler SysTick_Handler +#define vHardFault_Handler HardFault_Handler + +/* IMPORTANT: This define MUST be commented when used with STM32Cube firmware, + * to prevent overwriting SysTick_Handler defined within STM32Cube HAL. */ +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ diff --git a/examples/freertos/hal/inc/bsp.h b/examples/freertos/hal/inc/bsp.h new file mode 100644 index 0000000..f1b05d2 --- /dev/null +++ b/examples/freertos/hal/inc/bsp.h @@ -0,0 +1,94 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +#ifndef BSP_H +#define BSP_H + +/** @file + ** @brief Board support hardware abstraction layer declarations + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions ================================================================ */ + +#include "hal.h" + +/* === Cabecera C++ ============================================================================ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* === Public macros definitions =============================================================== */ + +/* === Public data type declarations =========================================================== */ + +/** + * @brief Structure with gpio outputs to drive an RGB led + */ +typedef struct led_rgb_s { + hal_gpio_bit_t red; /**< Gpio output used to drive red channel of RGB led */ + hal_gpio_bit_t green; /**< Gpio output used to drive green channel of RGB led */ + hal_gpio_bit_t blue; /**< Gpio output used to drive blue channel of RGB led */ +} const * const led_rgb_t; + +/** + * @brief Structure with gpio terminals usted by board + */ +typedef struct board_s { + struct led_rgb_s led_rgb[1]; /**< Structure with gpio output used by RGB led */ + hal_gpio_bit_t led_1; /**< Gpio output used to drive led 1 on board */ + hal_gpio_bit_t led_2; /**< Gpio output used to drive led 2 on board */ + hal_gpio_bit_t led_3; /**< Gpio output used to drive led 3 on board */ + hal_gpio_bit_t tec_1; /**< Gpio output used to read status of key 1 on board */ + hal_gpio_bit_t tec_2; /**< Gpio output used to read status of key 2 on board */ + hal_gpio_bit_t tec_3; /**< Gpio output used to read status of key 3 on board */ + hal_gpio_bit_t tec_4; /**< Gpio output used to read status of key 4 on board */ + hal_sci_t console; /**< Serial port used as console on board */ +} const * const board_t; + +/* === Public variable declarations ============================================================ */ + +/* === Public function declarations ============================================================ */ + +/** + * @brief Function to initialize the board and create an descriptor to his resources + * + * @return board_t Pointer to descriptor with board resources + */ +board_t BoardCreate(void); + +/* === End of documentation ==================================================================== */ + +#ifdef __cplusplus +} +#endif + +/** @} End of module definition for doxygen */ + +#endif /* BSP_H */ diff --git a/examples/freertos/hal/src/bsp.c b/examples/freertos/hal/src/bsp.c new file mode 100644 index 0000000..943b344 --- /dev/null +++ b/examples/freertos/hal/src/bsp.c @@ -0,0 +1,132 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** @file + ** @brief Board support hardware abstraction layer implementation + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#include "bsp.h" +#include "board.h" +#include + +/* === Macros definitions ====================================================================== */ + +/* === Private data type declarations ========================================================== */ + +/* === Private variable declarations =========================================================== */ + +/* === Private function declarations =========================================================== */ + +/* === Public variable definitions ============================================================= */ + +/* === Private variable definitions ============================================================ */ + +/* === Private function implementation ========================================================= */ + +static board_t AssignResources(struct hal_sci_pins_s * console_pins) { + static struct board_s board = {0}; + +#ifdef EDU_CIAA_NXP + board.led_rgb[0].red = HAL_GPIO5_0; + board.led_rgb[0].green = HAL_GPIO5_1; + board.led_rgb[0].blue = HAL_GPIO5_2; + + board.led_1 = HAL_GPIO0_14; + board.led_2 = HAL_GPIO1_11; + board.led_3 = HAL_GPIO1_12; + + board.tec_1 = HAL_GPIO0_4; + board.tec_2 = HAL_GPIO0_8; + board.tec_3 = HAL_GPIO0_9; + board.tec_4 = HAL_GPIO1_9; + + board.console = HAL_SCI_USART2; + console_pins->txd_pin = HAL_PIN_P7_1; + console_pins->rxd_pin = HAL_PIN_P7_2; +#elif BLUE_PILL + board.led_2 = HAL_GPIO_PB9; + board.tec_3 = HAL_GPIO_PB13; + + board.console = HAL_SCI_USART1; + console_pins->txd_pin = HAL_PIN_PA9; + console_pins->rxd_pin = HAL_PIN_PA10; +#elif POSIX + board.led_rgb[0].red = HAL_GPIO3_7; + board.led_rgb[0].green = HAL_GPIO3_6; + board.led_rgb[0].blue = HAL_GPIO3_5; + + board.led_1 = HAL_GPIO3_2; + board.led_2 = HAL_GPIO3_1; + board.led_3 = HAL_GPIO3_0; + + board.tec_1 = HAL_GPIO0_0; + board.tec_2 = HAL_GPIO0_1; + board.tec_3 = HAL_GPIO0_2; + board.tec_4 = HAL_GPIO0_3; +#else +#error "This program does not have support for the selected board" +#endif + return (board_t)&board; +} + +/* === Public function implementation ========================================================= */ + +board_t BoardCreate(void) { + static const struct hal_sci_line_s console_config = { + .baud_rate = 115200, + .data_bits = 8, + .parity = HAL_SCI_NO_PARITY, + }; + struct hal_sci_pins_s console_pins = {0}; + + BoardSetup(); + board_t board = AssignResources(&console_pins); + + GpioSetDirection(board->led_rgb->red, true); + GpioSetDirection(board->led_rgb->green, true); + GpioSetDirection(board->led_rgb->blue, true); + + GpioSetDirection(board->led_1, true); + GpioSetDirection(board->led_2, true); + GpioSetDirection(board->led_3, true); + + GpioSetDirection(board->tec_1, false); + GpioSetDirection(board->tec_2, false); + GpioSetDirection(board->tec_3, false); + GpioSetDirection(board->tec_4, false); + + SciSetConfig(board->console, &console_config, &console_pins); + return board; +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/freertos/src/main.c b/examples/freertos/hal/src/main.c similarity index 100% rename from examples/freertos/src/main.c rename to examples/freertos/hal/src/main.c diff --git a/examples/freertos/interrupts/inc/FreeRTOSConfig.h b/examples/freertos/interrupts/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..cb2cbfd --- /dev/null +++ b/examples/freertos/interrupts/inc/FreeRTOSConfig.h @@ -0,0 +1,171 @@ +/* + * FreeRTOS Kernel V10.2.0 + * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + */ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +#include + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html + *----------------------------------------------------------*/ + +/* clang-format off */ + +#define configSUPPORT_STATIC_ALLOCATION 0 + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICKLESS_IDLE 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ (SystemCoreClock) +#define configTICK_RATE_HZ ((TickType_t)1000) // 1000 ticks per second => 1ms tick rate +#define configMAX_PRIORITIES (15) +#define configMINIMAL_STACK_SIZE ((uint16_t)128) +#define configAPPLICATION_ALLOCATED_HEAP 0 +#define configTOTAL_HEAP_SIZE ((size_t)(16 * 1024)) /* 16 Kbytes. */ +#define configMAX_TASK_NAME_LEN (16) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES (2) + +/* Software timer definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 3) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 4) + +/* Set the following definitions to 1 to include the API function, or zero + * to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_xSemaphoreGetMutexHolder 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS +/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ +#define configPRIO_BITS __NVIC_PRIO_BITS +#else +#define configPRIO_BITS 3 /* 8 priority levels. */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" + * function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY ((1 << configPRIO_BITS) - 1) + +/* The highest interrupt priority that can be used by any interrupt service + * routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL + * INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER + * PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 + +/* Interrupt priorities used by the kernel port layer itself. These are generic + * to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY \ + (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) + +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! + * See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY \ + (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) + +/* Normal assert() semantics without relying on the provision of an assert.h + * header file. */ +#define configASSERT(x) \ + if ((x) == 0) { \ + taskDISABLE_INTERRUPTS(); \ + for (;;) { \ + ; \ + } \ + } + +/* Map the FreeRTOS printf() to the logging task printf. */ +#define configPRINTF(x) vLoggingPrintf x + +/* Map the logging task's printf to the board specific output function. */ +#define configPRINT_STRING DbgConsole_Printf + +/* Sets the length of the buffers into which logging messages are written - so + * also defines the maximum length of each log message. */ +#define configLOGGING_MAX_MESSAGE_LENGTH 100 + +/* Set to 1 to prepend each log message with a message number, the task name, + * and a time stamp. */ +#define configLOGGING_INCLUDE_TIME_AND_TASK_NAME 1 + +/* Demo specific macros that allow the application writer to insert code to be + * executed immediately before the MCU's STOP low power mode is entered and exited + * respectively. These macros are in addition to the standard + * configPRE_SLEEP_PROCESSING() and configPOST_SLEEP_PROCESSING() macros, which are + * called pre and post the low power SLEEP mode being entered and exited. These + * macros can be used to turn turn off and on IO, clocks, the Flash etc. to obtain + * the lowest power possible while the tick is off. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) +void vMainPreStopProcessing(void); +void vMainPostStopProcessing(void); +#endif /* defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) */ + +#define configPRE_STOP_PROCESSING vMainPreStopProcessing +#define configPOST_STOP_PROCESSING vMainPostStopProcessing + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS + * standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler +#define xPortSysTickHandler SysTick_Handler +#define vHardFault_Handler HardFault_Handler + +/* IMPORTANT: This define MUST be commented when used with STM32Cube firmware, + * to prevent overwriting SysTick_Handler defined within STM32Cube HAL. */ +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ diff --git a/examples/freertos/interrupts/inc/bsp.h b/examples/freertos/interrupts/inc/bsp.h new file mode 100644 index 0000000..d99f3ad --- /dev/null +++ b/examples/freertos/interrupts/inc/bsp.h @@ -0,0 +1,94 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +#ifndef BSP_H +#define BSP_H + +/** @file + ** @brief Board support hardware abstraction layer declarations + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions ================================================================ */ + +#include "hal.h" + +/* === Cabecera C++ ============================================================================ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* === Public macros definitions =============================================================== */ + +/* === Public data type declarations =========================================================== */ + +/** + * @brief Structure with gpio outputs to drive an RGB led + */ +typedef struct led_rgb_s { + hal_gpio_bit_t red; /**< Gpio output used to drive red channel of RGB led */ + hal_gpio_bit_t green; /**< Gpio output used to drive green channel of RGB led */ + hal_gpio_bit_t blue; /**< Gpio output used to drive blue channel of RGB led */ +} * const led_rgb_t; + +/** + * @brief Structure with gpio terminals usted by board + */ +typedef struct board_s { + struct led_rgb_s led_rgb[1]; /**< Structure with gpio output used by RGB led */ + hal_gpio_bit_t led_1; /**< Gpio output used to drive led 1 on board */ + hal_gpio_bit_t led_2; /**< Gpio output used to drive led 2 on board */ + hal_gpio_bit_t led_3; /**< Gpio output used to drive led 3 on board */ + hal_gpio_bit_t tec_1; /**< Gpio output used to read status of key 1 on board */ + hal_gpio_bit_t tec_2; /**< Gpio output used to read status of key 2 on board */ + hal_gpio_bit_t tec_3; /**< Gpio output used to read status of key 3 on board */ + hal_gpio_bit_t tec_4; /**< Gpio output used to read status of key 4 on board */ + hal_sci_t console; /**< Serial port used as console on board */ +} const * board_t; + +/* === Public variable declarations ============================================================ */ + +/* === Public function declarations ============================================================ */ + +/** + * @brief Function to initialize the board and create an descriptor to his resources + * + * @return board_t Pointer to descriptor with board resources + */ +board_t BoardCreate(void); + +/* === End of documentation ==================================================================== */ + +#ifdef __cplusplus +} +#endif + +/** @} End of module definition for doxygen */ + +#endif /* BSP_H */ diff --git a/examples/freertos/interrupts/inc/keyboard.h b/examples/freertos/interrupts/inc/keyboard.h new file mode 100644 index 0000000..850e9f3 --- /dev/null +++ b/examples/freertos/interrupts/inc/keyboard.h @@ -0,0 +1,93 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +#ifndef KEYBOARD_H +#define KEYBOARD_H + +/** @file + ** @brief Board support hardware abstraction layer declarations + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions ================================================================ */ + +#include "bsp.h" + +/* === Cabecera C++ ============================================================================ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* === Public macros definitions =============================================================== */ + +#define EVENT_TEC1_ON (1 << 0) +#define EVENT_TEC2_ON (1 << 1) +#define EVENT_TEC3_ON (1 << 2) +#define EVENT_TEC4_ON (1 << 3) + +#define EVENT_TEC1_OFF (1 << 4) +#define EVENT_TEC2_OFF (1 << 5) +#define EVENT_TEC3_OFF (1 << 6) +#define EVENT_TEC4_OFF (1 << 7) + +/* === Public data type declarations =========================================================== */ + +typedef struct keyboard_s * keyboard_t; + +/* === Public variable declarations ============================================================ */ + +/* === Public function declarations ============================================================ */ + +/** + * @brief Function to create a keyboard descriptor + * + * @param board Pointer to board descriptor + * + * @return keyboard_t Pointer to keyboard descriptor + */ +keyboard_t KeyboardCreate(board_t board); + +/** + * @brief Functio to wait a keyboard event + * + * @param keyboard Pointer to keyboard descriptor + * + * @return uint8_t Bit mask with events received + */ +uint8_t KeyboardWait(keyboard_t keyboard, uint8_t events); + +/* === End of documentation ==================================================================== */ + +#ifdef __cplusplus +} +#endif + +/** @} End of module definition for doxygen */ + +#endif /* KEYBOARD_H */ diff --git a/examples/freertos/interrupts/inc/serial.h b/examples/freertos/interrupts/inc/serial.h new file mode 100644 index 0000000..08720e0 --- /dev/null +++ b/examples/freertos/interrupts/inc/serial.h @@ -0,0 +1,98 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +#ifndef SERIAL_H +#define SERIAL_H + +/** @file + ** @brief Serial asynconous port declarations + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions ================================================================ */ + +#include +#include + +/* === Cabecera C++ ============================================================================ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* === Public macros definitions =============================================================== */ + +//! Referencia a un descriptor para gestionar puerto serial asincronico +typedef struct serial_port_s * serial_port_t; + +typedef void (*serial_event_t)(serial_port_t); + +/* === Public data type declarations =========================================================== */ + +/* === Public variable declarations ============================================================ */ + +/* === Public function declarations ============================================================ */ + +/** + * @brief Metodo para crear un puerto serial asincronico + * + * @param port Puerto serial aseincrónico que se utiliza + * @param bitrate Velocidad de transmisión del puerto + * @return serial_port_t Puntero al descriptor de la salida creada + */ +serial_port_t SerialPortCreate(uint8_t port, uint32_t bitrate); + +/** + * @brief Metodo para enviar datos por un puerto serial + * + * @param port Puntero al descriptor de la entrada + * @return true La entrada esta activa + * @return false La entrada esta inactiva + */ +uint8_t SerialPortTransmit(serial_port_t port, void const * const data, uint8_t size); + +/** + * @brief Metodo para consultar cambios en el estado de una entrada digital + * + * @param input Puntero al descriptor de la entrada + * @return true La entrada tuvo cambios desde la ultima llamada + * @return false La entrada no tuvo cambios desde la ultima llamada + */ +uint8_t SerialPortReceive(serial_port_t port, void const * const data, uint8_t size); + +void SerialPortOnTransmited(serial_port_t port, serial_event_t handler); + +/* === End of documentation ==================================================================== */ + +#ifdef __cplusplus +} +#endif + +/** @} End of module definition for doxygen */ + +#endif /* SERIAL_H */ diff --git a/examples/freertos/interrupts/makefile b/examples/freertos/interrupts/makefile new file mode 100644 index 0000000..f7b3118 --- /dev/null +++ b/examples/freertos/interrupts/makefile @@ -0,0 +1,31 @@ +################################################################################################## +# Copyright (c) 2022-2023, Laboratorio de Microprocesadores +# Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +# https://www.microprocesadores.unt.edu.ar/ +# +# Copyright (c) 2022-2023, Esteban Volentini +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +# associated documentation files (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, publish, distribute, +# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial +# portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT +################################################################################################## + +MUJU ?= ../../.. +BUILD_DIR := $(MUJU)/build +MODULES := module/hal module/freertos +BOARD ?= edu-ciaa-nxp + +include $(MUJU)/module/base/makefile diff --git a/examples/freertos/interrupts/src/bsp.c b/examples/freertos/interrupts/src/bsp.c new file mode 100644 index 0000000..943b344 --- /dev/null +++ b/examples/freertos/interrupts/src/bsp.c @@ -0,0 +1,132 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** @file + ** @brief Board support hardware abstraction layer implementation + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#include "bsp.h" +#include "board.h" +#include + +/* === Macros definitions ====================================================================== */ + +/* === Private data type declarations ========================================================== */ + +/* === Private variable declarations =========================================================== */ + +/* === Private function declarations =========================================================== */ + +/* === Public variable definitions ============================================================= */ + +/* === Private variable definitions ============================================================ */ + +/* === Private function implementation ========================================================= */ + +static board_t AssignResources(struct hal_sci_pins_s * console_pins) { + static struct board_s board = {0}; + +#ifdef EDU_CIAA_NXP + board.led_rgb[0].red = HAL_GPIO5_0; + board.led_rgb[0].green = HAL_GPIO5_1; + board.led_rgb[0].blue = HAL_GPIO5_2; + + board.led_1 = HAL_GPIO0_14; + board.led_2 = HAL_GPIO1_11; + board.led_3 = HAL_GPIO1_12; + + board.tec_1 = HAL_GPIO0_4; + board.tec_2 = HAL_GPIO0_8; + board.tec_3 = HAL_GPIO0_9; + board.tec_4 = HAL_GPIO1_9; + + board.console = HAL_SCI_USART2; + console_pins->txd_pin = HAL_PIN_P7_1; + console_pins->rxd_pin = HAL_PIN_P7_2; +#elif BLUE_PILL + board.led_2 = HAL_GPIO_PB9; + board.tec_3 = HAL_GPIO_PB13; + + board.console = HAL_SCI_USART1; + console_pins->txd_pin = HAL_PIN_PA9; + console_pins->rxd_pin = HAL_PIN_PA10; +#elif POSIX + board.led_rgb[0].red = HAL_GPIO3_7; + board.led_rgb[0].green = HAL_GPIO3_6; + board.led_rgb[0].blue = HAL_GPIO3_5; + + board.led_1 = HAL_GPIO3_2; + board.led_2 = HAL_GPIO3_1; + board.led_3 = HAL_GPIO3_0; + + board.tec_1 = HAL_GPIO0_0; + board.tec_2 = HAL_GPIO0_1; + board.tec_3 = HAL_GPIO0_2; + board.tec_4 = HAL_GPIO0_3; +#else +#error "This program does not have support for the selected board" +#endif + return (board_t)&board; +} + +/* === Public function implementation ========================================================= */ + +board_t BoardCreate(void) { + static const struct hal_sci_line_s console_config = { + .baud_rate = 115200, + .data_bits = 8, + .parity = HAL_SCI_NO_PARITY, + }; + struct hal_sci_pins_s console_pins = {0}; + + BoardSetup(); + board_t board = AssignResources(&console_pins); + + GpioSetDirection(board->led_rgb->red, true); + GpioSetDirection(board->led_rgb->green, true); + GpioSetDirection(board->led_rgb->blue, true); + + GpioSetDirection(board->led_1, true); + GpioSetDirection(board->led_2, true); + GpioSetDirection(board->led_3, true); + + GpioSetDirection(board->tec_1, false); + GpioSetDirection(board->tec_2, false); + GpioSetDirection(board->tec_3, false); + GpioSetDirection(board->tec_4, false); + + SciSetConfig(board->console, &console_config, &console_pins); + return board; +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/freertos/interrupts/src/keyboard.c b/examples/freertos/interrupts/src/keyboard.c new file mode 100644 index 0000000..0631258 --- /dev/null +++ b/examples/freertos/interrupts/src/keyboard.c @@ -0,0 +1,143 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** @file + ** @brief Simple sample of use FreeROTS with MUJU hal functions + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#include "keyboard.h" +#include "FreeRTOS.h" +#include "task.h" +#include "event_groups.h" + +/* === Macros definitions ====================================================================== */ + +#define TASK_STACK 256 +#define TASK_PRIORITY tskIDLE_PRIORITY + 2 + +/* === Private data type declarations ========================================================== */ + +//! Structure to storage a keybaord descriptor +typedef struct keyboard_s { + board_t board; //!< Pointer to board descriptor + TaskHandle_t task; //!< Pointer to task descriptor + EventGroupHandle_t key_events; //!< Events group to comunicate key actions +}; + +/* === Private variable declarations =========================================================== */ + +/* === Private function declarations =========================================================== */ + +/** + * @brief Allocate a keyboard descriptor + * + * @return keyboard_t Pointer to keyboard descriptor + */ +static keyboard_t CreateInstance(void); + +/** + * @brief Function to scan keyboard and send events to another tasks + * + * @param object Pointer to keyboard descriptor, used as parameter when task created + */ +void KeyboardTask(void * object); + +/* === Public variable definitions ============================================================= */ + +/* === Private variable definitions ============================================================ */ + +/* === Private function implementation ========================================================= */ + +static keyboard_t CreateInstance(void) { + static struct keyboard_s instances = {0}; + keyboard_t result = NULL; + + if ((instances.board == NULL) || (instances.key_events == NULL)) { + result = &instances; + } + return result; +} + +static void KeyTask(void * object) { + keyboard_t self = object; + uint8_t last_state, current_state, changes, events; + + while (true) { + vTaskDelay(pdMS_TO_TICKS(150)); + + current_state = 0; + if (!GpioGetState(self->board->tec_1)) { + current_state |= EVENT_TEC1_ON; + }; + if (!GpioGetState(self->board->tec_2)) { + current_state |= EVENT_TEC2_ON; + }; + if (!GpioGetState(self->board->tec_3)) { + current_state |= EVENT_TEC3_ON; + }; + if (!GpioGetState(self->board->tec_4)) { + current_state |= EVENT_TEC4_ON; + }; + + changes = current_state ^ last_state; + last_state = current_state; + events = ((changes & !current_state) << 4) | (changes & current_state); + + xEventGroupSetBits(self->key_events, events); + } +} + +/* === Public function implementation ========================================================= */ + +keyboard_t KeyboardCreate(board_t board) { + keyboard_t self = CreateInstance(); + + if (self) { + self->board = board; + self->key_events = xEventGroupCreate(); + if (self->key_events) { + xTaskCreate(KeyTask, "Keyboard", TASK_STACK, self, TASK_PRIORITY, &self->task); + } + } + if (self->task == NULL) { + self = NULL; + } + + return self; +} + +uint8_t KeyboardWait(keyboard_t keyboard, uint8_t events) { + return xEventGroupWaitBits(keyboard->key_events, events, TRUE, FALSE, portMAX_DELAY); +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/freertos/interrupts/src/main.c b/examples/freertos/interrupts/src/main.c new file mode 100644 index 0000000..88f4690 --- /dev/null +++ b/examples/freertos/interrupts/src/main.c @@ -0,0 +1,169 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** @file + ** @brief Simple sample of use FreeROTS with MUJU hal functions + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#include "bsp.h" +#include "FreeRTOS.h" +#include "task.h" +#include "semphr.h" +#include "keyboard.h" +#include "serial.h" + +/* === Macros definitions ====================================================================== */ + +#define CONSOLE_SERIAL_PORT 2 + +#define CONSOLE_BITRATE 115200 + +/* === Private data type declarations ========================================================== */ + +/* === Private variable declarations =========================================================== */ + +board_t board; + +keyboard_t keyboard; + +SemaphoreHandle_t semaforo; + +serial_port_t consola; + +/* === Private function declarations =========================================================== */ + +/** + * @brief Function to inform an error and stop program execution + * + * @param board Pointer to board descriptor + * @param code Code of error ocurred + */ +void StopByError(board_t board, uint8_t code); + +/** + * @brief Function to flash a led for a while + * + * @param object Pointer to task parameters structure, used as parameter when task created + */ +static void SendTask(void * object); + +/* === Public variable definitions ============================================================= */ + +/* === Private variable definitions ============================================================ */ + +/* === Private function implementation ========================================================= */ + +void StopByError(board_t board, uint8_t code) { + // Signal error condition + GpioBitSet(board->led_rgb->red); + + // Show error code + GpioSetState(board->led_1, code & (1 << 0)); + GpioSetState(board->led_2, code & (1 << 1)); + GpioSetState(board->led_3, code & (1 << 2)); + + // Stop program execution + while (true) { + }; +} + +void EventoSerial(serial_port_t port) { + BaseType_t planificar = pdFALSE; + + if (xSemaphoreGiveFromISR(semaforo, &planificar) != pdFAIL) { + portYIELD_FROM_ISR(planificar); + } else { + StopByError(board, 7); + } +} + +static void SendTask(void * object) { + board_t board = object; + + SerialPortOnTransmited(consola, EventoSerial); + + while (true) { + KeyboardWait(keyboard, EVENT_TEC4_ON); + + GpioBitSet(board->led_3); + /* Espera que se transmita la primera cadena */ + if (SerialPortTransmit(consola, "Hola ", 5)) { + } + + /* Espera que se transmita la segunda cadena */ + if (SerialPortTransmit(consola, "Mundo\r\n", 7)) { + } + ... Un monton de cosas... + + xSemaphoreTake(semaforo, portMAX_DELAY); + + GpioBitClear(board->led_3); + } +} + +/* === Public function implementation ========================================================= */ + +int main(void) { + + /* Inicializaciones y configuraciones de dispositivos */ + board = BoardCreate(); + + keyboard = KeyboardCreate(board); + if (keyboard == NULL) { + StopByError(board, 0); + } + + consola = SerialPortCreate(CONSOLE_SERIAL_PORT, CONSOLE_BITRATE); + + semaforo = xSemaphoreCreateCounting(1, 0); + if (semaforo == NULL) { + StopByError(board, 1); + } + + /* Creación de las tareas */ + if (xTaskCreate(SendTask, "Serial", 256, (void *)board, tskIDLE_PRIORITY + 1, NULL) != pdPASS) { + StopByError(board, 2); + } + + /* Arranque del sistema operativo */ + vTaskStartScheduler(); + + /* vTaskStartScheduler solo retorna si se detiene el sistema operativo */ + while (true) { + } + + /* El valor de retorno es solo para evitar errores en el compilador*/ + return 0; +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/freertos/interrupts/src/serial.c b/examples/freertos/interrupts/src/serial.c new file mode 100644 index 0000000..520f296 --- /dev/null +++ b/examples/freertos/interrupts/src/serial.c @@ -0,0 +1,224 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** @file + ** @brief Serial asynconous port definitions + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#include "serial.h" +#include "chip.h" +#include "cmsis_43xx.h" +#include + +/* === Macros definitions ====================================================================== */ + +#ifndef SERIAL_INSTANCES +#define SERIAL_INSTANCES 2 +#endif + +#ifndef SERIAL_TX_BUFFER_SIZE +#define SERIAL_TX_BUFFER_SIZE 8 +#endif + +#ifndef SERIAL_RX_BUFFER_SIZE +#define SERIAL_RX_BUFFER_SIZE 8 +#endif + +/* === Private data type declarations ========================================================== */ + +//! Estructura para almacenar el descriptor de puerto serial asincronico +struct serial_port_s { + LPC_USART_T * port; + IRQn_Type interupt; + serial_event_t handler; + struct { + char data[SERIAL_TX_BUFFER_SIZE]; + uint8_t count; + uint8_t sent; + } tx[1]; + struct { + char data[SERIAL_RX_BUFFER_SIZE]; + uint8_t count; + } rx[1]; + bool allocated; +}; + +/* === Private variable declarations =========================================================== */ + +/* === Private function declarations =========================================================== */ + +// Function para asignar un descriptor para crear una nuevo puerto serial asincronico +static serial_port_t SerialPortAllocate(void); + +static void InteruptEvent(serial_port_t port); + +/* === Public variable definitions ============================================================= */ + +static serial_port_t handlers[4]; + +/* === Private variable definitions ============================================================ */ + +/* === Private function implementation ========================================================= */ + +static serial_port_t SerialPortAllocate(void) { + serial_port_t port = NULL; + + static struct serial_port_s instances[SERIAL_INSTANCES] = {0}; + + for (int index = 0; index < SERIAL_INSTANCES; index++) { + if (!instances[index].allocated) { + instances[index].allocated = true; + port = &instances[index]; + break; + } + } + return port; +} + +static void InteruptEvent(serial_port_t port) { + uint8_t eventos; + + eventos = Chip_UART_ReadLineStatus(port->port); + + if (eventos & UART_LSR_THRE) { + Chip_UART_SendByte(port->port, port->tx->data[port->tx->sent]); + port->tx->sent++; + + if (port->tx->sent == port->tx->count) { + port->tx->count = 0; + Chip_UART_IntDisable(port->port, UART_IER_THREINT); + if (port->handler) { + port->handler(port); + } + } + } +} + +/* === Public function implementation ========================================================= */ + +serial_port_t SerialPortCreate(uint8_t port, uint32_t bitrate) { + serial_port_t self = SerialPortAllocate(); + + if (self) { + switch (port) { + case 0: + Chip_SCU_PinMux(9, 5, MD_PDN, FUNC7); /* P9_5: UART0_TXD */ + Chip_SCU_PinMux(9, 6, MD_PLN | MD_EZI | MD_ZI, FUNC7); /* P9_6: UART0_RXD */ + Chip_SCU_PinMux(6, 2, MD_PDN, FUNC2); /* P6_2: UART0_DIR */ + handlers[0] = self; + self->port = LPC_USART0; + self->interupt = USART0_IRQn; + break; + case 1: + handlers[1] = self; + self->port = LPC_UART1; + self->interupt = UART1_IRQn; + break; + case 2: + handlers[2] = self; + Chip_SCU_PinMux(7, 1, MD_PDN, FUNC6); /* P7_1: UART2_TXD */ + Chip_SCU_PinMux(7, 2, MD_PLN | MD_EZI | MD_ZI, FUNC6); /* P7_2: UART2_RXD */ + self->port = LPC_USART2; + self->interupt = USART2_IRQn; + break; + case 3: + handlers[3] = self; + Chip_SCU_PinMux(2, 3, MD_PDN, FUNC2); /* P2_3: UART3_TXD */ + Chip_SCU_PinMux(2, 4, MD_PLN | MD_EZI | MD_ZI, FUNC2); /* P2_4: UART3_RXD */ + self->port = LPC_USART3; + self->interupt = USART3_IRQn; + break; + default: + self->allocated = false; + self = NULL; + break; + } + } + + if (self) { + Chip_UART_Init(self->port); + Chip_UART_SetBaud(self->port, bitrate); + Chip_UART_SetupFIFOS(self->port, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0); + Chip_UART_TXEnable(self->port); + if (self->port == LPC_USART0) { + Chip_UART_SetRS485Flags(self->port, UART_RS485CTRL_DCTRL_EN | UART_RS485CTRL_OINV_1); + } + NVIC_EnableIRQ(self->interupt); + NVIC_SetPriority(self->interupt, 5); + } + return self; +} + +uint8_t SerialPortTransmit(serial_port_t port, void const * const data, uint8_t size) { + uint8_t count = 0; + + if (port->tx->count == 0) { + count = size; + if (count > SERIAL_TX_BUFFER_SIZE) { + count = SERIAL_TX_BUFFER_SIZE; + } + memcpy(port->tx->data, data, count); + port->tx->count = count; + port->tx->sent = 0; + + Chip_UART_IntEnable(port->port, UART_IER_THREINT); + InteruptEvent(port); + } + return count; +} + +uint8_t SerialPortReceive(serial_port_t port, void const * const data, uint8_t size) { + return 0; +} + +void SerialPortOnTransmited(serial_port_t port, serial_event_t handler) { + port->handler = handler; +} + +void UART0_IRQHandler(void) { + InteruptEvent(handlers[0]); +} + +void UART1_IRQHandler(void) { + InteruptEvent(handlers[1]); +} + +void UART2_IRQHandler(void) { + InteruptEvent(handlers[2]); +} + +void UART3_IRQHandler(void) { + InteruptEvent(handlers[3]); +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/freertos/keyboard/inc/FreeRTOSConfig.h b/examples/freertos/keyboard/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..cb2cbfd --- /dev/null +++ b/examples/freertos/keyboard/inc/FreeRTOSConfig.h @@ -0,0 +1,171 @@ +/* + * FreeRTOS Kernel V10.2.0 + * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + */ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +#include + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html + *----------------------------------------------------------*/ + +/* clang-format off */ + +#define configSUPPORT_STATIC_ALLOCATION 0 + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICKLESS_IDLE 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ (SystemCoreClock) +#define configTICK_RATE_HZ ((TickType_t)1000) // 1000 ticks per second => 1ms tick rate +#define configMAX_PRIORITIES (15) +#define configMINIMAL_STACK_SIZE ((uint16_t)128) +#define configAPPLICATION_ALLOCATED_HEAP 0 +#define configTOTAL_HEAP_SIZE ((size_t)(16 * 1024)) /* 16 Kbytes. */ +#define configMAX_TASK_NAME_LEN (16) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES (2) + +/* Software timer definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 3) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 4) + +/* Set the following definitions to 1 to include the API function, or zero + * to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_xSemaphoreGetMutexHolder 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS +/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ +#define configPRIO_BITS __NVIC_PRIO_BITS +#else +#define configPRIO_BITS 3 /* 8 priority levels. */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" + * function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY ((1 << configPRIO_BITS) - 1) + +/* The highest interrupt priority that can be used by any interrupt service + * routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL + * INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER + * PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 + +/* Interrupt priorities used by the kernel port layer itself. These are generic + * to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY \ + (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) + +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! + * See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY \ + (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) + +/* Normal assert() semantics without relying on the provision of an assert.h + * header file. */ +#define configASSERT(x) \ + if ((x) == 0) { \ + taskDISABLE_INTERRUPTS(); \ + for (;;) { \ + ; \ + } \ + } + +/* Map the FreeRTOS printf() to the logging task printf. */ +#define configPRINTF(x) vLoggingPrintf x + +/* Map the logging task's printf to the board specific output function. */ +#define configPRINT_STRING DbgConsole_Printf + +/* Sets the length of the buffers into which logging messages are written - so + * also defines the maximum length of each log message. */ +#define configLOGGING_MAX_MESSAGE_LENGTH 100 + +/* Set to 1 to prepend each log message with a message number, the task name, + * and a time stamp. */ +#define configLOGGING_INCLUDE_TIME_AND_TASK_NAME 1 + +/* Demo specific macros that allow the application writer to insert code to be + * executed immediately before the MCU's STOP low power mode is entered and exited + * respectively. These macros are in addition to the standard + * configPRE_SLEEP_PROCESSING() and configPOST_SLEEP_PROCESSING() macros, which are + * called pre and post the low power SLEEP mode being entered and exited. These + * macros can be used to turn turn off and on IO, clocks, the Flash etc. to obtain + * the lowest power possible while the tick is off. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) +void vMainPreStopProcessing(void); +void vMainPostStopProcessing(void); +#endif /* defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) */ + +#define configPRE_STOP_PROCESSING vMainPreStopProcessing +#define configPOST_STOP_PROCESSING vMainPostStopProcessing + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS + * standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler +#define xPortSysTickHandler SysTick_Handler +#define vHardFault_Handler HardFault_Handler + +/* IMPORTANT: This define MUST be commented when used with STM32Cube firmware, + * to prevent overwriting SysTick_Handler defined within STM32Cube HAL. */ +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ diff --git a/examples/freertos/keyboard/inc/bsp.h b/examples/freertos/keyboard/inc/bsp.h new file mode 100644 index 0000000..d99f3ad --- /dev/null +++ b/examples/freertos/keyboard/inc/bsp.h @@ -0,0 +1,94 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +#ifndef BSP_H +#define BSP_H + +/** @file + ** @brief Board support hardware abstraction layer declarations + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions ================================================================ */ + +#include "hal.h" + +/* === Cabecera C++ ============================================================================ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* === Public macros definitions =============================================================== */ + +/* === Public data type declarations =========================================================== */ + +/** + * @brief Structure with gpio outputs to drive an RGB led + */ +typedef struct led_rgb_s { + hal_gpio_bit_t red; /**< Gpio output used to drive red channel of RGB led */ + hal_gpio_bit_t green; /**< Gpio output used to drive green channel of RGB led */ + hal_gpio_bit_t blue; /**< Gpio output used to drive blue channel of RGB led */ +} * const led_rgb_t; + +/** + * @brief Structure with gpio terminals usted by board + */ +typedef struct board_s { + struct led_rgb_s led_rgb[1]; /**< Structure with gpio output used by RGB led */ + hal_gpio_bit_t led_1; /**< Gpio output used to drive led 1 on board */ + hal_gpio_bit_t led_2; /**< Gpio output used to drive led 2 on board */ + hal_gpio_bit_t led_3; /**< Gpio output used to drive led 3 on board */ + hal_gpio_bit_t tec_1; /**< Gpio output used to read status of key 1 on board */ + hal_gpio_bit_t tec_2; /**< Gpio output used to read status of key 2 on board */ + hal_gpio_bit_t tec_3; /**< Gpio output used to read status of key 3 on board */ + hal_gpio_bit_t tec_4; /**< Gpio output used to read status of key 4 on board */ + hal_sci_t console; /**< Serial port used as console on board */ +} const * board_t; + +/* === Public variable declarations ============================================================ */ + +/* === Public function declarations ============================================================ */ + +/** + * @brief Function to initialize the board and create an descriptor to his resources + * + * @return board_t Pointer to descriptor with board resources + */ +board_t BoardCreate(void); + +/* === End of documentation ==================================================================== */ + +#ifdef __cplusplus +} +#endif + +/** @} End of module definition for doxygen */ + +#endif /* BSP_H */ diff --git a/examples/freertos/keyboard/inc/keyboard.h b/examples/freertos/keyboard/inc/keyboard.h new file mode 100644 index 0000000..850e9f3 --- /dev/null +++ b/examples/freertos/keyboard/inc/keyboard.h @@ -0,0 +1,93 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +#ifndef KEYBOARD_H +#define KEYBOARD_H + +/** @file + ** @brief Board support hardware abstraction layer declarations + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions ================================================================ */ + +#include "bsp.h" + +/* === Cabecera C++ ============================================================================ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* === Public macros definitions =============================================================== */ + +#define EVENT_TEC1_ON (1 << 0) +#define EVENT_TEC2_ON (1 << 1) +#define EVENT_TEC3_ON (1 << 2) +#define EVENT_TEC4_ON (1 << 3) + +#define EVENT_TEC1_OFF (1 << 4) +#define EVENT_TEC2_OFF (1 << 5) +#define EVENT_TEC3_OFF (1 << 6) +#define EVENT_TEC4_OFF (1 << 7) + +/* === Public data type declarations =========================================================== */ + +typedef struct keyboard_s * keyboard_t; + +/* === Public variable declarations ============================================================ */ + +/* === Public function declarations ============================================================ */ + +/** + * @brief Function to create a keyboard descriptor + * + * @param board Pointer to board descriptor + * + * @return keyboard_t Pointer to keyboard descriptor + */ +keyboard_t KeyboardCreate(board_t board); + +/** + * @brief Functio to wait a keyboard event + * + * @param keyboard Pointer to keyboard descriptor + * + * @return uint8_t Bit mask with events received + */ +uint8_t KeyboardWait(keyboard_t keyboard, uint8_t events); + +/* === End of documentation ==================================================================== */ + +#ifdef __cplusplus +} +#endif + +/** @} End of module definition for doxygen */ + +#endif /* KEYBOARD_H */ diff --git a/examples/freertos/keyboard/makefile b/examples/freertos/keyboard/makefile new file mode 100644 index 0000000..f7b3118 --- /dev/null +++ b/examples/freertos/keyboard/makefile @@ -0,0 +1,31 @@ +################################################################################################## +# Copyright (c) 2022-2023, Laboratorio de Microprocesadores +# Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +# https://www.microprocesadores.unt.edu.ar/ +# +# Copyright (c) 2022-2023, Esteban Volentini +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +# associated documentation files (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, publish, distribute, +# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial +# portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT +################################################################################################## + +MUJU ?= ../../.. +BUILD_DIR := $(MUJU)/build +MODULES := module/hal module/freertos +BOARD ?= edu-ciaa-nxp + +include $(MUJU)/module/base/makefile diff --git a/examples/freertos/keyboard/src/bsp.c b/examples/freertos/keyboard/src/bsp.c new file mode 100644 index 0000000..943b344 --- /dev/null +++ b/examples/freertos/keyboard/src/bsp.c @@ -0,0 +1,132 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** @file + ** @brief Board support hardware abstraction layer implementation + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#include "bsp.h" +#include "board.h" +#include + +/* === Macros definitions ====================================================================== */ + +/* === Private data type declarations ========================================================== */ + +/* === Private variable declarations =========================================================== */ + +/* === Private function declarations =========================================================== */ + +/* === Public variable definitions ============================================================= */ + +/* === Private variable definitions ============================================================ */ + +/* === Private function implementation ========================================================= */ + +static board_t AssignResources(struct hal_sci_pins_s * console_pins) { + static struct board_s board = {0}; + +#ifdef EDU_CIAA_NXP + board.led_rgb[0].red = HAL_GPIO5_0; + board.led_rgb[0].green = HAL_GPIO5_1; + board.led_rgb[0].blue = HAL_GPIO5_2; + + board.led_1 = HAL_GPIO0_14; + board.led_2 = HAL_GPIO1_11; + board.led_3 = HAL_GPIO1_12; + + board.tec_1 = HAL_GPIO0_4; + board.tec_2 = HAL_GPIO0_8; + board.tec_3 = HAL_GPIO0_9; + board.tec_4 = HAL_GPIO1_9; + + board.console = HAL_SCI_USART2; + console_pins->txd_pin = HAL_PIN_P7_1; + console_pins->rxd_pin = HAL_PIN_P7_2; +#elif BLUE_PILL + board.led_2 = HAL_GPIO_PB9; + board.tec_3 = HAL_GPIO_PB13; + + board.console = HAL_SCI_USART1; + console_pins->txd_pin = HAL_PIN_PA9; + console_pins->rxd_pin = HAL_PIN_PA10; +#elif POSIX + board.led_rgb[0].red = HAL_GPIO3_7; + board.led_rgb[0].green = HAL_GPIO3_6; + board.led_rgb[0].blue = HAL_GPIO3_5; + + board.led_1 = HAL_GPIO3_2; + board.led_2 = HAL_GPIO3_1; + board.led_3 = HAL_GPIO3_0; + + board.tec_1 = HAL_GPIO0_0; + board.tec_2 = HAL_GPIO0_1; + board.tec_3 = HAL_GPIO0_2; + board.tec_4 = HAL_GPIO0_3; +#else +#error "This program does not have support for the selected board" +#endif + return (board_t)&board; +} + +/* === Public function implementation ========================================================= */ + +board_t BoardCreate(void) { + static const struct hal_sci_line_s console_config = { + .baud_rate = 115200, + .data_bits = 8, + .parity = HAL_SCI_NO_PARITY, + }; + struct hal_sci_pins_s console_pins = {0}; + + BoardSetup(); + board_t board = AssignResources(&console_pins); + + GpioSetDirection(board->led_rgb->red, true); + GpioSetDirection(board->led_rgb->green, true); + GpioSetDirection(board->led_rgb->blue, true); + + GpioSetDirection(board->led_1, true); + GpioSetDirection(board->led_2, true); + GpioSetDirection(board->led_3, true); + + GpioSetDirection(board->tec_1, false); + GpioSetDirection(board->tec_2, false); + GpioSetDirection(board->tec_3, false); + GpioSetDirection(board->tec_4, false); + + SciSetConfig(board->console, &console_config, &console_pins); + return board; +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/freertos/keyboard/src/keyboard.c b/examples/freertos/keyboard/src/keyboard.c new file mode 100644 index 0000000..0631258 --- /dev/null +++ b/examples/freertos/keyboard/src/keyboard.c @@ -0,0 +1,143 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** @file + ** @brief Simple sample of use FreeROTS with MUJU hal functions + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#include "keyboard.h" +#include "FreeRTOS.h" +#include "task.h" +#include "event_groups.h" + +/* === Macros definitions ====================================================================== */ + +#define TASK_STACK 256 +#define TASK_PRIORITY tskIDLE_PRIORITY + 2 + +/* === Private data type declarations ========================================================== */ + +//! Structure to storage a keybaord descriptor +typedef struct keyboard_s { + board_t board; //!< Pointer to board descriptor + TaskHandle_t task; //!< Pointer to task descriptor + EventGroupHandle_t key_events; //!< Events group to comunicate key actions +}; + +/* === Private variable declarations =========================================================== */ + +/* === Private function declarations =========================================================== */ + +/** + * @brief Allocate a keyboard descriptor + * + * @return keyboard_t Pointer to keyboard descriptor + */ +static keyboard_t CreateInstance(void); + +/** + * @brief Function to scan keyboard and send events to another tasks + * + * @param object Pointer to keyboard descriptor, used as parameter when task created + */ +void KeyboardTask(void * object); + +/* === Public variable definitions ============================================================= */ + +/* === Private variable definitions ============================================================ */ + +/* === Private function implementation ========================================================= */ + +static keyboard_t CreateInstance(void) { + static struct keyboard_s instances = {0}; + keyboard_t result = NULL; + + if ((instances.board == NULL) || (instances.key_events == NULL)) { + result = &instances; + } + return result; +} + +static void KeyTask(void * object) { + keyboard_t self = object; + uint8_t last_state, current_state, changes, events; + + while (true) { + vTaskDelay(pdMS_TO_TICKS(150)); + + current_state = 0; + if (!GpioGetState(self->board->tec_1)) { + current_state |= EVENT_TEC1_ON; + }; + if (!GpioGetState(self->board->tec_2)) { + current_state |= EVENT_TEC2_ON; + }; + if (!GpioGetState(self->board->tec_3)) { + current_state |= EVENT_TEC3_ON; + }; + if (!GpioGetState(self->board->tec_4)) { + current_state |= EVENT_TEC4_ON; + }; + + changes = current_state ^ last_state; + last_state = current_state; + events = ((changes & !current_state) << 4) | (changes & current_state); + + xEventGroupSetBits(self->key_events, events); + } +} + +/* === Public function implementation ========================================================= */ + +keyboard_t KeyboardCreate(board_t board) { + keyboard_t self = CreateInstance(); + + if (self) { + self->board = board; + self->key_events = xEventGroupCreate(); + if (self->key_events) { + xTaskCreate(KeyTask, "Keyboard", TASK_STACK, self, TASK_PRIORITY, &self->task); + } + } + if (self->task == NULL) { + self = NULL; + } + + return self; +} + +uint8_t KeyboardWait(keyboard_t keyboard, uint8_t events) { + return xEventGroupWaitBits(keyboard->key_events, events, TRUE, FALSE, portMAX_DELAY); +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/freertos/keyboard/src/main.c b/examples/freertos/keyboard/src/main.c new file mode 100644 index 0000000..79c33ae --- /dev/null +++ b/examples/freertos/keyboard/src/main.c @@ -0,0 +1,167 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** @file + ** @brief Simple sample of use FreeROTS with MUJU hal functions + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#include "bsp.h" +#include "FreeRTOS.h" +#include "task.h" +#include "keyboard.h" + +/* === Macros definitions ====================================================================== */ + +#define EVENT_TEC1_ON (1 << 0) +#define EVENT_TEC2_ON (1 << 1) +#define EVENT_TEC3_ON (1 << 2) +#define EVENT_TEC4_ON (1 << 3) + +#define EVENT_TEC1_OFF (1 << 4) +#define EVENT_TEC2_OFF (1 << 5) +#define EVENT_TEC3_OFF (1 << 6) +#define EVENT_TEC4_OFF (1 << 7) + +/* === Private data type declarations ========================================================== */ + +typedef struct flash_s { + keyboard_t keyboard; + uint8_t key; + hal_gpio_bit_t led; + uint32_t delay; +} * flash_s; + +/* === Private variable declarations =========================================================== */ + +/* === Private function declarations =========================================================== */ + +/** + * @brief Function to inform an error and stop program execution + * + * @param board Pointer to board descriptor + * @param code Code of error ocurred + */ +void StopByError(board_t board, uint8_t code); + +/** + * @brief Function to flash a led for a while + * + * @param object Pointer to task parameters structure, used as parameter when task created + */ +static void FlashTask(void * object); + +/* === Public variable definitions ============================================================= */ + +/* === Private variable definitions ============================================================ */ + +/* === Private function implementation ========================================================= */ + +void StopByError(board_t board, uint8_t code) { + // Signal error condition + GpioBitSet(board->led_rgb->red); + + // Show error code + GpioSetState(board->led_1, code & (1 << 0)); + GpioSetState(board->led_2, code & (1 << 1)); + GpioSetState(board->led_3, code & (1 << 2)); + + // Stop program execution + while (true) { + }; +} + +static void FlashTask(void * object) { + flash_s options = object; + TickType_t last_value = xTaskGetTickCount(); + + while (true) { + KeyboardWait(options->keyboard, options->key); + + GpioBitSet(options->led); + vTaskDelay(pdMS_TO_TICKS(options->delay)); + GpioBitClear(options->led); + vTaskDelay(pdMS_TO_TICKS(options->delay)); + } +} + +/* === Public function implementation ========================================================= */ + +int main(void) { + static struct flash_s flash[3]; + + /* Inicializaciones y configuraciones de dispositivos */ + board_t board = BoardCreate(); + keyboard_t keyboard = KeyboardCreate(board); + + if (keyboard == NULL) { + StopByError(board, 0); + } + + flash[0].keyboard = keyboard; + flash[0].key = EVENT_TEC2_ON; + flash[0].led = board->led_1; + flash[0].delay = 500; + + flash[1].keyboard = keyboard; + flash[1].key = EVENT_TEC3_ON; + flash[1].led = board->led_2; + flash[1].delay = 250; + + flash[2].keyboard = keyboard; + flash[2].key = EVENT_TEC4_ON; + flash[2].led = board->led_3; + flash[2].delay = 750; + + /* Creación de las tareas */ + if (xTaskCreate(FlashTask, "Red", 256, &flash[0], tskIDLE_PRIORITY + 1, NULL) != pdPASS) { + StopByError(board, 1); + } + if (xTaskCreate(FlashTask, "Yellow", 256, &flash[1], tskIDLE_PRIORITY + 1, NULL) != pdPASS) { + StopByError(board, 2); + } + if (xTaskCreate(FlashTask, "Green", 256, &flash[2], tskIDLE_PRIORITY + 1, NULL) != pdPASS) { + StopByError(board, 3); + } + + /* Arranque del sistema operativo */ + vTaskStartScheduler(); + + /* vTaskStartScheduler solo retorna si se detiene el sistema operativo */ + while (true) { + } + + /* El valor de retorno es solo para evitar errores en el compilador*/ + return 0; +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/freertos/queues/inc/FreeRTOSConfig.h b/examples/freertos/queues/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..cb2cbfd --- /dev/null +++ b/examples/freertos/queues/inc/FreeRTOSConfig.h @@ -0,0 +1,171 @@ +/* + * FreeRTOS Kernel V10.2.0 + * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + */ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +#include + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html + *----------------------------------------------------------*/ + +/* clang-format off */ + +#define configSUPPORT_STATIC_ALLOCATION 0 + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICKLESS_IDLE 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ (SystemCoreClock) +#define configTICK_RATE_HZ ((TickType_t)1000) // 1000 ticks per second => 1ms tick rate +#define configMAX_PRIORITIES (15) +#define configMINIMAL_STACK_SIZE ((uint16_t)128) +#define configAPPLICATION_ALLOCATED_HEAP 0 +#define configTOTAL_HEAP_SIZE ((size_t)(16 * 1024)) /* 16 Kbytes. */ +#define configMAX_TASK_NAME_LEN (16) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES (2) + +/* Software timer definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 3) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 4) + +/* Set the following definitions to 1 to include the API function, or zero + * to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_xSemaphoreGetMutexHolder 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS +/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ +#define configPRIO_BITS __NVIC_PRIO_BITS +#else +#define configPRIO_BITS 3 /* 8 priority levels. */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" + * function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY ((1 << configPRIO_BITS) - 1) + +/* The highest interrupt priority that can be used by any interrupt service + * routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL + * INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER + * PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 + +/* Interrupt priorities used by the kernel port layer itself. These are generic + * to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY \ + (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) + +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! + * See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY \ + (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) + +/* Normal assert() semantics without relying on the provision of an assert.h + * header file. */ +#define configASSERT(x) \ + if ((x) == 0) { \ + taskDISABLE_INTERRUPTS(); \ + for (;;) { \ + ; \ + } \ + } + +/* Map the FreeRTOS printf() to the logging task printf. */ +#define configPRINTF(x) vLoggingPrintf x + +/* Map the logging task's printf to the board specific output function. */ +#define configPRINT_STRING DbgConsole_Printf + +/* Sets the length of the buffers into which logging messages are written - so + * also defines the maximum length of each log message. */ +#define configLOGGING_MAX_MESSAGE_LENGTH 100 + +/* Set to 1 to prepend each log message with a message number, the task name, + * and a time stamp. */ +#define configLOGGING_INCLUDE_TIME_AND_TASK_NAME 1 + +/* Demo specific macros that allow the application writer to insert code to be + * executed immediately before the MCU's STOP low power mode is entered and exited + * respectively. These macros are in addition to the standard + * configPRE_SLEEP_PROCESSING() and configPOST_SLEEP_PROCESSING() macros, which are + * called pre and post the low power SLEEP mode being entered and exited. These + * macros can be used to turn turn off and on IO, clocks, the Flash etc. to obtain + * the lowest power possible while the tick is off. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) +void vMainPreStopProcessing(void); +void vMainPostStopProcessing(void); +#endif /* defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) */ + +#define configPRE_STOP_PROCESSING vMainPreStopProcessing +#define configPOST_STOP_PROCESSING vMainPostStopProcessing + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS + * standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler +#define xPortSysTickHandler SysTick_Handler +#define vHardFault_Handler HardFault_Handler + +/* IMPORTANT: This define MUST be commented when used with STM32Cube firmware, + * to prevent overwriting SysTick_Handler defined within STM32Cube HAL. */ +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ diff --git a/examples/freertos/queues/inc/bsp.h b/examples/freertos/queues/inc/bsp.h new file mode 100644 index 0000000..f1b05d2 --- /dev/null +++ b/examples/freertos/queues/inc/bsp.h @@ -0,0 +1,94 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +#ifndef BSP_H +#define BSP_H + +/** @file + ** @brief Board support hardware abstraction layer declarations + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions ================================================================ */ + +#include "hal.h" + +/* === Cabecera C++ ============================================================================ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* === Public macros definitions =============================================================== */ + +/* === Public data type declarations =========================================================== */ + +/** + * @brief Structure with gpio outputs to drive an RGB led + */ +typedef struct led_rgb_s { + hal_gpio_bit_t red; /**< Gpio output used to drive red channel of RGB led */ + hal_gpio_bit_t green; /**< Gpio output used to drive green channel of RGB led */ + hal_gpio_bit_t blue; /**< Gpio output used to drive blue channel of RGB led */ +} const * const led_rgb_t; + +/** + * @brief Structure with gpio terminals usted by board + */ +typedef struct board_s { + struct led_rgb_s led_rgb[1]; /**< Structure with gpio output used by RGB led */ + hal_gpio_bit_t led_1; /**< Gpio output used to drive led 1 on board */ + hal_gpio_bit_t led_2; /**< Gpio output used to drive led 2 on board */ + hal_gpio_bit_t led_3; /**< Gpio output used to drive led 3 on board */ + hal_gpio_bit_t tec_1; /**< Gpio output used to read status of key 1 on board */ + hal_gpio_bit_t tec_2; /**< Gpio output used to read status of key 2 on board */ + hal_gpio_bit_t tec_3; /**< Gpio output used to read status of key 3 on board */ + hal_gpio_bit_t tec_4; /**< Gpio output used to read status of key 4 on board */ + hal_sci_t console; /**< Serial port used as console on board */ +} const * const board_t; + +/* === Public variable declarations ============================================================ */ + +/* === Public function declarations ============================================================ */ + +/** + * @brief Function to initialize the board and create an descriptor to his resources + * + * @return board_t Pointer to descriptor with board resources + */ +board_t BoardCreate(void); + +/* === End of documentation ==================================================================== */ + +#ifdef __cplusplus +} +#endif + +/** @} End of module definition for doxygen */ + +#endif /* BSP_H */ diff --git a/examples/freertos/queues/makefile b/examples/freertos/queues/makefile new file mode 100644 index 0000000..f7b3118 --- /dev/null +++ b/examples/freertos/queues/makefile @@ -0,0 +1,31 @@ +################################################################################################## +# Copyright (c) 2022-2023, Laboratorio de Microprocesadores +# Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +# https://www.microprocesadores.unt.edu.ar/ +# +# Copyright (c) 2022-2023, Esteban Volentini +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +# associated documentation files (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, publish, distribute, +# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial +# portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT +################################################################################################## + +MUJU ?= ../../.. +BUILD_DIR := $(MUJU)/build +MODULES := module/hal module/freertos +BOARD ?= edu-ciaa-nxp + +include $(MUJU)/module/base/makefile diff --git a/examples/freertos/queues/src/bsp.c b/examples/freertos/queues/src/bsp.c new file mode 100644 index 0000000..943b344 --- /dev/null +++ b/examples/freertos/queues/src/bsp.c @@ -0,0 +1,132 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** @file + ** @brief Board support hardware abstraction layer implementation + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#include "bsp.h" +#include "board.h" +#include + +/* === Macros definitions ====================================================================== */ + +/* === Private data type declarations ========================================================== */ + +/* === Private variable declarations =========================================================== */ + +/* === Private function declarations =========================================================== */ + +/* === Public variable definitions ============================================================= */ + +/* === Private variable definitions ============================================================ */ + +/* === Private function implementation ========================================================= */ + +static board_t AssignResources(struct hal_sci_pins_s * console_pins) { + static struct board_s board = {0}; + +#ifdef EDU_CIAA_NXP + board.led_rgb[0].red = HAL_GPIO5_0; + board.led_rgb[0].green = HAL_GPIO5_1; + board.led_rgb[0].blue = HAL_GPIO5_2; + + board.led_1 = HAL_GPIO0_14; + board.led_2 = HAL_GPIO1_11; + board.led_3 = HAL_GPIO1_12; + + board.tec_1 = HAL_GPIO0_4; + board.tec_2 = HAL_GPIO0_8; + board.tec_3 = HAL_GPIO0_9; + board.tec_4 = HAL_GPIO1_9; + + board.console = HAL_SCI_USART2; + console_pins->txd_pin = HAL_PIN_P7_1; + console_pins->rxd_pin = HAL_PIN_P7_2; +#elif BLUE_PILL + board.led_2 = HAL_GPIO_PB9; + board.tec_3 = HAL_GPIO_PB13; + + board.console = HAL_SCI_USART1; + console_pins->txd_pin = HAL_PIN_PA9; + console_pins->rxd_pin = HAL_PIN_PA10; +#elif POSIX + board.led_rgb[0].red = HAL_GPIO3_7; + board.led_rgb[0].green = HAL_GPIO3_6; + board.led_rgb[0].blue = HAL_GPIO3_5; + + board.led_1 = HAL_GPIO3_2; + board.led_2 = HAL_GPIO3_1; + board.led_3 = HAL_GPIO3_0; + + board.tec_1 = HAL_GPIO0_0; + board.tec_2 = HAL_GPIO0_1; + board.tec_3 = HAL_GPIO0_2; + board.tec_4 = HAL_GPIO0_3; +#else +#error "This program does not have support for the selected board" +#endif + return (board_t)&board; +} + +/* === Public function implementation ========================================================= */ + +board_t BoardCreate(void) { + static const struct hal_sci_line_s console_config = { + .baud_rate = 115200, + .data_bits = 8, + .parity = HAL_SCI_NO_PARITY, + }; + struct hal_sci_pins_s console_pins = {0}; + + BoardSetup(); + board_t board = AssignResources(&console_pins); + + GpioSetDirection(board->led_rgb->red, true); + GpioSetDirection(board->led_rgb->green, true); + GpioSetDirection(board->led_rgb->blue, true); + + GpioSetDirection(board->led_1, true); + GpioSetDirection(board->led_2, true); + GpioSetDirection(board->led_3, true); + + GpioSetDirection(board->tec_1, false); + GpioSetDirection(board->tec_2, false); + GpioSetDirection(board->tec_3, false); + GpioSetDirection(board->tec_4, false); + + SciSetConfig(board->console, &console_config, &console_pins); + return board; +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/freertos/queues/src/main.c b/examples/freertos/queues/src/main.c new file mode 100644 index 0000000..6a0ccb9 --- /dev/null +++ b/examples/freertos/queues/src/main.c @@ -0,0 +1,188 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** @file + ** @brief Simple sample of use FreeROTS with MUJU hal functions + ** + ** @addtogroup sample-freertos FreeRTOS Sample + ** @ingroup samples + ** @brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#include "bsp.h" +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" + +/* === Macros definitions ====================================================================== */ + +/* === Private data type declarations ========================================================== */ + +typedef struct action_s { + hal_gpio_bit_t led; + uint32_t delay; +} * action_t; + +/* === Private variable declarations =========================================================== */ + +/* === Private function declarations =========================================================== */ + +/** + * @brief Function to inform an error and stop program execution + * + * @param board Pointer to board descriptor + * @param code Code of error ocurred + */ +void StopByError(board_t board, uint8_t code); + +/** + * @brief Function to flash a led for a while + * + * @param object Pointer to task parameters structure, used as parameter when task created + */ +static void FlashTask(void * object); + +/** + * @brief Function to scan keyboard and send events to another tasks + * + * @param object Pointer to board descriptor, used as parameter when task created + */ +static void KeyTask(void * object); + +/* === Public variable definitions ============================================================= */ + +/* === Private variable definitions ============================================================ */ + +/** + * @brief Queue data to comunicate tasks + */ +QueueHandle_t actions; + +/* === Private function implementation ========================================================= */ + +void StopByError(board_t board, uint8_t code) { + // Signal error condition + GpioBitSet(board->led_rgb->red); + + // Show error code + GpioSetState(board->led_1, code & (1 << 0)); + GpioSetState(board->led_2, code & (1 << 1)); + GpioSetState(board->led_3, code & (1 << 2)); + + // Stop program execution + while (true) { + }; +} + +static void FlashTask(void * object) { + board_t board = object; + struct action_s action; + + while (true) { + xQueueReceive(actions, &action, portMAX_DELAY); + GpioBitToogle(board->led_rgb->blue); + + GpioBitSet(action.led); + vTaskDelay(pdMS_TO_TICKS(action.delay)); + GpioBitClear(action.led); + vTaskDelay(pdMS_TO_TICKS(action.delay)); + } +} + +static void KeyTask(void * object) { + board_t board = object; + bool current_state, last_state[4] = {false, false, false, false}; + struct action_s action; + + while (true) { + vTaskDelay(pdMS_TO_TICKS(150)); + + current_state = !GpioGetState(board->tec_1); + if ((current_state != last_state[0]) && (current_state)) { + } + last_state[0] = current_state; + + current_state = !GpioGetState(board->tec_2); + if ((current_state != last_state[1]) && (current_state)) { + action.led = board->led_1; + action.delay = 750; + xQueueSend(actions, &action, portMAX_DELAY); + } + last_state[1] = current_state; + + current_state = !GpioGetState(board->tec_3); + if ((current_state != last_state[2]) && (current_state)) { + action.led = board->led_2; + action.delay = 500; + xQueueSend(actions, &action, portMAX_DELAY); + } + last_state[2] = current_state; + + current_state = !GpioGetState(board->tec_4); + if ((current_state != last_state[3]) && (current_state)) { + action.led = board->led_3; + action.delay = 1000; + xQueueSend(actions, &action, portMAX_DELAY); + xQueueSend(actions, &action, portMAX_DELAY); + } + last_state[3] = current_state; + } +} + +/* === Public function implementation ========================================================= */ + +int main(void) { + /* Inicializaciones y configuraciones de dispositivos */ + board_t board = BoardCreate(); + + actions = xQueueCreate(4, sizeof(struct action_s)); + if (actions == NULL) { + StopByError(board, 0); + } + + /* Creación de las tareas */ + if (xTaskCreate(KeyTask, "Keys", 256, (void *)board, tskIDLE_PRIORITY + 2, NULL) != pdPASS) { + StopByError(board, 1); + } + if (xTaskCreate(FlashTask, "Flash", 256, (void *)board, tskIDLE_PRIORITY + 1, NULL) != pdPASS) { + StopByError(board, 2); + } + + /* Arranque del sistema operativo */ + vTaskStartScheduler(); + + /* vTaskStartScheduler solo retorna si se detiene el sistema operativo */ + while (true) { + } + + /* El valor de retorno es solo para evitar errores en el compilador*/ + return 0; +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/i2c/main.c b/examples/i2c/main.c new file mode 100644 index 0000000..5144065 --- /dev/null +++ b/examples/i2c/main.c @@ -0,0 +1,266 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** \brief EDU-CIAA-NXP board sample application + ** + ** \addtogroup samples Samples + ** \brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#include "chip.h" +#include + +/* === Macros definitions ====================================================================== */ + +#define LED_R_PORT 2 +#define LED_R_PIN 0 +#define LED_R_FUNC SCU_MODE_FUNC4 +#define LED_R_GPIO 5 +#define LED_R_BIT 0 + +#define LED_G_PORT 2 +#define LED_G_PIN 1 +#define LED_G_FUNC SCU_MODE_FUNC4 +#define LED_G_GPIO 5 +#define LED_G_BIT 1 + +#define LED_B_PORT 2 +#define LED_B_PIN 2 +#define LED_B_FUNC SCU_MODE_FUNC4 +#define LED_B_GPIO 5 +#define LED_B_BIT 2 + +#define LED_1_PORT 2 +#define LED_1_PIN 10 +#define LED_1_FUNC SCU_MODE_FUNC0 +#define LED_1_GPIO 0 +#define LED_1_BIT 14 + +#define LED_2_PORT 2 +#define LED_2_PIN 11 +#define LED_2_FUNC SCU_MODE_FUNC0 +#define LED_2_GPIO 1 +#define LED_2_BIT 11 + +#define LED_3_PORT 2 +#define LED_3_PIN 12 +#define LED_3_FUNC SCU_MODE_FUNC0 +#define LED_3_GPIO 1 +#define LED_3_BIT 12 + +#define I2C_RATE 100000 + +#define CHIP_ADDRESS 0x28 + +#define REG_MAIN_CTRL 0x00 + +/* === Private data type declarations ========================================================== */ + +/** + * @brief Enumeration with color sequence of RGB led + */ +typedef enum rgb_color_e { + LED_RED_ON = 0, + LED_RED_OFF, + LED_GREEN_ON, + LED_GREEN_OFF, + LED_BLUE_ON, + LED_BLUE_OFF, +} rgb_color_t; + +/* === Private variable declarations =========================================================== */ + +/* === Private function declarations =========================================================== */ + +/** + * @brief Function to configure pins and gpio bits used by board leds + */ +static void ConfigureLeds(void); + +/** + * @brief Function to configure pins and gpio bits used by board keys + */ +static void ConfigureKeys(void); + +/** + * @brief Function to generate a delay of approximately 100 ms + */ +static void Delay(void); + +/* === Public variable definitions ============================================================= */ + +/* === Private variable definitions ============================================================ */ + +/* === Private function implementation ========================================================= */ + +static void ConfigureLeds(void) { + Chip_SCU_PinMuxSet(LED_R_PORT, LED_R_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_R_FUNC); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_R_GPIO, LED_R_BIT, false); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_R_GPIO, LED_R_BIT, true); + + Chip_SCU_PinMuxSet(LED_G_PORT, LED_G_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_G_FUNC); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_G_GPIO, LED_G_BIT, false); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_G_GPIO, LED_G_BIT, true); + + Chip_SCU_PinMuxSet(LED_B_PORT, LED_B_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_B_FUNC); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_B_GPIO, LED_B_BIT, false); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_B_GPIO, LED_B_BIT, true); + + /******************/ + Chip_SCU_PinMuxSet(LED_1_PORT, LED_1_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_1_FUNC); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_1_GPIO, LED_1_BIT, false); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_1_GPIO, LED_1_BIT, true); + + Chip_SCU_PinMuxSet(LED_2_PORT, LED_2_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_2_FUNC); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_2_GPIO, LED_2_BIT, false); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_2_GPIO, LED_2_BIT, true); + + Chip_SCU_PinMuxSet(LED_3_PORT, LED_3_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_3_FUNC); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_3_GPIO, LED_3_BIT, false); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_3_GPIO, LED_3_BIT, true); +} + +static void ConfigureKeys(void) { + /* Inicialización del Puerto I2C */ + + // Configuracion de las lineas de SDA y SCL de la placa + Chip_SCU_I2C0PinConfig(I2C0_STANDARD_FAST_MODE); + // Inicializacion del periferico + Chip_I2C_Init(I2C0); + // Seleccion de velocidad del bus + Chip_I2C_SetClockRate(I2C0, I2C_RATE); + // Configuracion para que los eventos se resuelvan por polling + // (la otra opcion es por interrupcion) + Chip_I2C_SetMasterEventHandler(I2C0, Chip_I2C_EventHandlerPolling); + // ToDo: Verificar si se inicializó correctamente +} + +static void FlashLed(void) { + static int divisor = 0; + static rgb_color_t state = LED_BLUE_OFF; + + divisor++; + if (divisor == 5) { + divisor = 0; + state = (state + 1) % (LED_BLUE_OFF + 1); + + switch (state) { + case LED_RED_ON: + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_R_GPIO, LED_R_BIT, true); + break; + case LED_GREEN_ON: + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_G_GPIO, LED_G_BIT, true); + break; + case LED_BLUE_ON: + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_B_GPIO, LED_B_BIT, true); + break; + default: + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_R_GPIO, LED_R_BIT, false); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_G_GPIO, LED_G_BIT, false); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_B_GPIO, LED_B_BIT, false); + break; + } + } +} + +static uint8_t ReadKeys(void) { + static uint8_t result = 0; + + I2CM_XFER_T transfer; + uint8_t data[5]; + + data[0] = REG_MAIN_CTRL; + + // Prepara la lectura de los cuatro primeros registros + transfer.slaveAddr = CHIP_ADDRESS; + transfer.options = 0; + transfer.status = 0; + transfer.txBuff = &data[0]; + transfer.txSz = 1; + transfer.rxBuff = &data[1]; + transfer.rxSz = 4; + + if (Chip_I2CM_XferBlocking(LPC_I2C0, &transfer)) { + if (data[1] & 0x01) { + // Borrando el flag INT + data[1] = data[1] & 0xFE; + // Prepara la operación de escritura + transfer.txBuff = data; + transfer.txSz = 2; + transfer.rxBuff = 0; + transfer.rxSz = 0; + // Borra los flags del integrado + Chip_I2CM_XferBlocking(LPC_I2C0, &transfer); + } + result = data[4]; + } + return result; +} + +static void Delay(void) { + for (int index = 0; index < 100; index++) { + for (int delay = 0; delay < 2500; delay++) { + __asm("NOP"); + } + } +} + +/* === Public function implementation ========================================================== */ + +int main(void) { + uint8_t teclas; + bool actual, anterior = false; + + ConfigureLeds(); + ConfigureKeys(); + + while (true) { + teclas = ReadKeys(); + + actual = teclas & 0x01; + if ((actual) && (!anterior)) { + Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, LED_2_GPIO, LED_2_BIT); + } + anterior = actual; + + if (teclas & 0x02) { + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_3_GPIO, LED_3_BIT, true); + } + if (teclas & 0x04) { + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_3_GPIO, LED_3_BIT, false); + } + + FlashLed(); + Delay(); + } + + return 0; +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/pixel/makefile b/examples/pixel/makefile new file mode 100644 index 0000000..2b3579f --- /dev/null +++ b/examples/pixel/makefile @@ -0,0 +1,5 @@ +BOARD ?= edu-ciaa-nxp +VERBOSE=y +MUJU ?= ../../ + +include $(MUJU)/module/base/makefile diff --git a/examples/pixel/src/main.c b/examples/pixel/src/main.c new file mode 100644 index 0000000..42188d6 --- /dev/null +++ b/examples/pixel/src/main.c @@ -0,0 +1,339 @@ +/************************************************************************************************ +Copyright (c) 2022-2023, Laboratorio de Microprocesadores +Facultad de Ciencias Exactas y Tecnología, Universidad Nacional de Tucumán +https://www.microprocesadores.unt.edu.ar/ + +Copyright (c) 2022-2023, Esteban Volentini + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +SPDX-License-Identifier: MIT +*************************************************************************************************/ + +/** \brief EDU-CIAA-NXP board sample application + ** + ** \addtogroup samples Samples + ** \brief Samples applications with MUJU Framwork + ** @{ */ + +/* === Headers files inclusions =============================================================== */ + +#ifndef EDU_CIAA_NXP +#error "This program can only be compiled for the EDU-CIAA-NXP board" +#endif + +#include "board.h" +#include "chip.h" +#include + +/* === Macros definitions ====================================================================== */ + +#define LED_R_PORT 2 +#define LED_R_PIN 0 +#define LED_R_FUNC SCU_MODE_FUNC4 +#define LED_R_GPIO 5 +#define LED_R_BIT 0 + +#define LED_G_PORT 2 +#define LED_G_PIN 1 +#define LED_G_FUNC SCU_MODE_FUNC4 +#define LED_G_GPIO 5 +#define LED_G_BIT 1 + +#define LED_B_PORT 2 +#define LED_B_PIN 2 +#define LED_B_FUNC SCU_MODE_FUNC4 +#define LED_B_GPIO 5 +#define LED_B_BIT 2 + +#define LED_1_PORT 2 +#define LED_1_PIN 10 +#define LED_1_FUNC SCU_MODE_FUNC0 +#define LED_1_GPIO 0 +#define LED_1_BIT 14 + +#define LED_2_PORT 2 +#define LED_2_PIN 11 +#define LED_2_FUNC SCU_MODE_FUNC0 +#define LED_2_GPIO 1 +#define LED_2_BIT 11 + +#define LED_3_PORT 2 +#define LED_3_PIN 12 +#define LED_3_FUNC SCU_MODE_FUNC0 +#define LED_3_GPIO 1 +#define LED_3_BIT 12 + +#define TEC_1_PORT 1 +#define TEC_1_PIN 0 +#define TEC_1_FUNC SCU_MODE_FUNC0 +#define TEC_1_GPIO 0 +#define TEC_1_BIT 4 + +#define TEC_2_PORT 1 +#define TEC_2_PIN 1 +#define TEC_2_FUNC SCU_MODE_FUNC0 +#define TEC_2_GPIO 0 +#define TEC_2_BIT 8 + +#define TEC_3_PORT 1 +#define TEC_3_PIN 2 +#define TEC_3_FUNC SCU_MODE_FUNC0 +#define TEC_3_GPIO 0 +#define TEC_3_BIT 9 + +#define TEC_4_PORT 1 +#define TEC_4_PIN 6 +#define TEC_4_FUNC SCU_MODE_FUNC0 +#define TEC_4_GPIO 1 +#define TEC_4_BIT 9 + +/* === Private data type declarations ========================================================== */ + +/** + * @brief Enumeration with color sequence of RGB led + */ +typedef enum rgb_color_e { + LED_RED_ON = 0, + LED_RED_OFF, + LED_GREEN_ON, + LED_GREEN_OFF, + LED_BLUE_ON, + LED_BLUE_OFF, +} rgb_color_t; + +/* === Private variable declarations =========================================================== */ + +/* === Private function declarations =========================================================== */ + +/** + * @brief Function to configure pins and gpio bits used by board leds + */ +static void ConfigureLeds(void); + +/** + * @brief Function to configure pins and gpio bits used by board keys + */ +static void ConfigureKeys(void); + +/** + * @brief Function to flash RGB led in sequence + */ +static void FlashLed(void); + +/** + * @brief Function to switch on and off a led with two keys + */ +static void SwitchLed(void); + +/** + * @brief Function to switch on and off a led with a single key + */ +static void ToggleLed(void); + +/** + * @brief Function to turn on a led while a key is pressed + */ +static void TestLed(void); + +/** + * @brief Function to generate a delay of approximately 100 ms + */ +static void Delay(void); + +/* === Public variable definitions ============================================================= */ + +/* === Private variable definitions ============================================================ */ + +/* === Private function implementation ========================================================= */ + +void PixelInit(void) { + Chip_SCU_PinMuxSet(1, 4, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | 5); + Chip_SSP_Init(LPC_SSP1); + Chip_SSP_SetBitRate(LPC_SSP1, 8000000); + Chip_SSP_Enable(LPC_SSP1); +} + +void PixelReset(void) { + Chip_SSP_SendFrame(LPC_SSP1, 0xFF); + for (int delay = 0; delay < 1000; delay++) { + __asm("NOP"); + } +} + +void PixelSend(uint8_t data[], uint8_t size) { + uint8_t sending = 0; + int index = 0; + int shift = 0; + + PixelReset(); + while (index < size) { + sending = data[index]; + shift = 0; + while (shift < 8) { + if (Chip_SSP_GetStatus(LPC_SSP1, SSP_STAT_TNF)) { + if (sending & 0x80) { + Chip_SSP_SendFrame(LPC_SSP1, 0xFC); + } else { + Chip_SSP_SendFrame(LPC_SSP1, 0xE0); + } + shift++; + sending <<= 1; + } + } + index++; + } + while (!Chip_SSP_GetStatus(LPC_SSP1, SSP_STAT_TFE)) { + __asm("NOP"); + } +} + +static void ConfigureLeds(void) { + Chip_SCU_PinMuxSet(LED_R_PORT, LED_R_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_R_FUNC); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_R_GPIO, LED_R_BIT, false); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_R_GPIO, LED_R_BIT, true); + + Chip_SCU_PinMuxSet(LED_G_PORT, LED_G_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_G_FUNC); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_G_GPIO, LED_G_BIT, false); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_G_GPIO, LED_G_BIT, true); + + Chip_SCU_PinMuxSet(LED_B_PORT, LED_B_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_B_FUNC); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_B_GPIO, LED_B_BIT, false); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_B_GPIO, LED_B_BIT, true); + + /******************/ + Chip_SCU_PinMuxSet(LED_1_PORT, LED_1_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_1_FUNC); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_1_GPIO, LED_1_BIT, false); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_1_GPIO, LED_1_BIT, true); + + Chip_SCU_PinMuxSet(LED_2_PORT, LED_2_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_2_FUNC); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_2_GPIO, LED_2_BIT, false); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_2_GPIO, LED_2_BIT, true); + + Chip_SCU_PinMuxSet(LED_3_PORT, LED_3_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_3_FUNC); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_3_GPIO, LED_3_BIT, false); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_3_GPIO, LED_3_BIT, true); +} + +static void ConfigureKeys(void) { + Chip_SCU_PinMuxSet(TEC_1_PORT, TEC_1_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_PULLUP | TEC_1_FUNC); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, TEC_1_GPIO, TEC_1_BIT, false); + + Chip_SCU_PinMuxSet(TEC_2_PORT, TEC_2_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_PULLUP | TEC_2_FUNC); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, TEC_2_GPIO, TEC_2_BIT, false); + + Chip_SCU_PinMuxSet(TEC_3_PORT, TEC_3_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_PULLUP | TEC_3_FUNC); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, TEC_3_GPIO, TEC_3_BIT, false); + + Chip_SCU_PinMuxSet(TEC_4_PORT, TEC_4_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_PULLUP | TEC_4_FUNC); + Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, TEC_4_GPIO, TEC_4_BIT, false); +} + +static void FlashLed(void) { + static int divisor = 0; + static rgb_color_t state = LED_BLUE_OFF; + + divisor++; + if (divisor == 5) { + divisor = 0; + state = (state + 1) % (LED_BLUE_OFF + 1); + + switch (state) { + case LED_RED_ON: + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_R_GPIO, LED_R_BIT, true); + break; + case LED_GREEN_ON: + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_G_GPIO, LED_G_BIT, true); + break; + case LED_BLUE_ON: + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_B_GPIO, LED_B_BIT, true); + break; + default: + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_R_GPIO, LED_R_BIT, false); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_G_GPIO, LED_G_BIT, false); + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_B_GPIO, LED_B_BIT, false); + break; + } + } +} + +static void SwitchLed(void) { + if (Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, TEC_1_GPIO, TEC_1_BIT) == 0) { + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_1_GPIO, LED_1_BIT, true); + } + if (Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, TEC_2_GPIO, TEC_2_BIT) == 0) { + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_1_GPIO, LED_1_BIT, false); + } +} + +static void ToggleLed(void) { + static const uint8_t data[][3] = { + // {255, 255, 255}, {255, 0, 0}, {0, 255, 0}, {0, 0, 255}, + // {255, 255, 0}, {0, 255, 255}, {255, 0, 255}, {255, 255, 255}, + {255, 255, 255}, {127, 127, 127}, {63, 63, 63}, {31, 31, 31}, + {15, 15, 15}, {7, 7, 7}, {3, 3, 3}, {1, 1, 1}, + }; + + static bool last_state = false; + bool current_state; + + current_state = (Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, TEC_3_GPIO, TEC_3_BIT) == 0); + if ((current_state) && (!last_state)) { + Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, LED_2_GPIO, LED_2_BIT); + PixelSend(data, sizeof(data)); + } + last_state = current_state; +} + +static void TestLed(void) { + if (Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, TEC_4_GPIO, TEC_4_BIT) == 0) { + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_3_GPIO, LED_3_BIT, true); + } else { + Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_3_GPIO, LED_3_BIT, false); + } +} + +static void Delay(void) { + for (int index = 0; index < 100; index++) { + for (int delay = 0; delay < 25000; delay++) { + __asm("NOP"); + } + } +} +/* === Public function implementation ========================================================== */ + +int main(void) { + BoardSetup(); + ConfigureLeds(); + ConfigureKeys(); + + PixelInit(); + + while (true) { + FlashLed(); + SwitchLed(); + ToggleLed(); + TestLed(); + + Delay(); + } + + return 0; +} + +/* === End of documentation ==================================================================== */ + +/** @} End of module definition for doxygen */ diff --git a/examples/poncho/inc/config.h b/examples/poncho/inc/config.h new file mode 100644 index 0000000..f5e9e78 --- /dev/null +++ b/examples/poncho/inc/config.h @@ -0,0 +1,151 @@ +/* Copyright 2016, Laboratorio de Microprocesadores + * Facultad de Ciencias Exactas y Tecnología + * Universidad Nacional de Tucuman + * http://www.microprocesadores.unt.edu.ar/ + * Copyright 2016, Esteban Volentini + * Copyright 2016, Matias Schida + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef CONFIG_H +#define CONFIG_H + +/* === Inclusiones de archivos externos ======================================================== */ +#include "stdint.h" +#include "chip.h" + +/* === Cabecera C++ ============================================================================ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* === Definicion y Macros ===================================================================== */ + +/** Señales de Control Display 7 Segmentos **/ +#define D7_1 LPC_GPIO_T->B[0][0] +#define D7_2 LPC_GPIO_T->B[0][1] +#define D7_3 LPC_GPIO_T->B[0][2] +#define D7_4 LPC_GPIO_T->B[0][3] +#define D7_A LPC_GPIO_T->B[2][0] +#define D7_B LPC_GPIO_T->B[2][1] +#define D7_C LPC_GPIO_T->B[2][2] +#define D7_D LPC_GPIO_T->B[2][3] +#define D7_E LPC_GPIO_T->B[2][4] +#define D7_F LPC_GPIO_T->B[2][5] +#define D7_G LPC_GPIO_T->B[2][6] +#define D7_P LPC_GPIO_T->B[5][16] + +#define Write_D7_1(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 0, (value))) +#define Write_D7_2(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 1, (value))) +#define Write_D7_3(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 2, (value))) +#define Write_D7_4(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 3, (value))) +#define Write_D7_A(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 2, 0, (value))) +#define Write_D7_B(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 2, 1, (value))) +#define Write_D7_C(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 2, 2, (value))) +#define Write_D7_D(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 2, 3, (value))) +#define Write_D7_E(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 2, 4, (value))) +#define Write_D7_F(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 2, 5, (value))) +#define Write_D7_G(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 2, 6, (value))) +#define Write_D7_P(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) + +/** Señales de control Display LCD**/ +#define LCD_0 LPC_GPIO_T->B[3][4] +#define LCD_1 LPC_GPIO_T->B[0][5] +#define LCD_2 LPC_GPIO_T->B[3][6] +#define LCD_3 LPC_GPIO_T->B[0][7] +#define LCD_RS LPC_GPIO_T->B[3][3] +#define LCD_E LPC_GPIO_T->B[3][8] +#define LCD_BAK LPC_GPIO_T->B[3][13] +#define Write_LCD_0(value)(Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_LCD_1(value)(Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_LCD_2(value)(Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_LCD_3(value)(Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_LCD_RS(value)(Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_LCD_E(value)(Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_LCD_BAK(value)(Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) + +/** Señales de Control Buzzer **/ +#define BUZZER LPC_GPIO_T->B[3][14] +#define Write_BUZZER(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) + +/** Señales de Control RS-232 **/ +#define RS232_TX LPC_GPIO_T->B[5][3] +#define RS232_RX LPC_GPIO_T->B[5][4] +#define Write_RS232_TX(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_RS232_R(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) + +/** Señales de Control Teclas **/ +#define BACEPF LPC_GPIO_T->B[5][8] +#define BCANCF LPC_GPIO_T->B[5][9] +#define F1F LPC_GPIO_T->B[5][12] +#define F2F LPC_GPIO_T->B[5][13] +#define F3F LPC_GPIO_T->B[5][14] +#define F4F LPC_GPIO_T->B[5][15] +#define Write_BACEPF(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_BCANCF(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_F1F(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_F2F(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_F3F(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_F4F(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) + +/** Señales de Control Led RGB **/ +#define LED5R LPC_GPIO_T->B[0][0] +#define LED5G LPC_GPIO_T->B[0][0] +#define LED5B LPC_GPIO_T->B[0][0] +#define Write_LED5R(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_LED5G(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_LED5B(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) + +/** Señales de Control de Teclado Numérico **/ +#define F_EN LPC_GPIO_T->B[3][15] +#define C1 LPC_GPIO_T->B[0][12] +#define C2 LPC_GPIO_T->B[0][13] +#define C3 LPC_GPIO_T->B[0][15] +#define Write_F_EN(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_C1(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_C2(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) +#define Write_C3(value) (Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16,(value)) + +/* Configura la liberia de display en modo 4 bits */ +#define LCD_DATA_BITS 4 + +#define lcdWriteEnable(valor) Chip_GPIO_SetPinState(LPC_GPIO_PORT, 2, 8, valor) +#define lcdRegisterSelect(valor) Chip_GPIO_SetPinState(LPC_GPIO_PORT, 3, 3, valor) +#define lcdWriteDataBits(valor) \ + Chip_GPIO_ClearValue(LPC_GPIO_PORT, 3, 0xF0); \ + Chip_GPIO_SetValue(LPC_GPIO_PORT, 3, valor & 0xF0); + +/* === Ciere de documentacion ================================================================== */ +#ifdef __cplusplus +} +#endif + +/** @} Final de la definición del modulo para doxygen */ + +#endif /* CONFIG_H */ diff --git a/examples/poncho/inc/display.h b/examples/poncho/inc/display.h new file mode 100644 index 0000000..de1120b --- /dev/null +++ b/examples/poncho/inc/display.h @@ -0,0 +1,112 @@ +/* Copyright 2016, Laboratorio de Microprocesadores + * Facultad de Ciencias Exactas y Tecnología + * Universidad Nacional de Tucuman + * http://www.microprocesadores.unt.edu.ar/ + * Copyright 2016, Esteban Volentini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef DISPLAY_H +#define DISPLAY_H + +/** \brief Manejo de pantallas alfanumericas + ** + ** Manejo de pantallas alfanumericas de texto basadas en el controlador HD44780. La libreria + ** soporta el manejo del display con 4 u 8 lineas de datos y sin la linea READ. + ** + ** \addtogroup lcd Pantalla LCD + ** \brief Manejo de pantallas LCD alfanumericas + ** @{ */ + +/* === Inclusiones de archivos externos ======================================================== */ +#include "stdint.h" +#include "config.h" + +/* === Cabecera C++ ============================================================================ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* === Definicion y Macros ===================================================================== */ +//! Configuracion del modo de trabajo en 4 u 8 bits +#ifndef LCD_DATA_BITS +#define LCD_DATA_BITS 8 +#else +#if (LCD_DATA_BITS != 4) && (LCD_DATA_BITS != 8) +#error Only 4 or 8 are valid values to LCD_DATA_BITS macro +#endif +#endif + +/* == Declaraciones de tipos de datos ========================================================== */ + +//! Registros internos del control de la pantalla lcd +typedef enum lcd_register_e { + LCD_CMD_REG = 0, //!< Registro de comandos (Linea RS igual a 0) + LCD_DATA_REG = 1, //!< Registro de datos (Linea RS igual a 1) +} lcd_register_t; + +/* === Declaraciones de variables externas ===================================================== */ + +/* === Declaraciones de funciones externas ===================================================== */ +/*! + * @brief Escribe un byte en el registro de comandos o de datos del LCD + * @param[in] command Indica si se escribe en el registro de comandos o el de datos + * @param[in] data Dato a escribir en el registro + */ +void lcdWriteData(lcd_register_t command, uint8_t data); + +/*! + * Inicializa el puerto y el display enviando los comandos adecuados + */ +void lcdInit(void); + +/*! + * @brief Lleva el cursor a una posicion especifica de la pantalla + * @param[in] row Numero de fila en la que se fija el cursor + * @param[in] col Numero de columna en la que se fija el cursor + */ +void lcdAtPos(uint8_t row, uint8_t col); + +//! Borra la pantalla y lleva el cursor la posicion inicial +void lcdClear(void); + +/*! + * @brief Escribe una cadena de texto a partir de la posicion actual del cursor + * @param[in] text Cadena de texto a escribir terminada con caracter null + */ +void lcdWriteString(char * text); + +/* === Ciere de documentacion ================================================================== */ +#ifdef __cplusplus +} +#endif + +/** @} Final de la definición del modulo para doxygen */ + +#endif /* DISPLAY_H */ diff --git a/examples/poncho/makefile b/examples/poncho/makefile new file mode 100644 index 0000000..2b3579f --- /dev/null +++ b/examples/poncho/makefile @@ -0,0 +1,5 @@ +BOARD ?= edu-ciaa-nxp +VERBOSE=y +MUJU ?= ../../ + +include $(MUJU)/module/base/makefile diff --git a/examples/poncho/src/display.c b/examples/poncho/src/display.c new file mode 100644 index 0000000..b189ed4 --- /dev/null +++ b/examples/poncho/src/display.c @@ -0,0 +1,157 @@ +/* Copyright 2016, Laboratorio de Microprocesadores + * Facultad de Ciencias Exactas y Tecnología + * Universidad Nacional de Tucuman + * http://www.microprocesadores.unt.edu.ar/ + * Copyright 2016, Esteban Volentini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** \brief Manejo de pantallas alfanumericas + ** + ** Manejo de pantallas alfanumericas de texto basadas en el controlador HD44780. La libreria + ** soporta el manejo del display con 4 u 8 lineas de datos y sin la linea READ. + ** + ** \addtogroup lcd Pantalla LCD + ** \brief Manejo de pantallas LCD alfanumericas + ** @{ */ + +/* === Inclusiones de cabeceras ================================================================ */ +#include "display.h" +#define DELAY_TW 1 +#define DELAY_CMD 5 +/* === Definicion y Macros ===================================================================== */ +//! Macro para reemplazar a la funcion de delay +// #define usDelay(value) + +//! Macro para reemplazar a la funcion de delay +#define msDelay(value) + +/* === Declaraciones de tipos de datos internos ================================================ */ + +/* === Declaraciones de funciones internas ===================================================== */ + +/* === Definiciones de variables externas ====================================================== */ + +/* === Definiciones de funciones internas =====================================================- */ +void delay(int value) { + int index; + for (index = 1; index < value; index++) + ; +} + +void usDelay(int value) { + int index; + for (index = 1; index < value; index++) { + delay(1000); + } +} + +/* === Definiciones de funciones externas ====================================================== */ +void lcdWriteData(lcd_register_t destination, uint8_t data) { + + lcdRegisterSelect(destination); + lcdWriteEnable(1); + +#if (LCD_DATA_BITS == 4) + lcdWriteDataBits(data & 0xF0); + + delay(DELAY_TW); + lcdWriteEnable(0); + delay(DELAY_TW); + + lcdWriteEnable(1); + lcdWriteDataBits(data << 4); +#else + lcdWriteDataBits(data); +#endif + delay(DELAY_TW); + lcdWriteEnable(0); + delay(DELAY_TW); + /* + if (destination == LCD_CMD_REG) usDelay(1); + */ + usDelay(DELAY_CMD); +} + +void lcdInit(void) { + + // #if (LCD_DATA_BITS == 4) + // lcdRW = 0; + // lcdRS = 0; + + // lcdDataPortDir |= lcdDataMask; // Configuro los pines de Salida + + // lcdDataPort &= lcdPortMask; // Pongo a cero los bit de datos + // lcdDataPort |= (0x20 >> (4 - lcdDataPins)); + lcdRegisterSelect(LCD_CMD_REG); + lcdWriteEnable(1); + lcdWriteDataBits(0x20); + delay(DELAY_TW); + lcdWriteEnable(0); + delay(DELAY_TW); + + usDelay(DELAY_CMD); + + lcdWriteData(LCD_CMD_REG, 0x22); // 4 Bits de Datos, 2 Lineas, Caracteres de 5x7 + + lcdWriteData(LCD_CMD_REG, 0x28); // 4 Bits de Datos, 2 Lineas, Caracteres de 5x7 + + /* + lcdWriteData(LCD_CMD_REG, 0x28); // 4 Bits de Datos, 2 Lineas, Caracteres de 5x7 + #else + lcdWriteData(LCD_CMD_REG, 0x38); // 8 Bits de Datos, 2 Lineas, Caracteres de 5x7 + #endif + */ + lcdWriteData(LCD_CMD_REG, 0x0C); // Mostrar Display, Ocultar Cursor, Sin Intermitente + lcdWriteData(LCD_CMD_REG, 0x06); // Incrementar Direccion, Desplazar Cursor + lcdClear(); + lcdWriteData(LCD_DATA_REG, 'A'); +} + +void lcdAtPos(uint8_t row, uint8_t col) { + const static uint8_t firstCol[4] = {0x80, 0xC0, 0x94, 0xD4}; + lcdWriteData(LCD_CMD_REG, firstCol[row] + col); + usDelay(2); +} + +void lcdClear(void) { + // Borrar Pantalla + lcdWriteData(LCD_CMD_REG, 0x01); + usDelay(500); +} + +void lcdWriteString(char * text) { + while (*text != 0) { + lcdWriteData(LCD_DATA_REG, *text); + text++; + } +} +/* === Ciere de documentacion ================================================================== */ + +/** @} Final de la definición del modulo para doxygen */ diff --git a/examples/poncho/src/prueba.c b/examples/poncho/src/prueba.c new file mode 100644 index 0000000..6b38e8c --- /dev/null +++ b/examples/poncho/src/prueba.c @@ -0,0 +1,292 @@ +/* Copyright 2016, Laboratorio de Microprocesadores + * Facultad de Ciencias Exactas y Tecnología + * Universidad Nacional de Tucuman + * http://www.microprocesadores.unt.edu.ar/ + * Copyright 2016, Esteban Volentini + * Copyright 2016, Matias Giori + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** @brief Prueba de funcionamiento del poncho educativo + ** + ** Programa de prueba para los ponchos educativos desarrollados para las placas + ** EDU-CIAA por el Laboratorio de Microcontroladores de la Universidad Nacional + ** de Tucumán. + ** + ** @addtogroup test Pruebas de sistema + ** @brief Prueba de funcionamiento del poncho educativo + ** @{ */ + +/* === Inclusiones de cabeceras ================================================================ */ +#if (lpc4337 == CPU) +#include "chip.h" +#elif (mk60fx512vlq15 == CPU) +#error Por el momento este programa solo puede ser compilado para la EDU-CIAA-NXP +#endif + +#include "display.h" + +/* === Definicion y Macros ===================================================================== */ + +#define SCU_MODE_SAL (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS) +#define SCU_MODE_ENT (SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN) + +#define TECLA_SI (1 << 8) +#define TECLA_NO (1 << 9) +#define TECLA_F1 (1 << 15) +#define TECLA_F2 (1 << 14) +#define TECLA_F3 (1 << 13) +#define TECLA_F4 (1 << 12) + +#define apagarSegmentos() Chip_GPIO_ClearValue(LPC_GPIO_PORT, 2, 0x7F) +#define prenderSegmentos(mascara) Chip_GPIO_SetValue(LPC_GPIO_PORT, 2, (mascara)&0x7F) +#define apagarDigitos() Chip_GPIO_ClearValue(LPC_GPIO_PORT, 0, 0x0F) +#define prenderDigito(digito) Chip_GPIO_SetValue(LPC_GPIO_PORT, 0, (1 << (digito)) & 0x0F) +#define prenderPunto(valor) Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 16, valor) + +/* === Declaraciones de tipos de datos internos ================================================ */ + +/* === Declaraciones de funciones internas ===================================================== */ + +void configurarPuertos(void); + +void configurarInterrupcion(void); + +/* === Definiciones de variables internas ====================================================== */ +const uint8_t digitos[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x67}; + +uint8_t numero[4] = {0, 0, 0, 0}; + +/* === Definiciones de variables externas ====================================================== */ + +/* === Definiciones de funciones internas ====================================================== */ +void configurarDigitos() { + apagarDigitos(); + apagarSegmentos(); + prenderPunto(false); + + /* Pines de los digitos */ + Chip_SCU_PinMux(0, 0, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(0, 1, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(1, 15, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(1, 17, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_GPIO_SetDir(LPC_GPIO_PORT, 0, 0x0F, 1); + + /* Pines de los segmentos */ + Chip_SCU_PinMux(4, 0, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(4, 1, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(4, 2, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(4, 3, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(4, 4, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(4, 5, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(4, 6, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_GPIO_SetDir(LPC_GPIO_PORT, 2, 0x7F, 1); + + /* Pin del punto */ + Chip_SCU_PinMux(6, 8, SCU_MODE_SAL, SCU_MODE_FUNC4); + Chip_GPIO_SetDir(LPC_GPIO_PORT, 5, 0x10000, 1); +} + +void configurarLcd(void) { + lcdWriteEnable(0); + + /* Pines de datos y control */ + Chip_SCU_PinMux(6, 4, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(6, 5, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(6, 9, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(6, 10, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(6, 11, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(6, 12, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_GPIO_SetDir(LPC_GPIO_PORT, 2, 0x100, 1); + Chip_GPIO_SetDir(LPC_GPIO_PORT, 3, 0xF8, 1); + + lcdInit(); +} + +void configurarLeds(void) { + /* Puerto Led RGB */ + Chip_SCU_PinMux(2, 0, SCU_MODE_SAL, SCU_MODE_FUNC4); + Chip_SCU_PinMux(2, 1, SCU_MODE_SAL, SCU_MODE_FUNC4); + Chip_SCU_PinMux(2, 2, SCU_MODE_SAL, SCU_MODE_FUNC4); + Chip_GPIO_ClearValue(LPC_GPIO_PORT, 5, (1 << 0) | (1 << 1) | (1 << 2)); + Chip_GPIO_SetDir(LPC_GPIO_PORT, 5, (1 << 0) | (1 << 1) | (1 << 2), 1); + + /* Puerto Leds 1 a 3 */ + Chip_SCU_PinMux(2, 10, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(2, 11, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_SCU_PinMux(2, 12, SCU_MODE_SAL, SCU_MODE_FUNC0); + Chip_GPIO_ClearValue(LPC_GPIO_PORT, 0, (1 << 14)); + Chip_GPIO_ClearValue(LPC_GPIO_PORT, 1, (1 << 11) | (1 << 12)); + Chip_GPIO_SetDir(LPC_GPIO_PORT, 0, (1 << 14), true); + Chip_GPIO_SetDir(LPC_GPIO_PORT, 1, (1 << 11) | (1 << 12), true); +} + +void configurarTeclas(void) { + + /* Puerto Teclas 1 a 4 */ + Chip_SCU_PinMux(4, 8, SCU_MODE_ENT, SCU_MODE_FUNC4); + Chip_SCU_PinMux(4, 9, SCU_MODE_ENT, SCU_MODE_FUNC4); + Chip_SCU_PinMux(4, 10, SCU_MODE_ENT, SCU_MODE_FUNC4); + Chip_SCU_PinMux(6, 7, SCU_MODE_ENT, SCU_MODE_FUNC4); + Chip_GPIO_SetDir(LPC_GPIO_PORT, 4, (1 << 8) | (1 << 9) | (1 << 10), false); + Chip_GPIO_SetDir(LPC_GPIO_PORT, 6, (1 << 7), false); + + /* Puerto Teclas Aceptar y Cancelar */ + Chip_SCU_PinMux(3, 1, SCU_MODE_ENT, SCU_MODE_FUNC4); + Chip_SCU_PinMux(3, 2, SCU_MODE_ENT, SCU_MODE_FUNC4); + Chip_GPIO_SetDir(LPC_GPIO_PORT, 3, (1 << 1) | (1 << 2), false); +} + +void configurarRGB(void) { + /* Puerto Leds RGB */ + Chip_SCU_PinMux(1, 3, SCU_MODE_SAL, SCU_MODE_FUNC1); + Chip_SCU_PinMux(1, 4, SCU_MODE_SAL, SCU_MODE_FUNC1); + Chip_SCU_PinMux(1, 5, SCU_MODE_SAL, SCU_MODE_FUNC1); + + Chip_SCTPWM_Init(LPC_SCT); + Chip_SCTPWM_SetRate(LPC_SCT, 100000); + Chip_SCTPWM_SetOutPin(LPC_SCT, 1, 8); + Chip_SCTPWM_SetOutPin(LPC_SCT, 2, 9); + Chip_SCTPWM_SetOutPin(LPC_SCT, 3, 10); + Chip_SCTPWM_Start(LPC_SCT); +} + +void configurarPuertos(void) { + + // Chip_GPIO_SetValue(LPC_GPIO_PORT, 2, 0x7F); //prende todos los led + // Chip_GPIO_SetDir(LPC_GPIO_PORT, 2, 0x7F, 1); + + Chip_GPIO_SetValue(LPC_GPIO_PORT, 0, 0x1); + Chip_GPIO_ClearValue(LPC_GPIO_PORT, 0, 0xF); + Chip_GPIO_SetValue(LPC_GPIO_PORT, 0, 0x2); + Chip_GPIO_ClearValue(LPC_GPIO_PORT, 0, 0xF); + Chip_GPIO_SetValue(LPC_GPIO_PORT, 0, 0x4); + Chip_GPIO_ClearValue(LPC_GPIO_PORT, 0, 0xF); + Chip_GPIO_SetValue(LPC_GPIO_PORT, 0, 0x8); + Chip_GPIO_ClearValue(LPC_GPIO_PORT, 0, 0xF); + + /* todos los LED del display a 1 */ + /* multiplex a 0 */ + /* Chip_GPIO_SetDir(LPC_GPIO_PORT, port, mask, output); */ + // Chip_GPIO_SetDir(LPC_GPIO_PORT, 5, (1 << 0) | (1 << 1) | (1 << 2), 1); +} + +void configurarInterrupcion(void) { + asm volatile("cpsid i"); + + /* Activate SysTick */ + SystemCoreClockUpdate(); + SysTick_Config(SystemCoreClock / 10000); + + /* Update priority set by SysTick_Config */ + NVIC_SetPriority(SysTick_IRQn, (1 << __NVIC_PRIO_BITS) - 1); + + asm volatile("cpsie i"); +} + +void refrescarDigitos(void) { + static int activo = 0; + + activo = ((activo + 1) & 0x03); + apagarDigitos(); + apagarSegmentos(); + prenderSegmentos(digitos[numero[activo] & 0x0F]); + prenderDigito(3 - activo); +} + +int escanearTeclado(void) { + int pulsadas; + int actuales; + static int anteriores = 0; + + actuales = Chip_GPIO_ReadValue(LPC_GPIO_PORT, 5); + pulsadas = ((actuales ^ anteriores) & actuales); + anteriores = actuales; + + return pulsadas; +} + +/* === Definiciones de funciones externas ====================================================== */ +void SysTick_Handler(void) { + static int divisor = 0; + + divisor = (divisor + 1) % 10; + if (divisor == 0) { + refrescarDigitos(); + } +} + +int main(void) { + int pulsadas; + + configurarRGB(); + configurarLeds(); + configurarTeclas(); + configurarDigitos(); + configurarLcd(); + configurarInterrupcion(); + + while (1) { + pulsadas = escanearTeclado(); + if (pulsadas & TECLA_F1) { + numero[0] = (numero[0] + 1) % 10; + } + if (pulsadas & TECLA_F2) { + numero[1] = (numero[1] + 1) % 10; + } + if (pulsadas & TECLA_F3) { + numero[2] = (numero[2] + 1) % 10; + } + if (pulsadas & TECLA_F4) { + numero[3] = (numero[3] + 1) % 10; + } + if (pulsadas & TECLA_SI) { + numero[0] = 9; + numero[1] = 9; + numero[2] = 9; + numero[3] = 9; + } + if (pulsadas & TECLA_NO) { + numero[0] = 0; + numero[1] = 0; + numero[2] = 0; + numero[3] = 0; + } + Chip_SCTPWM_SetDutyCycle(LPC_SCT, 1, + Chip_SCTPWM_PercentageToTicks(LPC_SCT, numero[0] * numero[1])); + Chip_SCTPWM_SetDutyCycle(LPC_SCT, 2, + Chip_SCTPWM_PercentageToTicks(LPC_SCT, numero[0] * numero[2])); + Chip_SCTPWM_SetDutyCycle(LPC_SCT, 3, + Chip_SCTPWM_PercentageToTicks(LPC_SCT, numero[0] * numero[3])); + } + return 0; +} +/* === Ciere de documentacion ================================================================== */ + +/** @} Final de la definición del modulo para doxygen */ diff --git a/module/base/makefile b/module/base/makefile index d762bf8..d927f86 100644 --- a/module/base/makefile +++ b/module/base/makefile @@ -213,7 +213,7 @@ endef # Definition of directories variables # out dir # BUILD_DIR = $(PROJECT_DIR)/build -BUILD_DIR = build +BUILD_DIR ?= build # object dir OBJ_DIR = $(BUILD_DIR)/obj # lib dir