Made some structural re-organization

master
Kerem Yollu 4 years ago
parent a504c85e79
commit 719c3ecb16

@ -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)

@ -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__);
}
}

@ -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);

@ -5,7 +5,7 @@
#include <iostream>
#include <array>
#include <string>
#include "i2c_ch1_pImpL.hpp"
#include "../../periferals/i2c/i2c_ch1_pImpL.hpp"
//Start measurement at 4lx resolution. Time typically 16ms.

@ -9,10 +9,10 @@
#include <iostream>
#include <stdint.h>
#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<unistd.h>

Binary file not shown.

@ -1,13 +0,0 @@
#ifndef _EXECUTEBASH_H_
#define _EXECUTEBASH_H_
#include <cstdio>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>
#include <array>
std::string execBash(const char* cmd);
#endif //_EXECUTEBASH_H_

@ -1,5 +1,4 @@
#include "i2c_ch0_pImpL.h"
#include "systemCall.h"
#include <cstdio>
#include <ostream>

@ -4,7 +4,8 @@
#include <stdint.h>
#include <iostream>
#include <string>
#include "errorHandling.h"
#include "../../management/errorHandling.h"
#include "../../systems/systemCall.h"
class i2c_ch0_pImpL
{

@ -1,5 +1,4 @@
#include "i2c_ch1_pImpL.hpp"
#include "systemCall.h"
#include <cstdio>
#include <ostream>

@ -4,7 +4,8 @@
#include <stdint.h>
#include <iostream>
#include <string>
#include "errorHandling.h"
#include "../../systems/systemCall.h"
#include "../../management/errorHandling.h"
class i2c_ch1_pImpL
{

@ -1,5 +1,4 @@
#include "i2c_driver.h"
#include "systemCall.h"
#include <cstdio>
#include <ostream>

@ -1,7 +1,8 @@
#include <stdint.h>
#include <iostream>
#include <string>
#include "errorHandling.h"
#include "../../management/errorHandling.h"
#include "../../systems/systemCall.h"
class I2C_Driver
{

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save