-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81b2d4e
commit 48ccfee
Showing
5 changed files
with
376 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/************************************************************************************************ | ||
Copyright (c) 2023, Esteban Volentini <[email protected]> | ||
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 LEDS_H | ||
#define LEDS_H | ||
|
||
/** @file leds.h | ||
** @brief Definiciones de la biblioteca para manejo de leds | ||
**/ | ||
|
||
/* === Headers files inclusions ================================================================ */ | ||
|
||
#include <stdint.h> | ||
|
||
/* === Cabecera C++ ============================================================================ */ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/* === Public macros definitions =============================================================== */ | ||
|
||
/* === Public data type declarations =========================================================== */ | ||
|
||
/* === Public variable declarations ============================================================ */ | ||
|
||
/* === Public function declarations ============================================================ */ | ||
|
||
/** | ||
* @brief Función principal del sistema, se ejecuta al iniciar el programa | ||
* | ||
* @return int Valor de retorno, cero si esta todo bien, negativo si hay un error | ||
*/ | ||
int main(void); | ||
|
||
/** | ||
* @brief Función para configurar la biblioteca | ||
* | ||
* @remark Esta función debe ser llamada antes que cualquier otra función de la biblioteca | ||
* | ||
* @param puerto | ||
*/ | ||
void leds_init(uint16_t * puerto); | ||
|
||
/** | ||
* @brief Función para prender un led individual | ||
* | ||
* @param led Numero de led a prender (del 1 al 16) | ||
*/ | ||
void leds_turn_on(int led); | ||
|
||
/** | ||
* @brief Función para apagar un led inividual | ||
* | ||
* @param led Numero de led a apagar (del 1 al 16) | ||
*/ | ||
void leds_turn_off(int led); | ||
|
||
/* === End of documentation ==================================================================== */ | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* MAIN_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
--- | ||
# Notes: | ||
# Sample project C code is not presently written to produce a release artifact. | ||
# As such, release build options are disabled. | ||
# This sample, therefore, only demonstrates running a collection of unit tests. | ||
|
||
:project: | ||
:use_exceptions: FALSE | ||
:use_test_preprocessor: TRUE | ||
:use_auxiliary_dependencies: TRUE | ||
:build_root: build | ||
# :release_build: TRUE | ||
:test_file_prefix: test_ | ||
:which_ceedling: gem | ||
:ceedling_version: 0.31.1 | ||
:default_tasks: | ||
- test:all | ||
|
||
#:test_build: | ||
# :use_assembly: TRUE | ||
|
||
#:release_build: | ||
# :output: MyApp.out | ||
# :use_assembly: FALSE | ||
|
||
:environment: | ||
|
||
:extension: | ||
:executable: .out | ||
|
||
:paths: | ||
:test: | ||
- +:test/** | ||
- -:test/support | ||
:source: | ||
- src/** | ||
:include: | ||
- inc/** | ||
:support: | ||
- test/support | ||
:libraries: [] | ||
|
||
:defines: | ||
# in order to add common defines: | ||
# 1) remove the trailing [] from the :common: section | ||
# 2) add entries to the :common: section (e.g. :test: has TEST defined) | ||
:common: &common_defines [] | ||
:test: | ||
- *common_defines | ||
- TEST | ||
:test_preprocess: | ||
- *common_defines | ||
- TEST | ||
|
||
:cmock: | ||
:mock_prefix: mock_ | ||
:when_no_prototypes: :warn | ||
:enforce_strict_ordering: TRUE | ||
:plugins: | ||
- :ignore | ||
- :callback | ||
:treat_as: | ||
uint8: HEX8 | ||
uint16: HEX16 | ||
uint32: UINT32 | ||
int8: INT8 | ||
bool: UINT8 | ||
|
||
# Add -gcov to the plugins list to make sure of the gcov plugin | ||
# You will need to have gcov and gcovr both installed to make it work. | ||
# For more information on these options, see docs in plugins/gcov | ||
:gcov: | ||
:reports: | ||
- HtmlDetailed | ||
- Cobertura | ||
:gcovr: | ||
:html_medium_threshold: 75 | ||
:html_high_threshold: 90 | ||
:uncovered_ignore_list: [src/main.c] | ||
|
||
#:tools: | ||
# Ceedling defaults to using gcc for compiling, linking, etc. | ||
# As [:tools] is blank, gcc will be used (so long as it's in your system path) | ||
# See documentation to configure a given toolchain for use | ||
|
||
# LIBRARIES | ||
# These libraries are automatically injected into the build process. Those specified as | ||
# common will be used in all types of builds. Otherwise, libraries can be injected in just | ||
# tests or releases. These options are MERGED with the options in supplemental yaml files. | ||
:libraries: | ||
:placement: :end | ||
:flag: "-l${1}" | ||
:path_flag: "-L ${1}" | ||
:system: [] # for example, you might list 'm' to grab the math library | ||
:test: [] | ||
:release: [] | ||
|
||
:plugins: | ||
:load_paths: | ||
- "#{Ceedling.load_path}" | ||
:enabled: | ||
- stdout_pretty_tests_report | ||
- module_generator | ||
- gcov | ||
- junit_tests_report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/************************************************************************************************ | ||
Copyright (c) 2023, Esteban Volentini <[email protected]> | ||
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 leds.c | ||
** @brief Implementación de la biblioteca para manejo de leds | ||
**/ | ||
|
||
/* === Headers files inclusions =============================================================== */ | ||
|
||
#include "leds.h" | ||
|
||
/* === Macros definitions ====================================================================== */ | ||
|
||
//! Constante con el bit menos significativo en alto | ||
#define BIT_HIGH 1 | ||
|
||
//! Constante con la diferencia entre el numero de led y el numero de bit correspondiente | ||
#define LED_OFFSET 1 | ||
|
||
//! Constante para apagar todos los leds | ||
#define ALL_LED_OFF 0x00 | ||
|
||
/* === Private data type declarations ========================================================== */ | ||
|
||
/* === Private variable declarations =========================================================== */ | ||
|
||
//! Variable para almacenar el puntero al puerto de los leds | ||
static uint16_t * puntero; | ||
|
||
/* === Private function declarations =========================================================== */ | ||
|
||
/** | ||
* @brief Función para convertir el numero de led en una masca de bits | ||
* | ||
* @param led Numero de led que se desea manipular (del 1 al 16) | ||
* @return uint16_t Mascara con el bit correspondiente al led en 1 y el resto en 0 | ||
*/ | ||
static uint16_t led_to_mask(int led); | ||
|
||
/* === Public variable definitions ============================================================= */ | ||
|
||
/* === Private variable definitions ============================================================ */ | ||
|
||
/* === Private function implementation ========================================================= */ | ||
|
||
static uint16_t led_to_mask(int led) { | ||
return (BIT_HIGH << (led - LED_OFFSET)); | ||
} | ||
|
||
/* === Public function implementation ========================================================== */ | ||
|
||
void leds_init(uint16_t * puerto) { | ||
puntero = puerto; | ||
*puntero = ALL_LED_OFF; | ||
} | ||
|
||
void leds_turn_on(int led) { | ||
*puntero |= led_to_mask(led); | ||
} | ||
|
||
void leds_turn_off(int led) { | ||
*puntero &= ~led_to_mask(led); | ||
} | ||
|
||
/* === End of documentation ==================================================================== */ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/************************************************************************************************ | ||
Copyright (c) 2023, Esteban Volentini <[email protected]> | ||
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 test_leds.c | ||
** @brief Pruebas unitarias de la biblioteca para manejo de leds | ||
**/ | ||
|
||
//! @todo Prender todos los leds que estan apagados en una sola operación | ||
//! @todo Apagar todos los leds que ya estan prendidos | ||
//! @todo Prender leds que ya esten prendidos de antes | ||
//! @todo Apagar leds que ya esten apagados | ||
//! @todo Comprobar valores prohibidos | ||
//! @todo Comprobar los valores de limite | ||
|
||
/* === Headers files inclusions =============================================================== */ | ||
|
||
#include "leds.h" | ||
#include "unity.h" | ||
|
||
/* === Macros definitions ====================================================================== */ | ||
|
||
static const int LED = 3; | ||
|
||
/* === Private data type declarations ========================================================== */ | ||
|
||
/* === Private variable declarations =========================================================== */ | ||
|
||
static uint16_t leds_virtuales; | ||
|
||
/* === Private function declarations =========================================================== */ | ||
|
||
/* === Public variable definitions ============================================================= */ | ||
|
||
/* === Private variable definitions ============================================================ */ | ||
|
||
/* === Private function implementation ========================================================= */ | ||
|
||
/* === Public function implementation ========================================================== */ | ||
|
||
void setUp(void) { | ||
leds_init(&leds_virtuales); | ||
} | ||
|
||
//! @test Al iniciar el controlador todos los leds deben quedar apagados. | ||
void test_todos_los_leds_inician_apagados(void) { | ||
uint16_t leds_virtuales = 0xFF; | ||
leds_init(&leds_virtuales); | ||
TEST_ASSERT_EQUAL_UINT16(0x00, leds_virtuales); | ||
} | ||
|
||
/** | ||
* @test Con todos los leds apagados prender el led 3 y verificar que | ||
* efectivamente el bit 2 se pone en 1 y el resto de bit permanece en 0 | ||
*/ | ||
void test_prender_un_led(void) { | ||
leds_turn_on(LED); | ||
|
||
// El bit 2 está en alto | ||
TEST_ASSERT_BIT_HIGH(LED - 1, leds_virtuales); | ||
// Todos los otros bits estan en bajo | ||
TEST_ASSERT_BITS_LOW(~(1 << (LED - 1)), leds_virtuales); | ||
} | ||
|
||
/** | ||
* @test Apagar un led prendido y ver que efectivamente se apaga | ||
* y que el resto no cambia su estado. | ||
*/ | ||
void test_apagar_un_led(void) { | ||
leds_turn_on(LED); | ||
leds_turn_off(LED); | ||
|
||
// Todos los bits estan en bajo | ||
TEST_ASSERT_EQUAL_UINT16(0x00, leds_virtuales); | ||
} | ||
|
||
/** | ||
* @test Prender y apagar varios leds par comprobar el estado final de cada uno | ||
*/ | ||
void test_prender_y_apagar_varios_leds(void) { | ||
leds_turn_on(5); | ||
leds_turn_on(7); | ||
leds_turn_off(5); | ||
|
||
// El bit 6 está en alto y el resto en bajo | ||
TEST_ASSERT_EQUAL_UINT16(1 << (7 - 1), leds_virtuales); | ||
} | ||
/* === End of documentation ==================================================================== */ |