diff options
author | Paulo Borges <paulo.borges@openbossa.org> | 2013-11-26 23:34:36 -0300 |
---|---|---|
committer | Paulo Borges <paulo.borges@openbossa.org> | 2013-12-22 22:43:06 -0300 |
commit | 48523e19d22e82726d6b692185df33ed07a3eb4e (patch) | |
tree | 8012f091282aaa5c489705d68ca3506fd8d5691e | |
parent | 61065da10cd2cb8c3a27f1ee687a802acf48d2fc (diff) |
nrf51822: Implement log module
-rw-r--r-- | platform/nrf51822/Makefile.platform | 9 | ||||
-rw-r--r-- | platform/nrf51822/log.c | 115 | ||||
-rw-r--r-- | platform/nrf51822/nrf51822.h | 29 |
3 files changed, 151 insertions, 2 deletions
diff --git a/platform/nrf51822/Makefile.platform b/platform/nrf51822/Makefile.platform index e3600b6..13ff024 100644 --- a/platform/nrf51822/Makefile.platform +++ b/platform/nrf51822/Makefile.platform @@ -75,13 +75,18 @@ PLATFORM_LDFLAGS = -T$(SDK_TEMPLATE_PATH)/gcc/$(LINKER_SCRIPT) \ -mcpu=$(CPU) PLATFORM_SOURCE_PATHS = $(SDK_SOURCE_PATH) \ - $(SDK_SOURCE_PATH)/simple_uart \ + $(SDK_SOURCE_PATH)/app_common \ $(SDK_SOURCE_PATH)/nrf_delay \ $(SDK_TEMPLATE_PATH) \ $(SDK_TEMPLATE_PATH/gcc) \ $(PLATFORM_PATH) -PLATFORM_SOURCE_FILES = system_nrf51.c +PLATFORM_SOURCE_FILES = system_nrf51.c \ + app_uart.c \ + app_fifo.c \ + app_gpiote.c \ + nrf_delay.c \ + log.c PLATFORM_ASM_PATHS = $(SDK_TEMPLATE_PATH)/gcc diff --git a/platform/nrf51822/log.c b/platform/nrf51822/log.c new file mode 100644 index 0000000..1bcaf78 --- /dev/null +++ b/platform/nrf51822/log.c @@ -0,0 +1,115 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2013 Paulo B. de Oliveira Filho <pauloborgesfilho@gmail.com> + * Copyright (c) 2013 Claudio Takahasi <claudio.takahasi@gmail.com> + * Copyright (c) 2013 João Paulo Rechi Vita <jprvita@gmail.com> + * + * 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. + */ + +#include <stdint.h> +#include <stdint.h> +#include <stdarg.h> +#include <stdio.h> +#include <string.h> + +#include <app_uart.h> +#include <nrf_delay.h> +#include <boards.h> + +#include "nrf51822.h" +#include "log.h" + +#define BUFFER_LEN 128 +#define READY 0 +#define BUSY 1 + +static uint16_t pos; +static uint16_t len; +static uint8_t buffer[BUFFER_LEN]; +static uint8_t state; + +static __inline void tx_next_byte(void) +{ + if (pos == len) { + state = READY; + return; + } + + app_uart_put(buffer[pos++]); +} + +void log_print(const char *format, ...) +{ + va_list args; + + while (state == BUSY); + + va_start(args, format); + vsnprintf((char *) buffer, BUFFER_LEN, format, args); + va_end(args); + + pos = 0; + len = strlen((char *) buffer); + state = BUSY; + + tx_next_byte(); +} + +static void uart_evt_handler(app_uart_evt_t *p_app_uart_evt) +{ + switch (p_app_uart_evt->evt_type) { + case APP_UART_TX_EMPTY: + tx_next_byte(); + break; + + default: + break; + } +} + +int16_t log_init(void) +{ + uint32_t err_code; + + app_uart_comm_params_t params = { + RX_PIN_NUMBER, + TX_PIN_NUMBER, + RTS_PIN_NUMBER, + CTS_PIN_NUMBER, + APP_UART_FLOW_CONTROL_ENABLED, + false, + UART_BAUDRATE_BAUDRATE_Baud115200 + }; + + APP_UART_INIT(¶ms, 0, 0, uart_evt_handler, IRQ_PRIORITY_MEDIUM, + err_code); + + if (err_code != NRF_SUCCESS) + return -1; + + state = READY; + + /* Necessary to fully initialize the UART */ + nrf_delay_ms(1); + log_print("\r\n"); + + return 0; +}
\ No newline at end of file diff --git a/platform/nrf51822/nrf51822.h b/platform/nrf51822/nrf51822.h new file mode 100644 index 0000000..c1ccb90 --- /dev/null +++ b/platform/nrf51822/nrf51822.h @@ -0,0 +1,29 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2013 Paulo B. de Oliveira Filho <pauloborgesfilho@gmail.com> + * Copyright (c) 2013 Claudio Takahasi <claudio.takahasi@gmail.com> + * Copyright (c) 2013 João Paulo Rechi Vita <jprvita@gmail.com> + * + * 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. + */ + +#define IRQ_PRIORITY_HIGH 0 +#define IRQ_PRIORITY_MEDIUM 1 +#define IRQ_PRIORITY_LOW 2 |