Lockheed Martin Embedded SWE

0.0(0)
studied byStudied by 0 people
0.0(0)
call with kaiCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/78

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 2:14 PM on 1/22/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

79 Terms

1
New cards

What is the stack?

a region of memory that stores local variables and functions calls.
memory is allocated on the stack during runtime when a program enters a fn.
memory is automatically freed when exiting a function

2
New cards

Why use the stack?

it is deterministic (moving stack ptr, no fragmentation), fast (predictable timing, safe for RT systems)

3
New cards

Stack downsides?

Much smaller than the heap.
Too much usage causes stack overflow.

4
New cards

What is the heap?

a region of memory used for dynamic memory allocation.
memory is allocated during runtime and freed manually.

5
New cards

Why is using the heap bad in embedded applications?

Non-deterministic, fragmentation risk, memory leak risk

6
New cards

C specific dynamic memory allocation

malloc()
free()
has no constructor
returns void *

7
New cards

C++ specific dynamic memory allocation

new
delete
calls constructor

8
New cards

What is a memory leak?

Allocated memory that is never freed.

9
New cards

Why are memory leaks bad in embedded?

Embedded systems have small RAM. Can exhaust the heap and cause embedded systems to crash.

10
New cards

What are dangling pointers?

Pointer that points to freed memory. Can cause unpredictable crashes

11
New cards

What is memory alignment?

Some CPUs require data to be aligned, ex: a 4 byte int must be at an address divisible by 4
Aligning memory increases performance and avoids faults.

12
New cards

Why is dynamic allocation dangerous in embedded?

Problems with fragmentation, non-deterministic timing (malloc can take unpredictable time), and heap exhaustion (no memory → system failure)

13
New cards

What is a pointer?

A variable that stores the memory address of another variable.

14
New cards

What is a reference?

an alias for an existing variable, providing direct access to the same object.
References allow functions to operate on existing variables without copying
In C++, & is used both as the address-of operator in expressions and as the reference declarator in type declarations.

15
New cards

Differences between pointer and references?

A pointer is an object that stores the memory address of another object and can be reassigned or null.
A reference is an alias to an existing object that must be initialized at creation and cannot be null.

16
New cards

const int* p vs. int* const p

  • Pointer to const data

  • Data cannot change

  • Const pointer

  • Pointer cannot change

17
New cards

How does pointer arithmetic work?

Arrays are contiguous in memory, but “contiguous” in element-to-element, not byte-to-byte.
Pointer arithmetic advances by element size so each pointer lands exactly on the next object.

18
New cards

Null Pointer Checks, how to do them? What happens if you dereference null?

if (p == NULL) return;
Catastrophic, hard fault

19
New cards

C vs. C++ in embedded

Embedded C++ provides abstractions like RAII, references, and strong typing

20
New cards

RAII example

class MutexLock {

public:

MutexLock(Mutex& m) : mutex(m) { mutex.lock(); }

~MutexLock() { mutex.unlock(); }

private:

Mutex& mutex;

};

Prevents problems with early returns in functions and makes code less verbose.

21
New cards

What are the 4 pillars of OOP?

Abstraction, Polymorphism, Inheritance, Encapsulation

22
New cards

What is abstraction?

a technique that manages complexity, exposing what an object does rather than how it does it

23
New cards

Example of abstraction?

A HAL: it can be as simple as a function that hides low-level register access, so users interact with hardware through APIs instead of raw registers.

24
New cards

Why is abstraction important?

Portability across MCU’s
Increases Readability of code
Increases safety (removes possibility of illegal register access)

25
New cards

What is polymorphism?

a technique that allows different objects to be treated through a common interface, whose implementation is determined at runtime (attained primarily with virtual functions)

26
New cards

Example of polymorphism?

think of a Sensor base class with read(), overridden by IMU and Lidar subclasses to read their values, the call to read() is known at runtime.

IMU and Lidar have different read implementations (virtual function in base class that is overridden by derived classes)

27
New cards

Why is C++ more type safe than C?

