Commit 20c1af05 authored by Martin Horauer's avatar Martin Horauer
Browse files

added a lot of comments to better describe the funcionality of the applications

parent 42f79811
...@@ -18,28 +18,36 @@ ...@@ -18,28 +18,36 @@
#include "mbed.h" #include "mbed.h"
/******************************************************************** Globals */ /******************************************************************** Globals */
AnalogOut aout(P14_8); /* create an object of class AnalogOut: "aout"
see drivers/AnalogOut.h
the parameter P14_8 is declared in
targets/TARGET_Infineon/TARGET_XMC4XXX/TARGET_XMC4500/PinNames.h
*/
AnalogOut aout (P14_8);
/****************************************************************** Functions */ /****************************************************************** Functions */
/** /**
* Main Function * Main Function
*/ */
int main() { int main (void)
{
const double pi = 3.141592653589793238462; const double pi = 3.141592653589793238462;
const double amplitude = 0.4f; const double amplitude = 0.4f;
const double offset = 65535; const double offset = 65535;
double rads = 0.0; double rads = 0.0;
uint16_t sample = 0; uint16_t sample = 0;
while(1) { while (1) {
/* Generate Sinus */ /* Generate Sinus */
for (int i = 0; i < 360; i++) { for (int i = 0; i < 360; i++) {
rads = (pi * i) / 180.0f; rads = (pi * i) / 180.0f;
sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset); sample = (uint16_t) (amplitude * (offset * (cos (rads + pi))) + offset);
aout.write_u16(sample); /* invoke the method .write_u16() on the object aout
see drivers/AnalogOut.h
this method outputs an anlog value on P14_8 using the DAC
*/
aout.write_u16 (sample);
} }
} }
} }
/*EOF*/ /*EOF*/
...@@ -18,20 +18,29 @@ ...@@ -18,20 +18,29 @@
#include "mbed.h" #include "mbed.h"
/******************************************************************** Globals */ /******************************************************************** Globals */
DigitalOut led(LED1); /* create an object from class Digitalout: "led"
see drivers/DigitalOut.h
the parameter LED1 is declared in
targets/TARGET_Infineon/TARGET_XMC4XXX/TARGET_XMC4500/PinNames.h
*/
DigitalOut led (LED1);
/****************************************************************** Functions */ /****************************************************************** Functions */
/** /**
* Main Function * Main Function
*/ */
int main() { int main (void)
{
/* Toggle LED1 */ /* Toggle LED1 */
while (1) { while (1) {
/* overload the operator = using "operator="
see drivers/DigitalOut.h
*/
led = !led; led = !led;
wait(0.5); /* call the function wait() - wait fro a number of seconds (ms resolution)
see platform/mbed_wait_api.cpp
*/
wait (0.5);
} }
} }
/*EOF*/ /*EOF*/
...@@ -19,8 +19,23 @@ ...@@ -19,8 +19,23 @@
#include "rtos.h" #include "rtos.h"
/***************************************************************** Prototypes */ /***************************************************************** Prototypes */
/* create an object of class InterruptIn: "sw"
see drivers/InterruptIn.h
SW2 is defined in
targets/TARGET_Infineon/TARGET_XMC4XXX/TARGET_XMC4500/PinNames.h
*/
InterruptIn sw (SW2); // BUTTON2 = P1.15 InterruptIn sw (SW2); // BUTTON2 = P1.15
/* create an object of class DigitalOut: "led1"
see drivers/DigitalOut.h
LED1 is defined in
targets/TARGET_Infineon/TARGET_XMC4XXX/TARGET_XMC4500/PinNames.h
*/
DigitalOut led1 (LED1); // LED1 = P1.1 DigitalOut led1 (LED1); // LED1 = P1.1
/* create an object of class Serial: "device"
see drivers/Serial.h
P0_1 and P0_0 are defined in
targets/TARGET_Infineon/TARGET_XMC4XXX/TARGET_XMC4500/PinNames.h
*/
Serial device (P0_1, P0_0); // UART1 -> Tx = P0.1, Rx = P0.0 Serial device (P0_1, P0_0); // UART1 -> Tx = P0.1, Rx = P0.0
/****************************************************************** Callbacks */ /****************************************************************** Callbacks */
...@@ -29,7 +44,10 @@ Serial device (P0_1, P0_0); // UART1 -> Tx = P0.1, Rx = P0.0 ...@@ -29,7 +44,10 @@ Serial device (P0_1, P0_0); // UART1 -> Tx = P0.1, Rx = P0.0
*/ */
void rise_handler (void) void rise_handler (void)
{ {
// Toggle LED1 /* ovverride the = operator using "operator ="
see drivers/DigitalOut.h
-> toggle LED1
*/
led1 = !led1; led1 = !led1;
} }
...@@ -38,27 +56,44 @@ void rise_handler (void) ...@@ -38,27 +56,44 @@ void rise_handler (void)
*/ */
void fall_handler (void) void fall_handler (void)
{ {
// output message via UART1 /* output a message via UART1, in partzicular the thread id is output
using the .gettid() method of the current thread
see rtos/Thread.cpp
*/
device.printf ("fall_handler in context %p\r\n", Thread::gettid()); device.printf ("fall_handler in context %p\r\n", Thread::gettid());
// Toggle LED1 /* toggle LED1 */
led1 = !led1; led1 = !led1;
} }
/****************************************************************** Functions */ /****************************************************************** Functions */
/** /**
* Main Function * Main Function
*/ */
int main (void) int main (void)
{ {
// Request the shared queue /* request the shared queue to the OS
see events mbed_event_queue.cpp
*/
EventQueue *queue = mbed_event_queue(); EventQueue *queue = mbed_event_queue();
// Output message via UART1 /* output a message via the device (here UART1) to that end the .printf()
method of platform/Stream.h is invoked, the function will output the
thread id of the main thread using the .gettid() method
see rtos/Thread.cpp
*/
device.printf ("Starting in context %p\r\n", Thread::gettid()); device.printf ("Starting in context %p\r\n", Thread::gettid());
/* the 'rise_handler()' callback function will execute in the IRQ context
// The 'rise' handler will execute in the IRQ context it is installed using the method .rise() and activated when a rising edge
occurs on the input
see drivers/InterruptIn.h
*/
sw.rise (rise_handler); sw.rise (rise_handler);
// The 'fall' handler will execute in the context of the shared queue thread /* The 'fall_handler()' callback will execute in the context of the shared
queue thread - it is installed using the .fall() method see
drivers/InterruptIn.h and activated when a falling edge on the input
is detected - whenever this occurs it is put into a general queue to
the OS see events/mbed_shared_queues.h
the fall_handler() will execute as a separate thread
*/
sw.fall (queue->event (fall_handler)); sw.fall (queue->event (fall_handler));
} }
/*! EOF */ /*! EOF */
...@@ -10,6 +10,11 @@ main mbed project hosted on github at https://github.com/mbed-Infineon-XMC/mbed- ...@@ -10,6 +10,11 @@ main mbed project hosted on github at https://github.com/mbed-Infineon-XMC/mbed-
The example applications are obtained from https://github.com/mbed-Infineon-XMC?tab=repositories[https://github.com/mbed-Infineon-XMC?tab=repositories] and are The example applications are obtained from https://github.com/mbed-Infineon-XMC?tab=repositories[https://github.com/mbed-Infineon-XMC?tab=repositories] and are
structured in folders named like `APP_XXX`. structured in folders named like `APP_XXX`.
[TIP]
Checkout the comments in the main.cpp files of every application - these
examples are heavily commented and refer to the respective files where the
classes, methods and definitions are found.
## Import the project ## Import the project
``` ```
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment