1 /**
2 * \ingroup MODULMACROS
3 *
4 * \file WriteMemBytes.c
5 *
6 * \brief Write bytes 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 
48 
49 /**
50   WriteMemBytes
51   Write bytes to a memory mapped location.
52   inData:  <addr(32)> <length(32)> <data(8)>{*}
53   outData: -
54   addr: the address to start writing to
55   length: number of bytes to write
56   data: data to write to the given location
57 */
58 
HAL_FUNCTION(_hal_WriteMemBytes)59 HAL_FUNCTION(_hal_WriteMemBytes)
60 {
61     static unsigned long lLen;
62     static unsigned long lAddr;
63 
64     short ret_value = 0;
65     unsigned char value;
66 
67     if(flags & MESSAGE_NEW_MSG)
68     {
69         if(STREAM_get_long(&lAddr) != 0)
70         {
71             return HALERR_WRITE_MEM_WORD_NO_RAM_ADDRESS;
72         }
73         if(STREAM_get_long(&lLen) == -1)
74         {
75             return HALERR_WRITE_MEM_WORD_NO_RAM_SIZE;
76         }
77         halt_cpu();
78         IHIL_Tclk(0);
79         cntrl_sig_16bit();
80         SetReg_16Bits(0x2418);
81     }
82 
83     lLen *= 2; //DLL always sends size in word
84     for(; lLen && (ret_value == 0); lLen--)
85     {
86         ret_value = STREAM_get_byte(&value);
87         addr_16bit();
88         SetReg_16Bits((unsigned short)lAddr);
89         data_to_addr();
90         SetReg_8Bits(value);
91         IHIL_Tclk(1);
92         IHIL_Tclk(0);
93         lAddr += 1;
94     }
95 
96     if(flags & MESSAGE_LAST_MSG)
97     {
98         release_cpu();
99     }
100     else if(ret_value == 1)
101     {
102         STREAM_out_change_type(RESPTYP_ACKNOWLEDGE);
103         ret_value = 0;
104     }
105     else
106     {
107         ret_value = HALERR_WRITE_MEM_WORD_UNKNOWN;
108     }
109     return(ret_value);
110 }
111