diff options
| author | Satish kumar sugasi <ssugas@codeaurora.org> | 2012-12-08 20:51:55 -0800 |
|---|---|---|
| committer | Satish kumar sugasi <ssugas@codeaurora.org> | 2012-12-08 20:51:55 -0800 |
| commit | 8dbae1cbcd8ee795e2d30f5ac26996d5c235d38b (patch) | |
| tree | 64258b09cbadd7ce47b7d1f3d71880a43764b914 /src/common | |
| parent | 709b0e9416802fff4b45611f17bf878a64af07d6 (diff) | |
| parent | 274e0ddfa092938c5839643af6abed3e6e7ef773 (diff) | |
| download | android_external_ant-wireless_ant_native-8dbae1cbcd8ee795e2d30f5ac26996d5c235d38b.tar.gz android_external_ant-wireless_ant_native-8dbae1cbcd8ee795e2d30f5ac26996d5c235d38b.tar.bz2 android_external_ant-wireless_ant_native-8dbae1cbcd8ee795e2d30f5ac26996d5c235d38b.zip | |
Merge remote-tracking branch 'remotes/origin/caf/github/master'
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/JAntNative.cpp | 366 | ||||
| -rw-r--r-- | src/common/ant_utils.c | 57 | ||||
| -rw-r--r-- | src/common/inc/ant_log.h | 174 | ||||
| -rw-r--r-- | src/common/inc/ant_native.h | 135 | ||||
| -rw-r--r-- | src/common/inc/ant_types.h | 125 | ||||
| -rw-r--r-- | src/common/inc/ant_utils.h | 139 | ||||
| -rw-r--r-- | src/common/inc/ant_version.h | 27 |
7 files changed, 1023 insertions, 0 deletions
diff --git a/src/common/JAntNative.cpp b/src/common/JAntNative.cpp new file mode 100644 index 0000000..2e3beb0 --- /dev/null +++ b/src/common/JAntNative.cpp @@ -0,0 +1,366 @@ +/* + * ANT Stack + * + * Copyright 2009 Dynastream Innovations + * + * 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. + */ +/*******************************************************************************\ +* +* FILE NAME: JAntNative.cpp +* +* BRIEF: +* This file provides the implementation of the native interface functions for ANT +* +* +\*******************************************************************************/ + +#include "android_runtime/AndroidRuntime.h" +#include "jni.h" +#include "nativehelper/JNIHelp.h" + +static JNIEnv *g_jEnv = NULL; +static JavaVM *g_jVM = NULL; +static jclass g_sJClazz; +static jmethodID g_sMethodId_nativeCb_AntRxMessage; +static jmethodID g_sMethodId_nativeCb_AntStateChange; + +extern "C" +{ + #include "ant_native.h" + #include "ant_log.h" + #undef LOG_TAG + #define LOG_TAG "JAntNative" + + void nativeJAnt_RxCallback(ANT_U8 ucLen, ANT_U8* pucData); + void nativeJAnt_StateCallback(ANTRadioEnabledStatus uiNewState); +} + +static jint nativeJAnt_Create(JNIEnv *env, jobject obj) +{ + ANTStatus antStatus = ANT_STATUS_FAILED; + (void)env; //unused warning + (void)obj; //unused warning + + ANT_FUNC_START(); + + antStatus = ant_init(); + if (antStatus) + { + ANT_DEBUG_D("failed to init ANT stack"); + goto CLEANUP; + } + + antStatus = set_ant_rx_callback(nativeJAnt_RxCallback); + if (antStatus) + { + ANT_DEBUG_D("failed to set ANT rx callback"); + goto CLEANUP; + } + + antStatus = set_ant_state_callback(nativeJAnt_StateCallback); + if (antStatus) + { + ANT_DEBUG_D("failed to set ANT state callback"); + goto CLEANUP; + } + +CLEANUP: + ANT_FUNC_END(); + return antStatus; +} + +static jint nativeJAnt_Destroy(JNIEnv *env, jobject obj) +{ + (void)env; //unused warning + (void)obj; //unused warning + ANTStatus status; + ANT_FUNC_START(); + + ANT_DEBUG_D("nativeJAnt_Destroy(): calling ant_deinit"); + status = ant_deinit(); + if (status) + { + ANT_DEBUG_D("failed to deinit ANT stack returned %d",(int)status); + return status; + } + else + { + ANT_DEBUG_D("deinit ANT stack Success"); + } + + ANT_FUNC_END(); + return status; +} + +static jint nativeJAnt_Enable(JNIEnv *env, jobject obj) +{ + (void)env; //unused warning + (void)obj; //unused warning + ANT_FUNC_START(); + + ANTStatus status = ant_enable_radio(); + + ANT_FUNC_END(); + return status; +} + +static jint nativeJAnt_Disable(JNIEnv *env, jobject obj) +{ + (void)env; //unused warning + (void)obj; //unused warning + ANT_FUNC_START(); + + ANTStatus status = ant_disable_radio(); + + ANT_FUNC_END(); + return status; +} + +static jint nativeJAnt_GetRadioEnabledStatus(JNIEnv *env, jobject obj) +{ + (void)env; //unused warning + (void)obj; //unused warning + ANT_FUNC_START(); + + jint status = ant_radio_enabled_status(); + + ANT_FUNC_END(); + return status; +} + +static jint nativeJAnt_TxMessage(JNIEnv *env, jobject obj, jbyteArray msg) +{ + (void)obj; //unused warning + ANT_FUNC_START(); + + if (msg == NULL) + { + if (jniThrowException(env, "java/lang/NullPointerException", NULL)) + { + ANT_ERROR("Unable to throw NullPointerException"); + } + return -1; + } + + jbyte* msgBytes = env->GetByteArrayElements(msg, NULL); + jint msgLength = env->GetArrayLength(msg); + + ANTStatus status = ant_tx_message((ANT_U8) msgLength, (ANT_U8 *)msgBytes); + ANT_DEBUG_D("nativeJAnt_TxMessage: ant_tx_message() returned %d", (int)status); + + env->ReleaseByteArrayElements(msg, msgBytes, JNI_ABORT); + + ANT_FUNC_END(); + return status; +} + +static jint nativeJAnt_HardReset(JNIEnv *env, jobject obj) +{ + (void)env; //unused warning + (void)obj; //unused warning + ANT_FUNC_START(); + + ANTStatus status = ant_radio_hard_reset(); + + ANT_FUNC_END(); + return status; +} + +extern "C" +{ + + /********************************************************************** + * Callback registration + ***********************************************************************/ + void nativeJAnt_RxCallback(ANT_U8 ucLen, ANT_U8* pucData) + { + JNIEnv* env = NULL; + jbyteArray jAntRxMsg = NULL; + ANT_FUNC_START(); + + ANT_DEBUG_D( "got message %d bytes", ucLen); + + g_jVM->AttachCurrentThread((&env), NULL); + + if (env == NULL) + { + ANT_DEBUG_D("nativeJAnt_RxCallback: Entered, env is null"); + return; // log error? cleanup? + } + else + { + ANT_DEBUG_D("nativeJAnt_RxCallback: jEnv %p", env); + } + + jAntRxMsg = env->NewByteArray(ucLen); + + if (jAntRxMsg == NULL) + { + ANT_ERROR("nativeJAnt_RxCallback: Failed creating java byte[]"); + goto CLEANUP; + } + + env->SetByteArrayRegion(jAntRxMsg,0,ucLen,(jbyte*)pucData); + + if (env->ExceptionOccurred()) + { + ANT_ERROR("nativeJAnt_RxCallback: ExceptionOccurred during byte[] copy"); + goto CLEANUP; + } + ANT_DEBUG_V("nativeJAnt_RxCallback: Calling java rx callback"); + env->CallStaticVoidMethod(g_sJClazz, g_sMethodId_nativeCb_AntRxMessage, jAntRxMsg); + ANT_DEBUG_V("nativeJAnt_RxCallback: Called java rx callback"); + + if (env->ExceptionOccurred()) + { + ANT_ERROR("nativeJAnt_RxCallback: Calling Java nativeCb_AntRxMessage failed"); + goto CLEANUP; + } + + //Delete the local references + if (jAntRxMsg != NULL) + { + env->DeleteLocalRef(jAntRxMsg); + } + + ANT_DEBUG_D("nativeJAnt_RxCallback: Exiting, Calling DetachCurrentThread at the END"); + + g_jVM->DetachCurrentThread(); + + ANT_FUNC_END(); + return; + + CLEANUP: + ANT_ERROR("nativeJAnt_RxCallback: Exiting due to failure"); + if (jAntRxMsg != NULL) + { + env->DeleteLocalRef(jAntRxMsg); + } + + if (env->ExceptionOccurred()) + { + env->ExceptionDescribe(); + env->ExceptionClear(); + } + + g_jVM->DetachCurrentThread(); + + return; + } + + void nativeJAnt_StateCallback(ANTRadioEnabledStatus uiNewState) + { + JNIEnv* env = NULL; + jint jNewState = uiNewState; + ANT_BOOL iShouldDetach = ANT_FALSE; + ANT_FUNC_START(); + + g_jVM->GetEnv((void**) &env, JNI_VERSION_1_4); + if (env == NULL) + { + ANT_DEBUG_D("nativeJAnt_StateCallback: called from rx thread, attaching to VM"); + g_jVM->AttachCurrentThread((&env), NULL); + if (env == NULL) + { + ANT_DEBUG_E("nativeJAnt_StateCallback: failed to attach rx thread to VM"); + return; + } + iShouldDetach = ANT_TRUE; + } + else + { + ANT_DEBUG_D("nativeJAnt_StateCallback: called from java enable/disable" + ", already attached, don't detach"); + } + + ANT_DEBUG_V("nativeJAnt_StateCallback: Calling java state callback"); + env->CallStaticVoidMethod(g_sJClazz, g_sMethodId_nativeCb_AntStateChange, jNewState); + ANT_DEBUG_V("nativeJAnt_StateCallback: Called java state callback"); + + if (env->ExceptionOccurred()) + { + ANT_ERROR("nativeJAnt_StateCallback: Calling Java nativeCb_AntStateChange failed"); + env->ExceptionDescribe(); + env->ExceptionClear(); + } + + if (iShouldDetach) + { + ANT_DEBUG_D("nativeJAnt_StateCallback: env was attached, detaching"); + g_jVM->DetachCurrentThread(); + } + + ANT_FUNC_END(); + return; + } +} + +static JNINativeMethod g_sMethods[] = +{ + /* name, signature, funcPtr */ + {"nativeJAnt_Create", "()I", (void*)nativeJAnt_Create}, + {"nativeJAnt_Destroy", "()I", (void*)nativeJAnt_Destroy}, + {"nativeJAnt_Enable", "()I", (void*)nativeJAnt_Enable}, + {"nativeJAnt_Disable", "()I", (void*)nativeJAnt_Disable}, + {"nativeJAnt_GetRadioEnabledStatus", "()I", (void*)nativeJAnt_GetRadioEnabledStatus}, + {"nativeJAnt_TxMessage","([B)I", (void*)nativeJAnt_TxMessage}, + {"nativeJAnt_HardReset", "()I", (void *)nativeJAnt_HardReset} +}; + +jint JNI_OnLoad(JavaVM* vm, void* reserved) { + ANT_FUNC_START(); + (void)reserved; //unused warning + + g_jVM = vm; + if (g_jVM->GetEnv((void**) &g_jEnv, JNI_VERSION_1_4) != JNI_OK) { + ANT_ERROR("GetEnv failed"); + return -1; + } + if (NULL == g_jEnv) { + ANT_ERROR("env is null"); + return -1; + } + + g_sJClazz = g_jEnv->FindClass("com/dsi/ant/core/JAntJava"); + if (NULL == g_sJClazz) { + ANT_ERROR("could not find class \"com/dsi/ant/core/JAntJava\""); + return -1; + } + + /* Save class information in global reference to prevent class unloading */ + g_sJClazz = (jclass)g_jEnv->NewGlobalRef(g_sJClazz); + + if (g_jEnv->RegisterNatives(g_sJClazz, g_sMethods, NELEM(g_sMethods)) != JNI_OK) { + ANT_ERROR("failed to register methods"); + return -1; + } + + g_sMethodId_nativeCb_AntRxMessage = g_jEnv->GetStaticMethodID(g_sJClazz, + "nativeCb_AntRxMessage", "([B)V"); + if (NULL == g_sMethodId_nativeCb_AntRxMessage) { + ANT_ERROR("VerifyMethodId: Failed getting method id of \"void nativeCb_AntRxMessage(byte[])\""); + return -1; + } + + g_sMethodId_nativeCb_AntStateChange = g_jEnv->GetStaticMethodID(g_sJClazz, + "nativeCb_AntStateChange", "(I)V"); + if (NULL == g_sMethodId_nativeCb_AntStateChange) { + ANT_ERROR("VerifyMethodId: Failed getting method id of \"void nativeCb_AntStateChange(int)\""); + return -1; + } + + ANT_FUNC_END(); + return JNI_VERSION_1_4; +} + diff --git a/src/common/ant_utils.c b/src/common/ant_utils.c new file mode 100644 index 0000000..65b35de --- /dev/null +++ b/src/common/ant_utils.c @@ -0,0 +1,57 @@ +/* + * ANT Stack + * + * Copyright 2009 Dynastream Innovations + * + * 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. + */ +/******************************************************************************\ +* +* FILE NAME: ANT_utils.c +* +* BRIEF: +* This file contains utility functions +* +* +\******************************************************************************/ + +#include "ant_types.h" +#include "ant_utils.h" + + +ANT_U16 ANT_UTILS_BEtoHost16(ANT_U8 * num) +{ + return (ANT_U16)(((ANT_U16) *(num) << 8) | ((ANT_U16) *(num+1))); +} +ANT_U16 ANT_UTILS_LEtoHost16(ANT_U8 * num) +{ + return (ANT_U16)(((ANT_U16) *(num+1) << 8) | ((ANT_U16) *(num))); +} +void ANT_UTILS_StoreBE16(ANT_U8 *buff, ANT_U16 be_value) +{ + buff[0] = (ANT_U8)(be_value>>8); + buff[1] = (ANT_U8)be_value; +} +void ANT_UTILS_StoreLE16(ANT_U8 *buff, ANT_U16 le_value) +{ + buff[1] = (ANT_U8)(le_value>>8); + buff[0] = (ANT_U8)le_value; +} + +void ANT_UTILS_StoreBE32(ANT_U8 *buff, ANT_U32 be_value) +{ + buff[0] = (ANT_U8)(be_value>>24); + buff[1] = (ANT_U8)(be_value>>16); + buff[2] = (ANT_U8)(be_value>>8); + buff[3] = (ANT_U8)be_value; +} diff --git a/src/common/inc/ant_log.h b/src/common/inc/ant_log.h new file mode 100644 index 0000000..bc45462 --- /dev/null +++ b/src/common/inc/ant_log.h @@ -0,0 +1,174 @@ +/* +* ANT Stack +* +* Copyright 2009 Dynastream Innovations +* +* 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. +*/ +/******************************************************************************\ +* +* FILE NAME: ANT_log.h +* +* BRIEF: +* This file defines logging functions +* +* +\******************************************************************************/ + +#ifndef __ANT_LOG_H +#define __ANT_LOG_H + +#include <unistd.h> +#include "ant_types.h" + +#define LEVEL_NONE 0 +#define LEVEL_ERROR 1 +#define LEVEL_WARNING 2 +#define LEVEL_INFO 3 +#define LEVEL_DEBUG 4 +#define LEVEL_VERBOSE 5 + +#define STREAM_STDOUT 16 +#define STREAM_LOGCAT 17 + +/* Define what stream output should go to depending on platform */ +#if defined(__ANDROID__) || defined(ANDROID) + #define ANT_OUTPUT_STREAM STREAM_LOGCAT +#elif defined(__linux__) || defined(__linux) || defined(linux) + #define ANT_OUTPUT_STREAM STREAM_STDOUT +#endif + +/* If no debug level defined, set default as none */ +#if !defined(ANT_DEBUG) + #define ANT_DEBUG LEVEL_NONE +#endif + +/* Define to show function entry and exit */ +//#define ANT_STACK_TRACE + +/* Define to show message in byte form */ +//#define ANT_LOG_SERIAL + +/* Define to write serial log to file instead of logcat */ +//#define ANT_LOG_SERIAL_FILE "/data/system/antseriallog.txt" + +#undef LOG_TAG +#define LOG_TAG "antradio" + +#if ANT_DEBUG == LEVEL_NONE + #undef ANT_STACK_TRACE + #undef ANT_LOG_SERIAL +#endif + +#if ANT_DEBUG >= LEVEL_ERROR + #define OUTPUT_LEVEL_ERROR(...) OUTPUT_ERROR(__VA_ARGS__) +#else + #define OUTPUT_LEVEL_ERROR(...) ((void)0) +#endif +#if ANT_DEBUG >= LEVEL_WARNING + #define OUTPUT_LEVEL_WARNING(...) OUTPUT_WARNING(__VA_ARGS__) +#else + #define OUTPUT_LEVEL_WARNING(...) ((void)0) +#endif +#if ANT_DEBUG >= LEVEL_INFO + #define OUTPUT_LEVEL_INFO(...) OUTPUT_INFO(__VA_ARGS__) +#else + #define OUTPUT_LEVEL_INFO(...) ((void)0) +#endif +#if ANT_DEBUG >= LEVEL_DEBUG + #define OUTPUT_LEVEL_DEBUG(...) OUTPUT_DEBUG(__VA_ARGS__) +#else + #define OUTPUT_LEVEL_DEBUG(...) ((void)0) +#endif +#if ANT_DEBUG >= LEVEL_VERBOSE + #define OUTPUT_LEVEL_VERBOSE(...) OUTPUT_VERBOSE(__VA_ARGS__) +#else + #define OUTPUT_LEVEL_VERBOSE(...) ((void)0) +#endif + +#if ANT_OUTPUT_STREAM == STREAM_STDOUT + #include <stdio.h> + #define OUTPUT_VERBOSE(fmt, ...) fprintf(stdout, LOG_TAG "<V>: " fmt "\n", ##__VA_ARGS__) + #define OUTPUT_DEBUG(fmt, ...) fprintf(stdout, LOG_TAG "<D>: " fmt "\n", ##__VA_ARGS__) + #define OUTPUT_INFO(fmt, ...) fprintf(stdout, LOG_TAG "<I>: " fmt "\n", ##__VA_ARGS__) + #define OUTPUT_WARNING(fmt, ...) fprintf(stdout, LOG_TAG "<W>: " fmt "\n", ##__VA_ARGS__) + #define OUTPUT_ERROR(fmt, ...) fprintf(stdout, LOG_TAG "<E>: " fmt "\n", ##__VA_ARGS__) +#elif ANT_OUTPUT_STREAM == STREAM_LOGCAT + #if (ANT_DEBUG >= LEVEL_VERBOSE) || (defined(ANT_LOG_SERIAL) && !defined(ANT_LOG_SERIAL_FILE)) + #undef NDEBUG /* Define verbose logging for logcat if required */ + #endif + #include <cutils/log.h> + #define OUTPUT_VERBOSE(...) ALOGV(__VA_ARGS__) + #define OUTPUT_DEBUG(...) ALOGD(__VA_ARGS__) + #define OUTPUT_INFO(...) ALOGI(__VA_ARGS__) + #define OUTPUT_WARNING(...) ALOGW(__VA_ARGS__) + #define OUTPUT_ERROR(...) ALOGE(__VA_ARGS__) +#endif + +#define ANT_WARN(...) OUTPUT_WARNING(__VA_ARGS__) +#define ANT_ERROR(...) OUTPUT_ERROR(__VA_ARGS__) + +#define ANT_DEBUG_V(...) OUTPUT_LEVEL_VERBOSE(__VA_ARGS__) +#define ANT_DEBUG_D(...) OUTPUT_LEVEL_DEBUG(__VA_ARGS__) +#define ANT_DEBUG_I(...) OUTPUT_LEVEL_INFO(__VA_ARGS__) +#define ANT_DEBUG_W(...) OUTPUT_LEVEL_WARNING(__VA_ARGS__) +#define ANT_DEBUG_E(...) OUTPUT_LEVEL_ERROR(__VA_ARGS__) + +#if defined(ANT_STACK_TRACE) + #define ANT_FUNC_START() OUTPUT_DEBUG("-> FUNC start %s", __FUNCTION__) + #define ANT_FUNC_END() OUTPUT_DEBUG("<- FUNC end %s", __FUNCTION__) +#else + #define ANT_FUNC_START() ((void)0) + #define ANT_FUNC_END() ((void)0) +#endif + +#if defined(ANT_LOG_SERIAL) +static inline void ANT_SERIAL(ANT_U8 *buf, ANT_U8 len, char dir) +{ + static const char hexToChar[] = {'0','1','2','3','4','5','6','7', + '8','9','A','B','C','D','E','F'}; + int i; + static char log[1024]; + char *ptr = log; + + *(ptr++) = dir; + *(ptr++) = 'x'; + *(ptr++) = ' '; + for (i = 0; i < len; i++) { + *(ptr++) = '['; + *(ptr++) = hexToChar[(buf[i] & 0xF0) >> 4]; + *(ptr++) = hexToChar[(buf[i] & 0x0F) >> 0]; + *(ptr++) = ']'; + } +#if defined(ANT_LOG_SERIAL_FILE) + *(ptr++) = '\n'; + FILE *fd = NULL; + fd = fopen(ANT_LOG_SERIAL_FILE, "a"); + if (NULL == fd) { + LOGW("Could not open %s for serial output. %s", ANT_LOG_SERIAL_FILE, strerror(errno)); + } else { + fwrite(log, 1, (ptr - log), fd); + if (fclose(fd)) { + LOGW("Could not close file for serial output. %s", strerror(errno)); + } + } +#else + *(ptr++) = '\0'; + OUTPUT_VERBOSE("%s", log); +#endif +} +#else + #define ANT_SERIAL(...) ((void)0) +#endif + +#endif /* __ANT_LOG_H */ diff --git a/src/common/inc/ant_native.h b/src/common/inc/ant_native.h new file mode 100644 index 0000000..6fe106d --- /dev/null +++ b/src/common/inc/ant_native.h @@ -0,0 +1,135 @@ +/* + * ANT Stack + * + * Copyright 2009 Dynastream Innovations + * + * 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. + */ +/******************************************************************************\ +* +* FILE NAME: ant_native.h +* +* BRIEF: +* This file defines the interface to the ANT transport layer +* +* +\******************************************************************************/ + +#ifndef __ANT_NATIVE_H +#define __ANT_NATIVE_H + +/******************************************************************************* + * + * Include files + * + ******************************************************************************/ +#include "ant_types.h" + +/******************************************************************************* + * + * Constants + * + ******************************************************************************/ + +/******************************************************************************* + * + * Types + * + ******************************************************************************/ +typedef void (*ANTNativeANTEventCb)(ANT_U8 ucLen, ANT_U8* pucData); +typedef void (*ANTNativeANTStateCb)(ANTRadioEnabledStatus uiNewState); + +/******************************************************************************* + * + * Data Structures + * + ******************************************************************************/ + +/******************************************************************************* + * + * Function declarations + * + ******************************************************************************/ + +/*------------------------------------------------------------------------------ + * ant_init() + * + * Called to initialize the ANT stack + */ +ANTStatus ant_init(void); + +/*------------------------------------------------------------------------------ + * ant_deinit() + * + * Called to de-initialize the ANT stack + */ +ANTStatus ant_deinit(void); + +/*------------------------------------------------------------------------------ + * ant_enable_radio() + * + * Power on the chip and set it to a state which can read / write to it + */ +ANTStatus ant_enable_radio(void); + +/*------------------------------------------------------------------------------ + * ant_disable_radio() + * + * Kill power to the ANT chip and set state which doesnt allow read / write + */ +ANTStatus ant_disable_radio(void); + +/*------------------------------------------------------------------------------ + * ant_radio_enabled_status() + * + * Gets if the chip/transport is disabled/disabling/enabling/enabled + */ +ANTRadioEnabledStatus ant_radio_enabled_status(void); + +/*------------------------------------------------------------------------------ + * set_ant_rx_callback() + * + * Sets the callback function for receiving ANT messages + */ +ANTStatus set_ant_rx_callback(ANTNativeANTEventCb rx_callback_func); + +/*------------------------------------------------------------------------------ + * set_ant_state_callback() + * + * Sets the callback function for any ANT radio enabled status state changes + */ +ANTStatus set_ant_state_callback(ANTNativeANTStateCb state_callback_func); + +/*------------------------------------------------------------------------------ + * ant_tx_message() + * + * Sends an ANT message command to the chip. + */ +ANTStatus ant_tx_message(ANT_U8 ucLen, ANT_U8 *pucMesg); + +/*------------------------------------------------------------------------------ + * ant_radio_hard_reset() + * + * If supported, forces the chip to do a power cycle reset + */ +ANTStatus ant_radio_hard_reset(void); + +/*------------------------------------------------------------------------------ + * ant_get_lib_version() + * + * Gets the current version and transport type of libantradio.so + */ +const char *ant_get_lib_version(void); + +#endif /* ifndef __ANT_NATIVE_H */ + diff --git a/src/common/inc/ant_types.h b/src/common/inc/ant_types.h new file mode 100644 index 0000000..bc896b6 --- /dev/null +++ b/src/common/inc/ant_types.h @@ -0,0 +1,125 @@ +/* + * ANT Stack + * + * Copyright 2009 Dynastream Innovations + * + * 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. + */ +/******************************************************************************\ +* +* FILE NAME: ANT_types.h +* +* BRIEF: +* This file defines types used in the ANT stack +* +* +\******************************************************************************/ + +#ifndef __ANT_TYPES_H +#define __ANT_TYPES_H + +#include <stdint.h> + +/* ------------------------------------------------------------- + * 8 Bits Types + */ +typedef uint8_t ANT_U8; +typedef int8_t ANT_S8; + +/* ------------------------------------------------------------- + * 16 Bits Types + */ +typedef uint16_t ANT_U16; +typedef int8_t ANT_S16; + +/* ------------------------------------------------------------- + * 32 Bits Types + */ +typedef uint32_t ANT_U32; +typedef int32_t ANT_S32; + + +/* ------------------------------------------------------------- + * Native Integer Types (# of bits irrelevant) + */ +typedef int ANT_INT; +typedef unsigned int ANT_UINT; + + +/* -------------------------------------------------------------- + * Boolean Definitions + */ +typedef ANT_INT ANT_BOOL; + +#define ANT_TRUE (1 == 1) +#define ANT_FALSE (1 == 0) + +/* +*/ +#define ANT_NO_VALUE ((ANT_U32)0xFFFFFFFFUL) + + +/* ------------------------------------------------------------- + * ANTRadioEnabledStatus Type + */ +typedef ANT_UINT ANTRadioEnabledStatus; + +#define RADIO_STATUS_UNKNOWN ((ANTRadioEnabledStatus)0) +#define RADIO_STATUS_ENABLING ((ANTRadioEnabledStatus)1) +#define RADIO_STATUS_ENABLED ((ANTRadioEnabledStatus)2) +#define RADIO_STATUS_DISABLING ((ANTRadioEnabledStatus)3) +#define RADIO_STATUS_DISABLED ((ANTRadioEnabledStatus)4) +#define RADIO_STATUS_NOT_SUPPORTED ((ANTRadioEnabledStatus)5) +#define RADIO_STATUS_SERVICE_NOT_INSTALLED ((ANTRadioEnabledStatus)6) +#define RADIO_STATUS_SERVICE_NOT_CONNECTED ((ANTRadioEnabledStatus)7) +#define RADIO_STATUS_RESETTING ((ANTRadioEnabledStatus)8) +#define RADIO_STATUS_RESET ((ANTRadioEnabledStatus)9) + +/*------------------------------------------------------------------------------ + * ANTStatus Type + * + */ +typedef ANT_UINT ANTStatus; + +#define ANT_STATUS_SUCCESS ((ANTStatus)0) +#define ANT_STATUS_FAILED ((ANTStatus)1) +#define ANT_STATUS_PENDING ((ANTStatus)2) +#define ANT_STATUS_INVALID_PARM ((ANTStatus)3) +#define ANT_STATUS_IN_PROGRESS ((ANTStatus)4) +#define ANT_STATUS_NOT_APPLICABLE ((ANTStatus)5) +#define ANT_STATUS_NOT_SUPPORTED ((ANTStatus)6) +#define ANT_STATUS_INTERNAL_ERROR ((ANTStatus)7) +#define ANT_STATUS_TRANSPORT_INIT_ERR ((ANTStatus)8) +#define ANT_STATUS_HARDWARE_ERR ((ANTStatus)9) +#define ANT_STATUS_NO_VALUE_AVAILABLE ((ANTStatus)10) +#define ANT_STATUS_CONTEXT_DOESNT_EXIST ((ANTStatus)11) +#define ANT_STATUS_CONTEXT_NOT_DESTROYED ((ANTStatus)12) +#define ANT_STATUS_CONTEXT_NOT_ENABLED ((ANTStatus)13) +#define ANT_STATUS_CONTEXT_NOT_DISABLED ((ANTStatus)14) +#define ANT_STATUS_NOT_DE_INITIALIZED ((ANTStatus)15) +#define ANT_STATUS_NOT_INITIALIZED ((ANTStatus)16) +#define ANT_STATUS_TOO_MANY_PENDING_CMDS ((ANTStatus)17) +#define ANT_STATUS_DISABLING_IN_PROGRESS ((ANTStatus)18) + +#define ANT_STATUS_COMMAND_WRITE_FAILED ((ANTStatus)20) +#define ANT_STATUS_SCRIPT_EXEC_FAILED ((ANTStatus)21) + +#define ANT_STATUS_FAILED_BT_NOT_INITIALIZED ((ANTStatus)23) +#define ANT_STATUS_AUDIO_OPERATION_UNAVAILIBLE_RESOURCES ((ANTStatus)24) + +#define ANT_STATUS_TRANSPORT_UNSPECIFIED_ERROR ((ANTStatus)30) + +#define ANT_STATUS_NO_VALUE ((ANTStatus)100) + +#endif /* __ANT_TYPES_H */ + diff --git a/src/common/inc/ant_utils.h b/src/common/inc/ant_utils.h new file mode 100644 index 0000000..60abe8c --- /dev/null +++ b/src/common/inc/ant_utils.h @@ -0,0 +1,139 @@ +/* + * ANT Stack + * + * Copyright 2009 Dynastream Innovations + * + * 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. + */ +/******************************************************************************\ +* +* FILE NAME: ANT_utils.h +* +* BRIEF: +* This file defines utility functions +* +* +\******************************************************************************/ +#ifndef __ANT_UTILS_H +#define __ANT_UTILS_H + +#include "ant_types.h" + +/**************************************************************************** + * + * Type Definitions + * + ****************************************************************************/ + + + +/*------------------------------------------------------------------------------ + * ANT_xxx() + * + * Brief: + * xxx + * + * Description: + * xxx + * + * Type: + * Syxxx/As + * + * Parameters: + * xxx [in] - + * + * Returns: + * xxx + */ +ANT_U16 ANT_UTILS_BEtoHost16(ANT_U8 * num); +/*------------------------------------------------------------------------------ + * ANT_xxx() + * + * Brief: + * xxx + * + * Description: + * xxx + * + * Type: + * Syxxx/As + * + * Parameters: + * xxx [in] - + * + * Returns: + * xxx + */ +ANT_U16 ANT_UTILS_LEtoHost16(ANT_U8 * num); +/*------------------------------------------------------------------------------ + * ANT_xxx() + * + * Brief: + * xxx + * + * Description: + * xxx + * + * Type: + * Syxxx/As + * + * Parameters: + * xxx [in] - + * + * Returns: + * xxx + */ +void ANT_UTILS_StoreBE16(ANT_U8 *buff, ANT_U16 be_value) ; +/*------------------------------------------------------------------------------ + * ANT_xxx() + * + * Brief: + * xxx + * + * Description: + * xxx + * + * Type: + * Syxxx/As + * + * Parameters: + * xxx [in] - + * + * Returns: + * xxx + */ +void ANT_UTILS_StoreLE16(ANT_U8 *buff, ANT_U16 le_value) ; +/*------------------------------------------------------------------------------ + * ANT_xxx() + * + * Brief: + * xxx + * + * Description: + * xxx + * + * Type: + * Syxxx/As + * + * Parameters: + * xxx [in] - + * + * Returns: + * xxx + */ +void ANT_UTILS_StoreBE32(ANT_U8 *buff, ANT_U32 be_value) ; + + + +#endif /* __ANT_UTILS_H */ + diff --git a/src/common/inc/ant_version.h b/src/common/inc/ant_version.h new file mode 100644 index 0000000..f6effae --- /dev/null +++ b/src/common/inc/ant_version.h @@ -0,0 +1,27 @@ +/*
+ * ANT Stack
+ *
+ * Copyright 2011 Dynastream Innovations
+ *
+ * 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.
+ */
+
+#ifndef __ANT_VERSION_H
+#define __ANT_VERSION_H
+
+#define LIBANT_STACK_MAJOR "1"
+#define LIBANT_STACK_MINOR "4"
+#define LIBANT_STACK_INCRE "0"
+
+#endif // __ANT_VERSION_H
+
|
