Statistics
| Branch: | Tag: | Revision:

amiro-os / unittests / periphery-lld / src / ut_alld_pcal6524.c @ 3940ba8a

History | View | Annotate | Download (9.38 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  Thomas Schöpping et al.
4

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

    
19
#include <ut_alld_pcal6524.h>
20

    
21
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_PCAL6524)) || defined(__DOXYGEN__)
22

    
23
#include <string.h>
24

    
25
/******************************************************************************/
26
/* LOCAL DEFINITIONS                                                          */
27
/******************************************************************************/
28

    
29
/******************************************************************************/
30
/* EXPORTED VARIABLES                                                         */
31
/******************************************************************************/
32

    
33
/******************************************************************************/
34
/* LOCAL TYPES                                                                */
35
/******************************************************************************/
36

    
37
/******************************************************************************/
38
/* LOCAL VARIABLES                                                            */
39
/******************************************************************************/
40

    
41
/******************************************************************************/
42
/* LOCAL FUNCTIONS                                                            */
43
/******************************************************************************/
44

    
45
/******************************************************************************/
46
/* EXPORTED FUNCTIONS                                                         */
47
/******************************************************************************/
48

    
49
aos_utresult_t utAlldPcal6524Func(BaseSequentialStream* stream, aos_unittest_t *ut)
50
{
51
  aosDbgCheck((ut->data != NULL) &&
52
              (((ut_pcal6524data_t*)ut->data)->pcal6524d != NULL));
53

    
54
  // local variables
55
  aos_utresult_t result = {0, 0};
56
  uint32_t status;
57
  uint8_t buffer[24];
58
  memset(buffer, 0xAA, sizeof(buffer));
59

    
60
// This test is currently not supported. See PCAL6524 driver implementation for further information.
61
//  chprintf(stream, "reading device ID...\n");
62
//  status = pcal6524_lld_read_id(((ut_pcal6524data_t*)ut->data)->pcal6524d, buffer, ((ut_pcal6524data_t*)ut->data)->timeout);
63
//  chprintf(stream, "\t\traw: 0x%02X 0x%02X 0x%02X\n", buffer[0], buffer[1], buffer[2]);
64
//  chprintf(stream, "\t\tname:     0x%03X\n", ((pcal6524_lld_deviceid_t*)buffer)->name);
65
//  chprintf(stream, "\t\tpart:     0x%03X\n", ((pcal6524_lld_deviceid_t*)buffer)->part);
66
//  chprintf(stream, "\t\trevision: 0x%01X\n", ((pcal6524_lld_deviceid_t*)buffer)->revision);
67
//  if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
68
//    aosUtPassed(stream, &result);
69
//  } else {
70
//    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
71
//  }
72

    
73
  chprintf(stream, "reading register...\n");
74
  status = pcal6524_lld_read_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, buffer, ((ut_pcal6524data_t*)ut->data)->timeout);
75
  chprintf(stream, "\t\tdebounce count: %u\n", buffer[0]);
76
  if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
77
    aosUtPassed(stream, &result);
78
  } else {
79
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
80
  }
81

    
82
  chprintf(stream, "writing register...\n");
83
  buffer[3] = 0xFF;
84
  status = pcal6524_lld_write_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, buffer[3], ((ut_pcal6524data_t*)ut->data)->timeout);
85
  status |= pcal6524_lld_read_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, &buffer[4], ((ut_pcal6524data_t*)ut->data)->timeout);
86
  status |= pcal6524_lld_write_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, buffer[0], ((ut_pcal6524data_t*)ut->data)->timeout);
87
  status |= pcal6524_lld_read_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, &buffer[1], ((ut_pcal6524data_t*)ut->data)->timeout);
88
  if (((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) &&
89
      ((buffer[1] == buffer[0]) && (buffer[4] == buffer[3]))) {
90
    aosUtPassed(stream, &result);
91
  } else {
92
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
93
  }
94

    
95
  chprintf(stream, "reading group...\n");
96
  status = pcal6524_lld_read_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, buffer, ((ut_pcal6524data_t*)ut->data)->timeout);
97
  chprintf(stream, "\t\toutput drive strength: 0x%04X 0x%04X 0x%04X\n",
98
           (((uint16_t)buffer[0]) << 8) | buffer[1],
99
           (((uint16_t)buffer[2]) << 8) | buffer[3],
100
           (((uint16_t)buffer[4]) << 8) | buffer[5]);
101
  if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
