| 1 | |
|---|
| 2 | #include "cc_config.h" |
|---|
| 3 | #include "cc_type.h" |
|---|
| 4 | #include "cc_def.h" |
|---|
| 5 | #include "cc_private.h" |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | /*config*/ |
|---|
| 9 | |
|---|
| 10 | #define MAX_NUM_USER_MSGQ (CC_NUM_PIC_USER_Q+8) |
|---|
| 11 | //user message°¡ Àֱ⠶§¹®¿¡ 8À» ´õ Ãß°¡ÇÔ |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | /* variables */ |
|---|
| 15 | |
|---|
| 16 | static struct { |
|---|
| 17 | |
|---|
| 18 | tDCCDDI_MSGQ p_user_msgq_id; |
|---|
| 19 | tDCCDDI_SEM p_sync_mtx_id; |
|---|
| 20 | tDCCDDI_SEM p_sync_sem_id; |
|---|
| 21 | |
|---|
| 22 | int num_msgq; |
|---|
| 23 | |
|---|
| 24 | struct { |
|---|
| 25 | UINT32 duration; //ms ´ÜÀ§ |
|---|
| 26 | UINT32 start_ms; |
|---|
| 27 | UINT32 prev_ms; |
|---|
| 28 | UINT32 opt; |
|---|
| 29 | } timer_list[MAX_NUM_TIMER]; |
|---|
| 30 | |
|---|
| 31 | BOOL buser_msg_on; |
|---|
| 32 | BOOL brst_ready; |
|---|
| 33 | |
|---|
| 34 | } p_main_attr; |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | #define ATTR(i) p_main_attr.i |
|---|
| 39 | |
|---|
| 40 | static BOOL b_cc_main_inited=FALSE; |
|---|
| 41 | |
|---|
| 42 | #if 0 |
|---|
| 43 | __Local_Func__() {} |
|---|
| 44 | #endif |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | static void p_proc_user_data(tDCC_PicUDRaw *praw_pud) |
|---|
| 48 | { |
|---|
| 49 | tDCC_CMD send_msg; |
|---|
| 50 | |
|---|
| 51 | if(!ATTR(p_user_msgq_id) || !ATTR(buser_msg_on)) return; |
|---|
| 52 | |
|---|
| 53 | send_msg.cmd=eCMD_USER_DATA; |
|---|
| 54 | send_msg.opt=0; |
|---|
| 55 | send_msg.param1=(UINT32)praw_pud; |
|---|
| 56 | send_msg.param2=0; |
|---|
| 57 | |
|---|
| 58 | CCPRINT("send_ud", "sending user data, pic_type: %d, pts : %ud, size: %d\n", |
|---|
| 59 | praw_pud->pic_type, |
|---|
| 60 | praw_pud->data, |
|---|
| 61 | praw_pud->size); |
|---|
| 62 | |
|---|
| 63 | if(DCCExec_IsCurDLY()) { |
|---|
| 64 | |
|---|
| 65 | //pud °Ë»öÇØ¼ DLC¸¦ ã¾Æ¾ß ÇÔ. |
|---|
| 66 | UINT8 *buf=praw_pud->data; |
|---|
| 67 | int i; |
|---|
| 68 | BOOL bdlc_send=FALSE; |
|---|
| 69 | |
|---|
| 70 | for(i=0; i<(buf[5]&0x1f); i++) { |
|---|
| 71 | |
|---|
| 72 | if(7+i*3+2>=praw_pud->size) { |
|---|
| 73 | break; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | if((buf[7+i*3]&0x3)==0x3) { |
|---|
| 77 | |
|---|
| 78 | if(buf[7+i*3+2]==0x8E) { //DLC |
|---|
| 79 | DCCExec_ProcessMsg(eCMD_DLC, 0, 0, 0); //delay cancelÀ» ³¯¸². |
|---|
| 80 | bdlc_send=TRUE; |
|---|
| 81 | } |
|---|
| 82 | else if(buf[7+i*3+2]==0x8F) { //RST |
|---|
| 83 | DCCExec_ProcessMsg(eCMD_DLC, 0, 0, 0); //delay cancelÀ» ³¯¸². |
|---|
| 84 | bdlc_send=TRUE; |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | else if((buf[7+i*3]&0x3)==0x2) { |
|---|
| 88 | |
|---|
| 89 | if(buf[7+i*3+1]==0x8E || buf[7+i*3+2]==0x8E) { //DLC |
|---|
| 90 | DCCExec_ProcessMsg(eCMD_DLC, 0, 0, 0); //delay cancelÀ» ³¯¸². |
|---|
| 91 | bdlc_send=TRUE; |
|---|
| 92 | } |
|---|
| 93 | else if(buf[7+i*3+1]==0x8F || buf[7+i*3+2]==0x8F) { //RST |
|---|
| 94 | DCCExec_ProcessMsg(eCMD_DLC, 0, 0, 0); //delay cancelÀ» ³¯¸². |
|---|
| 95 | bdlc_send=TRUE; |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | if(!bdlc_send && ATTR(num_msgq)>=CC_NUM_PIC_USER_Q*2/3) { |
|---|
| 101 | DCCExec_ProcessMsg(eCMD_DLC, 0, 0, 0); //delay cancelÀ» ³¯¸². |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | DCCDDI_SendMessage(ATTR(p_user_msgq_id), &send_msg, sizeof(send_msg)); |
|---|
| 107 | ATTR(num_msgq)++; |
|---|
| 108 | |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | #if 0 |
|---|
| 113 | __Task__() {} |
|---|
| 114 | #endif |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | static void p_cc_task(UINT32 arg) |
|---|
| 118 | { |
|---|
| 119 | int ret; |
|---|
| 120 | int rcv_len; |
|---|
| 121 | int i; |
|---|
| 122 | |
|---|
| 123 | tDCC_PicUDRaw *pic_ud_raw=NULL, *pic_ud_buf=NULL; |
|---|
| 124 | //pic_ud_buf´Â reorderingÀ» À§ÇØ ÇÊ¿äÇÔ. |
|---|
| 125 | tDCC_PicUD pic_ud; |
|---|
| 126 | tDCC_CMD user_msg; |
|---|
| 127 | |
|---|
| 128 | while(1) |
|---|
| 129 | { |
|---|
| 130 | |
|---|
| 131 | //±ú¾î³¯ ½Ã°¢ °è»ê |
|---|
| 132 | int min_ms=0x7fffffff; |
|---|
| 133 | // int min_id=MAX_NUM_TIMER; |
|---|
| 134 | //±ú¾î³¯ ½Ã°£ °è»ê |
|---|
| 135 | for(i=0; i<MAX_NUM_TIMER; i++) { |
|---|
| 136 | if(ATTR(timer_list)[i].duration==TIMER_NOUSE) continue; |
|---|
| 137 | |
|---|
| 138 | if(ATTR(timer_list)[i].prev_ms+ATTR(timer_list)[i].duration<min_ms) { |
|---|
| 139 | min_ms=ATTR(timer_list)[i].prev_ms+ATTR(timer_list)[i].duration; |
|---|
| 140 | // min_id=i; |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | #if 1//BKTEST |
|---|
| 144 | DHL_OS_Delay(100); |
|---|
| 145 | #endif |
|---|
| 146 | if(DCCExec_IsCurDLY()) { |
|---|
| 147 | ret=-1; |
|---|
| 148 | |
|---|
| 149 | DCCDDI_Delay(10); |
|---|
| 150 | } else if(min_ms==0x7fffffff) |
|---|
| 151 | ret=DCCDDI_ReceiveMessage(ATTR(p_user_msgq_id), &user_msg, sizeof(user_msg), &rcv_len); |
|---|
| 152 | else { |
|---|
| 153 | min_ms-=DCCDDI_GetCurMs(); |
|---|
| 154 | if(min_ms<0) min_ms=0; |
|---|
| 155 | ret=DCCDDI_ReceiveMessage_Wait(ATTR(p_user_msgq_id), &user_msg, sizeof(user_msg), &rcv_len, min_ms); |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | if((ret==0) && b_cc_main_inited) { //»ç¿ëÀÚ data°¡ ÀÖ´Â °æ¿ì. |
|---|
| 159 | |
|---|
| 160 | switch(user_msg.cmd) { |
|---|
| 161 | |
|---|
| 162 | case eCMD_USER_DATA : |
|---|
| 163 | |
|---|
| 164 | ATTR(num_msgq)--; |
|---|
| 165 | |
|---|
| 166 | if(ATTR(num_msgq)>=0 && ATTR(num_msgq)<CC_NUM_PIC_USER_Q) { |
|---|
| 167 | //¿¹¿Ü »óȲÀÌ ¹ß»ýÇÑ °æ¿ìÀÓ..ÀÌ °æ¿ì´Â ÃʱâÈ. |
|---|
| 168 | if(ATTR(num_msgq)<CC_NUM_PIC_USER_Q/2) |
|---|
| 169 | DCCGrp_SetScrollSpeed(CC_SCROLL_DELAY1, CC_SCROLL_SLICE1); |
|---|
| 170 | else if(ATTR(num_msgq)<CC_NUM_PIC_USER_Q*2/3) |
|---|
| 171 | DCCGrp_SetScrollSpeed(CC_SCROLL_DELAY2, CC_SCROLL_SLICE2); |
|---|
| 172 | else if(ATTR(num_msgq)<CC_NUM_PIC_USER_Q*3/4) |
|---|
| 173 | DCCGrp_SetScrollSpeed(CC_SCROLL_DELAY3, CC_SCROLL_SLICE3); |
|---|
| 174 | else |
|---|
| 175 | DCCGrp_SetScrollSpeed(CC_SCROLL_DELAY4, CC_SCROLL_SLICE4); |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | pic_ud_raw=(tDCC_PicUDRaw *)user_msg.param1; |
|---|
| 179 | //reordering ¼öÇà |
|---|
| 180 | |
|---|
| 181 | #if 1 |
|---|
| 182 | CCPRINT("parse_ud", "user data coming, pic_type: %d, pts : %ud, size: %d\n", |
|---|
| 183 | pic_ud_raw->pic_type, |
|---|
| 184 | pic_ud_raw->data, |
|---|
| 185 | pic_ud_raw->size); |
|---|
| 186 | #else |
|---|
| 187 | CCPRINT("parse_ud", "user data coming, pic_type(%d) !!\n", pic_ud_raw->pic_type); |
|---|
| 188 | #endif |
|---|
| 189 | |
|---|
| 190 | #if 1 // reordering ÇÊ¿äÇÑ °æ¿ì //adjust in cc ddi |
|---|
| 191 | if(pic_ud_raw->pic_type==eDCC_PIC_CT_I || pic_ud_raw->pic_type==eDCC_PIC_CT_P) { |
|---|
| 192 | if(pic_ud_buf) { |
|---|
| 193 | //Ȥ½Ã backupÀ» ÇØ ³õÀº °ÍÀÌ ÀÖÀ¸¸é ½ÇÇàÇÔ. |
|---|
| 194 | DCCFront_ParsePicUD(pic_ud_buf, &pic_ud); |
|---|
| 195 | pic_ud_buf=NULL; |
|---|
| 196 | } |
|---|
| 197 | //backup |
|---|
| 198 | pic_ud_buf=pic_ud_raw; |
|---|
| 199 | } |
|---|
| 200 | else { |
|---|
| 201 | DCCFront_ParsePicUD(pic_ud_raw, &pic_ud); |
|---|
| 202 | } |
|---|
| 203 | #else // reordering ¾È ÇÏ´Â °æ¿ì |
|---|
| 204 | DCCFront_ParsePicUD(pic_ud_raw, &pic_ud); |
|---|
| 205 | |
|---|
| 206 | pic_ud_raw->isUsing = 0; |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | #endif |
|---|
| 210 | break; |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | case eCMD_SET_TIMER : |
|---|
| 214 | if(user_msg.param1<MAX_NUM_TIMER) { |
|---|
| 215 | CCPRINT("time", "timer set(timer id:%d, duration:%d ms)\n", user_msg.param1, user_msg.param2); |
|---|
| 216 | ATTR(timer_list)[user_msg.param1].duration=user_msg.param2; |
|---|
| 217 | ATTR(timer_list)[user_msg.param1].opt=user_msg.opt; |
|---|
| 218 | ATTR(timer_list)[user_msg.param1].prev_ms=DCCDDI_GetCurMs(); |
|---|
| 219 | ATTR(timer_list)[user_msg.param1].start_ms=DCCDDI_GetCurMs(); |
|---|
| 220 | } |
|---|
| 221 | break; |
|---|
| 222 | |
|---|
| 223 | case eCMD_TIMER_RESET : |
|---|
| 224 | for(i=0; i<MAX_NUM_TIMER; i++) ATTR(timer_list)[i].duration=TIMER_NOUSE; |
|---|
| 225 | |
|---|
| 226 | break; |
|---|
| 227 | |
|---|
| 228 | case eCMD_USER_SET_SERVICE : |
|---|
| 229 | DCCFront_SetService(user_msg.param1); |
|---|
| 230 | DCCExec_ProcessMsg((tDCC_CmdSet)user_msg.cmd, user_msg.opt, user_msg.param1, user_msg.param2); |
|---|
| 231 | break; |
|---|
| 232 | |
|---|
| 233 | case eCMD_USER_SET_FEEDING : |
|---|
| 234 | DCCFront_SetFeeding608(user_msg.param1); |
|---|
| 235 | break; |
|---|
| 236 | |
|---|
| 237 | case eCMD_SYNC : |
|---|
| 238 | DCCDDI_GiveSemaphore(ATTR(p_sync_sem_id)); |
|---|
| 239 | break; |
|---|
| 240 | |
|---|
| 241 | default : |
|---|
| 242 | DCCExec_ProcessMsg((tDCC_CmdSet)user_msg.cmd, user_msg.opt, user_msg.param1, user_msg.param2); |
|---|
| 243 | } |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | for(i=0; i<MAX_NUM_TIMER; i++) { |
|---|
| 247 | if(ATTR(timer_list)[i].duration==TIMER_NOUSE) continue; |
|---|
| 248 | |
|---|
| 249 | if(CC_MS_PASS(ATTR(timer_list)[i].prev_ms) > ATTR(timer_list)[i].duration) { |
|---|
| 250 | DCCExec_ProcessMsg(eCMD_TIMER, 0, i, CC_MS_PASS(ATTR(timer_list)[i].start_ms)); |
|---|
| 251 | |
|---|
| 252 | ATTR(timer_list)[i].prev_ms=DCCDDI_GetCurMs(); |
|---|
| 253 | |
|---|
| 254 | if(ATTR(timer_list)[i].opt & eDCC_OPT_TIMER_ONESHOT) { |
|---|
| 255 | ATTR(timer_list)[i].duration=TIMER_NOUSE; |
|---|
| 256 | } |
|---|
| 257 | } |
|---|
| 258 | } |
|---|
| 259 | } |
|---|
| 260 | DHL_OS_SelfDeleteTask(); |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | #if 0 |
|---|
| 265 | __APIs__() {} |
|---|
| 266 | #endif |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | void DCCMain_Init() |
|---|
| 270 | { |
|---|
| 271 | int i; |
|---|
| 272 | |
|---|
| 273 | if(!b_cc_main_inited) { |
|---|
| 274 | |
|---|
| 275 | for(i=0; i<MAX_NUM_TIMER; i++) ATTR(timer_list)[i].duration=TIMER_NOUSE; |
|---|
| 276 | //ÃʱâÈ ÀÛ¾÷. |
|---|
| 277 | ATTR(p_user_msgq_id)=DCCDDI_CreateMessageQueue("cc exec", MAX_NUM_USER_MSGQ, sizeof(tDCC_CMD)); |
|---|
| 278 | ATTR(p_sync_mtx_id)=DCCDDI_CreateMutexSemaphore("cc mtx"); |
|---|
| 279 | ATTR(p_sync_sem_id)=DCCDDI_CreateBinarySemaphore("cc sem"); |
|---|
| 280 | //task »ý¼º |
|---|
| 281 | DCCDDI_SpawnTask((void *)p_cc_task); |
|---|
| 282 | |
|---|
| 283 | DCCDDI_SetUserCallback((tDCC_UserCallback)p_proc_user_data); |
|---|
| 284 | |
|---|
| 285 | ATTR(buser_msg_on)=TRUE; |
|---|
| 286 | |
|---|
| 287 | ATTR(num_msgq)=0; |
|---|
| 288 | |
|---|
| 289 | b_cc_main_inited=TRUE; |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | void DCCMain_ResetQueue(void) |
|---|
| 295 | { |
|---|
| 296 | tDCC_CMD user_msg; |
|---|
| 297 | int rcv_len; |
|---|
| 298 | |
|---|
| 299 | DCCMain_UserMsgOnOff(FALSE); |
|---|
| 300 | |
|---|
| 301 | while(DCCDDI_ReceiveMessage_NoWait(ATTR(p_user_msgq_id), &user_msg, |
|---|
| 302 | sizeof(user_msg), &rcv_len)==0) |
|---|
| 303 | { |
|---|
| 304 | //Ȥ½Ã syncµµ ³¯·Á¹ö¼ blockingÀÌ °É¸®´Â °æ¿ì°¡ ÀÖÀ» °Í °°¾Æ¼ ¾Æ·¡ ÄÚµå Ãß°¡ÇÔ. |
|---|
| 305 | if(user_msg.cmd==eCMD_SYNC) |
|---|
| 306 | DCCDDI_GiveSemaphore(ATTR(p_sync_sem_id)); |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | ATTR(num_msgq)=0; |
|---|
| 310 | |
|---|
| 311 | DCCMain_UserMsgOnOff(TRUE); |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | void DCCMain_UserMsgOnOff(BOOL bon) |
|---|
| 315 | { |
|---|
| 316 | //user message Áß´Ü/½ÃÀÛ. |
|---|
| 317 | ATTR(buser_msg_on)=bon; |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | void DCCMain_SendCmd(UINT8 cmd, UINT32 opt, UINT32 param1, UINT32 param2) |
|---|
| 322 | { |
|---|
| 323 | tDCC_CMD send_msg; |
|---|
| 324 | if(!b_cc_main_inited) return; |
|---|
| 325 | if(!ATTR(p_user_msgq_id)) return; |
|---|
| 326 | |
|---|
| 327 | if(!ATTR(buser_msg_on) && cmd==eCMD_USER_DATA) return; |
|---|
| 328 | //msg offÀ̰í userdata typeÀ̸é ó¸® ¾ÈÇÔ |
|---|
| 329 | |
|---|
| 330 | if(cmd==eCMD_SYNC) { |
|---|
| 331 | opt|=eDCC_OPT_SYNC; |
|---|
| 332 | } |
|---|
| 333 | else { |
|---|
| 334 | send_msg.cmd=cmd; |
|---|
| 335 | send_msg.opt=opt; |
|---|
| 336 | send_msg.param1=param1; |
|---|
| 337 | send_msg.param2=param2; |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | if(opt&eDCC_OPT_SYNC) { |
|---|
| 341 | |
|---|
| 342 | DCCDDI_TakeSemaphore(ATTR(p_sync_mtx_id)); |
|---|
| 343 | |
|---|
| 344 | if(cmd!=eCMD_SYNC) { |
|---|
| 345 | DCCDDI_SendMessage(ATTR(p_user_msgq_id), &send_msg, sizeof(send_msg)); |
|---|
| 346 | if(cmd==eCMD_USER_DATA) { |
|---|
| 347 | ATTR(num_msgq)++; |
|---|
| 348 | } |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | send_msg.cmd=eCMD_SYNC; |
|---|
| 352 | send_msg.opt=0; |
|---|
| 353 | send_msg.param1=0; |
|---|
| 354 | send_msg.param2=0; |
|---|
| 355 | |
|---|
| 356 | DCCDDI_SendMessage(ATTR(p_user_msgq_id), &send_msg, sizeof(send_msg)); |
|---|
| 357 | |
|---|
| 358 | DCCDDI_TakeSemaphore(ATTR(p_sync_sem_id)); |
|---|
| 359 | |
|---|
| 360 | DCCDDI_GiveSemaphore(ATTR(p_sync_mtx_id)); |
|---|
| 361 | } |
|---|
| 362 | else { |
|---|
| 363 | DCCDDI_SendMessage(ATTR(p_user_msgq_id), &send_msg, sizeof(send_msg)); |
|---|
| 364 | if(cmd==eCMD_USER_DATA) { |
|---|
| 365 | ATTR(num_msgq)++; |
|---|
| 366 | } |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | |
|---|
| 373 | /* end of file */ |
|---|