• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
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 _OS_API_H_
18 #define _OS_API_H_
19 
20 #include <stdint.h>
21 #include <slab.h>
22 
23 
24 struct I2cEventData {
25     void *cookie;
26     uint32_t tx;
27     uint32_t rx;
28     int err;
29 };
30 
31 union OsApiSlabItem { //main OS "things" slab must fit this
32     struct I2cEventData i2cAppCbkEvt;
33     struct {
34         uint32_t toTid;
35         void *cookie;
36     } i2cAppCbkInfo;
37 };
38 
39 
40 //EXTERNAL API
41 //level 1 indices in the OS table
42 #define SYSCALL_OS_MAIN                   0
43 #define SYSCALL_OS_DRIVERS                1
44 #define SYSCALL_OS_LAST                   2 // always last. holes are allowed, but not immediately before this
45 
46 //level 2 indices in the OS.drivers table
47 #define SYSCALL_OS_DRV_GPIO               0
48 #define SYSCALL_OS_DRV_I2C_MASTER         1
49 #define SYSCALL_OS_DRV_I2C_SLAVE          2
50 #define SYSCALL_OS_DRV_LAST               3 // always last. holes are allowed, but not immediately before this
51 
52 //level 3 indices in the OS.drivers.gpio table
53 /* more thing here eventually */
54 #define SYSCALL_OS_DRV_GPIO_REQ           0 // (uint32_t gpioNum) -> void* handle
55 #define SYSCALL_OS_DRV_GPIO_REL           1 // (handle) -> void
56 #define SYSCALL_OS_DRV_GPIO_CFG_IN        2 // (handle, i32 gpioSpeed, GpioPullMode pull) -> void
57 #define SYSCALL_OS_DRV_GPIO_CFG_OUT       3 // (handle, i32 gpioSpeed, GpioPullMode pull, GpioOpenDrainMode output, bool value) -> void
58 #define SYSCALL_OS_DRV_GPIO_CFG_ALT       4 // (handle, i32 gpioSpeed, GpioPullMode pull, GpioOpenDrainMode output, u32 altFunc) -> void
59 #define SYSCALL_OS_DRV_GPIO_GET           5 // (handle) -> bool isHigh
60 #define SYSCALL_OS_DRV_GPIO_SET           6 // (handle, bool value) -> void
61 #define SYSCALL_OS_DRV_GPIO_LAST          7 // always last. holes are allowed, but not immediately before this
62 
63 //level 3 indices in the OS.drivers.i2cM table
64 #define SYSCALL_OS_DRV_I2CM_REQ           0 // (I2cBus busId, I2cSpeed speed) -> int status
65 #define SYSCALL_OS_DRV_I2CM_REL           1 // (I2cBus busId) -> int status
66 #define SYSCALL_OS_DRV_I2CM_TXRX          2 // (I2cBus busId, I2cAddr addr, const void *txBuf, size_t txSize, void *rxBuf, size_t rxSize, uint32_t yourTidForEvts, void *cookie) -> int status
67 #define SYSCALL_OS_DRV_I2CM_LAST          3 // always last. holes are allowed, but not immediately before this
68 
69 //level 3 indices in the OS.drivers.i2cS table
70 #define SYSCALL_OS_DRV_I2CS_REQ           0 // (I2cBus busId, I2cAddr addr) -> int status
71 #define SYSCALL_OS_DRV_I2CS_REL           1 // (I2cBus busId) -> int status
72 #define SYSCALL_OS_DRV_I2CS_RX_EN         2 // (I2cBus busId, void *rxBuf, size_t rxSize, uint32_t yourTidForEvts, void *cookie) -> void
73 #define SYSCALL_OS_DRV_I2CS_TX_PRE        3 // (I2cBus busId, uint8_t byte, uint32_t yourTidForEvts, void *cookie) -> int status
74 #define SYSCALL_OS_DRV_I2CS_TX_PKT        4 // (I2cBus busId, const void *txBuf, size_t txSize, uint32_t yourTidForEvts, void *cookie) -> int status
75 #define SYSCALL_OS_DRV_I2CS_LAST          5 // always last. holes are allowed, but not immediately before this
76 
77 //level 2 indices in the OS.main table
78 #define SYSCALL_OS_MAIN_EVENTQ            0
79 #define SYSCALL_OS_MAIN_LOGGING           1
80 #define SYSCALL_OS_MAIN_SENSOR            2
81 #define SYSCALL_OS_MAIN_TIME              3
82 #define SYSCALL_OS_MAIN_HEAP              4
83 #define SYSCALL_OS_MAIN_SLAB              5
84 #define SYSCALL_OS_MAIN_LAST              6 // always last. holes are allowed, but not immediately before this
85 
86 //level 3 indices in the OS.main.event_queue table
87 #define SYSCALL_OS_MAIN_EVTQ_SUBCRIBE        0 // (uint32_t tid, uint32_t evtType) -> bool success
88 #define SYSCALL_OS_MAIN_EVTQ_UNSUBCRIBE      1 // ((uint32_t tid, uint32_t evtType) -> bool success
89 #define SYSCALL_OS_MAIN_EVTQ_ENQUEUE         2 // (uint32_t evtType, void *evtData, uint32_t tidForFreeEvt) -> bool success
90 #define SYSCALL_OS_MAIN_EVTQ_ENQUEUE_PRIVATE 3 // (uint32_t evtType, void *evtData, uint32_t tidForFreeEvt, uint32_t toTid) -> bool success
91 #define SYSCALL_OS_MAIN_EVTQ_RETAIN_EVT      4 // (TaggedPtr *evtFreeingInfoP) -> bool success
92 #define SYSCALL_OS_MAIN_EVTQ_FREE_RETAINED   5 // (uint32_t evtType, void *evtData, TaggedPtr *evtFreeingInfoP) -> void
93 #define SYSCALL_OS_MAIN_EVTQ_LAST            6 // always last. holes are allowed, but not immediately before this
94 
95 //level 3 indices in the OS.main.logging table
96 #define SYSCALL_OS_MAIN_LOG_LOGV         0 // (enum LogLevel level, const char *str, va_list *) -> void
97 #define SYSCALL_OS_MAIN_LOG_LAST         1 // always last. holes are allowed, but not immediately before this
98 
99 //level 3 indices in the OS.main.sensors table
100 #define SYSCALL_OS_MAIN_SENSOR_SIGNAL        0 // (uint32_t handle, uint32_t intEvtNum, uint32_t value1, uint32_t value2_lo, uint32_t value2_hi) -> bool /* used by sensor-provding apps */
101 #define SYSCALL_OS_MAIN_SENSOR_REG           1 // (const struct SensorInfo *si, uint32_t tid) -> u32 handle
102 #define SYSCALL_OS_MAIN_SENSOR_UNREG         2 // (uint32_t handle) -> bool
103 #define SYSCALL_OS_MAIN_SENSOR_REG_INIT_COMP 3 // (uint32_t handle) -> bool
104 #define SYSCALL_OS_MAIN_SENSOR_FIND          4 // (uint32_t sensorType, uint32_t idx, uint32_t *handleP) -> const struct SensorInfo* or NULL
105 #define SYSCALL_OS_MAIN_SENSOR_REQUEST       5 // (uint32_t clientId, uint32_t sensorHandle, uint32_t rate) -> bool success
106 #define SYSCALL_OS_MAIN_SENSOR_RATE_CHG      6 // (uint32_t clientId, uint32_t sensorHandle, uint32_t newRate) -> bool success
107 #define SYSCALL_OS_MAIN_SENSOR_RELEASE       7 // (uint32_t clientId, uint32_t sensorHandle) -> bool success
108 #define SYSCALL_OS_MAIN_SENSOR_TRIGGER       8 // (uint32_t clientId, uint32_t sensorHandle) -> bool success
109 #define SYSCALL_OS_MAIN_SENSOR_GET_RATE      9 // (uint32_t sensorHandle) -> uint32_t rate
110 #define SYSCALL_OS_MAIN_SENSOR_LAST         10 // always last. holes are allowed, but not immediately before this
111 
112 //level 3 indices in the OS.main.timer table
113 #define SYSCALL_OS_MAIN_TIME_GET_TIME     0 // (uint64_t *timeNanos) -> void
114 #define SYSCALL_OS_MAIN_TIME_SET_TIMER    1 // (uint32_t len_lo, uint32_t len_hi, uint32_t jitterPpm, uint32_t driftPpm, uint32_t tidForTimerEvt, void *cookie, bool oneshot) -> u32 timerId
115 #define SYSCALL_OS_MAIN_TIME_CANCEL_TIMER 2 // (uint32_t timer_id) -> bool success
116 #define SYSCALL_OS_MAIN_TIME_LAST         3 // always last. holes are allowed, but not immediately before this
117 
118 //level 3 indices in the OS.main.heap table
119 #define SYSCALL_OS_MAIN_HEAP_ALLOC        0 // (uint32_t sz) -> void *mem
120 #define SYSCALL_OS_MAIN_HEAP_FREE         1 // (void *mem) -> void
121 #define SYSCALL_OS_MAIN_HEAP_LAST         2 // always last. holes are allowed, but not immediately before this
122 
123 //level 3 indices in the OS.main.slab table
124 #define SYSCALL_OS_MAIN_SLAB_NEW          0 // (uint32_t itemSz, uint32_t itemAlign, uint32_t numItems) -> struct SlabAllocator *slab
125 #define SYSCALL_OS_MAIN_SLAB_DESTROY      1 // (struct SlabAllocator *slab) -> void
126 #define SYSCALL_OS_MAIN_SLAB_ALLOC        2 // (struct SlabAllocator *slab) -> void *mem
127 #define SYSCALL_OS_MAIN_SLAB_FREE         3 // (struct SlabAllocator *slab, void *mem) -> void
128 #define SYSCALL_OS_MAIN_SLAB_LAST         4 // always last. holes are allowed, but not immediately before this
129 
130 
131 //called by os entry point to export the api
132 void osApiExport(struct SlabAllocator *mainSlubAllocator);
133 
134 
135 
136 
137 #endif
138 
139