创建任务:
void taskstart (void *pdata) { extern struct netif lwip_netif; #if OS_CRITICAL_METHOD == 3 /* status register */ OS_CPU_SR cpu_sr; #endif targetInit(); my_lwip_init(); OSTaskCreate(stellarisif_input, (void *)&lwip_netif, &taskinput_stack[taskinputstck - 1], TASK_INPUT_PRIO); OSTaskCreate(httpd_thread, (void *)0, &tasklwip_stack[tasklwipstck - 1], TASK_LWIP_PRIO); /* OSTaskCreate(TCP_Client, (void *)0, &taskTCP_Client[taskTCPClient - 1], TASK_TCP_Client_PRIO); */ OSTaskCreate(Task_RS485_0, (void *)0, &taskTask_RS485_0[taskTask_RS485_0stck - 1], TASK_RS485_0_PRIO); OSTaskCreate(Task_DataProcess, (void *)0, &taskTask_DataProcess[taskTask_DataProcessstck - 1], TASK_DataProcess_PRIO); OSTaskCreate(Task_ReadCard, (void *)0, &taskTask_ReadCard[taskTask_ReadCardstck - 1], TASK_ReadCard_PRIO); OSTaskCreate(Task_I2C, (void *)0, &taskTask_I2C[taskTask_I2Cstck - 1], TASK_I2C_PRIO); OSTaskCreate(Identify_main, (void *)0, &taskIdentify_main[taskIdentify_mainstck - 1], TASK_Identify_main_PRIO); while(1){OSTaskSuspend(0); } }
被挂起的任务:
void Task_I2C(){ unsigned char *rd_addr=0,m_err=0,port=0,i2c_rd_dat=0,Alarm_port_data=0; unsigned char U2_State=0,U3_State=0; I2C_ADDR act_addr; I2C_PORT act_port; unsigned char act_dat; PCA9534Read(PAC9534_U2, &U2_State); PCA9534Read(PAC9534_U3, &U3_State); find_input_port(0,0xff,U2_State); OSTimeDly(10); find_input_port(1,0xff,U3_State); while(1) { Uart1Send("0...\n",5); rd_addr = OSQPend(Rd_i2c_Q,5000,&m_err); Uart1Send("1...\n",5); if(m_err == OS_NO_ERR) { Uart1Send("2...\n",5); switch(*rd_addr) { case PAC9534_U2: Uart1Send("3...\n",5); OSTimeDly(2); PCA9534Read(PAC9534_U2, &RD_I2C_data); port = RD_I2C_data^U2_State; U2_State = RD_I2C_data; if(port) //有信号变化 find_input_port(0,port,U2_State); break; case PAC9534_U3: Uart1Send("4...\n",5); OSTimeDly(2); PCA9534Read(PAC9534_U3, &RD_I2C_data); port = RD_I2C_data^U3_State; U3_State = RD_I2C_data; if((port)) //有信号变化 find_input_port(1,port,U3_State); break; case Act_Set_Time: Uart1Send("5...\n",5); PCF8583_SetTime(Time_buf); break; case Act_RELAY_Q: Uart1Send("6...\n",5); while(NULL != read_i2c_queue(&act_addr,&act_port,&act_dat)) { PCA9534Read(act_addr,&i2c_rd_dat); if(0 == act_dat)i2c_rd_dat = i2c_rd_dat & (~act_port); else if(1 == act_dat)i2c_rd_dat = i2c_rd_dat | act_port; PCA9534Write(act_addr,i2c_rd_dat); } break; case Get_TIME_Q: //1s 时钟节拍 Uart1Send("7...\n",5); PCF8583_GetSYSTime(&System_RTC);//获取时间,
write_queue_and_send(ONE_SENDCOND_CLK,0,0); //发送 1s 的时钟节拍同步信号 ALARM_scan_time_cnt++; //扫描报警输入口的状态 if(ALARM_scan_time_cnt >= ALARM_SCAN_TIME_OUT) { PCA9534Read(PAC9534_U2, &Alarm_port_data); find_input_port(0,PORT_6 | PORT_7,Alarm_port_data); // OSTimeDly(1); PCA9534Read(PAC9534_U3, &Alarm_port_data); find_input_port(1,PORT_6 | PORT_7,Alarm_port_data); ALARM_scan_time_cnt = 0; } break; } } else Uart1Send("8...\n",5); }}
void GPIO_Port_E_ISR(void){ unsigned long ulStatus; OS_ENTER_CRITICAL(); ulStatus = GPIOPinIntStatus(PCA9534_INT_PORT , true); // 读取中断状态 GPIOPinIntClear(PCA9534_INT_PORT , ulStatus); // 清除中断状态,重要 if(ulStatus & PCA9534U2_INT_PIN)// 如果PG5的中断状态有效 { OSQPost(Rd_i2c_Q , &i2c_u); Uart1Send("10...\n",6); } if(ulStatus & PCA9534U3_INT_PIN) { OSQPost(Rd_i2c_Q , &i3c_u); Uart1Send("11...\n",6); } OS_EXIT_CRITICAL(); OSIntExit();}
工程很大,没法全部粘帖上来。
[ 本帖最后由 yonglin503 于 2011-5-7 18:11 编辑 ]