• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_fw.h"
21 #if ACAMERA_ISP_PROFILING
22 #include "system_profiler.h"
23 #include "acamera_profiler.h"
24 #endif
25 #include "acamera_logger.h"
26 #include "system_semaphore.h"
27 
28 extern fsm_common_t * sensor_get_fsm_common(uint8_t ctx_id);
29 extern fsm_common_t * cmos_get_fsm_common(uint8_t ctx_id);
30 extern fsm_common_t * crop_get_fsm_common(uint8_t ctx_id);
31 extern fsm_common_t * general_get_fsm_common(uint8_t ctx_id);
32 extern fsm_common_t * AE_get_fsm_common(uint8_t ctx_id);
33 extern fsm_common_t * AWB_get_fsm_common(uint8_t ctx_id);
34 extern fsm_common_t * color_matrix_get_fsm_common(uint8_t ctx_id);
35 extern fsm_common_t * iridix_get_fsm_common(uint8_t ctx_id);
36 extern fsm_common_t * noise_reduction_get_fsm_common(uint8_t ctx_id);
37 extern fsm_common_t * sharpening_get_fsm_common(uint8_t ctx_id);
38 extern fsm_common_t * matrix_yuv_get_fsm_common(uint8_t ctx_id);
39 extern fsm_common_t * gamma_manual_get_fsm_common(uint8_t ctx_id);
40 extern fsm_common_t * monitor_get_fsm_common(uint8_t ctx_id);
41 extern fsm_common_t * sbuf_get_fsm_common(uint8_t ctx_id);
42 extern fsm_common_t * dma_writer_get_fsm_common(uint8_t ctx_id);
43 extern fsm_common_t * metadata_get_fsm_common(uint8_t ctx_id);
44 extern fsm_common_t * AF_get_fsm_common(uint8_t ctx_id);
45 extern fsm_common_t *autocapture_get_fsm_common( uint8_t ctx_id );
46 
acamera_fsm_mgr_init(acamera_fsm_mgr_t * p_fsm_mgr)47 void acamera_fsm_mgr_init(acamera_fsm_mgr_t *p_fsm_mgr)
48 {
49     uint8_t idx;
50     fsm_init_param_t init_param;
51 
52     FUN_PTR_GET_FSM_COMMON fun_ptr_arr[] = {
53         sensor_get_fsm_common,
54         cmos_get_fsm_common,
55         crop_get_fsm_common,
56         general_get_fsm_common,
57         AE_get_fsm_common,
58         AWB_get_fsm_common,
59         color_matrix_get_fsm_common,
60         iridix_get_fsm_common,
61         noise_reduction_get_fsm_common,
62         sharpening_get_fsm_common,
63         matrix_yuv_get_fsm_common,
64         gamma_manual_get_fsm_common,
65         monitor_get_fsm_common,
66         sbuf_get_fsm_common,
67         dma_writer_get_fsm_common,
68         metadata_get_fsm_common,
69         AF_get_fsm_common,
70         autocapture_get_fsm_common,
71     };
72 
73     for(idx = 0; idx < FSM_ID_MAX; idx++)
74         p_fsm_mgr->fsm_arr[idx] = fun_ptr_arr[idx](p_fsm_mgr->ctx_id);
75 
76     if(number_of_event_ids>256)
77         LOG(LOG_CRIT,"Too much events in the system. Will not work correctly!");
78     acamera_event_queue_init(&(p_fsm_mgr->event_queue),p_fsm_mgr->event_queue_data,ACAMERA_EVENT_QUEUE_SIZE);
79 
80     init_param.p_fsm_mgr = p_fsm_mgr;
81     init_param.isp_base = p_fsm_mgr->isp_base;
82     for(idx = 0; idx < FSM_ID_MAX; idx++){
83         p_fsm_mgr->fsm_arr[idx]->ops.init(p_fsm_mgr->fsm_arr[idx]->p_fsm, &init_param);
84 
85     }
86     /* we can reload_isp_calibratons after all FSMs initialized */
87     acamera_fsm_mgr_set_param( p_fsm_mgr, FSM_PARAM_SET_RELOAD_CALIBRATION, NULL, 0 );
88 }
89 
acamera_fsm_mgr_deinit(acamera_fsm_mgr_t * p_fsm_mgr)90 void acamera_fsm_mgr_deinit(acamera_fsm_mgr_t *p_fsm_mgr)
91 {
92     uint8_t idx;
93 
94     acamera_event_queue_deinit(&(p_fsm_mgr->event_queue));
95 
96     for(idx = 0; idx < FSM_ID_MAX; idx++) {
97         if(p_fsm_mgr->fsm_arr[idx]->ops.deinit)
98             p_fsm_mgr->fsm_arr[idx]->ops.deinit(p_fsm_mgr->fsm_arr[idx]->p_fsm);
99     }
100 }
101 
acamera_fsm_mgr_process_interrupt(acamera_fsm_mgr_t * p_fsm_mgr,uint8_t irq_event)102 void acamera_fsm_mgr_process_interrupt(acamera_fsm_mgr_t *p_fsm_mgr,uint8_t irq_event)
103 {
104     uint8_t idx;
105 
106     for(idx = 0; idx < FSM_ID_MAX; idx++) {
107         if(p_fsm_mgr->fsm_arr[idx]->ops.proc_interrupt){
108 #if ACAMERA_ISP_PROFILING
109             acamera_profiler_start(idx+1);
110 #endif
111             p_fsm_mgr->fsm_arr[idx]->ops.proc_interrupt(p_fsm_mgr->fsm_arr[idx]->p_fsm, irq_event);
112 #if ACAMERA_ISP_PROFILING
113             acamera_profiler_stop(idx+1,0);
114 #endif
115         }
116     }
117 }
118 
119 static const char * const event_name[] = {
120     "event_id_WB_matrix_ready",
121     "event_id_acamera_reset_sensor_hw",
122     "event_id_ae_result_ready",
123     "event_id_ae_stats_ready",
124     "event_id_af_refocus",
125     "event_id_af_stats_ready",
126     "event_id_antiflicker_changed",
127     "event_id_awb_result_ready",
128     "event_id_awb_stats_ready",
129     "event_id_cmos_refresh",
130     "event_id_crop_changed",
131     "event_id_crop_updated",
132     "event_id_exposure_changed",
133     "event_id_frame_buf_reinit",
134     "event_id_frame_buffer_ds_ready",
135     "event_id_frame_buffer_fr_ready",
136     "event_id_frame_buffer_metadata",
137     "event_id_frame_end",
138     "event_id_gamma_lut_ready",
139     "event_id_gamma_new_param_ready",
140     "event_id_gamma_stats_ready",
141     "event_id_metadata_ready",
142     "event_id_metadata_update",
143     "event_id_monitor_frame_end",
144     "event_id_monitor_notify_other_fsm",
145     "event_id_new_frame",
146     "event_id_sensor_not_ready",
147     "event_id_sensor_ready",
148     "event_id_sensor_sw_reset",
149     "event_id_sharp_lut_update",
150     "event_id_update_iridix",
151     "event_id_update_sharp_lut",
152     "event_id_drop_frame",
153     "unknown"
154 };
155 
acamera_fsm_mgr_process_events(acamera_fsm_mgr_t * p_fsm_mgr,int n_max_events)156 void acamera_fsm_mgr_process_events(acamera_fsm_mgr_t *p_fsm_mgr,int n_max_events)
157 {
158     int n_event=0;
159     for(;;)
160     {
161         acamera_isp_interrupts_disable(p_fsm_mgr);
162         int event=acamera_event_queue_pop(&(p_fsm_mgr->event_queue));
163         acamera_isp_interrupts_enable(p_fsm_mgr);
164         if(event<0)
165         {
166             break;
167         }
168         else
169         {
170             event_id_t event_id=(event_id_t)(event);
171             uint8_t b_event_processed=0,b_processed;
172             uint8_t idx;
173             LOG(LOG_DEBUG,"Processing event: %d %s",event_id,event_name[event_id]);
174 
175             for(idx = 0; idx < FSM_ID_MAX; idx++) {
176                 if(p_fsm_mgr->fsm_arr[idx]->ops.proc_event) {
177 #if ACAMERA_ISP_PROFILING
178                     acamera_profiler_start(idx+1);
179 #endif
180                     b_processed = p_fsm_mgr->fsm_arr[idx]->ops.proc_event(p_fsm_mgr->fsm_arr[idx]->p_fsm, event_id);
181                     b_event_processed |= b_processed;
182 #if ACAMERA_ISP_PROFILING
183                     acamera_profiler_stop(idx+1,b_processed);
184 #endif
185                 }
186             }
187 
188             if(b_event_processed)
189             {
190                 ++n_event;
191                 if((n_max_events>0)&&(n_event>=n_max_events))
192                 {
193                     break;
194                 }
195             }
196         }
197     }
198 }
199 
200 
201