C makes more assumptions that can break things / cause unintended behavior.
Example: More explicit casting is required in C++ as opposed to C.

28
New cards

What is inheritance?

a technique that allows a class to extend the behavior of another class. (is-a)

29
New cards

Inheritance example?

IMU and Lidar classes are derived classes from base class Sensor.
Sensor has a common function, lets say void calibrate();
Each derived class inherits this calibrate function and shares this code from the base class.

30
New cards

Inheritance vs Composition

Inheritance models an ‘is-a’ relationship but creates tight coupling. Composition models a ‘has-a’ relationship, which is more flexible

31
New cards

What is encapsulation?

A technique of hiding implementation details

32
New cards

Abstraction vs Encapsulation?

Abstraction focuses on what the system does.
Encapsulation focuses on what is hidden and protected.

class GPIO {

public:

void set(); // abstraction

private:

uint32_t ODR; // encapsulation

};

set(); is the abstraction that sets a pin to high or low.
ODR is encapsulated by being set to private in the GPIO class.

33
New cards

A PIE lock in

  • Abstraction → what an object does

  • Polymorphism → runtime behavior

  • Inheritance → reuse/extend

  • Encapsulation → hide how an object is implemented

34
New cards

MPU vs MCU

MPU is a processor implemented on a single IC, with no direct interface with external peripherals.
MCU contains a MPU, Memory, timer, ADC/DAC, DMA controller, and GPIO on one IC.

35
New cards

Rules of Interrupts

  • Keep short

  • No blocking

  • No malloc

  • No printf

36
New cards

ISR vs RTOS Task (thread)

ISRs are immediate, have no blocking, and use minimal logic.
Tasks are scheduled, can block, and contain heavy logic.

37
New cards

SPI

Serial Peripheral Interface
Synchronous (uses shared clock signal)
SPI uses 4 wires (MOSI, MISO, SCK, SS)

Full duplex

Uses more pins, used for flash memory, SD cards

38
New cards

I2C

Inter-Intergrated Circuit
Synchronous
I2C uses 2 wires (SDA and SCL)

Half-Duplex

Generally slower, used for sensors, connecting many devices

39
New cards

UART

Asynchronous
Slow

Full Duplex

Used typically for debugging

40
New cards

CAN (Controller Area Network)

Asynchronous
Half Duplex

each CAN message has its own priority

41
New cards

DMA

Direct Memory Access: allows peripherals to transfer large blocks of data directly to/from main memory without involving the CPU
Reduces latency & CPU load

42
New cards

Process vs. Thread

A process is an instance of a program. Processes do not share a memory space by default.
A thread is a unit of execution within a process. Threads within a process share the same address space.
HAVE DIRECT ACCESS TO MEMORY in embedded applications

43
New cards

What is a context switch?

when the OS stops one running thread and resumes another, saving the thread’s context and restoring a new one

during context switch TCB holds the stack pointer. CPU registers are stored onto the stack

44
New cards

What are CPU registers?

storage locations inside the processor, holds the live working state of the program.

45
New cards

What is PC?

Program Counter, a CPU register that stores where the program was executing

46
New cards

What is the SP?

Stack pointer, a CPU register that points to the top of the stack.

47
New cards

Where are the CPU registers saved?

In RTOS, they are saved in that task’s dedicated stack (in RAM). Too much memory usage from a thread can result in a stack overflow.

48
New cards

Why is context switching expensive?

CPU Overhead (saving/restoring registers)
Cache misses (CPU caches contain old thread data, cache lines must be reloaded from RAM)

49
New cards

Why does the overhead of context switching matter in embedded?

Too many context switches causes missed deadlines, jitter, and increased power consumption

50
New cards

Stack vs TCB

Stack: “Everything the task needs to resume execution
TCB: “Everything the scheduler needs to manage the task”

51
New cards

Running task state

Task is currently executing on CPU

52
New cards

Ready task state

Task is able to run, but is not currently executing

53
New cards

Blocked task state

Task cannot run until an event occurs
(waiting for delay, mutex, interrupt)

