some question about source code

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
XXzzz
Posts: 15
Joined: Wed Dec 20, 2017 8:14 am
Has thanked: 3 times
Been thanked: 1 time

some question about source code

Postby XXzzz » Thu May 31, 2018 5:05 am

when i reading the source code ,i have some question about the object oriented in chibios.
the struct BMP085Driver have four members,and there have some methods in the vmt.

Code: Select all

static BMP085Driver BMP085D1;
/**
 * @brief   BMP085 driver structure.
 */
struct BMP085Driver {
  /** @brief BaseSensor Virtual Methods Table.                              */
  const struct BaseSensorVMT      *vmt_basesensor;
  /** @brief BaseBarometer Virtual Methods Table.                           */
  const struct BaseBarometerVMT   *vmt_basebarometer;
  /** @brief BaseThermometer Virtual Methods Table.                         */
  const struct BaseThermometerVMT *vmt_basethermometer;
  _bmp085_data;
};

so the main.c invoke the macro 'barometerReadRaw'

Code: Select all

#define barometerReadRaw(ip, dp)                                              \
        (ip)->vmt->read_raw(ip, dp)
       
 typedef struct {
  /** @brief Virtual Methods Table.*/
  const struct BaseBarometerVMT *vmt;
  _base_barometer_data
} BaseBarometer;

so these class ,like this

Code: Select all

struct
{
   instance_offset
   parent_methods
   parent_data
   children_methods
   children_data
}children

ithink we can get instance throw the macro 'objGetInstance'

Code: Select all

#define objGetInstance(type, ip)                                            \
  (type)(((size_t)(ip)) - (ip)->vmt->instance_offset)


so the question is :
1. i can't find the place where invoke the macro
2. the 'barometerReadRaw' is (ip)->vmt->read_raw(ip, dp) but in the BMP085Driver we have three vmt,how it works?
3. where can get the chibios oo model ..
4. maybe the detail of the answer is complicated , give me some advice about learning the oo in c model will be beter.

and thanks for your help.

XXzzz
Posts: 15
Joined: Wed Dec 20, 2017 8:14 am
Has thanked: 3 times
Been thanked: 1 time

Re: some question about source code

Postby XXzzz » Thu May 31, 2018 5:08 am

this code is in the CHIBIOS182->testex->STM32F4XX->I2C-BMP085
maybe my problem description is not very accurate,
thanks for your help again

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: some question about source code

Postby Giovanni » Thu May 31, 2018 8:08 am

Hi,

I think that driver is not updated to the latest model, probably a misunderstanding between the maintainers. If you want to understand the OO model please look at one of the updated drivers, lps22hb.h for example.

This is a proper example:

Code: Select all

struct LPS22HBDriver {
  /** @brief Virtual Methods Table.*/
  const struct LPS22HBVMT   *vmt;
  /** @brief Base barometer interface.*/
  BaseBarometer             baro_if;
  /** @brief Base thermometer interface.*/
  BaseThermometer           thermo_if;
  _lps22hb_data
};


The model allows for multiple inheritance, both methods and data can be inherited. the object starts with its own VMT then it includes instances of the inherited ancestors entirely, both VMTs and data, at the end there is the object's own data.

The first field of the various VMTs is the offset to the object start address, this way the object base address can be recalculated knowing any interface pointer.

Giovanni

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: some question about source code

Postby tfAteba » Fri Jun 01, 2018 12:00 pm

Hi all,

Giovanni is right, the driver is not updated, I'm really sorry for that.

I'm not at home this weekend, I'm in travel, so I will manage that on Monday.

I hope that you can wait that time.

Thanks for you understanding.
regards,

Theo.

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: some question about source code

Postby tfAteba » Tue Jun 05, 2018 8:15 am

Hello,

I just want to said that I have just updated the code, but I still need to make some test before to push it to the svn repo.

I will do that tomorrow if all the test are fine.

Thanks.
regards,

Theo.

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: some question about source code

Postby tfAteba » Wed Jun 06, 2018 8:00 am

Hello,

Work is in progress, I have some troubles to resolve, It didn't work at the first time.

Thanks for your patience.
regards,

Theo.

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: some question about source code

Postby tfAteba » Tue Jun 12, 2018 9:01 am

Hi All,

The demo Is still not working.

So Marco can you take a look please and tell me if you see something wrong?

Thanks in advance.
Attachments
bmp085.zip
(1.3 MiB) Downloaded 186 times
regards,

Theo.

User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Location: Munich (Germany)
Has thanked: 83 times
Been thanked: 67 times
Contact:

Re: some question about source code

Postby RoccoMarco » Thu Jun 14, 2018 11:39 pm

Hello there,
I am going to take a look to it. Please look forward for a reply. Thanks for your effort in code maintenance.
Ciao,
RM

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: some question about source code

Postby tfAteba » Fri Jun 15, 2018 7:41 am

Hello Marco,

Thanks you for your help too :) . I hope we can manage that by combining our effort.

This week I will also continue to look in my side.

Thanks a lot.
regards,

Theo.


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 10 guests