LevelMeter-Display  2.0
An ultrasonic Level Meter for Stormwater Cisterns
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...
 
void FTest485 (void)
 Performs a Factory Test of the RS485-Lines. More...
 
uint8_t FTest485GetConnects (void)
 Returns Connections between the two RS485 Interfaces. More...
 
static bool FTestSupply (void)
 Test Supply Voltages. More...
 
static bool FTestSWUnreg ()
 Tests the Switched Unreg Node. More...
 
static void FTestToggleSignal ()
 Toggles the Optocoupler Outputs. More...
 
static bool FTestWalkingOne (void)
 Short Circuit Test #2. More...
 
static bool FTestWalkingZero ()
 Short Circuit Test #1. More...
 
bool GetRxD0 (void)
 Get RxD0-Pin Value. More...
 
bool GetRxD1 (void)
 Get RxD1-Pin Value. More...
 
static void PrintError ()
 Prints an Error Message for conflicting Pins. More...
 
static void PrintPass (bool pass)
 Prints PASS or FAIL. More...
 
void SetTxD0 (bool level)
 Sets the state of TxD0. More...
 
void SetTxD1 (bool level)
 Sets the state of TxD1. More...
 
static void WaitKeyBlinking (void)
 Waits for the Key to be pressed and released. 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 the 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!

Referenced by PrintError().

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.
All special function pins must be set to normal port I/O. The testMask basically is a copy of the DDR since only output pins can be tested. Take care of pins that must keep their special function during the test (e.g. TxD of the USART that receives the result). This has also to be masked out, as well as pins that would cause disastrous consequences if switched uncontrolled.
First the user is asked to press the pushbutton key. This is to test the key itself. After that, the signal outputs are toggled a few times each. LEDs connected on the test adapter will show the user if that works. The following tests require no user attention. The device will measure its supply voltages and test all output pins against all others so short circuits between output pins or output pin and VCC/GND will most likely be detected.
Since interrupts are disabled in the progress of this function and DDRs are modified, the calling routine should perform a watchdog reset to restore proper operation of the device.
Do not try to restore DDRs and interrupts, you will most likely forget some and there is nothing bad in willingly performing a reset...

Returns
True if no error detected, False if test fails

References delay1s(), FTestSupply(), FTestSWUnreg(), FTestToggleSignal(), FTestWalkingOne(), FTestWalkingZero(), hprintf_P(), LEDBlueOff(), LEDBlueOn(), LEDGreenOff(), LEDGreenOn(), LEDRedOff(), LEDRedOn(), LEDYellowOff(), LEDYellowOn(), SensorPowerOff(), and WaitKeyBlinking().

Referenced by CmdFTest().

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

◆ FTest485()

void FTest485 ( void  )

Performs a Factory Test of the RS485-Lines.

For this test to succeed, all jumpers on X3 have to be in position "485" and a switch has to be in the test adapter that connects sensor RS485 with host RS485.

References delay10ms(), FTest485GetConnects(), LCDPrintLine_P(), and secCnt.

Here is the call graph for this function:

◆ FTest485GetConnects()

uint8_t FTest485GetConnects ( void  )

Returns Connections between the two RS485 Interfaces.

Returns
0 if they are not connected
1 if only TxD0 is connected to RxD1
2 if only TxD1 is connected to RxD0
3 if they are fully connected

References delay50us(), GetRxD0(), GetRxD1(), SetTxD0(), SetTxD1(), Uart0DisableLineDriver(), Uart0EnableLineDriver(), Uart1DisableLineDriver(), and Uart1EnableLineDriver().

Referenced by FTest485().

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
Again the advice for P3: the pin measuring P3 is shared with the JTAG-interface. If JTAG is enabled by its fuse, P3-value will be inaccurate by up to 15% FSR, if a JTAG debugger is connected it is completely unmeasurable! Disable the JTAGEN-fuse or this test will fail!
Returns
True on test pass, False on fail

References ADCData_t::ADC_P3, ADCData_t::ADC_P5, ADCData_t::ADC_Unreg, ADCDataAvg, hprintf_P(), ADCData_t::named, P3FromADC(), P5FromADC(), PrintPass(), and UnregFromADC().

Referenced by FTest().

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

◆ FTestSWUnreg()

static bool FTestSWUnreg ( )
inlinestatic

Tests the Switched Unreg Node.

Returns
true if test passed, false if not

