libpic170x  0.2
Ease of use library for PIC16(L)1705/1709 chips
Macros | Functions | Variables
freq.h File Reference

Global timing definitions used for timing critical library components. More...

#include <stdint.h>
#include <stdbool.h>
#include <string.h>
Include dependency graph for freq.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define OSCCON_BITS   0
 OSCCON bits that can derived from the set _XTAL_FREQ that the OSCCON register can be initailized with.
 
#define __LIBPIC170X_DEVICE_NAME   "PIC16LF1705"
 Processor name internally used by libpic170x_check_library_build_arguments()
 

Functions

static bool libpic170x_check_library_build_arguments ()
 Verify matching configuration parameters between main project and static library. More...
 

Variables

const uint32_t __LIBPIC170X_BUILT_XTAL_FREQ
 Stores the _XTAL_FREQ that was used while building the static libpic170x library.
 
const char * __LIBPIC170X_BUILT_DEVICE_NAME
 Stores the device name (as string) used to build the static libpic170x library.
 

Detailed Description

Global timing definitions used for timing critical library components.

This file defines important timing preprocessor variables that are used throughout all library components. All libraries are based on the assumption that the processor clock frequency the PIC microcontroller operates on does not change over time. It should be set once at the start of the program never be touched again.

The frequencies are set via the OSCCON bits of the PIC microcontroller. freq.h derivs the correct OSCCON-bits from the defined _XTAL_FREQ. _XTAL_FREQ must therefore as a compiler definition from the outside. By default, it is set to 8000000 in Makefile but any of the following _XTAL_FREQ frequencies are supported by libpic170x:

32000000
16000000
8000000
4000000
2000000
1000000
500000

Lower frequencies are not supported because the core library timer0 would become unusable due to huge counter steps.

OSCCAL_BITS

One of the core-featues of freq.h is that is exposes the OSCCON bits that the main application should set through the preprocessor definition OSCCON_BITS. Before using any other library functions this OSCCON bits should be set by the application using libpic170x.

Example:

#include <freq.h>
#include <xc.h>
int main() {
OSCCON = OSCCON_BITS;
// ...
}

Definition in file freq.h.

Function Documentation

◆ libpic170x_check_library_build_arguments()

static bool libpic170x_check_library_build_arguments ( )
static

Verify matching configuration parameters between main project and static library.

This functions allows one to check if the arguments used while building the library are matching the build arguments for the current project. Generally, this should not be required, but it can be handy for sanity checks. It is advisable to include a call to this function at the start of any program and exit to a safe fail-state when the function returns false since the behavior of libpic170x is undefined if the build arguments do not match between a libpic170x static library and main application.

Returns
Returns true in case the build arguments are matching. If the function returns false, exit to a safe fail-state.

Definition at line 167 of file freq.h.