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

« Back to documentation index

Show/hide line numbers gpio.c Source File

gpio.c

00001 /**
00002  * @file    gpio.c
00003  * @brief
00004  *
00005  * DAPLink Interface Firmware
00006  * Copyright (c) 2009-2016, 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 "sam3u.h"
00023 #include "gpio.h"
00024 #include "uart.h"
00025 #include "compiler.h"
00026 #include "daplink.h"
00027 
00028 // This GPIO configuration is only valid for the SAM3U2C
00029 COMPILER_ASSERT(DAPLINK_HIC_ID == DAPLINK_HIC_ID_SAM3U2C);
00030 
00031 void gpio_init(void)
00032 {
00033     volatile int Cnt;
00034     //
00035     // Initially enable clock for GPIO and initialize LED ports as output with LED == off
00036     //
00037     PMC->PMC_PCER0 = (1 << 10) | (1 << 11) | (1 << 12);  // Enable clock for all PIOs
00038 
00039     // DAP LED
00040     PIN_DAP_LED_PORT->PIO_PER = PIN_DAP_LED;
00041     PIN_DAP_LED_PORT->PIO_SODR = PIN_DAP_LED;
00042     PIN_DAP_LED_PORT->PIO_OER = PIN_DAP_LED;
00043 
00044     // MSD LED
00045     PIN_MSD_LED_PORT->PIO_PER = PIN_MSD_LED;
00046     PIN_MSD_LED_PORT->PIO_SODR = PIN_MSD_LED;
00047     PIN_MSD_LED_PORT->PIO_OER = PIN_MSD_LED;
00048 
00049     // CDC LED
00050     PIN_CDC_LED_PORT->PIO_PER = PIN_CDC_LED;
00051     PIN_CDC_LED_PORT->PIO_SODR = PIN_CDC_LED;
00052     PIN_CDC_LED_PORT->PIO_OER = PIN_CDC_LED;
00053 
00054     // Forwarded reset
00055     PIN_RESET_IN_FWRD_PORT->PIO_PER  = PIN_RESET_IN_FWRD; // Pin == GPIO control
00056     PIN_RESET_IN_FWRD_PORT->PIO_ODR  = PIN_RESET_IN_FWRD; // Disable output
00057     PIN_RESET_IN_FWRD_PORT->PIO_PUER = PIN_RESET_IN_FWRD; // Enable pull-up
00058     Cnt = 1000000;
00059     do {} while (--Cnt);    // Give pull-up some time to become active
00060 
00061     // Enable port A interrupts in the NVIC
00062     NVIC_EnableIRQ(PIOA_IRQn);
00063 }
00064 
00065 void gpio_set_hid_led(gpio_led_state_t state)
00066 {
00067     if (GPIO_LED_ON == state) {
00068         PIN_DAP_LED_PORT->PIO_CODR = PIN_DAP_LED; // LED == on
00069     } else {
00070         PIN_DAP_LED_PORT->PIO_SODR = PIN_DAP_LED; // LED == off
00071     }
00072 }
00073 
00074 void gpio_set_cdc_led(gpio_led_state_t state)
00075 {
00076     if (GPIO_LED_ON == state) {
00077         PIN_CDC_LED_PORT->PIO_CODR = PIN_CDC_LED; //  LED == on
00078     } else {
00079         PIN_CDC_LED_PORT->PIO_SODR = PIN_CDC_LED; //  LED == off
00080     }
00081 }
00082 
00083 void gpio_set_msc_led(gpio_led_state_t state)
00084 {
00085     if (GPIO_LED_ON == state) {
00086         PIN_MSD_LED_PORT->PIO_CODR = PIN_MSD_LED; //  LED == on
00087     } else {
00088         PIN_MSD_LED_PORT->PIO_SODR = PIN_MSD_LED; //  LED == off
00089     }
00090 }
00091 
00092 void PIOA_IRQHandler(void)
00093 {
00094     //
00095     // ISR is called when flow control is de-asserted
00096     //
00097     uint32_t interrupts = PIOA->PIO_ISR;
00098 
00099     if ((interrupts >> 9) & 1) { //CTS
00100         uart_software_flow_control();
00101     }
00102 }
00103 
00104 uint8_t gpio_get_reset_btn_no_fwrd(void)
00105 {
00106     return 0;
00107 }
00108 
00109 uint8_t gpio_get_reset_btn_fwrd()
00110 {
00111     return (PIN_RESET_IN_FWRD_PORT->PIO_PDSR & PIN_RESET_IN_FWRD) == 0;
00112 }
00113 
00114 void gpio_set_board_power(bool powerEnabled)
00115 {
00116 }