Anh Tran / Mbed OS GR-Boards_WebCamera

Dependencies:   HttpServer_snapshot_mbed-os

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ssif_api.c Source File

ssif_api.c

00001 /*******************************************************************************
00002 * DISCLAIMER
00003 * This software is supplied by Renesas Electronics Corporation and is only
00004 * intended for use with Renesas products. No other uses are authorized. This
00005 * software is owned by Renesas Electronics Corporation and is protected under
00006 * all applicable laws, including copyright laws.
00007 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
00008 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
00009 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00010 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
00011 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
00012 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
00013 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
00014 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
00015 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
00016 * Renesas reserves the right, without notice, to make changes to this software
00017 * and to discontinue the availability of this software. By using this software,
00018 * you agree to the additional terms and conditions found by accessing the
00019 * following link:
00020 * http://www.renesas.com/disclaimer*
00021 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
00022 *******************************************************************************/
00023 
00024 #include "ssif_api.h"
00025 
00026 #if defined(TARGET_RZ_A1XX)
00027 #if defined(TARGET_RZA1H) /* mbed */
00028 static const PinMap PinMap_SSIF_SCK[] = {
00029 //   pin      ch     func
00030     {P2_8   , 0    , 4},
00031     {P4_4   , 0    , 5},
00032     {P3_4   , 1    , 3},
00033     {P7_1   , 1    , 6},
00034     {P10_12 , 1    , 2},
00035     {P7_5   , 2    , 6},
00036     {P9_5   , 2    , 3},
00037     {P4_12  , 3    , 6},
00038     {P7_8   , 3    , 2},
00039     {P7_12  , 4    , 2},
00040     {P8_12  , 4    , 8},
00041     {P11_4  , 4    , 3},
00042     {P2_4   , 5    , 4},
00043     {P4_8   , 5    , 5},
00044     {P8_8   , 5    , 8},
00045     {NC     , NC   , 0}
00046 };
00047 
00048 static const PinMap PinMap_SSIF_WS[] = {
00049 //   pin      ch     func
00050     {P2_9   , 0    , 4},
00051     {P4_5   , 0    , 5},
00052     {P3_5   , 1    , 3},
00053     {P7_2   , 1    , 6},
00054     {P10_13 , 1    , 2},
00055     {P7_6   , 2    , 6},
00056     {P9_6   , 2    , 3},
00057     {P4_13  , 3    , 6},
00058     {P7_9   , 3    , 2},
00059     {P7_13  , 4    , 2},
00060     {P8_13  , 4    , 8},
00061     {P11_5  , 4    , 3},
00062     {P2_5   , 5    , 4},
00063     {P4_9   , 5    , 5},
00064     {P8_9   , 5    , 8},
00065     {NC     , NC   , 0}
00066 };
00067 
00068 static const PinMap PinMap_SSIF_TxD[] = {
00069 //   pin      ch     func
00070     {P2_11  , 0    , 4},
00071     {P4_7   , 0    , 5},
00072     {P7_4   , 1    , 6},
00073     {P10_15 , 1    , 2},
00074     {P7_7   , 2    , 6},  /* SSIDATA2 */
00075     {P9_7   , 2    , 3},  /* SSIDATA2 */
00076     {P4_15  , 3    , 6},
00077     {P7_11  , 3    , 2},
00078     {P6_1   , 4    , 6},  /* SSIDATA4 */
00079     {P7_14  , 4    , 2},  /* SSIDATA4 */
00080     {P8_14  , 4    , 8},  /* SSIDATA4 */
00081     {P11_6  , 4    , 3},  /* SSIDATA4 */
00082     {P2_7   , 5    , 4},
00083     {P4_11  , 5    , 5},
00084     {P8_10  , 5    , 8},
00085     {NC     , NC   , 0}
00086 };
00087 
00088 static const PinMap PinMap_SSIF_RxD[] = {
00089 //   pin      ch     func
00090     {P2_10  , 0    , 4},
00091     {P4_6   , 0    , 5},
00092     {P3_7   , 1    , 3},
00093     {P7_3   , 1    , 6},
00094     {P10_14 , 1    , 2},
00095     {P7_7   , 2    , 6},  /* SSIDATA2 */
00096     {P9_7   , 2    , 3},  /* SSIDATA2 */
00097     {P4_14  , 3    , 6},
00098     {P7_10  , 3    , 2},
00099     {P6_1   , 4    , 6},  /* SSIDATA4 */
00100     {P7_14  , 4    , 2},  /* SSIDATA4 */
00101     {P8_14  , 4    , 8},  /* SSIDATA4 */
00102     {P11_6  , 4    , 3},  /* SSIDATA4 */
00103     {P2_6   , 5    , 4},
00104     {P4_10  , 5    , 5},
00105     {NC     , NC   , 0}
00106 };
00107 
00108 static const PinMap PinMap_SPDIF_AUDIO_CLK[] = {
00109     {NC,    NC,     0}
00110 };
00111 
00112 #else
00113 static const PinMap PinMap_SSIF_SCK[] = {
00114 //   pin      ch     func
00115     {P2_7   , 3    , 2},
00116     {NC     , NC   , 0}
00117 };
00118 
00119 static const PinMap PinMap_SSIF_WS[] = {
00120 //   pin      ch     func
00121     {P2_9   , 3    , 2},
00122     {NC     , NC   , 0}
00123 };
00124 
00125 static const PinMap PinMap_SSIF_TxD[] = {
00126 //   pin      ch     func
00127     {P2_8   , 3    , 2},
00128     {NC     , NC   , 0}
00129 };
00130 
00131 static const PinMap PinMap_SSIF_RxD[] = {
00132 //   pin      ch     func
00133     {P2_6   , 3    , 2},
00134     {NC     , NC   , 0}
00135 };
00136 
00137 static const PinMap PinMap_SPDIF_AUDIO_CLK[] = {
00138     {NC,    NC,     0}
00139 };
00140 
00141 #endif
00142 
00143 static void ssif_power_enable(uint32_t ssif_ch) {
00144     volatile uint8_t dummy;
00145 
00146     switch (ssif_ch) {
00147         case 0:
00148             CPGSTBCR11 &= ~(0x20);
00149             break;
00150         case 1:
00151             CPGSTBCR11 &= ~(0x10);
00152             break;
00153         case 2:
00154             CPGSTBCR11 &= ~(0x08);
00155             break;
00156         case 3:
00157             CPGSTBCR11 &= ~(0x04);
00158             break;
00159 #if defined(TARGET_RZA1H) /* mbed */
00160         case 4:
00161             CPGSTBCR11 &= ~(0x02);
00162             break;
00163         case 5:
00164             CPGSTBCR11 &= ~(0x01);
00165             break;
00166 #endif
00167     }
00168     dummy = CPGSTBCR11;
00169     (void)dummy;
00170 }
00171 
00172 #elif defined(TARGET_RZ_A2XX)
00173 
00174 static const PinMap PinMap_SSIF_SCK[] = {
00175 //   pin      ch     func
00176     {P9_6   , 0    , 5},
00177     {NC     , NC   , 0}
00178 };
00179 
00180 static const PinMap PinMap_SSIF_WS[] = {
00181 //   pin      ch     func
00182     {P9_5   , 0    , 5},
00183     {NC     , NC   , 0}
00184 };
00185 
00186 static const PinMap PinMap_SSIF_TxD[] = {
00187 //   pin      ch     func
00188     {P9_4   , 0    , 5},
00189     {NC     , NC   , 0}
00190 };
00191 
00192 static const PinMap PinMap_SSIF_RxD[] = {
00193 //   pin      ch     func
00194     {P9_3   , 0    , 5},
00195     {NC     , NC   , 0}
00196 };
00197 
00198 static void ssif_power_enable(uint32_t ssif_ch) {
00199     volatile uint8_t dummy;
00200 
00201     switch (ssif_ch) {
00202         case 0:
00203             CPG.STBCR7.BYTE &= ~(0x08);
00204             break;
00205         case 1:
00206             CPG.STBCR7.BYTE &= ~(0x04);
00207             break;
00208         case 2:
00209             CPG.STBCR7.BYTE &= ~(0x02);
00210             break;
00211         case 3:
00212             CPG.STBCR7.BYTE &= ~(0x01);
00213             break;
00214     }
00215     dummy = CPG.STBCR7.BYTE;
00216     (void)dummy;
00217 }
00218 
00219 static const PinMap PinMap_SPDIF_AUDIO_CLK[] = {
00220     {P6_4,  0,      4},
00221     {PH_0,  0,      1},
00222     {NC,    NC,     0}
00223 };
00224 
00225 #endif
00226 
00227 int32_t ssif_init(PinName sck, PinName ws, PinName tx, PinName rx, PinName audio_clk) {
00228     /* determine the ssif to use */
00229     uint32_t ssif_sck = pinmap_peripheral(sck, PinMap_SSIF_SCK);
00230     uint32_t ssif_ws  = pinmap_peripheral(ws,  PinMap_SSIF_WS);
00231     uint32_t ssif_tx  = pinmap_peripheral(tx,  PinMap_SSIF_TxD);
00232     uint32_t ssif_rx  = pinmap_peripheral(rx,  PinMap_SSIF_RxD);
00233     uint32_t ssif_ch  = pinmap_merge(ssif_tx, ssif_rx);
00234 
00235     if ((ssif_ch == ssif_sck) && (ssif_ch == ssif_ws)) {
00236         ssif_power_enable(ssif_ch);
00237         pinmap_pinout(sck, PinMap_SSIF_SCK);
00238         pinmap_pinout(ws,  PinMap_SSIF_WS);
00239         pinmap_pinout(tx,  PinMap_SSIF_TxD);
00240         pinmap_pinout(rx,  PinMap_SSIF_RxD);
00241         if ((int32_t)audio_clk != NC) {
00242             pinmap_pinout(audio_clk, PinMap_SPDIF_AUDIO_CLK);
00243         }
00244     } else {
00245         ssif_ch = (uint32_t)NC;
00246     }
00247 
00248     return (int32_t)ssif_ch;
00249 }
00250