Difference between revisions of "LPC17xx Software Framework Explained"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Example)
 
Line 7: Line 7:
 
# Reset Vector is fetched to go to RESET Handler
 
# Reset Vector is fetched to go to RESET Handler
 
# Reset Handler sets up Global Memory by copying from FLASH to RAM
 
# Reset Handler sets up Global Memory by copying from FLASH to RAM
# Reset Handler calls lowLevelInitialize();
+
# Reset Handler calls low_level_init();
#* lowLevelInitialize() sets up CPU speed according to sysConfig.h
+
#* low_level_init() sets up CPU speed according to sysConfig.h
#* lowLevelInitialize() sets up Flash Accelerator based on CPU Speed
+
#* low_level_init() sets up Flash Accelerator based on CPU Speed
#* lowLevelInitialize() sets up minimal UART0 Driver and prints out CPU speed
+
#* low_level_init() sets up minimal UART0 Driver and prints out CPU speed
# Reset Handler calls highLevelInitialize();
+
# Reset Handler calls high_level_init();
#* highLevelInitialize() initializes SPI Flash and SD Card Signals
+
#* high_level_init() initializes SPI Flash and SD Card Signals
#* highLevelInitialize() initializes Board Drivers (See next section)
+
#* high_level_init() initializes Board Drivers (See next section)
#* highLevelInitialize() sets up TIMER0 for delay functions and FreeRTOS run-time statistics
+
#* high_level_init() sets up TIMER0 for delay functions and FreeRTOS run-time statistics
#* highLevelInitialize() will setup 10ms timer interrupt (RIT) for <code>sd_timerproc()</code>
+
#* high_level_init() will setup 10ms timer interrupt (RIT) for <code>sd_timerproc()</code>
#* highLevelInitialize() attempts to move logfiles from SPI Flash to SD Card (See logger section)
+
#* high_level_init() attempts to move logfiles from SPI Flash to SD Card (See logger section)
#* highLevelInitialize() initializes all Board IO such as temperature and IR sensor.
+
#* high_level_init() initializes all Board IO such as temperature and IR sensor.
 
# Reset Handler calls your main();
 
# Reset Handler calls your main();
  
 
<br/>
 
<br/>
 
=== Pre-Configured Drivers & Devices ===
 
=== Pre-Configured Drivers & Devices ===
The following drivers and devices are initialized by <code>highLevelInitialize()</code> :
+
The following drivers and devices are initialized by <code>high_level_init()</code> :
  
 
Drivers:
 
Drivers:
Line 28: Line 28:
 
*  I2C #2
 
*  I2C #2
 
*  ADC0
 
*  ADC0
*  SPI #1
+
*  SPI #1 (SD + SPI Flash)
 +
*  SPI #2 (Nordic wireless)
  
 
Devices:
 
Devices:
Line 40: Line 41:
  
 
<br/>
 
<br/>
 
 
== Logger ==
 
== Logger ==
 
Logger functionality can be utilized to substitute '''printf''' because it may be difficult to analyze data while your program is running perhaps because of too much information being printed or maybe you don't have access to the terminal while your Board is running your program.
 
Logger functionality can be utilized to substitute '''printf''' because it may be difficult to analyze data while your program is running perhaps because of too much information being printed or maybe you don't have access to the terminal while your Board is running your program.

Latest revision as of 20:34, 2 August 2013

Notes

  • Do not forget to read the Project Documentation by generating it using Doxygen


Startup

The following occurs when the LPC processor resets:

  1. Reset Vector is fetched to go to RESET Handler
  2. Reset Handler sets up Global Memory by copying from FLASH to RAM
  3. Reset Handler calls low_level_init();
    • low_level_init() sets up CPU speed according to sysConfig.h
    • low_level_init() sets up Flash Accelerator based on CPU Speed
    • low_level_init() sets up minimal UART0 Driver and prints out CPU speed
  4. Reset Handler calls high_level_init();
    • high_level_init() initializes SPI Flash and SD Card Signals
    • high_level_init() initializes Board Drivers (See next section)
    • high_level_init() sets up TIMER0 for delay functions and FreeRTOS run-time statistics
    • high_level_init() will setup 10ms timer interrupt (RIT) for sd_timerproc()
    • high_level_init() attempts to move logfiles from SPI Flash to SD Card (See logger section)
    • high_level_init() initializes all Board IO such as temperature and IR sensor.
  5. Reset Handler calls your main();


Pre-Configured Drivers & Devices

The following drivers and devices are initialized by high_level_init() :

Drivers:

  • RTC
  • I2C #2
  • ADC0
  • SPI #1 (SD + SPI Flash)
  • SPI #2 (Nordic wireless)

Devices:

  • Acceleration Sensor
  • Infrared Sensor
  • Light Sensor
  • Temperature Sensor
  • 7-Segment LED Display
  • LEDs
  • Switches


Logger

Logger functionality can be utilized to substitute printf because it may be difficult to analyze data while your program is running perhaps because of too much information being printed or maybe you don't have access to the terminal while your Board is running your program.

The Logger class is designed to log data onto a file in your SPI Flash. It can be easily modified to log to a file onto an SD Card as well. Unlike printf, it has the following features:

  • Logger will log the timestamp, filename, function name, and line number along with your message.
  • Logger will log messages classified under INFO, WARNING, and ERROR
    If the log file is opened in Excel, you can easily filter the message types
  • Logger size is configurable, it will only flush data onto the log-file if the buffer becomes full.

Logger Behavior

  • Logger is designed to write a file onto the SPI Flash Memory as filename: "log.csv"
  • Upon the Board boot-up, if an SD Card is present and log.csv file is present in SPI Flash, it will move this file to your SD Card such that new logs will start over in a new file in the SPI Flash Memory.

Example

LOG_WARN("Did not expect this"); may log something like this:

   1200, WARN, my_file.cpp, my_function(), 123, Did not expect this

Practical Example

void sensor_task(void* p)
{
    while(1) {
        int sensor_value = get_sensor_value();
        if(0 == sensor_value) {
             LOG_WARN("Zero Sensor Value");
        }
        if(sensor_value < 0) {
             LOG_ERROR("Ooops");
        }
    }
}