Forked mbed-dev as I use an 20 pins stm32F042 and not the 32 pins version

Dependents:   Numitron_clock

Fork of mbed-dev by mbed official

targets/TARGET_ublox/TARGET_HI2110/hi2110_init.c

Committer:
<>
Date:
2016-11-08
Revision:
150:02e0a0aed4ec

File content as of revision 150:02e0a0aed4ec:

/* mbed Microcontroller Library
 * Copyright (c) 2016 u-blox
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#include <stdint.h>
#include <stdbool.h>
#include "mbed_assert.h"
#include "cmsis.h"
#include "hi2110_init.h"

/* ----------------------------------------------------------------
 * MACROS
 * ----------------------------------------------------------------*/

/* ----------------------------------------------------------------
 * FUNCTION PROTOTYPES
 * ----------------------------------------------------------------*/

static uint8_t get_owner(uint8_t pin);

/* ----------------------------------------------------------------
 * NON-API FUNCTIONS
 * ----------------------------------------------------------------*/

/* Determine which core owns a given pin
 * 0: None
 * 1: security core
 * 2: protocol core
 * 3: apps core */
static uint8_t get_owner(uint8_t pin)
{
    uint8_t value;
    uint8_t pio_owner_shift = (pin & 0x0F) << 1;
    volatile uint32_t * pio_owner_reg = (&PIO_OWNER0 + (pin >> 4));

    value = 0x03 & (*pio_owner_reg >> pio_owner_shift);

    return value;
}

/* ----------------------------------------------------------------
 * MBED API FUNCTIONS
 * ----------------------------------------------------------------*/

void HI2110_init(void)
{
    __attribute__ ((unused)) uint8_t owner[20];
    
    /* This purely for diagnostics to see who owns which PIO pin.
     * Put a break-point at the end of this function and take a look
     * at the array.
     * Any items marked as 1 or 2 belong to the security or protocol
     * cores.  Otherwise they are up for grabs. */
    for (uint8_t x = 0; x < 20; x++) {
        owner[x] = get_owner(x);
    }
}