diff --git a/developpment/interfacer/Makefile b/developpment/Makefile similarity index 69% rename from developpment/interfacer/Makefile rename to developpment/Makefile index 523dbd7..9849f39 100644 --- a/developpment/interfacer/Makefile +++ b/developpment/Makefile @@ -1,4 +1,5 @@ -cpp_src = $(wildcard *.cpp) +cpp_src = $(wildcard *.cpp) $(wildcard ./drivers/bh1750/*.cpp) $(wildcard ./management/*.cpp) $(wildcard ./systems/*.cpp) $(wildcard ./periferals/i2c/*.cpp) + #c_src = $(wildcard ../c/algorithms/*.c) $(wildcard driver/ma120x0/*.c) cpp_obj = $(cpp_src:.cpp=.o) diff --git a/developpment/algorithms/bitgestion.c b/developpment/algorithms/bitgestion.c new file mode 100755 index 0000000..525346c --- /dev/null +++ b/developpment/algorithms/bitgestion.c @@ -0,0 +1,509 @@ +#include "../main.h" +#include"bitgestion.h" + +//SET N th bit to one + + +void throwError( uint16_t error) +{ + printf("\n\rAglorithm.c : An Error has been generated on line : >>%d<<\n\r",error); +} + + +void set_nth_bit_uint8( uint8_t *value, uint8_t &n) +{ + if (n < 8 && n >=0) + { + *value|= 1 << n; + } + else + { + throwError(__LINE__); + } +} + +void set_nth_bit_int8( int8_t *value, uint8_t &n) +{ + if (n < 8 && n >=0) + { + *value|= 1 << n; + } + else + { + throwError(__LINE__); + } +} + +void set_nth_bit_uint16( uint16_t *value, uint8_t &n) +{ + if (n < 16 && n >=0) + { + *value|= 1 << n; + } + else + { + throwError(__LINE__); + } +} + +void set_nth_bit_int16( int16_t *value, uint8_t &n) +{ + if (n < 16 && n >=0) + { + *value|= 1 << n; + } + else + { + throwError(__LINE__); + } +} + +//SET N th bit to 0 +void unset_nth_bit_uint8( uint8_t *value, uint8_t &n) +{ + if (n < 8 && n >=0) + { + *value&=~(1 << n); + } + else + { + throwError(__LINE__); + } +} + +void unset_nth_bit_int8( int8_t *value, uint8_t &n) +{ + if (n < 8 && n >=0) + { + *value&=~(1 << n); + } + else + { + throwError(__LINE__); + } +} + +void unset_nth_bit_uint16( uint16_t *value, uint8_t &n) +{ + if (n < 16 && n >=0) + { + *value&=~(1 << n); + } + else + { + throwError(__LINE__); + } +} + +void unset_nth_bit_int16( int16_t *value, uint8_t &n) +{ + if (n < 16 && n >=0) + { + *value&=~(1 << n); + } + else + { + throwError(__LINE__); + } +} + +//Toggle N th bit +void toggle_nth_bit_uint8( uint8_t *value, uint8_t &n) +{ + if (n < 8 && n >=0) + { + *value^= 1 << n; + } + else + { + throwError(__LINE__); + } +} + +void toggle_nth_bit_int8( int8_t *value, uint8_t &n) +{ + if (n < 8 && n >=0) + { + *value^= 1 << n; + } + else + { + throwError(__LINE__); + } +} + +void toggle_nth_bit_uint16( uint16_t *value, uint8_t &n) +{ + if (n < 16 && n >=0) + { + *value^= 1 << n; + } + else + { + throwError(__LINE__); + } +} + +void toggle_nth_bit_int16( int16_t *value, uint8_t &n) +{ + if (n < 16 && n >=0) + { + *value^= 1 << n; + } + else + { + throwError(__LINE__); + } +} + +//Get N th bit +void get_nth_bit_uint8( uint8_t *value, uint8_t &n) +{ + if (n < 8 && n >=0) + { + *value= (*value>> n) & 1; + } + else + { + throwError(__LINE__); + } +} + +void get_nth_bit_int8( int8_t *value, uint8_t &n) +{ + if (n < 8 && n >=0) + { + *value= (*value>> n) & 1; + } + else + { + throwError(__LINE__); + } +} + +void get_nth_bit_uint16( uint16_t *value, uint8_t &n) +{ + if (n < 16 && n >=0) + { + *value= (*value>> n) & 1; + } + else + { + throwError(__LINE__); + } +} + +void get_nth_bit_int16( int16_t *value, uint8_t &n) +{ + if (n < 16 && n >=0) + { + *value= (*value>> n) & 1; + } + else + { + throwError(__LINE__); + } +} + + + +//Change N th bit to x +//number = (number & ~(1UL << n)) | (x << n); + +void change_nth_bit_to_x_uint8( uint8_t *value, uint8_t &n, uint8_t &x) +{ + if (n < 8 && n >=0) + { + *value= (*value& ~(1 << n)) | (x << n); + } + else + { + throwError(__LINE__); + } +} + +void change_nth_bit_to_x_int8( int8_t *value, uint8_t &n, uint8_t &x) +{ + if (n < 8 && n >=0) + { + *value= (*value& ~(1 << n)) | (x << n); + } + else + { + throwError(__LINE__); + } +} + +void change_nth_bit_to_x_uint16( uint16_t *value, uint8_t &n, uint8_t &x) +{ + if (n < 16 && n >=0) + { + *value= (*value& ~(1 << n)) | (x << n); + } + else + { + throwError(__LINE__); + } +} + +void change_nth_bit_to_x_int16( int16_t *value, uint8_t &n, uint8_t &x) +{ + if (n < 16 && n >=0) + { + *value= (*value& ~(1 << n)) | (x << n); + } + else + { + throwError(__LINE__); + } +} + + + + +//GET N numer of least significant bits +void get_n_bits_lsb_uint8( uint8_t *value, uint8_t &bits) +{ + if (bits < 8 && bits >=0) + { + *value= *value& ((1 << bits)-1); + } + else + { + throwError(__LINE__); + } +} + +void get_n_bits_lsb_int8(int8_t *value, uint8_t &bits) +{ + if (bits < 8 && bits >=0) + { + *value= *value& ((1 << bits)-1); + } + else + { + throwError(__LINE__); + } +} + +void get_n_bits_lsb_uint16( uint16_t *value, uint8_t &bits) +{ + if (bits < 8 && bits >=0) + { + *value= *value& ((1 << bits)-1); + } + else + { + throwError(__LINE__); + } +} + +void get_n_bits_lsb_int16( int16_t *value, uint8_t &bits) +{ + if (bits < 16 && bits >=0) + { + *value= *value& ((1 << bits)-1); + } + else + { + throwError(__LINE__); + } +} + + +//Get N number of most signigiant bit. +void get_n_bits_msb_uint8( uint8_t *value, uint8_t &bits) +{ + if (bits < 8 && bits >=0) + { + *value= *value>> (8-bits); + } + else + { + throwError(__LINE__); + } +} + +void get_n_bits_msb_int8(int8_t *value, uint8_t &bits) +{ + if (bits < 8 && bits >=0) + { + *value= *value>> (8-bits); + } + else + { + throwError(__LINE__); + } +} + +void get_n_bits_msb_uint16( uint16_t *value, uint8_t &bits) +{ + if (bits < 16 && bits >=0) + { + *value= *value>> (16-bits); + } + else + { + throwError(__LINE__); + } +} + +void get_n_bits_msb_int16( int16_t *value, uint8_t &bits) +{ + if (bits < 16 && bits >=0) + { + *value= *value>> (16-bits); + } + else + { + throwError(__LINE__); + } +} + +// Get Bits range from startBit to stopBit and *value= them shifted. +void get_bits_range_uint8( uint8_t *value, uint8_t &startBit, uint8_t &stopBit) +{ + if (startBit < 8 && startBit >=0) + { + if(stopBit < 8 && stopBit >=0) + { + if(startBit < stopBit) + { + uint8_t mask = 0; + uint8_t i = 0; + for(i = startBit; i < stopBit; i++ ) + { + mask |= (1 << i); + } + *value= ((*value& mask) >> startBit); + } + } + } + else + { + throwError(__LINE__); + } +} + +void get_bits_range_int8( int8_t *value, uint8_t &startBit, uint8_t &stopBit) +{ + if (startBit < 8 && startBit >=0) + { + if(stopBit < 8 && stopBit >=0) + { + if(startBit < stopBit) + { + uint8_t mask = 0; + uint8_t i = 0; + for(i = startBit; i < stopBit; i++ ) + { + mask |= (1 << i); + } + *value= (*value& mask) >> startBit; + } + } + } + else + { + throwError(__LINE__); + } +} + +void get_bits_range_uint16( uint16_t *value, uint8_t &startBit, uint8_t &stopBit) +{ + if (startBit < 16 && startBit >=0) + { + if(stopBit < 16 && stopBit >=0) + { + if(startBit < stopBit) + { + uint8_t mask = 0; + uint8_t i = 0; + for(i = startBit; i < stopBit; i++ ) + { + mask |= (1 << i); + } + *value= (*value& mask) >> startBit; + } + } + } + else + { + throwError(__LINE__); + } +} + + + +void get_bits_range_int16( int16_t *value, uint8_t &startBit, uint8_t &stopBit) +{ + if (startBit < 16 && startBit >=0) + { + if(stopBit < 16 && stopBit >=0) + { + if(startBit < stopBit) + { + uint8_t mask = 0; + uint8_t i = 0; + for(i = startBit; i < stopBit; i++ ) + { + mask |= (1 << i); + } + *value= (*value& mask) >> startBit; + } + } + } + else + { + throwError(__LINE__); + } +} + + +void set_bits_range_uint8(uint8_t *value, uint8_t &startBit, uint8_t &stopBit, uint8_t &replace) +{ + if (startBit < 8 && startBit >=0) + { + if(stopBit < 8 && stopBit >=0) + { + if(startBit < stopBit) + { + uint8_t mask = 0; + uint8_t i = 0; + for(i = startBit; i < stopBit; i++ ) + { + mask |= (1 << i); + } + *value= (*value & ~mask) | replace << startBit; + } + } + } + else + { + throwError(__LINE__); + } +} + +void set_bits_range_uint16(uint16_t *value, uint8_t &startBit, uint8_t &stopBit, uint16_t &replace) +{ + if (startBit < 16 && startBit >=0) + { + if(stopBit < 16 && stopBit >=0) + { + if(startBit < stopBit) + { + uint8_t mask = 0; + uint8_t i = 0; + for(i = startBit; i < stopBit; i++ ) + { + mask |= (1 << i); + } + *value= (*value & ~mask) | replace << startBit; + } + } + } + else + { + throwError(__LINE__); + } +} diff --git a/developpment/algorithms/bitgestion.h b/developpment/algorithms/bitgestion.h new file mode 100755 index 0000000..0d49ec9 --- /dev/null +++ b/developpment/algorithms/bitgestion.h @@ -0,0 +1,44 @@ +void set_bits_range_uint16(uint16_t *value, uint8_t &startBit, uint8_t &stopBit, uint16_t &replace); +void set_bits_range_uint8(uint8_t *value, uint8_t &startBit, uint8_t &stopBit, uint8_t &replace); + +void throwError( uint16_t error); + +void set_nth_bit_uint8( uint8_t *value, uint8_t &n); +void set_nth_bit_int8( int8_t *value, uint8_t &n); +void set_nth_bit_uint16( uint16_t *value, uint8_t &n); +void set_nth_bit_int16( int16_t *value, uint8_t &n); + +void unset_nth_bit_uint8( uint8_t *value, uint8_t &n); +void unset_nth_bit_int8( int8_t *value, uint8_t &n); +void unset_nth_bit_uint16( uint16_t *value, uint8_t &n); +void unset_nth_bit_int16( int16_t *value, uint8_t &n); + +void toggle_nth_bit_uint8( uint8_t *value, uint8_t &n); +void toggle_nth_bit_int8( int8_t *value, uint8_t &n); +void toggle_nth_bit_uint16( uint16_t *value, uint8_t &n); +void toggle_nth_bit_int16( int16_t *value, uint8_t &n); + +void get_nth_bit_uint8( uint8_t *value, uint8_t &n); +void get_nth_bit_int8( int8_t *value, uint8_t &n); +void get_nth_bit_uint16( uint16_t *value, uint8_t &n); +void get_nth_bit_int16( int16_t *value, uint8_t &n); + +void change_nth_bit_to_x_uint8( uint8_t *value, uint8_t &n, uint8_t &x); +void change_nth_bit_to_x_int8( int8_t *value, uint8_t &n, uint8_t &x); +void change_nth_bit_to_x_uint16( uint16_t *value, uint8_t &n, uint8_t &x); +void change_nth_bit_to_x_int16( int16_t *value, uint8_t &n, uint8_t &x); + +void get_n_bits_lsb_uint8( uint8_t *value, uint8_t &bits); +void get_n_bits_lsb_int8(int8_t *value, uint8_t &bits); +void get_n_bits_lsb_uint16( uint16_t *value, uint8_t &bits); +void get_n_bits_lsb_int16( int16_t *value, uint8_t &bits); + +void get_n_bits_msb_uint8( uint8_t *value, uint8_t &bits); +void get_n_bits_msb_int8(int8_t *value, uint8_t &bits); +void get_n_bits_msb_uint16( uint16_t *value, uint8_t &bits); +void get_n_bits_msb_int16( int16_t *value, uint8_t &bits); + +void get_bits_range_uint8( uint8_t *value, uint8_t &startBit, uint8_t &stopBit); +void get_bits_range_int8( int8_t *value, uint8_t &startBit, uint8_t &stopBit); +void get_bits_range_uint16( uint16_t *value, uint8_t &startBit, uint8_t &stopBit); +void get_bits_range_int16( int16_t *value, uint8_t &startBit, uint8_t &stopBit); diff --git a/developpment/interfacer/bh1750.cpp b/developpment/drivers/bh1750/bh1750.cpp similarity index 100% rename from developpment/interfacer/bh1750.cpp rename to developpment/drivers/bh1750/bh1750.cpp diff --git a/developpment/interfacer/bh1750.h b/developpment/drivers/bh1750/bh1750.h similarity index 96% rename from developpment/interfacer/bh1750.h rename to developpment/drivers/bh1750/bh1750.h index b02bcc4..043dbac 100644 --- a/developpment/interfacer/bh1750.h +++ b/developpment/drivers/bh1750/bh1750.h @@ -5,7 +5,7 @@ #include #include #include -#include "i2c_ch1_pImpL.hpp" +#include "../../periferals/i2c/i2c_ch1_pImpL.hpp" //Start measurement at 4lx resolution. Time typically 16ms. diff --git a/developpment/drivers/bh1750/bh1750.o b/developpment/drivers/bh1750/bh1750.o new file mode 100644 index 0000000..44efbf2 Binary files /dev/null and b/developpment/drivers/bh1750/bh1750.o differ diff --git a/developpment/interfacer/bh1750.py b/developpment/drivers/bh1750/bh1750.py similarity index 100% rename from developpment/interfacer/bh1750.py rename to developpment/drivers/bh1750/bh1750.py diff --git a/developpment/interfacer/interfacer.cpp b/developpment/interfacer.cpp similarity index 87% rename from developpment/interfacer/interfacer.cpp rename to developpment/interfacer.cpp index 33911e6..4f0eac6 100644 --- a/developpment/interfacer/interfacer.cpp +++ b/developpment/interfacer.cpp @@ -9,10 +9,10 @@ #include #include -#include "errorHandling.h" -#include "commandManager.h" -#include "systemCall.h" -#include "bh1750.h" +#include "./management/errorHandling.h" +#include "./management/commandManager.h" +#include "./systems/systemCall.h" +#include "./drivers/bh1750/bh1750.h" //#include "i2c_ch1_pImpL.cpp" #include diff --git a/developpment/interfacer.o b/developpment/interfacer.o new file mode 100644 index 0000000..d8d613f Binary files /dev/null and b/developpment/interfacer.o differ diff --git a/developpment/interfacer/$ b/developpment/interfacer/$ deleted file mode 100644 index 561212d..0000000 --- a/developpment/interfacer/$ +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _EXECUTEBASH_H_ -#define _EXECUTEBASH_H_ - -#include -#include -#include -#include -#include -#include - -std::string execBash(const char* cmd); - -#endif //_EXECUTEBASH_H_ diff --git a/developpment/interfacer/commandManager.cpp b/developpment/management/commandManager.cpp similarity index 100% rename from developpment/interfacer/commandManager.cpp rename to developpment/management/commandManager.cpp diff --git a/developpment/interfacer/commandManager.h b/developpment/management/commandManager.h similarity index 100% rename from developpment/interfacer/commandManager.h rename to developpment/management/commandManager.h diff --git a/developpment/management/commandManager.o b/developpment/management/commandManager.o new file mode 100644 index 0000000..c9eefcf Binary files /dev/null and b/developpment/management/commandManager.o differ diff --git a/developpment/interfacer/errorHandling.cpp b/developpment/management/errorHandling.cpp similarity index 100% rename from developpment/interfacer/errorHandling.cpp rename to developpment/management/errorHandling.cpp diff --git a/developpment/interfacer/errorHandling.h b/developpment/management/errorHandling.h similarity index 100% rename from developpment/interfacer/errorHandling.h rename to developpment/management/errorHandling.h diff --git a/developpment/management/errorHandling.o b/developpment/management/errorHandling.o new file mode 100644 index 0000000..5826368 Binary files /dev/null and b/developpment/management/errorHandling.o differ diff --git a/developpment/interfacer/i2c.hpp b/developpment/periferals/i2c/i2c.hpp similarity index 100% rename from developpment/interfacer/i2c.hpp rename to developpment/periferals/i2c/i2c.hpp diff --git a/developpment/interfacer/i2c_ch0_pImpL.cpp b/developpment/periferals/i2c/i2c_ch0_pImpL.cpp similarity index 99% rename from developpment/interfacer/i2c_ch0_pImpL.cpp rename to developpment/periferals/i2c/i2c_ch0_pImpL.cpp index 3b34f6e..6201bc8 100644 --- a/developpment/interfacer/i2c_ch0_pImpL.cpp +++ b/developpment/periferals/i2c/i2c_ch0_pImpL.cpp @@ -1,5 +1,4 @@ #include "i2c_ch0_pImpL.h" -#include "systemCall.h" #include #include diff --git a/developpment/interfacer/i2c_ch0_pImpL.h b/developpment/periferals/i2c/i2c_ch0_pImpL.h similarity index 89% rename from developpment/interfacer/i2c_ch0_pImpL.h rename to developpment/periferals/i2c/i2c_ch0_pImpL.h index c91299c..51fa22a 100644 --- a/developpment/interfacer/i2c_ch0_pImpL.h +++ b/developpment/periferals/i2c/i2c_ch0_pImpL.h @@ -4,7 +4,8 @@ #include #include #include -#include "errorHandling.h" +#include "../../management/errorHandling.h" +#include "../../systems/systemCall.h" class i2c_ch0_pImpL { diff --git a/developpment/periferals/i2c/i2c_ch0_pImpL.o b/developpment/periferals/i2c/i2c_ch0_pImpL.o new file mode 100644 index 0000000..b47e8ec Binary files /dev/null and b/developpment/periferals/i2c/i2c_ch0_pImpL.o differ diff --git a/developpment/interfacer/i2c_ch1_pImpL.cpp b/developpment/periferals/i2c/i2c_ch1_pImpL.cpp similarity index 99% rename from developpment/interfacer/i2c_ch1_pImpL.cpp rename to developpment/periferals/i2c/i2c_ch1_pImpL.cpp index a498ea2..7818b65 100644 --- a/developpment/interfacer/i2c_ch1_pImpL.cpp +++ b/developpment/periferals/i2c/i2c_ch1_pImpL.cpp @@ -1,5 +1,4 @@ #include "i2c_ch1_pImpL.hpp" -#include "systemCall.h" #include #include diff --git a/developpment/interfacer/i2c_ch1_pImpL.hpp b/developpment/periferals/i2c/i2c_ch1_pImpL.hpp similarity index 89% rename from developpment/interfacer/i2c_ch1_pImpL.hpp rename to developpment/periferals/i2c/i2c_ch1_pImpL.hpp index 4c5d5fd..d53d85f 100644 --- a/developpment/interfacer/i2c_ch1_pImpL.hpp +++ b/developpment/periferals/i2c/i2c_ch1_pImpL.hpp @@ -4,7 +4,8 @@ #include #include #include -#include "errorHandling.h" +#include "../../systems/systemCall.h" +#include "../../management/errorHandling.h" class i2c_ch1_pImpL { diff --git a/developpment/periferals/i2c/i2c_ch1_pImpL.o b/developpment/periferals/i2c/i2c_ch1_pImpL.o new file mode 100644 index 0000000..8402b60 Binary files /dev/null and b/developpment/periferals/i2c/i2c_ch1_pImpL.o differ diff --git a/developpment/interfacer/i2c_driver.cpp b/developpment/periferals/i2c/i2c_driver.cpp similarity index 99% rename from developpment/interfacer/i2c_driver.cpp rename to developpment/periferals/i2c/i2c_driver.cpp index 7b81d3d..d0a2ea3 100644 --- a/developpment/interfacer/i2c_driver.cpp +++ b/developpment/periferals/i2c/i2c_driver.cpp @@ -1,5 +1,4 @@ #include "i2c_driver.h" -#include "systemCall.h" #include #include diff --git a/developpment/interfacer/i2c_driver.h b/developpment/periferals/i2c/i2c_driver.h similarity index 88% rename from developpment/interfacer/i2c_driver.h rename to developpment/periferals/i2c/i2c_driver.h index dbbc361..dd69c05 100644 --- a/developpment/interfacer/i2c_driver.h +++ b/developpment/periferals/i2c/i2c_driver.h @@ -1,7 +1,8 @@ #include #include #include -#include "errorHandling.h" +#include "../../management/errorHandling.h" +#include "../../systems/systemCall.h" class I2C_Driver { diff --git a/developpment/periferals/i2c/i2c_driver.o b/developpment/periferals/i2c/i2c_driver.o new file mode 100644 index 0000000..57c9c26 Binary files /dev/null and b/developpment/periferals/i2c/i2c_driver.o differ diff --git a/developpment/runtest b/developpment/runtest new file mode 100755 index 0000000..e5cd4b4 Binary files /dev/null and b/developpment/runtest differ diff --git a/developpment/interfacer/systemCall.cpp b/developpment/systems/systemCall.cpp similarity index 100% rename from developpment/interfacer/systemCall.cpp rename to developpment/systems/systemCall.cpp diff --git a/developpment/interfacer/systemCall.h b/developpment/systems/systemCall.h similarity index 100% rename from developpment/interfacer/systemCall.h rename to developpment/systems/systemCall.h diff --git a/developpment/systems/systemCall.o b/developpment/systems/systemCall.o new file mode 100644 index 0000000..f7b9606 Binary files /dev/null and b/developpment/systems/systemCall.o differ