<div dir="ltr">Thank you very match<br><br><div class="gmail_quote">On Fri, Nov 27, 2009 at 12:09 PM, Stephen Tetley <span dir="ltr"><<a href="mailto:stephen.tetley@gmail.com">stephen.tetley@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Lev<br>
<br>
This one compiles with fairly minimal changes<br>
<br>
The main one is the new_state = ... line near the end has part<br>
commented out where there would otherwise be a type error.<br>
<br>
Also the nest where clause at the end was obscuring a variable binding<br>
that you needed, so I've removed the nesting.<br>
<br>
Pasted from my editor, hopefully, my mail client doesn't mangle the code:<br>
<br>
module DdrController where<br>
{-<br>
- DDR controller implements top function drive of original<br>
- list of commands . Assuming data is random .<br>
- The first version will drive commands from original command list<br>
- and adding to each command delta time , corresponding to minimum time<br>
- possible to execute<br>
-}<br>
<br>
-- Each command has it's set of attributes<br>
type Time = Int<br>
<br>
<br>
data DdrCmd =<br>
READ { bank :: Int, col :: Int } |<br>
READ_PCH { bank :: Int, col :: Int} |<br>
WRITE { bank :: Int, col :: Int} |<br>
WRITE_PCH { bank :: Int, col :: Int} |<br>
PCH_CMD {bank :: Int} |<br>
ACTIVATE {bank :: Int,row :: Int} |<br>
PCH_ALL |<br>
BST<br>
<br>
type DdrCommand = (Time,DdrCmd) -- Type of command containing offset<br>
<br>
<br>
-- Using tree to search for bank info<br>
data BankStateSingle = Single { bank_id :: Int , last_ras :: Time ,<br>
last_cas :: Time , last_pch :: Time };<br>
<br>
type BankEntry = (Int,BankStateSingle);<br>
type BankState = [BankEntry];<br>
<br>
<br>
<br>
-- Check point events<br>
data TimingCheckPoint = RAS | CAS | PCH | NONE deriving Show<br>
<br>
<br>
<br>
type TimingCondition = (Int,TimingCheckPoint,TimingCheckPoint)<br>
-- All possible timing constraints<br>
data (Num a,Show a) => TimingParams a = TRP a | TRCD a | TRAS a<br>
<br>
-- Function to initialize timing params<br>
-- Randomly generates<br>
<br>
-- Create list of entries<br>
init_bank_set :: [BankStateSingle] -> BankState<br>
init_bank_set ba_list = zip [0..((length ba_list)-1)] ba_list<br>
<br>
timing_configuration :: [(Int,TimingCheckPoint,TimingCheckPoint)]<br>
timing_configuration = [ {-tRCD-}(4,RAS,CAS) , {-tRC-}<br>
(10,RAS,RAS),{-tRP-} (2,PCH,RAS)]<br>
<br>
<br>
-- Translation of timing check point<br>
cmd2timing_checkpoint :: DdrCmd -> TimingCheckPoint<br>
cmd2timing_checkpoint cmd = case cmd of<br>
READ _ _ -> CAS<br>
READ_PCH _ _ -> CAS<br>
WRITE _ _ -> CAS<br>
WRITE_PCH _ _-> CAS<br>
PCH_CMD _-> PCH<br>
ACTIVATE _ _ -> RAS<br>
PCH_ALL -> PCH<br>
BST -> NONE<br>
<br>
-- Return method from bank Id to bank selector func<br>
<br>
bank_timing_update :: Time -> TimingCheckPoint -> BankStateSingle -><br>
BankStateSingle<br>
bank_timing_update time chk_point bank_state = new_bank_state<br>
where<br>
new_bank_state =<br>
case chk_point of<br>
RAS -> bank_state { last_ras = time }<br>
CAS -> bank_state { last_cas = time }<br>
PCH -> bank_state { last_pch = time }<br>
<br>
<br>
-- Change entry in list with other one if condition is met<br>
--upd_list :: (a -> Bool)->a->[a]->[a]<br>
--upd_list = ()<br>
<br>
-- Calculate cmd delay and update bank state<br>
-- For each cmd define whether this is RAS,CAS or PCH command<br>
-- For each cmd , find bank it refers to<br>
-- For bank calculate new timing offset based on last occurrence<br>
beginning of arc<br>
-- and longest arc to satisfy<br>
<br>
updateCmdDelay :: DdrCommand -> BankState -> [TimingCondition] -><br>
(DdrCommand,BankState)<br>
-- There are separate cases for commands<br>
-- PCH_ALL works on all banks and thus could not be issued before precharge<br>
-- timing ark is met for all cases<br>
updateCmdDelay (time,PCH_ALL) state timing = undefined<br>
updateCmdDelay (time,BST) state timing = ((time,BST),state)<br>
<br>
updateCmdDelay (time,(WRITE wr_bank wr_col)) state timing =<br>
<br>
-- Get all timing arcs to 'cmd2timing_checkpoint<br>
<br>
-- Find maximum by folding of delays and<br>
<br>
--<br>
<br>
((new_time,(WRITE wr_bank wr_col)),new_state)<br>
<br>
where {<br>
--new_state = num2bank wr_bank;<br>
<br>
new_time = if (earliest_time > time ) then earliest_time else time;<br>
<br>
<br>
new_state = (take ( wr_bank ) state) ++ {-<br>
[(wr_bank,curr_bank_state)] ++ -} (drop (wr_bank + 2) state);<br>
<br>
earliest_time = last_event_occur + (foldl max 0 delays);<br>
<br>
delays = [ time | (time,_,endpoint) <- timing ];<br>
<br>
last_event_occur = case endpoint of<br>
{ RAS -> last_ras $ snd curr_bank_state ;<br>
CAS -> last_cas $ snd curr_bank_state ;<br>
PCH -> last_pch $ snd curr_bank_state } ;<br>
<br>
-- Blabla<br>
endpoint = cmd2timing_checkpoint (WRITE wr_bank wr_col);<br>
<br>
<br>
curr_bank_state = head $ filter (\y -> fst y == wr_bank) state<br>
<br>
-- Update one of mields : last_ras,last_cas,last_pch<br>
-- For each bank<br>
<br>
<br>
}<br>
</blockquote></div><br></div>