📄 controller.c
字号:
#endif /* HAVE_UPDATE */t_SongInfos current_song_info;t_SongInfos next_song_info;t_SongInfos *capturing_song_info; // pointer on the song info of buffering songt_SongInfos ESP_read_song_info; // reading from ESP song infot_child_cmd_event FS_XFER_command_event;static t_child_cmd_event PLY_XFER_command_event;static t_decoder_cmd_event CTR_decoder_cmd_event;static t_cap_cmd_event cap_cmd_event;#if (0 != HAVE_SDC) || (0 != HAVE_USB)static tQsubcode_event device_subcode;#endifstatic uint8 ctr_active_transitions;// controller's stop flags:static uint8 ctr_stop_flag;static uint8 ctr_internal_stop_flag = 0;//STTODO what is this story with stop. there are SIX FLAGS it can not work properly// used to stop STOPstatic uint8 ctr_stop_stop_flag = 0;static uint8 filesys_decoder_stop_flag = 0;static uint8 ctr_stop_stop_finished = 0;// used to cancel cmd with new onestruct{ UInt active_devices : 3; t_controlled_command cmd_CD; t_controlled_command cmd_USB; t_controlled_command cmd_SDC;} ctr_active_cmd = {0,(t_controlled_command)0,(t_controlled_command)0,(t_controlled_command)0};uint8 sector_errors = 0;uint8 sector_errors_limit = 0xff;// pausevolatile uint8 pause_active = 0;// fast seekstatic t_SearchParams Search;static t_SearchParams WriteSearch;static t_SearchParams NextSearch;static uint8 xfer_splitted_data_FSM;static uint8 xfer_splitted_CD_extent;//tagstatic uint8 tag_bitrate_valid = 0;//for FFstatic uint8 next_write_force_execution_flag = 0;//for reconf audio/data of capturestatic uint8 next_bd_type;static uint8 next_end_mode; // for cd data acquisition//not to send cmd to CAP sooner than READ READY is received from CAPstatic uint8 Read_Request_Pending = 0;//if player sends unforced cmd after unforced stop, then it is a must to make this cmd forced onestatic uint8 was_unforced_stop = 0;//not to send PRE EOS earlier than CTR is really able to receive new nonforced cmdstatic int8 BOS_PREEOS_pairing;//if CTR receives cmd for prebuffering (play_at/search_at) earlier than previous song//was fully buffered, till PRE EOS was sent to PLY static uint8 pre_buffering_active = 0;extern int16 update_file_index;#define CTR_READ_ERRORS_STOP 3//extern void WritePause(uint8 val);//#define WAIT_4_READ_READY 1//#define OT_DEBUG//#define CTR_PLY_DEBUG//#define CTR_CAP_DEBUGstatic struct{ t_SongInfos *xfile;} controller_tag_fsm_params;static struct{ DUID did; t_position start; uint8 *buffer; t_offset stop_offset;} controller_read_fsm_params;static struct{ int32 flags;} controller_stop_filesys_fsm_params;static struct{ uint8 task;} controller_CD_data_for_TASK_fsm_params;static struct{ UInt force_execution : 1;} controller_read_toc_fsm_params;#if (0 != HAVE_USB)static struct{ uint8 task;} controller_USB_data_for_TASK_fsm_params;#endif#if (0 != HAVE_SDC)static struct{ uint8 task;} controller_SDC_data_for_TASK_fsm_params;#endifstatic struct{ UInt search_mode : 1; //indication of FF UInt force_execution : 1; UInt pause : 1; UInt user_defined_start : 1; UInt unused : 28; DUID did; uint16 index; uint32 last_played_pos; uint8 end_mode; uint32 start_offset; t_SearchParams SearchParams;} controller_play_fsm_params;static struct{ uint32 force_execution; uint32 eof_notification; uint32 request_size; uint32 search_mode; //indication of FF uint32 start_offset; t_SearchParams SearchParams; uint8 cur_TNO; UInt dont_ignore_first_track_change : 1; UInt all_subcode_indexes_were_zero :1; UInt at_least_one_sector_buffered_in_ESP : 1;} controller_cd_extent_fsm_params;static struct{ UInt search_mode : 1; //indication of FF UInt first_non_zero_index_found : 1; UInt buffer_zero_sectors_2_FB : 1; UInt unused : 29; tTimeEvent_type event_type; t_SearchParams SearchParams;} controller_device_data_for_CTR_fsm_params;static struct{ t_duid did; UInt force_execution : 1;}controller_mount_fsm_params;static struct{ DUID did;}controller_stop_fsm_params;static struct{ UInt search_mode : 1; //indication of FF UInt pause : 1; UInt unused : 30; uint32 start_offset; t_fsm *capturing_fsm; DUID did; t_SearchParams SearchParams;} controller_CD_data_fsm_params;static struct{ uint32 force_execution; DUID did; uint32 search_mode; //indication of FF} controller_esp_fsm_params;#define TRACK_ENDTIME_FROM_DISC(x) (XAR_GetFileLBA(x) + XAR_FileTotalSize(x)) //- XAR_GetFileLBA(XAR_GetMinTrack(x)))#define TRACK_BEGINTIME_FROM_DISC(x) (XAR_GetFileLBA(x)) //- XAR_GetFileLBA(XAR_GetMinTrack(x)))#define SET_DEV_OF_CTR_STATUS(dev) (((dev)&0x7)<<16)#define SET_CMD_OF_CTR_STATUS(cmd) (((cmd)&0xF)<<19)#define SET_DEV_CMD_TYPE_OF_CTR_STATUS(dev,cmd) (SET_DEV_OF_CTR_STATUS(dev) \ | SET_CMD_OF_CTR_STATUS(cmd))#define GET_DEV_OF_CTR_STATUS(ctr_status) (((ctr_status)>>16)&0x7)#define GET_CMD_OF_CTR_STATUS(ctr_status) (((ctr_status)>>19)&0xF) #define SET_ACTIVE_DEV(dev) ((ctr_active_cmd.active_devices)|=(dev))#define CLEAR_ACTIVE_DEV(dev) ((ctr_active_cmd.active_devices)&=(~(dev)))#define IS_DEV_ACTIVE(dev) ((dev)&(ctr_active_cmd.active_devices)) #define GET_ACTIVE_DEV (ctr_active_cmd.active_devices)#define SET_CMD_FOR_DEV(cmd,dev) if((dev)==DEV_CD_ID) \ ctr_active_cmd.cmd_CD = (cmd); \ else if((dev)==DEV_USB_ID) \ ctr_active_cmd.cmd_USB = (cmd); \ else if((dev)==DEV_SDC_ID) \ ctr_active_cmd.cmd_SDC = (cmd);#define GET_CMD_FOR_DEV(dev) (((dev)==DEV_CD_ID) ? (ctr_active_cmd.cmd_CD) : \ ( ((dev)==DEV_USB_ID) ? (ctr_active_cmd.cmd_USB) : \ ( ((dev)==DEV_SDC_ID) ? (ctr_active_cmd.cmd_SDC) : CONTROLLER_CMD_NO ) ))#define GET_ACTIVE_DEV_FOR_CMD(cmd) ((((cmd)==ctr_active_cmd.cmd_CD)&&(IS_DEV_ACTIVE(DEV_CD_ID))) ? DEV_CD_ID : \ ( (((cmd)==ctr_active_cmd.cmd_USB)&&(IS_DEV_ACTIVE(DEV_USB_ID))) ? DEV_USB_ID : \ ( (((cmd)==ctr_active_cmd.cmd_SDC)&&(IS_DEV_ACTIVE(DEV_SDC_ID))) ? DEV_SDC_ID : DEV_NO_DEVICE ) ))#define IS_CMD_ACTIVE_ON_SOME_DEV(cmd) (((GET_CMD_FOR_DEV(DEV_CD_ID)==(cmd))&&(IS_DEV_ACTIVE(DEV_CD_ID))) \ ||((GET_CMD_FOR_DEV(DEV_USB_ID)==(cmd))&&(IS_DEV_ACTIVE(DEV_USB_ID))) \ ||((GET_CMD_FOR_DEV(DEV_SDC_ID)==(cmd))&&(IS_DEV_ACTIVE(DEV_SDC_ID)))) #define IS_XXX_AT_CMD(cmd) (((cmd) == CONTROLLER_CMD_PLAY_AT) \ || ((cmd) == CONTROLLER_CMD_SEARCH_AT) \ || ((cmd) == CONTROLLER_CMD_PAUSE_AT))#define IS_NOT_XXX_AT_CMD(cmd) (!IS_XXX_AT_CMD(cmd)) #ifdef QAC_CHECK#define CTR_PRINT(x)#else//#define CTR_PRINT(...) dprintf(__VA_ARGS__)#define CTR_PRINT(...) do{}while(0)#endifstatic void print_fsm(t_fsm *fsm){ /* if (fsm->name == NULL) { CTR_PRINT("null name\n"); } */ const uint8 fsm_dbg[][6] = { "IDLE", "RUN", "DONE", "ERROR", }; if ((fsm->state != fsm->dbgstate) || (fsm->transition != fsm->dbgtransition)) { fsm->dbgstate = fsm->state; fsm->dbgtransition = fsm->transition; CTR_PRINT("%s %s %d\n", fsm->name, fsm_dbg[fsm->state], fsm->transition); }}static void debug_fsm(void){ print_fsm(&controller_stop_device_fsm);#if (0 != HAVE_USB) print_fsm(&controller_USB_data_for_CTR_fsm); print_fsm(&controller_USB_data_for_TASK_fsm);#endif#if (0 != HAVE_SDC) print_fsm(&controller_SDC_data_for_CTR_fsm); print_fsm(&controller_SDC_data_for_TASK_fsm);#endif print_fsm(&controller_cd_extent_fsm); print_fsm(&controller_CD_data_for_CTR_fsm); print_fsm(&controller_CD_data_for_TASK_fsm); print_fsm(&controller_init_new_disc_fsm); print_fsm(&controller_read_toc_fsm); print_fsm(&controller_mount_fs_fsm); print_fsm(&controller_tag_fsm); print_fsm(&controller_stop_fsm);#if (0 != HAVE_SDC) print_fsm(&controller_stop_USB_fsm);#endif print_fsm(&controller_stop_CD_fsm);#if (0 != HAVE_SDC) print_fsm(&controller_stop_SDC_fsm);#endif print_fsm(&controller_data_fsm); print_fsm(&controller_play_fsm); print_fsm(&controller_stop_filesys_fsm); print_fsm(&controller_stop_decoder_fsm); print_fsm(&controller_wait_capture_fsm);#if (0 != HAVE_UPDATE) print_fsm(&controller_update_fsm);#endif /* HAVE_UPDATE */}void controller_enable_hw_text(void);uint8 get_bd_type_from_LBA(uint32 a){return 0;} void ctr_debug(void);void InitControllerTask(void){ FSM_init(&controller_init_new_disc_fsm ,"CTRL init_new_disc_fsm"); FSM_init(&controller_read_toc_fsm ,"CTRL read_toc_fsm"); FSM_init(&controller_mount_fs_fsm ,"CTRL mount_fs_fsm"); FSM_init(&controller_tag_fsm ,"CTRL tag_fsm"); FSM_init(&controller_play_fsm ,"CTRL play_fsm"); FSM_init(&controller_data_fsm ,"CTRL data_fsm"); FSM_init(&controller_esp_fsm ,"CTRL esp_fsm"); FSM_init(&controller_CD_data_for_CTR_fsm ,"CTRL CD_data_for_CTR_fsm"); FSM_init(&controller_cd_extent_fsm ,"CTRL cd_extent_fsm"); FSM_init(&controller_CD_data_for_TASK_fsm ,"CTRL CD_data_for_filesys_fsm");#if (0 != HAVE_USB) FSM_init(&controller_USB_data_for_CTR_fsm ,"CTRL USB_data_for_CTR_fsm"); FSM_init(&controller_USB_data_for_TASK_fsm,"CTRL USB_data_for_filesys_fsm");#endif#if (0 != HAVE_SDC) FSM_init(&controller_SDC_data_for_CTR_fsm ,"CTRL SDC_data_for_CTR_fsm"); FSM_init(&controller_SDC_data_for_TASK_fsm,"CTRL SDC_data_for_filesys_fsm");#endif /* HAVE_SDC */ FSM_init(&controller_wait_capture_fsm ,"CTRL wait_capture_fsm"); FSM_init(&controller_read_fsm ,"CTRL read_fsm"); FSM_init(&controller_stop_fsm ,"CTRL stop_fsm"); FSM_init(&controller_stop_filesys_fsm ,"CTRL stop_filesys_fsm"); FSM_init(&controller_stop_decoder_fsm ,"CTRL stop_decoder_fsm"); FSM_init(&controller_stop_USB_fsm ,"CTRL stop_USB_fsm"); FSM_init(&controller_stop_CD_fsm ,"CTRL stop_CD_fsm");#if (0 != HAVE_SDC) FSM_init(&controller_stop_SDC_fsm ,"CTRL stop_SDC_fsm");#endif /* HAVE_SDC */ FSM_init(&controller_stop_device_fsm ,"CTRL stop_device_fsm");#if (0 != HAVE_UPDATE) FSM_init(&controller_update_fsm ,"CTRL update_fsm");#endif /* HAVE_UPDATE */ current_song_info.xid = 0; current_song_info.devid = DEV_NO_DEVICE; capturing_song_info = ¤t_song_info; controller_CD_data_fsm_params.did = DEV_NO_DEVICE; FrameBufferInit(FRAME_BUFFER_ELEMENT_LENGTH);}// ***************************** FSM_activate & FSM_deactivate ******************************** //void FSM_deactivate(t_fsm *fsm, uint32 out_event){ if (fsm->state == FSM_RUN) { CTR_PRINT("FSM_deactivate %s %d %d\n", fsm->name, fsm->parent_notify, out_event); fsm->state = FSM_ERROR; if (fsm->parent_notify) { event_set_controller(out_event); } } //else no need to stop this fsm - it's already stopped. //else // fsm->state = FSM_IDLE;}void FSM_init(t_fsm *fsm, uint8 *name){ fsm->state = FSM_IDLE; fsm->name = name; fsm->dbgstate = FSM_IDLE; CTR_PRINT("FSM_init %s\n", fsm->name);}void FSM_activate(t_fsm *fsm, uint8 start_transition, uint8 parent_notify){ CTR_PRINT("FSM_activate %s %d %d\n", fsm->name, start_transition, parent_notify); fsm->state = FSM_RUN; fsm->transition = start_transition; fsm->parent_notify = parent_notify;}// *************************** determine device CTR is playing ***************************** //t_duid ctr_playing_device(void){ t_duid play_device; if (((play_device = GET_ACTIVE_DEV_FOR_CMD(CONTROLLER_CMD_PLAY_AT)) != DEV_NO_DEVICE) ||((play_device = GET_ACTIVE_DEV_FOR_CMD(CONTROLLER_CMD_SEARCH_AT)) != DEV_NO_DEVICE) ||((play_device = GET_ACTIVE_DEV_FOR_CMD(CONTROLLER_CMD_PAUSE_AT)) != DEV_NO_DEVICE)) { // this condition covers the time interval between accepting PLAY cmd // from Player till time when current_song_info.devid is set in ctr_data_fsm() return play_device;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -