amiro-os / unittests / periphery-lld / src / ut_alld_PCA9544A_v1.c @ 5668089d
History | View | Annotate | Download (6.509 KB)
1 | e545e620 | Thomas Schöpping | /*
|
---|---|---|---|
2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | 84f0ce9e | Thomas Schöpping | Copyright (C) 2016..2019 Thomas Schöpping et al.
|
4 | e545e620 | Thomas Schöpping | |
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 | ddf34c3d | Thomas Schöpping | #include <amiroos.h> |
20 | 2a4dbf93 | Thomas Schöpping | #include <ut_alld_PCA9544A_v1.h> |
21 | e545e620 | Thomas Schöpping | |
22 | ddf34c3d | Thomas Schöpping | #if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_PCA9544A) && (AMIROLLD_CFG_PCA9544A == 1)) || defined(__DOXYGEN__) |
23 | |||
24 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
25 | /* LOCAL DEFINITIONS */
|
||
26 | /******************************************************************************/
|
||
27 | |||
28 | /******************************************************************************/
|
||
29 | /* EXPORTED VARIABLES */
|
||
30 | /******************************************************************************/
|
||
31 | |||
32 | /******************************************************************************/
|
||
33 | /* LOCAL TYPES */
|
||
34 | /******************************************************************************/
|
||
35 | |||
36 | /******************************************************************************/
|
||
37 | /* LOCAL VARIABLES */
|
||
38 | /******************************************************************************/
|
||
39 | |||
40 | /******************************************************************************/
|
||
41 | /* LOCAL FUNCTIONS */
|
||
42 | /******************************************************************************/
|
||
43 | |||
44 | /******************************************************************************/
|
||
45 | /* EXPORTED FUNCTIONS */
|
||
46 | /******************************************************************************/
|
||
47 | e545e620 | Thomas Schöpping | |
48 | aos_utresult_t utAlldPca9544aFunc(BaseSequentialStream* stream, aos_unittest_t* ut) |
||
49 | { |
||
50 | aosDbgCheck(ut->data != NULL && ((ut_pca9544adata_t*)ut->data)->driver != NULL); |
||
51 | |||
52 | // local variables
|
||
53 | aos_utresult_t result = {0,0}; |
||
54 | uint32_t status; |
||
55 | uint8_t ctrlreg; |
||
56 | pca9544a_lld_intstatus_t interrupt; |
||
57 | pca9544a_lld_chid_t channel; |
||
58 | uint8_t test_mask = 0x00u;
|
||
59 | |||
60 | chprintf(stream, "reading control register...\n");
|
||
61 | status = pca9544a_lld_read(((ut_pca9544adata_t*)ut->data)->driver, &ctrlreg, ((ut_pca9544adata_t*)ut->data)->timeout); |
||
62 | if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
|
||
63 | aosUtPassed(stream, &result); |
||
64 | } else {
|
||
65 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
66 | } |
||
67 | |||
68 | chprintf(stream, "writing control register...\n");
|
||
69 | status = APAL_STATUS_OK; |
||
70 | status |= pca9544a_lld_write(((ut_pca9544adata_t*)ut->data)->driver, (uint8_t)(PCA9544A_LLD_CTRLREG_EN), ((ut_pca9544adata_t*)ut->data)->timeout); |
||
71 | status |= pca9544a_lld_read(((ut_pca9544adata_t*)ut->data)->driver, &ctrlreg, ((ut_pca9544adata_t*)ut->data)->timeout); |
||
72 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && ctrlreg == PCA9544A_LLD_CTRLREG_EN) {
|
||
73 | aosUtPassed(stream, &result); |
||
74 | } else {
|
||
75 | aosUtFailedMsg(stream, &result, "0x%08X, 0x%X\n", status, ctrlreg);
|
||
76 | } |
||
77 | |||
78 | chprintf(stream, "reading interrupt status...\n");
|
||
79 | status = pca9544a_lld_getintstatus(((ut_pca9544adata_t*)ut->data)->driver, &interrupt, ((ut_pca9544adata_t*)ut->data)->timeout); |
||
80 | if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
|
||
81 | aosUtPassedMsg(stream, &result, "0x%08X\n", interrupt);
|
||
82 | } else {
|
||
83 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
84 | } |
||
85 | |||
86 | chprintf(stream, "reading current channel...\n");
|
||
87 | status = pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout); |
||
88 | if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
|
||
89 | aosUtPassedMsg(stream, &result, "0x%08X\n", channel);
|
||
90 | } else {
|
||
91 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
92 | } |
||
93 | |||
94 | chprintf(stream, "setting current channel...\n");
|
||
95 | status = APAL_STATUS_OK; |
||
96 | status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH0, ((ut_pca9544adata_t*)ut->data)->timeout); |
||
97 | status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout); |
||
98 | test_mask |= (channel != PCA9544A_LLD_CH0) ? 0x01u : 0x00u; |
||
99 | status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH1, ((ut_pca9544adata_t*)ut->data)->timeout); |
||
100 | status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout); |
||
101 | test_mask |= (channel != PCA9544A_LLD_CH1) ? 0x02u : 0x00u; |
||
102 | status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH2, ((ut_pca9544adata_t*)ut->data)->timeout); |
||
103 | status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout); |
||
104 | test_mask |= (channel != PCA9544A_LLD_CH2) ? 0x04u : 0x00u; |
||
105 | status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH3, ((ut_pca9544adata_t*)ut->data)->timeout); |
||
106 | status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout); |
||
107 | test_mask |= (channel != PCA9544A_LLD_CH3) ? 0x08u : 0x00u; |
||
108 | status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH_NONE, ((ut_pca9544adata_t*)ut->data)->timeout); |
||
109 | status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout); |
||
110 | test_mask |= (channel != PCA9544A_LLD_CH_NONE) ? 0x10u : 0x00u; |
||
111 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && test_mask == 0x00u) { |
||
112 | aosUtPassed(stream, &result); |
||
113 | } else {
|
||
114 | aosUtFailedMsg(stream, &result, "0x%08X, 0x%X\n", status, test_mask);
|
||
115 | } |
||
116 | |||
117 | aosUtInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(PCA9544ADriver)); |
||
118 | |||
119 | return result;
|
||
120 | } |
||
121 | |||
122 | ddf34c3d | Thomas Schöpping | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_PCA9544A) && (AMIROLLD_CFG_PCA9544A == 1) */ |