mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Thu Nov 12 13:30:10 2015 +0000
Parent:
20:6bf7f0bb0f66
Child:
22:9c52de9bc1d7
Commit message:
Synchronized with git revision 10a39f48b0777d4ce6dc89816a6739a2e4272424

Full URL: https://github.com/mbedmicro/mbed/commit/10a39f48b0777d4ce6dc89816a6739a2e4272424/

Free hardware resource in pwmout_free()

Changed in this revision

targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/pwmout_api.c Show annotated file Show diff for this revision Revisions of this file
--- a/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/pwmout_api.c	Wed Nov 11 07:30:10 2015 +0000
+++ b/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/pwmout_api.c	Thu Nov 12 13:30:10 2015 +0000
@@ -116,6 +116,19 @@
     timer->TASKS_START = 0x01;
 }
 
+static void timer_free()
+{
+    NRF_TIMER_Type *timer = Timers[0];
+    for(uint8_t i = 1; i < NO_PWMS; i++){
+        if(PWM_taken[i]){
+            break;
+        }
+        if((i == NO_PWMS - 1) && (!PWM_taken[i]))
+            timer->TASKS_STOP = 0x01;
+    }
+}
+
+
 /** @brief Function for initializing the GPIO Tasks/Events peripheral.
  */
 void gpiote_init(PinName pin, uint8_t channel_number)
@@ -154,6 +167,14 @@
     __NOP();
 }
 
+static void gpiote_free(PinName pin,uint8_t channel_number)
+{
+    NRF_GPIOTE->TASKS_OUT[channel_number] = 0;
+    NRF_GPIOTE->CONFIG[channel_number] = 0;
+    NRF_GPIO->PIN_CNF[pin] = (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos);
+
+}
+
 /** @brief Function for initializing the Programmable Peripheral Interconnect peripheral.
  */
 static void ppi_init(uint8_t pwm)
@@ -173,6 +194,16 @@
                      (1 << (channel_number + 1));
 }
 
+static void ppi_free(uint8_t pwm)
+{
+    //using ppi channels 0-7 (only 0-7 are available)
+    uint8_t channel_number = 2*pwm;
+
+    // Disable PPI channels.
+    NRF_PPI->CHEN &= (~(1 << channel_number))
+                  &  (~(1 << (channel_number+1)));
+}
+
 void setModulation(pwmout_t *obj, uint8_t toggle, uint8_t high)
 {
     if (high) {
@@ -239,11 +270,13 @@
     pwmout_write    (obj, 0);
 }
 
-void pwmout_free(pwmout_t *obj)
-{
+void pwmout_free(pwmout_t* obj) {
     MBED_ASSERT(obj->pwm != (PWMName)NC);
+    pwmout_write(obj, 0);
     PWM_taken[obj->pwm] = 0;
-    pwmout_write(obj, 0);
+    timer_free();
+    ppi_free(obj->pwm);
+    gpiote_free(obj->pin,obj->pwm);
 }
 
 void pwmout_write(pwmout_t *obj, float value)