1 /*
2 *
3 * SPDX-License-Identifier: GPL-2.0
4 *
5 * Copyright (C) 2011-2018 ARM or its affiliates
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 */
19
20 #include "acamera.h"
21 #include "acamera_fw.h"
22 #include "acamera_firmware_config.h"
23 #include "acamera_logger.h"
24 #include "system_timer.h"
25
get_current_set(void * p_ctx)26 static ACameraCalibrations *get_current_set( void *p_ctx )
27 {
28 return &( (acamera_context_ptr_t)p_ctx )->acameraCalibrations;
29 }
30
_GET_LOOKUP_PTR(void * p_ctx,uint32_t idx)31 LookupTable *_GET_LOOKUP_PTR( void *p_ctx, uint32_t idx )
32 {
33 LookupTable *result = NULL;
34 if ( idx < CALIBRATION_TOTAL_SIZE ) {
35 result = get_current_set( p_ctx )->calibrations[idx];
36 } else {
37 result = NULL;
38 LOG( LOG_CRIT, "Trying to access an isp lut with invalid index %d", (int)idx );
39 }
40 return result;
41 }
42
43
_GET_LUT_PTR(void * p_ctx,uint32_t idx)44 const void *_GET_LUT_PTR( void *p_ctx, uint32_t idx )
45 {
46 const void *result = NULL;
47 LookupTable *lut = _GET_LOOKUP_PTR( p_ctx, idx );
48 if ( lut != NULL ) {
49 result = lut->ptr;
50 } else {
51 while ( 1 ) {
52 fsm_param_mon_err_head_t mon_err_head;
53 mon_err_head.err_type = MON_TYPE_ERR_CALIBRATION_LUT_NULL;
54 mon_err_head.err_param = idx;
55 acamera_fsm_mgr_set_param( &( (acamera_context_ptr_t)p_ctx )->fsm_mgr, FSM_PARAM_SET_MON_ERROR_REPORT, &mon_err_head, sizeof( mon_err_head ) );
56 LOG( LOG_CRIT, "LUT 0x%x is not initialized. Pointer is NULL. Going to the infinite loop", (int)idx );
57
58 // sleep 3 second to avoid affect system performance badly.
59 system_timer_usleep( 3 * 1000 * 1000 );
60 };
61 }
62 return result;
63 }
64
65 // use fast version of lut access routines
_GET_UCHAR_PTR(void * p_ctx,uint32_t idx)66 uint8_t *_GET_UCHAR_PTR( void *p_ctx, uint32_t idx )
67 {
68 uint8_t *result = (uint8_t *)_GET_LUT_PTR( p_ctx, idx );
69 return result;
70 }
71
_GET_USHORT_PTR(void * p_ctx,uint32_t idx)72 uint16_t *_GET_USHORT_PTR( void *p_ctx, uint32_t idx )
73 {
74 uint16_t *result = (uint16_t *)_GET_LUT_PTR( p_ctx, idx );
75 return result;
76 }
77
_GET_UINT_PTR(void * p_ctx,uint32_t idx)78 uint32_t *_GET_UINT_PTR( void *p_ctx, uint32_t idx )
79 {
80 uint32_t *result = (uint32_t *)_GET_LUT_PTR( p_ctx, idx );
81 return result;
82 }
83
_GET_MOD_ENTRY16_PTR(void * p_ctx,uint32_t idx)84 modulation_entry_t *_GET_MOD_ENTRY16_PTR( void *p_ctx, uint32_t idx )
85 {
86 modulation_entry_t *result = (modulation_entry_t *)_GET_LUT_PTR( p_ctx, idx );
87 return result;
88 }
89
_GET_MOD_ENTRY32_PTR(void * p_ctx,uint32_t idx)90 modulation_entry_32_t *_GET_MOD_ENTRY32_PTR( void *p_ctx, uint32_t idx )
91 {
92 modulation_entry_32_t *result = (modulation_entry_32_t *)_GET_LUT_PTR( p_ctx, idx );
93 return result;
94 }
95
_GET_ROWS(void * p_ctx,uint32_t idx)96 uint32_t _GET_ROWS( void *p_ctx, uint32_t idx )
97 {
98 uint32_t result = 0;
99 LookupTable *lut = _GET_LOOKUP_PTR( p_ctx, idx );
100 if ( lut != NULL ) {
101 result = lut->rows;
102 }
103 return result;
104 }
105
_GET_COLS(void * p_ctx,uint32_t idx)106 uint32_t _GET_COLS( void *p_ctx, uint32_t idx )
107 {
108 uint32_t result = 0;
109 LookupTable *lut = _GET_LOOKUP_PTR( p_ctx, idx );
110 if ( lut != NULL ) {
111 result = lut->cols;
112 }
113 return result;
114 }
115
_GET_LEN(void * p_ctx,uint32_t idx)116 uint32_t _GET_LEN( void *p_ctx, uint32_t idx )
117 {
118 uint32_t result = 0;
119 LookupTable *lut = _GET_LOOKUP_PTR( p_ctx, idx );
120 if ( lut != NULL ) {
121 result = lut->cols * lut->rows;
122 }
123 return result;
124 }
125
_GET_WIDTH(void * p_ctx,uint32_t idx)126 uint32_t _GET_WIDTH( void *p_ctx, uint32_t idx )
127 {
128 uint32_t result = 0;
129 LookupTable *lut = _GET_LOOKUP_PTR( p_ctx, idx );
130 if ( lut != NULL ) {
131 result = lut->width;
132 }
133 return result;
134 }
135
_GET_SIZE(void * p_ctx,uint32_t idx)136 uint32_t _GET_SIZE( void *p_ctx, uint32_t idx )
137 {
138 uint32_t result = 0;
139 LookupTable *lut = _GET_LOOKUP_PTR( p_ctx, idx );
140 if ( lut != NULL ) {
141 result = lut->cols * lut->rows * lut->width;
142 }
143 return result;
144 }
145