Skip to content

Commit b4d1ec5

Browse files
author
Marcus Chang
committed
Helper functions for sharing hardware peripherals on NRF52
Common functions for getting and setting the instance owner of a hardware peripheral. Used for reconfiguring SPI/I2C after change of ownership.
1 parent 05dc919 commit b4d1ec5

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "object_owners.h"
18+
19+
#include "nrf.h"
20+
#include "nrf_peripherals.h"
21+
22+
#include <stdio.h>
23+
24+
#define SPI2C_INSTANCES SPI_COUNT
25+
26+
static void * nordic_spi2c_owners[SPI2C_INSTANCES] = { NULL, NULL, NULL };
27+
28+
/**
29+
* Brief Set instance owner for the SPI/I2C peripheral.
30+
*
31+
* Parameter instance The instance.
32+
* Parameter object The object.
33+
*/
34+
void object_owner_spi2c_set(int instance, void *object)
35+
{
36+
if (instance < SPI2C_INSTANCES) {
37+
nordic_spi2c_owners[instance] = object;
38+
}
39+
}
40+
41+
/**
42+
* Brief Get instance owner for the SPI/I2C peripheral.
43+
*
44+
* Parameter instance The instance.
45+
*
46+
* Return Pointer to the object owning the instance.
47+
*/
48+
void * object_owner_spi2c_get(int instance)
49+
{
50+
void *object = (void *) 0xFFFFFFFF;
51+
52+
if (instance < SPI2C_INSTANCES) {
53+
object = nordic_spi2c_owners[instance];
54+
}
55+
56+
return object;
57+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef OBJECT_OWNERS_H
18+
#define OBJECT_OWNERS_H
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
/**
25+
* @brief Set instance owner for the SPI/I2C peripheral.
26+
*
27+
* @param[in] instance The instance.
28+
* @param object The object.
29+
*/
30+
void object_owner_spi2c_set(int instance, void *object);
31+
32+
/**
33+
* @brief Get instance owner for the SPI/I2C peripheral.
34+
*
35+
* @param[in] instance The instance.
36+
*
37+
* @return Pointer to the object owning the instance.
38+
*/
39+
void * object_owner_spi2c_get(int instance);
40+
41+
#ifdef __cplusplus
42+
}
43+
#endif
44+
45+
#endif

0 commit comments

Comments
 (0)