pic24_util.c File Reference

#include "pic24_all.h"
#include <stdio.h>

Go to the source code of this file.

Defines

#define u16_INTTREGlast   BITS2WORD(INTTREGBITS_last)

Functions

void _ISR _DefaultInterrupt (void)
void reportError (const char *sz_errorMessage)
uint32 readProgramMemory (uint32 u32_address)
void checkDeviceAndRevision (void)
void checkOscOption (void)
void printResetCause (void)
void configPinsForLowPower (void)
void configBasic (const char *sz_helloMsg)
uint32 roundFloatToUint32 (float f_x)
uint16 roundFloatToUint16 (float f_x)

Variables

static _PERSISTENT const char * sz_lastError
_PERSISTENT char * sz_lastTimeoutError
static _PERSISTENT INTTREGBITS INTTREGBITS_last

Heartbeat

These routines provide heartbeat support by blinking a LED on a regular basis. See doHeartbeat() for more information.

Todo:
Doxygen doesn't show this grouping or the functions in this group.


uint32 u32_heartbeatCount
static uint32 u32_heartbeatMax
void configHeartbeat (void)
void doHeartbeat (void)
void toggleHeartbeat (void)


Detailed Description

This file contains implmentations for functions prototyped in pic24_util.h.

Definition in file pic24_util.c.


Define Documentation

#define u16_INTTREGlast   BITS2WORD(INTTREGBITS_last)

Make the INTTREGBITS_last also accessible as a word. This is like uint16 u16_INTTREGlast except that INTTREGBITS_last and u16_INTTREGlast refer to the same data.

Definition at line 136 of file pic24_util.c.


Function Documentation

void _ISR _DefaultInterrupt ( void   ) 

Provide a default interrupt handler which records what interrupt was not handled then resets the chip. Typically, a call to printResetCause during chip startup will then print the error.

Definition at line 146 of file pic24_util.c.

void checkDeviceAndRevision ( void   ) 

Determines the device and revision of the PIC this program is executing on. This information is then output via the default UART. A warning message is issued if this program was not compiled for the chip it is running on.

Definition at line 192 of file pic24_util.c.

void checkOscOption ( void   ) 

Reports the oscillator currently in use to the default serial port.

Definition at line 267 of file pic24_util.c.

void configBasic ( const char *  sz_helloMsg  ) 

Perform basic chip configuration:

  • Configure the heartbeat
  • Configure the clock
  • Configure UART1
  • Determine and print the cause of reset
  • Print a hello message.

Parameters:
sz_helloMsg Hello message to print.

Definition at line 493 of file pic24_util.c.

void configHeartbeat ( void   ) 

Configures a GPIO pin for use with the heartbeat and sets up the heartbeat counter.

See also:
doHeartbeat

Definition at line 78 of file pic24_util.c.

void configPinsForLowPower ( void   ) 

This function puts the PIC24 in low-power mode by:

  • Configuring all digital I/O pins as inputs
  • Configuring all analog I/O pins shared with digital I/O pins to be digital only
  • Enables pullups on all pins not used by the oscillator.

WARNING: if pullups are enabled on pins used by the oscillator, the clock typically stops running. Currently, this code works for demo purposes with the FRC oscillator when used in the reset.c program. It *should* also work with primary and secondary oscillators, using conditional compiles in the code.

Definition at line 479 of file pic24_util.c.

void doHeartbeat ( void   ) 

This heartbeat function should be called repeatedly in any sort of blocking wait loop. It will periodically toggle an LED after u32_heartbeatMax increments.

Definition at line 94 of file pic24_util.c.

void printResetCause ( void   ) 

Determines and prints the cause of a CPU reset. This should be called when the chip first starts up. For an example, see the configBasic function.

Definition at line 314 of file pic24_util.c.

uint32 readProgramMemory ( uint32  u32_address  ) 

Reads a 24-bit program memory word at the given address.

Parameters:
u32_address Address of program memory to read.
Returns:
The 24-bit program memory word at u32_address. The upper 8 bits are 0.

Definition at line 180 of file pic24_util.c.

void reportError ( const char *  sz_errorMessage  ) 

Report a critical error by recording a message in sz_lastError then resetting the chip, assuming hat printResetCause will be called during chip initialization.

Parameters:
sz_errorMessage Error message to report.
See also:
REPORT_ERROR

Definition at line 167 of file pic24_util.c.

uint16 roundFloatToUint16 ( float  f_x  ) 

Round a floating-point number to the nearest integer.

Parameters:
f_x Floating-point value to round
Returns:
The nearest uint32 to f_x.

Definition at line 515 of file pic24_util.c.

uint32 roundFloatToUint32 ( float  f_x  ) 

Round a floating-point number to the nearest integer.

Parameters:
f_x Floating-point value to round
Returns:
The nearest uint32 to f_x.

Definition at line 506 of file pic24_util.c.

void toggleHeartbeat ( void   ) 

A function which toggles the hearbeat LED.

See also:
doHeartbeat

Definition at line 106 of file pic24_util.c.


Variable Documentation

_PERSISTENT INTTREGBITS INTTREGBITS_last [static]

Store a copy of the INTTREG register as a bitfield. This is not defined for the PIC24F, so work around with an #ifdef. This is _PERSISTENT so that it survives the resets which occurs immeidately after the default interrupt handler _DefaultInterrupt copies INTTREG to this variable.

Definition at line 130 of file pic24_util.c.

_PERSISTENT const char* sz_lastError [static]

Persistent storage for an error message, typically set by reportError and reported at reset by printResetCause.

Definition at line 116 of file pic24_util.c.

_PERSISTENT char* sz_lastTimeoutError

Persistent storage for a timeout error, to be reported if a watchdog reset occurs.

Definition at line 120 of file pic24_util.c.

The current heartbeat count. When this value reaches u32_heartbeatMax, the heatbeat LED is toggled by doHeartbeat().

See also:
doHeartbeat

Definition at line 67 of file pic24_util.c.

When u32_heartbeatCount reaches this maximum, the heatbeat LED is toggled by doHeartbeat().

Definition at line 71 of file pic24_util.c.


Generated on Mon Oct 18 07:40:48 2010 for Python-on-a-chip by  doxygen 1.5.9