os/kernelhwsrv/kerneltest/e32test/device/t_prom.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\device\t_prom.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32test.h>
sl@0
    19
#include <e32twin.h>
sl@0
    20
#include <e32hal.h>
sl@0
    21
#include <d32prom.h>
sl@0
    22
sl@0
    23
GLDEF_D RDevE2Prom prom;
sl@0
    24
GLDEF_D RTest test(_L("E2PROM tests"));
sl@0
    25
sl@0
    26
#if !defined(__WINS__)
sl@0
    27
LOCAL_C TInt CheckProm(TInt aVal)
sl@0
    28
//
sl@0
    29
// Write aVal to every location in prom and verify...
sl@0
    30
//
sl@0
    31
    {
sl@0
    32
sl@0
    33
    TBuf16<16> buf;
sl@0
    34
sl@0
    35
    test(prom.WriteAll(aVal)==KErrNone);
sl@0
    36
    test(prom.ReadData(buf)==KErrNone);
sl@0
    37
sl@0
    38
    TInt len;
sl@0
    39
sl@0
    40
    for(len=0;len<16;len++)
sl@0
    41
        test(buf[len]==aVal);
sl@0
    42
sl@0
    43
    return(KErrNone);
sl@0
    44
    }
sl@0
    45
#endif
sl@0
    46
sl@0
    47
GLDEF_C TInt E32Main()
sl@0
    48
//
sl@0
    49
// Test E2 PROM handling.
sl@0
    50
