首页 > 评测 > 【AutoChips 7801x MCU评测报告】+串口nr_micro_shell移植测试
【AutoChips 7801x MCU评测报告】+串口nr_micro_shell移植测试
- [导读]
- 移植了一个串口shell程序nr_micro_shell。顺便测试了I2C接口的读写AT24Cxx。移植很简单,主要在nr_micro_shell_config.h文件内配置,以及串口发送接收函数。主函数main内初始化
移植了一个串口shell程序nr_micro_shell。顺便测试了I2C接口的读写AT24Cxx。移植很简单,主要在nr_micro_shell_config.h文件内配置,以及串口发送接收函数。主函数main内初始化和接收串口数据处理。
代码如下:
- /*************<include>****************/
- #include "string.h"
- #include "ac780x.h"
- #include "system_ac780x.h"
- #include "ac780x_gpio.h"
- #include "ac780x_uart.h"
- #include "elog.h"
- #include "nr_micro_shell.h"
- #include "i2c.h"
- /*************<macro>******************/
- #define LED2_PORT (GPIOC)
- #define LED2_PIN (GPIO_PIN9)
- #define LED3_PORT (GPIOC)
- #define LED3_PIN (GPIO_PIN7)
- #define LED2_ON() do{GPIO_SetPinLevel(LED2_PORT, LED2_PIN, GPIO_LEVEL_HIGH);}while(0)
- #define LED2_OFF() do{GPIO_SetPinLevel(LED2_PORT, LED2_PIN, GPIO_LEVEL_LOW);}while(0)
- #define LED2_TOGGLE() do{if(GPIO_GetPinLevel(LED2_PORT, LED2_PIN)){LED2_OFF;}else{LED2_ON;}}while(0)
- #define LED3_ON() do{GPIO_SetPinLevel(LED3_PORT, LED3_PIN, GPIO_LEVEL_HIGH);}while(0)
- #define LED3_OFF() do{GPIO_SetPinLevel(LED3_PORT, LED3_PIN, GPIO_LEVEL_LOW);}while(0)
- #define LED3_TOGGLE() do{if(GPIO_GetPinLevel(LED3_PORT, LED3_PIN)){LED3_OFF;}else{LED3_ON;}}while(0)
- /*************<enum>*******************/
- /*************<union>******************/
- /*************<struct>*****************/
- /*************<variable>***************/
- /*************<prototype>**************/
- void shell_ls_cmd(char argc, char *argv)
- {
- unsigned int i = 0;
- if (argc > 1)
- {
- if (!strcmp("cmd", &argv[argv[1]]))
- {
- for (i = 0; nr_shell.static_cmd[i].fp != NULL; i++)
- {
- shell_printf(nr_shell.static_cmd[i].cmd);
- shell_printf("\r\n");
- }
- }
- else if (!strcmp("-v", &argv[argv[1]]))
- {
- shell_printf("ls version 1.0.\r\n");
- }
- else if (!strcmp("-h", &argv[argv[1]]))
- {
- shell_printf("useage: ls [options]\r\n");
- shell_printf("options: \r\n");
- shell_printf("\t -h \t: show help\r\n");
- shell_printf("\t -v \t: show version\r\n");
- shell_printf("\t cmd \t: show all commands\r\n");
- }
- }
- else
- {
- shell_printf("ls need more arguments!\r\n");
- }
- }
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] test command
- */
- void shell_test_cmd(char argc, char *argv)
- {
- unsigned int i;
- shell_printf("test command:\r\n");
- for (i = 0; i < argc; i++)
- {
- shell_printf("paras %d: %s\r\n", i, &(argv[argv[i]]));
- }
- }
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] test command
- */
- void shell_led_cmd(char argc, char *argv)
- {
- if (argc > 1)
- {
- if (!strcmp("on", &argv[argv[1]]))
- {
- if (!strcmp("1", &argv[argv[2]]))
- {
- LED2_ON();
- }else if (!strcmp("2", &argv[argv[2]]))
- {
- LED3_ON();
- }else
- {
- shell_printf("useage: led [on/off] [1/2/3/4]\r\n");
- }
- }else if (!strcmp("off", &argv[argv[1]]))
- {
- if (!strcmp("1", &argv[argv[2]]))
- {
- LED2_OFF();
- }else if (!strcmp("2", &argv[argv[2]]))
- {
- LED3_OFF();
- }else
- {
- shell_printf("useage: led [on/off] [1/2/3/4]\r\n");
- }
- }else{
- shell_printf("useage: led [on/off] [1/2/3/4]\r\n");
- }
- }
- }
- void at24cxx_cmd(char argc, char *argv)
- {
- if (argc > 1)
- {
- if (!strcmp("read", &argv[argv[1]]))
- {
- I2C_RdDataFromAT24C();
- }else if (!strcmp("write", &argv[argv[1]]))
- {
- I2C_WrDataToAT24C();
- }else{
- shell_printf("useage: at24 [read/write] \r\n");
- }
- }else{
- shell_printf("useage: at24 [read/write] \r\n");
- }
- }
- NR_SHELL_CMD_EXPORT(at24, at24cxx_cmd);
- #ifdef NR_SHELL_USING_EXPORT_CMD
- NR_SHELL_CMD_EXPORT(ls, shell_ls_cmd);
- NR_SHELL_CMD_EXPORT(test, shell_test_cmd);
- NR_SHELL_CMD_EXPORT(led, shell_led_cmd);
- #else
- const static_cmd_st static_cmd[] =
- {
- {"ls", shell_ls_cmd},
- {"test", shell_test_cmd},
- {"led", shell_led_cmd},
- {"\0", NULL}
- };
- #endif
- /**
- * [url=home.php?mod=space&uid=555622]@prototype[/url] main(void)
- *
- * @param[in] void
- * @return void
- *
- * @brief main entry.
- * main.
- */
- int main(void)
- {
- uint8_t ch;
- InitDelay(); //sysclk Delay
- InitDebug(); //Uart Debug printf
- //èLEDGPIO.
- GPIO_SetDir(LED2_PORT, LED2_PIN, GPIO_OUT);
- GPIO_SetDir(LED3_PORT, LED3_PIN, GPIO_OUT);
- I2C_InitHw();
- elog_init();
- shell_init(); /* nr_micro_shell*/
- while(1)
- {
- if (UART_RxIsDataReady(UART2))
- {br />
- ch = UART_ReceiveData(UART2);
- shell(ch);
- }
- }
- }
- /*************<end>********************/
I2C程序:
- /* Copyright Statement:
- *
- * This software/firmware and related documentation ("AutoChips Software") are
- * protected under relevant copyright laws. The information contained herein is
- * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
- * the prior written permission of AutoChips inc. and/or its licensors, any
- * reproduction, modification, use or disclosure of AutoChips Software, and
- * information contained herein, in whole or in part, shall be strictly
- * prohibited.
- *
- * AutoChips Inc. (C) 2018. All rights reserved.
- *
- * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
- * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
- * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
- * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
- * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
- * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
- * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
- * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
- * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
- * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
- * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
- * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
- * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
- * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
- * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
- * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
- * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
- */
- /*************<start>******************/
- /*************<include>****************/
- #include "i2c.h"
- /*************<macro>******************/
- #define AT24C02_DEV_ADDR (0x50)
- /*************<enum>*******************/
- /*************<union>******************/
- /*************<struct>*****************/
- /*************<variable>***************/
- uint8_t g_wrAT24CDataBuf[9];
- uint8_t g_rdAT24CDataBuf[9];
- /*************<prototype>**************/
- /**
- * @prototype I2C_InitHw(void)
- *
- * @param[in] void
- * @return void
- *
- * @brief I2C.
- */
- void I2C_InitHw(void)
- {
- I2C_ConfigType i2cConfig = {0};
- /*I2C.*/
- GPIO_SetFunc(I2C0_SCL_PORT, I2C0_SCL_PIN, GPIO_FUN3);
- GPIO_SetFunc(I2C0_SDA_PORT, I2C0_SDA_PIN, GPIO_FUN3);
- /*I2Cè.*/
- i2cConfig.masterConfigs.ARBEn = ENABLE;/*è÷ú.*/
- i2cConfig.masterConfigs.SYNCEn = ENABLE;/*è÷úSCL.*/
- /*è¨100Kbps,bandrate = 24M / (10 * 12 * 2) = 100Kbps;*/
- i2cConfig.masterConfigs.sampleCnt = 9;
- i2cConfig.masterConfigs.stepCnt = 11;
- i2cConfig.slaveConfigs.addExtEn = DISABLE;/*.*/
- i2cConfig.slaveConfigs.addRangeEn = DISABLE;/*§.*/
- i2cConfig.slaveConfigs.monitorEn = DISABLE;/*úà.*/
- i2cConfig.slaveConfigs.stretchEn = DISABLE;/*úSCLì.*/
- i2cConfig.slaveConfigs.gcaEn = DISABLE;/*úSCL.*/
- i2cConfig.slaveConfigs.wakeupEn = DISABLE;/*,ú±§.*/
- i2cConfig.slaveConfigs.RXFInterruptEn = DISABLE;/*ú.*/
- i2cConfig.slaveConfigs.RXOFInterruptEn = DISABLE;/*.*/
- i2cConfig.slaveConfigs.TXEInterruptEn = DISABLE;/*.*/
- i2cConfig.slaveConfigs.TXUFInterruptEn = DISABLE;/*.*/
- i2cConfig.slaveConfigs.slaveAddress = AT24C02_DEV_ADDR;/*ú.*/
- i2cConfig.slaveConfigs.slave7BitRangeAddress = 0;/*ú§.*/
- i2cConfig.glitchFilterCnt = 0;/*.*/
- i2cConfig.interruptEn = DISABLE;/*I2C.*/
- i2cConfig.nackInterruptEn = DISABLE;/*NACK.*/
- i2cConfig.ssInterruptEn = DISABLE;/*×startòstop.*/
- i2cConfig.dmaRxEn = DISABLE;/*èDMA.*/
- i2cConfig.dmaTxEn = DISABLE;/*èDMA.*/
- i2cConfig.mode = I2C_MASTER;/*è÷ú.*/
- i2cConfig.i2cEn &bsp; = ENABLE;/*é.*/
- i2cConfig.callBack = NULL;/*÷.*/
- I2C_Init(I2C0, &i2cConfig);
- }
- /**
- * @prototype I2C_WrDataToAT24C(void)
- *
- * @param[in] void
- * @return void
- *
- * @brief EEPROM.
- */
- void I2C_WrDataToAT24C(void)
- {
- g_wrAT24CDataBuf[0] = 0x00;//
- for (uint8_t ii = 0; ii < 8; ii++)
- {
- g_wrAT24CDataBuf[ii + 1] = ii+10;
- printf("%02X ", g_wrAT24CDataBuf[ii + 1]);
- }printf("\r\n");
- I2C_MasterBurstWrite(I2C0, AT24C02_DEV_ADDR, g_wrAT24CDataBuf, 9, ENABLE);
- }
- /**
- * @prototype I2C_RdDataFromAT24C(void)
- *
- * @param[in] void
- * @return void
- *
- * @brief EEPROM.
- */
- void I2C_RdDataFromAT24C(void)
- {
- g_wrAT24CDataBuf[0] = 0x00;//
- I2C_MasterBurstWrite(I2C0, AT24C02_DEV_ADDR, g_wrAT24CDataBuf, 1, DISABLE);
- I2C_MasterBurstRead (I2C0, AT24C02_DEV_ADDR, g_rdAT24CDataBuf, 8);
- for (uint8_t ii = 0; ii < 8; ii++)
- {
- printf("%02X ", g_rdAT24CDataBuf[ii]);
- }
- printf("\r\n");
- }
- /*************<end>********************/
工程代码:
- 本文系21ic原创,未经许可禁止转载!
网友评论
- 联系人:巧克力娃娃
- 邮箱:board@21ic.com
- 我要投稿
-
欢迎入驻,开放投稿
-
人均百万?英伟达中国员工收入曝光! 2024-08-29
-
《黑神话:悟空》玩家硬盘升级攻略:提升游戏体验,畅享3A大作 2024-08-29
-
数睿数据参加《系统与软件工程 低代码开发平台通用技术要求》国家标准编制 2024-08-29
- NRF52810蓝牙数字耳机找人定制
预算:¥30005天前
- 125KW模块式PCS软硬件外包开发
预算:¥1100000015小时前
- 12V汽车启动电源项目BMS设计
预算:¥50000023小时前
- 数据可视化软件 开发
预算:¥5000023小时前
- PLC项目调试修改
预算:¥100001天前
- 起动电机控制器开发
预算:¥1100001天前