102
    aosUtPassed(stream, &result);
103
  } else {
104
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
105
  }
106

    
107
  chprintf(stream, "writing group...\n");
108
  memset(&buffer[6], PCAL6524_LL_OUTPUTDRIVESTRENGTH_0_25, 6);
109
  status = pcal6524_lld_write_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[6], ((ut_pcal6524data_t*)ut->data)->timeout);
110
  status |= pcal6524_lld_read_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[12], ((ut_pcal6524data_t*)ut->data)->timeout);
111
  status |= pcal6524_lld_write_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[0], ((ut_pcal6524data_t*)ut->data)->timeout);
112
  status |= pcal6524_lld_read_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[18], ((ut_pcal6524data_t*)ut->data)->timeout);
113
  if (((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) &&
114
      ((memcmp(&buffer[12], &buffer[6], 6) == 0) && (memcmp(&buffer[18], &buffer[0], 6) == 0))) {
115
    aosUtPassed(stream, &result);
116
  } else {
117
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
118
  }
119

    
120
  chprintf(stream, "reading continuously...\n");
121
  // read the following registers continously (24 bytes):
122
  // output 0-3 + polarity inversions 0-3 + configuration 0-3 + output drive strength 0A-2B + input latch 0-3 + pupd enable 0-3 + pupd selection 0-3
123
  status = pcal6524_lld_read_continuous(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, buffer, 24, ((ut_pcal6524data_t*)ut->data)->timeout);
124
  chprintf(stream, "\t\toutput: 0x%02X 0x%02X 0x%02X\n", buffer[0], buffer[1], buffer[2]);
125
  chprintf(stream, "\t\tpolarity inversion: 0x%02X 0x%02X 0x%02X\n", buffer[3], buffer[4], buffer[5]);
126
  chprintf(stream, "\t\tconfiguration: 0x%02X 0x%02X 0x%02X\n", buffer[6], buffer[7], buffer[8]);
127
  chprintf(stream, "\t\toutput drive strength: 0x%04X 0x%04X 0x%04X\n",
128
           (((uint16_t)buffer[9]) << 8) | buffer[10],
129
           (((uint16_t)buffer[11]) << 8) | buffer[12],
130
           (((uint16_t)buffer[13]) << 8) | buffer[14]);
131
  chprintf(stream, "\t\tinput latch: 0x%02X 0x%02X 0x%02X\n", buffer[15], buffer[16], buffer[17]);
132
  chprintf(stream, "\t\tpupd enable: 0x%02X 0x%02X 0x%02X\n", buffer[18], buffer[19], buffer[20]);
133
  chprintf(stream, "\t\tpupd selection: 0x%02X 0x%02X 0x%02X\n", buffer[21], buffer[22], buffer[23]);
134
  if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
135
    aosUtPassed(stream, &result);
136
  } else {
137
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
138
  }
139

    
140
  chprintf(stream, "writing continuously...\n");
141
  {
142
    uint8_t writebuffer[24];
143
    uint8_t readbuffer[2][24];
144
    // copy the read configuration but set the output drive strength to factor 0.25
145
    memcpy(writebuffer, buffer, sizeof(buffer));
146
    memset(&writebuffer[9], PCAL6524_LL_OUTPUTDRIVESTRENGTH_0_25, 6);
147
    status = pcal6524_lld_write_continuous(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, writebuffer, 24, ((ut_pcal6524data_t*)ut->data)->timeout);
148
    status |= pcal6524_lld_read_continuous(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, readbuffer[0], 24, ((ut_pcal6524data_t*)ut->data)->timeout);
149
    status |= pcal6524_lld_write_continuous(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, buffer, 24, ((ut_pcal6524data_t*)ut->data)->timeout);
150
    status |= pcal6524_lld_read_continuous(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, readbuffer[1], 24, ((ut_pcal6524data_t*)ut->data)->timeout);
151
    if (((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) &&
152
        ((memcmp(writebuffer, readbuffer[0], 24) == 0) && (memcmp(buffer, readbuffer[1], 24) == 0))) {
153
      aosUtPassed(stream, &result);
154
    } else {
155
      aosUtFailedMsg(stream, &result, "0x%08X\n", status);
156
    }
157
  }
158

    
159
  aosUtInfoMsg(stream, "driver object memory footprint: %u bytes\n", sizeof(PCAL6524Driver));
160

    
161
  return result;
162
}
163

    
164
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_PCAL6524) */