From 18e9b4222de669afeaefd7236ddbedc77a2aaf2a Mon Sep 17 00:00:00 2001 From: pavl_g Date: Sun, 9 Oct 2022 23:30:37 +0200 Subject: [PATCH 1/9] NativeLibs: implemented libuart and an example --- HelloNativeLibs/README.md | 41 +++ HelloNativeLibs/avr/Hellouart/README.md | 0 HelloNativeLibs/avr/Hellouart/build/build.sh | 6 + .../avr/Hellouart/build/compile.sh | 51 +++ HelloNativeLibs/avr/Hellouart/build/upload.sh | 19 ++ .../avr/Hellouart/build/variables.sh | 30 ++ HelloNativeLibs/avr/Hellouart/libs/libuart.a | Bin 0 -> 15064 bytes .../avr/Hellouart/libs/libuart.map | 149 +++++++++ .../avr/Hellouart/output/libHelloUART.elf | Bin 0 -> 11012 bytes .../avr/Hellouart/output/libHelloUART.hex | 110 +++++++ .../avr/Hellouart/src/include/serial.h | 304 ++++++++++++++++++ .../avr/Hellouart/src/lib/hello_uart.cpp | 82 +++++ HelloNativeLibs/avr/libuart/.gitignore | 3 + HelloNativeLibs/avr/libuart/README.md | 17 + HelloNativeLibs/avr/libuart/build/build.sh | 6 + HelloNativeLibs/avr/libuart/build/compile.sh | 72 +++++ .../avr/libuart/build/variables.sh | 29 ++ HelloNativeLibs/avr/libuart/output/libuart.a | Bin 0 -> 15064 bytes .../avr/libuart/output/libuart.map | 149 +++++++++ .../avr/libuart/output/receiver_isr.c.o | Bin 0 -> 1148 bytes HelloNativeLibs/avr/libuart/output/start.c.o | Bin 0 -> 1076 bytes HelloNativeLibs/avr/libuart/output/stop.c.o | Bin 0 -> 968 bytes .../avr/libuart/output/transmitter_isr.c.o | Bin 0 -> 1204 bytes .../avr/libuart/output/udr_cprint.c.o | Bin 0 -> 992 bytes .../avr/libuart/output/udr_cprintln.c.o | Bin 0 -> 1164 bytes .../avr/libuart/output/udr_plain_io.c.o | Bin 0 -> 1192 bytes .../avr/libuart/output/udr_print.c.o | Bin 0 -> 1188 bytes .../avr/libuart/output/udr_println.c.o | Bin 0 -> 1176 bytes .../avr/libuart/output/udr_reset_isr.c.o | Bin 0 -> 1260 bytes .../avr/libuart/output/udr_sprint.c.o | Bin 0 -> 1052 bytes .../avr/libuart/output/udr_sprintln.c.o | Bin 0 -> 1132 bytes .../avr/libuart/src/include/serial.h | 304 ++++++++++++++++++ .../avr/libuart/src/lib/receiver_isr.c | 19 ++ HelloNativeLibs/avr/libuart/src/lib/start.c | 9 + HelloNativeLibs/avr/libuart/src/lib/stop.c | 6 + .../avr/libuart/src/lib/transmitter_isr.c | 20 ++ .../avr/libuart/src/lib/udr_cprint.c | 7 + .../avr/libuart/src/lib/udr_cprintln.c | 6 + .../avr/libuart/src/lib/udr_plain_io.c | 12 + .../avr/libuart/src/lib/udr_print.c | 12 + .../avr/libuart/src/lib/udr_println.c | 6 + .../avr/libuart/src/lib/udr_reset_isr.c | 21 ++ .../avr/libuart/src/lib/udr_sprint.c | 8 + .../avr/libuart/src/lib/udr_sprintln.c | 6 + 44 files changed, 1504 insertions(+) create mode 100644 HelloNativeLibs/README.md create mode 100644 HelloNativeLibs/avr/Hellouart/README.md create mode 100755 HelloNativeLibs/avr/Hellouart/build/build.sh create mode 100755 HelloNativeLibs/avr/Hellouart/build/compile.sh create mode 100755 HelloNativeLibs/avr/Hellouart/build/upload.sh create mode 100644 HelloNativeLibs/avr/Hellouart/build/variables.sh create mode 100755 HelloNativeLibs/avr/Hellouart/libs/libuart.a create mode 100644 HelloNativeLibs/avr/Hellouart/libs/libuart.map create mode 100755 HelloNativeLibs/avr/Hellouart/output/libHelloUART.elf create mode 100644 HelloNativeLibs/avr/Hellouart/output/libHelloUART.hex create mode 100644 HelloNativeLibs/avr/Hellouart/src/include/serial.h create mode 100644 HelloNativeLibs/avr/Hellouart/src/lib/hello_uart.cpp create mode 100644 HelloNativeLibs/avr/libuart/.gitignore create mode 100644 HelloNativeLibs/avr/libuart/README.md create mode 100755 HelloNativeLibs/avr/libuart/build/build.sh create mode 100755 HelloNativeLibs/avr/libuart/build/compile.sh create mode 100644 HelloNativeLibs/avr/libuart/build/variables.sh create mode 100755 HelloNativeLibs/avr/libuart/output/libuart.a create mode 100644 HelloNativeLibs/avr/libuart/output/libuart.map create mode 100644 HelloNativeLibs/avr/libuart/output/receiver_isr.c.o create mode 100644 HelloNativeLibs/avr/libuart/output/start.c.o create mode 100644 HelloNativeLibs/avr/libuart/output/stop.c.o create mode 100644 HelloNativeLibs/avr/libuart/output/transmitter_isr.c.o create mode 100644 HelloNativeLibs/avr/libuart/output/udr_cprint.c.o create mode 100644 HelloNativeLibs/avr/libuart/output/udr_cprintln.c.o create mode 100644 HelloNativeLibs/avr/libuart/output/udr_plain_io.c.o create mode 100644 HelloNativeLibs/avr/libuart/output/udr_print.c.o create mode 100644 HelloNativeLibs/avr/libuart/output/udr_println.c.o create mode 100644 HelloNativeLibs/avr/libuart/output/udr_reset_isr.c.o create mode 100644 HelloNativeLibs/avr/libuart/output/udr_sprint.c.o create mode 100644 HelloNativeLibs/avr/libuart/output/udr_sprintln.c.o create mode 100644 HelloNativeLibs/avr/libuart/src/include/serial.h create mode 100644 HelloNativeLibs/avr/libuart/src/lib/receiver_isr.c create mode 100644 HelloNativeLibs/avr/libuart/src/lib/start.c create mode 100644 HelloNativeLibs/avr/libuart/src/lib/stop.c create mode 100644 HelloNativeLibs/avr/libuart/src/lib/transmitter_isr.c create mode 100644 HelloNativeLibs/avr/libuart/src/lib/udr_cprint.c create mode 100644 HelloNativeLibs/avr/libuart/src/lib/udr_cprintln.c create mode 100644 HelloNativeLibs/avr/libuart/src/lib/udr_plain_io.c create mode 100644 HelloNativeLibs/avr/libuart/src/lib/udr_print.c create mode 100644 HelloNativeLibs/avr/libuart/src/lib/udr_println.c create mode 100644 HelloNativeLibs/avr/libuart/src/lib/udr_reset_isr.c create mode 100644 HelloNativeLibs/avr/libuart/src/lib/udr_sprint.c create mode 100644 HelloNativeLibs/avr/libuart/src/lib/udr_sprintln.c diff --git a/HelloNativeLibs/README.md b/HelloNativeLibs/README.md new file mode 100644 index 00000000..05c465b7 --- /dev/null +++ b/HelloNativeLibs/README.md @@ -0,0 +1,41 @@ +# Native Libraries development using GCC + + + +## Contents of this tutorial: +1) Static V.S. Dynamic Native libraries. +2) Simple project compilation using gcc for intel/arm processors V.S. avr-gcc. + + +## 1) Static V.S. Dynamic Native libraries: + +| `Objective` | `Static Native libraries` | `Dynamic Native libraries` | +|-------------|---------------------------|----------------------------| +| Definition | Are object files that includes all the sources for the target compiled project including the external included sources | Are object files that includes the project sources only +| Other names | Compile-time libraries | Shared or Runtime libraries | +| Time of linking | At the compile time, the static object files are linked to the project and compiled with the project sources to an executable file | At the runtime, the loader loads the runtime library | + +-------------------------------------------------------- +## 2) Simple project compilation using intel gcc V.S. avr-gcc: + +- Quick Overview: + +| `Compiling for intel/arm processors` | `Compiling for avr MCUs` | +|--------------------------------------|--------------------------| +| For intel/arm processors, it's far direct to compile object files and the obejct files are compiled into shared or dynamic libs by default unless specified `-static` compiler option explicitly. | Object files are compiled into static object files by default and the compiler don't support dynamic compilation | + +1) Compiling the project into a dynamic/shared (or runtime) library for intel processors: + + +2) Compiling the project into a static (or compile-time) library for intel processors: + + +3) Compiling the project into a dynamic/shared (or runtime) library for avr MCUs: + + +4) Compiling the project into a dynamic/shared (or runtime) library: + + + +- Analysis of the compiler command and command options: + diff --git a/HelloNativeLibs/avr/Hellouart/README.md b/HelloNativeLibs/avr/Hellouart/README.md new file mode 100644 index 00000000..e69de29b diff --git a/HelloNativeLibs/avr/Hellouart/build/build.sh b/HelloNativeLibs/avr/Hellouart/build/build.sh new file mode 100755 index 00000000..fae2af6b --- /dev/null +++ b/HelloNativeLibs/avr/Hellouart/build/build.sh @@ -0,0 +1,6 @@ +echo "Ccoffee Script starts" +echo "---------------------------------------------" +source compile.sh +source upload.sh +echo "---------------------------------------------" +echo "Ccoffee Script finishes" diff --git a/HelloNativeLibs/avr/Hellouart/build/compile.sh b/HelloNativeLibs/avr/Hellouart/build/compile.sh new file mode 100755 index 00000000..56855c06 --- /dev/null +++ b/HelloNativeLibs/avr/Hellouart/build/compile.sh @@ -0,0 +1,51 @@ +source variables.sh +export LC_ALL=C + +function addLibsTold() { + sudo ${AVR_HOME}'/bin/avr-ld' --library-path "${project}/libs" "${project}/libs/libuart" +} + +function compile() { + # addLibsTold + # attrs : dir to compile & sharedLib name + nativeSources=`find ${project}'/src/lib' -name '*.c' -o -name '*.cxx' -o -name '*.cpp' -o -name '*.c++'` + + # compile to ``.elf`` full program (Executable and Linkable format) + ${AVR_HOME}'/bin/avr-g++' -O2 -x c++ \ + -mmcu=${CHIP} ${nativeSources} \ + -I${AVR_HOME}'/avr/include' \ + -I${project}'/src/include' \ + -L"${project}/libs/" -l'uart' \ + -o ${output}'.elf' + + # get the elf32bit file from the object linked data -- the elf is the whole application + # ${AVR_HOME}'/bin/avr-g++' -mmcu=${CHIP} -O2 ${output}'.o' -L"${project}/libs/" -l'uart' -o ${output}'.elf' + + return $? +} + +function convertToHex() { + ${AVR_HOME}'/bin/avr-objcopy' -I 'elf32-avr' -O 'ihex' ${output}'.elf' ${output}'.hex' + return $? +} + +echo -e "${WHITE_C} --MajorTask@Compile : Compiling the project" + +echo -e ${RESET_Cs} + +if [[ ! `compile` -eq 0 ]]; then + echo -e "${RED_C} --MajorTask@Compile : Failed compiling sources, exits with errno500." + exit 500 +else + echo -e "${GREEN_C} --MajorTask@Compile : Compilation succeeded." +fi +echo -e ${RESET_Cs} + +echo -e "${WHITE_C} --MajorTask@Hexing : Creating Hex file" +if [[ ! `convertToHex` -eq 0 ]]; then + echo -e "${RED_C} --MajorTask@Hexing : Failed to create hex file, exits with errno600." + exit 600 +else + echo -e "${GREEN_C} --MajorTask@Hexing : Hex file created successfully." +fi +echo -e ${RESET_Cs} diff --git a/HelloNativeLibs/avr/Hellouart/build/upload.sh b/HelloNativeLibs/avr/Hellouart/build/upload.sh new file mode 100755 index 00000000..f0dcc326 --- /dev/null +++ b/HelloNativeLibs/avr/Hellouart/build/upload.sh @@ -0,0 +1,19 @@ +source variables.sh + +function prepare() { + sudo stty -F ${PORT} ${BAUD_RATE} +} + +function upload() { + sudo avrdude -c ${PROGRAMMER} -b${BAUD_RATE} -P${PORT} -p${CHIP_ALIAS} -F -U flash:w:${output}'.hex' + return $? +} +prepare +echo -e "${WHITE_C} --MajorTask@UploadingCode : Uploading Hex file" +if [[ ! `upload` -eq 0 ]]; then + echo -e "${RED_C} --MajorTask@UploadingCode : Failed to upload hex file, exits with errno700." + exit 700 +else + echo -e "${GREEN_C} --MajorTask@UploadingCode : Task finished." +fi +echo -e ${RESET_Cs} diff --git a/HelloNativeLibs/avr/Hellouart/build/variables.sh b/HelloNativeLibs/avr/Hellouart/build/variables.sh new file mode 100644 index 00000000..f382c36d --- /dev/null +++ b/HelloNativeLibs/avr/Hellouart/build/variables.sh @@ -0,0 +1,30 @@ +#** +#* Ccoffee Build tool, manual build, alpha-v1. +#* +#* @author pavl_g. +#*# + + +# define work directory +# 1) print the current working directory to a string value +pwd=`pwd` +project="${pwd%/*}" + +avr_examples_dir="${project%/*}" + +hello_native_libs="${avr_examples_dir%/*}" +# cut the working directory from its end by a one '/' delimiter again +rootProject="${hello_native_libs%/*}" +# pass the value of the dire + +clibName=('libHelloUART') +# AVR-DUDE properties +BAUD_RATE='57600' +PORT='/dev/ttyUSB0' +CHIP='atmega328p' +CHIP_ALIAS='m328' +PROGRAMMER='arduino' +# Common Variables contain colors +source ${rootProject}'/CommonVariables.sh' +AVR_HOME=${rootProject}'/avr8-gnu-toolchain-linux_x86_64' +output=${project}'/output/'${clibName} diff --git a/HelloNativeLibs/avr/Hellouart/libs/libuart.a b/HelloNativeLibs/avr/Hellouart/libs/libuart.a new file mode 100755 index 0000000000000000000000000000000000000000..8f7c35ab26a0d380866d910427c7a0aecefc365c GIT binary patch literal 15064 zcmeI3ZH!!18OP7iZM$77yIre5F?67n6vcVjm)TuXVQIUx#ZopcAU4F=?e3H=ncdmU z4p>0!R6vL}bZ3VO#t53A(WrqKqDF}nBSaHo`QQf<4IQE%_<(80G=@a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ne96k^%?`h;xKacjh?k;#D$44 zBefi+TBA2_33jn={FWQs9GY~y!d&iNU)xkvoHV8wYLCPAN^?ofAcD2Daa*@JG47||jXPm}MQ z56iV>uP=IS&7CnKA*!^*TLNDHUmK9&ptDl*$UM(+N=PTKi{{syMGBI*+D#*+nh|rs zdVh>+`sy>+q8>fnUobkY&Rp-6`t_!|Z_}nw)I%3EOr38n&hHRSo>blC(yJS%&{?le z6_ah86?7dr%Mdqp(e1$N_4ymueRs;~YAcMLrpJtfL&%pQudOe0tY#%Rpsd0)eAluf zUiO5O&{*c(!RTgjVYsL}?UIE5mgo-muuaiWh%tNbZQZe8D~_?Ke(W%FTFC6$MbM5_ z$L!QF)Pq|=PdFB`Z|>={<8!FJJ+!40H=v$Pbl(WI_HD+AJe3c&w$f$JD52}CnMXJJ z{q}E3wcprKQMRBzNGTP}sEX1#JFF;g*nVaz_q&?4?wyErE)EhURJ4l;l zHwt;;=~;L_I!irzCN$eny +#include +#include +#include + +#if defined (__AVR_ATmega32__) + +/** UCSRA register */ +# define REG_UCSRA UCSRA +# define BIT_RXC RXC +# define BIT_TXC TXC +# define BIT_UDRE UDRE +# define BIT_FE FE +# define BIT_PE PE +# define BIT_U2X U2X +# define BIT_MPCM MPCM + +/** UCSRB register */ +# define REG_UCSRB UCSRB +# define BIT_RXCIE RXCIE +# define BIT_TXCIE TXCIE +# define BIT_UDRIE UDRIE +# define BIT_RXEN RXEN +# define BIT_TXEN TXEN +# define BIT_UCSZ2 UCSZ2 +# define BIT_RXB8 RXB8 +# define BIT_TXB8 TXB8 + +/** UCSRC register */ +# define REG_UCSRC UCSRC +# define BIT_URSEL URSEL +# define BIT_UMSEL UMSEL +# define BIT_UPM0 UPM0 +# define BIT_UPM1 UPM1 +# define BIT_USBS USBS +# define BIT_UCSZ0 UCSZ0 +# define BIT_UCSZ1 UCSZ1 +# define BIT_UCPOL UCPOL + +# define REG_UBRR UBRR + +/** UBRRL register */ +# define REG_UBRRL UBRRL + +/** UBRRH register */ +# define REG_UBRRH UBRRH + +/** UDR register */ +# define REG_UDR UDR + +# define __vector_USART_RX USART_RXC_vect +# define __vector_USART_TX USART_TXC_vect + +#elif defined (__AVR_ATmega328P__) + +/** UCSRA register */ +# define REG_UCSRA UCSR0A +# define BIT_RXC RXC0 +# define BIT_TXC TXC0 +# define BIT_UDRE UDRE0 +# define BIT_FE FE0 +# define BIT_PE PE0 +# define BIT_U2X U2X0 +# define BIT_MPCM MPCM0 + +/** UCSRB register */ +# define REG_UCSRB UCSR0B +# define BIT_RXCIE RXCIE0 +# define BIT_TXCIE TXCIE0 +# define BIT_UDRIE UDRIE0 +# define BIT_RXEN RXEN0 +# define BIT_TXEN TXEN0 +# define BIT_UCSZ2 UCSZ02 +# define BIT_RXB8 RXB80 +# define BIT_TXB8 TXB80 + +/** UCSRC register */ +# define REG_UCSRC UCSR0C +# define BIT_URSEL URSEL0 +# define BIT_UMSEL UMSEL0 +# define BIT_UPM0 UPM00 +# define BIT_UPM1 UPM01 +# define BIT_USBS USBS0 +# define BIT_UCSZ0 UCSZ00 +# define BIT_UCSZ1 UCSZ01 +# define BIT_UCPOL UCPOL0 + +# define REG_UBRR UBRR0 + +/** UBRRL register */ +# define REG_UBRRL UBRR0L + +/** UBRRH register */ +# define REG_UBRRH UBRR0H + +/** UDR register */ +# define REG_UDR UDR0 + +# define __vector_USART_RX USART_RX_vect +# define __vector_USART_TX USART_TX_vect + +#endif + +#define BAUD_RATE_9600 ((const uint8_t) 0x67) +#define BAUD_RATE_57600 ((const uint8_t) 0x10) + +/** + * @brief Defines a constant for the carriage return combined with the new line in a single value. + */ +#define NEW_LINE_CARRIAGE_R (char*)"\n\r" + +/** + * @brief Defines a constant for the decimal radix base to print the number in decimal case. + */ +#define DEC_RADIX (const uint8_t) 10 + +/** + * @brief Defines a constant for the binary radix base to print the numbner in binary case. + */ +#define BIN_RADIX (const uint8_t) 2 + +/** + * @brief Allocates an expandable string buffer for small/medium/large integers and clears the buffer to zero. + * + * @example For decimal base 10: 155 is the same as saying [const char str[] = {'155', NULL};] or [char str[] = {'155', '\0'};]. + * @example For binary base 2: 0b11110000 is the same as saying [const char str[] = {'1', '1' ,'1', '1', '0', '0', '0', '0', '\0'};], + * i.e. one character for each bit plus one for the string terminator '\0' which is (NULL). + */ +#define allocateStringBuffer() ((char*) calloc(1, sizeof(char*))) + +/** + * @brief Operates, controls, read/write to UART serial port. + */ +struct uart { + + struct state { + + void onProtocolStarted(); + + void onProtocolStopped(); + + /** + * @brief Triggered when the data receive is completed at the Rx pin. + * + * @param data the received byte at the Rx pin. + */ + void onDataReceiveCompleted(const uint8_t); + + /** + * @brief Triggered when the data transmit is completed at the Tx pin. + * + * @param data the transmitted byte at the Tx pin which is equal to UDRn at that moment. + */ + void onDataTransmitCompleted(const uint8_t); + + void onDataBufferCleared(const uint8_t*); + + } state_instance; + + /** + * @warning Internal use only. + * + * @brief A volatile buffer to assign the transmitter data to the data register (UDRn). + * @see Serial::UART::setTransmitDataRegister(const uint8_t* transmitData) for implementation. + */ + volatile uint8_t* transmitData; + + /** + * @brief Sets the Transmit Data Register to be used by the UDR when the UDRE bit is set. + * + * @param transmitData the data buffer to transmit. + */ + void setTransmitDataRegister(const uint8_t* transmitData); + + /** + * @brief Starts the UART Protocol by setting up the control status registers and the baud rate register. + * it operates the UART as Tx and Rx. + * + * @param BAUD_RATE_VAL the code for the baud rate. + */ + void startProtocol(const uint16_t BAUD_RATE_VAL); + + /** + * @brief Stops the UART protocol by setting [UCSRB] to zero. + */ + void stopProtocol(); + + /** + * @warning Internal use only. + * + * @brief Activates the ISR handler for the UDRE (Data register empty) bit. + */ + void startDataRegisterEmptyBufferISR(); + + /** + * @warning Internal use only. + * + * @brief Activates the ISR handler for the RXC bit (Receiver Complete). + */ + void startReceiverISR(); + + /** + * @warning Internal use only. + * @brief Activates the ISR handler for the TXC bit (Transmitter Complete). + */ + void startTransmitterISR(); + + /** + * @warning Internal use only. + * + * @brief Deactivates the ISR handler for the UDRE (Data register empty) bit. + */ + void stopDataRegisterEmptyBufferISR(); + + /** + * @warning Internal use only. + * + * @brief Deactivates the ISR handler for the RXC bit (Receiver Complete). + */ + void stopReceiverISR(); + + /** + * @warning Internal use only. + * + * @brief Deactivates the ISR handler for the TXC bit (Transmitter Complete). + */ + void stopTransmitterISR(); + + /** + * @brief Reads the [UDR0] Data register in ASCII as default. + * + * @return uint8_t an 8-bit integer read from the UDR0, the output is in ascii. + */ + uint8_t readASCII(); + + /** + * @brief Reads the [UDR0] Data register in Integers after converting from ASCII by subtracting the result from '0' aka [48]. + * + * @return uint8_t + */ + uint8_t readInteger(); + + /** + * @brief Prints a charachter data to the serial stream. + * + * @param data a char data of 8-bit size. + */ + void cprint(char* data); + + /** + * @brief Prints a charachter data to the serial stream in a new line. + * + * @param data a char data of 8-bit size. + */ + void cprintln(char* data); + + /** + * @brief Prints a string (char array) buffer to the serial stream. + * + * @param data the string buffer to print. + */ + void sprint(char* data); + + /** + * @brief Prints a string (char array) buffer to the serial stream in a new line with a carriage return [(\n\r)]. + * + * @param data the string buffer to print. + */ + void sprintln(char* data); + + /** + * @brief Prints an integer data of max 64-bits with a base radix (2 for binary print or 10 for decimal print). + * + * @param data the integer to print. + * @param base the base, either 2 for binary print () + */ + void print(const int64_t data, const uint8_t base); + + /** + * @brief Prints an integer data of max 64-bits with a base radix (2 for binary print or 10 for decimal print) + * in a new line with carriage return [(\n\r)]. + * + * @param data the integer to print. + * @param base the base, either 2 for binary print (with max size = 64 * sizeof(uint8_t) + 1) or 10 for decimal print + * (with max size = 1 * sizeof(int64_t) + 1). + */ + void println(const int64_t data, const uint8_t base); +} static uart_instance; + + +#endif \ No newline at end of file diff --git a/HelloNativeLibs/avr/Hellouart/src/lib/hello_uart.cpp b/HelloNativeLibs/avr/Hellouart/src/lib/hello_uart.cpp new file mode 100644 index 00000000..311a66ab --- /dev/null +++ b/HelloNativeLibs/avr/Hellouart/src/lib/hello_uart.cpp @@ -0,0 +1,82 @@ +/** + * @file hello_uart.c. + * @author pavl_g. + * @brief Shows a basic implementation of the [libuart] library based on the observer/subscriber pattern. + * @version 0.1 + * @date 2022-10-08 + * + * @copyright Copyright (c) 2022 + * + */ +#include +#include + +#include + +const char* message = "Data Transmission completed successfully !"; + +/** + * Called when the data buffer is cleared and is available to carry a new data on the UDR. + * + * Use the uart::setTransmitterData(uint_8*) from the udr_plain_io.c.o objectcode + */ +void uart::state::onDataBufferCleared(const uint8_t* transmitData) { + uart_instance.sprintln((char*) "Data Transmitted !"); +} + +/** + * An implementation (function definition) for the function prototype. + * + * Listens for the protocol start command and fires accordingly. + */ +void uart::state::onProtocolStarted() { + uart_instance.sprintln((char*) "Protocol Started Successfully !"); +} + +/** + * An implementation (function definition) for the function prototype. + * + * Listens for the protocol stop command and fires accordingly. + */ +void uart::state::onProtocolStopped() { + uart_instance.sprintln((char*) "Protocol Stopped !"); +} + +/** + * An implementation (function definition) for the function prototype. + * + * Listens for the receive vector interrupt service subroutine ISR(RX) as it + * fires the listener when a data is received on the UDR register. + * + * @param data a data to be received through the interrupt service from the data register. + */ +void uart::state::onDataReceiveCompleted(const uint8_t data) { + uart_instance.println((const int64_t) data, 16); + uart_instance.stopProtocol(); +} + +/** + * An implementation (function definition) for the function prototype. + * + * Listens for the transmitter vector interrupt service subroutine ISR(TX) as it + * fires the listener when a data is transmitted on the UDR register. + * + * @param data a data to be transmitted through the interrupt service from the data register. + */ +void uart::state::onDataTransmitCompleted(const uint8_t data) { + uart_instance.sprintln((char*) message); +} + +/** + * The main application entry point. + * + * @param void parameters to pass from the compiler. + */ +int main(void) { + + uart_instance.startProtocol(BAUD_RATE_57600); + + while (true); // wait forever + + return 0; +} \ No newline at end of file diff --git a/HelloNativeLibs/avr/libuart/.gitignore b/HelloNativeLibs/avr/libuart/.gitignore new file mode 100644 index 00000000..8b66d9be --- /dev/null +++ b/HelloNativeLibs/avr/libuart/.gitignore @@ -0,0 +1,3 @@ +./*.executable +./*.hex +./*.buildconfig diff --git a/HelloNativeLibs/avr/libuart/README.md b/HelloNativeLibs/avr/libuart/README.md new file mode 100644 index 00000000..71a82752 --- /dev/null +++ b/HelloNativeLibs/avr/libuart/README.md @@ -0,0 +1,17 @@ +# libuart + +libuart: is a C avr library designed to interface and control the UART protocol with an implementation biased design towards file streams and file io (startProtocol, sendData and readData). + +The library has one header `serial.h` and 12 source `.C` files, each file has one function or 2 highly connected functions at most so far. + +This library is completely based on the HelloUART example written previously on the AVR-Sandbox project with removal of some ridiculous object-oriented patterns (the singleton pointer and the struct) since the developer already knows that the protocol is a singleton in its hardware implementation (you cannot have 2 different pointers pointing at the same hardware and behaving differently). + +The design of this library is based on a tweaked version of the Concrete Command-State pattern. + +The concrete command-state pattern of the `serial.h`: + +1) It's a concrete pattern, i.e: no abstraction layer. + +2) Encapsulate the boolean operations for the `initialization` and `termination` of the universal async/sync receiver/transmitter protocol by triggering status control registers. + +3) Firing listeners as a response to a command to the interrupt uint of the avr. \ No newline at end of file diff --git a/HelloNativeLibs/avr/libuart/build/build.sh b/HelloNativeLibs/avr/libuart/build/build.sh new file mode 100755 index 00000000..d5ea55ed --- /dev/null +++ b/HelloNativeLibs/avr/libuart/build/build.sh @@ -0,0 +1,6 @@ +echo -e "--Building the libuart into a static object file---" +echo "Ccoffee Script starts" +echo "---------------------------------------------" +source compile.sh +echo "---------------------------------------------" +echo "Ccoffee Script finishes" diff --git a/HelloNativeLibs/avr/libuart/build/compile.sh b/HelloNativeLibs/avr/libuart/build/compile.sh new file mode 100755 index 00000000..1075e3c8 --- /dev/null +++ b/HelloNativeLibs/avr/libuart/build/compile.sh @@ -0,0 +1,72 @@ +source variables.sh +export LC_ALL=C +function compile() { + # attrs : dir to compile & sharedLib name + cd ${project}'/src/lib/' + nativeSources=(`ls *.c *.cpp *.c++ *.cxx`) + + for ((i=0; i<${#nativeSources[@]}; i++)); do + ${AVR_HOME}'/bin/avr-g++' \ + -c -O -x c++ \ + -mmcu=${CHIP} "${project}/src/lib/${nativeSources[i]}" \ + -I${AVR_HOME}'/avr/include' \ + -I${project}'/src/include' \ + -o "${project}/output/${nativeSources[i]}.o" + done + + objectcode=`find ${project}'/output/' -name '*.o'` + + ${AVR_HOME}'/bin/avr-ar' rcs ${output}'.a' $objectcode + + ${AVR_HOME}'/bin/avr-nm' ${output}'.a' > ${output}'.map' + +} + +function provokePermissions() { + sudo chmod +xrwrwrw ${output}'.a' +} + +function copyToExample() { + cp ${output}'.a' ${avr_examples_dir}'/Hellouart/libs' + cp ${output}'.map' ${avr_examples_dir}'/Hellouart/libs' + cp -r ${project}'/src/include/.' ${avr_examples_dir}'/Hellouart/src/include/' +} + +echo -e "${WHITE_C} --MajorTask@Compile : Compiling the project" + +echo -e ${RESET_Cs} + +compile + +if [[ ! $? -eq 0 ]]; then + echo -e "${RED_C} --MajorTask@Compile : Failed compiling sources, exits with errno500." + exit 500 +else + echo -e "${GREEN_C} --MajorTask@Compile : Compilation succeeded." +fi +echo -e ${RESET_Cs} + +echo -e "${WHITE_C} --MajorTask@PermissionControl : Provoking permissions to the object file." + +echo -e ${RESET_Cs} + +provokePermissions + +if [[ ! $? -eq 0 ]]; then + echo -e "${RED_C} --MajorTask@PermissionsControl : Failed to provoke permissions." + exit 500 +else + echo -e "${GREEN_C} --MajorTask@PermissionsControl : Permissions provoked successfully." +fi +echo -e ${RESET_Cs} + +copyToExample + +if [[ ! $? -eq 0 ]]; then + echo -e "${RED_C} --MajorTask@Copying : " + exit 500 +else + echo -e "${GREEN_C} --MajorTask@Copying : " +fi +echo -e ${RESET_Cs} + diff --git a/HelloNativeLibs/avr/libuart/build/variables.sh b/HelloNativeLibs/avr/libuart/build/variables.sh new file mode 100644 index 00000000..c5007395 --- /dev/null +++ b/HelloNativeLibs/avr/libuart/build/variables.sh @@ -0,0 +1,29 @@ +#** +#* Ccoffee Build tool, manual build, alpha-v1. +#* +#* @author pavl_g. +#*# + + +# define work directory +# 1) print the current working directory to a string value +pwd=`pwd` +# cut the working directory from its end by a one '/' delimiter +project="${pwd%/*}" + +avr_examples_dir="${project%/*}" + +hello_native_libs="${avr_examples_dir%/*}" +# cut the working directory from its end by a one '/' delimiter again +rootProject="${hello_native_libs%/*}" +# pass the value of the dire + +clibName=('libuart') +# AVR-DUDE properties +CHIP='atmega328p' + +# Common Variables contain colors +source ${rootProject}'/CommonVariables.sh' +# provide avr home +AVR_HOME=${rootProject}'/avr8-gnu-toolchain-linux_x86_64' +output=${project}'/output/'${clibName} diff --git a/HelloNativeLibs/avr/libuart/output/libuart.a b/HelloNativeLibs/avr/libuart/output/libuart.a new file mode 100755 index 0000000000000000000000000000000000000000..8f7c35ab26a0d380866d910427c7a0aecefc365c GIT binary patch literal 15064 zcmeI3ZH!!18OP7iZM$77yIre5F?67n6vcVjm)TuXVQIUx#ZopcAU4F=?e3H=ncdmU z4p>0!R6vL}bZ3VO#t53A(WrqKqDF}nBSaHo`QQf<4IQE%_<(80G=@aY`2XK~p1Ehv z%yRFvgIg1y=I%MqJ77ee zOSo-3H@+uz_tYGUIx_lM?^Q$D)cE9$d$;b~X%s)<*4e4C6gfWV6(ZpjZ%=9>HFaNI z)%#h(#%aBA=fRr7OwZ=--*WGP19m>WG3N9Brq!|yRm+x`a2vwttU>pd+k+}<53<@J zSEt3}-Wa=gGMkj)5SfT%q8&MJ1SF^CvhGcq&8EkvW|C7G_fA$fRjo}ng&wNCB}H`~ zi@L+TS|)Qo#A7j}R{tjY`k=*obz#Rk4v*}*DHIA}TDTHYdzGgt_2-L}dK5{0PVy$z zp;oGVX})yvlS+-1W=j%pKi=_SrM7R~dR=(ajd$!x4kq_c<&xWX-=4fJlSxk;WHoyu z1CdxVJ}{KHCOi=7jl}dj&A@zjn<`h#v}H9V!z{)>Q#jZs=f)yk!guzN3UyZmtOH+B4 z?IO>r$lU$Yx$*r7b6Gb$D6woRJs!!W4&_wDDP4qRiexiXXdaKmRb(PFJ)N4#A8>X?2S8H8H=grVfk^HX3O+IVdNu2g# z7uWF~-h?ne+m5!wxERX3x&?7QE5bBhYjBy*&!ZkY#Yo#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4&**e6lbSMpjU12}fZ)$YzrDaS_{?)qiR%Z!)9Ab&KU{HMopx`JA6FgnZKBSCP-1 z#RoyFy($YmhhA7iUr@~AC0!GISAdqsNkOBgnqij9yds9D|LYk<72U1RQPY3qxx>k+ zd%uXBM!bVY_;?Cn0sSNzX{bi`M|)AMzQXs&-BA6mW73c2)+tVUrHeQ`Oi2XwqnrZi u$Y#;p=YQaQYf9v3C?qYGM)-zo29q=k%};yKH#ddm?$<@lcg!hJAHpA0!oPz6 literal 0 HcmV?d00001 diff --git a/HelloNativeLibs/avr/libuart/output/start.c.o b/HelloNativeLibs/avr/libuart/output/start.c.o new file mode 100644 index 0000000000000000000000000000000000000000..e5a6186c683f9e81eaf24e04e5d9d5b92f776c17 GIT binary patch literal 1076 zcma)5UuzRV5T7$Ot)NAN6hVwdT&^deajWw9as^7hu9Vp){LhMizx-8q(MI$LCja{o-pe$Gw9Tf(eF53}fW zRseqB_}76SIsUB-GnmeJq{R%=nXTn7dFby-j?Pmf4cvw;fN|guE(4#O@xPw&X=sAj zh>)agHDpc7IjGM;vrICX>wf7C>SZrNpD0u$+k2ZF@k>eLMy!nv zb-!|uW$qzilwa17O}2Oh)vX+59DggRZmLlAj#T`t)#Rk?Y8m!b5X;VRh<#jz=F?xY z2E3f&Yrus|SRgl`mU9!>a*Du(RV*xG_-rXM?jwPiWcA1M*CdZ5r+bxzZCXKnBuq z`E>I%bq6qg`v~LrP}<#H&n|2qAK_Q5HZ+#@f8#HunqfU?M3@%^v5bD<+uCBbAo60_ zo;39Cc_Yy24l@9$SKTmAxoKh}Fiw$;LA2BTNce}tX9;gQd~Sdlbh=CQ9rn=aem8kO z$)ozNrC<~eOkj%q3@Pf4V4Cpt8xDz9Z4m-u}Dp-MMQGe(m@qOqT{}=TNKM?Ahi6iLDT{rfZ(bkRIQebwAub1 zmn9LuLE4CU-uVAov+whX0^Hk{O;FQ0!eg{p!?_7s^M>1L*&*(lt@oLNJU_0^V%A%o zZ?GL-uE#NJtmDPA=kCu@f9qCcG)!4bse$podZxv_aQ}P{o}~;ew_c4lK2XdW*I|1B DJC=0* literal 0 HcmV?d00001 diff --git a/HelloNativeLibs/avr/libuart/output/transmitter_isr.c.o b/HelloNativeLibs/avr/libuart/output/transmitter_isr.c.o new file mode 100644 index 0000000000000000000000000000000000000000..4b8ac5f67bb16be2c259b57aac46ad23515d5e7f GIT binary patch literal 1204 zcma)5L2nXK5FVsbnwT!di&2wuP*W4Lg;J$$qEsnT4QUOu#&CHqun`hq$?mhM^#G>v z438}bPd(|iH;?vaym|Fx@aDm!@(XYV_Q4u2PBJ^+H}8A1Gn?5)GX2ow@qjcBWMRSp z(q4eKc(^vi+c-<|I$9p$6anY*@V$L(#K*@oS) zTlTSiVxQV)_P~BFK0~wD?#&*-I1a>_I29-2ShPe#7=npy5f_U>X)B+U_I&$N7gCAD zT4>?^(+pc-`7&pztzEWb7?navE7w?5jj3T4iLKtb8H%Yu`r0K9)q zOdN-HnHQ$uBJz9VTz_yC@m&|cjyUe(>KGH~57zKG>7hSJIp_2y57u{^7tTY@Nz7sl zqT&D};R_Cbhw(D{Gl##&C@p~Ct0WkS12?srRV{O_o2+b^Y5^F_K4F`TjX-(?GRf2s z@M@iz`imhx&`m>`)i8STRjhs&+~fZT1e-Yrb} z(cLQPP_>B#5M-S-1XXwRj|dK9tsv3)}nz$EoT{nH$@qciC4dOuO~ J9dpuTy+1rZ$i)Bv literal 0 HcmV?d00001 diff --git a/HelloNativeLibs/avr/libuart/output/udr_cprint.c.o b/HelloNativeLibs/avr/libuart/output/udr_cprint.c.o new file mode 100644 index 0000000000000000000000000000000000000000..d98c5388fec42fd61fb7ade04b189c955e43c3fe GIT binary patch literal 992 zcma)4&ubGw6n^X0)Iu$_h#vHile8d1L)ylc`m@9+gc6e0LodT-vzUeKZke5y>ctc+ zcobCpcRcxbs1li%`YzW3fYZ{F<8hkEm+=Xqq|QHQQPqO)s67f5bQ z1go?_B^v#@91YJe3i|Qe8=eop{G{RN^JwWS(T#7^*xTDFuRed%mXBmN*0QmGC=ar1 z5cY#Ol~qv_>#|bY-dZcyL{+TYecjpJe~!k5oAdwbj>yO7!lyY}Lg2|PI4bvmiIvtw8eatIR^c}%6_@{q-I_W7H9;-OjA|xq0 zE%{2yDQQkgyWW@(og7OQy`Av)k;<%d)T~rb0;Oe~<~m5jh~&}!21mB0h3hR;HlfNk zG)f<+AkC9l>qx!swCktXu$Rej5Cuwh^BlK_K7HIbpKt|MGDp1)K5zIP&fUbo5c#`A z2VKlsP3OL4DjEbrM`xNuFVF!A-a&*}l0>PVuKusF3>Du+$*B1q@_)9l_jC^dZtpetp@;^+Hb#@Jhtgd1>@5Nvp$1GUKb_?dN-$j2r kR%A5nvKFZsK7w7sxEJo9&#??!fVuTF7Jf&}g6lB;07o=^yZ`_I literal 0 HcmV?d00001 diff --git a/HelloNativeLibs/avr/libuart/output/udr_cprintln.c.o b/HelloNativeLibs/avr/libuart/output/udr_cprintln.c.o new file mode 100644 index 0000000000000000000000000000000000000000..475b86c4f12cfffe0fc190318c62fb87103574b8 GIT binary patch literal 1164 zcma)6O>fgc5FL|}ln4ssfP}b298eKxRgo^vTelc~kazv|bBy4%}NnyW89?#fL$7-`wv`5@n?X&fE~qeQkuTdYaH z{dnVkvn^U;%`WO>ckLyb&7BfeE_6oBD{h(D65U|s*+QMoZ!>=C@VktkJN&@{1I*@a zzMuC{UjH(^G=8k?@p^7ls7jxVaEo(;9kF9TZzm=Gqs0G|I2{d@3@2)o=r|D}Nx9dT zuca(NuK>H9ZVvQ#B31M`$6q6rTC(5sTStM?a+G8`NWzHZ{?0m-O*?g`&vP4bqYy7h zS>8e}$zdwPbaE_*feyG2&^QW|9AsJEebqb`J~~u07^$&RY;KuTwO(MPn!#708$Yae zES_8AI^Pf?J09y`z*(yzA6lfMI1oDeqDkbf2{a^B3Ie+?d=g;qUI`5+1^)q%|zDD*eN}WxtcRYX*4!#ky8^BMes2Z zp(rgQ@nDu5jW2=UH}qBThlaj2<4i{5EWS@>7>z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>)m06xpvNQ1WnG>{4Pue)|<~EyT%Q@`R-mb$6N!9pbtONW73RsSt literal 0 HcmV?d00001 diff --git a/HelloNativeLibs/avr/libuart/output/udr_reset_isr.c.o b/HelloNativeLibs/avr/libuart/output/udr_reset_isr.c.o new file mode 100644 index 0000000000000000000000000000000000000000..a06bc9780326438e8df1ced5ad868caa4a623751 GIT binary patch literal 1260 zcma)5&rcIU6n?d}Kw?;$Rjlsk$G)4K5C<<0EHiZ-6Qu?` zx6^?$e*%dIFD7#H@2Js(2NSIE=ApjV?zHR0_>#Bp``&!>_RX(@c;ZPQ5CClfScM(~ zI0^#1#lgw8U)l!=hpp5=IfECmys5EMg!DHygmb{SX@=Tt}syvXkWO7-~$#H4ajE_cb zq;~ZL78e#~N5>wmr`R-0=LK6#K4)vTUC89De2K-(DRY8Fr)KWm9-T5{=7e5ZFZ$OP zf@Z5X0ucOb^~7-ld=`Wd3?qNg%{5!s5a0Ll8;Iw8{7x4WXtt*D+v}m(ihJYqrvTRX zTM#b83okKu$D~(Y&otV?e;RVYSd{2Ox#csi*mduP@Eb@||x&LXSsH6VFo}S+1YY$VnsmqIIKy+{i(B%~&_pjJyv4KkESel^ziAnSQYh_6qVYpc;dQk zt7*0zQQ#$>6Zz8J;<8cV1)furPP{(vG=$Nl0+9IYG!!TFGDg!di<$f5Y#7ZWzo*3p z@&{VHJmy5g=nj4-GlbEjxK2AU?5`sMmtZ$e)X>kNqNxe4AwT*jhJ%JD{C%(GNN#}; zJ6mE?h!Lrd$ac9hB(k$FJp0*@zpy=51$)(e;lT8yXgR(#9m@u>S6iV>an!iHg`HK( z8tyeriH0kzwrzT%?)x~Gfi{J2;s*NLF<(btL`%j;T}7UX`5N-MtN20C9Vc+@0tMWE z-jQYl>IJ>UScmFI_mW1_b&8W->GCmGPn!BsPJwh}*U|L#hd3YI jtAgrB9!q1KAp34tifRXnMb|xbQvZ6jZ-I(%zEb literal 0 HcmV?d00001 diff --git a/HelloNativeLibs/avr/libuart/output/udr_sprintln.c.o b/HelloNativeLibs/avr/libuart/output/udr_sprintln.c.o new file mode 100644 index 0000000000000000000000000000000000000000..703739d800a24c9f9453d415523546094f5a6fb3 GIT binary patch literal 1132 zcma)5O;6iE5FIx(p;3z{he}m15eG!oY85w#&`NEoAcR&aLeLM1%iuUxiR9SPdXY*m zaOt(;&>s0`9P$_P3&M=O6PBDhk~8nUc{@8Bug_bZ9nbSX!h=J&WdPUr0De<(EjO$} z6)JEsx*RS11vnlJM}p`7RUZMgx3=EYRzG|@zzyv74Yv2b;+Hgy!;_$&U_&)k9sTC( z_2;#wYN)zw>STBCIT%lz5|r*t2E?Geb}~s-r1x5+$cdAzFXl5gY#~e?>YKa@6q~r-3%uPcjoEVFY-zx5mnbv~KNFZ!4}BVlH7X#V{S7 zVJ|QNZOSx`0*&1)lTpj|*mO0ZVlk(sg~BmUsa!2Er;5c7S+{<+%3A(kWG$%dY+!;e zWuuFHB1lJZpiK1BfXb&+Jd@HX6Sn)x2NkA+L6jJ3`QK3^C%^NuUBP#q-=Boshi4@4 z_?xy+r$6ABFrSw_T;nsYST48o6LB}B-%ApCt?Luae)0JhzhaSs`_1~;yGajc`K~?_ y=Cu-B +#include +#include +#include + +#if defined (__AVR_ATmega32__) + +/** UCSRA register */ +# define REG_UCSRA UCSRA +# define BIT_RXC RXC +# define BIT_TXC TXC +# define BIT_UDRE UDRE +# define BIT_FE FE +# define BIT_PE PE +# define BIT_U2X U2X +# define BIT_MPCM MPCM + +/** UCSRB register */ +# define REG_UCSRB UCSRB +# define BIT_RXCIE RXCIE +# define BIT_TXCIE TXCIE +# define BIT_UDRIE UDRIE +# define BIT_RXEN RXEN +# define BIT_TXEN TXEN +# define BIT_UCSZ2 UCSZ2 +# define BIT_RXB8 RXB8 +# define BIT_TXB8 TXB8 + +/** UCSRC register */ +# define REG_UCSRC UCSRC +# define BIT_URSEL URSEL +# define BIT_UMSEL UMSEL +# define BIT_UPM0 UPM0 +# define BIT_UPM1 UPM1 +# define BIT_USBS USBS +# define BIT_UCSZ0 UCSZ0 +# define BIT_UCSZ1 UCSZ1 +# define BIT_UCPOL UCPOL + +# define REG_UBRR UBRR + +/** UBRRL register */ +# define REG_UBRRL UBRRL + +/** UBRRH register */ +# define REG_UBRRH UBRRH + +/** UDR register */ +# define REG_UDR UDR + +# define __vector_USART_RX USART_RXC_vect +# define __vector_USART_TX USART_TXC_vect + +#elif defined (__AVR_ATmega328P__) + +/** UCSRA register */ +# define REG_UCSRA UCSR0A +# define BIT_RXC RXC0 +# define BIT_TXC TXC0 +# define BIT_UDRE UDRE0 +# define BIT_FE FE0 +# define BIT_PE PE0 +# define BIT_U2X U2X0 +# define BIT_MPCM MPCM0 + +/** UCSRB register */ +# define REG_UCSRB UCSR0B +# define BIT_RXCIE RXCIE0 +# define BIT_TXCIE TXCIE0 +# define BIT_UDRIE UDRIE0 +# define BIT_RXEN RXEN0 +# define BIT_TXEN TXEN0 +# define BIT_UCSZ2 UCSZ02 +# define BIT_RXB8 RXB80 +# define BIT_TXB8 TXB80 + +/** UCSRC register */ +# define REG_UCSRC UCSR0C +# define BIT_URSEL URSEL0 +# define BIT_UMSEL UMSEL0 +# define BIT_UPM0 UPM00 +# define BIT_UPM1 UPM01 +# define BIT_USBS USBS0 +# define BIT_UCSZ0 UCSZ00 +# define BIT_UCSZ1 UCSZ01 +# define BIT_UCPOL UCPOL0 + +# define REG_UBRR UBRR0 + +/** UBRRL register */ +# define REG_UBRRL UBRR0L + +/** UBRRH register */ +# define REG_UBRRH UBRR0H + +/** UDR register */ +# define REG_UDR UDR0 + +# define __vector_USART_RX USART_RX_vect +# define __vector_USART_TX USART_TX_vect + +#endif + +#define BAUD_RATE_9600 ((const uint8_t) 0x67) +#define BAUD_RATE_57600 ((const uint8_t) 0x10) + +/** + * @brief Defines a constant for the carriage return combined with the new line in a single value. + */ +#define NEW_LINE_CARRIAGE_R (char*)"\n\r" + +/** + * @brief Defines a constant for the decimal radix base to print the number in decimal case. + */ +#define DEC_RADIX (const uint8_t) 10 + +/** + * @brief Defines a constant for the binary radix base to print the numbner in binary case. + */ +#define BIN_RADIX (const uint8_t) 2 + +/** + * @brief Allocates an expandable string buffer for small/medium/large integers and clears the buffer to zero. + * + * @example For decimal base 10: 155 is the same as saying [const char str[] = {'155', NULL};] or [char str[] = {'155', '\0'};]. + * @example For binary base 2: 0b11110000 is the same as saying [const char str[] = {'1', '1' ,'1', '1', '0', '0', '0', '0', '\0'};], + * i.e. one character for each bit plus one for the string terminator '\0' which is (NULL). + */ +#define allocateStringBuffer() ((char*) calloc(1, sizeof(char*))) + +/** + * @brief Operates, controls, read/write to UART serial port. + */ +struct uart { + + struct state { + + void onProtocolStarted(); + + void onProtocolStopped(); + + /** + * @brief Triggered when the data receive is completed at the Rx pin. + * + * @param data the received byte at the Rx pin. + */ + void onDataReceiveCompleted(const uint8_t); + + /** + * @brief Triggered when the data transmit is completed at the Tx pin. + * + * @param data the transmitted byte at the Tx pin which is equal to UDRn at that moment. + */ + void onDataTransmitCompleted(const uint8_t); + + void onDataBufferCleared(const uint8_t*); + + } state_instance; + + /** + * @warning Internal use only. + * + * @brief A volatile buffer to assign the transmitter data to the data register (UDRn). + * @see Serial::UART::setTransmitDataRegister(const uint8_t* transmitData) for implementation. + */ + volatile uint8_t* transmitData; + + /** + * @brief Sets the Transmit Data Register to be used by the UDR when the UDRE bit is set. + * + * @param transmitData the data buffer to transmit. + */ + void setTransmitDataRegister(const uint8_t* transmitData); + + /** + * @brief Starts the UART Protocol by setting up the control status registers and the baud rate register. + * it operates the UART as Tx and Rx. + * + * @param BAUD_RATE_VAL the code for the baud rate. + */ + void startProtocol(const uint16_t BAUD_RATE_VAL); + + /** + * @brief Stops the UART protocol by setting [UCSRB] to zero. + */ + void stopProtocol(); + + /** + * @warning Internal use only. + * + * @brief Activates the ISR handler for the UDRE (Data register empty) bit. + */ + void startDataRegisterEmptyBufferISR(); + + /** + * @warning Internal use only. + * + * @brief Activates the ISR handler for the RXC bit (Receiver Complete). + */ + void startReceiverISR(); + + /** + * @warning Internal use only. + * @brief Activates the ISR handler for the TXC bit (Transmitter Complete). + */ + void startTransmitterISR(); + + /** + * @warning Internal use only. + * + * @brief Deactivates the ISR handler for the UDRE (Data register empty) bit. + */ + void stopDataRegisterEmptyBufferISR(); + + /** + * @warning Internal use only. + * + * @brief Deactivates the ISR handler for the RXC bit (Receiver Complete). + */ + void stopReceiverISR(); + + /** + * @warning Internal use only. + * + * @brief Deactivates the ISR handler for the TXC bit (Transmitter Complete). + */ + void stopTransmitterISR(); + + /** + * @brief Reads the [UDR0] Data register in ASCII as default. + * + * @return uint8_t an 8-bit integer read from the UDR0, the output is in ascii. + */ + uint8_t readASCII(); + + /** + * @brief Reads the [UDR0] Data register in Integers after converting from ASCII by subtracting the result from '0' aka [48]. + * + * @return uint8_t + */ + uint8_t readInteger(); + + /** + * @brief Prints a charachter data to the serial stream. + * + * @param data a char data of 8-bit size. + */ + void cprint(char* data); + + /** + * @brief Prints a charachter data to the serial stream in a new line. + * + * @param data a char data of 8-bit size. + */ + void cprintln(char* data); + + /** + * @brief Prints a string (char array) buffer to the serial stream. + * + * @param data the string buffer to print. + */ + void sprint(char* data); + + /** + * @brief Prints a string (char array) buffer to the serial stream in a new line with a carriage return [(\n\r)]. + * + * @param data the string buffer to print. + */ + void sprintln(char* data); + + /** + * @brief Prints an integer data of max 64-bits with a base radix (2 for binary print or 10 for decimal print). + * + * @param data the integer to print. + * @param base the base, either 2 for binary print () + */ + void print(const int64_t data, const uint8_t base); + + /** + * @brief Prints an integer data of max 64-bits with a base radix (2 for binary print or 10 for decimal print) + * in a new line with carriage return [(\n\r)]. + * + * @param data the integer to print. + * @param base the base, either 2 for binary print (with max size = 64 * sizeof(uint8_t) + 1) or 10 for decimal print + * (with max size = 1 * sizeof(int64_t) + 1). + */ + void println(const int64_t data, const uint8_t base); +} static uart_instance; + + +#endif \ No newline at end of file diff --git a/HelloNativeLibs/avr/libuart/src/lib/receiver_isr.c b/HelloNativeLibs/avr/libuart/src/lib/receiver_isr.c new file mode 100644 index 00000000..9b88dd6f --- /dev/null +++ b/HelloNativeLibs/avr/libuart/src/lib/receiver_isr.c @@ -0,0 +1,19 @@ +#include + +/** + * @brief Triggered when the RXC0 is settled and the receiving has been completed. + */ +ISR (__vector_USART_RX) { + uart_instance.state_instance.onDataReceiveCompleted((const uint8_t) REG_UDR); +} + +void uart::startReceiverISR() { + REG_UCSRB |= (1 << BIT_RXCIE); + /* start the interrupt service handlers */ + sei(); +} + +void uart::stopReceiverISR() { + // Finds the 1s complement of all bits in RXCIE0 ---> eg: 0b11111101 + REG_UCSRB &= ~(1 << BIT_RXCIE); +} \ No newline at end of file diff --git a/HelloNativeLibs/avr/libuart/src/lib/start.c b/HelloNativeLibs/avr/libuart/src/lib/start.c new file mode 100644 index 00000000..0318bca4 --- /dev/null +++ b/HelloNativeLibs/avr/libuart/src/lib/start.c @@ -0,0 +1,9 @@ +#include + +void uart::startProtocol(const uint16_t BAUD_RATE_VAL) { + REG_UCSRB = (1 << BIT_TXEN) | (1 << BIT_RXEN); /* enable the transmit and receiver buffers and their interrupt services */ + REG_UCSRC = (1 << BIT_USBS) | (3 << BIT_UCSZ0); // enables the UCSZ0, UCSZ1 and URSEL + REG_UBRR = BAUD_RATE_VAL; // 0x10 (16) for BR = 57600 // 0x33 (51) for 9600 + uart_instance.state_instance.onProtocolStarted(); + uart_instance.startReceiverISR(); +} \ No newline at end of file diff --git a/HelloNativeLibs/avr/libuart/src/lib/stop.c b/HelloNativeLibs/avr/libuart/src/lib/stop.c new file mode 100644 index 00000000..f974657b --- /dev/null +++ b/HelloNativeLibs/avr/libuart/src/lib/stop.c @@ -0,0 +1,6 @@ +#include + +void uart::stopProtocol() { + uart_instance.state_instance.onProtocolStopped(); + REG_UCSRB = 0x00; +} \ No newline at end of file diff --git a/HelloNativeLibs/avr/libuart/src/lib/transmitter_isr.c b/HelloNativeLibs/avr/libuart/src/lib/transmitter_isr.c new file mode 100644 index 00000000..0c86bcc7 --- /dev/null +++ b/HelloNativeLibs/avr/libuart/src/lib/transmitter_isr.c @@ -0,0 +1,20 @@ +#include + +/** + * @brief Triggered when the bit TXC is settled and the data transmission has been completed. + */ +ISR (__vector_USART_TX) { + uart_instance.state_instance.onDataTransmitCompleted((const uint8_t) REG_UDR); + uart_instance.stopTransmitterISR(); +} + +void uart::startTransmitterISR() { + REG_UCSRB |= (1 << BIT_TXCIE); + /* start the interrupt service handlers */ + sei(); +} + +void uart::stopTransmitterISR() { + // Finds the 1s complement of all bits in RXCIE0 ---> eg: 0b11111101 + REG_UCSRB &= ~(1 << BIT_TXCIE); +} \ No newline at end of file diff --git a/HelloNativeLibs/avr/libuart/src/lib/udr_cprint.c b/HelloNativeLibs/avr/libuart/src/lib/udr_cprint.c new file mode 100644 index 00000000..32d9fe72 --- /dev/null +++ b/HelloNativeLibs/avr/libuart/src/lib/udr_cprint.c @@ -0,0 +1,7 @@ +#include + +void uart::cprint(char* data) { + while (!(REG_UCSRA & (1 << BIT_UDRE))); + REG_UDR = *data; + uart_instance.startTransmitterISR(); +} \ No newline at end of file diff --git a/HelloNativeLibs/avr/libuart/src/lib/udr_cprintln.c b/HelloNativeLibs/avr/libuart/src/lib/udr_cprintln.c new file mode 100644 index 00000000..6c2ab8e0 --- /dev/null +++ b/HelloNativeLibs/avr/libuart/src/lib/udr_cprintln.c @@ -0,0 +1,6 @@ +#include + +void uart::cprintln(char* data) { + uart_instance.cprint(data); + uart_instance.sprint(NEW_LINE_CARRIAGE_R); +} \ No newline at end of file diff --git a/HelloNativeLibs/avr/libuart/src/lib/udr_plain_io.c b/HelloNativeLibs/avr/libuart/src/lib/udr_plain_io.c new file mode 100644 index 00000000..0f3c763d --- /dev/null +++ b/HelloNativeLibs/avr/libuart/src/lib/udr_plain_io.c @@ -0,0 +1,12 @@ +#include + +void uart::setTransmitDataRegister(const uint8_t* transmitData) { + *(uart_instance.transmitData) = *transmitData; + uart_instance.startDataRegisterEmptyBufferISR(); + uart_instance.startTransmitterISR(); +} + +uint8_t uart::readASCII() { + while (!(REG_UCSRA & (1 << BIT_RXC))); + return REG_UDR; +} \ No newline at end of file diff --git a/HelloNativeLibs/avr/libuart/src/lib/udr_print.c b/HelloNativeLibs/avr/libuart/src/lib/udr_print.c new file mode 100644 index 00000000..bedf39ee --- /dev/null +++ b/HelloNativeLibs/avr/libuart/src/lib/udr_print.c @@ -0,0 +1,12 @@ +#include + +void uart::print(const int64_t data, const uint8_t base) { + char* strBuffer = allocateStringBuffer(); + // convert input to string + itoa(data, strBuffer, base); + int i = 0; + while (i < strlen(strBuffer)) { + uart_instance.cprint(&strBuffer[i++]); + } + free(strBuffer); +} \ No newline at end of file diff --git a/HelloNativeLibs/avr/libuart/src/lib/udr_println.c b/HelloNativeLibs/avr/libuart/src/lib/udr_println.c new file mode 100644 index 00000000..74299eb9 --- /dev/null +++ b/HelloNativeLibs/avr/libuart/src/lib/udr_println.c @@ -0,0 +1,6 @@ +#include + +void uart::println(const int64_t data, const uint8_t base) { + uart_instance.print(data, base); + uart_instance.sprint(NEW_LINE_CARRIAGE_R); +} \ No newline at end of file diff --git a/HelloNativeLibs/avr/libuart/src/lib/udr_reset_isr.c b/HelloNativeLibs/avr/libuart/src/lib/udr_reset_isr.c new file mode 100644 index 00000000..920d7fcd --- /dev/null +++ b/HelloNativeLibs/avr/libuart/src/lib/udr_reset_isr.c @@ -0,0 +1,21 @@ +#include + +/** + * @brief Triggered when the bit UDRE0 is one (the data register buffer is empty and ready to send data). + */ +ISR (USART_UDRE_vect) { + REG_UDR = *(uart_instance.transmitData); + uart_instance.state_instance.onDataBufferCleared((const uint8_t*) uart_instance.transmitData); + uart_instance.stopDataRegisterEmptyBufferISR(); +} + +void uart::startDataRegisterEmptyBufferISR() { + REG_UCSRB |= (1 << BIT_UDRIE); + /* start the interrupt service handlers */ + sei(); +} + +void uart::stopDataRegisterEmptyBufferISR() { + // Finds the 1s complement of all bits in UDRIE0 ---> eg: 0b11111101 + REG_UCSRB &= ~(1 << BIT_UDRIE); +} \ No newline at end of file diff --git a/HelloNativeLibs/avr/libuart/src/lib/udr_sprint.c b/HelloNativeLibs/avr/libuart/src/lib/udr_sprint.c new file mode 100644 index 00000000..68948308 --- /dev/null +++ b/HelloNativeLibs/avr/libuart/src/lib/udr_sprint.c @@ -0,0 +1,8 @@ +#include + +void uart::sprint(char* data) { + int i = 0; + while (i < strlen(data)) { + uart_instance.cprint(&data[i++]); + } +} \ No newline at end of file diff --git a/HelloNativeLibs/avr/libuart/src/lib/udr_sprintln.c b/HelloNativeLibs/avr/libuart/src/lib/udr_sprintln.c new file mode 100644 index 00000000..ac75dbb1 --- /dev/null +++ b/HelloNativeLibs/avr/libuart/src/lib/udr_sprintln.c @@ -0,0 +1,6 @@ +#include + +void uart::sprintln(char* data) { + uart_instance.sprint(data); + uart_instance.sprint(NEW_LINE_CARRIAGE_R); +} \ No newline at end of file From 03b12b65c6de9dd0aab626f1c4c29d5779fea7c6 Mon Sep 17 00:00:00 2001 From: pavl_g Date: Sun, 9 Oct 2022 23:43:14 +0200 Subject: [PATCH 2/9] hello_uart.c: Fix `@brief` description --- HelloNativeLibs/avr/Hellouart/src/lib/hello_uart.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HelloNativeLibs/avr/Hellouart/src/lib/hello_uart.cpp b/HelloNativeLibs/avr/Hellouart/src/lib/hello_uart.cpp index 311a66ab..d1ded376 100644 --- a/HelloNativeLibs/avr/Hellouart/src/lib/hello_uart.cpp +++ b/HelloNativeLibs/avr/Hellouart/src/lib/hello_uart.cpp @@ -1,7 +1,7 @@ /** * @file hello_uart.c. * @author pavl_g. - * @brief Shows a basic implementation of the [libuart] library based on the observer/subscriber pattern. + * @brief Shows a basic implementation of the [libuart] library based on the command-state pattern. * @version 0.1 * @date 2022-10-08 * From 9743ad2dc570d93654d67823100ad1f9103ad1cc Mon Sep 17 00:00:00 2001 From: pavl_g Date: Mon, 10 Oct 2022 11:53:51 +0200 Subject: [PATCH 3/9] Build-Scripts: Added find the sources and the build parts by the canonical directory of the build script --- HelloNativeLibs/avr/Hellouart/build/build.sh | 7 +++-- .../avr/Hellouart/build/compile.sh | 6 ++-- HelloNativeLibs/avr/Hellouart/build/upload.sh | 5 +++- .../avr/Hellouart/build/variables.sh | 9 +++--- HelloNativeLibs/avr/Hellouart/libs/libuart.a | Bin 15064 -> 15064 bytes .../avr/Hellouart/libs/libuart.map | 26 +++++++++--------- .../avr/Hellouart/output/libHelloUART.elf | Bin 11012 -> 11012 bytes .../avr/Hellouart/output/libHelloUART.hex | 26 +++++++++--------- HelloNativeLibs/avr/libuart/build/build.sh | 5 +++- HelloNativeLibs/avr/libuart/build/compile.sh | 7 +++-- .../avr/libuart/build/variables.sh | 10 ++++--- HelloNativeLibs/avr/libuart/output/libuart.a | Bin 15064 -> 15064 bytes .../avr/libuart/output/libuart.map | 26 +++++++++--------- 13 files changed, 72 insertions(+), 55 deletions(-) diff --git a/HelloNativeLibs/avr/Hellouart/build/build.sh b/HelloNativeLibs/avr/Hellouart/build/build.sh index fae2af6b..d4c038cb 100755 --- a/HelloNativeLibs/avr/Hellouart/build/build.sh +++ b/HelloNativeLibs/avr/Hellouart/build/build.sh @@ -1,6 +1,9 @@ +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` + echo "Ccoffee Script starts" echo "---------------------------------------------" -source compile.sh -source upload.sh +source $build_dir"/"compile.sh +source $build_dir"/"upload.sh echo "---------------------------------------------" echo "Ccoffee Script finishes" diff --git a/HelloNativeLibs/avr/Hellouart/build/compile.sh b/HelloNativeLibs/avr/Hellouart/build/compile.sh index 56855c06..c3011366 100755 --- a/HelloNativeLibs/avr/Hellouart/build/compile.sh +++ b/HelloNativeLibs/avr/Hellouart/build/compile.sh @@ -1,5 +1,7 @@ -source variables.sh -export LC_ALL=C +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` + +source $build_dir"/"variables.sh function addLibsTold() { sudo ${AVR_HOME}'/bin/avr-ld' --library-path "${project}/libs" "${project}/libs/libuart" diff --git a/HelloNativeLibs/avr/Hellouart/build/upload.sh b/HelloNativeLibs/avr/Hellouart/build/upload.sh index f0dcc326..08cac593 100755 --- a/HelloNativeLibs/avr/Hellouart/build/upload.sh +++ b/HelloNativeLibs/avr/Hellouart/build/upload.sh @@ -1,4 +1,7 @@ -source variables.sh +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` + +source $build_dir"/"variables.sh function prepare() { sudo stty -F ${PORT} ${BAUD_RATE} diff --git a/HelloNativeLibs/avr/Hellouart/build/variables.sh b/HelloNativeLibs/avr/Hellouart/build/variables.sh index f382c36d..f63bc65c 100644 --- a/HelloNativeLibs/avr/Hellouart/build/variables.sh +++ b/HelloNativeLibs/avr/Hellouart/build/variables.sh @@ -3,12 +3,13 @@ #* #* @author pavl_g. #*# +export LC_ALL=C +# define work directory +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` -# define work directory -# 1) print the current working directory to a string value -pwd=`pwd` -project="${pwd%/*}" +project="${build_dir%/*}" avr_examples_dir="${project%/*}" diff --git a/HelloNativeLibs/avr/Hellouart/libs/libuart.a b/HelloNativeLibs/avr/Hellouart/libs/libuart.a index 8f7c35ab26a0d380866d910427c7a0aecefc365c..70857d27345b92f48e4fe2d3c361e393b7c24150 100755 GIT binary patch delta 296 zcmcandZToLEUTr7xw+v)r34{e8wLi$2nGf-1sI-e%_=+DjmvxDp9Pa2GImX#&FIR^ zpszoRYGJCwV5o?teN$tU)o8L9`QNK5K4vK}t^<1p?#L5a=p pl&uk5@y&mAcvvBNH}e@Wvq+ko;d7mn*)*2P0%oF69eNt`SOBgQO<@24 delta 303 zcmcandZToLEUSryp_#=*r34|JGYkwcZ1{zN!AxMXHLL987=6jf@mxj||16lS&g3%L zpNV7g60PLPp8CR*C7F1c8T9oh7cyy2p2_4fnT=U!@H#UzlsbZ}hg1Fpf-AB4 vow7B8E513OodD6>M%<`Wa&oU8kWd9tFJ2$FT3hSOO94E<1X diff --git a/HelloNativeLibs/avr/Hellouart/libs/libuart.map b/HelloNativeLibs/avr/Hellouart/libs/libuart.map index a5d727f7..41c9cad1 100644 --- a/HelloNativeLibs/avr/Hellouart/libs/libuart.map +++ b/HelloNativeLibs/avr/Hellouart/libs/libuart.map @@ -98,19 +98,6 @@ udr_sprint.c.o: 00000000 a __tmp_reg__ 00000001 a __zero_reg__ -receiver_isr.c.o: -00000000 b _ZL13uart_instance -0000005e T _ZN4uart15stopReceiverISREv -00000050 T _ZN4uart16startReceiverISREv - U _ZN4uart5state22onDataReceiveCompletedEh -0000003e a __SP_H__ -0000003d a __SP_L__ -0000003f a __SREG__ - U __do_clear_bss -00000000 a __tmp_reg__ -00000000 T __vector_18 -00000001 a __zero_reg__ - udr_reset_isr.c.o: 00000000 b _ZL13uart_instance 0000000e T _ZN4uart30stopDataRegisterEmptyBufferISREv @@ -147,3 +134,16 @@ udr_cprintln.c.o: U __do_copy_data 00000000 a __tmp_reg__ 00000001 a __zero_reg__ + +receiver_isr.c.o: +00000000 b _ZL13uart_instance +0000005e T _ZN4uart15stopReceiverISREv +00000050 T _ZN4uart16startReceiverISREv + U _ZN4uart5state22onDataReceiveCompletedEh +0000003e a __SP_H__ +0000003d a __SP_L__ +0000003f a __SREG__ + U __do_clear_bss +00000000 a __tmp_reg__ +00000000 T __vector_18 +00000001 a __zero_reg__ diff --git a/HelloNativeLibs/avr/Hellouart/output/libHelloUART.elf b/HelloNativeLibs/avr/Hellouart/output/libHelloUART.elf index cbc7839f0b3f923fb37dd97c715ad99aab6b40df..42b908b88577c210739832b39f30aa2a9b9d25bb 100755 GIT binary patch delta 135 zcmV;20C@j|R)kiN-T^4F-x&b`P?PxqX8{_MVFFbU8UgLk-;vLeACV7{|B&yHlQ07m z2!ZL5;0}~s0h7i8C;^0%?*c=!P6LJ(0jaaq8505luCwVIKLG)tvnd__0Rc3#DIX64 p0Z_9!AqN2&b!2j1V{me5ZgehV0CHtxWodS0a$jk4aVFFbUPXX=E-;vLeACV7{|B&yHlV$@b z0fCbX14A0%?C{`#frbD5&-(#@fq;|70EFq0;0}~s0kcd4h!z2>v(*_B0s)e<=^H-* z0fe(D9sdCVp0g<*4*~%+vpFFL0U2^-V`XV}WpZC>b8;?Y0Ci+?Ut@4`X>N40St6?l DjbA(u diff --git a/HelloNativeLibs/avr/Hellouart/output/libHelloUART.hex b/HelloNativeLibs/avr/Hellouart/output/libHelloUART.hex index 2500c1d1..dc5fb927 100644 --- a/HelloNativeLibs/avr/Hellouart/output/libHelloUART.hex +++ b/HelloNativeLibs/avr/Hellouart/output/libHelloUART.hex @@ -2,7 +2,7 @@ :100010000C9451000C9451000C9451000C9451001C :100020000C9451000C9451000C9451000C9451000C :100030000C9451000C9451000C9451000C945100FC -:100040000C9451000C9451000C941A010C94510022 +:100040000C9451000C9451000C9428010C94510014 :100050000C946A010C9451000C9451000C945100C2 :100060000C9451000C94510011241FBECFEFD8E026 :10007000DEBFCDBF11E0A0E0B1E0EEE4F6E002C0EB @@ -20,28 +20,28 @@ :1001300071E082E891E00E94F3001F910F91EF902F :10014000089588E18093C1008EE08093C20070938F :10015000C5006093C40085E891E00E94590085E8DD -:1001600091E00E944201089588E891E00E945F00BA +:1001600091E00E945001089588E891E00E945F00AC :100170001092C1000895CF92DF92EF920F931F93D8 :10018000CF93DF9362E070E081E090E00E949D01F8 :100190006C014E2D50E0BC01802F912F0E94E50292 :1001A000D0E0C0E0860101501109F6010190002065 :1001B000E9F73197EC19FD09CE17DF0748F42196CE -:1001C000B8016C0F7D1F8BE891E00E944F01EDCFCD +:1001C000B8016C0F7D1F8BE891E00E941A01EDCF02 :1001D000C6010E945502DF91CF911F910F91EF90C0 :1001E000DF90CF900895EF92FF920F931F93CF93DC :1001F000DF938B01D0E0C0E07B0181E0E81AF108D9 :10020000F80101900020E9F73197E01BF10BCE17C0 :10021000DF0748F42196B7016C0F7D1F8EE891E04F -:100220000E944F01EDCFDF91CF911F910F91FF9071 -:10023000EF9008951F920F920FB60F9211242F93F3 -:100240003F934F935F936F937F938F939F93AF935E -:10025000BF93EF93FF936091C60081E991E00E9404 -:100260006500FF91EF91BF91AF919F918F917F9129 -:100270006F915F914F913F912F910F900FBE0F9013 -:100280001F901895E1ECF0E080818068808378947D -:100290000895E1ECF0E080818F7780830895E0ECB1 -:1002A000F0E0808185FFFDCFFB0180818093C60057 -:1002B00084E991E00E945D010895E1ECF0E0808125 +:100220000E941A01EDCFDF91CF911F910F91FF90A6 +:10023000EF900895E0ECF0E0808185FFFDCFFB01B9 +:1002400080818093C60081E991E00E945D0108955C +:100250001F920F920FB60F9211242F933F934F933B +:100260005F936F937F938F939F93AF93BF93EF931E +:10027000FF936091C60084E991E00E946500FF91C0 +:10028000EF91BF91AF919F918F917F916F915F910E +:100290004F913F912F910F900FBE0F901F90189587 +:1002A000E1ECF0E080818068808378940895E1EC4F +:1002B000F0E080818F7780830895E1ECF0E0808129 :1002C0008064808378940895E1ECF0E080818F7BF6 :1002D000808308951F920F920FB60F9211242F93CF :1002E0003F934F935F936F937F938F939F93AF93BE diff --git a/HelloNativeLibs/avr/libuart/build/build.sh b/HelloNativeLibs/avr/libuart/build/build.sh index d5ea55ed..df8a5754 100755 --- a/HelloNativeLibs/avr/libuart/build/build.sh +++ b/HelloNativeLibs/avr/libuart/build/build.sh @@ -1,6 +1,9 @@ +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` + echo -e "--Building the libuart into a static object file---" echo "Ccoffee Script starts" echo "---------------------------------------------" -source compile.sh +source $build_dir"/"compile.sh echo "---------------------------------------------" echo "Ccoffee Script finishes" diff --git a/HelloNativeLibs/avr/libuart/build/compile.sh b/HelloNativeLibs/avr/libuart/build/compile.sh index 1075e3c8..75cd4419 100755 --- a/HelloNativeLibs/avr/libuart/build/compile.sh +++ b/HelloNativeLibs/avr/libuart/build/compile.sh @@ -1,5 +1,8 @@ -source variables.sh -export LC_ALL=C +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` + +source $build_dir"/"variables.sh + function compile() { # attrs : dir to compile & sharedLib name cd ${project}'/src/lib/' diff --git a/HelloNativeLibs/avr/libuart/build/variables.sh b/HelloNativeLibs/avr/libuart/build/variables.sh index c5007395..2ba4d727 100644 --- a/HelloNativeLibs/avr/libuart/build/variables.sh +++ b/HelloNativeLibs/avr/libuart/build/variables.sh @@ -4,12 +4,14 @@ #* @author pavl_g. #*# +# export all locales as C +export LC_ALL=C + +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` -# define work directory -# 1) print the current working directory to a string value -pwd=`pwd` # cut the working directory from its end by a one '/' delimiter -project="${pwd%/*}" +project=`dirname $build_dir` avr_examples_dir="${project%/*}" diff --git a/HelloNativeLibs/avr/libuart/output/libuart.a b/HelloNativeLibs/avr/libuart/output/libuart.a index 8f7c35ab26a0d380866d910427c7a0aecefc365c..70857d27345b92f48e4fe2d3c361e393b7c24150 100755 GIT binary patch delta 296 zcmcandZToLEUTr7xw+v)r34{e8wLi$2nGf-1sI-e%_=+DjmvxDp9Pa2GImX#&FIR^ zpszoRYGJCwV5o?teN$tU)o8L9`QNK5K4vK}t^<1p?#L5a=p pl&uk5@y&mAcvvBNH}e@Wvq+ko;d7mn*)*2P0%oF69eNt`SOBgQO<@24 delta 303 zcmcandZToLEUSryp_#=*r34|JGYkwcZ1{zN!AxMXHLL987=6jf@mxj||16lS&g3%L zpNV7g60PLPp8CR*C7F1c8T9oh7cyy2p2_4fnT=U!@H#UzlsbZ}hg1Fpf-AB4 vow7B8E513OodD6>M%<`Wa&oU8kWd9tFJ2$FT3hSOO94E<1X diff --git a/HelloNativeLibs/avr/libuart/output/libuart.map b/HelloNativeLibs/avr/libuart/output/libuart.map index a5d727f7..41c9cad1 100644 --- a/HelloNativeLibs/avr/libuart/output/libuart.map +++ b/HelloNativeLibs/avr/libuart/output/libuart.map @@ -98,19 +98,6 @@ udr_sprint.c.o: 00000000 a __tmp_reg__ 00000001 a __zero_reg__ -receiver_isr.c.o: -00000000 b _ZL13uart_instance -0000005e T _ZN4uart15stopReceiverISREv -00000050 T _ZN4uart16startReceiverISREv - U _ZN4uart5state22onDataReceiveCompletedEh -0000003e a __SP_H__ -0000003d a __SP_L__ -0000003f a __SREG__ - U __do_clear_bss -00000000 a __tmp_reg__ -00000000 T __vector_18 -00000001 a __zero_reg__ - udr_reset_isr.c.o: 00000000 b _ZL13uart_instance 0000000e T _ZN4uart30stopDataRegisterEmptyBufferISREv @@ -147,3 +134,16 @@ udr_cprintln.c.o: U __do_copy_data 00000000 a __tmp_reg__ 00000001 a __zero_reg__ + +receiver_isr.c.o: +00000000 b _ZL13uart_instance +0000005e T _ZN4uart15stopReceiverISREv +00000050 T _ZN4uart16startReceiverISREv + U _ZN4uart5state22onDataReceiveCompletedEh +0000003e a __SP_H__ +0000003d a __SP_L__ +0000003f a __SREG__ + U __do_clear_bss +00000000 a __tmp_reg__ +00000000 T __vector_18 +00000001 a __zero_reg__ From 38188b46f1055fb22892fa2fcc9064eee643f9a4 Mon Sep 17 00:00:00 2001 From: pavl_g Date: Mon, 17 Oct 2022 07:32:33 +0200 Subject: [PATCH 4/9] NativeLibs: Added an Rs232-interface lib for amd64 processors --- HelloNativeLibs/amd-64/Rs232-Interface/build/.build | 0 HelloNativeLibs/amd-64/Rs232-Interface/output/.build | 0 .../amd-64/Rs232-Interface/src/include/TerminalControl.h | 4 ++++ .../amd-64/Rs232-Interface/src/lib/TerminalControl.c | 7 +++++++ 4 files changed, 11 insertions(+) create mode 100644 HelloNativeLibs/amd-64/Rs232-Interface/build/.build create mode 100644 HelloNativeLibs/amd-64/Rs232-Interface/output/.build create mode 100644 HelloNativeLibs/amd-64/Rs232-Interface/src/include/TerminalControl.h create mode 100644 HelloNativeLibs/amd-64/Rs232-Interface/src/lib/TerminalControl.c diff --git a/HelloNativeLibs/amd-64/Rs232-Interface/build/.build b/HelloNativeLibs/amd-64/Rs232-Interface/build/.build new file mode 100644 index 00000000..e69de29b diff --git a/HelloNativeLibs/amd-64/Rs232-Interface/output/.build b/HelloNativeLibs/amd-64/Rs232-Interface/output/.build new file mode 100644 index 00000000..e69de29b diff --git a/HelloNativeLibs/amd-64/Rs232-Interface/src/include/TerminalControl.h b/HelloNativeLibs/amd-64/Rs232-Interface/src/include/TerminalControl.h new file mode 100644 index 00000000..2ccfd208 --- /dev/null +++ b/HelloNativeLibs/amd-64/Rs232-Interface/src/include/TerminalControl.h @@ -0,0 +1,4 @@ +#ifndef _TERMINAL_CONTROL_RS232 +#define _TERMINAL_CONTROL_RS232 + +#endif diff --git a/HelloNativeLibs/amd-64/Rs232-Interface/src/lib/TerminalControl.c b/HelloNativeLibs/amd-64/Rs232-Interface/src/lib/TerminalControl.c new file mode 100644 index 00000000..8ab6d8c7 --- /dev/null +++ b/HelloNativeLibs/amd-64/Rs232-Interface/src/lib/TerminalControl.c @@ -0,0 +1,7 @@ +#include + +int main(int argc, char **argv) +{ + printf("give me a bottle of rum!\n"); + return 0; +} From 8f923f78622a91c181b8d927771966d9dc3fff05 Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 18 Oct 2022 21:40:30 +0200 Subject: [PATCH 5/9] Avr-Libs: Added the bash shebang for the build scripts for bash-non-default OS --- HelloNativeLibs/avr/Hellouart/build/build.sh | 2 ++ HelloNativeLibs/avr/Hellouart/build/compile.sh | 2 ++ HelloNativeLibs/avr/Hellouart/build/upload.sh | 2 ++ HelloNativeLibs/avr/Hellouart/build/variables.sh | 2 ++ HelloNativeLibs/avr/libuart/build/build.sh | 2 ++ HelloNativeLibs/avr/libuart/build/compile.sh | 2 ++ HelloNativeLibs/avr/libuart/build/variables.sh | 2 ++ 7 files changed, 14 insertions(+) diff --git a/HelloNativeLibs/avr/Hellouart/build/build.sh b/HelloNativeLibs/avr/Hellouart/build/build.sh index d4c038cb..bd0c09ff 100755 --- a/HelloNativeLibs/avr/Hellouart/build/build.sh +++ b/HelloNativeLibs/avr/Hellouart/build/build.sh @@ -1,3 +1,5 @@ +#!/bin/bash + canonical_link=`readlink -f ${0}` build_dir=`dirname $canonical_link` diff --git a/HelloNativeLibs/avr/Hellouart/build/compile.sh b/HelloNativeLibs/avr/Hellouart/build/compile.sh index c3011366..fbc53f07 100755 --- a/HelloNativeLibs/avr/Hellouart/build/compile.sh +++ b/HelloNativeLibs/avr/Hellouart/build/compile.sh @@ -1,3 +1,5 @@ +#!/bin/bash + canonical_link=`readlink -f ${0}` build_dir=`dirname $canonical_link` diff --git a/HelloNativeLibs/avr/Hellouart/build/upload.sh b/HelloNativeLibs/avr/Hellouart/build/upload.sh index 08cac593..3c9fabd6 100755 --- a/HelloNativeLibs/avr/Hellouart/build/upload.sh +++ b/HelloNativeLibs/avr/Hellouart/build/upload.sh @@ -1,3 +1,5 @@ +#!/bin/bash + canonical_link=`readlink -f ${0}` build_dir=`dirname $canonical_link` diff --git a/HelloNativeLibs/avr/Hellouart/build/variables.sh b/HelloNativeLibs/avr/Hellouart/build/variables.sh index f63bc65c..3f016176 100644 --- a/HelloNativeLibs/avr/Hellouart/build/variables.sh +++ b/HelloNativeLibs/avr/Hellouart/build/variables.sh @@ -1,3 +1,5 @@ +#!/bin/bash + #** #* Ccoffee Build tool, manual build, alpha-v1. #* diff --git a/HelloNativeLibs/avr/libuart/build/build.sh b/HelloNativeLibs/avr/libuart/build/build.sh index df8a5754..68c2c0b0 100755 --- a/HelloNativeLibs/avr/libuart/build/build.sh +++ b/HelloNativeLibs/avr/libuart/build/build.sh @@ -1,3 +1,5 @@ +#!/bin/bash + canonical_link=`readlink -f ${0}` build_dir=`dirname $canonical_link` diff --git a/HelloNativeLibs/avr/libuart/build/compile.sh b/HelloNativeLibs/avr/libuart/build/compile.sh index 75cd4419..f8d6dca7 100755 --- a/HelloNativeLibs/avr/libuart/build/compile.sh +++ b/HelloNativeLibs/avr/libuart/build/compile.sh @@ -1,3 +1,5 @@ +#!/bin/bash + canonical_link=`readlink -f ${0}` build_dir=`dirname $canonical_link` diff --git a/HelloNativeLibs/avr/libuart/build/variables.sh b/HelloNativeLibs/avr/libuart/build/variables.sh index 2ba4d727..29163747 100644 --- a/HelloNativeLibs/avr/libuart/build/variables.sh +++ b/HelloNativeLibs/avr/libuart/build/variables.sh @@ -1,3 +1,5 @@ +#!/bin/bash + #** #* Ccoffee Build tool, manual build, alpha-v1. #* From f12a86ee3206466a1061eb1e1417efbba065f9ff Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 25 Oct 2022 13:22:29 +0200 Subject: [PATCH 6/9] Added amd-64 dynamic libs and the overview README data --- HelloNativeLibs/README.md | 116 +++++++- .../Hello-Rs232/build/build.sh | 23 ++ .../Hello-Rs232/build/compile.sh | 57 ++++ .../Hello-Rs232/build/variables.sh | 39 +++ .../native/Linux/linux-x86-x64/librs232.so | Bin 0 -> 19296 bytes .../output/linux-x86-x64/HelloRs232.elf | Bin 0 -> 19056 bytes .../Hello-Rs232/src/include/BufferUtils.h | 124 +++++++++ .../Hello-Rs232/src/include/DynamicBuffer.h | 155 +++++++++++ .../Hello-Rs232/src/include/ErrnoUtils.h | 53 ++++ .../Hello-Rs232/src/include/Rs232Service.h | 34 +++ .../Hello-Rs232/src/include/info.md | 6 + .../src/include/linux/SerialUtils.h | 77 ++++++ .../src/include/linux/TerminalDevice.h | 258 ++++++++++++++++++ .../Hello-Rs232/src/include/linux/Thread.h | 51 ++++ .../Hello-Rs232/src/include/linux/info.md | 1 + .../Hello-Rs232/src/lib/Rs232Service.c | 127 +++++++++ .../Hello-Rs232/src/main/main.c | 25 ++ .../Rs232-Interface/build/build.sh | 28 ++ .../Rs232-Interface/build/compile.sh | 131 +++++++++ .../Rs232-Interface/build/variables.sh | 57 ++++ .../native/Linux/linux-x86-x64/librs232.so | Bin 0 -> 19296 bytes .../Rs232-Interface/src/include/BufferUtils.h | 124 +++++++++ .../src/include/DynamicBuffer.h | 155 +++++++++++ .../Rs232-Interface/src/include/ErrnoUtils.h | 53 ++++ .../Rs232-Interface/src/include/info.md | 6 + .../src/include/linux/SerialUtils.h | 77 ++++++ .../src/include/linux/TerminalDevice.h | 258 ++++++++++++++++++ .../src/include/linux/Thread.h | 51 ++++ .../Rs232-Interface/src/include/linux/info.md | 1 + .../Rs232-Interface/src/lib/DynamicBuffer.c | 62 +++++ .../Rs232-Interface/src/lib/info.md | 4 + .../src/lib/linux/TerminalDevice.c | 249 +++++++++++++++++ .../Rs232-Interface/src/lib/linux/Thread.c | 40 +++ .../amd-64/Rs232-Interface/build/.build | 0 .../amd-64/Rs232-Interface/output/.build | 0 .../src/include/TerminalControl.h | 4 - .../Rs232-Interface/src/lib/TerminalControl.c | 7 - .../Hello-Rs232/build/build.sh | 21 ++ .../Hello-Rs232/build/compile.sh | 54 ++++ .../Hello-Rs232/build/variables.sh | 37 +++ .../output/linux-x86-x64/HelloRs232.elf | Bin 0 -> 17816 bytes .../Hello-Rs232/src/include/BufferUtils.h | 124 +++++++++ .../Hello-Rs232/src/include/DynamicBuffer.h | 155 +++++++++++ .../Hello-Rs232/src/include/ErrnoUtils.h | 53 ++++ .../Hello-Rs232/src/include/info.md | 6 + .../src/include/linux/SerialUtils.h | 77 ++++++ .../src/include/linux/TerminalDevice.h | 258 ++++++++++++++++++ .../Hello-Rs232/src/include/linux/Thread.h | 51 ++++ .../Hello-Rs232/src/include/linux/info.md | 1 + .../Hello-Rs232/src/main/main.c | 34 +++ .../Rs232-Interface/build/build.sh | 26 ++ .../Rs232-Interface/build/compile.sh | 129 +++++++++ .../Rs232-Interface/build/variables.sh | 37 +++ .../Rs232-Interface/src/include/BufferUtils.h | 124 +++++++++ .../src/include/DynamicBuffer.h | 155 +++++++++++ .../Rs232-Interface/src/include/ErrnoUtils.h | 53 ++++ .../Rs232-Interface/src/include/info.md | 6 + .../src/include/linux/SerialUtils.h | 77 ++++++ .../src/include/linux/TerminalDevice.h | 258 ++++++++++++++++++ .../src/include/linux/Thread.h | 51 ++++ .../Rs232-Interface/src/include/linux/info.md | 1 + .../Rs232-Interface/src/lib/DynamicBuffer.c | 62 +++++ .../Rs232-Interface/src/lib/info.md | 4 + .../src/lib/linux/TerminalDevice.c | 249 +++++++++++++++++ .../Rs232-Interface/src/lib/linux/Thread.c | 40 +++ .../native/Linux/linux-x86-x64/librs232.so | Bin 0 -> 19296 bytes 66 files changed, 4581 insertions(+), 15 deletions(-) create mode 100755 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/build/build.sh create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/build/compile.sh create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/build/variables.sh create mode 100755 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/libs/shared/native/Linux/linux-x86-x64/librs232.so create mode 100755 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/output/linux-x86-x64/HelloRs232.elf create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/BufferUtils.h create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/DynamicBuffer.h create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/ErrnoUtils.h create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/Rs232Service.h create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/info.md create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/SerialUtils.h create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/TerminalDevice.h create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/Thread.h create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/info.md create mode 100755 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/lib/Rs232Service.c create mode 100755 HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/main/main.c create mode 100755 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/build/build.sh create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/build/compile.sh create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/build/variables.sh create mode 100755 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/shared/native/Linux/linux-x86-x64/librs232.so create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/BufferUtils.h create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/DynamicBuffer.h create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/ErrnoUtils.h create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/info.md create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/SerialUtils.h create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/TerminalDevice.h create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/Thread.h create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/info.md create mode 100755 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/DynamicBuffer.c create mode 100644 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/info.md create mode 100755 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/linux/TerminalDevice.c create mode 100755 HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/linux/Thread.c delete mode 100644 HelloNativeLibs/amd-64/Rs232-Interface/build/.build delete mode 100644 HelloNativeLibs/amd-64/Rs232-Interface/output/.build delete mode 100644 HelloNativeLibs/amd-64/Rs232-Interface/src/include/TerminalControl.h delete mode 100644 HelloNativeLibs/amd-64/Rs232-Interface/src/lib/TerminalControl.c create mode 100755 HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/build/build.sh create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/build/compile.sh create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/build/variables.sh create mode 100755 HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/output/linux-x86-x64/HelloRs232.elf create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/BufferUtils.h create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/DynamicBuffer.h create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/ErrnoUtils.h create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/info.md create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/SerialUtils.h create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/TerminalDevice.h create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/Thread.h create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/info.md create mode 100755 HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/main/main.c create mode 100755 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/build/build.sh create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/build/compile.sh create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/build/variables.sh create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/BufferUtils.h create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/DynamicBuffer.h create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/ErrnoUtils.h create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/info.md create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/SerialUtils.h create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/TerminalDevice.h create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/Thread.h create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/info.md create mode 100755 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/DynamicBuffer.c create mode 100644 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/info.md create mode 100755 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/linux/TerminalDevice.c create mode 100755 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/linux/Thread.c create mode 100755 HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/static/native/Linux/linux-x86-x64/librs232.so diff --git a/HelloNativeLibs/README.md b/HelloNativeLibs/README.md index 05c465b7..ccf26d13 100644 --- a/HelloNativeLibs/README.md +++ b/HelloNativeLibs/README.md @@ -11,14 +11,14 @@ | `Objective` | `Static Native libraries` | `Dynamic Native libraries` | |-------------|---------------------------|----------------------------| -| Definition | Are object files that includes all the sources for the target compiled project including the external included sources | Are object files that includes the project sources only +| Definition | Are object files that includes all the sources for the target compiled project including the external included sources | Are object files that includes the project sources only and symbolic runtime links for the other dynamic libraries | | Other names | Compile-time libraries | Shared or Runtime libraries | | Time of linking | At the compile time, the static object files are linked to the project and compiled with the project sources to an executable file | At the runtime, the loader loads the runtime library | -------------------------------------------------------- ## 2) Simple project compilation using intel gcc V.S. avr-gcc: -- Quick Overview: +### Quick Overview: | `Compiling for intel/arm processors` | `Compiling for avr MCUs` | |--------------------------------------|--------------------------| @@ -26,16 +26,124 @@ 1) Compiling the project into a dynamic/shared (or runtime) library for intel processors: +- The linker gnu (GNU ld) program makes sure to load the dynamic library on application runtime and link the library to the application code automatically, however you can do this also manually and here comes the difference in operation between shared and dynamic libs. + +- Here is how to compile the project to a dynamic library: +```bash +function linux_x86_x64() { + local native_sources=$1 + if [[ ! -d $linux_natives_dir'/linux-x86-x64' ]]; then + mkdir -p $linux_natives_dir'/linux-x86-x64' + fi + $gcc -fPIC -v $native_sources -shared -o $linux_natives_dir'/linux-x86-x64/'${clibName} \ + -I${JAVA__HOME%/*}'/include' \ + -I${JAVA__HOME%/*}'/include/linux' \ + -I${nativessrc_directory}'/include/linux/' \ + -I${nativessrc_directory}'/include/' \ + + return $? +} +``` + +- Here is how to link the library to another project and add the library path to the gnu ld: +```bash +function linux_x86_x64() { + local native_sources=$1 + if [[ ! -d $output_dir'/linux-x86-x64' ]]; then + mkdir -p $output_dir'/linux-x86-x64' + fi + $gcc -fpie $native_sources -o $output_dir'/linux-x86-x64/'${clibName} \ + -I${JAVA__HOME%/*}'/include' \ + -I${JAVA__HOME%/*}'/include/linux' \ + -I${nativessrc_directory}'/include/linux/' \ + -I${nativessrc_directory}'/include' \ + -L$linux_libs_root_dir \ + -Wl,-rpath,$linux_libs_root_dir \ + -l'rs232' + + return $? +} +``` + +- For shared libraries, the linker library can be included in the code using `dlfcn.h` and dynamic libraries can be loaded in code using the absolute file path and you won't need to link the library at the project compile-time. 2) Compiling the project into a static (or compile-time) library for intel processors: +--- WIP --- 3) Compiling the project into a dynamic/shared (or runtime) library for avr MCUs: +``` +There is no way to use the dynamic linked libraries on a microcontroller, since there is no a runtime environment to act upon (the linker program needs a linux machine), so shared libraries on avr-gcc isn't supported. +``` -4) Compiling the project into a dynamic/shared (or runtime) library: +4) Compiling the project into a static library for avr MCUs: +- Compiling of source files into object files and then packaging the object files into a library archive using the `ar` archive gnu binutil tool: +```bash +function compile() { + + cd ${project}'/src/lib/' + nativeSources=(`ls *.c *.cpp *.c++ *.cxx`) + for ((i=0; i<${#nativeSources[@]}; i++)); do + ${AVR_HOME}'/bin/avr-g++' \ + -c -O -x c++ \ + -mmcu=${CHIP} "${project}/src/lib/${nativeSources[i]}" \ + -I${AVR_HOME}'/avr/include' \ + -I${project}'/src/include' \ + -o "${project}/output/${nativeSources[i]}.o" + done -- Analysis of the compiler command and command options: + objectcode=`find ${project}'/output/' -name '*.o'` + ${AVR_HOME}'/bin/avr-ar' rcs ${output}'.a' $objectcode + + ${AVR_HOME}'/bin/avr-nm' ${output}'.a' > ${output}'.map' + +} +``` +- Linking the static library to another project: +```bash +function compile() { + # addLibsTold + # attrs : dir to compile & sharedLib name + nativeSources=`find ${project}'/src/lib' -name '*.c' -o -name '*.cxx' -o -name '*.cpp' -o -name '*.c++'` + + # compile to ``.elf`` full program (Executable and Linkable format) + ${AVR_HOME}'/bin/avr-g++' -O2 -x c++ \ + -mmcu=${CHIP} ${nativeSources} \ + -I${AVR_HOME}'/avr/include' \ + -I${project}'/src/include' \ + -L"${project}/libs/" -l'uart' \ + -o ${output}'.elf' + + return $? +} +``` +- Object files are selectively added to the final code if a call has been made to their source functions in the main source code (to resolve undefined references), otherwise they aren't added to the final elf, even if you have included their function prototypes. + +5) Analysis of the compiler command and command options: + +- `gcc`: GNU C Collections Toolchains (or GNU C Compiler), is a GNU binutil designed to compile and link C code into static object files and shared object files, object-code is a machine specific generated code, this machine-code is interpreted into hex code when runnning on the CPU, you need to do the interpretation manually on some tiny devices like (MCUs) before uploading using the `object-copy` gnu binutils as follows: +```bash +function convertToHex() { + ${AVR_HOME}'/bin/avr-objcopy' -I 'elf32-avr' -O 'ihex' ${output}'.elf' ${output}'.hex' + return $? +} +``` +- `g++`: GNU C++ Compiler Toolchains, is the same as gcc with added functionalities to compile and link C++ code into object files. + +- `-mmcu=[CHIP]`: Defines the chip (micro-controller unit) used to compile the code, this ensures that the io package is the right package for the target hardware at the compile-time. + +- `-I[DIR]`: Adds a directory to the include path. + +- `-L[LIB-DIR]`: Adds a library directory to the gnu linker at compile-time. + +- `-Wl,-rpath=[DYNAMIC-LIB-DIR]`: Adds a library path (dynamic library) to the runtime path of the linker. + +- `-o[OUTPUT]`: Specifies the output object-code. + +- `-c`: Commands the gnu compiler to compile the source only to static object files and skip the linking step. + +- `-x[LANGUAGE]`: Explicitly specifies the language to use. diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/build/build.sh b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/build/build.sh new file mode 100755 index 00000000..b370e2b8 --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/build/build.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +#** +#* Ccoffee Build tool, manual build, alpha-v1. +#* +#* @author pavl_g. +#*# + +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` + +echo "Compiling the project" +echo -e $RESET_Cs +echo "--------Script start--------" + +source $build_dir'/compile.sh' + +echo -e $RESET_Cs + +compile + +echo -e $RESET_Cs +echo "--------Script end--------" diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/build/compile.sh b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/build/compile.sh new file mode 100644 index 00000000..97fc784a --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/build/compile.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +#** +#* Ccoffee Build tool, manual build, alpha-v1. +#* +#* @author pavl_g. +#*# + +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` + +source $build_dir'/variables.sh' + +## +# Compile and build native sources. +# +# @echo Script Succeeded if all the commands have passed successfully, exit with error code otherwise. +## +function compile() { + native_sources=`find $nativessrc_directory'/main' $nativessrc_directory'/lib' -name '*.c' -o -name '*.cxx' -o -name '*.cpp' -o -name '*.c++'-o -name '*.ino'` + # tests if the sources exist, then give the current user full permissions on them and compile them + chmod +x $native_sources + # append -lwiringPi for raspberry wiringPi includes + # ${JAVA__HOME%/*} : % returns back to the root base directory of the java home, / is the separator delimiter of the directory string + # compile and build a shared lib for linux systems + if [[ `linux_x86_x64 "${native_sources}"` -eq 0 ]]; then + echo -e "$GREEN_C Task@Build Linux-x86-x64 : Succeeded" + else + echo -e "$RED_C Task@Build Linux-x86-x64 : Failed" + echo -e "$RED_C Exiting Script with error 150" + exit 150 + fi + echo -e "$GREEN_C---MajorTask@Build Native Sources : Succeeded---" +} + +## +# Build for desktop linux systems +# +# @param nativeSources sources to be compiled for linux desktop. +# @return 0 if command passes, non zero number otherwise with exit code 150 (search the code on repo's wiki). +## +function linux_x86_x64() { + local native_sources=$1 + if [[ ! -d $output_dir'/linux-x86-x64' ]]; then + mkdir -p $output_dir'/linux-x86-x64' + fi + $gcc -fpie $native_sources -o $output_dir'/linux-x86-x64/'${clibName} \ + -I${JAVA__HOME%/*}'/include' \ + -I${JAVA__HOME%/*}'/include/linux' \ + -I${nativessrc_directory}'/include/linux/' \ + -I${nativessrc_directory}'/include' \ + -L$linux_libs_root_dir \ + -Wl,-rpath,$linux_libs_root_dir \ + -l'rs232' + + return $? +} \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/build/variables.sh b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/build/variables.sh new file mode 100644 index 00000000..1832bcbf --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/build/variables.sh @@ -0,0 +1,39 @@ +#** +#* Ccoffee Build tool, manual build, alpha-v1. +#* +#* @author pavl_g. +#*# + +# print the canonical file name from its symbolic link +canonical_link=`readlink -f ${0}` +#!/bin/bash + +# get the directory name of this canonical name +build_dir=`dirname $canonical_link` + +# work directories +project_root="${build_dir%/*}" + +dynamic_libs_dir="${project_root%/*}" + +amd_examples_dir="${dynamic_libs_dir%/*}" + +hello_native_libs="${amd_examples_dir%/*}" + +# cut the working directory from its end by a one '/' delimiter again +avr_sandbox_root="${hello_native_libs%/*}" + +# constant independent +clibName=('HelloRs232.elf') + +# native toolchains +gcc='g++-10' + +# code sources +nativessrc_directory=$project_root'/src' + +# native shared/dynamic libs +linux_libs_root_dir=$project_root'/libs/shared/native/Linux/linux-x86-x64/' +output_dir=$project_root'/output' + +source $avr_sandbox_root'/CommonVariables.sh' diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/libs/shared/native/Linux/linux-x86-x64/librs232.so b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/libs/shared/native/Linux/linux-x86-x64/librs232.so new file mode 100755 index 0000000000000000000000000000000000000000..bdecefbb66edc68c1d0e91d2e5d7988f64a39cb8 GIT binary patch literal 19296 zcmeHP3vg6bn!f3ThZsl(5g1{lmjOh@kPdGLupw!<(F9sZ7-7(+Nq0!Qoo?)OM^G7~ z5r>`_i`CH?mG!}@<+_%#j-`xcVGswEQa-!QHJdIpYxyYdvD(c zoSNFIt>sXi|DNxEod5jianHToKR0`77C8zEG*t?<`5M)>en%p1W~`~=3lO(9TRRJX z$7*AQY*Ch#bJbfSAw{)PS*JDz&?VQcbRO#|s`#WQ+H;aJic|c}&=CV=T~VVRu}aG% zzjVHt?sUj{7gME2Rnl{^o|E+y?IMRz6df$9!bkFRHrun(2`s0m=o2vSNAUn%k8nx> zE1k~mDXR3YgdTTYDxTu63i~o{FJD}GxjjX>D*879Z4~0OcuBqXpR>vyy#Ccm)31B_ z5wm3C6RVy`Zh+~Gf=C)_syvrvS6%82bT;m5W z5<9TxIU@>mE)Do&-uNxCj4mr_gnsaQ`=0>L+L&9ijMxgwItSe;^BPFhF+lk7JudF;QF$IsXE*ncFCoh^CfZ^?tx{Bh!AEsFrq+_M(1@UvKJ7%e&NEN~Xq`*5vT z(`f>utdm6h5|r>e&XK_R@SDmi5zk`nBAVzZS4pD1%lO{&C2$Sn(;1&Yivxw`Je7O6 z-P%#IK2s7c!Sc7V{WiuoiMSPOPtqbrIUtGlDcjj;vGYgn?}Oi!f|V@)FKlN6Epn75 zNwinkPCMI~!FVI%qb&A|+0Q>(?B5SPire`dx5aGdcie8brQKO<{~3I{E{|OS-zQ=Zsvi}LjZ(;mno)3S|_$tux@P8SP7rU$7t;TVj z6dcC#FEH-lb{}GV9{Y3eSP9(CxaRY%YmP>IEpdM=?(=EB>bhEAAQ%g-3$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YL8uq?iuZ{TkmJl{$2|{+-{zK>H6ThJIqDwR>iHeCl +#include +#include + +namespace BufferUtils { + + /** + * Nullifies a single buffer cell at the index. + * + * @param buffer the buffer to nullify its cell. + * @param index the index of the buffer cell to nullify. + */ + static inline void nullifyBuffer(void** buffer, int index) { + buffer[index] = NULL; + } + + /** + * Frees the memory utilized by the individual buffer cells on a [buffer] with [count] number of cells. + * + * @param buffer the buffer to free its cells. + * @param count the number of cells to free, starting from index zero. + */ + static inline void freeBufferCells(void** buffer, int* count) { + for (int i = 0; i < *count; i++) { + BufferUtils::nullifyBuffer(buffer, i); + free(buffer[i]); + } + } + + /** + * @brief Deletes a typified buffer and frees its memory. + * + * @param buffer the buffer to delete. + */ + static inline void deleteBuffer(void* buffer) { + free(buffer); + BufferUtils::nullifyBuffer(&buffer, 0); + } + + /** + * @brief Deeply copies the data of the [src] buffer into a new + * buffer and returns it. + * + * @param src the source buffer to get the data from. + * @param count the count length of the buffer. + * @return void** a new buffer with the same data as the source. + */ + static inline void** copy(void** src, int* count) { + void** copy = (void**) calloc(1, sizeof(void**)); + for (int i = 0; i < *count; i++) { + /* add new memory on the next array block */ + copy[i] = (void*) calloc(1, sizeof(void*)); + copy[i] = src[i]; + } + return copy; + } + + /** + * @brief Re-validates the buffer from [NULL] pointers. + * + * @param buffer the buffer to re-validate. + * @param count the pointers count. + */ + static inline void reValidateBuffer(void** buffer, int* count, int* isProcessed) { + /* get a temp copy from flagged buffer */ + void** temp = BufferUtils::copy(buffer, count); + /* free the buffer cells to prepare the buffer to be reinitialized */ + BufferUtils::freeBufferCells(buffer, count); + /* re-init the buffer, removing the null pointers */ + for (int i = 0, j = 0; i < *count; i++) { + if (temp[i] == NULL) { + printf("%s\n", "zero"); + continue; + } + buffer[j] = (void*) calloc(1, sizeof(void*)); + buffer[j] = temp[i]; + j++; + } + *isProcessed = 1; + /* free the temp buffer */ + BufferUtils::freeBufferCells(temp, count); + } +} +#endif diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/DynamicBuffer.h b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/DynamicBuffer.h new file mode 100644 index 00000000..21d32850 --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/DynamicBuffer.h @@ -0,0 +1,155 @@ +/** + * @file DynamicBuffer.h + * @author pavl_g. + * @brief Represents a cross platform dynamic buffer wrapper. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _DYNAMIC_BUFFER +#define _DYNAMIC_BUFFER + +#include +#include +#include + +struct DynamicBuffer { + + int count = 0; + int isProcessed = 0; + + /** + * Declares and initializes a pointer that points to + * other void* buffers starting from index zero. + * + * @note The pointer is of single size of a type. + * @note The pointer points to only and only one buffer at a time. + * @note New buffers can be added to this pointer by dereferencing it and adding one to the memory address to move + * it to a new cell block. + * e.g: + * 1) First way of adding a new buffer to this pointer using the deep copy: + * buffer[index] = (void*) calloc(1, sizeof(void*)); + * buffer[index] = item; + * + * 2) Second way of adding a new buffer to this pointer (the one used here): + * *(buffer += count) = (void*) calloc(1, sizeof(void*)); + * *buffer = item; + * buffer -= count; + * + * 3) The superficial copy example: + * buffer[index] = item; + */ + void** buffer = (void**) calloc(1, sizeof(void**));; + + static inline struct DynamicBuffer* createNewInstance() { + return (struct DynamicBuffer*) calloc(1, sizeof(struct DynamicBuffer)); + } + + /** + * Retrieves the pointer to this dynamic buffer. + * + * @return a pointer to this array of buffers. + */ + void** getBuffer() { + return buffer; + } + + /** + * Retrieves this structure size. + * + * @return an integer representing this struct in bytes. + */ + size_t getBufferSize() { + return sizeof(struct DynamicBuffer); + } + + /** + * Resets the pointer value back to zero. + */ + void resetDataPointer() { + this->count = 0; + } + + /** + * Gets the memory address to the integer of the items count. + * + * @return a pointer referring to the memory address of the integer that represents the item counts. + */ + int* getItemsCount(); + + /** + * Adds a new buffer to this pointer in a new index. + * + * @param item a void* buffer to add. + */ + void add(void* item); + + /** + * Adds a new buffer on a particular location in this pointer replacing an old one if exists. + * + * @param index the index where the new buffer will be located in this pointer. + * @param item the buffer to add. + */ + void add(int index, void* item); + + /** + * Frees a buffer from the memory at a particular index. + * @warning this method call is expensive as it removes and revalidates the whole buffer from NULL pointers. + * + * @param index the index of the buffer to remove. + */ + void removeAt(int index); + + /** + * Frees all the buffers of this pointer from the memory. + */ + void removeAll(); + + /** + * Retrieves a buffer index. + * + * @param item the buffer to get its index. + * @return the buffer index in an integer format. + */ + int getItemIndex(void* item); + + /** + * Retrieves a buffer from this pointer using its index. + * + * @param index the index where the buffer is located in this pointer. + * @return the buffer corresponding to this index. + */ + void* getItem(int index); +}; + + +#endif diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/ErrnoUtils.h b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/ErrnoUtils.h new file mode 100644 index 00000000..58ec430d --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/ErrnoUtils.h @@ -0,0 +1,53 @@ +/** + * @file ErrnoUtils.util + * @author pavl_g. + * @brief Represents native user and machine errnos. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _ERRNO_UTILS +#define _ERRNO_UTILS + +#include + +#define ERR_INVALID_PORT (-2) +#define ERR_INVALID_DIR (-3) +#define ERR_NO_RESULT (0) +#define LOGGER_DISABLED (-5) +#define ERR_OPERATION_FAILED (-1) +#define ERR_NO_AVAILABLE_TTY_DEVICES (-4) + +#define OPERATION_SUCCEEDED (1) + + +#endif diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/Rs232Service.h b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/Rs232Service.h new file mode 100644 index 00000000..a5e00b42 --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/Rs232Service.h @@ -0,0 +1,34 @@ +#ifndef _RS232_SERVICE +#define _RS232_SERVICE + +#include +#include +#include +#include +#include + +#define PORT ((const char*) "/dev/ttyUSB0") +#define HANDSHAKING_SIGNAL ((const char*) "_HANDSHAKER0 2022") +#define HANDSHAKES_LEN ((size_t) sizeof(HANDSHAKING_SIGNAL) / sizeof(HANDSHAKING_SIGNAL[0])) + +static pthread_mutex_t handshake_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t handshake_cond = PTHREAD_COND_INITIALIZER; + +static pthread_t handshakeTx_service; +static pthread_t handshakeRx_service; + +static int fd = 0; + +int* startRs232Service(); + +void initRs232Service(int* fd); + +void* stopRs232Service(int*); + +void* handshakeDeviceDriver(void*); + +void* logHandshakingSignals(void*); + +void releaseRs232Service(); + +#endif \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/info.md b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/info.md new file mode 100644 index 00000000..166e55df --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/info.md @@ -0,0 +1,6 @@ +# Serial4j API C Utils + +## Includes the following: +- BufferUtils.h: for managing native buffers. +- DynamicBuffer.h: for creating dynamic buffers. +- ErrnoUtils.h: for checking and referencing different errno code numbers. \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/SerialUtils.h b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/SerialUtils.h new file mode 100644 index 00000000..007d1a5e --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/SerialUtils.h @@ -0,0 +1,77 @@ +/** + * @file SerialUtils.util + * @author pavl_g. + * @brief Represents utilities for the [Serial.h] library. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _SERIAL_UTILS +#define _SERIAL_UTILS + +#include +#include +#include +#include +#include + +namespace SerialUtils { + + /** + * @brief Converts a [file] into a [device] and outputs the + * result into a [buffer]. + * + * @param buffer a buffer to fill in the operation. + * @param file the file to convert into a device. + * @return char* a buffer of {"/dev/"} formula. + */ + static inline char* concatIntoDevice(char* buffer, const char* file, const char* DEVICES_DIR) { + strcat(buffer, DEVICES_DIR); + strcat(buffer, file); + return buffer; + } + + /** + * @brief Tests whether the PATH specified is a real serial port. + * + * @param path the path to specify if its a serial port. + * @return int 1 if FD is a valid descriptor, 0 otherwise. + */ + static inline int isSerialPort(char* path, const int FLAG) { + int fdp = open(path, FLAG); + int state = isatty(fdp); + close(fdp); + return state; + } +} + +#endif diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/TerminalDevice.h b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/TerminalDevice.h new file mode 100644 index 00000000..571d1c5f --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/TerminalDevice.h @@ -0,0 +1,258 @@ +/** + * @file Serial.h + * @author pavl_g. + * @brief Represents the serial port devices control and operation for POSIX systems. + * @note This is the base [HAL] (Hardware abstraction layer) for the Serial4j api. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API, RS232. + * 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 _RS232 +#define _RS232 "RS232-Interface" + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#define READ_CONFIG_SIZE (2) +#define DEVICES_DIR ((const char*) "/dev/") + +/** The default flags for the base file api */ +#define DEFAULT_FLAGS (O_RDWR | O_NONBLOCK | O_NOCTTY) + +typedef unsigned short int TerminalFlag; + +namespace TerminalDevice { + + /** Param@0 = VTIME, Param@1 = VMIN */ + const cc_t POLLING_READ[READ_CONFIG_SIZE] = {0, 0}; + const cc_t BLOCKING_READ_ONE_CHAR[READ_CONFIG_SIZE] = {0, 1}; + const cc_t READ_WITH_TIMEOUT[READ_CONFIG_SIZE] = {1, 0}; + const cc_t READ_WITH_INTERBYTE_TIMEOUT[READ_CONFIG_SIZE] = {1, 1}; + + /** + * Retrieves the termios of this tty device described by the file descriptor (fd). + * + * @param fd the virtual file descriptor for this tty device. + * @return a memory reference to the termios defining this tty device terminal attributes. + */ + struct termios* getTermiosFromFd(int* fd); + + /** + * @brief Fetches serial port devices on "/dev/" into [serialPorts] buffer. + * @note Uses , , , and . + * + * @return int (-3) if the directory ["/dev"] is invalid, (-4) if there are no tty + * devices available at the ["/dev"] directory, (1) if operation succeeded. + */ + int fetchSerialPorts(struct DynamicBuffer* serialPorts); + + /** + * @brief Opens a serial port device with a name. + * @note Uses Unix file base api and . + * + * @param port the path for the serial port device. + * @return int* a memory reference for the port file descriptor. + */ + int openPort(const char* port, int flag); + + /** + * @brief Initializes the default terminal for this device with the following default charachteristics: + * ----------- + * # c_cflag: for control mode flags. + * *** Enable these bits: + * - [CREAD]: Allow input to be received. + * - [CS8]: For charachter size 8-bit, you can use the bit mask CSIZE to read this value. + * - [CLOCAL]: Ignore modem status lines (don’t check carrier signal). + * ----------- + * # c_lflag: for local mode flags. + * ***Disable these bits: + * - [ICANON]: Canonical mode (line-by-line) input. + * - [ECHO]: Echo input characters. + * - [ECHOE]: Perform ERASE visually. + * - [ECHOK]: Echo KILL visually. + * - [ECHOKE]: Don’t output a newline after echoed KILL. + * - [ECHONL]: Echo NL (in canonical mode) even if echoing is disabled. + * - [ECHOPRT]: Echo deleted characters backward (between \ and / ). + * - [ECHOCTL]: Echo control characters visually (e.g., ^L ). + * - [ISIG]: Enable signal-generating characters (INTR, QUIT, SUSP). + * - [IEXTEN]: Enable extended processing of input characters. + * ----------- + * # c_oflag: for output mode flags. + * ***Disable these bits: + * - [OPOST]: Perform output postprocessing. + * - [ONLCR]: Map NL to CR-NL on output. + * ----------- + * # c_iflag: for input mode flags. + * ***Disable all input bit masks. + * ----------- + * # c_cc: For control characters. + * ***Sets to BLOCKING READ ONE CHAR AT A TIME MODE. + * ----------- + * + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int initTermios(int* fd); + + /** + * @brief Sets the Terminal Control Flag [c_cflag] for the [termios] variable. + * + * @param flag bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalControlFlag(TerminalFlag flag, int* fd); + + /** + * @brief Sets the Terminal Local Flag [c_lflag] for the [termios] variable. + * + * @param flag bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalLocalFlag(TerminalFlag flag, int* fd); + + /** + * @brief Sets the Terminal Output Flag [c_oflag] for the [termios] variable. + * + * @param flag bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalOutputFlag(TerminalFlag flag, int* fd); + + /** + * @brief Sets the Terminal Input Flag [c_iflag] for the [termios] variable. + * + * @param flags bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalInputFlag(TerminalFlag flag, int* fd); + + /** + * @brief Gets the Terminal Control Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal control flag in [unsigned short int]. + */ + TerminalFlag getTerminalControlFlag(int* fd); + + /** + * @brief Gets the Terminal Local Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal local flag in [unsigned short int]. + */ + TerminalFlag getTerminalLocalFlag(int* fd); + + /** + * @brief Gets the Terminal Input Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal input flag in [unsigned short int]. + */ + TerminalFlag getTerminalInputFlag(int* fd); + + /** + * @brief Gets the Terminal Output Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal output flag in [unsigned short int]. + */ + TerminalFlag getTerminalOutputFlag(int* fd); + + /** + * @brief Sets the Read Configuration Mode using a ReadConfiguration with a + * VMIN_VALUE for lesser bytes to read and VTIME_VALUE for the elapsed time to + * set if the ReadConfiguration mode provides a timeout. + * + * @param VTIME_VALUE the value of the read timeout elapsed time, the timer starts + * with this value after read() is called. + * @param VMIN_VALUE the value of the minimum number of bytes to read. + * @return int (ERR_INVALID_PORT = -2) if port isn't available, (0) otherwise. + */ + int setReadConfigurationMode(const int VTIME_VALUE, const int VMIN_VALUE, int* fd); + + /** + * @brief Get the Read Configuration Mode in a new pointer. + * + * @return int* a memory reference to the new read configuration instance holding the VTIME and VMIN. + */ + cc_t* getReadConfigurationMode(int* fd); + + /** + * @brief Sets the Baud Rate object for the terminal io. + * + * @param baudRate the baud rate (bits/seconds). + * @return int (1) for success, (-1) for failure, (-2) for invalid port. + */ + int setBaudRate(int baudRate, int* fd); + + /** + * @brief Gets the Baud Rate object. + * + * @return speed_t baud rate in integers. + */ + speed_t getBaudRate(int* fd); + + /** + * @brief Writes a data to the serial port device from a buffer. + * + * @param buffer a buffer to write to the file. + * @param length the number of charachters to write from the buffer. + * @return ssize_t the number of bytes written to the serial device, (-1) for failure, (-2) for invalid port. + */ + ssize_t writeData(const void* buffer, int length, int* fd); + + /** + * @brief Reads data from the serial port device and saves it to a buffer. + * + * @param buffer a buffer to read from the file to it. + * @param length the number of the charachters to read by this buffer. + * @return ssize_t the number of bytes read from the terminal, (-1) for failure, (-2) for invalid port. + */ + ssize_t readData(void* buffer, int length, int* fd); + + /** + * @brief Closes the serial port device. + * + * @return int (1) for success, (-1) for failure, (-2) for invalid port. + */ + int closePort(int* fd); + +} + + +#endif diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/Thread.h b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/Thread.h new file mode 100644 index 00000000..938587e8 --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/Thread.h @@ -0,0 +1,51 @@ +/** + * @file Thread.h + * @author pavl_g. + * @brief Optional header for operating within PThreads. + * @version 0.1 + * @date 2022-08-24 + * + * @note TODO. + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _THREADS +#define _THREADS + +#include +#include + +namespace POSIX { + struct Thread { + }; +} + +#endif \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/info.md b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/info.md new file mode 100644 index 00000000..000fa073 --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/info.md @@ -0,0 +1 @@ +# Rs232-Interface API designed for Linux/Unix diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/lib/Rs232Service.c b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/lib/Rs232Service.c new file mode 100755 index 00000000..91e1736c --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/lib/Rs232Service.c @@ -0,0 +1,127 @@ +#include +#include + +int* startRs232Service() { + /** create a service block to enable the retry again criteria */ + service: { + fd = TerminalDevice::openPort(PORT, DEFAULT_FLAGS); + + if (fd <= 0) { + TerminalDevice::closePort(&fd); + } else { + printf("%s\n", " --- Rs232 driver service opened --- "); + } + + // try again and block until a request is accepted -- services retry criteria. + if (fd <= 0) { + goto service; + } + } + + return &fd; +} + +void initRs232Service(int* fd) { + int state = TerminalDevice::initTermios(fd); + int baud_state = TerminalDevice::setBaudRate(B57600, fd); + if ((state | baud_state) == -2) { + perror(" --- Invalid Port --- \n"); + } else if (state < 0) { + perror(" --- Failed to initialize the service --- \n"); + } else { + printf("%s\n", " --- Initialized the Rs232 driver service --- "); + } +} + +void* handshakeDeviceDriver(void* data) { + int* service_descriptor = (int*) data; + + printf("%s\n", " --- Started Rs232 handshake service --- "); + + handshake_service:{ + assert(pthread_mutex_lock(&handshake_mutex) == 0); + assert(pthread_cond_wait(&handshake_cond, &handshake_mutex) == 0); + /* critical section starts */ + + int numberOfWrittenBytes = TerminalDevice::writeData(HANDSHAKING_SIGNAL, strlen(HANDSHAKING_SIGNAL), service_descriptor); + if (numberOfWrittenBytes == -2) { + perror(" --- Invalid Port --- \n"); + } else if (numberOfWrittenBytes < 0) { + perror(" --- Failed to handshake the service --- \n"); + } + + assert(pthread_mutex_unlock(&handshake_mutex) == 0); + /* critical section ends */ + usleep(1000000); + + goto handshake_service; + } + + + pthread_exit(NULL); +} + +void* logHandshakingSignals(void* data) { + + int* service_descriptor = (int*) data; + + char* vacant = (char*) calloc(1, sizeof(char)); + + printf("%s\n", " --- Started Rs232 log service --- "); + + /* wait for the start of the reading thread */ + printf("%s\n\r", " --- Read Rs232 driver service handshakes --- "); + + read_service:{ + assert(pthread_mutex_lock(&handshake_mutex) == 0); + /* critical section starts */ + + int numberOfReadBytes = TerminalDevice::readData((void*) vacant, 1, service_descriptor); + + if (numberOfReadBytes > 0) { + printf("%c\n", *vacant); + *vacant = 0; + } else if (numberOfReadBytes == -2) { + perror(" --- Invalid Port --- \n"); + return NULL; + } + /* critical section ends */ + + assert(pthread_cond_signal(&handshake_cond) == 0); + assert(pthread_mutex_unlock(&handshake_mutex) == 0); + usleep(10000); + + goto read_service; + } + + + + pthread_exit(NULL); +} + +void* stopRs232Service(int* service_descriptor) { + + assert(pthread_mutex_lock(&handshake_mutex) == 0); + + /* run the main command and retrieve the state */ + int state = TerminalDevice::closePort(service_descriptor); + /* log the error/print according to the state or behave differently or use a retry criteria as defined above */ + if (state == -2) { + perror(" --- Invalid Port --- \n"); + } else if (state < 0) { + perror(" --- Failed to stop the service --- \n"); + } else { + printf("%s\n", " --- Stopped Rs232 driver service successfully --- "); + } + + assert(pthread_mutex_unlock(&handshake_mutex) == 0); + + releaseRs232Service(); + + pthread_exit(NULL); +} + +void releaseRs232Service() { + assert(pthread_mutex_destroy(&handshake_mutex) == 0); + assert(pthread_cond_destroy(&handshake_cond) == 0); +} \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/main/main.c b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/main/main.c new file mode 100755 index 00000000..9693cda8 --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/main/main.c @@ -0,0 +1,25 @@ +#include + +static inline int* prepareRs232Service() { + + int* service_descriptor = startRs232Service(); + initRs232Service(service_descriptor); + + return service_descriptor; +} + +static inline void dispatchRs232Services(int* service_descriptor) { + + pthread_create(&handshakeTx_service, NULL, &handshakeDeviceDriver, service_descriptor); + pthread_create(&handshakeRx_service, NULL, &logHandshakingSignals, service_descriptor); + + pthread_join(handshakeRx_service, NULL); +} + +int main(int argc, char **argv) { + printf("%s\n", " --- Started Rs232 driver example --- "); + + dispatchRs232Services(prepareRs232Service()); + + return 0; +} diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/build/build.sh b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/build/build.sh new file mode 100755 index 00000000..d1a27d01 --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/build/build.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +#** +#* Ccoffee Build tool, manual build, alpha-v1. +#* +#* @author pavl_g. +#*# + +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` + +echo "Compiling the project" +echo -e $RESET_Cs +echo "--------Script start--------" + +source $build_dir'/compile.sh' + +echo -e $RESET_Cs + +if [[ $enable_natives_build == true ]]; then + echo -e "$MAGNETA_C---MajorTask@Build Native Sources : Native build started" + compile + copyToExample + echo -e "$MAGNETA_C---MajorTask@Build Native Sources : Native build finished" +fi + +echo -e $RESET_Cs +echo "--------Script end--------" diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/build/compile.sh b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/build/compile.sh new file mode 100644 index 00000000..d5f4b985 --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/build/compile.sh @@ -0,0 +1,131 @@ +#!/bin/bash + +#** +#* Ccoffee Build tool, manual build, alpha-v1. +#* +#* @author pavl_g. +#*# + +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` + +source $build_dir'/variables.sh' + +## +# Compile and build native sources. +# +# @echo Script Succeeded if all the commands have passed successfully, exit with error code otherwise. +## +function compile() { + native_sources=`find $nativessrc_directory'/lib' -name '*.c' -o -name '*.cxx' -o -name '*.cpp' -o -name '*.c++'-o -name '*.ino'` + # tests if the sources exist, then give the current user full permissions on them and compile them + if [[ $native_sources ]]; then + chmod +x $native_sources + # append -lwiringPi for raspberry wiringPi includes + # ${JAVA__HOME%/*} : % returns back to the root base directory of the java home, / is the separator delimiter of the directory string + # compile and build a shared lib for linux systems + if [[ `linux_x86_x64 "${native_sources}"` -eq 0 ]]; then + echo -e "$GREEN_C Task@Build Linux-x86-x64 : Succeeded" + else + echo -e "$RED_C Task@Build Linux-x86-x64 : Failed" + echo -e "$RED_C Exiting Script with error 150" + exit 150 + fi + # compile and build a shared lib for android systems + if [[ $enable_android_build == true ]]; then + if [[ `linux_android "${arm64}" "${arm64_lib}" "${native_sources}" "${min_android_sdk}"` -eq 0 ]]; then + echo -e "$GREEN_C Task@Build Android-Arm-64 : Succeeded" + else + echo -e "$RED_C Task@Build Android-Arm-64 : Failed" + echo -e "$RED_C Exiting Script with error 250" + exit 250 + fi + + if [[ `linux_android "${arm32}" "${arm32_lib}" "${native_sources}" "${min_android_sdk}"` -eq 0 ]]; then + echo -e "$GREEN_C Task@Build Android-Arm-32 : Succeeded" + else + echo -e "$RED_C Task@Build Android-Arm-32 : Failed" + echo -e "$RED_C Exiting Script with error 350" + exit 350 + fi + + if [[ `linux_android "${intel64}" "${intel64_lib}" "${native_sources}" "${min_android_sdk}"` -eq 0 ]]; then + echo -e "$GREEN_C Task@Build Android-Intel-64 : Succeeded" + else + echo -e "$RED_C Task@Build Android-Intel-64 : Failed" + echo -e "$RED_C Exiting Script with error 450" + exit 450 + fi + + if [[ `linux_android "${intel32}" "${intel32_lib}" "${native_sources}" "${min_android_sdk}"` -eq 0 ]]; then + echo -e "$GREEN_C Task@Build Android-Intel-32 : Succeeded" + else + echo -e "$RED_C Task@Build Android-Intel-32 : Failed" + echo -e "$RED_C Exiting Script with error 550" + exit 550 + fi + fi + fi + echo -e "$GREEN_C---MajorTask@Build Native Sources : Succeeded---" +} + +## +# Build for desktop linux systems +# +# @param nativeSources sources to be compiled for linux desktop. +# @return 0 if command passes, non zero number otherwise with exit code 150 (search the code on repo's wiki). +## +function linux_x86_x64() { + local native_sources=$1 + if [[ ! -d $linux_natives_dir'/linux-x86-x64' ]]; then + mkdir -p $linux_natives_dir'/linux-x86-x64' + fi + $gcc -fPIC -v $native_sources -shared -o $linux_natives_dir'/linux-x86-x64/'${clibName} \ + -I${JAVA__HOME%/*}'/include' \ + -I${JAVA__HOME%/*}'/include/linux' \ + -I${nativessrc_directory}'/include/linux/' \ + -I${nativessrc_directory}'/include/' \ + + return $? +} + +## +# Building native code for arm and intel android. +# +# @param triple the ABI triple name, also used for -target flag of the clang++. +# @param folder the created folder name. +# @param sources the sources to compile and build an object file for them. +# @param min_android_sdk the minimum android sdk to compile against. +# @return 0 if command passes, non zero number otherwise. +## +function linux_android() { + # parameters attributes + local triple=$1 + local folder=$2 + local sources=$3 + local min_android_sdk=$4 + + if [[ ! -d $android_natives_dir ]]; then + mkdir $android_natives_dir + fi + + if [[ ! -d $android_natives_dir"/$folder" ]]; then + mkdir $android_natives_dir"/$folder" + fi + $NDK__BASEHOME'/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++' -v -target ${triple}${min_android_sdk} \ + -fPIC $sources -shared \ + -stdlib=libstdc++ \ + -o $android_natives_dir"/$folder/"${clibName} \ + -I$nativessrc_directory'/includes' \ + -I$NDK__BASEHOME'/sources/cxx-stl/llvm-libc++/include' \ + -lc++_shared + result=$? + cp $NDK__BASEHOME"/sources/cxx-stl/llvm-libc++/libs/${folder}/libc++_shared.so" $android_natives_dir"/$folder" + return $result +} + +function copyToExample() { + local hello_rs232="`dirname $project_root`/Hello-Rs232" + cp -r $shared_root_dir $hello_rs232'/libs/' + cp -r ${nativessrc_directory}'/include/.' $hello_rs232'/src/include/' +} diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/build/variables.sh b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/build/variables.sh new file mode 100644 index 00000000..2f5c1b2d --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/build/variables.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +#** +#* Ccoffee Build tool, manual build, alpha-v1. +#* +#* @author pavl_g. +#*# + +# print the canonical file name from its symbolic link +canonical_link=`readlink -f ${0}` +# get the directory name of this canonical name +build_dir=`dirname $canonical_link` + +# work directories +project_root="${build_dir%/*}" + +dynamic_libs_dir="${project_root%/*}" + +amd_examples_dir="${dynamic_libs_dir%/*}" + +hello_native_libs="${amd_examples_dir%/*}" + +# cut the working directory from its end by a one '/' delimiter again +avr_sandbox_root="${hello_native_libs%/*}" + +# constant independent +clibName=('librs232.so') + +# native toolchains +gcc='g++-10' + +# android tool-chain constants +min_android_sdk=21 +arm64="aarch64-linux-android" +arm64_lib="arm64-v8a" +arm32="armv7a-linux-androideabi" +arm32_lib="armeabi-v7a" +intel32="i686-linux-android" +intel32_lib="x86" +intel64="x86_64-linux-android" +intel64_lib="x86_64" +android_natives_jar="android-natives-${min_android_sdk}.jar" + +# set some build guards +enable_natives_build=true +enable_android_build=false + +# code sources +nativessrc_directory=$project_root'/src' + +# native shared/dynamic libs +shared_root_dir=$project_root'/shared' +android_natives_dir=$project_root'/shared/lib' +linux_natives_dir=$project_root'/shared/native/Linux' + +source $avr_sandbox_root'/NDKPATH.sh' +source $avr_sandbox_root'/CommonVariables.sh' diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/shared/native/Linux/linux-x86-x64/librs232.so b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/shared/native/Linux/linux-x86-x64/librs232.so new file mode 100755 index 0000000000000000000000000000000000000000..bd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 zQ^{q`gAyq!r)=X}=0lm&R&1QkNv+9^n<1ZzlFX3wbt*6aHpyr<-d23ORHl<8Y-JOU zayny4&9Ter6Ujg(MS+|~Xev&U6-IlZ$*4^PtoceZH}F(i73D|{QhTg9xy+IsiD_-= zzin!gW$N4KE#^+8Oo9}3^)#ZDo5wIh*OB>CT7_TYi>rIOdHLyZ3(<-&&dv~*mG!yvrlHV*}G07>(4wdObKnK?ATNL zY?zGMeG+4$m9=baj{Dbw#$%E;sjEmd9xPiINtCTkgu;PKLIF+Gn*1$IT3KLY1e%f} zKUQ#BgRvH5E}AMn@M6KRpA`6NeK@X_iCah+F3Z+MQH=*T;IFt*mBpgCr}?$AU=tr@ zngTGQYEo66X{3g_Mhlb}jOL?pvJB^howY43S{Y7N%{VOC9N)e*M32unQsUWC7WIBk z(Fu$zg2x?GDMJlk>qnLT8op4po2BtMCkl?2rZO8fdZ(=P)%!k0+qgj@^lY#6)f*x= zFtV-m)q6oj)q87*h(b1uMMs6+AuE0L{!r01EUf%ja*Ec2Pw%8vUA<>i)XDl*{~6W- zxFDX=SMMVgeS!s5`_}$PSbrhQsrTv`${i+syj94F-v(eLg2yFU)cXad>V3Uplds0o zf{IaJy$4lvjV0g~^V*Ls`s#hDqN=~DO;uO)Cl-D69#GNk>I)P$pxRgVIxYI@{i~vQ z<6m*W zpe_!W>W0!&<9I7{Nkr+Z_tM={0irm?-|Qcyujt!g8TB* +#include +#include + +namespace BufferUtils { + + /** + * Nullifies a single buffer cell at the index. + * + * @param buffer the buffer to nullify its cell. + * @param index the index of the buffer cell to nullify. + */ + static inline void nullifyBuffer(void** buffer, int index) { + buffer[index] = NULL; + } + + /** + * Frees the memory utilized by the individual buffer cells on a [buffer] with [count] number of cells. + * + * @param buffer the buffer to free its cells. + * @param count the number of cells to free, starting from index zero. + */ + static inline void freeBufferCells(void** buffer, int* count) { + for (int i = 0; i < *count; i++) { + BufferUtils::nullifyBuffer(buffer, i); + free(buffer[i]); + } + } + + /** + * @brief Deletes a typified buffer and frees its memory. + * + * @param buffer the buffer to delete. + */ + static inline void deleteBuffer(void* buffer) { + free(buffer); + BufferUtils::nullifyBuffer(&buffer, 0); + } + + /** + * @brief Deeply copies the data of the [src] buffer into a new + * buffer and returns it. + * + * @param src the source buffer to get the data from. + * @param count the count length of the buffer. + * @return void** a new buffer with the same data as the source. + */ + static inline void** copy(void** src, int* count) { + void** copy = (void**) calloc(1, sizeof(void**)); + for (int i = 0; i < *count; i++) { + /* add new memory on the next array block */ + copy[i] = (void*) calloc(1, sizeof(void*)); + copy[i] = src[i]; + } + return copy; + } + + /** + * @brief Re-validates the buffer from [NULL] pointers. + * + * @param buffer the buffer to re-validate. + * @param count the pointers count. + */ + static inline void reValidateBuffer(void** buffer, int* count, int* isProcessed) { + /* get a temp copy from flagged buffer */ + void** temp = BufferUtils::copy(buffer, count); + /* free the buffer cells to prepare the buffer to be reinitialized */ + BufferUtils::freeBufferCells(buffer, count); + /* re-init the buffer, removing the null pointers */ + for (int i = 0, j = 0; i < *count; i++) { + if (temp[i] == NULL) { + printf("%s\n", "zero"); + continue; + } + buffer[j] = (void*) calloc(1, sizeof(void*)); + buffer[j] = temp[i]; + j++; + } + *isProcessed = 1; + /* free the temp buffer */ + BufferUtils::freeBufferCells(temp, count); + } +} +#endif diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/DynamicBuffer.h b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/DynamicBuffer.h new file mode 100644 index 00000000..21d32850 --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/DynamicBuffer.h @@ -0,0 +1,155 @@ +/** + * @file DynamicBuffer.h + * @author pavl_g. + * @brief Represents a cross platform dynamic buffer wrapper. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _DYNAMIC_BUFFER +#define _DYNAMIC_BUFFER + +#include +#include +#include + +struct DynamicBuffer { + + int count = 0; + int isProcessed = 0; + + /** + * Declares and initializes a pointer that points to + * other void* buffers starting from index zero. + * + * @note The pointer is of single size of a type. + * @note The pointer points to only and only one buffer at a time. + * @note New buffers can be added to this pointer by dereferencing it and adding one to the memory address to move + * it to a new cell block. + * e.g: + * 1) First way of adding a new buffer to this pointer using the deep copy: + * buffer[index] = (void*) calloc(1, sizeof(void*)); + * buffer[index] = item; + * + * 2) Second way of adding a new buffer to this pointer (the one used here): + * *(buffer += count) = (void*) calloc(1, sizeof(void*)); + * *buffer = item; + * buffer -= count; + * + * 3) The superficial copy example: + * buffer[index] = item; + */ + void** buffer = (void**) calloc(1, sizeof(void**));; + + static inline struct DynamicBuffer* createNewInstance() { + return (struct DynamicBuffer*) calloc(1, sizeof(struct DynamicBuffer)); + } + + /** + * Retrieves the pointer to this dynamic buffer. + * + * @return a pointer to this array of buffers. + */ + void** getBuffer() { + return buffer; + } + + /** + * Retrieves this structure size. + * + * @return an integer representing this struct in bytes. + */ + size_t getBufferSize() { + return sizeof(struct DynamicBuffer); + } + + /** + * Resets the pointer value back to zero. + */ + void resetDataPointer() { + this->count = 0; + } + + /** + * Gets the memory address to the integer of the items count. + * + * @return a pointer referring to the memory address of the integer that represents the item counts. + */ + int* getItemsCount(); + + /** + * Adds a new buffer to this pointer in a new index. + * + * @param item a void* buffer to add. + */ + void add(void* item); + + /** + * Adds a new buffer on a particular location in this pointer replacing an old one if exists. + * + * @param index the index where the new buffer will be located in this pointer. + * @param item the buffer to add. + */ + void add(int index, void* item); + + /** + * Frees a buffer from the memory at a particular index. + * @warning this method call is expensive as it removes and revalidates the whole buffer from NULL pointers. + * + * @param index the index of the buffer to remove. + */ + void removeAt(int index); + + /** + * Frees all the buffers of this pointer from the memory. + */ + void removeAll(); + + /** + * Retrieves a buffer index. + * + * @param item the buffer to get its index. + * @return the buffer index in an integer format. + */ + int getItemIndex(void* item); + + /** + * Retrieves a buffer from this pointer using its index. + * + * @param index the index where the buffer is located in this pointer. + * @return the buffer corresponding to this index. + */ + void* getItem(int index); +}; + + +#endif diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/ErrnoUtils.h b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/ErrnoUtils.h new file mode 100644 index 00000000..58ec430d --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/ErrnoUtils.h @@ -0,0 +1,53 @@ +/** + * @file ErrnoUtils.util + * @author pavl_g. + * @brief Represents native user and machine errnos. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _ERRNO_UTILS +#define _ERRNO_UTILS + +#include + +#define ERR_INVALID_PORT (-2) +#define ERR_INVALID_DIR (-3) +#define ERR_NO_RESULT (0) +#define LOGGER_DISABLED (-5) +#define ERR_OPERATION_FAILED (-1) +#define ERR_NO_AVAILABLE_TTY_DEVICES (-4) + +#define OPERATION_SUCCEEDED (1) + + +#endif diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/info.md b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/info.md new file mode 100644 index 00000000..166e55df --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/info.md @@ -0,0 +1,6 @@ +# Serial4j API C Utils + +## Includes the following: +- BufferUtils.h: for managing native buffers. +- DynamicBuffer.h: for creating dynamic buffers. +- ErrnoUtils.h: for checking and referencing different errno code numbers. \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/SerialUtils.h b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/SerialUtils.h new file mode 100644 index 00000000..007d1a5e --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/SerialUtils.h @@ -0,0 +1,77 @@ +/** + * @file SerialUtils.util + * @author pavl_g. + * @brief Represents utilities for the [Serial.h] library. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _SERIAL_UTILS +#define _SERIAL_UTILS + +#include +#include +#include +#include +#include + +namespace SerialUtils { + + /** + * @brief Converts a [file] into a [device] and outputs the + * result into a [buffer]. + * + * @param buffer a buffer to fill in the operation. + * @param file the file to convert into a device. + * @return char* a buffer of {"/dev/"} formula. + */ + static inline char* concatIntoDevice(char* buffer, const char* file, const char* DEVICES_DIR) { + strcat(buffer, DEVICES_DIR); + strcat(buffer, file); + return buffer; + } + + /** + * @brief Tests whether the PATH specified is a real serial port. + * + * @param path the path to specify if its a serial port. + * @return int 1 if FD is a valid descriptor, 0 otherwise. + */ + static inline int isSerialPort(char* path, const int FLAG) { + int fdp = open(path, FLAG); + int state = isatty(fdp); + close(fdp); + return state; + } +} + +#endif diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/TerminalDevice.h b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/TerminalDevice.h new file mode 100644 index 00000000..571d1c5f --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/TerminalDevice.h @@ -0,0 +1,258 @@ +/** + * @file Serial.h + * @author pavl_g. + * @brief Represents the serial port devices control and operation for POSIX systems. + * @note This is the base [HAL] (Hardware abstraction layer) for the Serial4j api. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API, RS232. + * 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 _RS232 +#define _RS232 "RS232-Interface" + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#define READ_CONFIG_SIZE (2) +#define DEVICES_DIR ((const char*) "/dev/") + +/** The default flags for the base file api */ +#define DEFAULT_FLAGS (O_RDWR | O_NONBLOCK | O_NOCTTY) + +typedef unsigned short int TerminalFlag; + +namespace TerminalDevice { + + /** Param@0 = VTIME, Param@1 = VMIN */ + const cc_t POLLING_READ[READ_CONFIG_SIZE] = {0, 0}; + const cc_t BLOCKING_READ_ONE_CHAR[READ_CONFIG_SIZE] = {0, 1}; + const cc_t READ_WITH_TIMEOUT[READ_CONFIG_SIZE] = {1, 0}; + const cc_t READ_WITH_INTERBYTE_TIMEOUT[READ_CONFIG_SIZE] = {1, 1}; + + /** + * Retrieves the termios of this tty device described by the file descriptor (fd). + * + * @param fd the virtual file descriptor for this tty device. + * @return a memory reference to the termios defining this tty device terminal attributes. + */ + struct termios* getTermiosFromFd(int* fd); + + /** + * @brief Fetches serial port devices on "/dev/" into [serialPorts] buffer. + * @note Uses , , , and . + * + * @return int (-3) if the directory ["/dev"] is invalid, (-4) if there are no tty + * devices available at the ["/dev"] directory, (1) if operation succeeded. + */ + int fetchSerialPorts(struct DynamicBuffer* serialPorts); + + /** + * @brief Opens a serial port device with a name. + * @note Uses Unix file base api and . + * + * @param port the path for the serial port device. + * @return int* a memory reference for the port file descriptor. + */ + int openPort(const char* port, int flag); + + /** + * @brief Initializes the default terminal for this device with the following default charachteristics: + * ----------- + * # c_cflag: for control mode flags. + * *** Enable these bits: + * - [CREAD]: Allow input to be received. + * - [CS8]: For charachter size 8-bit, you can use the bit mask CSIZE to read this value. + * - [CLOCAL]: Ignore modem status lines (don’t check carrier signal). + * ----------- + * # c_lflag: for local mode flags. + * ***Disable these bits: + * - [ICANON]: Canonical mode (line-by-line) input. + * - [ECHO]: Echo input characters. + * - [ECHOE]: Perform ERASE visually. + * - [ECHOK]: Echo KILL visually. + * - [ECHOKE]: Don’t output a newline after echoed KILL. + * - [ECHONL]: Echo NL (in canonical mode) even if echoing is disabled. + * - [ECHOPRT]: Echo deleted characters backward (between \ and / ). + * - [ECHOCTL]: Echo control characters visually (e.g., ^L ). + * - [ISIG]: Enable signal-generating characters (INTR, QUIT, SUSP). + * - [IEXTEN]: Enable extended processing of input characters. + * ----------- + * # c_oflag: for output mode flags. + * ***Disable these bits: + * - [OPOST]: Perform output postprocessing. + * - [ONLCR]: Map NL to CR-NL on output. + * ----------- + * # c_iflag: for input mode flags. + * ***Disable all input bit masks. + * ----------- + * # c_cc: For control characters. + * ***Sets to BLOCKING READ ONE CHAR AT A TIME MODE. + * ----------- + * + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int initTermios(int* fd); + + /** + * @brief Sets the Terminal Control Flag [c_cflag] for the [termios] variable. + * + * @param flag bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalControlFlag(TerminalFlag flag, int* fd); + + /** + * @brief Sets the Terminal Local Flag [c_lflag] for the [termios] variable. + * + * @param flag bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalLocalFlag(TerminalFlag flag, int* fd); + + /** + * @brief Sets the Terminal Output Flag [c_oflag] for the [termios] variable. + * + * @param flag bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalOutputFlag(TerminalFlag flag, int* fd); + + /** + * @brief Sets the Terminal Input Flag [c_iflag] for the [termios] variable. + * + * @param flags bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalInputFlag(TerminalFlag flag, int* fd); + + /** + * @brief Gets the Terminal Control Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal control flag in [unsigned short int]. + */ + TerminalFlag getTerminalControlFlag(int* fd); + + /** + * @brief Gets the Terminal Local Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal local flag in [unsigned short int]. + */ + TerminalFlag getTerminalLocalFlag(int* fd); + + /** + * @brief Gets the Terminal Input Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal input flag in [unsigned short int]. + */ + TerminalFlag getTerminalInputFlag(int* fd); + + /** + * @brief Gets the Terminal Output Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal output flag in [unsigned short int]. + */ + TerminalFlag getTerminalOutputFlag(int* fd); + + /** + * @brief Sets the Read Configuration Mode using a ReadConfiguration with a + * VMIN_VALUE for lesser bytes to read and VTIME_VALUE for the elapsed time to + * set if the ReadConfiguration mode provides a timeout. + * + * @param VTIME_VALUE the value of the read timeout elapsed time, the timer starts + * with this value after read() is called. + * @param VMIN_VALUE the value of the minimum number of bytes to read. + * @return int (ERR_INVALID_PORT = -2) if port isn't available, (0) otherwise. + */ + int setReadConfigurationMode(const int VTIME_VALUE, const int VMIN_VALUE, int* fd); + + /** + * @brief Get the Read Configuration Mode in a new pointer. + * + * @return int* a memory reference to the new read configuration instance holding the VTIME and VMIN. + */ + cc_t* getReadConfigurationMode(int* fd); + + /** + * @brief Sets the Baud Rate object for the terminal io. + * + * @param baudRate the baud rate (bits/seconds). + * @return int (1) for success, (-1) for failure, (-2) for invalid port. + */ + int setBaudRate(int baudRate, int* fd); + + /** + * @brief Gets the Baud Rate object. + * + * @return speed_t baud rate in integers. + */ + speed_t getBaudRate(int* fd); + + /** + * @brief Writes a data to the serial port device from a buffer. + * + * @param buffer a buffer to write to the file. + * @param length the number of charachters to write from the buffer. + * @return ssize_t the number of bytes written to the serial device, (-1) for failure, (-2) for invalid port. + */ + ssize_t writeData(const void* buffer, int length, int* fd); + + /** + * @brief Reads data from the serial port device and saves it to a buffer. + * + * @param buffer a buffer to read from the file to it. + * @param length the number of the charachters to read by this buffer. + * @return ssize_t the number of bytes read from the terminal, (-1) for failure, (-2) for invalid port. + */ + ssize_t readData(void* buffer, int length, int* fd); + + /** + * @brief Closes the serial port device. + * + * @return int (1) for success, (-1) for failure, (-2) for invalid port. + */ + int closePort(int* fd); + +} + + +#endif diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/Thread.h b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/Thread.h new file mode 100644 index 00000000..7b57ec42 --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/Thread.h @@ -0,0 +1,51 @@ +/** + * @file Thread.h + * @author pavl_g. + * @brief Optional header for operating within PThreads. + * @version 0.1 + * @date 2022-08-24 + * + * @note TODO. + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _THREADS +#define _THREADS + +#include + +namespace POSIX { + struct Thread { + + }; +} + +#endif \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/info.md b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/info.md new file mode 100644 index 00000000..000fa073 --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/include/linux/info.md @@ -0,0 +1 @@ +# Rs232-Interface API designed for Linux/Unix diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/DynamicBuffer.c b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/DynamicBuffer.c new file mode 100755 index 00000000..0bd13205 --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/DynamicBuffer.c @@ -0,0 +1,62 @@ +#include + +void DynamicBuffer::add(void* item) { + + /* move the pointer to point to the last item */ + /* then, obtain a superficial copy */ + void** copy = (buffer += count); + /* dereference and evalute using the superficial copy */ + *copy = (void*) calloc(1, sizeof(void*)); + *copy = item; + /* move the pointer back to the start of the buffer (first item) */ + buffer -= count; + count++; +} + +void DynamicBuffer::add(int index, void* item) { + /* adds on the count if the location was empty previously */ + if (buffer[index] == NULL) { + ++count; + } + buffer[index] = item; +} + +void DynamicBuffer::removeAt(int index) { + BufferUtils::nullifyBuffer(buffer, index); + BufferUtils::reValidateBuffer(buffer, getItemsCount(), &(this->isProcessed)); + + while (!this->isProcessed); + this->isProcessed = 0; + + count--; +} + +void DynamicBuffer::removeAll() { + for (int i = 0; i < *(this->getItemsCount()); i++) { + BufferUtils::nullifyBuffer(buffer, i); + } + + BufferUtils::reValidateBuffer(buffer, getItemsCount(), &(this->isProcessed)); + + while (!this->isProcessed); + this->isProcessed = 0; + + this->resetDataPointer(); +} + +void* DynamicBuffer::getItem(int index) { + return buffer[index]; +} + +int DynamicBuffer::getItemIndex(void* item) { + for (int i = 0; i < *getItemsCount(); i++) { + if (buffer[i] == item) { + return i; + } + } + return ERR_OPERATION_FAILED; +} + +int* DynamicBuffer::getItemsCount() { + return &count; +} diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/info.md b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/info.md new file mode 100644 index 00000000..d9a935a6 --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/info.md @@ -0,0 +1,4 @@ +# Serial4j API C Utils + +## Includes the following: +- DynamicBuffer.c: for creating dynamic buffers. \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/linux/TerminalDevice.c b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/linux/TerminalDevice.c new file mode 100755 index 00000000..fc587fab --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/linux/TerminalDevice.c @@ -0,0 +1,249 @@ +#include + +struct termios* TerminalDevice::getTermiosFromFd(int* fd) { + if (fd == NULL) { + return NULL; + } + struct termios* tty = (struct termios*) calloc(1, sizeof(struct termios)); + /* update the termios struct pointer with the data from the port descriptor */ + tcgetattr(*fd, tty); + return tty; +} + +int TerminalDevice::openPort(const char* port, int flag) { + return open(port, flag); +} + +int TerminalDevice::fetchSerialPorts(struct DynamicBuffer* serialPorts) { + + DIR* dirp = opendir(DEVICES_DIR); + + /* sanity check the input */ + if (dirp == NULL) { + return ERR_INVALID_DIR; + } + + struct dirent* dp = (struct dirent*) calloc(1, sizeof(struct dirent)); + + /* start at the beginning of the buffer to override last data */ + serialPorts->resetDataPointer(); + + /* start reading available ports */ + while ((dp = readdir(dirp)) != NULL) { + + char* device = (char*) calloc(1, sizeof(char)); + device = SerialUtils::concatIntoDevice(device, dp->d_name, DEVICES_DIR); + + /* delete the device buffer if it's not a serial port */ + if (!SerialUtils::isSerialPort(device, DEFAULT_FLAGS)) { + BufferUtils::deleteBuffer(device); + continue; + } + + /* add the device to the serial ports major buffer and count up */ + serialPorts->add(device); + } + + /* release resources */ + closedir(dirp); + BufferUtils::deleteBuffer(dp); + + /* throws error indicating the availability issues */ + if (serialPorts->getItem(0) == NULL) { + return ERR_NO_AVAILABLE_TTY_DEVICES; + } + return OPERATION_SUCCEEDED; +} + +int TerminalDevice::initTermios(int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + /* setup tty attributes */ + tty->c_cflag &= ~(CBAUDEX | CBAUD); /* clear BAUDs */ + tty->c_cflag |= (CREAD | CS8 | CLOCAL); /* set flags */ + tty->c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT | ECHOCTL | ISIG | IEXTEN); + tty->c_oflag &= ~(OPOST | ONLCR); + tty->c_iflag = 0x00; + + /* define default read mode as blocking read on char at a time */ + tty->c_cc[VTIME] = BLOCKING_READ_ONE_CHAR[0]; + tty->c_cc[VMIN] = BLOCKING_READ_ONE_CHAR[1]; + + /* apply attriutes flag bits */ + int state = tcsetattr(*fd, TCSAFLUSH, tty); + BufferUtils::deleteBuffer(tty); + + return state; +} + +int TerminalDevice::setTerminalControlFlag(TerminalFlag flag, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + tty->c_cflag = flag; + /* sets the new terminal settings to the file descriptor with flushing any output */ + int state = tcsetattr(*fd, TCSAFLUSH, tty); + BufferUtils::deleteBuffer(tty); + + return state; +} + +int TerminalDevice::setTerminalLocalFlag(TerminalFlag flag, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + tty->c_lflag = flag; + int state = tcsetattr(*fd, TCSAFLUSH, tty); + BufferUtils::deleteBuffer(tty); + + return state; +} + +int TerminalDevice::setTerminalInputFlag(TerminalFlag flag, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + tty->c_iflag = flag; + int state = tcsetattr(*fd, TCSAFLUSH, tty); + BufferUtils::deleteBuffer(tty); + + return state; +} + +int TerminalDevice::setTerminalOutputFlag(TerminalFlag flag, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + tty->c_oflag = flag; + int state = tcsetattr(*fd, TCSAFLUSH, tty); + BufferUtils::deleteBuffer(tty); + + return state; +} + +TerminalFlag TerminalDevice::getTerminalControlFlag(int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + return tty->c_cflag; +} + +TerminalFlag TerminalDevice::getTerminalLocalFlag(int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + return tty->c_lflag; +} + +TerminalFlag TerminalDevice::getTerminalInputFlag(int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + return tty->c_iflag; +} + +TerminalFlag TerminalDevice::getTerminalOutputFlag(int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + return tty->c_oflag; +} + +int TerminalDevice::setReadConfigurationMode(const int VTIME_VALUE, const int VMIN_VALUE, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + tty->c_cc[VTIME] = VTIME_VALUE; + tty->c_cc[VMIN] = VMIN_VALUE; + int state = tcsetattr(*fd, TCSAFLUSH, tty); + BufferUtils::deleteBuffer(tty); + + return state; +} + +cc_t* TerminalDevice::getReadConfigurationMode(int* fd) { + cc_t* readConfig = (cc_t*) calloc(2, sizeof(unsigned char)); + if (*fd <= 0) { + readConfig[0] = ERR_INVALID_PORT; + readConfig[1] = ERR_INVALID_PORT; + return readConfig; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + readConfig[0] = tty->c_cc[VTIME]; + readConfig[1] = tty->c_cc[VMIN]; + BufferUtils::deleteBuffer(tty); + + return readConfig; +} + +int TerminalDevice::setBaudRate(int baudRate, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + /* update the baud rate of the termios */ + cfsetspeed(tty, baudRate); + int state = tcsetattr(*fd, TCSAFLUSH, tty); + BufferUtils::deleteBuffer(tty); + + return state; +} + +speed_t TerminalDevice::getBaudRate(int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + int speed = cfgetospeed(tty); + BufferUtils::deleteBuffer(tty); + + return speed; +} + +ssize_t TerminalDevice::writeData(const void* buffer, int length, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + return write(*fd, buffer, length); +} + +ssize_t TerminalDevice::readData(void* buffer, int length, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + return read(*fd, buffer, length); +} + +int TerminalDevice::closePort(int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + return close(*fd); +} diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/linux/Thread.c b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/linux/Thread.c new file mode 100755 index 00000000..a0dd490f --- /dev/null +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Rs232-Interface/src/lib/linux/Thread.c @@ -0,0 +1,40 @@ +/** + * @file Thread.c + * @author pavl_g. + * @brief Optional source for operating within PThreads. + * @version 0.1 + * @date 2022-08-24 + * + * @note TODO. + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project + * 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. + */ +#include \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Rs232-Interface/build/.build b/HelloNativeLibs/amd-64/Rs232-Interface/build/.build deleted file mode 100644 index e69de29b..00000000 diff --git a/HelloNativeLibs/amd-64/Rs232-Interface/output/.build b/HelloNativeLibs/amd-64/Rs232-Interface/output/.build deleted file mode 100644 index e69de29b..00000000 diff --git a/HelloNativeLibs/amd-64/Rs232-Interface/src/include/TerminalControl.h b/HelloNativeLibs/amd-64/Rs232-Interface/src/include/TerminalControl.h deleted file mode 100644 index 2ccfd208..00000000 --- a/HelloNativeLibs/amd-64/Rs232-Interface/src/include/TerminalControl.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef _TERMINAL_CONTROL_RS232 -#define _TERMINAL_CONTROL_RS232 - -#endif diff --git a/HelloNativeLibs/amd-64/Rs232-Interface/src/lib/TerminalControl.c b/HelloNativeLibs/amd-64/Rs232-Interface/src/lib/TerminalControl.c deleted file mode 100644 index 8ab6d8c7..00000000 --- a/HelloNativeLibs/amd-64/Rs232-Interface/src/lib/TerminalControl.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main(int argc, char **argv) -{ - printf("give me a bottle of rum!\n"); - return 0; -} diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/build/build.sh b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/build/build.sh new file mode 100755 index 00000000..fd8b0542 --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/build/build.sh @@ -0,0 +1,21 @@ +#** +#* Ccoffee Build tool, manual build, alpha-v1. +#* +#* @author pavl_g. +#*# + +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` + +echo "Compiling the project" +echo -e $RESET_Cs +echo "--------Script start--------" + +source $build_dir'/compile.sh' + +echo -e $RESET_Cs + +compile + +echo -e $RESET_Cs +echo "--------Script end--------" diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/build/compile.sh b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/build/compile.sh new file mode 100644 index 00000000..cdd849f2 --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/build/compile.sh @@ -0,0 +1,54 @@ +#** +#* Ccoffee Build tool, manual build, alpha-v1. +#* +#* @author pavl_g. +#*# + +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` + +source $build_dir'/variables.sh' + +## +# Compile and build native sources. +# +# @echo Script Succeeded if all the commands have passed successfully, exit with error code otherwise. +## +function compile() { + native_sources=`find $nativessrc_directory'/main' -name '*.c' -o -name '*.cxx' -o -name '*.cpp' -o -name '*.c++'-o -name '*.ino'` + # tests if the sources exist, then give the current user full permissions on them and compile them + chmod +x $native_sources + # append -lwiringPi for raspberry wiringPi includes + # ${JAVA__HOME%/*} : % returns back to the root base directory of the java home, / is the separator delimiter of the directory string + # compile and build a shared lib for linux systems + if [[ `linux_x86_x64 "${native_sources}"` -eq 0 ]]; then + echo -e "$GREEN_C Task@Build Linux-x86-x64 : Succeeded" + else + echo -e "$RED_C Task@Build Linux-x86-x64 : Failed" + echo -e "$RED_C Exiting Script with error 150" + exit 150 + fi + echo -e "$GREEN_C---MajorTask@Build Native Sources : Succeeded---" +} + +## +# Build for desktop linux systems +# +# @param nativeSources sources to be compiled for linux desktop. +# @return 0 if command passes, non zero number otherwise with exit code 150 (search the code on repo's wiki). +## +function linux_x86_x64() { + local native_sources=$1 + if [[ ! -d $output_dir'/linux-x86-x64' ]]; then + mkdir -p $output_dir'/linux-x86-x64' + fi + $gcc -fpie $native_sources -v -o $output_dir'/linux-x86-x64/'${clibName} \ + -I${JAVA__HOME%/*}'/include' \ + -I${JAVA__HOME%/*}'/include/linux' \ + -I${nativessrc_directory}'/include/linux/' \ + -I${nativessrc_directory}'/include' \ + -L$linux_libs_root_dir \ + -l'rs232' + + return $? +} \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/build/variables.sh b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/build/variables.sh new file mode 100644 index 00000000..2dfc13b6 --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/build/variables.sh @@ -0,0 +1,37 @@ +#** +#* Ccoffee Build tool, manual build, alpha-v1. +#* +#* @author pavl_g. +#*# + +# print the canonical file name from its symbolic link +canonical_link=`readlink -f ${0}` +# get the directory name of this canonical name +build_dir=`dirname $canonical_link` + +# work directories +project_root="${build_dir%/*}" + +dynamic_libs_dir="${project_root%/*}" + +amd_examples_dir="${dynamic_libs_dir%/*}" + +hello_native_libs="${amd_examples_dir%/*}" + +# cut the working directory from its end by a one '/' delimiter again +avr_sandbox_root="${hello_native_libs%/*}" + +# constant independent +clibName=('HelloRs232.elf') + +# native toolchains +gcc='g++-10' + +# code sources +nativessrc_directory=$project_root'/src' + +# native shared/dynamic libs +linux_libs_root_dir=$project_root'/libs/shared/native/Linux/linux-x86-x64/' +output_dir=$project_root'/output' + +source $avr_sandbox_root'/CommonVariables.sh' diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/output/linux-x86-x64/HelloRs232.elf b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/output/linux-x86-x64/HelloRs232.elf new file mode 100755 index 0000000000000000000000000000000000000000..eae86db8160703bfbd934707561142583afc7fde GIT binary patch literal 17816 zcmeHPeQ;FO6~DWiKoCfRg+f8)iP&N_n{2>Hi|FQKVS^#0A<>A%$0oZ;wkEsr?ORN! zd^n(EL}zfORi?Hxw6z~&$B{Z#nd&&PFp8bF13I13+G#1(PEr+draG}I+uynGp3U2r zw~qCXPXBlp_MLlv=i}ac-hFTPzIRV{M_ShTeLle@Ag&X{ja6DmSP2fURTYr1SS{w_ zsEMUw2KW+*S@N(&AhpUVe<3YXcmR~_7E#58USz?7Dff^l*%d1%R0B+f8VA{xl9A$_ z^tY;?Oj(|9Pa|U#O&;^~Vr9qFZbz{>Qf28MQSr-DWp_eRwj-A8jw`$4%8qHJ(r3!? zq?piWwTh>cYLHRU=bK9PK(f1TRrNr;Y9N`)4p$AYuB)nB70jfAwNg&~qBdww zt#9oV{yk!hFt(@qe0(UZB>!tk#l=^?_4lF9lh0n-xqHPAm)_d^1p6Qx(xF27JSB*y zdO1F%V~zhV)GUnX$;9sli54sCAh^&)c&G^eWD)#>B6uY_=H~w!Mf7JE(SNasK8;($ z$5~zj;MVT_MevJ(Yxp?JRRA<62>ze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ia0EZ~R2Dt0~M{LUj}#yGKe)($}@uZ;a@X z)+S1F(viBRN1_UhHnj`A>E_n@jm?chU*EE+p}s}mv~JzzNQd50-_R0)#q`9c>B&!t zc+89;gK85pj^fFbp3NjM5SiS>DM?{Y7or>?nURFakV)(Pu~b|pV>vRR!nRB!dzzF= zin5EFZVDQS-XQY1T+*aya-l1f$z)51%J&AzOIA`;9-;oZ4BDB^MWKdYWR&GYOF^*O z5SYjmfbL920hE4K*n~@O?SuNn%(a5tuQ2Ck*~6qV%nCey+I%+=%!~}0v2IY)uxLNm zk}0Io4T&J$2PT5JhXjWVq`4X9hz;t_CXtDmj4KHFVpVkekm~)hOuq=mM^b3QqNZU< z@YXVuOs5JM9WtEo7#XPA(10m|GWbDMgMDeRW?~ped8UI#TF%8_qF>!O`r~lI9K0jD zEiv4a7&38BqclM2%(|yoKDdrHV}r>an50c=3*Dtz9>hr%LEO~_akFx{r+*fR*5^Ka z@bxMSua}rQf4P#by<7%{mcndL-oCio_q}Z`NKOaZ}qbAv& z*N05`xdv2ZamN34p!5uZ?Rg!^6z_;-;r_E8(_N6#GYRH-y~%V)*;D_ipWJ^1iw97l zn6f>uOPTU>5pJLDdHfG6`v&EZ*RM>+6i)W|wVQ9B?Y|Fs+-SS_qlFIM4rg zA++1`dYCD#f9yrM%{TKC2<`T~Zf45kWgpBlJ?yX_Qw=cnabT4LZlC=6wb+aJ*^3DavWHh*-s{|Y2_`$^4GWjddPw&HC6 z&yd;e`8feo$MRR|+T4k=V9N1Pmwoi{y`N&$I%@c6$+4sx=nv z%3E3$wqv@;VbANEE@jWxDZ61i<}ZOgVcdUS?+krPdwOn7{a5PjR#>(cymv+q?G&Q%Tr2P^&q DN@EuX literal 0 HcmV?d00001 diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/BufferUtils.h b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/BufferUtils.h new file mode 100644 index 00000000..7e08167f --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/BufferUtils.h @@ -0,0 +1,124 @@ +/** + * @file BufferUtils.util + * @author pavl_g. + * @brief Represents utility functions for buffers. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _BUFFER_UTILS +#define _BUFFER_UTILS + +#include +#include +#include + +namespace BufferUtils { + + /** + * Nullifies a single buffer cell at the index. + * + * @param buffer the buffer to nullify its cell. + * @param index the index of the buffer cell to nullify. + */ + static inline void nullifyBuffer(void** buffer, int index) { + buffer[index] = NULL; + } + + /** + * Frees the memory utilized by the individual buffer cells on a [buffer] with [count] number of cells. + * + * @param buffer the buffer to free its cells. + * @param count the number of cells to free, starting from index zero. + */ + static inline void freeBufferCells(void** buffer, int* count) { + for (int i = 0; i < *count; i++) { + BufferUtils::nullifyBuffer(buffer, i); + free(buffer[i]); + } + } + + /** + * @brief Deletes a typified buffer and frees its memory. + * + * @param buffer the buffer to delete. + */ + static inline void deleteBuffer(void* buffer) { + free(buffer); + BufferUtils::nullifyBuffer(&buffer, 0); + } + + /** + * @brief Deeply copies the data of the [src] buffer into a new + * buffer and returns it. + * + * @param src the source buffer to get the data from. + * @param count the count length of the buffer. + * @return void** a new buffer with the same data as the source. + */ + static inline void** copy(void** src, int* count) { + void** copy = (void**) calloc(1, sizeof(void**)); + for (int i = 0; i < *count; i++) { + /* add new memory on the next array block */ + copy[i] = (void*) calloc(1, sizeof(void*)); + copy[i] = src[i]; + } + return copy; + } + + /** + * @brief Re-validates the buffer from [NULL] pointers. + * + * @param buffer the buffer to re-validate. + * @param count the pointers count. + */ + static inline void reValidateBuffer(void** buffer, int* count, int* isProcessed) { + /* get a temp copy from flagged buffer */ + void** temp = BufferUtils::copy(buffer, count); + /* free the buffer cells to prepare the buffer to be reinitialized */ + BufferUtils::freeBufferCells(buffer, count); + /* re-init the buffer, removing the null pointers */ + for (int i = 0, j = 0; i < *count; i++) { + if (temp[i] == NULL) { + printf("%s\n", "zero"); + continue; + } + buffer[j] = (void*) calloc(1, sizeof(void*)); + buffer[j] = temp[i]; + j++; + } + *isProcessed = 1; + /* free the temp buffer */ + BufferUtils::freeBufferCells(temp, count); + } +} +#endif diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/DynamicBuffer.h b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/DynamicBuffer.h new file mode 100644 index 00000000..21d32850 --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/DynamicBuffer.h @@ -0,0 +1,155 @@ +/** + * @file DynamicBuffer.h + * @author pavl_g. + * @brief Represents a cross platform dynamic buffer wrapper. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _DYNAMIC_BUFFER +#define _DYNAMIC_BUFFER + +#include +#include +#include + +struct DynamicBuffer { + + int count = 0; + int isProcessed = 0; + + /** + * Declares and initializes a pointer that points to + * other void* buffers starting from index zero. + * + * @note The pointer is of single size of a type. + * @note The pointer points to only and only one buffer at a time. + * @note New buffers can be added to this pointer by dereferencing it and adding one to the memory address to move + * it to a new cell block. + * e.g: + * 1) First way of adding a new buffer to this pointer using the deep copy: + * buffer[index] = (void*) calloc(1, sizeof(void*)); + * buffer[index] = item; + * + * 2) Second way of adding a new buffer to this pointer (the one used here): + * *(buffer += count) = (void*) calloc(1, sizeof(void*)); + * *buffer = item; + * buffer -= count; + * + * 3) The superficial copy example: + * buffer[index] = item; + */ + void** buffer = (void**) calloc(1, sizeof(void**));; + + static inline struct DynamicBuffer* createNewInstance() { + return (struct DynamicBuffer*) calloc(1, sizeof(struct DynamicBuffer)); + } + + /** + * Retrieves the pointer to this dynamic buffer. + * + * @return a pointer to this array of buffers. + */ + void** getBuffer() { + return buffer; + } + + /** + * Retrieves this structure size. + * + * @return an integer representing this struct in bytes. + */ + size_t getBufferSize() { + return sizeof(struct DynamicBuffer); + } + + /** + * Resets the pointer value back to zero. + */ + void resetDataPointer() { + this->count = 0; + } + + /** + * Gets the memory address to the integer of the items count. + * + * @return a pointer referring to the memory address of the integer that represents the item counts. + */ + int* getItemsCount(); + + /** + * Adds a new buffer to this pointer in a new index. + * + * @param item a void* buffer to add. + */ + void add(void* item); + + /** + * Adds a new buffer on a particular location in this pointer replacing an old one if exists. + * + * @param index the index where the new buffer will be located in this pointer. + * @param item the buffer to add. + */ + void add(int index, void* item); + + /** + * Frees a buffer from the memory at a particular index. + * @warning this method call is expensive as it removes and revalidates the whole buffer from NULL pointers. + * + * @param index the index of the buffer to remove. + */ + void removeAt(int index); + + /** + * Frees all the buffers of this pointer from the memory. + */ + void removeAll(); + + /** + * Retrieves a buffer index. + * + * @param item the buffer to get its index. + * @return the buffer index in an integer format. + */ + int getItemIndex(void* item); + + /** + * Retrieves a buffer from this pointer using its index. + * + * @param index the index where the buffer is located in this pointer. + * @return the buffer corresponding to this index. + */ + void* getItem(int index); +}; + + +#endif diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/ErrnoUtils.h b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/ErrnoUtils.h new file mode 100644 index 00000000..58ec430d --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/ErrnoUtils.h @@ -0,0 +1,53 @@ +/** + * @file ErrnoUtils.util + * @author pavl_g. + * @brief Represents native user and machine errnos. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _ERRNO_UTILS +#define _ERRNO_UTILS + +#include + +#define ERR_INVALID_PORT (-2) +#define ERR_INVALID_DIR (-3) +#define ERR_NO_RESULT (0) +#define LOGGER_DISABLED (-5) +#define ERR_OPERATION_FAILED (-1) +#define ERR_NO_AVAILABLE_TTY_DEVICES (-4) + +#define OPERATION_SUCCEEDED (1) + + +#endif diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/info.md b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/info.md new file mode 100644 index 00000000..166e55df --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/info.md @@ -0,0 +1,6 @@ +# Serial4j API C Utils + +## Includes the following: +- BufferUtils.h: for managing native buffers. +- DynamicBuffer.h: for creating dynamic buffers. +- ErrnoUtils.h: for checking and referencing different errno code numbers. \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/SerialUtils.h b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/SerialUtils.h new file mode 100644 index 00000000..007d1a5e --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/SerialUtils.h @@ -0,0 +1,77 @@ +/** + * @file SerialUtils.util + * @author pavl_g. + * @brief Represents utilities for the [Serial.h] library. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _SERIAL_UTILS +#define _SERIAL_UTILS + +#include +#include +#include +#include +#include + +namespace SerialUtils { + + /** + * @brief Converts a [file] into a [device] and outputs the + * result into a [buffer]. + * + * @param buffer a buffer to fill in the operation. + * @param file the file to convert into a device. + * @return char* a buffer of {"/dev/"} formula. + */ + static inline char* concatIntoDevice(char* buffer, const char* file, const char* DEVICES_DIR) { + strcat(buffer, DEVICES_DIR); + strcat(buffer, file); + return buffer; + } + + /** + * @brief Tests whether the PATH specified is a real serial port. + * + * @param path the path to specify if its a serial port. + * @return int 1 if FD is a valid descriptor, 0 otherwise. + */ + static inline int isSerialPort(char* path, const int FLAG) { + int fdp = open(path, FLAG); + int state = isatty(fdp); + close(fdp); + return state; + } +} + +#endif diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/TerminalDevice.h b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/TerminalDevice.h new file mode 100644 index 00000000..571d1c5f --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/TerminalDevice.h @@ -0,0 +1,258 @@ +/** + * @file Serial.h + * @author pavl_g. + * @brief Represents the serial port devices control and operation for POSIX systems. + * @note This is the base [HAL] (Hardware abstraction layer) for the Serial4j api. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API, RS232. + * 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 _RS232 +#define _RS232 "RS232-Interface" + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#define READ_CONFIG_SIZE (2) +#define DEVICES_DIR ((const char*) "/dev/") + +/** The default flags for the base file api */ +#define DEFAULT_FLAGS (O_RDWR | O_NONBLOCK | O_NOCTTY) + +typedef unsigned short int TerminalFlag; + +namespace TerminalDevice { + + /** Param@0 = VTIME, Param@1 = VMIN */ + const cc_t POLLING_READ[READ_CONFIG_SIZE] = {0, 0}; + const cc_t BLOCKING_READ_ONE_CHAR[READ_CONFIG_SIZE] = {0, 1}; + const cc_t READ_WITH_TIMEOUT[READ_CONFIG_SIZE] = {1, 0}; + const cc_t READ_WITH_INTERBYTE_TIMEOUT[READ_CONFIG_SIZE] = {1, 1}; + + /** + * Retrieves the termios of this tty device described by the file descriptor (fd). + * + * @param fd the virtual file descriptor for this tty device. + * @return a memory reference to the termios defining this tty device terminal attributes. + */ + struct termios* getTermiosFromFd(int* fd); + + /** + * @brief Fetches serial port devices on "/dev/" into [serialPorts] buffer. + * @note Uses , , , and . + * + * @return int (-3) if the directory ["/dev"] is invalid, (-4) if there are no tty + * devices available at the ["/dev"] directory, (1) if operation succeeded. + */ + int fetchSerialPorts(struct DynamicBuffer* serialPorts); + + /** + * @brief Opens a serial port device with a name. + * @note Uses Unix file base api and . + * + * @param port the path for the serial port device. + * @return int* a memory reference for the port file descriptor. + */ + int openPort(const char* port, int flag); + + /** + * @brief Initializes the default terminal for this device with the following default charachteristics: + * ----------- + * # c_cflag: for control mode flags. + * *** Enable these bits: + * - [CREAD]: Allow input to be received. + * - [CS8]: For charachter size 8-bit, you can use the bit mask CSIZE to read this value. + * - [CLOCAL]: Ignore modem status lines (don’t check carrier signal). + * ----------- + * # c_lflag: for local mode flags. + * ***Disable these bits: + * - [ICANON]: Canonical mode (line-by-line) input. + * - [ECHO]: Echo input characters. + * - [ECHOE]: Perform ERASE visually. + * - [ECHOK]: Echo KILL visually. + * - [ECHOKE]: Don’t output a newline after echoed KILL. + * - [ECHONL]: Echo NL (in canonical mode) even if echoing is disabled. + * - [ECHOPRT]: Echo deleted characters backward (between \ and / ). + * - [ECHOCTL]: Echo control characters visually (e.g., ^L ). + * - [ISIG]: Enable signal-generating characters (INTR, QUIT, SUSP). + * - [IEXTEN]: Enable extended processing of input characters. + * ----------- + * # c_oflag: for output mode flags. + * ***Disable these bits: + * - [OPOST]: Perform output postprocessing. + * - [ONLCR]: Map NL to CR-NL on output. + * ----------- + * # c_iflag: for input mode flags. + * ***Disable all input bit masks. + * ----------- + * # c_cc: For control characters. + * ***Sets to BLOCKING READ ONE CHAR AT A TIME MODE. + * ----------- + * + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int initTermios(int* fd); + + /** + * @brief Sets the Terminal Control Flag [c_cflag] for the [termios] variable. + * + * @param flag bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalControlFlag(TerminalFlag flag, int* fd); + + /** + * @brief Sets the Terminal Local Flag [c_lflag] for the [termios] variable. + * + * @param flag bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalLocalFlag(TerminalFlag flag, int* fd); + + /** + * @brief Sets the Terminal Output Flag [c_oflag] for the [termios] variable. + * + * @param flag bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalOutputFlag(TerminalFlag flag, int* fd); + + /** + * @brief Sets the Terminal Input Flag [c_iflag] for the [termios] variable. + * + * @param flags bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalInputFlag(TerminalFlag flag, int* fd); + + /** + * @brief Gets the Terminal Control Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal control flag in [unsigned short int]. + */ + TerminalFlag getTerminalControlFlag(int* fd); + + /** + * @brief Gets the Terminal Local Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal local flag in [unsigned short int]. + */ + TerminalFlag getTerminalLocalFlag(int* fd); + + /** + * @brief Gets the Terminal Input Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal input flag in [unsigned short int]. + */ + TerminalFlag getTerminalInputFlag(int* fd); + + /** + * @brief Gets the Terminal Output Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal output flag in [unsigned short int]. + */ + TerminalFlag getTerminalOutputFlag(int* fd); + + /** + * @brief Sets the Read Configuration Mode using a ReadConfiguration with a + * VMIN_VALUE for lesser bytes to read and VTIME_VALUE for the elapsed time to + * set if the ReadConfiguration mode provides a timeout. + * + * @param VTIME_VALUE the value of the read timeout elapsed time, the timer starts + * with this value after read() is called. + * @param VMIN_VALUE the value of the minimum number of bytes to read. + * @return int (ERR_INVALID_PORT = -2) if port isn't available, (0) otherwise. + */ + int setReadConfigurationMode(const int VTIME_VALUE, const int VMIN_VALUE, int* fd); + + /** + * @brief Get the Read Configuration Mode in a new pointer. + * + * @return int* a memory reference to the new read configuration instance holding the VTIME and VMIN. + */ + cc_t* getReadConfigurationMode(int* fd); + + /** + * @brief Sets the Baud Rate object for the terminal io. + * + * @param baudRate the baud rate (bits/seconds). + * @return int (1) for success, (-1) for failure, (-2) for invalid port. + */ + int setBaudRate(int baudRate, int* fd); + + /** + * @brief Gets the Baud Rate object. + * + * @return speed_t baud rate in integers. + */ + speed_t getBaudRate(int* fd); + + /** + * @brief Writes a data to the serial port device from a buffer. + * + * @param buffer a buffer to write to the file. + * @param length the number of charachters to write from the buffer. + * @return ssize_t the number of bytes written to the serial device, (-1) for failure, (-2) for invalid port. + */ + ssize_t writeData(const void* buffer, int length, int* fd); + + /** + * @brief Reads data from the serial port device and saves it to a buffer. + * + * @param buffer a buffer to read from the file to it. + * @param length the number of the charachters to read by this buffer. + * @return ssize_t the number of bytes read from the terminal, (-1) for failure, (-2) for invalid port. + */ + ssize_t readData(void* buffer, int length, int* fd); + + /** + * @brief Closes the serial port device. + * + * @return int (1) for success, (-1) for failure, (-2) for invalid port. + */ + int closePort(int* fd); + +} + + +#endif diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/Thread.h b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/Thread.h new file mode 100644 index 00000000..7b57ec42 --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/Thread.h @@ -0,0 +1,51 @@ +/** + * @file Thread.h + * @author pavl_g. + * @brief Optional header for operating within PThreads. + * @version 0.1 + * @date 2022-08-24 + * + * @note TODO. + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _THREADS +#define _THREADS + +#include + +namespace POSIX { + struct Thread { + + }; +} + +#endif \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/info.md b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/info.md new file mode 100644 index 00000000..000fa073 --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/include/linux/info.md @@ -0,0 +1 @@ +# Rs232-Interface API designed for Linux/Unix diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/main/main.c b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/main/main.c new file mode 100755 index 00000000..6f9c9906 --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Hello-Rs232/src/main/main.c @@ -0,0 +1,34 @@ +#include + +static inline int* startRs232Service() { + printf("%s\n", " --- Started Rs232 driver service --- "); + + static int fd = TerminalDevice::openPort("/dev/ttyUSB0", DEFAULT_FLAGS); + if (fd <= 0) { + perror("Error driver not available, trying again......"); + } + + // try again and block until a request is accepted + while (fd <= 0 ) { + startRs232Service(); + } + + return &fd; +} + +static inline void initRs232Service(int* fd) { + int state = TerminalDevice::initTermios(fd); + if (state > 0) { + perror("Cannot initialize port"); + } +} + +int main(int argc, char **argv) { + printf("%s\n", " --- Started Rs232 driver example --- "); + + int* service_descriptor = startRs232Service(); + + initRs232Service(service_descriptor); + + return 0; +} diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/build/build.sh b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/build/build.sh new file mode 100755 index 00000000..ca2f35c8 --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/build/build.sh @@ -0,0 +1,26 @@ +#** +#* Ccoffee Build tool, manual build, alpha-v1. +#* +#* @author pavl_g. +#*# + +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` + +echo "Compiling the project" +echo -e $RESET_Cs +echo "--------Script start--------" + +source $build_dir'/compile.sh' + +echo -e $RESET_Cs + +if [[ $enable_natives_build == true ]]; then + echo -e "$MAGNETA_C---MajorTask@Build Native Sources : Native build started" + compile + copyToExample + echo -e "$MAGNETA_C---MajorTask@Build Native Sources : Native build finished" +fi + +echo -e $RESET_Cs +echo "--------Script end--------" diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/build/compile.sh b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/build/compile.sh new file mode 100644 index 00000000..cac0b3e2 --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/build/compile.sh @@ -0,0 +1,129 @@ +#** +#* Ccoffee Build tool, manual build, alpha-v1. +#* +#* @author pavl_g. +#*# + +canonical_link=`readlink -f ${0}` +build_dir=`dirname $canonical_link` + +source $build_dir'/variables.sh' + +## +# Compile and build native sources. +# +# @echo Script Succeeded if all the commands have passed successfully, exit with error code otherwise. +## +function compile() { + native_sources=`find $nativessrc_directory'/lib' -name '*.c' -o -name '*.cxx' -o -name '*.cpp' -o -name '*.c++'-o -name '*.ino'` + # tests if the sources exist, then give the current user full permissions on them and compile them + if [[ $native_sources ]]; then + chmod +x $native_sources + # append -lwiringPi for raspberry wiringPi includes + # ${JAVA__HOME%/*} : % returns back to the root base directory of the java home, / is the separator delimiter of the directory string + # compile and build a shared lib for linux systems + if [[ `linux_x86_x64 "${native_sources}"` -eq 0 ]]; then + echo -e "$GREEN_C Task@Build Linux-x86-x64 : Succeeded" + else + echo -e "$RED_C Task@Build Linux-x86-x64 : Failed" + echo -e "$RED_C Exiting Script with error 150" + exit 150 + fi + # compile and build a shared lib for android systems + if [[ $enable_android_build == true ]]; then + if [[ `linux_android "${arm64}" "${arm64_lib}" "${native_sources}" "${min_android_sdk}"` -eq 0 ]]; then + echo -e "$GREEN_C Task@Build Android-Arm-64 : Succeeded" + else + echo -e "$RED_C Task@Build Android-Arm-64 : Failed" + echo -e "$RED_C Exiting Script with error 250" + exit 250 + fi + + if [[ `linux_android "${arm32}" "${arm32_lib}" "${native_sources}" "${min_android_sdk}"` -eq 0 ]]; then + echo -e "$GREEN_C Task@Build Android-Arm-32 : Succeeded" + else + echo -e "$RED_C Task@Build Android-Arm-32 : Failed" + echo -e "$RED_C Exiting Script with error 350" + exit 350 + fi + + if [[ `linux_android "${intel64}" "${intel64_lib}" "${native_sources}" "${min_android_sdk}"` -eq 0 ]]; then + echo -e "$GREEN_C Task@Build Android-Intel-64 : Succeeded" + else + echo -e "$RED_C Task@Build Android-Intel-64 : Failed" + echo -e "$RED_C Exiting Script with error 450" + exit 450 + fi + + if [[ `linux_android "${intel32}" "${intel32_lib}" "${native_sources}" "${min_android_sdk}"` -eq 0 ]]; then + echo -e "$GREEN_C Task@Build Android-Intel-32 : Succeeded" + else + echo -e "$RED_C Task@Build Android-Intel-32 : Failed" + echo -e "$RED_C Exiting Script with error 550" + exit 550 + fi + fi + fi + echo -e "$GREEN_C---MajorTask@Build Native Sources : Succeeded---" +} + +## +# Build for desktop linux systems +# +# @param nativeSources sources to be compiled for linux desktop. +# @return 0 if command passes, non zero number otherwise with exit code 150 (search the code on repo's wiki). +## +function linux_x86_x64() { + local native_sources=$1 + if [[ ! -d $linux_natives_dir'/linux-x86-x64' ]]; then + mkdir -p $linux_natives_dir'/linux-x86-x64' + fi + $gcc -fPIC -v $native_sources -shared -o $linux_natives_dir'/linux-x86-x64/'${clibName} \ + -I${JAVA__HOME%/*}'/include' \ + -I${JAVA__HOME%/*}'/include/linux' \ + -I${nativessrc_directory}'/include/linux/' \ + -I${nativessrc_directory}'/include/' \ + + return $? +} + +## +# Building native code for arm and intel android. +# +# @param triple the ABI triple name, also used for -target flag of the clang++. +# @param folder the created folder name. +# @param sources the sources to compile and build an object file for them. +# @param min_android_sdk the minimum android sdk to compile against. +# @return 0 if command passes, non zero number otherwise. +## +function linux_android() { + # parameters attributes + local triple=$1 + local folder=$2 + local sources=$3 + local min_android_sdk=$4 + + if [[ ! -d $android_natives_dir ]]; then + mkdir $android_natives_dir + fi + + if [[ ! -d $android_natives_dir"/$folder" ]]; then + mkdir $android_natives_dir"/$folder" + fi + $NDK__BASEHOME'/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++' -v -target ${triple}${min_android_sdk} \ + -fPIC $sources -shared \ + -stdlib=libstdc++ \ + -o $android_natives_dir"/$folder/"${clibName} \ + -I$nativessrc_directory'/includes' \ + -I$NDK__BASEHOME'/sources/cxx-stl/llvm-libc++/include' \ + -lc++_shared + result=$? + cp $NDK__BASEHOME"/sources/cxx-stl/llvm-libc++/libs/${folder}/libc++_shared.so" $android_natives_dir"/$folder" + return $result +} + +function copyToExample() { + local hello_rs232="`dirname $project_root`/Hello-Rs232" + cp -r $shared_root_dir $hello_rs232'/libs/' + cp -r ${nativessrc_directory}'/include/.' $hello_rs232'/src/include/' +} diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/build/variables.sh b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/build/variables.sh new file mode 100644 index 00000000..8c18f23f --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/build/variables.sh @@ -0,0 +1,37 @@ +#** +#* Ccoffee Build tool, manual build, alpha-v1. +#* +#* @author pavl_g. +#*# + +# print the canonical file name from its symbolic link +canonical_link=`readlink -f ${0}` +# get the directory name of this canonical name +build_dir=`dirname $canonical_link` + +# work directories +project_root="${build_dir%/*}" + +static_libs_dir="${project_root%/*}" + +amd_examples_dir="${static_libs_dir%/*}" + +hello_native_libs="${amd_examples_dir%/*}" + +# cut the working directory from its end by a one '/' delimiter again +avr_sandbox_root="${hello_native_libs%/*}" + +# constant independent +clibName=('librs232.a') + +# native toolchains +gcc='g++-10' + +# code sources +nativessrc_directory=$project_root'/src' + +# native static libs +shared_root_dir=$project_root'/static' +linux_natives_dir=$project_root'/static/native/Linux' + +source $avr_sandbox_root'/CommonVariables.sh' diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/BufferUtils.h b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/BufferUtils.h new file mode 100644 index 00000000..7e08167f --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/BufferUtils.h @@ -0,0 +1,124 @@ +/** + * @file BufferUtils.util + * @author pavl_g. + * @brief Represents utility functions for buffers. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _BUFFER_UTILS +#define _BUFFER_UTILS + +#include +#include +#include + +namespace BufferUtils { + + /** + * Nullifies a single buffer cell at the index. + * + * @param buffer the buffer to nullify its cell. + * @param index the index of the buffer cell to nullify. + */ + static inline void nullifyBuffer(void** buffer, int index) { + buffer[index] = NULL; + } + + /** + * Frees the memory utilized by the individual buffer cells on a [buffer] with [count] number of cells. + * + * @param buffer the buffer to free its cells. + * @param count the number of cells to free, starting from index zero. + */ + static inline void freeBufferCells(void** buffer, int* count) { + for (int i = 0; i < *count; i++) { + BufferUtils::nullifyBuffer(buffer, i); + free(buffer[i]); + } + } + + /** + * @brief Deletes a typified buffer and frees its memory. + * + * @param buffer the buffer to delete. + */ + static inline void deleteBuffer(void* buffer) { + free(buffer); + BufferUtils::nullifyBuffer(&buffer, 0); + } + + /** + * @brief Deeply copies the data of the [src] buffer into a new + * buffer and returns it. + * + * @param src the source buffer to get the data from. + * @param count the count length of the buffer. + * @return void** a new buffer with the same data as the source. + */ + static inline void** copy(void** src, int* count) { + void** copy = (void**) calloc(1, sizeof(void**)); + for (int i = 0; i < *count; i++) { + /* add new memory on the next array block */ + copy[i] = (void*) calloc(1, sizeof(void*)); + copy[i] = src[i]; + } + return copy; + } + + /** + * @brief Re-validates the buffer from [NULL] pointers. + * + * @param buffer the buffer to re-validate. + * @param count the pointers count. + */ + static inline void reValidateBuffer(void** buffer, int* count, int* isProcessed) { + /* get a temp copy from flagged buffer */ + void** temp = BufferUtils::copy(buffer, count); + /* free the buffer cells to prepare the buffer to be reinitialized */ + BufferUtils::freeBufferCells(buffer, count); + /* re-init the buffer, removing the null pointers */ + for (int i = 0, j = 0; i < *count; i++) { + if (temp[i] == NULL) { + printf("%s\n", "zero"); + continue; + } + buffer[j] = (void*) calloc(1, sizeof(void*)); + buffer[j] = temp[i]; + j++; + } + *isProcessed = 1; + /* free the temp buffer */ + BufferUtils::freeBufferCells(temp, count); + } +} +#endif diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/DynamicBuffer.h b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/DynamicBuffer.h new file mode 100644 index 00000000..21d32850 --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/DynamicBuffer.h @@ -0,0 +1,155 @@ +/** + * @file DynamicBuffer.h + * @author pavl_g. + * @brief Represents a cross platform dynamic buffer wrapper. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _DYNAMIC_BUFFER +#define _DYNAMIC_BUFFER + +#include +#include +#include + +struct DynamicBuffer { + + int count = 0; + int isProcessed = 0; + + /** + * Declares and initializes a pointer that points to + * other void* buffers starting from index zero. + * + * @note The pointer is of single size of a type. + * @note The pointer points to only and only one buffer at a time. + * @note New buffers can be added to this pointer by dereferencing it and adding one to the memory address to move + * it to a new cell block. + * e.g: + * 1) First way of adding a new buffer to this pointer using the deep copy: + * buffer[index] = (void*) calloc(1, sizeof(void*)); + * buffer[index] = item; + * + * 2) Second way of adding a new buffer to this pointer (the one used here): + * *(buffer += count) = (void*) calloc(1, sizeof(void*)); + * *buffer = item; + * buffer -= count; + * + * 3) The superficial copy example: + * buffer[index] = item; + */ + void** buffer = (void**) calloc(1, sizeof(void**));; + + static inline struct DynamicBuffer* createNewInstance() { + return (struct DynamicBuffer*) calloc(1, sizeof(struct DynamicBuffer)); + } + + /** + * Retrieves the pointer to this dynamic buffer. + * + * @return a pointer to this array of buffers. + */ + void** getBuffer() { + return buffer; + } + + /** + * Retrieves this structure size. + * + * @return an integer representing this struct in bytes. + */ + size_t getBufferSize() { + return sizeof(struct DynamicBuffer); + } + + /** + * Resets the pointer value back to zero. + */ + void resetDataPointer() { + this->count = 0; + } + + /** + * Gets the memory address to the integer of the items count. + * + * @return a pointer referring to the memory address of the integer that represents the item counts. + */ + int* getItemsCount(); + + /** + * Adds a new buffer to this pointer in a new index. + * + * @param item a void* buffer to add. + */ + void add(void* item); + + /** + * Adds a new buffer on a particular location in this pointer replacing an old one if exists. + * + * @param index the index where the new buffer will be located in this pointer. + * @param item the buffer to add. + */ + void add(int index, void* item); + + /** + * Frees a buffer from the memory at a particular index. + * @warning this method call is expensive as it removes and revalidates the whole buffer from NULL pointers. + * + * @param index the index of the buffer to remove. + */ + void removeAt(int index); + + /** + * Frees all the buffers of this pointer from the memory. + */ + void removeAll(); + + /** + * Retrieves a buffer index. + * + * @param item the buffer to get its index. + * @return the buffer index in an integer format. + */ + int getItemIndex(void* item); + + /** + * Retrieves a buffer from this pointer using its index. + * + * @param index the index where the buffer is located in this pointer. + * @return the buffer corresponding to this index. + */ + void* getItem(int index); +}; + + +#endif diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/ErrnoUtils.h b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/ErrnoUtils.h new file mode 100644 index 00000000..58ec430d --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/ErrnoUtils.h @@ -0,0 +1,53 @@ +/** + * @file ErrnoUtils.util + * @author pavl_g. + * @brief Represents native user and machine errnos. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _ERRNO_UTILS +#define _ERRNO_UTILS + +#include + +#define ERR_INVALID_PORT (-2) +#define ERR_INVALID_DIR (-3) +#define ERR_NO_RESULT (0) +#define LOGGER_DISABLED (-5) +#define ERR_OPERATION_FAILED (-1) +#define ERR_NO_AVAILABLE_TTY_DEVICES (-4) + +#define OPERATION_SUCCEEDED (1) + + +#endif diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/info.md b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/info.md new file mode 100644 index 00000000..166e55df --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/info.md @@ -0,0 +1,6 @@ +# Serial4j API C Utils + +## Includes the following: +- BufferUtils.h: for managing native buffers. +- DynamicBuffer.h: for creating dynamic buffers. +- ErrnoUtils.h: for checking and referencing different errno code numbers. \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/SerialUtils.h b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/SerialUtils.h new file mode 100644 index 00000000..007d1a5e --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/SerialUtils.h @@ -0,0 +1,77 @@ +/** + * @file SerialUtils.util + * @author pavl_g. + * @brief Represents utilities for the [Serial.h] library. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _SERIAL_UTILS +#define _SERIAL_UTILS + +#include +#include +#include +#include +#include + +namespace SerialUtils { + + /** + * @brief Converts a [file] into a [device] and outputs the + * result into a [buffer]. + * + * @param buffer a buffer to fill in the operation. + * @param file the file to convert into a device. + * @return char* a buffer of {"/dev/"} formula. + */ + static inline char* concatIntoDevice(char* buffer, const char* file, const char* DEVICES_DIR) { + strcat(buffer, DEVICES_DIR); + strcat(buffer, file); + return buffer; + } + + /** + * @brief Tests whether the PATH specified is a real serial port. + * + * @param path the path to specify if its a serial port. + * @return int 1 if FD is a valid descriptor, 0 otherwise. + */ + static inline int isSerialPort(char* path, const int FLAG) { + int fdp = open(path, FLAG); + int state = isatty(fdp); + close(fdp); + return state; + } +} + +#endif diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/TerminalDevice.h b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/TerminalDevice.h new file mode 100644 index 00000000..571d1c5f --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/TerminalDevice.h @@ -0,0 +1,258 @@ +/** + * @file Serial.h + * @author pavl_g. + * @brief Represents the serial port devices control and operation for POSIX systems. + * @note This is the base [HAL] (Hardware abstraction layer) for the Serial4j api. + * @version 0.1 + * @date 2022-08-24 + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API, RS232. + * 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 _RS232 +#define _RS232 "RS232-Interface" + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#define READ_CONFIG_SIZE (2) +#define DEVICES_DIR ((const char*) "/dev/") + +/** The default flags for the base file api */ +#define DEFAULT_FLAGS (O_RDWR | O_NONBLOCK | O_NOCTTY) + +typedef unsigned short int TerminalFlag; + +namespace TerminalDevice { + + /** Param@0 = VTIME, Param@1 = VMIN */ + const cc_t POLLING_READ[READ_CONFIG_SIZE] = {0, 0}; + const cc_t BLOCKING_READ_ONE_CHAR[READ_CONFIG_SIZE] = {0, 1}; + const cc_t READ_WITH_TIMEOUT[READ_CONFIG_SIZE] = {1, 0}; + const cc_t READ_WITH_INTERBYTE_TIMEOUT[READ_CONFIG_SIZE] = {1, 1}; + + /** + * Retrieves the termios of this tty device described by the file descriptor (fd). + * + * @param fd the virtual file descriptor for this tty device. + * @return a memory reference to the termios defining this tty device terminal attributes. + */ + struct termios* getTermiosFromFd(int* fd); + + /** + * @brief Fetches serial port devices on "/dev/" into [serialPorts] buffer. + * @note Uses , , , and . + * + * @return int (-3) if the directory ["/dev"] is invalid, (-4) if there are no tty + * devices available at the ["/dev"] directory, (1) if operation succeeded. + */ + int fetchSerialPorts(struct DynamicBuffer* serialPorts); + + /** + * @brief Opens a serial port device with a name. + * @note Uses Unix file base api and . + * + * @param port the path for the serial port device. + * @return int* a memory reference for the port file descriptor. + */ + int openPort(const char* port, int flag); + + /** + * @brief Initializes the default terminal for this device with the following default charachteristics: + * ----------- + * # c_cflag: for control mode flags. + * *** Enable these bits: + * - [CREAD]: Allow input to be received. + * - [CS8]: For charachter size 8-bit, you can use the bit mask CSIZE to read this value. + * - [CLOCAL]: Ignore modem status lines (don’t check carrier signal). + * ----------- + * # c_lflag: for local mode flags. + * ***Disable these bits: + * - [ICANON]: Canonical mode (line-by-line) input. + * - [ECHO]: Echo input characters. + * - [ECHOE]: Perform ERASE visually. + * - [ECHOK]: Echo KILL visually. + * - [ECHOKE]: Don’t output a newline after echoed KILL. + * - [ECHONL]: Echo NL (in canonical mode) even if echoing is disabled. + * - [ECHOPRT]: Echo deleted characters backward (between \ and / ). + * - [ECHOCTL]: Echo control characters visually (e.g., ^L ). + * - [ISIG]: Enable signal-generating characters (INTR, QUIT, SUSP). + * - [IEXTEN]: Enable extended processing of input characters. + * ----------- + * # c_oflag: for output mode flags. + * ***Disable these bits: + * - [OPOST]: Perform output postprocessing. + * - [ONLCR]: Map NL to CR-NL on output. + * ----------- + * # c_iflag: for input mode flags. + * ***Disable all input bit masks. + * ----------- + * # c_cc: For control characters. + * ***Sets to BLOCKING READ ONE CHAR AT A TIME MODE. + * ----------- + * + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int initTermios(int* fd); + + /** + * @brief Sets the Terminal Control Flag [c_cflag] for the [termios] variable. + * + * @param flag bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalControlFlag(TerminalFlag flag, int* fd); + + /** + * @brief Sets the Terminal Local Flag [c_lflag] for the [termios] variable. + * + * @param flag bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalLocalFlag(TerminalFlag flag, int* fd); + + /** + * @brief Sets the Terminal Output Flag [c_oflag] for the [termios] variable. + * + * @param flag bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalOutputFlag(TerminalFlag flag, int* fd); + + /** + * @brief Sets the Terminal Input Flag [c_iflag] for the [termios] variable. + * + * @param flags bits to set, concatenate the flags using bitwise OR [|]. + * @return int (-1) for failure, (-2) for invalid port or (1) for success. + */ + int setTerminalInputFlag(TerminalFlag flag, int* fd); + + /** + * @brief Gets the Terminal Control Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal control flag in [unsigned short int]. + */ + TerminalFlag getTerminalControlFlag(int* fd); + + /** + * @brief Gets the Terminal Local Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal local flag in [unsigned short int]. + */ + TerminalFlag getTerminalLocalFlag(int* fd); + + /** + * @brief Gets the Terminal Input Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal input flag in [unsigned short int]. + */ + TerminalFlag getTerminalInputFlag(int* fd); + + /** + * @brief Gets the Terminal Output Flag defined by the termios attributes for this serial device. + * + * @return TerminalFlag the terminal output flag in [unsigned short int]. + */ + TerminalFlag getTerminalOutputFlag(int* fd); + + /** + * @brief Sets the Read Configuration Mode using a ReadConfiguration with a + * VMIN_VALUE for lesser bytes to read and VTIME_VALUE for the elapsed time to + * set if the ReadConfiguration mode provides a timeout. + * + * @param VTIME_VALUE the value of the read timeout elapsed time, the timer starts + * with this value after read() is called. + * @param VMIN_VALUE the value of the minimum number of bytes to read. + * @return int (ERR_INVALID_PORT = -2) if port isn't available, (0) otherwise. + */ + int setReadConfigurationMode(const int VTIME_VALUE, const int VMIN_VALUE, int* fd); + + /** + * @brief Get the Read Configuration Mode in a new pointer. + * + * @return int* a memory reference to the new read configuration instance holding the VTIME and VMIN. + */ + cc_t* getReadConfigurationMode(int* fd); + + /** + * @brief Sets the Baud Rate object for the terminal io. + * + * @param baudRate the baud rate (bits/seconds). + * @return int (1) for success, (-1) for failure, (-2) for invalid port. + */ + int setBaudRate(int baudRate, int* fd); + + /** + * @brief Gets the Baud Rate object. + * + * @return speed_t baud rate in integers. + */ + speed_t getBaudRate(int* fd); + + /** + * @brief Writes a data to the serial port device from a buffer. + * + * @param buffer a buffer to write to the file. + * @param length the number of charachters to write from the buffer. + * @return ssize_t the number of bytes written to the serial device, (-1) for failure, (-2) for invalid port. + */ + ssize_t writeData(const void* buffer, int length, int* fd); + + /** + * @brief Reads data from the serial port device and saves it to a buffer. + * + * @param buffer a buffer to read from the file to it. + * @param length the number of the charachters to read by this buffer. + * @return ssize_t the number of bytes read from the terminal, (-1) for failure, (-2) for invalid port. + */ + ssize_t readData(void* buffer, int length, int* fd); + + /** + * @brief Closes the serial port device. + * + * @return int (1) for success, (-1) for failure, (-2) for invalid port. + */ + int closePort(int* fd); + +} + + +#endif diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/Thread.h b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/Thread.h new file mode 100644 index 00000000..7b57ec42 --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/Thread.h @@ -0,0 +1,51 @@ +/** + * @file Thread.h + * @author pavl_g. + * @brief Optional header for operating within PThreads. + * @version 0.1 + * @date 2022-08-24 + * + * @note TODO. + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API. + * 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 _THREADS +#define _THREADS + +#include + +namespace POSIX { + struct Thread { + + }; +} + +#endif \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/info.md b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/info.md new file mode 100644 index 00000000..000fa073 --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/include/linux/info.md @@ -0,0 +1 @@ +# Rs232-Interface API designed for Linux/Unix diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/DynamicBuffer.c b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/DynamicBuffer.c new file mode 100755 index 00000000..0bd13205 --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/DynamicBuffer.c @@ -0,0 +1,62 @@ +#include + +void DynamicBuffer::add(void* item) { + + /* move the pointer to point to the last item */ + /* then, obtain a superficial copy */ + void** copy = (buffer += count); + /* dereference and evalute using the superficial copy */ + *copy = (void*) calloc(1, sizeof(void*)); + *copy = item; + /* move the pointer back to the start of the buffer (first item) */ + buffer -= count; + count++; +} + +void DynamicBuffer::add(int index, void* item) { + /* adds on the count if the location was empty previously */ + if (buffer[index] == NULL) { + ++count; + } + buffer[index] = item; +} + +void DynamicBuffer::removeAt(int index) { + BufferUtils::nullifyBuffer(buffer, index); + BufferUtils::reValidateBuffer(buffer, getItemsCount(), &(this->isProcessed)); + + while (!this->isProcessed); + this->isProcessed = 0; + + count--; +} + +void DynamicBuffer::removeAll() { + for (int i = 0; i < *(this->getItemsCount()); i++) { + BufferUtils::nullifyBuffer(buffer, i); + } + + BufferUtils::reValidateBuffer(buffer, getItemsCount(), &(this->isProcessed)); + + while (!this->isProcessed); + this->isProcessed = 0; + + this->resetDataPointer(); +} + +void* DynamicBuffer::getItem(int index) { + return buffer[index]; +} + +int DynamicBuffer::getItemIndex(void* item) { + for (int i = 0; i < *getItemsCount(); i++) { + if (buffer[i] == item) { + return i; + } + } + return ERR_OPERATION_FAILED; +} + +int* DynamicBuffer::getItemsCount() { + return &count; +} diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/info.md b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/info.md new file mode 100644 index 00000000..d9a935a6 --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/info.md @@ -0,0 +1,4 @@ +# Serial4j API C Utils + +## Includes the following: +- DynamicBuffer.c: for creating dynamic buffers. \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/linux/TerminalDevice.c b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/linux/TerminalDevice.c new file mode 100755 index 00000000..fc587fab --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/linux/TerminalDevice.c @@ -0,0 +1,249 @@ +#include + +struct termios* TerminalDevice::getTermiosFromFd(int* fd) { + if (fd == NULL) { + return NULL; + } + struct termios* tty = (struct termios*) calloc(1, sizeof(struct termios)); + /* update the termios struct pointer with the data from the port descriptor */ + tcgetattr(*fd, tty); + return tty; +} + +int TerminalDevice::openPort(const char* port, int flag) { + return open(port, flag); +} + +int TerminalDevice::fetchSerialPorts(struct DynamicBuffer* serialPorts) { + + DIR* dirp = opendir(DEVICES_DIR); + + /* sanity check the input */ + if (dirp == NULL) { + return ERR_INVALID_DIR; + } + + struct dirent* dp = (struct dirent*) calloc(1, sizeof(struct dirent)); + + /* start at the beginning of the buffer to override last data */ + serialPorts->resetDataPointer(); + + /* start reading available ports */ + while ((dp = readdir(dirp)) != NULL) { + + char* device = (char*) calloc(1, sizeof(char)); + device = SerialUtils::concatIntoDevice(device, dp->d_name, DEVICES_DIR); + + /* delete the device buffer if it's not a serial port */ + if (!SerialUtils::isSerialPort(device, DEFAULT_FLAGS)) { + BufferUtils::deleteBuffer(device); + continue; + } + + /* add the device to the serial ports major buffer and count up */ + serialPorts->add(device); + } + + /* release resources */ + closedir(dirp); + BufferUtils::deleteBuffer(dp); + + /* throws error indicating the availability issues */ + if (serialPorts->getItem(0) == NULL) { + return ERR_NO_AVAILABLE_TTY_DEVICES; + } + return OPERATION_SUCCEEDED; +} + +int TerminalDevice::initTermios(int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + /* setup tty attributes */ + tty->c_cflag &= ~(CBAUDEX | CBAUD); /* clear BAUDs */ + tty->c_cflag |= (CREAD | CS8 | CLOCAL); /* set flags */ + tty->c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT | ECHOCTL | ISIG | IEXTEN); + tty->c_oflag &= ~(OPOST | ONLCR); + tty->c_iflag = 0x00; + + /* define default read mode as blocking read on char at a time */ + tty->c_cc[VTIME] = BLOCKING_READ_ONE_CHAR[0]; + tty->c_cc[VMIN] = BLOCKING_READ_ONE_CHAR[1]; + + /* apply attriutes flag bits */ + int state = tcsetattr(*fd, TCSAFLUSH, tty); + BufferUtils::deleteBuffer(tty); + + return state; +} + +int TerminalDevice::setTerminalControlFlag(TerminalFlag flag, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + tty->c_cflag = flag; + /* sets the new terminal settings to the file descriptor with flushing any output */ + int state = tcsetattr(*fd, TCSAFLUSH, tty); + BufferUtils::deleteBuffer(tty); + + return state; +} + +int TerminalDevice::setTerminalLocalFlag(TerminalFlag flag, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + tty->c_lflag = flag; + int state = tcsetattr(*fd, TCSAFLUSH, tty); + BufferUtils::deleteBuffer(tty); + + return state; +} + +int TerminalDevice::setTerminalInputFlag(TerminalFlag flag, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + tty->c_iflag = flag; + int state = tcsetattr(*fd, TCSAFLUSH, tty); + BufferUtils::deleteBuffer(tty); + + return state; +} + +int TerminalDevice::setTerminalOutputFlag(TerminalFlag flag, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + tty->c_oflag = flag; + int state = tcsetattr(*fd, TCSAFLUSH, tty); + BufferUtils::deleteBuffer(tty); + + return state; +} + +TerminalFlag TerminalDevice::getTerminalControlFlag(int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + return tty->c_cflag; +} + +TerminalFlag TerminalDevice::getTerminalLocalFlag(int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + return tty->c_lflag; +} + +TerminalFlag TerminalDevice::getTerminalInputFlag(int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + return tty->c_iflag; +} + +TerminalFlag TerminalDevice::getTerminalOutputFlag(int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + return tty->c_oflag; +} + +int TerminalDevice::setReadConfigurationMode(const int VTIME_VALUE, const int VMIN_VALUE, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + tty->c_cc[VTIME] = VTIME_VALUE; + tty->c_cc[VMIN] = VMIN_VALUE; + int state = tcsetattr(*fd, TCSAFLUSH, tty); + BufferUtils::deleteBuffer(tty); + + return state; +} + +cc_t* TerminalDevice::getReadConfigurationMode(int* fd) { + cc_t* readConfig = (cc_t*) calloc(2, sizeof(unsigned char)); + if (*fd <= 0) { + readConfig[0] = ERR_INVALID_PORT; + readConfig[1] = ERR_INVALID_PORT; + return readConfig; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + readConfig[0] = tty->c_cc[VTIME]; + readConfig[1] = tty->c_cc[VMIN]; + BufferUtils::deleteBuffer(tty); + + return readConfig; +} + +int TerminalDevice::setBaudRate(int baudRate, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + /* update the baud rate of the termios */ + cfsetspeed(tty, baudRate); + int state = tcsetattr(*fd, TCSAFLUSH, tty); + BufferUtils::deleteBuffer(tty); + + return state; +} + +speed_t TerminalDevice::getBaudRate(int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + struct termios* tty = TerminalDevice::getTermiosFromFd(fd); + + int speed = cfgetospeed(tty); + BufferUtils::deleteBuffer(tty); + + return speed; +} + +ssize_t TerminalDevice::writeData(const void* buffer, int length, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + return write(*fd, buffer, length); +} + +ssize_t TerminalDevice::readData(void* buffer, int length, int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + return read(*fd, buffer, length); +} + +int TerminalDevice::closePort(int* fd) { + if (*fd <= 0) { + return ERR_INVALID_PORT; + } + return close(*fd); +} diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/linux/Thread.c b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/linux/Thread.c new file mode 100755 index 00000000..a0dd490f --- /dev/null +++ b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/src/lib/linux/Thread.c @@ -0,0 +1,40 @@ +/** + * @file Thread.c + * @author pavl_g. + * @brief Optional source for operating within PThreads. + * @version 0.1 + * @date 2022-08-24 + * + * @note TODO. + * + * @copyright + * BSD 3-Clause License + * + * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project + * 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. + */ +#include \ No newline at end of file diff --git a/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/static/native/Linux/linux-x86-x64/librs232.so b/HelloNativeLibs/amd-64/Static-Libraries/Rs232-Interface/static/native/Linux/linux-x86-x64/librs232.so new file mode 100755 index 0000000000000000000000000000000000000000..bdecefbb66edc68c1d0e91d2e5d7988f64a39cb8 GIT binary patch literal 19296 zcmeHP3vg6bn!f3ThZsl(5g1{lmjOh@kPdGLupw!<(F9sZ7-7(+Nq0!Qoo?)OM^G7~ z5r>`_i`CH?mG!}@<+_%#j-`xcVGswEQa-!QHJdIpYxyYdvD(c zoSNFIt>sXi|DNxEod5jianHToKR0`77C8zEG*t?<`5M)>en%p1W~`~=3lO(9TRRJX z$7*AQY*Ch#bJbfSAw{)PS*JDz&?VQcbRO#|s`#WQ+H;aJic|c}&=CV=T~VVRu}aG% zzjVHt?sUj{7gME2Rnl{^o|E+y?IMRz6df$9!bkFRHrun(2`s0m=o2vSNAUn%k8nx> zE1k~mDXR3YgdTTYDxTu63i~o{FJD}GxjjX>D*879Z4~0OcuBqXpR>vyy#Ccm)31B_ z5wm3C6RVy`Zh+~Gf=C)_syvrvS6%82bT;m5W z5<9TxIU@>mE)Do&-uNxCj4mr_gnsaQ`=0>L+L&9ijMxgwItSe;^BPFhF+lk7JudF;QF$IsXE*ncFCoh^CfZ^?tx{Bh!AEsFrq+_M(1@UvKJ7%e&NEN~Xq`*5vT z(`f>utdm6h5|r>e&XK_R@SDmi5zk`nBAVz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{IaJy$4lvjV0g~^V*Ls`s#hDqN=~DO;uO)Cl-D69#GNk>I)P$pxRgVIxYI@{i~vQ z<6m*W zpe_!W>W0!&<9I7{Nkr+Z_tM={0irm?-|Qcyujt!g8TB* Date: Tue, 25 Oct 2022 16:46:12 +0200 Subject: [PATCH 7/9] Update README.md --- HelloNativeLibs/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/HelloNativeLibs/README.md b/HelloNativeLibs/README.md index ccf26d13..0701a4df 100644 --- a/HelloNativeLibs/README.md +++ b/HelloNativeLibs/README.md @@ -74,7 +74,9 @@ function linux_x86_x64() { 3) Compiling the project into a dynamic/shared (or runtime) library for avr MCUs: ``` -There is no way to use the dynamic linked libraries on a microcontroller, since there is no a runtime environment to act upon (the linker program needs a linux machine), so shared libraries on avr-gcc isn't supported. +There is no way to use the dynamic linked libraries on a microcontroller, +since there is no a runtime environment to act upon (the linker program needs a linux machine), +so shared libraries on avr-gcc isn't supported. ``` 4) Compiling the project into a static library for avr MCUs: From d1550994f7ea33278524bd6aca07c9e3f17bdf2b Mon Sep 17 00:00:00 2001 From: pavl_g Date: Fri, 28 Oct 2022 08:34:53 +0200 Subject: [PATCH 8/9] Hello-Rs232: Fixed R/W Services --- .../output/linux-x86-x64/HelloRs232.elf | Bin 19056 -> 19160 bytes .../Hello-Rs232/src/include/linux/Thread.h | 2 +- .../Hello-Rs232/src/lib/Rs232Service.c | 36 +++++++++++++----- .../Hello-Rs232/src/main/main.c | 13 ++++--- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/output/linux-x86-x64/HelloRs232.elf b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/output/linux-x86-x64/HelloRs232.elf index 5ecdeaf3dff1c1d62e317602302a83e947a8f2fd..66d0ad42f1b401f35db87e4160dcabe638f9cc67 100755 GIT binary patch delta 3843 zcmZWs4Nz3q6~1?u6&Ar|L0nfvh={*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faZ89`hpq6)t=0KL! z$+{ukRMWwLkJpRKfh_Ttz#-l*Hq3h!?VWjU&xpFUnJIRlV_{BKB=SmX`Of&Z5-)$O zRoyo76)F>BC(sdPH`W=xBGFs=tvEG5+gik0fq~K+4&l+RKGMIU_GgEF8 z#bs_Dp*xx7O^f(lAS=L@;i{F(JgmRcL`iuH92v-bN6n_O;&5G|X#Ta)+QoTfn}f?+ zIv6fZU??UpUv6NUfyuC>vnF#bRI=v{%s~TloG{4f%aqR53Nv7Mzf|7u)J1Bu^8VLg zm?pkj;O6Djdg?JEs%PSeek!WU-JY%Rx-1?xRH+D*Xcf)nZoc2(IYw=9pTRSo&944` zC{0C8oQ=CGN>?jsoJd68GiuJXNzU79?8e!H*Ds0}y6Lo|-9)YD zWgw~kiTsDfd3gV%c*@i)8Rrl@A5*ODOL%9BUQ1?if^ZhR(afu}8p8t>|DvknIc3ih zD;BwV3AOQ#MRP5#hHY%+uLAP|t2Xc2y=~KG-zIS_SQRh+Nue#iX7NVOUlymA_+1V1 zzXN8<3*sKEIqI01a=s`J`Rz^0+9aAoW%eUVJ0f~RWf|tlHD!W}`=Pxl>(zl5c{OhF zMvcqfq0U%`=&dOe@71JRhHT<~jW5;QcQ~Pe+8X|ZXsh+R%;RCo?c#K81%Eq!4=oOD zd7a;G?xB9sTvx#_iC&|*w^OwUEq&Y`USv2}t!P_X#$Oe^OAG%8 D*T2x@ diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/Thread.h b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/Thread.h index 938587e8..7b57ec42 100644 --- a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/Thread.h +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/include/linux/Thread.h @@ -41,10 +41,10 @@ #define _THREADS #include -#include namespace POSIX { struct Thread { + }; } diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/lib/Rs232Service.c b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/lib/Rs232Service.c index 91e1736c..f5448d19 100755 --- a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/lib/Rs232Service.c +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/lib/Rs232Service.c @@ -1,6 +1,13 @@ #include #include +static inline void terminatePrinterFormat(int* numberOfPrintedChars, size_t targetLength) { + if (*numberOfPrintedChars == targetLength) { + printf("\r\n"); + *numberOfPrintedChars = 0; + } +} + int* startRs232Service() { /** create a service block to enable the retry again criteria */ service: { @@ -37,12 +44,12 @@ void* handshakeDeviceDriver(void* data) { int* service_descriptor = (int*) data; printf("%s\n", " --- Started Rs232 handshake service --- "); - + handshake_service:{ assert(pthread_mutex_lock(&handshake_mutex) == 0); assert(pthread_cond_wait(&handshake_cond, &handshake_mutex) == 0); /* critical section starts */ - + int numberOfWrittenBytes = TerminalDevice::writeData(HANDSHAKING_SIGNAL, strlen(HANDSHAKING_SIGNAL), service_descriptor); if (numberOfWrittenBytes == -2) { perror(" --- Invalid Port --- \n"); @@ -50,10 +57,11 @@ void* handshakeDeviceDriver(void* data) { perror(" --- Failed to handshake the service --- \n"); } - assert(pthread_mutex_unlock(&handshake_mutex) == 0); /* critical section ends */ - usleep(1000000); + assert(pthread_mutex_unlock(&handshake_mutex) == 0); + usleep(100000); /* send data each 100,000 micros = 0.1 seconds */ + goto handshake_service; } @@ -67,6 +75,8 @@ void* logHandshakingSignals(void* data) { char* vacant = (char*) calloc(1, sizeof(char)); + int numberOfPrintedChars = 0; + printf("%s\n", " --- Started Rs232 log service --- "); /* wait for the start of the reading thread */ @@ -78,24 +88,32 @@ void* logHandshakingSignals(void* data) { int numberOfReadBytes = TerminalDevice::readData((void*) vacant, 1, service_descriptor); + if (*vacant == 0x20) { + /* critical section ends */ + assert(pthread_cond_signal(&handshake_cond) == 0); + assert(pthread_mutex_unlock(&handshake_mutex) == 0); + + goto read_service; + } + if (numberOfReadBytes > 0) { - printf("%c\n", *vacant); + printf("%c", *vacant); *vacant = 0; + numberOfPrintedChars += 1; } else if (numberOfReadBytes == -2) { perror(" --- Invalid Port --- \n"); return NULL; } - /* critical section ends */ + + terminatePrinterFormat(&numberOfPrintedChars, strlen(HANDSHAKING_SIGNAL)); + /* critical section ends */ assert(pthread_cond_signal(&handshake_cond) == 0); assert(pthread_mutex_unlock(&handshake_mutex) == 0); - usleep(10000); goto read_service; } - - pthread_exit(NULL); } diff --git a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/main/main.c b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/main/main.c index 9693cda8..28db4de6 100755 --- a/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/main/main.c +++ b/HelloNativeLibs/amd-64/Dynamic-Libraries/Hello-Rs232/src/main/main.c @@ -8,18 +8,21 @@ static inline int* prepareRs232Service() { return service_descriptor; } -static inline void dispatchRs232Services(int* service_descriptor) { +static inline void dispatchRs232Services() { - pthread_create(&handshakeTx_service, NULL, &handshakeDeviceDriver, service_descriptor); - pthread_create(&handshakeRx_service, NULL, &logHandshakingSignals, service_descriptor); + const int* handshake_descriptor = prepareRs232Service(); + + pthread_create(&handshakeRx_service, NULL, &logHandshakingSignals, (void*) handshake_descriptor); + usleep(2000000); /* sleep 2 seconds until the read service starts */ + pthread_create(&handshakeTx_service, NULL, &handshakeDeviceDriver, (void*) handshake_descriptor); - pthread_join(handshakeRx_service, NULL); + pthread_join(handshakeRx_service, NULL); /* wait for the Rx thread to terminate */ } int main(int argc, char **argv) { printf("%s\n", " --- Started Rs232 driver example --- "); - dispatchRs232Services(prepareRs232Service()); + dispatchRs232Services(); return 0; } From 31811761badd25754ea7b171855a50732906c0c2 Mon Sep 17 00:00:00 2001 From: pavl_g Date: Wed, 16 Nov 2022 16:49:12 +0200 Subject: [PATCH 9/9] HelloUart: refactored example to handshake signals --- .../avr/Hellouart/output/libHelloUART.elf | Bin 11012 -> 8840 bytes .../avr/Hellouart/output/libHelloUART.hex | 145 +++++------------- .../avr/Hellouart/src/lib/hello_uart.cpp | 9 +- 3 files changed, 45 insertions(+), 109 deletions(-) diff --git a/HelloNativeLibs/avr/Hellouart/output/libHelloUART.elf b/HelloNativeLibs/avr/Hellouart/output/libHelloUART.elf index 42b908b88577c210739832b39f30aa2a9b9d25bb..65efcb9f0aa8e42d3bb0de9cbe2dc07bcf73c773 100755 GIT binary patch delta 1974 zcmZ9Ne`s4(6vxkdX_jmxXT!sXRQ?!D(QV=~wFmPt%!`WDrcZb5 zSRhZf9qQ83XKT{`RU6lT|EHkOIVZfCsRyQAmv8JXOs!5Aw7EMoAGOT5R&MyR_iLW) zLr|ig!eHUlYP#Ub4v~8@zOqGmzRG(ti?hGXKJ(hwTB6H%OyYdmS*o14n$D-)lkUmW z$}>T|tAhp0b~jF@R+4;)-Y6t_o}T9g>gI1~T!nU;<6p$b^atH7A&+iq@h^<+UT>Gpb3%D~Y@U?z#BH9p#iRA}cen2}rcwJ5X_^w9 z=1fb53R){JVnlIG(P;%%#zJ&^9rmwK*`gZH-Dq&moDYDb;OkJ2Ip22cyg}`7kh`?P zj|2OKO%XQ0{hO>4gXLut@#BCqVEchnWjteJiJu4mu({q?D=ygrB;#eU{lLG=<~P7s zpgtrZH?GHKpTf3oxF2j!=n?Q%!fVA&@aFyoHi*OV9NHt|M^h7E)Lw~H;1oDlLXreC zGLLu}s_;Rbf$FudkJM+FIHIdmRb+aK6egR<@w0j0eCQhz*(XDX_f)Z>yN1_AqX=^-@-l?!5IzUa+*@+OQ2g3>FDs;x4fL#;vw_Y0;x# zR7jnV4AJwFqqG6Iw~Q0utrlqX5_k+Hd>n2`I0d%4A}#tr;*(H_@MmBj5_}3Q@zftb zdNjf3_I6jiFnnZ)?+K3a_rY-<-S>ohB;Grm80uBQ(qm;lMdfFCeeYZz9Xf_ z)kCAH{%*KTk4yFwQX_4UKDZ%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j zJ^LIu(z8g*&I9vTqY0BI(15&>z+KptgdYN5z=2}%O7Vyy~){VofnOXyp4?x zI9nq*tThgs%PNy%zs#{E)lN9GO*wC9tk&wr^_y&U>~fAdA;OP6&MArK``FB>`Xogd z_UozV;~n)I9Za43oHojCuFQ^eE6#06Ql>kYdnRseor|s0Z=V^BQg3TqSKBbby2J!o zK9Aj5U+-)nYa1O7_E>+AePqz8_VA$L8iu z6Hckwn|U*YF*R$$5=vo*u=q0AS6B{bu!mS$3YpP3qwM2MLPANAYivWK`6J7}-HDj7 T%L9?@&m-hpq>l~U0eSonr@gv$ diff --git a/HelloNativeLibs/avr/Hellouart/output/libHelloUART.hex b/HelloNativeLibs/avr/Hellouart/output/libHelloUART.hex index dc5fb927..d3441b04 100644 --- a/HelloNativeLibs/avr/Hellouart/output/libHelloUART.hex +++ b/HelloNativeLibs/avr/Hellouart/output/libHelloUART.hex @@ -2,109 +2,46 @@ :100010000C9451000C9451000C9451000C9451001C :100020000C9451000C9451000C9451000C9451000C :100030000C9451000C9451000C9451000C945100FC -:100040000C9451000C9451000C9428010C94510014 -:100050000C946A010C9451000C9451000C945100C2 +:100040000C9451000C9451000C94C5000C94510078 +:100050000C9407010C9451000C9451000C94510025 :100060000C9451000C94510011241FBECFEFD8E026 -:10007000DEBFCDBF11E0A0E0B1E0EEE4F6E002C0EB -:1000800005900D92AC37B107D9F721E0ACE7B1E0AC -:1000900001C01D92AE39B207E1F70E9496010C949F -:1000A00025030C94000068E071E08CE791E00C946B -:1000B00085006BE171E08CE791E00C9485006BE3C7 -:1000C00071E08CE791E00C948500EF920F931F9301 -:1000D00080E1E82E062F10E020E030E040E050E024 -:1000E00060E070E08CE791E00E9490008CE791E086 -:1000F0001F910F91EF900C94B400609100017091EA -:1001000001018CE791E00C9485008FE791E00E945B -:10011000F30069E771E08FE791E00E94F300089532 -:10012000EF920F931F9382E891E00E94BB0069E772 -:1001300071E082E891E00E94F3001F910F91EF902F -:10014000089588E18093C1008EE08093C20070938F -:10015000C5006093C40085E891E00E94590085E8DD -:1001600091E00E945001089588E891E00E945F00AC -:100170001092C1000895CF92DF92EF920F931F93D8 -:10018000CF93DF9362E070E081E090E00E949D01F8 -:100190006C014E2D50E0BC01802F912F0E94E50292 -:1001A000D0E0C0E0860101501109F6010190002065 -:1001B000E9F73197EC19FD09CE17DF0748F42196CE -:1001C000B8016C0F7D1F8BE891E00E941A01EDCF02 -:1001D000C6010E945502DF91CF911F910F91EF90C0 -:1001E000DF90CF900895EF92FF920F931F93CF93DC -:1001F000DF938B01D0E0C0E07B0181E0E81AF108D9 -:10020000F80101900020E9F73197E01BF10BCE17C0 -:10021000DF0748F42196B7016C0F7D1F8EE891E04F -:100220000E941A01EDCFDF91CF911F910F91FF90A6 -:10023000EF900895E0ECF0E0808185FFFDCFFB01B9 -:1002400080818093C60081E991E00E945D0108955C -:100250001F920F920FB60F9211242F933F934F933B -:100260005F936F937F938F939F93AF93BF93EF931E -:10027000FF936091C60084E991E00E946500FF91C0 -:10028000EF91BF91AF919F918F917F916F915F910E -:100290004F913F912F910F900FBE0F901F90189587 -:1002A000E1ECF0E080818068808378940895E1EC4F -:1002B000F0E080818F7780830895E1ECF0E0808129 -:1002C0008064808378940895E1ECF0E080818F7BF6 -:1002D000808308951F920F920FB60F9211242F93CF -:1002E0003F934F935F936F937F938F939F93AF93BE -:1002F000BF93EF93FF936091C60087E991E00E945E -:100300007D0087E991E00E946401FF91EF91BF9128 -:10031000AF919F918F917F916F915F914F913F919D -:100320002F910F900FBE0F901F90189560E170E015 -:100330008CE791E00E94A100FFCF0F931F93CF9312 -:10034000DF93869F8001879F100D969F100D1124CB -:10035000C8010E94B901EC01009729F0A80170E0E2 -:1003600060E00E94DE02CE01DF91CF911F910F91DC -:1003700008950F931F93CF93DF938230910510F46C -:1003800082E090E0E0919C01F0919D0130E020E05E -:10039000B0E0A0E0309799F42115310509F44AC086 -:1003A000281B390B24303105D8F58A819B816115D2 -:1003B000710589F1FB0193838283FE0111C04081A5 -:1003C00051810281138148175907E0F048175907F6 -:1003D00099F4109761F012960C93129713961C9350 -:1003E0003296CF01DF91CF911F910F910895009325 -:1003F0009C0110939D01F4CF2115310551F0421756 -:10040000530738F0A901DB019A01BD01DF01F801B2 -:10041000C1CFEF01F9CF90939D0180939C01CDCF87 -:10042000FE01E20FF31F819391932250310939832A -:100430002883D7CF20919A0130919B01232B41F43F -:10044000209104013091050130939B0120939A0182 -:1004500020910201309103012115310541F42DB79E -:100460003EB74091060150910701241B350BE091E6 -:100470009A01F0919B01E217F307A0F42E1B3F0BAA -:100480002817390778F0AC014E5F5F4F2417350706 -:1004900048F04E0F5F1F50939B0140939A01819348 -:1004A00091939FCFF0E0E0E09CCFCF93DF93009754 -:1004B000E9F0FC01329713821282A0919C01B09165 -:1004C0009D01ED0130E020E01097A1F42081318101 -:1004D000820F931F20919A0130919B0128173907B1 -:1004E00009F061C0F0939B01E0939A01DF91CF91F5 -:1004F0000895EA01CE17DF07E8F54A815B819E0186 -:1005000041155105B1F7E901FB83EA8349915991FE -:10051000C40FD51FEC17FD0761F48081918102960D -:10052000840F951FE90199838883828193819B833E -:100530008A83F0E0E0E012968D919C9113970097EA -:10054000B9F52D913C911197CD010296820F931F21 -:1005500020919A0130919B012817390739F630977D -:1005600051F510929D0110929C01B0939B01A093B4 -:100570009A01BCCFD383C28340815181840F951FE0 -:10058000C817D90761F44E5F5F4F88819981480F82 -:10059000591F518340838A819B81938382832115D4 -:1005A000310509F0B0CFF0939D01E0939C019ECFFF -:1005B000FD01DC01C0CF13821282D7CFDC0101C064 -:1005C0006D9341505040E0F708954532510520F4B5 -:1005D000423010F00C94F002FB011082CB01089520 -:1005E000BB274A3031F4992322F4BDE290958195DE -:1005F0009F4F0C94FC02BB27FB015527AA27880FAD -:10060000991FAA1FA41710F0A41B83955051B9F786 -:10061000A05DAA3308F0A95DA193009779F7B11105 -:10062000B1931192CB010C941503DC01FC01672FEF -:1006300071917723E1F7329704C07C916D937083B9 -:0E0640006291AE17BF07C8F30895F894FFCF7C -:10064E004E0100009E0120004461746120547261CD -:10065E006E736D697474656420210050726F746FCF -:10066E00636F6C2053746172746564205375636399 -:10067E0065737366756C6C7920210050726F746FA0 -:10068E00636F6C2053746F70706564202100446139 -:10069E007461205472616E736D697373696F6E202D -:1006AE00636F6D706C6574656420737563636573D9 -:0C06BE007366756C6C792021000A0D0039 +:10007000DEBFCDBF11E0A0E0B1E0E8E7F2E002C0F2 +:1000800005900D92A635B107D9F721E0A6E5B1E0BC +:1000900001C01D92AB36B207E1F70E9433010C9408 +:1000A0003A010C94000062E071E086E591E00C9466 +:1000B0007200089565E171E086E591E00C947200AC +:1000C000CF93DF931F92CDB7DEB76983BE016F5F19 +:1000D0007F4F86E591E00E94B7000F90DF91CF91AE +:1000E0000895089589E591E00E94900063E571E02C +:1000F00089E591E00E949000089588E18093C10015 +:100100008EE08093C2007093C5006093C4008CE5BC +:1001100091E00E9459008CE591E00E94ED00089565 +:10012000EF92FF920F931F93CF93DF938B01D0E059 +:10013000C0E07B0181E0E81AF108F801019000209D +:10014000E9F73197E01BF10BCE17DF0748F4219652 +:10015000B7016C0F7D1F8FE591E00E94B700EDCFD6 +:10016000DF91CF911F910F91FF90EF900895E0ECF8 +:10017000F0E0808185FFFDCFFB0180818093C60088 +:1001800082E691E00E94FA0008951F920F920FB646 +:100190000F9211242F933F934F935F936F937F930D +:1001A0008F939F93AF93BF93EF93FF936091C6009C +:1001B00085E691E00E946000FF91EF91BF91AF91C1 +:1001C0009F918F917F916F915F914F913F912F916F +:1001D0000F900FBE0F901F901895E1ECF0E080811A +:1001E0008068808378940895E1ECF0E080818F77D7 +:1001F00080830895E1ECF0E08081806480837894CE +:100200000895E1ECF0E080818F7B808308951F9258 +:100210000F920FB60F9211242F933F934F935F933A +:100220006F937F938F939F93AF93BF93EF93FF93BE +:100230006091C60088E691E00E94710088E691E036 +:100240000E940101FF91EF91BF91AF919F918F911A +:100250007F916F915F914F913F912F910F900FBEC2 +:100260000F901F90189560E170E086E591E00E9484 +:080270007D00FFCFF894FFCFE1 +:10027800280144617461205472616E736D697474ED +:10028800656420210050726F746F636F6C20537423 +:100298006F7070656420210044617461205472613C +:1002A8006E736D697373696F6E20636F6D706C65C3 +:1002B800746564207375636365737366756C6C79B4 +:0602C8002021000A0D00D8 :00000001FF diff --git a/HelloNativeLibs/avr/Hellouart/src/lib/hello_uart.cpp b/HelloNativeLibs/avr/Hellouart/src/lib/hello_uart.cpp index d1ded376..50f14a3d 100644 --- a/HelloNativeLibs/avr/Hellouart/src/lib/hello_uart.cpp +++ b/HelloNativeLibs/avr/Hellouart/src/lib/hello_uart.cpp @@ -30,7 +30,7 @@ void uart::state::onDataBufferCleared(const uint8_t* transmitData) { * Listens for the protocol start command and fires accordingly. */ void uart::state::onProtocolStarted() { - uart_instance.sprintln((char*) "Protocol Started Successfully !"); + // uart_instance.sprintln((char*) "Protocol Started Successfully !"); } /** @@ -51,8 +51,7 @@ void uart::state::onProtocolStopped() { * @param data a data to be received through the interrupt service from the data register. */ void uart::state::onDataReceiveCompleted(const uint8_t data) { - uart_instance.println((const int64_t) data, 16); - uart_instance.stopProtocol(); + uart_instance.cprint((char*) &data); } /** @@ -64,7 +63,7 @@ void uart::state::onDataReceiveCompleted(const uint8_t data) { * @param data a data to be transmitted through the interrupt service from the data register. */ void uart::state::onDataTransmitCompleted(const uint8_t data) { - uart_instance.sprintln((char*) message); + // uart_instance.sprintln((char*) message); } /** @@ -79,4 +78,4 @@ int main(void) { while (true); // wait forever return 0; -} \ No newline at end of file +}