References ADCData_t::ADC_SWUnreg, ADCData_t::ADC_Unreg, ADCData, ADCDataAvg, ADCFLAG_NEWRESULTS, adcFlags, delay1s(), hprintf_P(), ADCData_t::named, PrintPass(), SensorPowerOff(), SensorPowerOn(), SWUnregFromADC(), tickCnt, and UnregFromADC().

Referenced by FTest().

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

◆ FTestToggleSignal()

static void FTestToggleSignal ( )
inlinestatic

Toggles the Optocoupler Outputs.

This is not an automated test. The user has to verify that LEDs connected to the optocouplers will toggle.

References delay50ms(), hprintf_P(), Sig1OFF(), Sig1ON(), Sig2OFF(), and Sig2ON().

Referenced by FTest().

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

References bit, delay50us(), hprintf_P(), ftestPortsStruct::pin, ftestPortsStruct::port, port, ports, PrintError(), PrintPass(), ftestPortsStruct::testMask, testPort, tppin, tpport, and tptestMask.

Referenced by FTest().

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 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

References bit, delay50us(), hprintf_P(), ftestPortsStruct::pin, ftestPortsStruct::port, port, ports, PrintError(), PrintPass(), ftestPortsStruct::testMask, testPort, tppin, tpport, and tptestMask.

Referenced by FTest().

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

◆ GetRxD0()

bool GetRxD0 ( void  )

Get RxD0-Pin Value.

Returns
True if RxD0=1

Referenced by FTest485GetConnects().

Here is the caller graph for this function:

◆ GetRxD1()

bool GetRxD1 ( void  )

Get RxD1-Pin Value.

Returns
True if RxD1=1

Referenced by FTest485GetConnects().

Here is the caller graph for this function:

◆ PrintError()

static void PrintError ( )
static

Prints an Error Message for conflicting Pins.

References bit, Byte2bin(), hprintf_P(), port, testPort, tppin, tpport, and tptestMask.

Referenced by FTestWalkingOne(), and FTestWalkingZero().

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

References hprintf_P().

Referenced by FTestSupply(), FTestSWUnreg(), FTestWalkingOne(), and FTestWalkingZero().

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

◆ SetTxD0()

void SetTxD0 ( bool  level)

Sets the state of TxD0.

Parameters
levelThe desired Output Level

Referenced by FTest485GetConnects().

Here is the caller graph for this function:

◆ SetTxD1()

void SetTxD1 ( bool  level)

Sets the state of TxD1.

Parameters
levelThe desired Output Level

Referenced by FTest485GetConnects().

Here is the caller graph for this function:

◆ WaitKeyBlinking()

static void WaitKeyBlinking ( void  )
static

Waits for the Key to be pressed and released.

The LCD-backlight is blinking until the key is pressed.

References KFLAG_KEYRELEASED, kflags, LCDSetBrightness(), and tickCnt.

Referenced by FTest().

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

Variable Documentation

◆ bit

uint8_t bit
static

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

Referenced by FTestWalkingOne(), FTestWalkingZero(), and PrintError().

◆ port

uint8_t port
static

The Port currently under test.

Referenced by FTestWalkingOne(), FTestWalkingZero(), and PrintError().

◆ ports

const ftestPortsStruct ports[]
static
Initial value:
=
{
{
&PORTA,&PINA,0b11111111
},
{
&PORTB,&PINB,0b11111111
},
{
&PORTC,&PINC,0b11111111
},
{
&PORTD,&PIND,0b11010011
},
{
&PORTE,&PINE,0b11111100
},
{
&PORTF,&PINF,0b00001111
},
{
&PORTG,&PING,0b00011111
},
}

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!

Referenced by FTestWalkingOne(), and FTestWalkingZero().

◆ testPort

uint8_t testPort
static

The Port tested against current port.

Referenced by FTestWalkingOne(), FTestWalkingZero(), and PrintError().

◆ tppin

uint8_t tppin
static

The Read-Value of testPort PIN value.

Referenced by FTestWalkingOne(), FTestWalkingZero(), and PrintError().

◆ tpport

uint8_t tpport
static

The Read-Value of testPort PORT value.

Referenced by FTestWalkingOne(), FTestWalkingZero(), and PrintError().

◆ tptestMask

uint8_t tptestMask
static

The Test Mask of testPort.

Referenced by FTestWalkingOne(), FTestWalkingZero(), and PrintError().