kopia lustrzana https://github.com/SP8EBC/ParaTNC
backlight control for davis base unit and first sketch of modbus rtu
rodzic
26fa8c00bf
commit
2f3e304b23
|
@ -66,7 +66,7 @@ all: ParaTNC.elf secondary-outputs
|
|||
ParaTNC.elf: $(OBJS) $(USER_OBJS)
|
||||
@echo 'Building target: $@'
|
||||
@echo 'Invoking: Cross ARM C++ Linker'
|
||||
arm-none-eabi-g++ -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -T mem.ld -T libs.ld -T sections.ld -nostartfiles -Xlinker --gc-sections -L"../ldscripts" -Wl,-Map,"ParaTNC.map" --specs=nano.specs -u _printf_float -o "ParaTNC.elf" $(OBJS) $(USER_OBJS) $(LIBS)
|
||||
arm-none-eabi-g++ -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -g3 -T mem.ld -T libs.ld -T sections.ld -nostartfiles -Xlinker --gc-sections -L"../ldscripts" -Wl,-Map,"ParaTNC.map" --specs=nano.specs -u _printf_float -o "ParaTNC.elf" $(OBJS) $(USER_OBJS) $(LIBS)
|
||||
@echo 'Finished building target: $@'
|
||||
@echo ' '
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ C_DEPS += \
|
|||
src/%.o: ../src/%.c
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross ARM C Compiler'
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ C_DEPS += \
|
|||
system/src/aprs/%.o: ../system/src/aprs/%.c
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross ARM C Compiler'
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ C_DEPS += \
|
|||
system/src/cmsis/%.o: ../system/src/cmsis/%.c
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross ARM C Compiler'
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ C_DEPS += \
|
|||
system/src/cortexm/%.o: ../system/src/cortexm/%.c
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross ARM C Compiler'
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ C_DEPS += \
|
|||
system/src/diag/%.o: ../system/src/diag/%.c
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross ARM C Compiler'
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ C_DEPS += \
|
|||
system/src/drivers/%.o: ../system/src/drivers/%.c
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross ARM C Compiler'
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
|
|
@ -36,14 +36,14 @@ CPP_DEPS += \
|
|||
system/src/newlib/%.o: ../system/src/newlib/%.cpp
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross ARM C++ Compiler'
|
||||
arm-none-eabi-g++ -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu++11 -fabi-version=0 -fno-exceptions -fno-rtti -fno-use-cxa-atexit -fno-threadsafe-statics -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
arm-none-eabi-g++ -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu++11 -fabi-version=0 -fno-exceptions -fno-rtti -fno-use-cxa-atexit -fno-threadsafe-statics -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
system/src/newlib/%.o: ../system/src/newlib/%.c
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross ARM C Compiler'
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ C_DEPS += \
|
|||
system/src/stm32f1-stdperiph/%.o: ../system/src/stm32f1-stdperiph/%.c
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross ARM C Compiler'
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -g3 -DDEBUG -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include/aprs" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -Wunused-function -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
|
|
@ -11,5 +11,7 @@
|
|||
#define DAVIS_OK 0
|
||||
#define DAVIS_NOT_AVALIABLE 1
|
||||
#define DAVIS_WRONG_CRC 2
|
||||
#define DAVIS_WRONG_PARAMETER 3
|
||||
#define DAVIS_GEN_FAIL 127
|
||||
|
||||
#endif /* INCLUDE_DAVIS_VANTAGE_DAVIS_RETVAL_DEF_H_ */
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#define SRL_TIMEOUT_ENABLE 1
|
||||
#define SRL_TIMEOUT_DISABLE 0
|
||||
|
||||
typedef uint8_t(*srl_rx_termination_callback_t)(uint8_t current_data, const uint8_t * const rx_buffer, uint16_t rx_bytes_counter);
|
||||
|
||||
typedef enum srlRxState {
|
||||
SRL_RX_NOT_CONFIG,
|
||||
SRL_RX_IDLE,
|
||||
|
@ -77,8 +79,15 @@ typedef struct srl_context_t {
|
|||
uint8_t srl_rx_lenght_param_addres;
|
||||
uint8_t srl_rx_lenght_param_modifier;
|
||||
|
||||
// this is a pointer to function which could be optionally called
|
||||
// after each byte received by the serial port
|
||||
// the value returned by this function determines if the receiving shall
|
||||
// be continued (if returned 0) or not (if returned 1)
|
||||
srl_rx_termination_callback_t srl_rx_term;
|
||||
|
||||
}srl_context_t;
|
||||
|
||||
|
||||
#define SRL_UNINITIALIZED 127
|
||||
#define SRL_OK 0
|
||||
#define SRL_DATA_TOO_LONG 1
|
||||
|
@ -120,6 +129,7 @@ uint8_t srl_wait_for_rx_completion_or_timeout(srl_context_t *ctx, uint8_t* outpu
|
|||
void srl_irq_handler(srl_context_t *ctx);
|
||||
uint8_t srl_receive_data(srl_context_t *ctx, int num, char start, char stop, char echo, char len_addr, char len_modifier);
|
||||
uint8_t srl_receive_data_with_instant_timeout(srl_context_t *ctx, int num, char start, char stop, char echo, char len_addr, char len_modifier);
|
||||
uint8_t srl_receive_data_with_callback(srl_context_t *ctx, srl_rx_termination_callback_t cbk);
|
||||
uint16_t srl_get_num_bytes_rxed(srl_context_t *ctx);
|
||||
uint8_t* srl_get_rx_buffer(srl_context_t *ctx);
|
||||
void srl_keep_timeout(srl_context_t *ctx);
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* rtu_frame_t.h
|
||||
*
|
||||
* Created on: 27.08.2020
|
||||
* Author: mateusz
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_MODBUS_RTU_RTU_FRAME_T_H_
|
||||
#define INCLUDE_MODBUS_RTU_RTU_FRAME_T_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define RTU_MAXIMUM_DATA_LN 64
|
||||
|
||||
typedef struct rtu_frame_t {
|
||||
uint8_t address;
|
||||
|
||||
uint8_t function;
|
||||
|
||||
uint8_t data[RTU_MAXIMUM_DATA_LN];
|
||||
|
||||
uint16_t crc;
|
||||
}rtu_frame_t;
|
||||
|
||||
#endif /* INCLUDE_MODBUS_RTU_RTU_FRAME_T_H_ */
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* rtu_parser.h
|
||||
*
|
||||
* Created on: 27.08.2020
|
||||
* Author: mateusz
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_MODBUS_RTU_RTU_PARSER_H_
|
||||
#define INCLUDE_MODBUS_RTU_RTU_PARSER_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint16_t rtu_parser_stream_crc(uint16_t previous_crc, uint8_t current_data);
|
||||
|
||||
#endif /* INCLUDE_MODBUS_RTU_RTU_PARSER_H_ */
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* rtu_serial_io.h
|
||||
*
|
||||
* Created on: 27.08.2020
|
||||
* Author: mateusz
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_MODBUS_RTU_RTU_SERIAL_IO_H_
|
||||
#define INCLUDE_MODBUS_RTU_RTU_SERIAL_IO_H_
|
||||
|
||||
|
||||
|
||||
#endif /* INCLUDE_MODBUS_RTU_RTU_SERIAL_IO_H_ */
|
|
@ -10,6 +10,8 @@
|
|||
#include <davis_vantage/davis_query_state_t.h>
|
||||
#include <davis_vantage/davis_qf_t.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define DAVIS_ACK 0x06
|
||||
|
||||
#define LOOP_PACKET_LN 99
|
||||
|
@ -49,6 +51,8 @@ uint8_t davis_loop_avaliable;
|
|||
static const char line_feed = '\n';
|
||||
static const char line_feed_return[] = {'\n', '\r'};
|
||||
static const char loop_command[] = "LOOP 1\n";
|
||||
static const char lamps_off[] = "LAMPS 0\n";
|
||||
static const char lamps_on[] = "LAMPS 1\n";
|
||||
|
||||
uint32_t davis_init(srl_context_t* srl_port) {
|
||||
|
||||
|
@ -302,10 +306,40 @@ uint32_t davis_leave_receiving_screen(void) {
|
|||
return retval;
|
||||
}
|
||||
|
||||
/** This function sends the "LAMPS" commands to the station base unit
|
||||
* which controls the backliht of main LCD screen. Warning! this call
|
||||
* has blocking I/O and waits until the transmission through RS232 port
|
||||
* finish
|
||||
*
|
||||
*
|
||||
*/
|
||||
uint32_t davis_control_backlight(uint8_t state) {
|
||||
|
||||
uint32_t retval = DAVIS_OK;
|
||||
|
||||
uint8_t serial_result = SRL_UNINITIALIZED;
|
||||
|
||||
// switch over desired backlight state
|
||||
if (state == 0) {
|
||||
serial_result = srl_send_data(davis_serial_context, (uint8_t*)lamps_off, 1, strlen(lamps_off), 0);
|
||||
}
|
||||
else if (state == 1) {
|
||||
serial_result = srl_send_data(davis_serial_context, (uint8_t*)lamps_on, 1, strlen(lamps_on), 0);
|
||||
|
||||
}
|
||||
else {
|
||||
retval = DAVIS_WRONG_PARAMETER;
|
||||
}
|
||||
|
||||
// check the transmission request result
|
||||
if (serial_result == SRL_OK) {
|
||||
// if it was OK wait until the transmission will finish
|
||||
srl_wait_for_tx_completion(davis_serial_context);
|
||||
}
|
||||
else {
|
||||
retval = DAVIS_GEN_FAIL;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
#include "drivers/serial.h"
|
||||
#include "drivers/gpio_conf.h"
|
||||
|
||||
//#define PORT USART1
|
||||
|
||||
|
||||
#include "station_config.h"
|
||||
#include "diag/Trace.h"
|
||||
|
||||
|
@ -30,42 +27,6 @@ uint8_t srl_usart2_tx_buffer[TX_BUFFER_2_LN] = {'\0'}; // dane do wys<79>ania do
|
|||
uint8_t srl_usart2_rx_buffer[RX_BUFFER_2_LN] = {'\0'}; // dane odebrane od zdalnego urz<72>dzenia
|
||||
#endif
|
||||
|
||||
//uint8_t *srl_tx_buf_pointer;
|
||||
//uint8_t *srl_rx_buf_pointer;
|
||||
//
|
||||
//uint16_t srl_rx_buf_ln = 0;
|
||||
//uint16_t srl_tx_buf_ln = 0;
|
||||
//
|
||||
//uint16_t srl_rx_bytes_counter = 0;
|
||||
//uint16_t srl_tx_bytes_counter = 0;
|
||||
//
|
||||
//uint16_t srl_rx_bytes_req = 0;
|
||||
//uint16_t srl_tx_bytes_req = 0;
|
||||
//
|
||||
//uint8_t srl_triggered_start = 0;
|
||||
//uint8_t srl_triggered_stop = 0;
|
||||
//
|
||||
//uint8_t srl_start_trigger = 0x00; // znak oznaczaj<61>cy pocz<63>tek istotnych danych do odbebrania
|
||||
//uint8_t srl_stop_trigger = 0x00; // znak oznaczaj<61>cy koniec istotnych danych do odebrania
|
||||
//
|
||||
//volatile uint8_t srl_garbage_storage;
|
||||
//
|
||||
//uint8_t srl_rx_timeout_enable = 0;
|
||||
//uint8_t srl_rx_timeout_waiting_enable = 0;
|
||||
//uint8_t srl_rx_timeout_calc_started = 0;
|
||||
//uint8_t srl_rx_timeout_waiting_calc_started = 0;
|
||||
//uint32_t srl_rx_timeout_trigger_value_in_msec = 0;
|
||||
//uint32_t srl_rx_start_time = 0;
|
||||
//uint32_t srl_rx_waiting_start_time = 0;
|
||||
//
|
||||
//srl_rx_state_t srl_rx_state = SRL_RX_NOT_CONFIG;
|
||||
//srl_tx_state_t srl_tx_state = SRL_TX_NOT_CONFIG;
|
||||
//
|
||||
//uint8_t srl_enable_echo = 0;
|
||||
//
|
||||
//uint8_t srl_rx_lenght_param_addres = 0;
|
||||
//uint8_t srl_rx_lenght_param_modifier = 0;
|
||||
|
||||
|
||||
void srl_init(
|
||||
srl_context_t *ctx,
|
||||
|
@ -182,7 +143,7 @@ uint8_t srl_send_data(srl_context_t *ctx, uint8_t* data, uint8_t mode, uint16_t
|
|||
if (internal_external == 0) {
|
||||
|
||||
// if data at the input is too long to fit in the buffer
|
||||
if (leng >= TX_BUFFER_1_LN)
|
||||
if (leng >= ctx->srl_rx_buf_ln)
|
||||
return SRL_DATA_TOO_LONG;
|
||||
|
||||
// setting a pointer to transmit buffer to the internal buffer inside the driver
|
||||
|
@ -237,7 +198,7 @@ uint8_t srl_start_tx(srl_context_t *ctx, short leng) {
|
|||
return SRL_BUSY;
|
||||
|
||||
// if data at the input is too long to fit in the buffer
|
||||
if (leng >= TX_BUFFER_1_LN)
|
||||
if (leng >= ctx->srl_rx_buf_ln)
|
||||
return SRL_DATA_TOO_LONG;
|
||||
|
||||
ctx->srl_tx_bytes_req = leng;
|
||||
|
@ -300,7 +261,7 @@ uint8_t srl_receive_data(srl_context_t *ctx, int num, char start, char stop, cha
|
|||
|
||||
//trace_printf("Serial:SrlReceiveData()\r\n");
|
||||
|
||||
if (num >= RX_BUFFER_1_LN)
|
||||
if (num >= ctx->srl_rx_buf_ln)
|
||||
return SRL_DATA_TOO_LONG;
|
||||
|
||||
memset(ctx->srl_rx_buf_pointer, 0x00, ctx->srl_rx_buf_ln);
|
||||
|
@ -352,7 +313,7 @@ uint8_t srl_receive_data_with_instant_timeout(srl_context_t *ctx, int num, char
|
|||
|
||||
//trace_printf("Serial:SrlReceiveData()\r\n");
|
||||
|
||||
if (num >= RX_BUFFER_1_LN)
|
||||
if (num >= ctx->srl_rx_buf_ln)
|
||||
return SRL_DATA_TOO_LONG;
|
||||
|
||||
memset(ctx->srl_rx_buf_pointer, 0x00, ctx->srl_rx_buf_ln);
|
||||
|
@ -401,7 +362,46 @@ uint8_t srl_receive_data_with_instant_timeout(srl_context_t *ctx, int num, char
|
|||
return SRL_OK;
|
||||
}
|
||||
|
||||
uint8_t srl_receive_data_with_callback(srl_context_t *ctx, srl_rx_termination_callback_t cbk) {
|
||||
uint8_t retval = SRL_OK;
|
||||
|
||||
if (ctx->srl_rx_state == SRL_RXING) {
|
||||
retval = SRL_BUSY;
|
||||
}
|
||||
else {
|
||||
// check if input pointers were set to something
|
||||
if (cbk == NULL || ctx == NULL) {
|
||||
retval = SRL_WRONG_PARAMS_COMBINATION;
|
||||
}
|
||||
else {
|
||||
// set the callback pointer within the context
|
||||
ctx->srl_rx_term = cbk;
|
||||
|
||||
// set the amount of bytes to be received as the size
|
||||
// of the receive buffer (minus one byte for safety).
|
||||
// it will be up to the callback function to terminate the receiving
|
||||
ctx->srl_rx_bytes_req = ctx->srl_rx_buf_ln - 1;
|
||||
|
||||
// clear the rx buffer
|
||||
memset(ctx->srl_rx_buf_pointer, 0x00, ctx->srl_rx_buf_ln);
|
||||
|
||||
ctx->srl_rx_bytes_counter = 0;
|
||||
|
||||
ctx->srl_rx_lenght_param_addres = 0;
|
||||
ctx->srl_rx_lenght_param_modifier = 0;
|
||||
|
||||
ctx->srl_triggered_start = 0;
|
||||
ctx->srl_triggered_stop = 0;
|
||||
ctx->srl_enable_echo = 0;
|
||||
|
||||
ctx->srl_rx_timeout_calc_started = 0;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void srl_irq_handler(srl_context_t *ctx) {
|
||||
|
||||
|
@ -465,6 +465,24 @@ void srl_irq_handler(srl_context_t *ctx) {
|
|||
|
||||
// moving buffer pointer forward
|
||||
ctx->srl_rx_bytes_counter++;
|
||||
|
||||
// check if termination callback pointer has been set
|
||||
if (ctx->srl_rx_term != NULL) {
|
||||
// if yes call it
|
||||
stop_rxing = ctx->srl_rx_term( ctx->srl_rx_buf_pointer[ctx->srl_rx_bytes_counter],
|
||||
ctx->srl_rx_buf_pointer,
|
||||
ctx->srl_rx_bytes_counter);
|
||||
|
||||
// and check the return value
|
||||
if (stop_rxing == 1) {
|
||||
// if this was the last byte of transmission switch the state
|
||||
// of receiving part to done
|
||||
ctx->srl_rx_state = SRL_RX_DONE;
|
||||
|
||||
ctx->srl_triggered_stop = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// if the user want the driver to stop receiving after certain is received
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* rtu_parser.c
|
||||
*
|
||||
* Created on: 27.08.2020
|
||||
* Author: mateusz
|
||||
*/
|
||||
|
||||
#include "./modbus_rtu/rtu_parser.h"
|
||||
|
||||
uint16_t rtu_parser_stream_crc(uint16_t previous_crc, uint8_t current_data) {
|
||||
int i;
|
||||
|
||||
previous_crc ^= (uint16_t)current_data;
|
||||
for (i = 0; i < 8; ++i) {
|
||||
if (previous_crc & 1)
|
||||
previous_crc = (previous_crc) ^ 0xA001;
|
||||
else
|
||||
previous_crc = (previous_crc >> 1);
|
||||
}
|
||||
|
||||
return previous_crc;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
/*
|
||||
* rtu_serial_io.c
|
||||
*
|
||||
* Created on: 27.08.2020
|
||||
* Author: mateusz
|
||||
*/
|
||||
|
||||
|
Ładowanie…
Reference in New Issue