• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HPMicro
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <ohos_init.h>
16 #include <stdio.h>
17 #include <los_task.h>
18 #include <stdint.h>
19 #include <log.h>
20 #include <gpio_if.h>
21 #include <hpm_soc.h>
22 #include <hpm_clock_drv.h>
23 
24 #define LOG_TAG "HPM_GPIO_OUT"
25 
26 #define GPIOA(pin) (pin)
27 #define GPIOB(pin) (pin + 32)
28 #define GPIOC(pin) (pin + 32 * 2)
29 #define GPIOD(pin) (pin + 32 * 3)
30 #define GPIOE(pin) (pin + 32 * 4)
31 #define GPIOF(pin) (pin + 32 * 5)
32 #define GPIOY(pin) (pin + 32 * 14)
33 #define GPIOZ(pin) (pin + 32 * 15)
34 
GpioDriverOutTestTask(unsigned int arg)35 static void *GpioDriverOutTestTask(unsigned int arg)
36 {
37     HILOG_INFO(HILOG_MODULE_APP, "GpioDriverOutTestTask");
38 
39     HPM_IOC->PAD[IOC_PAD_PB11].FUNC_CTL = 0;
40     HPM_IOC->PAD[IOC_PAD_PB11].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1);
41 
42     HPM_IOC->PAD[IOC_PAD_PB12].FUNC_CTL = 0;
43     HPM_IOC->PAD[IOC_PAD_PB12].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1);
44 
45     HPM_IOC->PAD[IOC_PAD_PB13].FUNC_CTL = 0;
46     HPM_IOC->PAD[IOC_PAD_PB13].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1);
47 
48     GpioSetDir(GPIOB(11), GPIO_DIR_OUT);
49     GpioSetDir(GPIOB(12), GPIO_DIR_OUT);
50     GpioSetDir(GPIOB(13), GPIO_DIR_OUT);
51 
52     while (1) {
53         GpioWrite(GPIOB(11), GPIO_VAL_LOW);
54         LOS_TaskDelay(500);
55         GpioWrite(GPIOB(11), GPIO_VAL_HIGH);
56         LOS_TaskDelay(500);
57         GpioWrite(GPIOB(12), GPIO_VAL_LOW);
58         LOS_TaskDelay(500);
59         GpioWrite(GPIOB(12), GPIO_VAL_HIGH);
60         LOS_TaskDelay(500);
61         GpioWrite(GPIOB(13), GPIO_VAL_LOW);
62         LOS_TaskDelay(500);
63         GpioWrite(GPIOB(13), GPIO_VAL_HIGH);
64         LOS_TaskDelay(500);
65     }
66     return NULL;
67 }
68 
GpioDriverTest(void)69 static void GpioDriverTest(void)
70 {
71     TSK_INIT_PARAM_S taskInitParam = {0};
72 
73     taskInitParam.pcName = "gpio_out_test";
74     taskInitParam.pfnTaskEntry = GpioDriverOutTestTask;
75     taskInitParam.stackAddr = 0;
76     taskInitParam.uwStackSize = 8192;
77     taskInitParam.usTaskPrio = 20;
78     taskInitParam.uwArg = 0x66;
79     UINT32 taskID;
80     LOS_TaskCreate(&taskID, &taskInitParam);
81 }
82 
83 APP_FEATURE_INIT(GpioDriverTest);
84