基於芯馳 X9E PTG4.3 添加 PMU CTRLx 的控制驅動

本文通過修改 SYS_CTRL3 的引腳配置為例說明 PMU CTRLx 的控制方法。

1.打開 PMU 的開關

(1)打開 PMU 的開關

vim lunch_config/X9E_Ref_Linux_Serdes_1G_2133.json

 

SUPPORT_PMU_SDDRV=true SUPPORT_PMU_TEST=true


(2)修改後記得重新配置編譯環境

source lunch_sd.sh -c X9E_Ref_Linux_Serdes_1G_2133.json -b X9_PTG4.3 -u customer_c


 

 

2.添加 PMU 的控制代碼

(1)在 target_init.c 中添加 PMU 的控制代碼

vim rtos/freertos_safetyos/target/reference_x9/safety/target_init.c


 

(2)具體實現函數如下:

int enable_sys_ctrl3(void)

{

        int ret = 0;

        int id = 3;

        int status_val = 0;

        int io_mode = PWR_CTRL_OUTPUT;

        int ctrl_mode = PWR_CTRL_OUTPUT_MANUAL;

        int level = PWR_CTRL_OUTPUT_HIGH;       //PWR_CTRL_OUTPUT_LOW;

        void *sys_ctrl3_handle = NULL;

        //uint32_t pmu_res_glb_idx = RES_PMU_PMU;

        int pu_delay = 0x09;                            // 3ms

        int pd_delay = 0x09;                            // 3ms

 

        ret = hal_pmu_creat_handle( &sys_ctrl3_handle, RES_PMU_PMU);

        if(0 != ret){

                dprintf(CRITICAL, "**[ stark add 1 _%s ] creat handle err! ret:%d\n", __func__, ret);

                return ret;

        }

        else    dprintf(CRITICAL, "**[ stark add 1 _%s ] creat handle [ OK! ] ret:%d\n", __func__, ret);

 

        ret = hal_pmu_init(sys_ctrl3_handle);

        if(0 != ret){

                dprintf(CRITICAL, "**[ stark add 2 _%s ] handle init err! ret:%d\n", __func__, ret);

                return ret;

        }

        else    dprintf(CRITICAL, "**[ stark add 2 _%s ] handle init [ OK! ] ret:%d\n", __func__, ret);

 

  /** get pmu status */

        ret = hal_pmu_get_status(sys_ctrl3_handle, &status_val);

        if(0 != ret){

                dprintf(CRITICAL, "**[ stark add 2.1 _%s ] get status err! ret:%d\n", __func__, ret);

                return ret;

        }

        else    dprintf(CRITICAL, "**[ stark add 2.1 _%s ] get status [ OK! ] status_val:0x%x\n", __func__, status_val);

 

  /* set ctrl_id as output mode */

        ret = hal_pmu_set_powerctrl_io_mode(sys_ctrl3_handle, id, io_mode);

        if(0 != ret){

                dprintf(CRITICAL, "**[ stark add 3 _%s ] handle set io_mode err! ret:%d\n", __func__, ret);

                return ret;

        }

        else    dprintf(CRITICAL, "**[ stark add 3 _%s ] handle set io_mode [ ctrl_id:%d, io_mode:%d (0:output, 1:input)] ret:%d\n", __func__, id, io_mode, ret);

 

  /* set output as auto or manual */

        ret = hal_pmu_set_powerctrl_out_mode(sys_ctrl3_handle, id, ctrl_mode);

        if(0 != ret){

                dprintf(CRITICAL, "**[ stark add 4 _%s ] handle set out_mode err! ret:%d\n", __func__, ret);

return ret;

        }

        else    dprintf(CRITICAL, "**[ stark add 4 _%s ] handle set out_mode [ ctrl_id:%d, ctrl_mode:%d (0:auto, 1:manual)] ret:%d\n", __func__, id, ctrl_mode, ret);


 

  /* set powerctrl powerup delay */

        ret = hal_pmu_set_powerctrl_powerup_delay(sys_ctrl3_handle, id, pu_delay);

        if(0 != ret){

                dprintf(CRITICAL, "**[ stark add 5 _%s ] handle set powerup_delay err! ret:%d\n", __func__, ret);

                return ret;

        }

        else    dprintf(CRITICAL, "**[ stark add 5 _%s ] handle set powerup_delay [ ctrl_id:%d, powerup_delay:0x0%x (0x09: 3ms)] ret:%d\n", __func__, id, pu_delay, ret);

 

  /* set powerctrl powerdown delay */

        ret = hal_pmu_set_powerctrl_powerdown_delay(sys_ctrl3_handle, id, pd_delay);

        if(0 != ret){

                dprintf(CRITICAL, "**[ stark add 6 _%s ] handle set powerdown_delay err! ret:%d\n", __func__, ret);

                return ret;

        }

        else    dprintf(CRITICAL, "**[ stark add 6 _%s ] handle set powerdown_delay [ ctrl_id:%d, powerdown_delay:0x0%x (0x09: 3ms)] ret:%d\n", __func__, id, pd_delay, ret);

 

   /** set powerctrl out high or low **/

        ret = hal_pmu_set_powerctrl_out_ctrl(sys_ctrl3_handle, id, level);

        if(0 != ret){

                dprintf(CRITICAL, "**[ stark add 7 _%s ] handle set out_ctrl err! ret:%d\n", __func__, ret);

                return ret;

        }

        else    dprintf(CRITICAL, "**[ stark add 7 _%s ] handle set out_ctrl [ ctrl_id:%d, level:%d (0:low, 1:high)] ret:%d\n", __func__, id, level, ret);

 

  /**** exit ****/

        ret = hal_pmu_exit(sys_ctrl3_handle);

        if(0 != ret){

                dprintf(CRITICAL, "**[ stark add 8 _%s ] handle exit err! ret:%d\n", __func__, ret);

                return ret;

        }

        else    dprintf(CRITICAL, "**[ stark add 8 _%s ] handle exit [ OK! ] ret:%d\n", __func__, ret);

 

        ret = hal_pmu_release_handle(sys_ctrl3_handle);

        if(0 != ret){

                dprintf(CRITICAL, "**[ stark add 9 _%s ] handle release err! ret:%d\n", __func__, ret);

                return ret;

        }

        else    dprintf(CRITICAL, "**[ stark add 9 _%s ] handle release [ OK! ]! ret:%d\n", __func__, ret);

 

        dprintf(CRITICAL, "**[ stark add 10 _%s ] - [ enable_ctrl3 running OK! ]!\n", __func__);

        return 0;​

 3.相關宏定義參數修改

(1)PMU 相關的宏定義位置在 pmu_drv.h 文件中

vim rtos/lk_boot/chipdev/pmu/sd_pmu/inc/pmu_drv.h​

 (2)這裡需要修改 Manual 和 auto 模式的定義

 4.編譯燒寫測試

(1)編譯打包

make freertos

make genpac

 (2)燒寫驗證

開機 safety log 確認如下信息即配置成功。

 

5.總結

本文通過修改 SYS_CTRL3 的引腳配置為例說明 PMU CTRLx 的控制方法,文中還給出了實際添加的控制 SYS_CTRL3 的代碼,讀者可以通過相同的修改,完全實現這個功能。

6.參考資料

[1]《Semidrive_AN_9系列PMU使用說明》

[2]《X9_SDK_用戶手冊_Rev1.7》

芯馳 X9系列相關博文:

      《基於芯馳 X9HP PTG4.1 添加 yocto 應用》

      《基於芯馳 X9HP PTG4.3 修改 4G DDR Layout》

      《基於芯馳 X9HP PTG4.1 修改 UART10 作為 linux 串口輸出》

      
歡迎在博文下方留言評論,我們會及時回復您的問題。

如有更多需求,歡迎聯繫大聯大世平集團 ATU 部門:atu.sh@wpi-group.com   
作者:好景虛設


更多資訊,請掃碼關注我們!


★博文內容均由個人提供,與平台無關,如有違法或侵權,請與網站管理員聯繫。

★文明上網,請理性發言。內容一周內被舉報5次,發文人進小黑屋喔~

參考來源

評論