summaryrefslogtreecommitdiffstats
path: root/src/occ_gpe1/gpe1_main.c
blob: 2115f3974cc747ee3e9f1b9f5bca416e888c835f (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_gpe1/gpe1_main.c $                                    */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2018                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* 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.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

/// \file gpe1_main.c
/// \brief Sample program that creates and starts a thread
///
/// This file demonstrates how to create a thread and run it.  It also provides
/// an example of how to add traces to the code.

#include "pk.h"
#include "pk_trace.h"
#include "ipc_api.h"
#include "gpe_export.h"
#include "gpe_membuf.h"

#if defined(__OCMB_UNIT_TEST__)
#include "membuf_structs.h"
#include "ocmb_mem_data.h"
#endif

#define KERNEL_STACK_SIZE  1024

uint64_t        G_kernel_stack[KERNEL_STACK_SIZE/8];

//Point to the GPE shared structure
#define GPE_SHARED_DATA_ADDR 0xFFFB3C00
#define GPE_SHARED_DATA_SIZE 256

gpe_shared_data_t * G_gpe_shared_data = (gpe_shared_data_t*) GPE_SHARED_DATA_ADDR;

extern PkTraceBuffer* g_pk_trace_buf_ptr;

#if defined(__OCMB_UNIT_TEST__)
MemBufGetMemDataParms_t G_dataParms;
MemBufConfiguration_t G_membufConfiguration;
OcmbMemData G_escache;

extern MemBufConfiguration_t * G_membuf_config;

int gpe_ocmb_configuration_create(MemBufConfiguration_t* o_config);
int get_ocmb_sensorcache(MemBufConfiguration_t* i_config,
                         MemBufGetMemDataParms_t* i_parms);
#endif

// The main function is called by the boot code (after initializing some
// registers)
int main(int argc, char **argv)
{
    int rc;
    uint32_t l_timebase = G_gpe_shared_data->nest_freq_div;

    // Don't initialize with a 0
    if (!l_timebase)
    {
        l_timebase = PPE_TIMEBASE_HZ;
    }

    // Mark the location of the trace buffer in shared data
    G_gpe_shared_data->gpe1_tb_ptr = (uint32_t) g_pk_trace_buf_ptr;
    G_gpe_shared_data->gpe1_tb_sz = sizeof(PkTraceBuffer);

    // initializes kernel data (stack, threads, timebase, timers, etc.)
    pk_initialize((PkAddress)G_kernel_stack,
                  KERNEL_STACK_SIZE,
                  PK_TIMEBASE_CONTINUES,
                  l_timebase);

    PK_TRACE("Kernel init completed, timebase is %d Hz", l_timebase);

    // Disable IPC's and register the IPC interrupt handler
    rc = ipc_init();
    if(rc)
    {
        PK_TRACE("ipc_init failed with rc = 0x%08x", rc);
        pk_halt();
    }

    // enable IPC's
    rc = ipc_enable();
    if(rc)
    {
        PK_TRACE("ipc_enable failed with rc = 0x%08x", rc);
        pk_halt();
    }
#if defined(__OCMB_UNIT_TEST__)
    G_dataParms.error.rc = 0;
    G_dataParms.collect = 0;
    G_dataParms.update = -1;
    G_dataParms.data = (uint64_t*)(&G_escache);
    G_membuf_config = &G_membufConfiguration;

    rc = get_ocmb_sensorcache(&G_membufConfiguration, &G_dataParms);

    PK_TRACE("get_ocmb_sensorcache rc = %x",rc);
#endif
    return 0;
}

OpenPOWER on IntegriCloud