/* ===================================================================*/ LDD_TDeviceData* DacLdd1_Init(LDD_TUserData *UserDataPtr) { DacLdd1_TDeviceData *DeviceDataPtr; /* LDD device structure */ /* Allocate HAL device structure */ /* {Default RTOS Adapter} Driver memory allocation: Dynamic allocation is simulated by a pointer to the static object */ DeviceDataPtr = &DeviceDataPtr__DEFAULT_RTOS_ALLOC; DeviceDataPtr->DmaTransferDeviceDataPtr = NULL; /* DMA is not used */ DeviceDataPtr->UserDataPtr = UserDataPtr; /* Store the RTOS device structure */ /* SIM_SCGC6: DAC0=1 */ SIM_SCGC6 |= SIM_SCGC6_DAC0_MASK; DAC_PDD_EnableDevice(DAC0_BASE_PTR,PDD_DISABLE); /* Disable device */ /* Initialization of pin routing */ /* PORTE_PCR30: ISF=0,MUX=0 */ PORTE_PCR30 &= (uint32_t)~(uint32_t)((PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x07))); /* DAC0_DAT0H: ??=0,??=0,??=0,??=0,DATA1=0 */ DAC0_DAT0H = DAC_DATH_DATA1(0x00); /* DAC0_DAT0L: DATA0=0 */ DAC0_DAT0L = DAC_DATL_DATA0(0x00); /* DAC0_C2: ??=0,??=0,??=0,DACBFRP=0,??=1,??=1,??=1,DACBFUP=1 */ DAC0_C2 = (DAC_C2_DACBFUP_MASK | 0x0EU); /* DAC0_C1: DMAEN=0,??=0,??=0,??=0,??=0,DACBFMD=0,??=0,DACBFEN=0 */ DAC0_C1 = 0x00U; /* DAC0_SR: ??=0,??=0,??=0,??=0,??=0,??=0,DACBFRPTF=0,DACBFRPBF=0 */ DAC0_SR = 0x00U; /* DAC0_C0: DACEN=1,DACRFS=0,DACTRGSEL=0,DACSWTRG=0,LPEN=0,??=0,DACBTIEN=0,DACBBIEN=0 */ DAC0_C0 = DAC_C0_DACEN_MASK; /* Registration of the device structure */ PE_LDD_RegisterDeviceStructure(PE_LDD_COMPONENT_DacLdd1_ID,DeviceDataPtr); return ((LDD_TDeviceData*)DeviceDataPtr); /* Return pointer to the data data structure */ }
/* ** =================================================================== ** Method : DA1_Enable (component DAC_LDD) ** ** Description : ** Enables DAC device. If possible, this method switches on ** digital-to-analog converter device, voltage reference, etc. ** This method is intended to be used together with Disable ** method to temporary switch On/Off the device after the ** device is initialized. ** This method is required if the <Enable in init. code> ** property is set to "no" value. ** Parameters : ** NAME - DESCRIPTION ** * DeviceDataPtr - Device data structure ** pointer returned by <Init> method. ** Returns : ** --- - Error code, possible codes: ** - ERR_OK - OK. ** - ERR_SPEED - This device does not work in ** the active clock configuration. ** =================================================================== */ LDD_TError DA1_Enable(LDD_TDeviceData *DeviceDataPtr) { /* Clock configuration test - this test can be disabled by setting the "Ignore clock configuration test" property to the "yes" value in the "Configuration inspector" */ if (((DA1_TDeviceData*)DeviceDataPtr)->EnMode == 0x00U) { /* Is the device disabled in the actual speed CPU mode? */ return ERR_SPEED; /* No, return ERR_SPEED */ } DAC_PDD_EnableDevice(DAC0_BASE_PTR,PDD_ENABLE); /* Enable device */ ((DA1_TDeviceData*)DeviceDataPtr)->EnUser = TRUE; /* Set the flag "device enabled by user" */ return ERR_OK; }
LDD_TError DAC_Enable ( /* [IN] Device data structure pointer. */ LDD_TDeviceDataPtr DeviceData ) { /* Get DAC module base address */ DAC_MemMapPtr DAC_BasePtr = ((DAC_TDeviceDataPtr)DeviceData)->DAC_MODULE_BASE_PTR; DAC_PDD_EnableDevice(DAC_BasePtr); return DAC_ERROR_OK; }
/* ** =================================================================== ** Method : DA1_Disable (component DAC_LDD) ** ** Description : ** Disables the DAC device. If possible, this method switches ** off digital-to-analog converter device, voltage reference, ** etc. When the device is disabled, some component methods ** should not be called. If so, error ERR_DISABLED is reported. ** This method is intended to be used together with Enable ** method to temporary switch On/Off the device after the ** device is initialized. ** This method is not required. The Deinit method can be used ** to switch off and uninstall the device. ** Parameters : ** NAME - DESCRIPTION ** * DeviceDataPtr - Device data structure ** pointer returned by <Init> method. ** Returns : ** --- - Error code, possible codes: ** - ERR_OK - OK. ** - ERR_SPEED - This device does not work in ** the active clock configuration. ** =================================================================== */ LDD_TError DA1_Disable(LDD_TDeviceData *DeviceDataPtr) { (void)DeviceDataPtr; /* Parameter not used, suppress not used argument warning */ /* Clock configuration test - this test can be disabled by setting the "Ignore clock configuration test" property to the "yes" value in the "Configuration inspector" */ if (((DA1_TDeviceData*)DeviceDataPtr)->EnMode == 0x00U) { /* Is the device disabled in the actual speed CPU mode? */ return ERR_SPEED; /* No, return ERR_SPEED */ } DAC_PDD_EnableDevice(DAC0_BASE_PTR,PDD_DISABLE); /* Disable device */ ((DA1_TDeviceData*)DeviceDataPtr)->EnUser = FALSE; /* Set the flag "device disabled by user" */ return ERR_OK; }
/* ** =================================================================== ** Method : DA1_Deinit (component DAC_LDD) ** ** Description : ** Disables the device and frees the device data structure ** memory. If DMA service is enabled this method also ** deinitializes inherited DMA Transfer component. ** Parameters : ** NAME - DESCRIPTION ** * DeviceDataPtr - Device data structure ** pointer returned by <Init> method. ** Returns : Nothing ** =================================================================== */ void DA1_Deinit(LDD_TDeviceData *DeviceDataPtr) { (void)DeviceDataPtr; /* Parameter not used, suppress not used argument warning */ DAC_PDD_EnableDevice(DAC0_BASE_PTR,PDD_DISABLE); /* Disable device */ /* Interrupt vector(s) deallocation */ /* {MQX RTOS Adapter} Restore interrupt vector (function handler and ISR parameter) */ /* Note: Exception handler for interrupt is not restored, because it was not modified */ (void)_int_install_isr(LDD_ivIndex_INT_DAC0, ((DA1_TDeviceData *)DeviceDataPtr)->SavedISRSettings_BufferInterrupt.isrFunction, ((DA1_TDeviceData *)DeviceDataPtr)->SavedISRSettings_BufferInterrupt.isrData); /* Deallocation of the device structure */ /* {MQX RTOS Adapter} Driver memory deallocation: RTOS function call is defined by MQX RTOS Adapter property */ _mem_free(DeviceDataPtr); /* Disable device clock gate */ /* SIM_SCGC2: DAC0=0 */ SIM_SCGC2 &= (uint32_t)~0x1000UL; }
/* ** =================================================================== ** Method : DA1_Init (component DAC_LDD) ** ** Description : ** Initializes the device according to design-time ** configuration properties. Allocates memory for the device ** data structure. ** If the <Enable in init. code> is set to "yes" then the ** device is also enabled (see the description of the Enable ** method). ** This method can be called only once. Before the second call ** of Init the Deinit method must be called first. If DMA ** service is enabled this method also initializes inherited ** DMA Transfer component. ** Parameters : ** NAME - DESCRIPTION ** * UserDataPtr - Pointer to the user or ** RTOS specific data. This pointer will be ** passed as an events or callback parameter. ** Returns : ** --- - Device data structure pointer. ** =================================================================== */ LDD_TDeviceData* DA1_Init(LDD_TUserData *UserDataPtr) { DA1_TDeviceData *DeviceDataPtr; /* Allocate HAL device structure */ /* {MQX RTOS Adapter} Driver memory allocation: RTOS function call is defined by MQX RTOS Adapter property */ DeviceDataPtr = (DA1_TDeviceData *)_mem_alloc_system((_mem_size)sizeof(DA1_TDeviceData)); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (DeviceDataPtr == NULL) { return (NULL); } #endif DeviceDataPtr->DmaTransferDeviceDataPtr = NULL; /* DMA is not used */ DeviceDataPtr->UserDataPtr = UserDataPtr; /* Store the RTOS device structure */ /* Enable device clock gate */ /* SIM_SCGC2: DAC0=1 */ SIM_SCGC2 |= (uint32_t)0x1000UL; DAC_PDD_EnableDevice(DAC0_BASE_PTR,PDD_DISABLE); /* Disable device */ /* Interrupt vector(s) allocation */ /* {MQX RTOS Adapter} Save old and set new interrupt vector (function handler and ISR parameter) */ /* Note: Exception handler for interrupt is not saved, because it is not modified */ DeviceDataPtr->SavedISRSettings_BufferInterrupt.isrData = _int_get_isr_data(LDD_ivIndex_INT_DAC0); DeviceDataPtr->SavedISRSettings_BufferInterrupt.isrFunction = _int_install_isr(LDD_ivIndex_INT_DAC0, DA1_BufferInterrupt, DeviceDataPtr); /* Interrupt vector(s) priority setting */ /* NVICIP81: PRI81=0x90 */ NVICIP81 = (uint8_t)0x90U; /* NVICISER2: SETENA|=0x00020000 */ NVICISER2 |= (uint32_t)0x00020000UL; /* DAC0_DAT0H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT0H = (uint8_t)0x00U; /* DAC0_DAT0L: DATA=0 */ DAC0_DAT0L = (uint8_t)0x00U; /* DAC0_DAT1H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT1H = (uint8_t)0x00U; /* DAC0_DAT1L: DATA=0 */ DAC0_DAT1L = (uint8_t)0x00U; /* DAC0_DAT2H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT2H = (uint8_t)0x00U; /* DAC0_DAT2L: DATA=0 */ DAC0_DAT2L = (uint8_t)0x00U; /* DAC0_DAT3H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT3H = (uint8_t)0x00U; /* DAC0_DAT3L: DATA=0 */ DAC0_DAT3L = (uint8_t)0x00U; /* DAC0_DAT4H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT4H = (uint8_t)0x00U; /* DAC0_DAT4L: DATA=0 */ DAC0_DAT4L = (uint8_t)0x00U; /* DAC0_DAT5H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT5H = (uint8_t)0x00U; /* DAC0_DAT5L: DATA=0 */ DAC0_DAT5L = (uint8_t)0x00U; /* DAC0_DAT6H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT6H = (uint8_t)0x00U; /* DAC0_DAT6L: DATA=0 */ DAC0_DAT6L = (uint8_t)0x00U; /* DAC0_DAT7H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT7H = (uint8_t)0x00U; /* DAC0_DAT7L: DATA=0 */ DAC0_DAT7L = (uint8_t)0x00U; /* DAC0_DAT8H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT8H = (uint8_t)0x00U; /* DAC0_DAT8L: DATA=0 */ DAC0_DAT8L = (uint8_t)0x00U; /* DAC0_DAT9H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT9H = (uint8_t)0x00U; /* DAC0_DAT9L: DATA=0 */ DAC0_DAT9L = (uint8_t)0x00U; /* DAC0_DAT10H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT10H = (uint8_t)0x00U; /* DAC0_DAT10L: DATA=0 */ DAC0_DAT10L = (uint8_t)0x00U; /* DAC0_DAT11H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT11H = (uint8_t)0x00U; /* DAC0_DAT11L: DATA=0 */ DAC0_DAT11L = (uint8_t)0x00U; /* DAC0_DAT12H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT12H = (uint8_t)0x00U; /* DAC0_DAT12L: DATA=0 */ DAC0_DAT12L = (uint8_t)0x00U; /* DAC0_DAT13H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT13H = (uint8_t)0x00U; /* DAC0_DAT13L: DATA=0 */ DAC0_DAT13L = (uint8_t)0x00U; /* DAC0_DAT14H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT14H = (uint8_t)0x00U; /* DAC0_DAT14L: DATA=0 */ DAC0_DAT14L = (uint8_t)0x00U; /* DAC0_DAT15H: ??=0,??=0,??=0,??=0,DATA=0 */ DAC0_DAT15H = (uint8_t)0x00U; /* DAC0_DAT15L: DATA=0 */ DAC0_DAT15L = (uint8_t)0x00U; /* DAC0_C2: DACBFRP=0,DACBFUP=0x0F */ DAC0_C2 = (uint8_t)0x0FU; /* DAC0_C1: DMAEN=0,??=0,??=0,DACBFWM=3,DACBFMD=0,DACBFEN=1 */ DAC0_C1 = (uint8_t)0x19U; /* DAC0_C0: DACEN=0,DACRFS=1,DACTRGSEL=1,DACSWTRG=0,LPEN=0,DACBWIEN=1,DACBTIEN=1,DACBBIEN=0 */ DAC0_C0 = (uint8_t)0x66U; /* DAC0_SR: ??=0,??=0,??=0,??=0,??=0,DACBFWMF=0,DACBFRPTF=0,DACBFRPBF=0 */ DAC0_SR = (uint8_t)0x00U; DeviceDataPtr->EnMode = TRUE; /* Set the flag "device enabled" in the actual speed CPU mode */ DeviceDataPtr->EnUser = FALSE; /* Set the flag "device disabled by user" */ /* Registration of the device structure */ PE_LDD_RegisterDeviceStructure(PE_LDD_COMPONENT_DA1_ID,DeviceDataPtr); return ((LDD_TDeviceData*)DeviceDataPtr); /* Return pointer to the data data structure */ }