69 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			69 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
|  | /****************************************************************************
 | ||
|  | 
 | ||
|  | Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED. | ||
|  | 
 | ||
|  | This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT | ||
|  | be copied by any method or incorporated into another program without | ||
|  | the express written consent of Aerospace C.Power. This Information or any portion | ||
|  | thereof remains the property of Aerospace C.Power. The Information contained herein | ||
|  | is believed to be accurate and Aerospace C.Power assumes no responsibility or | ||
|  | liability for its use in any way and conveys no license or title under | ||
|  | any patent or copyright and makes no representation or warranty that this | ||
|  | Information is free from patent or copyright infringement. | ||
|  | 
 | ||
|  | ****************************************************************************/ | ||
|  | 
 | ||
|  | #include "os_types.h"
 | ||
|  | #include "sec_cpu_utils.h"
 | ||
|  | #include "sec_cpu_timer.h"
 | ||
|  | #include "sec_cpu_crypto_share.h"
 | ||
|  | 
 | ||
|  | #define SEC_CPU_FSM_LOOP_US                     (10 * 1000)
 | ||
|  | 
 | ||
|  | #define SEC_CPU_FSM_EVENT_LOOP_TIMEOUT          (1 << 31)
 | ||
|  | 
 | ||
|  | typedef struct _sec_cpu_fsm { | ||
|  |     /* fsm loop timestamp */ | ||
|  |     uint32_t loop_ts; | ||
|  | } sec_cpu_fsm_t; | ||
|  | 
 | ||
|  | static sec_cpu_fsm_t g_sec_cpu_fsm = { 0 }; | ||
|  | 
 | ||
|  | static uint32_t sec_cpu_fsm_loop(uint32_t events) | ||
|  | { | ||
|  |     (void)events; | ||
|  | 
 | ||
|  |     sec_cpu_crypto_share_query(); | ||
|  | 
 | ||
|  |     return 0; | ||
|  | } | ||
|  | 
 | ||
|  | static uint32_t sec_cpu_fsm_event_wait(uint32_t timeout_us) | ||
|  | { | ||
|  |     uint32_t wait_time, ts; | ||
|  | 
 | ||
|  |     do { | ||
|  |         ts = sec_cpu_timer_sys_get(); | ||
|  |         wait_time = (uint32_t)(ts - g_sec_cpu_fsm.loop_ts); | ||
|  |     } while (wait_time < timeout_us); | ||
|  |     g_sec_cpu_fsm.loop_ts = ts; | ||
|  | 
 | ||
|  |     return SEC_CPU_FSM_EVENT_LOOP_TIMEOUT; | ||
|  | } | ||
|  | 
 | ||
|  | void sec_cpu_fsm_main(void) | ||
|  | { | ||
|  |     uint32_t events; | ||
|  | 
 | ||
|  |     for (;;) { | ||
|  |         events = sec_cpu_fsm_event_wait(SEC_CPU_FSM_LOOP_US); | ||
|  | 
 | ||
|  |         sec_cpu_fsm_loop(events); | ||
|  |     } | ||
|  | } | ||
|  | 
 | ||
|  | void sec_cpu_fsm_init(void) | ||
|  | { | ||
|  |     sec_cpu_crypto_share_init(); | ||
|  | } |