class::hal::Core

class hal::Core
  : public hal::Periph< core_info_t, core_attr_t, CoreAttributes, CORE_IOC_IDENT_CHAR >

This is the Core class. It is used to access core MCU information such as clock speed and to adjust interrupt priorities.

Here is an example of how to read the MCU serial number:

#include <sapi/hal.hpp>
#include <cstdio>

int main(int argc, char * argv[]){
   int i;
   Core core(0);
   core_attr_t attr;
   core.open();
   core.get_attr(&attr);
   printf("Serial Number is:");
   for(i=3; i >= 0; i--){
      printf("%X", attr.serial_number[i]);
   }
   printf("\n");
   core.close(); //core is never "powered-down" but this frees the file descriptor
}

Summary

Core(

port_t port
)

int get_mcu_board_config(

mcu_board_config_t & config
)

void invoke_bootloader()

void reset()

int set_clock_divide(

u32 value
)

int set_pin_function(

const core_pinfunc_t & req
)

int set_pin_function(

const arg::McuPin & pin,
enum func func,
const arg::Port & port
)

enum func

Members

Core(

port_t port
)

Contructs a new core object using the specified port.

Parameters

  • port The core port (zero for all single core devices)

int get_mcu_board_config(

mcu_board_config_t & config
)

Loads the MCU board configuration data provided by the board support package.

Parameters

  • config A reference to the destination data

Returns

Zero on success


void invoke_bootloader()

Invokes the device’s bootloader. If no bootloader is available, a normal reset will occur.


void reset()

Resets the device.


int set_clock_divide(

u32 value
)

Sets the core CPU clock divider.

Parameters

  • value The amount to divide the clock by

Returns

Zero on success

This method will change the CPU clock speed (if supported). If the native clock speed is 120MHz the following code will make it 60MHz

Core core(0);
core.open();
core.set_clock_divide(2); //set to 60MHz
core.set_clock_divide(1); //restore to 120MHz
core.close();

int set_pin_function(

const core_pinfunc_t & req
)

Changes pin functionality using a core_pinfunc_t structure.


int set_pin_function(

const arg::McuPin & pin,
enum func func,
const arg::Port & port
)

Changes pin function.

Parameters

  • port The PIO port

  • pin The PIO pin number

  • func The function (e.g. Core::UART)

  • func_port The functional port (e.g. 0 for UART0)

Returns

Zero on success

This can be used if the default pinassign values are not adequate for your application.


enum func
  • CORE Core Functionality
  • ADC Analog to Digital Converter
  • DAC Digital to Analog Converter
  • UART UART
  • SPI SPI
  • USB USB
  • CAN CAN
  • ENET ENET
  • I2C I2C
  • I2S I2S
  • MEM External memory interface
  • RTC RTC
  • CEC Consumer Electronic Control (Part of HDMI)
  • QEI Quadrature Encoder Interface
  • PWM PWM
  • PIO GPIO
  • TMR Timer (output compare and input capture)
  • EINT External interrupts
  • WDT Watch dog timer
  • BOD Brown out detection
  • DMA Direct Memory Access
  • JTAG JTAG
  • RESET Reset
  • CLKOUT Clockout
  • LCD LCD
  • LCD1 LCD
  • LCD2 LCD
  • LCD3 LCD
  • EMC External Memory Controller
  • MCI Multimedia Card Interface
  • SSP SSP
  • MCPWM Motor Control PWM
  • NMI Non-maskable Interrupt
  • TRACE Trace data

Core functional types


X

Thanks for Coming!

Subscribe to news and updates