54
New cards

Suspended task state

Task is explicitly stopped, won’t run again unless resumed manually

55
New cards

Deleted task state

Task is destroyed and memory is freed

56
New cards

Yielded vs Preempted

A yielded task voluntarily gives up the CPU, yielded task goes into Ready state.
Preempted task is forcibly interrupted when a higher priority task is Ready (or ISR is triggered), the preempted task goes into the Ready state and higher priority task runs.

57
New cards

When does a full context save occur?

When the CPU switches from one task to another.

58
New cards

Interrupt vs Task context switch

Interrupts cannot block and switch tasks directly, does not fully save context. Preempts the currently running task

59
New cards

RTOS vs Baremetal

Bare-metal is for simple, resource-constrained tasks
RTOS is used for complex systems needing multitasking and scheduling, offering structure but with overhead

60
New cards

What is priority based scheduling?

Every task has a priority, the highest priority task always runs

61
New cards

What is preemption?

A running task is forcibly stopped, it occurs when a higher priority task become ready.

62
New cards

What is the tick interrupt?

A hardware timer interrupt, unblocks tasks whose delay expired

63
New cards

Time slicing

tasks of equal priority get short fixed durations to run (in round robin fashion) to give the illusion of concurrency

64
New cards

What is a mutex?

mutual exclusion used to prevent multiple threads from simultaneously accessing a shared resource

65
New cards

What is priority inversion?

a high-priority task gets delayed by a lower-priority task holding a needed shared resource. soln is priority inheritance
Ex:

  • Low-priority task holds mutex

  • High-priority task blocks on mutex

  • Medium-priority task preempts low

66
New cards

What is a race condition?

a bug where the outcome of a program depends on the unpredictable timing of multiple threads accessing a shared resource

67
New cards

Race condition exmaple.

Bank transaction, when two threads access the same account. Account has $100. Thread 1 withdraws $50. Thread 2 withdraws $100 and intervenes due to timing, reads the original balance before Thread 1 updates it. Thread 1 writes $50 to the balance. Thread 2 overwrites $0 to the balance. Final balance ends in $0, but balance should be -$50.

68
New cards

How to fix race condition?

Use a mutex, ensuring ONLY one thread can access a shared resource during the critical section.

69
New cards

What is a deadlock?

When tasks are permanently stuck waiting on each other, none can continue. Occurs when all four Coffman conditions are met: mutual exclusion, hold and wait, no preemption, and circular wait.

70
New cards

Deadlock Example

Task A holds Mutex 1 → waiting for Mutex 2

Task B holds Mutex 2 → waiting for Mutex 1

71
New cards

How to prevent deadlock?

Break ANY ONE condition:

  • Enforce mutex order (break circular wait)

  • Don’t hold multiple locks (break hold & wait)

  • Use timeouts (break no preemption logically)

  • Reduce shared resources

72
New cards

What is an atomic operation?

An operation that completes fully without being interrupted.

73
New cards

When are atomic operations used?

Mutex is too slow, as it involves the scheduler and a possible context switch.
Use for small critical sections, such as a simple counter.
Atomics work because there is no blocking, it executes immediately, and interrupts are disabled briefly (ISR safe, ISR cannot run in the middle of an atomic operation).

74
New cards

Fixed Priority Scheduling

a CPU scheduling method where each task gets a static, unchanging priority; the scheduler always runs the highest-priority ready task, preempting lower-priority ones if a higher-priority task arrives

75
New cards

What version of C++ and why?

I use C++17 because it provides modern language features that improve safety and performance.
Favorite feature:
Guaranteed copy elision, it removes unnecessary object copies, improving performance without changing code

76
New cards

Why use static in embedded?

Preserve state of variables between function calls
Another files cannot access static global variables

77
New cards

Semaphore vs Mutex

Mutexes protect shared data; semaphores signal events.

78
New cards

importance of modern C++

high performance, low-level control, and strong type safety

79
New cards

Array

a data structure that stores elements of the same type sequentially and is contiguous in memory