Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers target_family.c Source File

target_family.c

Go to the documentation of this file.
00001 /**
00002  * @file    target_family.c
00003  * @brief   Implementation of target_family.h
00004  *
00005  * DAPLink Interface Firmware
00006  * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved
00007  * SPDX-License-Identifier: Apache-2.0
00008  *
00009  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00010  * not use this file except in compliance with the License.
00011  * You may obtain a copy of the License at
00012  *
00013  * http://www.apache.org/licenses/LICENSE-2.0
00014  *
00015  * Unless required by applicable law or agreed to in writing, software
00016  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00017  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00018  * See the License for the specific language governing permissions and
00019  * limitations under the License.
00020  */
00021 
00022 #include "daplink.h"
00023 #include "DAP_config.h"
00024 #include "swd_host.h"
00025 #include "target_family.h"
00026 #include "target_board.h"
00027 
00028 // Stub families
00029 const target_family_descriptor_t g_hw_reset_family = {
00030     .family_id  = kStub_HWReset_FamilyID,
00031     .default_reset_type = kHardwareReset,
00032 };
00033 
00034 const target_family_descriptor_t g_sw_vectreset_family = {
00035     .family_id  = kStub_SWVectReset_FamilyID,
00036     .default_reset_type = kSoftwareReset,
00037     .soft_reset_type = VECTRESET,
00038 };
00039 
00040 const target_family_descriptor_t g_sw_sysresetreq_family = {
00041     .family_id  = kStub_SWSysReset_FamilyID,
00042     .default_reset_type = kSoftwareReset,
00043     .soft_reset_type = SYSRESETREQ,
00044 };
00045 
00046 //Weakly define family
00047 __attribute__((weak))
00048 const target_family_descriptor_t g_nxp_kinetis_kseries = {0};
00049 __attribute__((weak))
00050 const target_family_descriptor_t g_nxp_kinetis_lseries = {0};
00051 __attribute__((weak))
00052 const target_family_descriptor_t g_nxp_kinetis_k32w_series = {0};
00053 __attribute__((weak))
00054 const target_family_descriptor_t g_nxp_mimxrt = {0};
00055 __attribute__((weak))
00056 const target_family_descriptor_t g_nxp_rapid_iot = {0};
00057 __attribute__((weak))
00058 const target_family_descriptor_t  g_nordic_nrf51  = {0};
00059 __attribute__((weak))
00060 const target_family_descriptor_t  g_nordic_nrf52  = {0};
00061 __attribute__((weak))
00062 const target_family_descriptor_t g_realtek_rtl8195am  = {0};
00063 __attribute__((weak))
00064 const target_family_descriptor_t g_ti_family  = {0};
00065 __attribute__((weak))
00066 const target_family_descriptor_t g_wiznet_family  = {0};
00067 __attribute__((weak))
00068 const target_family_descriptor_t g_renesas_family  = {0};
00069 __attribute__((weak))
00070 const target_family_descriptor_t g_toshiba_tz_family  = {0};
00071 
00072 __attribute__((weak))
00073 const target_family_descriptor_t *g_families[] = {
00074     &g_hw_reset_family,
00075     &g_sw_vectreset_family,
00076     &g_sw_sysresetreq_family,
00077     &g_nxp_kinetis_kseries,
00078     &g_nxp_kinetis_lseries,
00079     &g_nxp_kinetis_k32w_series,
00080     &g_nxp_mimxrt,
00081     &g_nxp_rapid_iot,
00082     &g_nordic_nrf51,
00083     &g_nordic_nrf52,
00084     &g_realtek_rtl8195am,
00085     &g_ti_family,
00086     &g_wiznet_family,
00087     &g_renesas_family,
00088     &g_toshiba_tz_family,
00089     0 // list terminator
00090 };
00091 
00092 __attribute__((weak))
00093 const target_family_descriptor_t *g_target_family = NULL;
00094 
00095 
00096 void init_family(void)
00097 {
00098     uint8_t index = 0;
00099     uint16_t family_id = get_family_id();
00100     if (g_target_family != NULL){ //already set
00101         return;
00102     }
00103 
00104     while (g_families[index]!=0) {
00105         if (g_families[index]->family_id && (g_families[index]->family_id == family_id)) {
00106             g_target_family = g_families[index];
00107             break;
00108         }
00109         index++;
00110     }
00111 
00112     if(g_target_family == NULL){ //default family
00113         g_target_family = &g_hw_reset_family;
00114     }
00115 }
00116 
00117 uint8_t target_set_state(target_state_t state)
00118 {
00119     if (g_board_info.target_set_state) { //target specific
00120         g_board_info.target_set_state(state);
00121     }
00122     if (g_target_family) {
00123         if (g_target_family->target_set_state ) {
00124             //customize target state
00125             return g_target_family->target_set_state (state);
00126         } else {
00127             if (g_target_family->default_reset_type  == kHardwareReset) {
00128                 return swd_set_target_state_hw(state);
00129             } else if (g_target_family->default_reset_type  == kSoftwareReset) {
00130                 if (g_board_info.soft_reset_type) { //board has precedence
00131                     swd_set_soft_reset(g_board_info.soft_reset_type);
00132                 } else if (g_target_family->soft_reset_type ) {
00133                     swd_set_soft_reset(g_target_family->soft_reset_type );
00134                 }
00135                 return swd_set_target_state_sw(state);
00136             }else {
00137                 return 1;
00138             }
00139         }
00140     }else{
00141         return 0;
00142     }
00143 }
00144 
00145 void swd_set_target_reset(uint8_t asserted)
00146 {
00147     if (g_target_family && g_target_family->swd_set_target_reset ) {
00148         g_target_family->swd_set_target_reset (asserted);
00149     }else {
00150         (asserted) ? PIN_nRESET_OUT(0) : PIN_nRESET_OUT(1);
00151     }
00152 }
00153 
00154 uint32_t target_get_apsel()
00155 {
00156     if (g_target_family && g_target_family->apsel ) {
00157         return g_target_family->apsel ;
00158     } else {
00159         return 0;
00160     }
00161 }