123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- /*
- *********************************************************************************************************
- * 函 数 名: main
- * 功能说明: c程序入口
- * 形 参:无
- * 返 回 值: 错误代码(无需处理)
- *********************************************************************************************************
- */
- #include "main.h"
- void DumpHEX(uint8_t *buffer, uint32_t len)
- {
- uint32_t i;
- printf("[DumpHEX]Length:%d ", len);
- for (i = 0; i < len; i++)
- {
- if (i % 16 == 0)
- printf("\r\n");
- else if (i % 8 == 0)
- printf(" ");
- else
- printf(":");
- printf("%02x", buffer[i]);
- }
- printf("\r\n");
- }
- int main(void)
- {
- #if 0
- /* 打开GOIOI 端口时钟 */
- *(unsigned int *)(0x40023800 + 0x30) |= (1 << 8);
- /* PI10 为输出 */
- *(unsigned int *)(0x40022000 + 0x00) &= ~((0x03) << (2 * 10));
- *(unsigned int *)(0x40022000 + 0x00) |= (1 << (2 * 10));
- /* PI10 输出高电平 */
- *(unsigned int *)(0x40022000 + 0x14) |= (1 << 10);
- /* PI10 输出低电平 */
- *(unsigned int *)(0x40022000 + 0x14) &= ~(1 << 10);
- #elif 0
- bsp_init();
- while (1)
- {
- GPIO_ResetBits(GPIOI, GPIO_Pin_10);
- Delay(0xFFFFFFFF);
- // GPIO_SetBits(GPIOI, GPIO_Pin_10);
- // Delay(0xFFFFFFFF);
- GPIO_ResetBits(GPIOF, GPIO_Pin_7);
- Delay(0xFFFFFF);
- // GPIO_SetBits(GPIOF, GPIO_Pin_7);
- // Delay(0xFFFFFF);
- GPIO_ResetBits(GPIOF, GPIO_Pin_8);
- Delay(0xFFFFFF);
- // GPIO_SetBits(GPIOF, GPIO_Pin_8);
- // Delay(0xFFFFFF);
- GPIO_ResetBits(GPIOC, GPIO_Pin_2);
- Delay(0xFFFFFF);
- // GPIO_SetBits(GPIOC, GPIO_Pin_2);
- // Delay(0xFFFFFF);
- };
- #elif 1
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
- OSInit();
- bsp_init();
- RegisterIec10x();
- /* init task */
- /* 创建一个启动任务(也就是主任务)。启动任务会创建所有的应用程序任务 */
- OSTaskCreateExt(init_task, /* 启动任务函数指针 */
- (void *)0, /* 传递给任务的参数 */
- (OS_STK *)&init_task_stk[INIT_STK_SIZE - 1], /* 指向任务栈栈顶的指针 */
- INIT_TASK_PRIO, /* 任务的优先级,必须唯一,数字越低优先级越高 */
- INIT_TASK_PRIO, /* 任务ID,一般和任务优先级相同 */
- (OS_STK *)&init_task_stk[0], /* 指向任务栈栈底的指针。OS_STK_GROWTH
- 决定堆栈增长方向 */
- INIT_STK_SIZE, /* 任务栈大小 */
- (void *)0, /* 一块用户内存区的指针,用于任务控制块TCB的扩展功能
- (如任务切换时保存CPU浮点寄存器的数据)。一般不用,填0即可 */
- OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR); /* 任务选项字 */
- OSStart();
- #endif
- }
- /*!
- \brief init task
- \param[in] pvParameters not used
- \param[out] none
- \retval none
- */
- void init_task(void *pvParameters)
- {
- SysTick_Config(SystemCoreClock / OS_TICKS_PER_SEC);
- /* configure the systick handler priority */
- NVIC_SetPriority(SysTick_IRQn, 0x00U);
- OSTaskCreateExt((void (*)(void *))misc_task, /* 启动任务函数指针 */
- (void *)0, /* 传递给任务的参数 */
- (OS_STK *)&misc_task_stk[MISC_TASK_STK_SIZE - 1], /* 指向任务栈栈顶的指针 */
- (INT8U)MISC_PRIO, /* 任务的优先级,必须唯一,数字越低优先级越高 */
- (INT16U)MISC_PRIO, /* 任务ID,一般和任务优先级相同 */
- (OS_STK *)&misc_task_stk[0], /* 指向任务栈栈底的指针。OS_STK_GROWTH 决定堆栈增长方向 */
- (INT32U)MISC_TASK_STK_SIZE, /* 任务栈大小 */
- (void *)0, /* 一块用户内存区的指针,用于任务控制块TCB的扩展功能
- (如任务切换时保存CPU浮点寄存器的数据)。一般不用,填0即可 */
- (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP); /* 任务选项字 */
- // OSTaskCreateExt((void (*)(void *))modbus_master_task,
- // (void *)0,
- // (OS_STK *)&uart1_task_stk[UART1_TASK_STK_SIZE - 1],
- // (INT8U)UART1_TASK_PRIO,
- // (INT16U)UART1_TASK_PRIO,
- // (OS_STK *)&uart1_task_stk[0],
- // (INT32U)UART1_TASK_STK_SIZE,
- // (void *)0,
- // (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
- /* 485 modbus从机模式 */
- OSTaskCreateExt((void (*)(void *))modbus_slave_task,
- (void *)0,
- (OS_STK *)&uart3_task_stk[UART3_TASK_STK_SIZE - 1],
- (INT8U)UART3_TASK_PRIO,
- (INT16U)UART3_TASK_PRIO,
- (OS_STK *)&uart3_task_stk[0],
- (INT32U)UART3_TASK_STK_SIZE,
- (void *)0,
- (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
- OSTaskCreateExt((void (*)(void *))net_task,
- (void *)0,
- (OS_STK *)&net_task_stk[NET_TASK_STK_SIZE - 1],
- (INT8U)NET_PRIO,
- (INT16U)NET_PRIO,
- (OS_STK *)&net_task_stk[0],
- (INT32U)NET_TASK_STK_SIZE,
- (void *)0,
- (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
- // /* ESP8266 STA任务*/
- // OSTaskCreateExt((void (*)(void *))esp_8266_task,
- // (void *)0,
- // (OS_STK *)&uart6_task_stk[UART6_TASK_STK_SIZE - 1],
- // (INT8U)UART6_TASK_PRIO,
- // (INT16U)UART6_TASK_PRIO,
- // (OS_STK *)&uart6_task_stk[0],
- // (INT32U)UART6_TASK_STK_SIZE,
- // (void *)0,
- // (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
- }
- void misc_task(void)
- {
- INT8U cnt = 0;
- INT16U save_cnt = 0;
- INT8U temperature;
- INT8U humidity;
- INT8U ret;
- INT8U key_state;
- AD7606_SetOS(AD_OS_NO); /* 无过采样 */
- AD7606_SetInputRange(0); /* 0表示输入量程为正负5V, 1表示正负10V */
- // bsp_StartAutoTimer(0, 500); /* 启动1个200ms的自动重装的定时器 */
- AD7606_ReadNowAdc(); /* 读取采样结果 */
- AD7606_StartConvst(); /* 启动1次转换 */
- while (1)
- {
- iwdg_feed(MISC_DOG);
- key_scan();
- key_state = key_get();
- if (key_state != KEY_NONE)
- {
- switch (key_state)
- {
- case KEY_1_UP:
- printf("1111111\r\n");
- break;
- case KEY_1_DOWN:
- printf("wwwwwwwwwwww\r\n");
- break;
- case KEY_1_LONG:
- printf("333333333\r\n");
- break;
- default:
- printf("44444444\r\n");
- break;
- }
- }
- if ((cnt % 10 == 0) && (cnt != 0))
- {
- // printf("%ld\r\n", NAND_ReadID());
- // printf("%c\r\n", NOR_ReadByte(0x4000));
- }
- if ((cnt % 25 == 0) && (cnt != 0))
- {
- // printf("%ld\r\n", NAND_ReadID());
- LED2_RUN_TOGGLE;
- }
- if ((cnt % 15 == 0) && (cnt != 0))
- {
- // if (NOR_EraseSector(0x4000) == 0)
- // {
- // NOR_WriteByte(0x4000, 0xFF);
- // }
- }
- if (cnt == 10)
- {
- // if (am2303_init())
- // {
- // printf("error\r\n");
- // }
- // else
- // {
- ret = am2303_read_data(&temperature, &humidity); //读取温湿度值
- // if (ret == 1)
- // {
- // printf("Temp: (%d).\n", temperature);
- // printf("Humi: (%d).\n", humidity);
- // }
- // else
- // {
- // printf("\r\n未发现DHT11温湿度传感器\r\n");
- // }
- // }
- }
- if (cnt >= 25)
- {
- /* 每隔500ms 进来一次. 由软件启动转换 */
- AD7606_ReadNowAdc(); /* 读取采样结果 */
- AD7606_StartConvst(); /* 启动下次转换 */
- cnt = 0; /* 刷新显示 */
- }
- else
- {
- cnt++;
- }
- if (save_cnt >= 25)
- {
- save_cnt = 0;
- }
- else
- {
- save_cnt++;
- }
- OSTimeDly(20);
- };
- }
|