added example code to C++ project

main
Jonas Arnold 4 years ago
parent 17c5886383
commit e5b4c409c7
  1. 964
      ADIS_tinyK22_Cpp_Project/.cproject
  2. 14
      ADIS_tinyK22_Cpp_Project/source/ADIS_tinyK22_Cpp_Project.cpp
  3. 44
      ADIS_tinyK22_Cpp_Project/source/car.cpp
  4. 21
      ADIS_tinyK22_Cpp_Project/source/car.hh

File diff suppressed because it is too large Load Diff

@ -40,6 +40,7 @@
#include "MK22F51212.h" #include "MK22F51212.h"
#include "fsl_debug_console.h" #include "fsl_debug_console.h"
/* TODO: insert other include files here. */ /* TODO: insert other include files here. */
#include "car.hh"
/* TODO: insert other definitions and declarations here. */ /* TODO: insert other definitions and declarations here. */
@ -59,14 +60,9 @@ int main(void) {
PRINTF("Hello World\n"); PRINTF("Hello World\n");
/* Force the counter to be placed into memory. */ CAR_Test();
volatile static int i = 0 ; CAR_Exit();
/* Enter an infinite loop, just incrementing a counter. */
while(1) {
i++ ;
/* 'Dummy' NOP to allow source level single stepping of
tight while() loop */
__asm volatile ("nop");
}
return 0 ; return 0 ;
} }

@ -0,0 +1,44 @@
/*
* Copyright (c) 2021-2022, Erich Styger
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "car.hh"
#include <stdlib.h> // for exit()
class Car {
private: int price;
public:
Car(void) { // constructor
price = 1000;
}
~Car(void) { // destructor
price = -1;
}
void SetPrice(int price) { // setter method
this->price = price;
}
};
// global variables
static Car c; // global object, shall be initialized by startup (constructor)
static int i; // initialized by startup (zero-out)
static int j = 0x1234; // initialized by startup (copy-down)
void CAR_Test(void) {
Car newCar; // local object: constructor called?
c.SetPrice(i+1000);
newCar.SetPrice(j);
// destructors of newCar called?
}
extern "C" {
extern void __libc_fini_array(void);
}
void CAR_Exit(void) {
// __libc_fini_array();
exit(-1); // force application exit, global destructors called?
}

@ -0,0 +1,21 @@
/*
* Copyright (c) 2021-2022, Erich Styger
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef CAR_HH_
#define CAR_HH_
#ifdef __cplusplus
extern "C" {
#endif
void CAR_Test(void);
void CAR_Exit(void);
#ifdef __cplusplus
}
#endif
#endif /* CAR_HH_ */
Loading…
Cancel
Save