Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (7.975 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 <chprintf.h>
24
#include <string.h>
25

    
26
aos_utresult_t utAlldPcal6524Func(BaseSequentialStream* stream, aos_unittest_t *ut)
27
{
28
  aosDbgCheck((ut->data != NULL) &&
29
              (((ut_pcal6524data_t*)ut->data)->pcal6524d != NULL));
30

    
31
  // local variables
32
  aos_utresult_t result = {0, 0};
33
  uint32_t status;
34
  uint8_t buffer[24];
35
  memset(buffer, 0xAA, sizeof(buffer));
36

    
37
// This test is currently not supported. See PCAL6524 driver implementation for further information.
38
//  chprintf(stream, "reading device ID...\n");
39
//  status = pcal6524_lld_read_id(((ut_pcal6524data_t*)ut->data)->pcal6524d, buffer, ((ut_pcal6524data_t*)ut->data)->timeout);
40
//  chprintf(stream, "\t\traw: 0x%02X 0x%02X 0x%02X\n", buffer[0], buffer[1], buffer[2]);
41
//  chprintf(stream, "\t\tname:     0x%03X\n", ((pcal6524_lld_deviceid_t*)buffer)->name);
42
//  chprintf(stream, "\t\tpart:     0x%03X\n", ((pcal6524_lld_deviceid_t*)buffer)->part);
43
//  chprintf(stream, "\t\trevision: 0x%01X\n", ((pcal6524_lld_deviceid_t*)buffer)->revision);
44
//  if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
45
//    aosUtPassed(stream, &result);
46
//  } else {
47
//    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
48
//  }
49

    
50
  chprintf(stream, "reading register...\n");
51
  status = pcal6524_lld_read_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, buffer, ((ut_pcal6524data_t*)ut->data)->timeout);
52
  chprintf(stream, "\t\tdebounce count: %u\n", buffer[0]);
53
  if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
54
    aosUtPassed(stream, &result);
55
  } else {
56
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
57
  }
58

    
59
  chprintf(stream, "writing register...\n");
60
  buffer[3] = 0xFF;
61
  status = pcal6524_lld_write_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, buffer[3], ((ut_pcal6524data_t*)ut->data)->timeout);
62
  status |= pcal6524_lld_read_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, &buffer[4], ((ut_pcal6524data_t*)ut->data)->timeout);
63
  status |= pcal6524_lld_write_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, buffer[0], ((ut_pcal6524data_t*)ut->data)->timeout);
64
  status |= pcal6524_lld_read_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, &buffer[1], ((ut_pcal6524data_t*)ut->data)->timeout);
65
  if (((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) &&
66
      ((buffer[1] == buffer[0]) && (buffer[4] == buffer[3]))) {
67
    aosUtPassed(stream, &result);
68
  } else {
69
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
70
  }
71

    
72
  chprintf(stream, "reading group...\n");
73
  status = pcal6524_lld_read_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, buffer, ((ut_pcal6524data_t*)ut->data)->timeout);
74
  chprintf(stream, "\t\toutput drive strength: 0x%04X 0x%04X 0x%04X\n",
75
           (((uint16_t)buffer[0]) << 8) | buffer[1],
76
           (((uint16_t)buffer[2]) << 8) | buffer[3],
77
           (((uint16_t)buffer[4]) << 8) | buffer[5]);
78
  if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
79
    aosUtPassed(stream, &result);
80
  } else {
81
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
82
  }
83

    
84
  chprintf(stream, "writing group...\n");
85
  memset(&buffer[6], PCAL6524_LL_OUTPUTDRIVESTRENGTH_0_25, 6);
86
  status = pcal6524_lld_write_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[6], ((ut_pcal6524data_t*)ut->data)->timeout);
87
  status |= pcal6524_lld_read_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[12], ((ut_pcal6524data_t*)ut->data)->timeout);
88
  status |= pcal6524_lld_write_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[0], ((ut_pcal6524data_t*)ut->data)->timeout);
89
  status |= pcal6524_lld_read_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[18], ((ut_pcal6524data_t*)ut->data)->timeout);
90
  if (((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) &&
91
      ((memcmp(&buffer[12], &buffer[6], 6) == 0) && (memcmp(&buffer[18], &buffer[0], 6) == 0))) {
92
    aosUtPassed(stream, &result);
93
  } else {
94
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
95
  }
96

    
97
  chprintf(stream, "reading continuously...\n");
98
  // read the following registers continously (24 bytes):
99
  // 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
100
  status = pcal6524_lld_read_continuous(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, buffer, 24, ((ut_pcal6524data_t*)ut->data)->timeout);
101
  chprintf(stream, "\t\toutput: 0x%02X 0x%02X 0x%02X\n", buffer[0], buffer[1], buffer[2]);
102
  chprintf(stream, "\t\tpolarity inversion: 0x%02X 0x%02X 0x%02X\n", buffer[3], buffer[4], buffer[5]);
103
  chprintf(stream, "\t\tconfiguration: 0x%02X 0x%02X 0x%02X\n", buffer[6], buffer[7], buffer[8]);
104
  chprintf(stream, "\t\toutput drive strength: 0x%04X 0x%04X 0x%04X\n",
105
           (((uint16_t)buffer[9]) << 8) | buffer[10],
106
           (((uint16_t)buffer[11]) << 8) | buffer[12],
107
           (((uint16_t)buffer[13]) << 8) | buffer[14]);
108
  chprintf(stream, "\t\tinput latch: 0x%02X 0x%02X 0x%02X\n", buffer[15], buffer[16], buffer[17]);
109
  chprintf(stream, "\t\tpupd enable: 0x%02X 0x%02X 0x%02X\n", buffer[18], buffer[19], buffer[20]);
110
  chprintf(stream, "\t\tpupd selection: 0x%02X 0x%02X 0x%02X\n", buffer[21], buffer[22], buffer[23]);
111
  if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
112
    aosUtPassed(stream, &result);
113
  } else {
114
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
115
  }
116

    
117
  chprintf(stream, "writing continuously...\n");
118
  {
119
    uint8_t writebuffer[24];
120
    uint8_t readbuffer[2][24];
121
    // copy the read configuration but set the output drive strength to factor 0.25
122
    memcpy(writebuffer, buffer, sizeof(buffer));
123
    memset(&writebuffer[9], PCAL6524_LL_OUTPUTDRIVESTRENGTH_0_25, 6);
124
    status = pcal6524_lld_write_continuous(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, writebuffer, 24, ((ut_pcal6524data_t*)ut->data)->timeout);
125
    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);
126
    status |= pcal6524_lld_write_continuous(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, buffer, 24, ((ut_pcal6524data_t*)ut->data)->timeout);
127
    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);
128
    if (((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) &&
129
        ((memcmp(writebuffer, readbuffer[0], 24) == 0) && (memcmp(buffer, readbuffer[1], 24) == 0))) {
130
      aosUtPassed(stream, &result);
131
    } else {
132
      aosUtFailedMsg(stream, &result, "0x%08X\n", status);
133
    }
134
  }
135

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

    
138
  return result;
139
}
140

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