# SFBProcessor Class Reference

Wrapper class implementing the Processor object for access to CPU speed control. More...

`#include <SFBProcessor.h>`

## Public Member Functions
void | setMaxSpeed ()
| Change the CPU clock to its fastest-computing (most power-consuming) available value.
void | setMinSpeed ()
| Change the CPU clock to its most power-conserving (slowest-computing) available value.
u32 | getMHzMin ()
| Return the slowest supported CPU clock speed, in millions of cycles-per-second.
u32 | getCodeMin ()
| Return the slowest supported CPU clock speed, as a 'CPU Speed Code'.
u32 | getMHzMax ()
| Return the fastest supported CPU clock speed, in millions of cycles-per-second.
u32 | getCodeMax ()
| Return the fastest supported CPU clock speed, as a 'CPU Speed Code'.
u32 | getHz ()
| Return the current CPU clock speed in cycles-per-second.
u32 | getMHz ()
| Return the current CPU clock speed in millions of cycles-per-second.
u32 | getCode ()
| Return the current CPU clock speed as a 'CPU Speed Code'.
void | setHz (u32 hz)
| Change the clock speed to hz cycles-per-second, or to the next lower available value, if hz is not an exactly supported value.
void | setMHz (u32 mhz)
| Change the clock speed to mhz million cycles-per-second, or to the next lower available value, if mhz is not an exactly supported value.
void | setCode (u32 code)
| Change the clock speed to that specified by code.

## Detailed Description

Wrapper class implementing the Processor object for access to CPU speed control.

Since:
  0.9.14

## Member Function Documentation

u32 SFBProcessor::getCode | ( |  | ) |

Return the current CPU clock speed as a 'CPU Speed Code'.

Returns:
  From 1 (CSC_12MHZ) to 6 (CSC_72MHZ) by 1's

Examples:
  speed4.cpp.

u32 SFBProcessor::getCodeMax | ( |  | ) | `[inline]`

Return the fastest supported CPU clock speed, as a 'CPU Speed Code'.

Currently the fastest possible speed code is CSC_72MHZ.

Examples:
  speed4.cpp.

u32 SFBProcessor::getCodeMin | ( |  | ) | `[inline]`

Return the slowest supported CPU clock speed, as a 'CPU Speed Code'.

Currently the slowest possible speed code is CSC_12MHZ.

Examples:
  speed4.cpp.

u32 SFBProcessor::getHz | ( |  | ) | `[inline]`

Return the current CPU clock speed in cycles-per-second.

Returns:
  From 12,000,000 to 72,000,000 by 12,000,000's

u32 SFBProcessor::getMHz | ( |  | ) | `[inline]`

Return the current CPU clock speed in millions of cycles-per-second.

Returns:
  From 12 to 72 by 12's

Examples:
  speed2.cpp, speed3.cpp, and speed4.cpp.

u32 SFBProcessor::getMHzMax | ( |  | ) | `[inline]`

Return the fastest supported CPU clock speed, in millions of cycles-per-second.

Currently the fastest possible speed is 72MHz.

u32 SFBProcessor::getMHzMin | ( |  | ) | `[inline]`

Return the slowest supported CPU clock speed, in millions of cycles-per-second.

Currently the slowest possible speed is 12MHz.

void SFBProcessor::setCode | ( | u32 | code | ) |

Change the clock speed to that specified by code.

Higher speed codes (e.g., CSC_72MHZ) compute faster; lower speed codes (e.g., CSC_12MHZ) save power.

Although time-based calls such as millis(), micros(), and delay() are essentially unaffected by processor speed changes, one must be sensitive to the obvious and inescapable fact that at slower speeds computing stuff just takes longer. If you explore with the Profile object, for example, at slower speeds you'll see interrupt overhead, as well as alarm and packet handlers, eating more and more time.

And beyond that, sketch programmers must also be aware of these important less obvious limitations and warnings about changing the CPU speed:

1. It takes some time -- possibly tens of milliseconds -- to change the CPU speed.
2. The maximum baud rate that can be performed reliably declines with the clock speed. While the overall sustainable data rate always depends on particulars of the given sketch, the maximum baud rate that will be negotiated by the core software -- normally SFBAUD500000 -- declines to SFBAUD230400 at CSC_24MHZ, and to SFBAUD115200 at CSC_12MHZ.
3. Peripheral hardware operations may be disrupted during the speed change. For example, inbound and/or outbound serial data may be lost or corrupted, and hardware timers may glitch. Sketch code must be robust to such events when speed changing is contemplated.
4. After a speed change, the hardware peripherals that are managed by the core software --- including TIMER0, the voltage monitoring ADCs, and any UARTs that have been started via SFBSerial::begin() or SFBSerial::begin(u32 baud, bool manual) --- are automatically adjusted. But if a sketch has done any additional hardware configuration, it is the sketch's responsibility to compensate however necessary after a speed change. See getCurrentClockConfiguration() and setClockSpeedChangeCallback().

Blinks:
  E_API_ARGUMENT if code is less that CSC_MIN_MHZ or greater than CSC_MAX_MHZ.

Examples:
  speed4.cpp.

void SFBProcessor::setHz | ( | u32 | hz | ) | `[inline]`

Change the clock speed to hz cycles-per-second, or to the next lower available value, if hz is not an exactly supported value.

Higher speeds compute faster; lower speeds save power. See notes at setCode for implications of speed changes.

Blinks:
  E_API_ARGUMENT if hz is less than 12,000,000 or greater than 72,000,000.

void SFBProcessor::setMaxSpeed | ( |  | ) | `[inline]`

Change the CPU clock to its fastest-computing (most power-consuming) available value.

See also setMinSpeed. See notes at setCode for possible implications of speed changes.

void SFBProcessor::setMHz | ( | u32 | mhz | ) | `[inline]`

Change the clock speed to mhz million cycles-per-second, or to the next lower available value, if mhz is not an exactly supported value.

Higher speeds compute faster; lower speeds save power. See notes at setCode for implications of speed changes.

Blinks:
  E_API_ARGUMENT if mhz is less than 12 or greater than 72.

Examples:
  speed2.cpp, and speed3.cpp.

void SFBProcessor::setMinSpeed | ( |  | ) | `[inline]`

Change the CPU clock to its most power-conserving (slowest-computing) available value.

See also setMaxSpeed. See notes at setCode for possible implications of speed changes.

Examples:
  speed1.cpp.

The documentation for this class was generated from the following files:

- src/include/SFBProcessor.h
- src/components/board/SFBProcessor.cpp