//
sl@0
    51
    {
sl@0
    52
	test.Title();
sl@0
    53
#if defined(__WINS__)
sl@0
    54
	test.Start(_L("This test is valid under EPOC platforms only"));
sl@0
    55
	test.End();
sl@0
    56
	test.Close();
sl@0
    57
	return(KErrNone);
sl@0
    58
#else
sl@0
    59
sl@0
    60
    test.Start(_L("Loading E2PROM LDD"));
sl@0
    61
	TInt r=User::LoadLogicalDevice(_L("E2PROM"));
sl@0
    62
    test(r==KErrNone || r==KErrAlreadyExists);
sl@0
    63
    test.Next(_L("Opening device driver"));
sl@0
    64
	test(prom.Open()==KErrNone);
sl@0
    65
	test.Next(_L("Copying current contents of PROM"));
sl@0
    66
	TInt currentProtectValue=prom.ProtectRead();
sl@0
    67
	TBuf16<16> currentContents;
sl@0
    68
sl@0
    69
/*  Random hacky code */
sl@0
    70
/*
sl@0
    71
    TBuf<0x100> buf;
sl@0
    72
    RProcess().CommandLine(buf);
sl@0
    73
    TLex lex(buf);
sl@0
    74
    TUint val;
sl@0
    75
    if (buf==KNullDesC)
sl@0
    76
        val=0;
sl@0
    77
    else
sl@0
    78
        {
sl@0
    79
        TInt r;
sl@0
    80
        r=lex.Val(val);
sl@0
    81
        test(r==KErrNone); 
sl@0
    82
        test.Printf(_L("Setting to value %08x"), val);
sl@0
    83
        }
sl@0
    84
    currentContents.SetLength(16);
sl@0
    85
    Mem::FillZ((TUint8 *)currentContents.Ptr(), 32);
sl@0
    86
    test(prom.ReadData(currentContents)==KErrNone);
sl@0
    87
    currentContents[4]=val;
sl@0
    88
    TInt i;
sl@0
    89
    TUint8 s=0;
sl@0
    90
    for (i=1; i<32; i++)
sl@0
    91
        {
sl@0
    92
        s^=((TUint8*)currentContents.Ptr())[i];
sl@0
    93
        }
sl@0
    94
    s^=0x42;
sl@0
    95
    ((TUint8*)currentContents.Ptr())[0]=s;
sl@0
    96
    test(prom.WriteData(currentContents)==KErrNone);
sl@0
    97
    test.Next(_L("Reading back"));
sl@0
    98
    test(prom.ReadData(currentContents)==KErrNone);
sl@0
    99
    test.Next(_L("Check checksum"));
sl@0
   100
    s=0;
sl@0
   101
    for (i=0; i<32; i++)
sl@0
   102
        {
sl@0
   103
        s^=((TUint8 *)currentContents.Ptr())[i];
sl@0
   104
        }
sl@0
   105
    test.Printf(_L("checksum=%08x"), s);
sl@0
   106
sl@0
   107
    User::FreeLogicalDevice(_L("E2PROM"));
sl@0
   108
    test.End();
sl@0
   109
    return KErrNone;
sl@0
   110
    }
sl@0
   111
*/
sl@0
   112
                                               
sl@0
   113
	test(prom.ReadData(currentContents)==KErrNone);
sl@0
   114
sl@0
   115
sl@0
   116
		
sl@0
   117
    TBuf16<16> buf1;
sl@0
   118
    TBuf16<16> buf2;
sl@0
   119
sl@0
   120
	test.Next(_L("Clearing protect register"));
sl@0
   121
sl@0
   122
    test(prom.ProtectClear()==KErrNone);
sl@0
   123
    test(prom.ProtectRead()==63);
sl@0
   124
sl@0
   125
    test.Next(_L("Writing all"));
sl@0
   126
sl@0
   127
    test(CheckProm(0)==KErrNone);
sl@0
   128
    test(CheckProm(0x0008)==KErrNone);
sl@0
   129
    test(CheckProm(0x0080)==KErrNone);
sl@0
   130
    test(CheckProm(0x0800)==KErrNone);
sl@0
   131
    test(CheckProm(0x8000)==KErrNone);
sl@0
   132
    test(CheckProm(0xffff)==KErrNone);
sl@0
   133
    test(CheckProm(0xf0f0)==KErrNone);
sl@0
   134
    test(CheckProm(0xf00f)==KErrNone);
sl@0
   135
sl@0
   136
    test.Next(_L("Writing data"));
sl@0
   137
sl@0
   138
    TInt len;
sl@0
   139
sl@0
   140
    buf1.SetLength(16);
sl@0
   141
sl@0
   142
    for(len=0;len<16;len++)
sl@0
   143
        buf1[len]=(TInt16)len;
sl@0
   144
sl@0
   145
    test(prom.WriteData(buf1)==KErrNone);
sl@0
   146
    test.Next(_L("Reading and verifying"));
sl@0
   147
    test(prom.ReadData(buf2)==KErrNone);
sl@0
   148
    test(buf1==buf2);
sl@0
   149
sl@0
   150
	test.Next(_L("Testing protection"));
sl@0
   151
	test(prom.ProtectSet(6)==KErrNone);
sl@0
   152
	test(prom.ProtectRead()==6);
sl@0
   153
	test(prom.WriteAll(0)==KErrNone);
sl@0
   154
	test(prom.ReadData(buf2)==KErrNone);
sl@0
   155
	test(buf1==buf2);
sl@0
   156
	
sl@0
   157
	for(len=0;len<16;len++)
sl@0
   158
		buf1[len]=(TInt16)(len+0x8570);
sl@0
   159
sl@0
   160
	test(prom.WriteData(buf1)==KErrNone);
sl@0
   161
	test(prom.ReadData(buf2)==KErrNone);
sl@0
   162
	test(buf1!=buf2);
sl@0
   163
	
sl@0
   164
	for(len=6;len<16;len++)
sl@0
   165
		buf1[len]=(TInt16)len;
sl@0
   166
sl@0
   167
	test(buf1==buf2);
sl@0
   168
	test.Next(_L("Writing back original contents"));
sl@0
   169
	test(prom.ProtectClear()==KErrNone);
sl@0
   170
	test(prom.WriteData(currentContents)==KErrNone);
sl@0
   171
	test(prom.ProtectSet(currentProtectValue)==KErrNone);
sl@0
   172
    prom.Close();
sl@0
   173
sl@0
   174
    test.End();
sl@0
   175
sl@0
   176
	return(KErrNone);
sl@0
   177
#endif
sl@0
   178
    }
sl@0
   179