Electronic Load  1.0
Programmable Constant Current Sink
Functions | Variables
ftest.c File Reference

Contains Factory Test Routines. More...

Include dependency graph for ftest.c:

Functions

static const char * Byte2bin (uint8_t byte, char str[9])
 Converts a Byte into a binary String. More...
 
bool FTest (void)
 Performs a simple Factory Test. More...
 
static bool FTestSupply (void)
 Test Supply Voltages. More...
 
static bool FTestWalkingOne (void)
 Short Circuit Test #2. More...
 
static bool FTestWalkingZero ()
 Short Circuit Test #1. More...
 
static void PrintError ()
 Prints an Error Message for conflicting Pins. More...
 
static void PrintPass (bool pass)
 Prints PASS or FAIL. More...
 

Variables

static uint8_t bit
 The Pin of port currently under test. This is a bit mask. More...
 
static uint8_t port
 The Port currently under test. More...
 
static const ftestPortsStruct ports []
 Ports to test. More...
 
static uint8_t testPort
 The Port tested against current port. More...
 
static uint8_t tppin
 The Read-Value of testPort PIN value. More...
 
static uint8_t tpport
 The Read-Value of testPort PORT value. More...
 
static uint8_t tptestMask
 The Test Mask of testPort. More...
 

Detailed Description

Contains Factory Test Routines.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Function Documentation

◆ Byte2bin()

static const char* Byte2bin ( uint8_t  byte,
char  str[9] 
)
static

Converts a Byte into a binary String.

Parameters
byteThe byte
strA String capable of holding at least the 9 characters representing the binary value
Returns
A pointer to a string
Note
This function is not reentrant! The string must be used before the next call since its address is static! Multiple arguments in a single printf will not work! Split them into several printfs and do not call this function from ISRs!
Here is the caller graph for this function:

◆ PrintError()

static void PrintError ( )
static

Prints an Error Message for conflicting Pins.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrintPass()

static void PrintPass ( bool  pass)
static

Prints PASS or FAIL.

Parameters
passTrue if passed
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FTestWalkingZero()

static bool FTestWalkingZero ( )
inlinestatic

Short Circuit Test #1.

All pins included in the testMask[] are set to 1. A single "0" is shifted through all pins, the pin-registers are read to verify its presence exactly on this position.

Returns
True on test pass, False on fail
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FTestWalkingOne()

static bool FTestWalkingOne ( void  )
inlinestatic

Short Circuit Test #2.

All pins included in the testMask[] are set to 0. A single "1" is shiftet through all pins, the pin-registers are read to verify its presence exactly on this position.

Returns
True on test pass, False on fail
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FTestSupply()

static bool FTestSupply ( void  )
inlinestatic

Test Supply Voltages.

Note
The calibration procedure has to be done first to get accurate results!
Returns
True on test pass, False on fail
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FTest()

bool FTest ( void  )

Performs a simple Factory Test.

This routine tries to test everything that can be tested without user intervention. It cannot detect all possible error conditions but will detect a lot of possible short circuits and other errors and can give valuable hints to the test personal.
This is done by performing a "Walking Zero" and a "Walking One" test i.e. all pins are set to 1 (or 0) and a single 0 (or 1) walks through all pins. As long only the currently tested pin is 0, everything is o.k., if another pin goes to 0, you have a short between these two pins. If a pin always stays at a fixed level, you have a short to VCC or GND.
A test mask defines which pins have to be tested. Bits set to 0 will not be touched and not be tested. Bits set to 1 will be programmed as output and tested against all other 1-pins and the supply.
A few rules have to be obeyed for the factory test to work:

  • All special function pins must be set to normal port I/O. Disable all timer outputs, SPIs, USARTS etc. except the interface to the host.
  • Some devices have a DIDR (digital input disable). Do not forget to enable digital inputs.
  • The host interface pins must be set to 0 and cannot be tested. But they are o.k. if the device is able to communicate with the host, anyway.
  • Lines with Chip Select functions should be left as output with Chip Select set to inactive but set to 0 in the test mask. So these pins will not be touched and the chips remain disabled throughout the test and do not interfere with the test sequence.
  • All lines to other chips that are disabled can be set to 1 if the connected chip leaves it tri state when disabled, even if they are input lines normally.

Since interrupts are disabled in the progress of this function and DDRs are modified, the calling routine should perform a watchdog reset to restart the device.
Do not try to restore previous state and continue normal operation, you will most likely forget something and there is nothing bad in willingly performing a reset...

Returns
True if no error detected, False if test fails
Here is the call graph for this function:

Variable Documentation

◆ ports

const ftestPortsStruct ports[]
static
Initial value:
=
{
{
&PORTA,&PINA,&DDRA,0b11111111
},
{
&PORTB,&PINB,&DDRB,0b10111111
},
{
&PORTC,&PINC,&DDRC,0b11111111
},
{
&PORTD,&PIND,&DDRD,0b11100100
},
}

Ports to test.

You must specify every port in your system in ascending order (even if it has not to be tested) and every bit that is set will be included in the test.
Only pins configured as output can be tested!

◆ port

uint8_t port
static

The Port currently under test.

◆ bit

uint8_t bit
static

The Pin of port currently under test. This is a bit mask.

◆ testPort

uint8_t testPort
static

The Port tested against current port.

◆ tpport

uint8_t tpport
static

The Read-Value of testPort PORT value.

◆ tppin

uint8_t tppin
static

The Read-Value of testPort PIN value.

◆ tptestMask

uint8_t tptestMask
static

The Test Mask of testPort.