1 /**
2 * \ingroup MODULMACROSX
3 *
4 * \file WriteMemWordsX.c
5 *
6 * \brief Write words (16bit values) to a memory mapped location
7 *
8 */
9 /*
10  * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
11  *
12  *
13  *  Redistribution and use in source and binary forms, with or without
14  *  modification, are permitted provided that the following conditions
15  *  are met:
16  *
17  *    Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  *
20  *    Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in the
22  *    documentation and/or other materials provided with the
23  *    distribution.
24  *
25  *    Neither the name of Texas Instruments Incorporated nor the names of
26  *    its contributors may be used to endorse or promote products derived
27  *    from this software without specific prior written permission.
28  *
29  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  */
41 
42 #include "error_def.h"
43 #include "arch.h"
44 #include "edt.h"
45 #include "hal.h"
46 #include "stream.h"
47 
HAL_FUNCTION(_hal_WriteMemWordsX)48 HAL_FUNCTION(_hal_WriteMemWordsX)
49 {
50     static unsigned long lLen;
51     static unsigned long lAddr;
52     short ret_value = 0;
53     unsigned short tmp_uint;
54 
55     if(flags & MESSAGE_NEW_MSG)
56     {
57         if(STREAM_get_long(&lAddr) != 0)
58         {
59             return HALERR_WRITE_MEM_WORD_NO_RAM_ADDRESS;
60         }
61         if(STREAM_get_long(&lLen) == -1)
62         {
63             return HALERR_WRITE_MEM_WORD_NO_RAM_SIZE;
64         }
65         halt_cpu();
66         IHIL_Tclk(0);
67         cntrl_sig_low_byte();
68         SetReg_16Bits(0x08);
69     }
70 
71     for(; lLen && (ret_value == 0); lLen--)
72     {
73         ret_value = STREAM_get_word(&tmp_uint);
74         addr_16bit();
75         SetReg_20Bits(lAddr);
76         data_to_addr();
77         SetReg_16Bits(tmp_uint);
78         IHIL_Tclk(1);
79         IHIL_Tclk(0);
80         lAddr += 2;
81     }
82 
83     if(flags & MESSAGE_LAST_MSG)
84     {
85         release_cpu();
86     }
87     else if(ret_value == 1)
88     {
89         STREAM_out_change_type(RESPTYP_ACKNOWLEDGE);
90         ret_value = 0;
91     }
92     else
93     {
94         ret_value = HALERR_WRITE_MEM_WORD_UNKNOWN;
95     }
96     return(ret_value);
97 }
98