Home | History | Annotate | Download | only in base
      1 /*
      2  * xcam_common.h - xcam common and utilities
      3  *
      4  *  Copyright (c) 2014 Intel Corporation
      5  *
      6  * Licensed under the Apache License, Version 2.0 (the "License");
      7  * you may not use this file except in compliance with the License.
      8  * You may obtain a copy of the License at
      9  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing, software
     13  * distributed under the License is distributed on an "AS IS" BASIS,
     14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  * See the License for the specific language governing permissions and
     16  * limitations under the License.
     17  *
     18  * Author: Wind Yuan <feng.yuan (at) intel.com>
     19  */
     20 
     21 #ifndef XCAM_COMMON_H
     22 #define XCAM_COMMON_H
     23 
     24 #include <string.h>
     25 #include <stddef.h>
     26 #include <stdio.h>
     27 #include <stdint.h>
     28 #include <stdlib.h>
     29 #include <errno.h>
     30 #include <assert.h>
     31 #include <pthread.h>
     32 #include <math.h>
     33 #include <base/xcam_defs.h>
     34 
     35 XCAM_BEGIN_DECLARE
     36 
     37 typedef enum {
     38     XCAM_RETURN_NO_ERROR        = 0,
     39     XCAM_RETURN_BYPASS          = 1,
     40 
     41     /* errors */
     42     XCAM_RETURN_ERROR_PARAM     = -1,
     43     XCAM_RETURN_ERROR_MEM       = -2,
     44     XCAM_RETURN_ERROR_FILE      = -3,
     45     XCAM_RETURN_ERROR_AIQ       = -4,
     46     XCAM_RETURN_ERROR_ISP       = -5,
     47     XCAM_RETURN_ERROR_SENSOR    = -6,
     48     XCAM_RETURN_ERROR_THREAD    = -7,
     49     XCAM_RETURN_ERROR_IOCTL     = -8,
     50     XCAM_RETURN_ERROR_CL        = -9,
     51     XCAM_RETURN_ERROR_ORDER     = -10,
     52 
     53     XCAM_RETURN_ERROR_TIMEOUT   = -20,
     54 
     55     XCAM_RETURN_ERROR_UNKNOWN   = -255,
     56 } XCamReturn;
     57 
     58 #define xcam_malloc_type(TYPE) (TYPE*)(xcam_malloc(sizeof(TYPE)))
     59 #define xcam_malloc_type_array(TYPE, num) (TYPE*)(xcam_malloc(sizeof(TYPE) * (num)))
     60 
     61 #define xcam_malloc0_type(TYPE) (TYPE*)(xcam_malloc0(sizeof(TYPE)))
     62 #define xcam_malloc0_type_array(TYPE, num) (TYPE*)(xcam_malloc0(sizeof(TYPE) * (num)))
     63 
     64 #define xcam_mem_clear(v_stack) memset(&(v_stack), 0, sizeof(v_stack))
     65 
     66 uint32_t xcam_version ();
     67 void * xcam_malloc (size_t size);
     68 void * xcam_malloc0 (size_t size);
     69 
     70 void xcam_free (void *ptr);
     71 
     72 /*
     73   * return, 0 successfully
     74   *            else, check errno
     75   */
     76 int xcam_device_ioctl (int fd, int cmd, void *arg);
     77 const char *xcam_fourcc_to_string (uint32_t fourcc);
     78 
     79 void xcam_set_log (const char* file_name);
     80 void xcam_print_log (const char* format, ...);
     81 
     82 static inline uint32_t
     83 xcam_ceil (uint32_t value, const uint32_t align) {
     84     return (value + align - 1) / align * align;
     85 }
     86 
     87 static inline uint32_t
     88 xcam_around (uint32_t value, const uint32_t align) {
     89     return (value + align / 2) / align * align;
     90 }
     91 
     92 static inline uint32_t
     93 xcam_floor (uint32_t value, const uint32_t align) {
     94     return value / align * align;
     95 }
     96 
     97 // return true or false
     98 static inline int
     99 xcam_ret_is_ok (XCamReturn err) {
    100     return err >= XCAM_RETURN_NO_ERROR;
    101 }
    102 
    103 //format to [0 ~ 360]
    104 static inline float
    105 format_angle (float angle)
    106 {
    107     if (angle < 0.0f)
    108         angle += 360.0f;
    109     if (angle >= 360.0f)
    110         angle -= 360.0f;
    111 
    112     XCAM_ASSERT (angle >= 0.0f && angle < 360.0f);
    113     return angle;
    114 }
    115 
    116 XCAM_END_DECLARE
    117 
    118 #endif //XCAM_COMMON_H
    119 
    120