summaryrefslogtreecommitdiff
path: root/firmware/os/platform/stm32/hostIntf.c
blob: 2a96032de05573905ca8b45b8611354770a6c9ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * 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 <bl.h>
#include <hostIntf.h>
#include <hostIntf_priv.h>

#include <variant/variant.h>

#include <plat/cmsis.h>
#include <plat/spi.h>


const struct HostIntfComm *platHostIntfInit()
{
    uint32_t priorityGroup = NVIC_GetPriorityGrouping();
    uint32_t priority, preemptPriority, subPriority;
    enum IRQn rx, tx;
    const struct HostIntfComm *ret = NULL;

#if defined(PLATFORM_HOST_INTF_I2C_BUS)
    ret = hostIntfI2cInit(PLATFORM_HOST_INTF_I2C_BUS);
#elif defined(PLATFORM_HOST_INTF_SPI_BUS)
    ret = hostIntfSpiInit(PLATFORM_HOST_INTF_SPI_BUS);

    /* get the rx and tx irq numbers used by the host spi bus */
    ret->request();
    rx = spiRxIrq(PLATFORM_HOST_INTF_SPI_BUS);
    tx = spiTxIrq(PLATFORM_HOST_INTF_SPI_BUS);
    ret->release();

    /* make the tx and rx dma isrs execute before other isrs when multiple
       interrupts are pending (if avaliable subpriority bits).
       We do not change the preempt priority */
    priority = NVIC_GetPriority(rx);
    NVIC_DecodePriority (priority, priorityGroup, &preemptPriority, &subPriority);
    if (&subPriority > 0)
        subPriority --;
    NVIC_SetPriority(rx, NVIC_EncodePriority(priorityGroup, preemptPriority, subPriority));

    priority = NVIC_GetPriority(tx);
    NVIC_DecodePriority (priority, priorityGroup, &preemptPriority, &subPriority);
    if (&subPriority > 0)
        subPriority --;
    NVIC_SetPriority(tx, NVIC_EncodePriority(priorityGroup, preemptPriority, subPriority));
#else
#error "No host interface bus specified"
#endif
    return ret;
}

uint16_t platHwType(void)
{
    return PLATFORM_HW_TYPE;
}

uint16_t platHwVer(void)
{
    return PLATFORM_HW_VER;
}

uint16_t platBlVer()
{
    return BL.blGetVersion();
}